/*********************************
*
*  This is the jQuery code for Doormark
*
*  Kit Koenig - April 5, 2010
*
**********************************/
database = new Object();

$(document).ready(function(){
	validations();  //	See bottom of the file
	hideContent();	// 	Function to hide all the div containers
	datePhoneMask();//	add Date and add mask for phone number (xxx)xxx-xxxx
	populateDatabase();	// Use a AJAX call to load a javascript object with database data
	 


	
	$("button").click(function(){
        // add molding_1_type id
		
		$i=1
		while (document.getElementById(["Molding_"+ $i + "_Quantity"]) != null) {	
		    x=(document.getElementById("Molding_" + $i + "_Quantity"));
			//alert( x.value );   
	    	if ((document.getElementById("Molding_" + $i + "_Type").selectedIndex) != 0 ) {	    		
	    		var z=document.getElementById("Molding_" + $i + "_Type").selectedIndex;
		    	var y=(document.getElementById("Molding_" + $i + "_Type").options);		
				//alert( y[z].text );
		    	if ((x.value==null || x.value=="")) {
					alert("Molding qty is empty. Enter 0 for none.");
			    }
	    	}	
		    	$i=++$i   
		 }
		  //$(".bar").css("background-color","yellow"); 

	});
	
	$("#Molding_1_Quantity").change(function(){
		
	});
	
	
	$("#Door_Design").change(function(){  
		//clearOptions(); // this resets Color, Door Options and Drawer Options on Door Design Change
		doorDesignCode = $(this).val();  //This is the value - now the desgin code
		doorDesignName = $("#Door_Design option:selected").text(); //This is the desname
		$("#Door_Design_Name").val(doorDesignName);
		buildColor(doorDesignCode);
		buildDoorStyle(doorDesignCode);
		buildDrawStyle(doorDesignCode);
		checkEdges(doorDesignName); 	// checks if edges should be shown full or minimum
		$(".hideColorView").show();
		
		$(".edgesFull").show();
		$(".edgesMin").hide();
		if (doorDesignName == "Gulfstream" || doorDesignName.match("Shaker") == "Shaker"){
			$(".edgesFull").hide();
			$(".edgesMin").show();
		}
	});
	
	$("#Color").change(function(){		
		colorCode = $(this).val();
		colorName = $("#Color option:selected").text(); //This is the Color Name
		doorDesignName = $("#Door_Design option:selected").text(); //This is the desname
		
		$("#Color_Name").val(colorName);
		checkGlaze(doorDesignName, colorCode);
		$(".hideView").show();
	});
	$("#units").change(function(){
		unitsValidations();  //adds min and max units to doors - and changes is units change
	});
	
	$(".addmore").click(function(){
		var type = $(this).attr('id');				//  This is the id from the add another item
		var numOfAdds = parseInt(type.substr(0,1)); // This is the id from the 
													// add another item giving  - first character is the number
		var numOfAddsPlus = numOfAdds + 1;			// add one to the previous added number
		var newId = numOfAddsPlus + type.substr(1);	// create the new id string for the click div
		
		var topdiv = type.substr(2);				// remove the first 2 chars from id to get the top container id
		var clones = topdiv + "_add";				// create a string from the top div for a new id
			
		var nameNew = new Array();					// create an array of input names

	    $("#" + topdiv).find(':input').each(function(i) {
		    var names = this.name;							// get existing names
		    var pattern=/_\d\d?_/;							// make a pattern for _x_ where x is a number of adds
		    var replace = "_" + numOfAddsPlus + "_";		// Make a new name
			nameNew[i] = names.replace(pattern, replace);	// replace the new name
	    });
		var cloninator = $("#" + topdiv).clone();			// Make a clone of the old form piece
		
		cloninator.find(':input').each(function(i) {		//  Add in the new names
		   $(this).attr("name", nameNew[i]).val("");
		   $(this).attr("id", nameNew[i]).val("");            // jm
			   
		});
		cloninator.appendTo("#" + clones);					// Add it to the current Form

		$("#" + type).attr("id", newId);					// Finally change the id of the text that is clicked
															// to add the fields
		unitsValidations();  //adds min and max units to doors - and changes is units change
	}); 
	
	$('#expand_doors_tag').click(function(){toggling ("#expand_doors", "Door");}); //Sets up Toggling hide / show for doors
	$('#expand_drawers_tag').click(function(){toggling ("#expand_drawers", "Drawers");}); //Sets up Toggling hide / show for drawers
	$('#expand_mullion_tag').click(function(){toggling ("#expand_mullion", "Mullion Doors");}); //Sets up Toggling hide / show for mullion Doors
	$('#expand_slabfillers_tag').click(function(){toggling ("#expand_slabfillers", "Slab Fillers");}); //Sets up Toggling hide / show for Slab Fillers
	$('#expand_slabfillersmin_tag').click(function(){toggling ("#expand_slabfillersmin", "Slab Fillers");}); //Sets up Toggling hide / show for Slab Fillers
	$('#expand_molding_tag').click(function(){toggling ("#expand_molding", "Molding");}); //Sets up Toggling hide / show for Molding
	$('#expand_appPanels_tag').click(function(){toggling ("#expand_appPanels", "Application Panels");}); //Sets up Toggling hide / show for Application Panels
	$('#expand_panelOP_tag').click(function(){toggling ("#expand_panelOP", "Panel Over Panel");}); //Sets up Toggling hide / show for Panel Over Panel
	$('#expand_wineRacks_tag').click(function(){toggling ("#expand_wineRacks", "Wind Racks");}); //Sets up Toggling hide / show for Wine Racks
	$('#expand_valances_tag').click(function(){toggling ("#expand_valances", "Valances");}); //Sets up Toggling hide / show for Valances
	$('#expand_squareedge_tag').click(function(){toggling ("#expand_squareedge", "Square Edge Doors");}); //Sets up Toggling hide / show for Slab Fillers
	$('#expand_squareedgemin_tag').click(function(){toggling ("#expand_squareedgemin", "Square Edge Doors");}); //Sets up Toggling hide / show for Slab Fillers
	$('#expand_pilasters_tag').click(function(){toggling ("#expand_pilasters", "Filuted Pilasters");}); //Sets up Toggling hide / show for Fluted Pilasters
	$('#expand_thermofoil_tag').click(function(){toggling ("#expand_thermofoil", "Thermofoil");}); //Sets up Toggling hide / show for Thermofoil
	$('#expand_rosettes_tag').click(function(){toggling ("#expand_rosettes", "Rosettes");}); //Sets up Toggling hide / show for Rosettes
	$('#expand_laminate_tag').click(function(){toggling ("#expand_laminate", "Laminate");}); //Sets up Toggling hide / show for Laminate
});
function hideContent(){
	$(".hideColorView").hide();	// Hide the door colors
	$(".glazeView").hide(); 	// Hide the Glaze Colors
	$(".hideView").hide();		// Hide the units, back and Finger Pull
	$("#expand_doors").hide();	// Hide Door Styles
	$("#expand_drawers").hide();	// Hide Drawer Styles
	$("#expand_mullion").hide();	// Hide Mullion Doors
	$('#expand_slabfillers').hide();	// Hide Slab Fillers
	$('#expand_slabfillersmin').hide();	// Hide Slab Fillers
	$('#expand_molding').hide();	// Hide Molding
	$('#expand_appPanels').hide();	// Hide Application Panels
	$('#expand_panelOP').hide();	// Hide Panel Over Panel
	$('#expand_wineRacks').hide();	// Hide Wine Racks
	$('#expand_valances').hide();	// Hide Valances
	$('#expand_squareedge').hide();	// Hide Square Edge Doors
	$('#expand_squareedgemin').hide();	// Hide Square Edge Doors
	$('#expand_pilasters').hide();	// Hide Fluted Pilasters
	$('#expand_thermofoil').hide();	// Hide Thermofoil
	$('#expand_rosettes').hide();	// Hide Rosettes
	$('#expand_laminate').hide();	// Hide Laminate
}
function datePhoneMask(){
	/* Below adds an input mask to the date and phone number */
	$("#Date").mask("99/99/9999");
	$("#Phone_Number").mask("(999) 999-9999");
	/*Add the Date into the Date box */
	var d=new Date();
	var dateString = (d.getMonth()+1) + " / " + d.getDate() + " / " + d.getFullYear();
	$("#Date").val(dateString);
}
function populateDatabase(){
	/* Load initial Door Designs and Colors */
	$.post(	"../ajax/loadForm.php",{
		item:"designColor"}, 
		function(msg){buildDoorDesign(msg); 
			},"json");
}
function buildDoorDesign(msg){
	var options;
	database = msg;

	//loop through all items in the JSON array  
	for (var x = 0; x < database.design.length; x++) {  
		options += '<option value="' + database.design[x].descode + '">' + database.design[x].desname + '</option>';
	 }  
	$("#Door_Design").append(options); 
}
function buildColor(doorDesignCode){
	var colcode = '';

	for (var x = 0; x < database.descolxref.length; x++) {
		if (doorDesignCode == database.descolxref[x].descode){
			colcode += database.descolxref[x].colcode;
		}
	}
	
	optionmatte = '<optgroup label="Solid Matte:">';
	optionsatin = '<optgroup label="Gloss and Satin:">';
	optionwood = '<optgroup label="Wood Grain:">';

	for (var x = 0; x < database.color.length; x++) {  
		if (colcode.match(database.color[x].colcode)){
			if ( database.color[x].matteSatinWood == "matte" ){
				optionmatte += '<option value="' + database.color[x].colcode + '">' + database.color[x].colname + '</option>';
			} else if ( database.color[x].matteSatinWood == "satin" ){
				 optionsatin += '<option value="' + database.color[x].colcode + '">' + database.color[x].colname + '</option>';
			} else {
				 optionwood += '<option value="' + database.color[x].colcode + '">' + database.color[x].colname + '</option>';
			}
		}
	}
	optionmatte += '</optgroup>';
	optionsatin += '</optgroup>';
	optionwood += '</optgroup>';
	
	colorOptions = optionmatte + optionsatin + optionwood;
	
	$("#Color").append(colorOptions); 
}

