//Get selected vanity unit if it isn't hidden
function ValidateVanityUnit(){

	if (document.frmeasyspec.hidvanity.value == 1){
		var selectedVanityUnit = document.getElementById("vanity_materialoptions").selectedIndex;
	}
	
	switch(selectedVanityUnit)
	{
	case 0:
	  //Nothing selected
	  alert ("Choose Vanity Units Material Options");
	  return false;
	  break;    
	case 1:
	  //HPL
	  validateGroup1("hpl");
	  break;
	case 2:
	  //SGL
	  validateGroup1("sgl");
	  break;
	case 3:
	  //Quartz
	  validateGroup2("quartz");
	  break;
	 case 4:
	  //Granite
	  validateGroup2("granite");
	  break;
	 case 5:
	  //Soild Surface
	  validateGroup1("solidsurface");
	  break;	  
	default:
	}	
}

// Validation for HPL and SGL and Solid surface(Group 1)
function validateGroup1(material){
	// Vanity Unit Type
	var selectedVanityUnit = document.getElementById("vanity_materialoptions").selectedIndex;
	// Width
	var vu_hpl0 = document.getElementById("vu_hpl0").value;
	// Front edge profile - not user selecteable, always present
	var fep01 = document.getElementById("fep01").value;	
	//Rear edge profile
	var vu_hpl3 = document.getElementById("vu_hpl3").selectedIndex;
	//Support system
	var vu_hpl4 = document.getElementById("vu_hpl4").selectedIndex;
	//Other requirements
	var vu_hpl6 = document.getElementById("vu_hpl6").selectedIndex;
	//Under panels - Only appears when vu_hpl4 == 1 or 2
	var vu_hpl1 = document.getElementById("vu_hpl1").selectedIndex;
	//Panel fixings - Only appears when vu_hpl4 == 1 or 2
	var vu_hpl5 = document.getElementById("vu_hpl5").selectedIndex;
	
	// HPL AND SOLID SURFACE
	//Name													FIELD ID			ARRAY VALUE		OPTION				
	//Vanity tops material Width							vu_hpl0				N/A				1						NB:  value direct from drop-down, no array lookup required
	//Front edge											fep01				N/A				2						NB:  value direct from drop-down, no array lookup required
	//Rear Edge Profile										vu_hpl3				rep_hpl			3
	//Underpanel material									vu_hpl1				up				4						NB: Also contains values for Finish/colour and Edge treatment	(Options 5 and 6)
	//Panel Fixing (Accessories)	 						vu_hpl5				pf				7
	//Support system 										vu_hpl4				ss_a			8
	//Other requirements 									vu_hpl6				or_a			9
	
	// SGL
	//Name													FIELD ID			ARRAY VALUE		OPTION				
	//Vanity tops material Width							vu_hpl0				N/A				1						NB:  value direct from drop-down, no array lookup required
	//Vanity tops material Upstand							N/A					N/A				2						NB: "and upstand" appended to SGL 350/555 with Upstand ONLY using condition below
	//Front edge width										fep01				N/A				3						NB:  value direct from drop-down, no array lookup required
	//Front edge radius										N/A					N/A				4						NB: "front" appended to SGL 350/555 with Upstand ONLY using condition below
	//Rear Edge Profile										vu_hpl3				rep_hpl			5		
	//Underpanel material									vu_hpl1				up				6						NB: Also contains values for Finish/colour and Edge treatment	(Options 7 and 8)
	//Panel Fixing (Accessories)	 						vu_hpl5				pf				9
	//Support system 										vu_hpl4				ss_a			10
	//Other requirements 									vu_hpl6				or_a			11
	
	// Option 2 "and upstand" appended  appended to SGL 350/555 with Upstand ONLY			
	var vanityTopsMaterialUpstand = "";
	var vanityTopsMaterialFront = "";	
	if(material == "sgl" && vu_hpl3 == 1){
			vanityTopsMaterialUpstand = "and upstand";			
	}else{
			vanityTopsMaterialUpstand = " ";
	}
	
	vanityTopsMaterialFront = "front"; // This was a dynamic option for upstand/no upstand, but rather than reworking all the templates yet again I'm setting this as a static variable..
	
	// validate dropdowns for hpl/sgl
	
	var validateGroup1 = false;
	
	// validate routine
	
	// Support system 1 or 2 selected
	if(vu_hpl4 <= 2){
		// If SGL with a width of 350 is selected it has no Under Panel Options, so don't check for it
		if(selectedVanityUnit == "2" && vu_hpl0 == "350"){
			// Under Panel Options are not applicable so don't check for it
			if(vu_hpl0 == 0 || vu_hpl3 == 0 || vu_hpl4 == 0 || vu_hpl6 == 0){
				validateGroup1 = false;
			}else{
				validateGroup1 = true;		
			}
		}else{
			// Under Panels are currently displayed
			// Under Panels option 6 (Not Applicable) selected, Under Panels dissapears, so don't check for it	
			if(vu_hpl1 == 6){
				if(vu_hpl0 == 0 || vu_hpl3 == 0 || vu_hpl4 == 0 || vu_hpl6 == 0){
					validateGroup1 = false;
				}else{
					validateGroup1 = true;					
				}
			// Under Panels < option 6 (Not Applicable) selected, Under Panels appears, so check for it
			}else{
				if(vu_hpl0 == 0 || vu_hpl3 == 0 || vu_hpl4 == 0 || vu_hpl6 == 0 || vu_hpl1 == 0 || vu_hpl5 == 0){
					validateGroup1 = false;
				}else{
					validateGroup1 = true;				
				}
			}
		}
	// Support system 3 or 4 selected
	}else if(vu_hpl4 >= 2){
		//Validate without Underpanels and Panel fixings
		if(vu_hpl0 == 0 || vu_hpl3 == 0 || vu_hpl6 == 0){
			validateGroup1 = false;
		}else{
			validateGroup1 = true;
		}
	}else{
		validateGroup1 = false;
	}
	
	// create doc
	
	if(validateGroup1 != false){
		// if the support system is cantilver brackets (vu_hpl4 == 1 || vu_hpl4 == 2), then there are no under panels or panel fixings
		if(material == "hpl"){
			if(vu_hpl4 == 1 || vu_hpl4 == 2){
				document.frmeasyspec.frmvanityunitvalues.value = material + ":" + "" + vu_hpl0 + ":" + "" + fep01 + ":" + "" + rep_hpl[vu_hpl3] + ":" + "" + up_a[vu_hpl1] + ":" + "" + pf[vu_hpl5] + ":" + "" + ss_a[vu_hpl4] + ":" + "" + or_a[vu_hpl6];
			}else if(vu_hpl4 == 3 || vu_hpl4 == 4){
				document.frmeasyspec.frmvanityunitvalues.value = material + ":" + "" + vu_hpl0 + ":" + "" + fep01 + ":" + "" + rep_hpl[vu_hpl3] + ":" + "" + ":" + "" + ":" + "" +  ":" + "" + ":" + "" + ss_a[vu_hpl4] + ":" + "" + or_a[vu_hpl6];
			}
		}else if(material == "sgl"){
			if(vu_hpl4 == 1 || vu_hpl4 == 2){
				document.frmeasyspec.frmvanityunitvalues.value = material + ":" + "" + vu_hpl0 + ":" + "" + vanityTopsMaterialUpstand + ":" + fep01 + ":" + "" + vanityTopsMaterialFront + ":" + "" + rep_sgl[vu_hpl3] + ":" + "" + up_b[vu_hpl1] + ":" + "" + pf[vu_hpl5] + ":" + "" + ss_a[vu_hpl4]  +":" + "" + or_a[vu_hpl6];
			}else if(vu_hpl4 == 3 || vu_hpl4 == 4){
				document.frmeasyspec.frmvanityunitvalues.value = material + ":" + "" + vu_hpl0 + ":" + "" + vanityTopsMaterialUpstand + ":" + fep01 + ":" + "" + vanityTopsMaterialFront + ":" + "" + rep_sgl[vu_hpl3] + ":" + "" + ":" + "" + ":" + "" + ":" + ""  + ":" + "" + ss_a[vu_hpl4] + ":" +  "" + or_a[vu_hpl6];
			}
		}else if(material == "solidsurface"){
			if(vu_hpl4 == 1 || vu_hpl4 == 2){
				document.frmeasyspec.frmvanityunitvalues.value = material + ":" + "" + vu_hpl0 + ":" + "" + fep01 + ":" + "" + rep_ss[vu_hpl3] + ":" + "" + up_a[vu_hpl1] + ":" + "" + pf[vu_hpl5] + ":" + "" + ss_a[vu_hpl4] + ":" + "" + or_a[vu_hpl6];
			}else if(vu_hpl4 == 3 || vu_hpl4 == 4){
				document.frmeasyspec.frmvanityunitvalues.value = material + ":" + "" + vu_hpl0 + ":" + "" + fep01 + ":" + "" + rep_ss[vu_hpl3] + ":" + "" + ":" + "" + ":" + "" +  ":" + "" + ":" + "" + ss_a[vu_hpl4] + ":" + "" + or_a[vu_hpl6];
			}
		}
		}else{
			// validation failed
			if(material == "hpl"){
				alert ("Choose Vanity Units > All High Pressure Laminate options");
			}else if(material == "sgl"){
				alert ("Choose Vanity Units > All Solid Grade options");
			}else if(material == "solidsurface"){
				alert ("Choose Vanity Units > All Solid Surface options");
			}		
		}	
	}

