var pricekk = new Array()
var pricefin = new Array()
var glass = new Array(0,24,93,93,218,218,218,218,239,239,239,239);
var glass2 = new Array(209,221,221,'non',296,296,296,296,332,332,332,332);
var glass3 = new Array(321,331,331,'non',407,407,407,407,444,444,444,444);
var glasscust = new Array (211,235,304,304,429,429,429,429,450,450,450,450);
var glasscust2 = new Array (211,235,304,304,429,429,429,429,450,450,450,450) ;

var gold= new Array(0,110,315,315,315,315,425,425,425,425,425,425);
var gold2= new Array(0,83,133,133,133,133,197,197,197,197,197,197);
var gold3= new Array(0,37,'k','j','j','k','j','j','k','j','j','k','j','j','k','j','j','k','j','j');


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",  glass3,  glass2 , glasscust )
pricekk [4] =new Array ("20-36,cust", glasscust,  glasscust)


pricefin[1]= new Array("20-36,cus", gold, gold )         
pricefin[2] = new Array ( "20-36, cus" , gold2, gold2)
pricefin [3] =new Array ("20-36,cus", gold3, gold)
pricefin [4] =new Array ("20-36,cus", gold, 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 widht or exact overlap
	e2=document.getElementById("newopt1").getElementsByTagName("select");
	if (e2.length==0)
		{e=e1}
		else
		{e=e2}
	if (e.length>0){
//alert(e.length);
	document.getElementById("newinp").innerHTML = '<input name="vwattr0_Width Top" id="NewW0" type="hidden" value=""><input name="vwattr0_Width Middle" id="NewW2" type=hidden><input name="vwattr0_Widht Bottom" id="NewW4" type=hidden>';

		var cartValue;
		var u;
// collecting values from drop down;
		for (i=0; i<=4 ; i=i+2){
		
			var myindex  = e[i].selectedIndex;
			var myindex2  = e[i+1].selectedIndex;
		//alert(i);
			var SelValue = e[i].options[myindex].value;
			var SelValue2 = e[i+1].options[myindex2].value;
		
			cartValue = SelValue +' '+ SelValue2 + '/16 Inches';
		//alert(cartValue);
 			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 widht or exact overlap
//alert(e.length);
	var cartValue;
// collecting values from drop down;
	var myindex  = e[0].selectedIndex;
	var myindex2  = e[1].selectedIndex;
	//alert(i);
	var SelValue = e[0].options[myindex].value;
	var SelValue2 = e[1].options[myindex2].value;
	cartValue = SelValue +' '+ SelValue2 + '/16 Inches';
		//alert(cartValue);
//trasfering to cart
	document.getElementById("CusHeight").innerHTML = '<input name="vwattr0_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='Custom Width Top ' + document.getElementById("NewW0").value;
document.getElementById("CustomW2In").innerHTML='Custom Width Middle ' + document.getElementById("NewW2").value;
document.getElementById("CustomW3In").innerHTML='Custom Width Bottom ' + document.getElementById("NewW4").value;
//alert('h');
//alert(document.getElementById("newopt"));
//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>';
//alert(document.getElementById("CustomW1Qu").innerHTML);
//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");
//alert (e2.length);

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;
	//alert(vv);
//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])
//alert(kk1);
// 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 required (+$100)", "Filler is not required");
var filervalue = new Array ("Filler required (+$100)", "Filler is not required");

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('vwattr0_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 (56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,0);
 var option_value_top2 = new Array (56,57,58,59,60,61,62,63,64,65,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 =24 } else {var st = 0; var ls = 28; }
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 ('vwattr0_Custom Door Height',option_name_top2,option_value_top2, st, ls,"CustomHe");
CreateDD('vwattr0_Custom Door Height Quad', option_name_top, option_value_top, 17,32,"CustomHeQu");

}

var option_name_top = new Array (20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,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_top = new Array (20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);

//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 != 'vwattr0_Add Filler' && combo_box.name != 'vwattr0_Custom Door Height' && combo_box.name != 'vwattr0_Custom Door Height Quad' ){
	combo_box.onchange=function(){FillerTest();
	};
	}
	
	if (combo_box.name == 'vwattr0_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/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>';
//document.getElementById("CustomHeithText").innerHTML='Choose Custom Height';
CreateDD('vwattr0_Custom Width Top Inch', option_name_top, option_value_top, 0,16, "CustomW1In" );
CreateDD('vwattr0_Custom Widht Top Quad', option_name_top, option_value_top, 17,32, "CustomW1Qu" );
CreateDD('vwattr0_Custom Width Middle Inch', option_name_top, option_value_top, 0,16, "CustomW2In" );
CreateDD('vwattr0_Custom Width Middle Quad', option_name_top, option_value_top, 17,32, "CustomW2Qu" );
CreateDD('vwattr0_Custom Width Bottom Inch', option_name_top, option_value_top, 0,16, "CustomW3In" );
CreateDD('vwattr0_Custom Width Bottom Quad', option_name_top, option_value_top, 17,32, "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 customWidhtForOverlap(){

//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('vwattr0_Door Width Top Inch', option_name_top, option_value_top, 0,40, "CustomW1In" );
CreateDD('vwattr0_Door Widht Top Quad', option_name_top, option_value_top, 40,54, "CustomW1Qu" );
CreateDD('vwattr0_Door Width Middle Inch', option_name_top, option_value_top, 0,40, "CustomW2In" );
CreateDD('vwattr0_Door Width Middle Quad', option_name_top, option_value_top, 41,54, "CustomW2Qu" );
CreateDD('vwattr0_Door Width Bottom Inch', option_name_top, option_value_top, 0,40, "CustomW3In" );
CreateDD('vwattr0_Door Width Bottom Quad', option_name_top, option_value_top, 41,54, "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["vwattr0_Door_Height"].selectedIndex;
//removing custom height fields if custom height is not chosen or was changed to other value
if (tub_show < 6){
//alert(el);

document.getElementById("customw").innerHTML="";

}

}
  if (el3 != null){
 //alert(el);
 document.getElementById("CustomMid").innerHTML="";
 }
  if (el2 != null){
 //alert(el);
 document.getElementById("newopt1").innerHTML="";
 
 }
 //alert(el);
//el.parentNode.removeChild(el);
//alert('removed');
//}
}


function setOptions(chosen) {
removeElement();
//alert(chosen)
var selbox = document.f1.vwattr0_Door_Width;
//var selbox2 = document.f1.optthree;
 
selbox.options.length = 0;
//selbox2.options.length = 0;
if (chosen == ' ') {
selbox.options[selbox.options.length] = new Option('Please select one of the options above first',' ');
//selbox2.options[selbox2.options.length] = new Option('Please select one of the options above first',' ');
}
if (chosen == '1') {
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 20"-36"','20"-36" Finished Opening Required [Model : 18CS]');
//selbox2.options[selbox2.options.length] = new Option('Tub Shower - option one A','oneoneA');
//selbox2.options[selbox2.options.length] = new Option('first choice - option two A','onetwoA');
test(1);
}
if (chosen == '2') {
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 20"-36"','20"-36" Finished Opening Required [Model : 18CS+400S]');
test(1)
//selbox2.options[selbox2.options.length] = new Option('second choice - option one A','twooneA');
//selbox2.options[selbox2.options.length] = new Option('second choice - option two A','twotwoA');
//selbox2.options[selbox2.options.length] = new Option('second choice - option three A','twothreeA');
}

if (chosen == '3') { 
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 20"-36"','20"-36" Finished Opening Required [Model : 18CS+400H]');
//creating custom height for shower
test(1)

}
if (chosen == '4') { 
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 20"-36"','20"-36" Finished Opening Required [Model : 18CS-CUS+400H]');
test(2)
//creating custom height for shower


}
if (chosen == '5') { 
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 38"-48"','38"-48" Finished Opening Required [Model : 3000]');
selbox.options[selbox.options.length] = new Option('Door - 49"-60"','49"-60" Finished Opening Required [Model : 3055]');
selbox.options[selbox.options.length] = new Option('Choose Custom Shower Door Width - [Model : 3000CUS]  ','Custom Width [Model : 3000CUS]');
//creating custom height for shower


}
if (chosen == '6') { 
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 38"-48"','38"-48" Finished Opening Required [Model : 3000CUS]');
selbox.options[selbox.options.length] = new Option('Door - 49"-60"','49"-60" Finished Opening Required [Model : 3055CUS]');
selbox.options[selbox.options.length] = new Option('Choose Custom Shower Door Width - [Model : 3000CUS]  ','Custom Width [Model : 3000CUS]');
//creating custom height for shower
test(1);

}
//replacing prices according to selection

ModifyOptions();

}