function grainColorBack (colrback, grain){
	if (colrback == 0){
		$("#matchback").empty().append('<option value="White_Back" selected="selected">White Back</option>');
	} else {
		var matchbackOptions =	'<option value="White_Back" selected="selected">White Back</option>';
		matchbackOptions +=	'<option value="Matched_Back">Matched Back</option>';
		$("#matchback").empty().append(matchbackOptions);

	}
	if (grain == 0){
		$("#grain").hide();
	} else {
		var grainOptions = '<option value="" selected="selected">Choose Grain...</option>';
		grainOptions += '<option value="Horizontal">Horizontal</option>';
		grainOptions += '<option value="Vertical">Vertical</option>';
		$("#grain").empty().append(grainOptions);
	}
}
function checkEdges(doorDesignName){
	shaker =  doorDesignName.match("Shaker");
	$(".edgesFull").show();
	$(".edgesMin").hide();
	if (doorDesignName == "Gulfstream" || doorDesignName.match("Shaker") == "Shaker"){
		$(".edgesFull").hide();
		$(".edgesMin").show();
	}
}
function checkGlaze(doorDesignName, colorCode){
	if (doorDesignName != ""){
		//  test if both Glazable
		for (var x = 0; x < database.design.length; x++) {  
			if ( doorDesignName == database.design[x].desname ){
				var glazeDesign = database.design[x].glazable;
				break;
			}
		 }
		for (var x = 0; x < database.color.length; x++) {  
			if ( colorCode == database.color[x].colcode ){
				var grain = database.color[x].grain;
				var colrback = database.color[x].colrback;
				var glazeColor = database.color[x].glazable;
				break;
			}
		 }
		
		grainColorBack (colrback, grain); 	//This is a function to change grain 
											//direction or colorback depends on Color
		if (glazeDesign == 1 && glazeColor == 1) {
			$(".glazeView").show();
		 }else{
			$(".glazeView").hide();
		}
	}
}
function buildDoorStyle(doorDesignCode){
	var options = '';
	var desdoorstyle = '';
	
	for (var x = 0; x < database.desdoorxref.length; x++) {
		if (doorDesignCode == database.desdoorxref[x].descode){
			desdoorstyle += database.desdoorxref[x].desdoorstyle + ",";
		}
	}
	for (var x = 0; x < database.doorstyle.length; x++) {
		if (desdoorstyle.match(database.doorstyle[x].doorstylecode)){
			options += '<option value="' + database.doorstyle[x].doorstylename + '">' + database.doorstyle[x].doorstylename + '</option>';
		}
	}
	$(".doorstyle").append(options);
}
function buildDrawStyle(doorDesignCode){
	var options = '';
	var drawstyle = '';
	
	for (var x = 0; x < database.desdrawxref.length; x++) {
		if (doorDesignCode == database.desdrawxref[x].descode){
			drawstyle += database.desdrawxref[x].drawstyle + ",";
		}
	}
	for (var x = 0; x < database.drawstyle.length; x++) {
		if (drawstyle.match(database.drawstyle[x].drawstylecode)){
			options += '<option value="' + database.drawstyle[x].drawstylename + '">' + database.drawstyle[x].drawstylename + '</option>';
		}
	}
	$(".drawerstyle").append(options);
}
function toggling (id, label){
	$(id).toggle('fast');
	
  	if ($(id + "_tag").text().match("[+]"))
  	{$(id + "_tag").text("[-]" + label);
  	} else {$(id + "_tag").text("[+]" + label);	} 
}
function validations(){
	$("#orderform").validate({	
		rules: {
			Company_ID: {required: true, alphanumeric: true, minlength: 3},
			Customer_Number: {required: true, alphanumeric: true, minlength: 3},
			PO_Number: {required: true},
			Door_Style1_Style: { required: function(element) {return $("#Door_Style1_1_Quantity").val() != "";}	},
			Door_Style1_1_Quantity: {required: function(element) {return $("#Door_Style1_Style").val() != "";}	},
			Door_Style1_1_Width: {required: function(element) {	return $("#Door_Style1_Style").val() != "";	},max: 47},
			Door_Style1_1_Height: {	required: function(element) {return $("#Door_Style1_Style").val() != "";},max: 96}, 
			Phone_Number: {	required: true, phoneUS: true},
			Email: {required: false, email: true}
		}
	});
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
		phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/);
	}, "Please specify a valid phone number");
	
	jQuery.validator.addMethod("alphanumeric", function(value, element) {
		return this.optional(element) || /^([a-z0-9]+)$/i.test(value);
	}, "Letters, numbers only please"); 
	
	jQuery.validator.addMethod("d1type", function(value, element) {
		return this.optional(element) || /^([a-z0-9]+)$/i.test(value);
	}, "Letters, numbers only please"); 
}
function unitsValidations(){
	var units = $("#units").val();
	if (units == "metric"){
		wd_max = 914.4;
		ht_max = 2438.4;
	} else {
		wd_max = 47;
		ht_max = 96;
	}
	$(".wd_max").each(function () {
		$(this).rules("remove"); 
		$(this).rules("add", {	max: wd_max }); 
	});
	$(".ht_max").each(function () {
		$(this).rules("remove");
		$(this).rules("add", {	max: ht_max });
	});
}

