var pricekk = new Array()
var pricefin = new Array()
var glass = new Array(483,606,698,698,926,926,926,926,1218,1218,1218,1218);
var glass2 = new Array(120,243,335,335,563,563,563,563,855,855,855,855);
var glass3 = new Array(0,123,215,215,443,443,443,443,735,735,735,735);
var glass4 = new Array(515,638,730,730,958,958,958,958,1250,1250,1250,1250);
var glass5 = new Array(544,667,759,759,987,987,987,987,1279,1279,1279,1279);
var glass6 = new Array(178,301,393,393,621,621,621,621,913,913,913,913);
var glass7 = new Array(44,167,259,259,487,487,487,487,779,779,779,779);
var glass8 = new Array(620,743,835,835,1063,1063,1063,1063,1355,1355,1355,1355);


var gold= new Array(0,144,564,564,564,564,732,732,732,732,732,732);
var gold2= new Array(0,125,414,414,414,414,562,562,562,562,562,562);
var gold3= new Array(0,107,228,228,228,228,499,499,499,499,499,499,499,499);
var gold4= new Array(0,129,584,584,584,584,792,792,792,792,792,792);
var gold5= new Array(0,193,593,593,593,593,767,767,767,767,767,767);
var gold6= new Array(0,131,439,439,439,439,601,601,601,601,601,601);
var gold7= new Array(0,122,249,249,249,249,508,508,508,508,508,508);
var gold8= new Array(0,130,530,530,530,530,752,752,752,752,752,752);

pricekk[1]= new Array("20-36, cust",glass3 , glass4)         
pricekk[2] = new Array ( "20-36 cust ", glass)
pricekk[3]= new Array("20-36, cust",glass2)         
pricekk[4] = new Array ( "20-36 cust ", glass7, glass8)
pricekk[5] = new Array ( "20-36 cust ", glass5)
pricekk[6] = new Array ( "20-36 cust ", glass6)




//pricekk [4] =new Array ("20-36,cust", glasscust4, glasscust4)

pricefin[1]= new Array("20-36, cust",gold3 , gold4)         
pricefin[2] = new Array ( "20-36 cust ", gold)
pricefin[3]= new Array("20-36, cust",gold2)         
pricefin[4] = new Array ( "20-36 cust ", gold7, gold7)
pricefin[5]= new Array("20-36, cust",gold5) 
pricefin[6]= new Array("20-36, cust",gold6) 

//pricefin [4] =new Array ("20-36,cus", gold5, gold4,gold5,gold4)
// 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){
//alert(e.length);
	document.getElementById("newinp").innerHTML = '<input name="vwattr0_Width Door (Front) Side" id="NewW0" type="hidden" value=""><input name="vwattr0_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;
		//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 Width 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='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;
//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 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('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 (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 ('vwattr0_Custom Door Height',option_name_top2,option_value_top2, st, ls,"CustomHe");
CreateDD('vwattr0_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-tub-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('vwattr0_Width Door Side  Inch', option_name_top, option_value_top, 0,40, "CustomW1In" );
CreateDD('vwattr0_Width Door Side Quad', option_name_top3, option_value_top3, 0,15, "CustomW1Qu" );
CreateDD('vwattr0_Width Panel Side Inch', option_name_top, option_value_top, 0,28, "CustomW2In" );
CreateDD('vwattr0_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('vwattr0_Door Width Top Inch', option_name_top, option_value_top, 0,40, "CustomW1In" );
CreateDD('vwattr0_Door Width Top Quad', option_name_top, option_value_top, 41,56, "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,56, "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,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["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();

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 Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Frameless 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 3401]');
selbox.options[selbox.options.length] = new Option('Infinity 1/4" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 4401]');
}

if (chosen == '2') {
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
//selbox.options[selbox.options.length] = new Option('Deluxe 3/16" Enclosure Door Side up to 60", Panel - to 24"','Door Side up to 60", panel - to 24" Finished Opening Required [Model : 6153]');

selbox.options[selbox.options.length] = new Option('Supreme 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 2151]');
//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 Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Deluxe 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 6151]');
//selbox.options[selbox.options.length] = new Option('Supreme 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 2151]');
//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 == '4') { 
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Frameless 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 3501]');
selbox.options[selbox.options.length] = new Option('Infinity 1/4" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 4501]');
}
//creating custom height for shower
//test(1);
if (chosen == '5') { 
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Supreme 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 3151]');

}
if (chosen == '6') { 
selbox.options[selbox.options.length] = new Option('Choose Your Door Width and Type','None');
selbox.options[selbox.options.length] = new Option('Deluxe 3/16" Enclosure Door Side up to 60", Panel - to 40"','Door Side up to 60", panel - to 40" Finished Opening Required [Model : 7151]');

}

ModifyOptions();
}