var pricekk = new Array()
var pricefin = new Array()
var glass = new Array(0,146,146,138,138,138,138,469,469,469,469);
var glass2 = new Array(248,248,400,400,368,368,368,368,723,723,723,723);
var glasscust = new Array (317,463,463,455,455,455,455,786,786,786,786) ;
var glasscust2 = new Array (419,500,653,653,622,622,622,622,975,975,975,975); 
var gold= new Array(0,179,419,419,419,419,520,520,520,520,520,520);
var gold2= new Array(0,95,507,507,507,507,625,625,625,625,625,625);
pricekk[1]= new Array("20-36, cust",glass, glasscust)         
pricekk[2] = new Array ( "20-36 cust ", glass2, glasscust)
pricekk[3] = new Array ("20-36,cus", glasscust, glasscust, glasscust,glasscust)
pricefin[1]= new Array("20-36,cus", gold, gold , gold, gold )         
pricefin[2] = new Array ( "20-36, cus" , gold2, gold2, gold, gold, gold )
pricefin [3] =new Array ("20-36,cus", gold, gold, gold2, gold2, gold )
// concatanates WIDTH  value of 2 dropdowns delete dropdownd and create hidden input fields to transfer information to the cart
function concatanateOptions(){
// check if it's for overlap or for custom width;
	e1=document.getElementById("newoptoverlap").getElementsByTagName("select")
//if it's custom Width or exact overlap
	e2=document.getElementById("newopt1").getElementsByTagName("select");
	if (e2.length==0)
		{e=e1}
		else
		{e=e2}
	if (e.length>0){
	document.getElementById("newinp").innerHTML = '<input name="Width Door (Front) Side" id="NewW0" type="hidden" value=""><input name="Width Panel Side" id="NewW2" type=hidden>';
		var cartValue;
		var u;
// collecting values from drop down;
		for (i=0; i<=2 ; i=i+2){
			var myindex  = e[i].selectedIndex;
			var myindex2  = e[i+1].selectedIndex;
			var SelValue = e[i].options[myindex].value;
			var SelValue2 = e[i+1].options[myindex2].value;
			cartValue = SelValue +' '+ SelValue2 + '/16 Inches';
 			var t = i;
			var t2=(i+2)/2
 			var par = 'NewW' + t;
 			par2 = 'CustomW' + t2 + 'In';
//trasfering to cart
			document.getElementById(par).value=cartValue;
		}
// removing all other values
	document.getElementById("CustomW1Qu").innerHTML='';
	document.getElementById("CustomW2Qu").innerHTML='';
//	document.getElementById("CustomW3Qu").innerHTML='';
// replace dropdowns with other options
	removeOpt();
	}
}