function d1typeValidations(){
	
	$(".d1type_check").each(function () {
		$(this).rules("remove"); 
		$(this).rules("add", {	max: 99 }); 
	});
}

function confirmSubmit1()
{
	var z = 0
	var x = 0
	var y = 0
	var $i = 0
	
	if ((document.getElementById("Door_Style1_Style").selectedIndex) != 0 ) {	    		
		z=document.getElementById("Door_Style1_Style").selectedIndex;
    	y=(document.getElementById("Door_Style1_Style").options);		
   	}	
	$i=1
	while (document.getElementById(["Door_Style1_"+ $i + "_Quantity"]) != null) {	
		x=(document.getElementById("Door_Style1_" + $i + "_Quantity"));
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Door_Style1 Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "" && x.value != 0)) && (z == 0) ) {
			alert("Please select Door Style1 Style.");
			return false;
	    }
	    $i=++$i   
	 }
	
	z=0;
	if ((document.getElementById("Door_Style2_Style").selectedIndex) != 0 ) {	    		
		z=document.getElementById("Door_Style2_Style").selectedIndex;
    	y=(document.getElementById("Door_Style2_Style").options);		
   	}	
	$i=1
	while (document.getElementById(["Door_Style2_"+ $i + "_Quantity"]) != null) {	
		x=(document.getElementById("Door_Style2_" + $i + "_Quantity"));
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Door_Style2 Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "" && x.value != 0)) && (z == 0) ) {
			alert("Please select Door Style2 Style.");
			return false;
	    }
	    $i=++$i   
	 }
