//=============================================================
function SetHorzCode(){
	var xSect1=document.DetailHorz.Sect1.value
	var xSect2=document.DetailHorz.Sect2.value
	
	if(xSect1 && xSect2){
		if(xSect1=="Door" && xSect2=="Panel"){
			SetCode1();
		}else if(xSect1=="Panel" && xSect2=="Door"){
			SetCode2();
		}else if(xSect1=="Panel" && xSect2=="Panel"){
			SetCode3();
		}else{
			alert("Make sure both sections have been filled out");
		}
	}else{
		alert("Make sure both sections have been filled out");
	}
}

function ValidateDetail(){
var xCode = new String(document.DetailHorz.HorzCode.value)

	if(xCode.indexOf("WP")!=-1 && xCode.indexOf("WW")==-1){
		alert("Pocket Doors can only have Solid Panels attached to them")
	}

}
//=============================================================
function SetCode1(){ //--> Door to Panel
var xDProfile, xDMake, xDFrame, xPProfile, xPFrame
	if(navigator.appName=="Netscape"){//if the browser is netscape must use different
		//get the door selections from section 1
		var xlist1=document.DetailHorz.DoorType1
		xDProfile=xlist1.options[xlist1.selectedIndex].value
		var xlist2=document.DetailHorz.DoorMake1
		xDMake=xlist2.options[xlist2.selectedIndex].value
		var xlist3=document.DetailHorz.DoorFrame1
		xDFrame=xlist3.options[xlist3.selectedIndex].value
		//next is the panel selections from section 2
		var xlist4=document.DetailHorz.PanelType2
		xPProfile=xlist4.options[xlist4.selectedIndex].value
		var xlist5=document.DetailHorz.PanelFrame2
		xPFrame=xlist5.options[xlist5.selectedIndex].value
	}else{// for IE users
	
		//get door selections from section 1
		xDProfile=document.DetailHorz.DoorType1.value
		xDMake=document.DetailHorz.DoorMake1.value
		xDFrame=document.DetailHorz.DoorFrame1.value
		//get panel selections from section 2
		xPProfile=document.DetailHorz.PanelType2.value
		xPFrame=document.DetailHorz.PanelFrame2.value
	}
	// set the horizontal code based by the selections
	if(xPProfile&&xDMake&&xDFrame&&xPProfile&&xPFrame){//make sure everything is selected that is needed
		if(xPProfile=="WW"){
			document.DetailHorz.HorzCode.value=xDFrame+"-"+xPProfile+"-"+xDProfile+xDMake;
		}else{
			document.DetailHorz.HorzCode.value=xDFrame+"-"+xPFrame+"-"+xDProfile+xDMake;
		}
		//alert("Door Profile: "+xDProfile+"\nDoor Make: "+xDMake+"\nDoor Frame: "+xDFrame)
	}else{
		alert("Please make sure everything is selected")
	}
}

//=============================================================
function SetCode2(){ //--> Panel to Door
var xDProfile, xDMake, xDFrame, xPProfile, xPFrame
	if(navigator.appName=="Netscape"){//if the browser is netscape must use different
	
		//get the panel selections from section 1
		var xlist1=document.DetailHorz.PanelType1
		xPProfile=xlist1.options[xlist1.selectedIndex].value
		var xlist2=document.DetailHorz.PanelFrame1
		xPFrame=xlist2.options[xlist2.selectedIndex].value
		
		//get the door selections from section 1
		var xlist3=document.DetailHorz.DoorType2
		xDProfile=xlist3.options[xlist3.selectedIndex].value
		var xlist4=document.DetailHorz.DoorMake2
		xDMake=xlist4.options[xlist4.selectedIndex].value
		var xlist5=document.DetailHorz.DoorFrame2
		xDFrame=xlist5.options[xlist5.selectedIndex].value
		
	}else{// for IE users
	
		//get door selections from section 2
		xDProfile=document.DetailHorz.DoorType2.value
		xDMake=document.DetailHorz.DoorMake2.value
		xDFrame=document.DetailHorz.DoorFrame2.value
		//get panel selections from section 1
		xPProfile=document.DetailHorz.PanelType1.value
		xPFrame=document.DetailHorz.PanelFrame1.value
	}
	// set the horizontal code based by the selections
	if(xPProfile&&xDMake&&xDFrame&&xPProfile&&xPFrame){//make sure everything is selected that is needed
		if(xPProfile=="WW"){
			document.DetailHorz.HorzCode.value=xDFrame+"-"+xPProfile+"-"+xDProfile+xDMake;
		}else{
			document.DetailHorz.HorzCode.value=xDFrame+"-"+xPFrame+"-"+xDProfile+xDMake;
		}
	}else{
		alert("Please make sure everything is selected")
	}
}