// Validation for Granite and Quartz (Group 2)
function validateGroup2(material){
	// Width
	var  vu_hpl90 =  document.getElementById("vu_hpl90").value;
	// Front edge profile - not user selecteable, always present
	var  fep01 = document.getElementById("fep01").value;	
	// Rear edge profile
	var vu_sgl3   = document.getElementById("vu_sgl3").selectedIndex;
	// Support system
	var  vu_sgl4   = document.getElementById("vu_sgl4").selectedIndex;
	// Other
	var  vu_sgl6   = document.getElementById("vu_sgl6").selectedIndex;
	
	// Validate for all secondary options	
	if(vu_hpl90 == 0 || vu_sgl3 == 0 || vu_sgl4 == 0 || vu_sgl6 == 0){	
		alert ("Choose Vanity Units > All Solid Grade Laminate options");
		return false; 
	}else{
			//Name													FIELD ID			ARRAY VALUE		OPTION			
			//Vanity tops material Width							vu_hpl90					N/A				1						NB:  value direct from drop-down, no array lookup required
			//Vanity tops material Radius							N/A							N/A				2						NB: ",small radius to edges" appended to Granite 350/550 with Upstand ONLY using condition below
			//Front edge											fep01						N/A				3						NB:  value direct from drop-down, no array lookup required
			//Rear Edge Profile										vu_sgl3						rep_b			4
			//Support System										vu_sgl4						ss_b			5
			//Other Requirements									vu_sgl6						or_b			6
			
			// Option 2 value - "small radius to edges" appended to Granite 350/550 with Upstand ONLY			
			var  vanityTopsMaterialRadius = "";			
			if(material == "granite" && vu_sgl3 == 1){
					vanityTopsMaterialRadius = ", small radius to edges";
			}else{
				vanityTopsMaterialRadius = " ";
			}
			document.frmeasyspec.frmvanityunitvalues.value =  material + ":" + vu_hpl90 + ":" + vanityTopsMaterialRadius + ":" + fep01 + ":" + rep_b[vu_sgl3] + ":" + ss_b[vu_sgl4] + ":" + or_b[vu_sgl6];
	}
}