/*	alert("1");*/
	z=0;
	if ((document.getElementById("Drawer_Style1_Type").selectedIndex) != 0 ) {	    		
		z=document.getElementById("Drawer_Style1_Type").selectedIndex;
    	y=(document.getElementById("Drawer_Style1_Type").options);		
   	}	
	$i=1
	while (document.getElementById(["Drawer_Style1_"+ $i + "_Quantity"]) != null) {	
		x=(document.getElementById("Drawer_Style1_" + $i + "_Quantity"));
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Drawer Style1 Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "" && x.value != 0)) && (z == 0) ) {
			alert("Please select Drawer Style1 Type.");
			return false;
	    }
	    $i=++$i   
	 }
	
	/*	alert("1");*/
	z=0;
	if ((document.getElementById("Drawer_Style2_Type").selectedIndex) != 0 ) {	    		
		z=document.getElementById("Drawer_Style2_Type").selectedIndex;
    	y=(document.getElementById("Drawer_Style2_Type").options);		
   	}	
	$i=1
	while (document.getElementById(["Drawer_Style2_"+ $i + "_Quantity"]) != null) {	
		x=(document.getElementById("Drawer_Style2_" + $i + "_Quantity"));
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Drawer Style2 Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "" && x.value != 0)) && (z == 0) ) {
			alert("Please select Drawer Style2 Type.");
			return false;
	    }
	    $i=++$i   
	 }
		
	x = 0
	$i= 1
	while (document.getElementById(["Molding_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Molding_" + $i + "_Quantity"));
		/*alert(document.getElementById("Molding_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Molding_" + $i + "_Type").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Molding_" + $i + "_Type").selectedIndex;
	    	y=(document.getElementById("Molding_" + $i + "_Type").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Molding qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Molding Type.");
			return false;
	    }
	    $i=++$i   
	 }
	
	x = 0
	$i= 1
	while (document.getElementById(["Mullion_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Mullion_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Mullion_" + $i + "_Type").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Mullion_" + $i + "_Type").selectedIndex;
	    	y=(document.getElementById("Mullion_" + $i + "_Type").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Mullion qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Mullion Type.");
			return false;
	    }
	    $i=++$i   
	 }
	/*alert("app");*/
	x = 0
	$i= 1
	while (document.getElementById(["Appliance_Panel_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Appliance_Panel_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Appliance_Panel_" + $i + "_Style").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Appliance_Panel_" + $i + "_Style").selectedIndex;
	    	y=(document.getElementById("Appliance_Panel_" + $i + "_Style").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Appliance_Panel Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Appliance Panel Style.");
			return false;
	    }
	    $i=++$i   
	 }
	/*alert("Panel_Over_Panel");*/
	x = 0
	$i= 1
	while (document.getElementById(["Panel_Over_Panel_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Panel_Over_Panel_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Panel_Over_Panel_" + $i + "_Type").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Panel_Over_Panel_" + $i + "_Type").selectedIndex;
	    	y=(document.getElementById("Panel_Over_Panel_" + $i + "_Type").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Panel Over Panel Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Panel Over Panel Type.");
			return false;
	    }
	    $i=++$i   
	 }
	
	/*alert("Slab Filler");*/
	x = 0
	$i= 1
	while (document.getElementById(["Slab_Filler_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Slab_Filler_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Slab_Filler_" + $i + "_Type").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Slab_Filler_" + $i + "_Type").selectedIndex;
	    	y=(document.getElementById("Slab_Filler_" + $i + "_Type").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Slab Filler Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Slab Filler Type.");
			return false;
	    }
	    $i=++$i   
	 }
	
	/*alert("Wine Racks");*/
	x = 0
	$i= 1
	while (document.getElementById(["Wine_Racks_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Wine_Racks_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Wine_Racks_" + $i + "_Edge").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Wine_Racks_" + $i + "_Edge").selectedIndex;
	    	y=(document.getElementById("Wine_Racks_" + $i + "_Edge").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Wine Racks Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Wine Racks Edge.");
			return false;
	    }
	    $i=++$i   
	 }
	
	/*alert("Valance");*/
	x = 0
	$i= 1
	while (document.getElementById(["Valances_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Valances_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex);
		alert( x.value ); */  
    	if ((document.getElementById("Valances_" + $i + "_Type").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Valances_" + $i + "_Type").selectedIndex;
	    	y=(document.getElementById("Valances_" + $i + "_Type").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Valances Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Valances Type.");
			return false;
	    }
	    $i=++$i   
	 }
	
	/*alert("Square_Edge_Doors");*/ 
	x = 0
	$i= 1
	
	while (document.getElementById(["Square_Edge_Doors_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Square_Edge_Doors_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex); */
		/*alert( x.value );*/  
    	if ((document.getElementById("Square_Edge_Doors_" + $i + "_Edge").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Square_Edge_Doors_" + $i + "_Edge").selectedIndex;
	    	y=(document.getElementById("Square_Edge_Doors_" + $i + "_Edge").options);		
			/*alert( z ); z defaults to 1 for square edge doors .. groan*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 1) ) {
				alert("Square Edge Doors Qty is Empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Square Edge Doors Edge.");
			return false;
	    }
	    $i=++$i   
	 }

	/*alert("Fluted_Pilasters");*/ 
	x = 0
	$i= 1
	while (document.getElementById(["Fluted_Pilasters_"+ $i + "_Quantity"]) != null) {	
	    z = 0;
		x=(document.getElementById("Fluted_Pilasters_" + $i + "_Quantity"));
		/*alert(document.getElementById("Mullion_" + $i + "_Type").selectedIndex); */
		/*alert( x.value );  */
    	if ((document.getElementById("Fluted_Pilasters_" + $i + "_Edge").selectedIndex) != 0 ) {	    		
    		z=document.getElementById("Fluted_Pilasters_" + $i + "_Edge").selectedIndex;
	    	y=(document.getElementById("Fluted_Pilasters_" + $i + "_Edge").options);		
			/*alert( y[z].text );*/
       	}	
    	if (((x.value==null || x.value=="")) && (z != 0) ) {
				alert("Flutes Qty is empty. Enter 0 for none.");
				return false;
		}
    	if (((x.value != null && x.value != "")) && (z == 0) ) {
			alert("Please select Flutes Edge.");
			return false;
	    }
	    $i=++$i   
	 }
	
	return true;
}


function disableEnterKey(e) {
	   var key;     
	   if (window.event)
	        key == window.event.keyCode; 
	    else 
	        key == e.which;       
	   return (key != 13);
	}