//=============================================================
function SetCode3(){ //--> Panel to Panel
var xPProfile1, xPProfile2, xPFrame1, xPFrame2
//alert ("set code 3")
	if(navigator.appName=="Netscape"){//if the browser is netscape must use different
	
		//get the panel selections from section 1
		var xlist1=document.DetailHorz.PanelType1
		xPProfile1=xlist1.options[xlist1.selectedIndex].value
		var xlist2=document.DetailHorz.PanelFrame1
		xPFrame1=xlist2.options[xlist2.selectedIndex].value
		
		//get the door selections from section 1
		var xlist3=document.DetailHorz.PanelType2
		xPProfile2=xlist3.options[xlist3.selectedIndex].value
		var xlist4=document.DetailHorz.PanelFrame2
		xPFrame2=xlist4.options[xlist4.selectedIndex].value
		
	}else{// for IE users
	
		//get door selections from section 2
		xPProfile1=document.DetailHorz.PanelType1.value
		xPFrame1=document.DetailHorz.PanelFrame1.value
		//get panel selections from section 1
		xPProfile2=document.DetailHorz.PanelType2.value
		xPFrame2=document.DetailHorz.PanelFrame2.value
		//alert("xPFrame="+xPFrame1 + "\nxPProfile1=" + xPProfile1+"\nxPProfile2="+xPProfile2+"\nxPFrame2"+xPFrame2)
		
	}
	// set the horizontal code based by the selections

	//if(xPProfile1 && xPFrame1 && xPProfile2 && xPFrame2){//make sure everything is selected that is needed
		
		if(xPProfile1=="WW" && xPProfile2!="WW"){
			document.DetailHorz.HorzCode.value=xPProfile1+"-"+xPFrame2;
			//alert("2")
		}else if(xPProfile2=="WW" && xPProfile1!="WW"){
			document.DetailHorz.HorzCode.value=xPProfile2+"-"+xPFrame1;
			//alert("3")
		}else if(xPProfile1=="WW" && xPProfile2=="WW"){
			document.DetailHorz.HorzCode.value="WW-WW";
			//alert("4")
		}else if(xPProfile1!="WW" && xPProfile2!="WW"){
			//alert("5")
			document.DetailHorz.HorzCode.value = xPFrame1+"-"+xPFrame2;
			
		}
		//alert("Value= "+document.DetailHorz.HorzCode.value)
	//}else{
		//alert("1a")
		//document.DetailHorz.HorzCode.value=""
		//alert("Please make sure everything is selected");
	//}
}

//=============================================================
function SetValue(xSec,xValue){
	if(xSec=="Section1"){
		document.DetailHorz.Sect1.value=xValue;
	}else if(xSec=="Section2"){
		document.DetailHorz.Sect2.value=xValue;
	}else{
		document.DetailHorz.Sect1.value=""
		document.DetailHorz.Sect2.value="";
	}
}

//=============================================================
function SubmitCheck(){
	var xSection1=document.DetailHorz.Sect1.value;
	var xSection2=document.DetailHorz.Sect2.value;
	
	if(xSection1 && xSection2){
		if(xSection1=="Door" && xSection2=="Door"){
			alert("At the moment there are no Horizontal Details for a Door to Door combination")
		}else{
			document.DetailHorz.submit();
		}
	}
}