function concatanateOptionsHeight(){
// check if it's for overlap or for custom width;
	e=document.getElementById("customw").getElementsByTagName("select")
	if (e.length > 0){
//if it's custom Width or exact overlap
	var cartValue;
// collecting values from drop down;
	var myindex  = e[0].selectedIndex;
	var myindex2  = e[1].selectedIndex;
	var SelValue = e[0].options[myindex].value;
	var SelValue2 = e[1].options[myindex2].value;
	cartValue = SelValue +' '+ SelValue2 + '/16 Inches';
//trasfering to cart
	document.getElementById("CusHeight").innerHTML = '<input name="Custom Height" id="NewHei" type="hidden" value="">';
	document.getElementById("NewHei").value=cartValue;
// removing all other values
document.getElementById("customw").innerHTML='';
// replace dropdowns with other options
}
}
function removeOpt(){
//replacing html for dropdowns with selected values
document.getElementById("CustomW1In").innerHTML='Door Side Width' + document.getElementById("NewW0").value;
document.getElementById("CustomW2In").innerHTML='Panel Side Width ' + document.getElementById("NewW2").value;
//document.getElementById("CustomW3In").innerHTML='Custom Width Bottom ' + document.getElementById("NewW4").value;
//document.getElementById("newopt").innerHTML='<table><tr><td rowspan=3><img src=http://site.bathroom-glass-vanities.com/images/multi/custom-mes-bascto.gif></td><td><span id="NewW1Text"></span><br><span id="CustomW1In"></span><span id="CustomW1Qu"></span></td></tr><tr><td><span id="NewW2Text"></span><br><span id="CustomW2In"></span><span id="CustomW2Qu"></span></td></tr><tr><td><span id="NewW3Text"></span><br><span id="CustomW3In"></span><span id="CustomW3Qu"></span></td></tr></table>';
//CustomW1In
}
//option creation
var ott = new Array (1,2,3,4,4,5,5);
//filler test - calling by anychanges of created select-boxes
function FillerTest (){
var e3;
// if filler is for overlap or for custom shower;
e1=document.getElementById("newoptoverlap").getElementsByTagName("select")
e2=document.getElementById("newopt1").getElementsByTagName("select");
if (e2.length==0){e3=e1}else{e3=e2}
if (e3.length > 0){
for (i=0; i< e3.length ; i++){
	var myindex3  = e3[i].selectedIndex;
	var vv=e3[i].options[myindex3].value;
//need to store all info in array 
	ott[i]=vv;
	}
 var k = Math.max(ott[0], ott[2],ott[4])
  var kk = Math.min(ott[0], ott[2],ott[4])
var k1 = Math.max(ott[1], ott[3],ott[5])
  var kk1 = Math.min(ott[1], ott[3],ott[5])
// if any difference in values than we need filler
if (kk-k==0 && kk1-k1==0){
removeFiller();} else {createFiller();}
}
}
function removeFiller(){
document.getElementById("filler").innerHTML='';
}
var fillerlist = new Array ("Filler is not required", "Filler required (+$100)");
var filervalue = new Array ("Filler is not required", "Filler required (+$100)");
function createFiller(){
if (document.getElementById("filler").innerHTML=='')
	{
	    document.getElementById("filler").innerHTML='<p class="shortbr3">Add Filler<span class="smalldesc"> When walls are out of level beyond 3/8&quot; tapered filler for proper fit is required</span></p><span id="fillerDrop"></span>';
		CreateDD('Add Filler', fillerlist, filervalue, 0,1, "fillerDrop" );
	}
}
//put overlap selection back to page
function RestoreOverlap(){
if (document.getElementById("overlap")!=null){
//var vv = document.getElementById("overlap").innerHTML;
// checking if it's on the page already
if (document.getElementById("overlap").innerHTML !=''){} 
// if no - put it back;
else
{//if (document.getElementById("overlap")==null){ alert('reds');
document.getElementById("overlap").innerHTML=over;
}
}
}
//creating custom Height selector
function test(a) {
//deleting previous 
document.getElementById("customw").innerHTML='';
 var option_name_top2 = new Array (66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84);
 var option_value_top2 = new Array (66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84);
// if tub or shower - height of the door is different
 if (a==1){var st=0; var ls =18 } else {var st = 7; var ls = 22; }
document.getElementById("customw").innerHTML='<p class="shortbr3"> Select Custom Height of Your Door <span class="smalldesc"> from ' + option_name_top2[st] + ' Inches up to ' + option_name_top2[ls] + '</span></p><span id="CustomHe"></span> <span id="CustomHeQu"></span>';
CreateDD ('Custom Door Height',option_name_top2,option_value_top2, st, ls,"CustomHe");
CreateDD('Custom Door Height Quad', option_name_top3, option_value_top3, 0,15,"CustomHeQu");
}
 var option_name_top3 = new Array (0,'1/16','1/8','3/16','1/4','5/16','3/8','7/16','1/2','9/16','5/8','11/16','3/4','13/16','7/8','15/16');
