var pricekk = new Array();
var pricefin = new Array();
var glass = new Array(0,40,111,111,343,343,343,343,396,396,396,396,396);
var glass2 = new Array(76,113,187,187,376,376,376,376,431,431,431,431,431);
var glasscust = new Array (238,278,349,349,581,581,581,581,634,634,634,634,634) ;
var glasscust2 = new Array (238,278,349,349,581,581,581,581,634,634,634,634,634) ;

var gold= new Array(0,73,180,180,180,237,237,237,237,237,237,237);
var gold2= new Array(0,82,180,180,180,180,345,345,345,345,345,345,345);


pricekk[1]= new Array("20-36, cust", glass ,glasscust );         
pricekk[2] = new Array ( "20-36 cust ", glass ,glasscust);
pricekk [3] =new Array ("20-36,cus",  glass,  glass2 , glasscust );
pricekk [4] =new Array ("20-36,cust", glass,  glass2  ,glasscust);
pricekk [5] =new Array ("20-36,cust", glass,  glass2  ,glasscust);
pricekk [6] =new Array ("20-36,cust", glasscust,  glasscust2  ,glasscust2);


pricefin[1]= new Array("20-36,cus", gold, gold,gold2 );  
pricefin[2] = new Array ( "20-36, cus" , gold2, gold2,gold2);
pricefin [3] =new Array ("20-36,cus", gold, gold,gold2);
pricefin [4] =new Array ("20-36,cus", gold, gold,gold2);
pricefin [5] =new Array ("20-36,cus", gold2, gold2,gold2);
pricefin [6] =new Array ("20-36,cus", gold2, gold2,gold2);
// 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('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);
// if tub or shower - height of the door is different
 if (a==1){var st=0; var ls =24 } 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_top, option_value_top, 35,51,"CustomHeQu");

}
var option_name_top = new Array (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,67,70,71,72,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 (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,67,70,71,72,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
//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 != '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,22, "CustomW1In" );
CreateDD('vwattr0_Custom Widht Top Quad', option_name_top, option_value_top, 35,50, "CustomW1Qu" );
CreateDD('vwattr0_Custom Width Middle Inch', option_name_top, option_value_top, 0,22, "CustomW2In" );
CreateDD('vwattr0_Custom Width Middle Quad', option_name_top, option_value_top, 35,50, "CustomW2Qu" );
CreateDD('vwattr0_Custom Width Bottom Inch', option_name_top, option_value_top, 0,22, "CustomW3In" );
CreateDD('vwattr0_Custom Width Bottom Quad', option_name_top, option_value_top, 35,50, "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){
document.getElementById("customw").innerHTML="";
}
}
  if (el3 != null){
 document.getElementById("CustomMid").innerHTML="";
 }
  if (el2 != null){
 document.getElementById("newopt1").innerHTML="";
 
 }
}

function setOptions(chosen) {
removeElement();
var selbox = document.f1.vwattr0_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 Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 47"-60"','47"-60" Finished Opening Required [Model : 2000S]');
selbox.options[selbox.options.length] = new Option('Custom Width','Custom Tub Door Width [Model : 2000-CUS]');
}
if (chosen == '2') {
selbox.options[selbox.options.length] = new Option('Choose Your Shower Width','None');
selbox.options[selbox.options.length] = new Option('Door - 47"-60"','47"-60" Finished Opening Required [Model : 2000]');
selbox.options[selbox.options.length] = new Option('Custom Width','Custom Shower Door Width [Model : 1700]');
}

if (chosen == '3') { 
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 : 3000S]');
selbox.options[selbox.options.length] = new Option('Door - 49"-60"','49"-60" Finished Opening Required [Model : 3055S]');
selbox.options[selbox.options.length] = new Option('Choose Custom Shower Door Width - [Model : 3000CUS]  ','Custom Width [Model : 3000CUS]');
}
if (chosen == '4') { 
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 : 3000T]');
selbox.options[selbox.options.length] = new Option('Door - 49"-60"','49"-60" Finished Opening Required [Model : 3055T]');
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 == '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();
}