//=============================================================
function SetDoorMake(xSec){
	if(xSec=="Section1"){
		document.DetailHorz.DMake1.value=document.DetailHorz.DoorMake1.value;
	}else if(xSec=="Section2"){
		document.DetailHorz.DMake2.value=document.DetailHorz.DoorMake2.value;
	}else{
		document.DetailHorz.DMake1.value=""
		document.DetailHorz.DMake2.value="";
	}
}

//=============================================================
function ChangeDoorFrame(xSect){
var xDoor, xaDoorMake, xFrameField, xFrameValue
	if(xSect=="Section1"){
		xDoor=document.DetailHorz.DoorType1.value;
		xDoorMake=document.DetailHorz.DMake1.value;
	}else{
		xDoor=document.DetailHorz.DoorType2.value;
		xDoorMake=document.DetailHorz.DMake2.value;
	}
	
	if(xDoor=='WP'){
		xFrameField=new String("Select Door Frame, Pocket Wood Door Frame");
		xFrameValue=new String("--,WP");
	}else if(xDoor=="WB"){
		if(xDoorMake=="S67"||xDoorMake=="S136"||xDoorMake=="E67"){
			xFrameField=new String("Select Door Frame, Anodized Aluminum Frame");
			xFrameValue=new String("--,AP");
		}else{
			xFrameField=new String("Select Door Frame, Wood Door Frame");
			xFrameValue=new String("--,WB");
		}
	}else if(xDoorMake=="S67"||xDoorMake=="S136"||xDoorMake=="E67"){
		xFrameField=new String("Select Door Frame, Anodized Aluminum Frame");
		xFrameValue=new String("--,AP");
	}else{
		xFrameField=new String("Select Door Frame, Aluminum Door, 1 1/2inch(39mm) Wood Frame,2inch(51mm) Wood Frame");
		xFrameValue=new String("none,WD,3WF,5WF");
	}
	var xTextList = eval(xFrameField);
	var xValueList = eval(xFrameValue);
	var xArrayFill=xTextList.split(",");
	var xArrayValue=xValueList.split(",");
	
	if(xSect=="Section1"){
		xTempField=document.DetailHorz.DoorFrame1.options.length;
	}else{
		xTempField=document.DetailHorz.DoorFrame2.options.length;
	}
	
	if(navigator.appName=="Netscape"){
		for(x=xTempField; x!=-1; x+=-1){
			if(xSect=="Section1"){
				//alert("1- "+document.DetailHorz.DoorFrame1.options[x])
				document.DetailHorz.DoorFrame1.options[x]=null;
			}else{
				document.DetailHorz.DoorFrame2.options[x]=null;
			}
		}
	}else{
		for(x=xTempField; x!=-1; x+=-1){
			if(xSect=="Section1"){
				document.DetailHorz.DoorFrame1.options.remove(x);
			}else{
				document.DetailHorz.DoorFrame2.options.remove(x);
			}
		}
	}
	
	if(navigator.appName=="Netscape"){
		for(i=0;i<xArrayFill.length;i++){
			if(xSect=="Section1"){
				document.DetailHorz.DoorFrame1.options[i]=new Option(xArrayFill[i],xArrayValue[i],false,false);
			}else{
				document.DetailHorz.DoorFrame2.options[i]=new Option(xArrayFill[i],xArrayValue[i],false,false);
			}
		}
	}else{
		for(i=0; i<xArrayFill.length;i++){
			var newElem = document.createElement("OPTION");
			newElem.text = xArrayFill[i];
  			newElem.value = xArrayValue[i];
			
			if(xSect=="Section1"){
  				document.DetailHorz.DoorFrame1.options.add(newElem,[i]);
			}else{
				document.DetailHorz.DoorFrame2.options.add(newElem,[i]);
			}
		}
	}
}