var option_value_top3 = new Array (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
var option_name_top = new Array (20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72);
var option_value_top = new Array (20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72);
//option creation
function CreateDD(name, valuename, valuelist, start,end, parentelementID)
{
	var combo_box;
	var choice;
	combo_box = document.createElement('SELECT');
	combo_box.name = name;
	// all created dropdowns (3 width ) have onchange event = filler test
	if (combo_box.name != 'Add Filler' && combo_box.name != 'Custom Door Height' && combo_box.name != 'Custom Door Height Quad' ){
	combo_box.onchange=function(){FillerTest();
	};
	}
	if (combo_box.name == 'Add Filler'){
	combo_box.onchange=function(){updatePrice2(this.form,this);
	};
	}
	for(j=start; j <= end; j++)
		{
			 choice = document.createElement('option');
			  choice.value = valuelist[j];
			  choice.appendChild(document.createTextNode(valuename[j]));
			combo_box.appendChild(choice);
		}
	document.getElementById(parentelementID).appendChild(combo_box);
}
// creating combo boxes for custom width 
function cWidth(){
//creating spot for new options
document.getElementById("newopt1").innerHTML='<table><tr><td rowspan=3><img src=http://site.bathroom-glass-vanities.com/images/multi/basco-enclosure-mes.jpg></td><td><span id="NewW1Text"><p class="shortbr3">Door (Front) Width* <span class="smalldesc"><br>(Including Front Panel)</span> </p></span><span id="CustomW1In"></span><span id="CustomW1Qu"></span></td></tr><tr><td><span id="NewW2Text"><p class="shortbr3">Panel Side Width</p></span><span id="CustomW2In"></span><span id="CustomW2Qu"></span></td></tr></table>';
//document.getElementById("CustomHeithText").innerHTML='Choose Custom Height';
CreateDD('Width Door Side  Inch', option_name_top, option_value_top, 0,40, "CustomW1In" );
CreateDD('Width Door Side Quad', option_name_top3, option_value_top3, 0,15, "CustomW1Qu" );
CreateDD('Width Panel Side Inch', option_name_top, option_value_top, 0,28, "CustomW2In" );
CreateDD('Width Panel Side Quad',option_name_top3, option_value_top3, 0,15, "CustomW2Qu" );
//CreateDD('Custom Width Bottom Inch', option_name_top, option_value_top, 0,40, "CustomW3In" );
//CreateDD('Custom Width Bottom Quad',option_name_top3, option_value_top3, 0,15, "CustomW3Qu" );
//remove overlap from the page as custom width is always assume exact overlap;
var el =document.getElementById("overlap");
if (el != null){
 //alert(el);
 document.getElementById("overlap").innerHTML="";
 }
}
//creating width options for exact overlap
function customWidthForOverlap(){
//creating spot for new options
document.getElementById("newoptoverlap").innerHTML='<table><tr><td rowspan=3><img src=http://site.bathroom-glass-vanities.com/images/multi/custom-mes-overlap-bascto.gif></td><td><span id="NewW1Text"></span><br><span id="CustomW1In"></span><span id="CustomW1Qu"></span></td></tr><tr><td><span id="NewW2Text"></span><br><span id="CustomW2In"></span><span id="CustomW2Qu"></span></td></tr><tr><td><span id="NewW3Text"></span><br><span id="CustomW3In"></span><span id="CustomW3Qu"></span></td></tr></table>';
// creating 6 dropdowns
CreateDD('Door Width Top Inch', option_name_top, option_value_top, 0,40, "CustomW1In" );
CreateDD('Door Width Top Quad', option_name_top, option_value_top, 41,56, "CustomW1Qu" );
CreateDD('Door Width Middle Inch', option_name_top, option_value_top, 0,40, "CustomW2In" );
CreateDD('Door Width Middle Quad', option_name_top, option_value_top, 41,56, "CustomW2Qu" );
CreateDD('Door Width Bottom Inch', option_name_top, option_value_top, 0,40, "CustomW3In" );
CreateDD('Door Width Bottom Quad', option_name_top, option_value_top, 41,56, "CustomW3Qu" );
}
// removing elements
 function removeElement() {
var el =document.getElementById("CustomHe");
  var el2 =document.getElementById("newopt1");
   var el3 =document.getElementById("CustomMid");
 if (el != null){
 var tub_show = document.forms[0].elements["Door_Height"].selectedIndex;
//removing custom height fields if custom height is not chosen or was changed to other value
if (tub_show < 6){
document.getElementById("customw").innerHTML="";
}
}
  if (el3 != null){
 document.getElementById("CustomMid").innerHTML="";
 }
  if (el2 != null){
 document.getElementById("newopt1").innerHTML="";
 }
//el.parentNode.removeChild(el);
}
function setOptions(chosen) {
removeElement();
var selbox = document.f1.Door_Width;
selbox.options.length = 0;
if (chosen == ' ') {
selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
}
if (chosen == '1') {
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Frameless Enclosure door up to 60", panel - to 48"','Frameless 60"x48" Finished Opening Required [Model : 1415]');
selbox.options[selbox.options.length] = new Option('Custom Frameless Enclosure','Custom Frameless Enclosure [Model : 1415CUS]');
}
if (chosen == '2') { 
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Frameless Enclosure door up to 60", panel - to 48"','Frameless 60"x48" Finished Opening Required [Model : 1715]');
selbox.options[selbox.options.length] = new Option('Custom Frameless Enclosure','Custom Frameless Enclosure [Model : 1715CUS]');
}
if (chosen == '3') { 
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Frameless Enclosure door up to 60", panel - to 48"','Frameless 60"x48" Finished Opening Required [Model : 1715CUS]');
selbox.options[selbox.options.length] = new Option('Custom Frameless Enclosure','Custom Frameless Enclosure [Model : 1715CUS-CUS]');
test(1); 
}
//replacing prices according to selection
ModifyOptions();
}