// for ink rate
var HHS_PosCombination = new Array(12);
HHS_PosCombination[0] = "1,2";
HHS_PosCombination[1] = "1,2";
HHS_PosCombination[2] = "3,4,5";
HHS_PosCombination[3] = "3,4,5";
HHS_PosCombination[4] = "3,4,5";
HHS_PosCombination[5] = "6,7";
HHS_PosCombination[6] = "6,7";
HHS_PosCombination[7] = "8";
HHS_PosCombination[8] = "9";
HHS_PosCombination[9] = "10";
HHS_PosCombination[10] = "11";
HHS_PosCombination[11] = "12";

// for color
var HHS_PosGroups = new Array(2);
HHS_PosGroups[0] = "1,3,6,7,8,9,10,11,12";
HHS_PosGroups[1] = "2,4,5,7,8,9,10,11,12";

// Functions to satisfy combination
function ApplyCombination(HHS_PosVarObj, HHS_PosId){	//HHS_PosId is the position ( -1 is the index of combination)
	
	if(HHS_PosVarObj.checked==true){ // if position is checked
		//alert("checked "+HHS_PosId);
		var HHS_temp = HHS_PosCombination[HHS_PosId-1].split(",");
		var PositionCount = document.product.nopos.value;
		var AllowThisPosition = true;
		
		for(var i=0; i < PositionCount; i++){		
			PositionID = eval("document.product.ppid"+i+".value;");
			AllowThisPosition = true;
			
			//chk if this position is within this combination
			for(j=0; j < HHS_temp.length; j++){
				if( HHS_temp[j] == PositionID ){
					AllowThisPosition = true;
				}
			}	
			if(!AllowThisPosition){
				eval("document.product.pos"+i+".checked=false;");
				eval("document.product.pos"+i+".disabled=true;");
			}
		}			
	}
	else{	// if position is unchecked
		//alert("unchecked "+HHS_PosId);
		var HHS_temp = HHS_PosCombination[HHS_PosId-1].split(",");
		var PositionCount = document.product.nopos.value;
		
		// loop thro the positions and chk if any other position is checked
		for(var i=0; i < PositionCount; i++){	
			if(eval("document.product.pos"+i+".checked;") == true){ // if checked do nothing return
				return true;
			}						
		}
		
		// no position is chosen, enable all positions
		for(i=0; i < PositionCount; i++){	
			eval("document.product.pos"+i+".disabled=false;");
		}
		
	}
}

function validForm(){
	//alert(""+document.product.ser[0].checked);
	//if(document.product.ser.value=='ScreenPrinting'){ //if screen printing then chk if color is chosen and validate
	//if(document.product.ser[0].checked==true){ //if screen printing then chk if color is chosen and validate
	if(document.all['selser'].style.visibility!="hidden"){ //if screen printing then chk if color is chosen and validate
		HHS_FrontColorsChosen = document.product.nofront.value;
		HHS_BackColorsChosen = document.product.noback.value;
		
		if( (HHS_FrontColorsChosen != "0") || (HHS_BackColorsChosen != "0") ){
			
			var PositionCount = document.product.nopos.value;
			var i,j,PositionID;
			
			// if front color chosen
			if( HHS_FrontColorsChosen != "0" ){
				var HHS_FrontPosChosen = false;
				for(i=0; i < PositionCount; i++){		
					if(eval("document.product.pos"+i+".checked;") == true){ // if checked then chk if pos id is in front group
						PositionID = eval("document.product.ppid"+i+".value;");
						HHS_FrontPosGrp = HHS_PosGroups[0].split(","); // positions in front grp
						for(j=0; j<HHS_FrontPosGrp.length; j++){
							if(HHS_FrontPosGrp[j] == PositionID){
								HHS_FrontPosChosen = true;	// Front position is chosen
								break;
							}								
						}
					}						
				}	
			}
			
			// if back color chosen
			if( HHS_BackColorsChosen != "0" ){
				var HHS_BackPosChosen = false;
				for(i=0; i < PositionCount; i++){		
					if(eval("document.product.pos"+i+".checked;") == true){ // if checked then chk if pos id is in back group
						PositionID = eval("document.product.ppid"+i+".value;");
						HHS_BackPosGrp = HHS_PosGroups[1].split(","); // positions in back grp
						for(j=0; j < HHS_BackPosGrp.length; j++){
							if(HHS_BackPosGrp[j] == PositionID){
								HHS_BackPosChosen = true;   // back position is chosen
								break;
							}								
						}
					}						
				}	
			}
			
			// chk if color position and artwork positions match
			if( ((HHS_FrontColorsChosen != "0") && (HHS_FrontPosChosen != true)) || ((HHS_BackColorsChosen != "0") && (HHS_BackPosChosen != true)) ){
				alert("Choose valid artwork position and No. of colors");
				return false;
			}
			
		}
	}
	
	return true;
}