// Information arrays for HPL / SGL

// Rear Edge Profile - HPL
var rep_hpl = new Array(2);
rep_hpl[1] = "Postformed to form coved upstand up to 75mm high";
rep_hpl[2] = "Not required";

// Rear Edge Profile - SOLID SURFACE
var rep_ss = new Array(2);
rep_ss[1] = "Featuring a 75mm upstand. Bed and upstand bonded to provide an invisible seam.";
rep_ss[2] = "Not applicable";

// Rear Edge Profile - SGL
var rep_sgl = new Array(2);
rep_sgl[1] = "Laminate top and 75mm upstand rebated into extruded aluminium jointing section.  Jointing section has smooth coved radius.";
rep_sgl[2] = "No rear upstand";

// Under Panels - HPL
var up_a = new Array(6);
up_a[1] = "19mm high performance moisture resistant (MR) melamine faced 710kg/m3 chipboard (MFC):Colour to be confirmed from Amwell Washroom MFC selection:All edges are lipped with corresponding / contrasting durable PVC ";				
up_a[2] = "18mm moisture resistant V313 chipboard faced both sides with high pressure laminate:Colour to be confirmed from Amwell Washroom HPL selection:All edges are lipped with corresponding / contrasting durable PVC";				
up_a[3] = "18mm moisture resistant V313 chipboard faced both sides with high pressure laminate:Colour to be confirmed from Amwell Washroom HPL selection:Vertical edges postformed, horizontal edges are lipped with corresponding / contrasting durable PVC";				
up_a[4] = "12/13mm solid grade laminate (SGL) to provide maximum protection against water and vandalism:Colour to be confirmed from Amwell Washroom HPL selection:Edges are machined to a smooth profile";
up_a[5] = "18mm moisture resistant V313 chipboard faced both sides with real wood veneer:Timber species to be confirmed:Edges are lipped in hardwood prior to veneering";
up_a[6] = "Not applicable:Not applicable:Not applicable";

// Under Panels - SGL
var up_b = new Array(6);
up_b[1] = "19mm high performance moisture resistant (MR) melamine faced 710kg/m3 chipboard (MFC):Colour to be confirmed from Amwell Washroom MFC selection:All edges are lipped with corresponding / contrasting durable PVC ";				
up_b[2] = "18mm moisture resistant V313 chipboard faced both sides with high pressure laminate:Colour to be confirmed from Interplan Washroom SGL selection:All edges are lipped with corresponding / contrasting durable PVC";				
up_b[3] = "18mm moisture resistant V313 chipboard faced both sides with high pressure laminate:Colour to be confirmed from Amwell Washroom SGL selection:Vertical edges postformed, horizontal edges are lipped with corresponding / contrasting durable PVC";				
up_b[4] = "12/13mm solid grade laminate (SGL) to provide maximum protection against water and vandalism:Colour to be confirmed from Amwell Washroom SGL selection:Edges are machined to a smooth profile";
up_b[5] = "18mm moisture resistant V313 chipboard faced both sides with real wood veneer:Timber species to be confirmed:Edges are lipped in hardwood prior to veneering";
up_b[6] = "Not applicable:Not applicable:Not applicable";

// Panel Fixing (Accessories)
var pf = new Array(4);
pf[1] = "Concealed Keku ‘lift off’ brackets.";				
pf[2] = "Concealed Keku ‘push fit’ brackets.";				
pf[3] = "Underpanels to supplied with easyfit hinges";				
pf[4] = "Underpanels to be supplied with easyfit hinges & budget cylinder lock";

// Support System
var ss_a = new Array(4);
ss_a[1] = "Treated softwood framework, notched and screwed made to measure and site assembled.";			
ss_a[2] = "Galvanised mild steel channel sections made to measure and site assembled.";
ss_a[3] = "Polyester powder coated aluminium cantilever brackets";
ss_a[4] = "Satin polished stainless steel cantilever brackets";	

// Other requirements
var or_a = new Array(2);
or_a[1] = "Complete with cut outs for top mounted wash hand basins. (sanitaryware & silicone sealant by others)";
or_a[2] = "Not applicable";

// Information arrays for GRANITE / QUARTZ

// Rear Edge Profile	
var rep_b = new Array(2);
rep_b[1] = "75mm high upstand butted directly onto bed.";
rep_b[2] = "No rear upstand";

// Support System
var ss_b = new Array(2);
ss_b[1] = "Polyester powder coated aluminium cantilever brackets";
ss_b[2] = "Satin polished stainless steel cantilever brackets";			

// Other requirements
var or_b = new Array(2);
or_b[1] = "Complete with cut outs for either top mounted or undermounted wash hand basins. (sanitaryware & silicone sealant by others)";
or_b[2] = "Not applicable";
