var min_width=0;
var max_width=0;
var min_drop=0;
var max_drop=0;
var price=0;

// calculates the minimum price for current product
function getMinimumPrice(form_calc)
{
	//var discount=venetianmm_arr[0][6] / 100;
	var min_price=vertical_arr[0][6][3][0];
	
	for(i=0; i<vertical_arr.length; i++)
	{	
			var slat_arr=vertical_arr[i][6];
			for(j=0; j<slat_arr[0].length; j++)
			{	
				var cur_price=slat_arr[3][j]*(1-discount_);
				if (min_price>cur_price)
				{
					min_price=cur_price;
				}
			}
		
	}
	min_price=formatDecimal(min_price,true,2);
	if(typeof(sale) != 'undefined' && sale.sale > 0)
		min_price = formatDecimal(min_price - (min_price * sale.sale /100), true,2);
	document.getElementById('minprice').innerHTML = min_price;
}


function getParams()
{
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1)
	{
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++)
		{
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
		}
	}
	return params;
}

function SetOtherParams()
{
    params = getParams();
    if (params["controls"] && params["louvre"] && params["stack"] && params["recess"] && params["bracket"] && params["headrail"])
    {
        document.form_calcvertical.louvre_value.value = params["louvre"];
        selectLouvre(document.form_calcvertical.louvre_value.value);
        document.form_calcvertical.controls.value = params["controls"];
        document.form_calcvertical.stack_pos.value = params["stack"];
        document.form_calcvertical.recess.value = params["recess"];
        document.form_calcvertical.bracket.value = params["bracket"];
        document.form_calcvertical.headrail.value = params["headrail"];
    }

	if (params["slat"])
    {
        document.form_calcvertical.louvre_value.value = params["slat"];
        selectLouvre(document.form_calcvertical.louvre_value.value);

		var slatObj = document.form_calcvertical.louvre;
		for(k = 0; k < slatObj.length; k++) {
			if(slatObj[k].value == params["slat"])
				slatObj[k].checked = true;
		}
    }

	if((document.form_calcvertical.custom_drop.value!="")&&(document.form_calcvertical.custom_width.value!="")) {		
		GetCustomPrice();		
	}


}

function formatDecimal(argvalue, addzero, decimaln) {
  var numOfDecimal = (decimaln == null) ? 2 : decimaln;
  var number = 1;

  number = Math.pow(10, numOfDecimal);

  argvalue = Math.round(parseFloat(argvalue) * number) / number;
  
  argvalue = "" + argvalue;

  if (argvalue.indexOf(".") == 0)
    argvalue = "0" + argvalue;

  if (addzero == true) {
    if (argvalue.indexOf(".") == -1)
      argvalue = argvalue + ".";

    while ((argvalue.indexOf(".") + 1) > (argvalue.length - numOfDecimal))
      argvalue = argvalue + "0";
  }

  return argvalue;
}

function selectLouvre(louvre)
{
	document.form_calcvertical.louvre_value.value=louvre; // radul

	document.form_calcvertical.price.value="";
	document.form_calcvertical.saveprice.value="";
	document.form_calcvertical.addtobasket.disabled=false;
	var louvre_poz=-1;
	for(i=0; i<vertical_arr.length;i++)
	{
		if(vertical_arr[i][0]==louvre)
			louvre_poz=i;
	}
	if(louvre_poz<0)
		return;
		
	 //document.form_calcvertical.louvre.value=louvre;


	//add min max
	/*var widthminmax=document.form_calcvertical.widthminmax;
	widthminmax.options[1]=null;
	widthminmax.options[0]=null;
	
	widthminmax.options[0]=new Option(vertical_arr[louvre_poz][2], 1);*/
	min_width=parseInt(vertical_arr[louvre_poz][2]);
	//widthminmax.options[1]=new Option(vertical_arr[louvre_poz][3], 2);
	max_width=parseInt(vertical_arr[louvre_poz][3]);
	//widthminmax.value=2;
	
	/*var dropminmax=document.form_calcvertical.dropminmax;
	dropminmax.options[0]=null;
	
	dropminmax.options[0]=new Option(vertical_arr[louvre_poz][4], 1);*/
	min_drop=parseInt(vertical_arr[louvre_poz][4]);
	//dropminmax.options[1]=new Option(vertical_arr[louvre_poz][5], 2);
	max_drop=parseInt(vertical_arr[louvre_poz][5]);
	//dropminmax.value=2;
	
	price=0;
	
	params = getParams();
	
	width = params["width"];
	drop = params["drop"];
	
	if((width!="")&&(typeof(width) != "undefined"))
		document.form_calcvertical.custom_width.value=unescape(width);
	if((drop!="")&&(typeof(drop) != "undefined"))
		document.form_calcvertical.custom_drop.value=unescape(drop);
	
	if((document.form_calcvertical.custom_drop.value!="")&&(document.form_calcvertical.custom_width.value!=""))
		GetCustomPrice();
}

function AddLouvres()
{
	//add louvres
	/* radul */
	var louvre_value = GetSlatValue(document.form_calcvertical);
	//document.form_calcvertical.louvre_value.value = louvre_value; // put selected slat's value in a hidden field

	selectLouvre(louvre_value); //select default louvre	
	
}

function ChangePrice(custom_ctrl, form_calc)
{
	custom_ctrl.value="";
	form_calc.price.value="";
	form_calc.saveprice.value="";
	//form_calc.addtobasket.disabled=true; 
}

function GetPrice(prices_arr, width, drop)
{
	var min_dif_width=-1, min_dif_drop=-1;
	var sel_width=-1, sel_drop=-1;
	var price=0;
	for(i=0;i<prices_arr[0].length;i++)
	{
		var cur_dif_width=prices_arr[1][i]-width;
		var cur_dif_drop=prices_arr[2][i]-drop;
		//alert("dif curenta: "+cur_dif_width+"   width: "+sizes_arr[1][i]+" custom width:"+custom_width);
		if(((min_dif_width==-1)||(cur_dif_width<min_dif_width))&&(cur_dif_width>=0))
		{
			min_dif_width=cur_dif_width;
			sel_width=prices_arr[1][i];
			sel_drop=-1;
			min_dif_drop=-1;
		}
		
		if(prices_arr[1][i]==sel_width)
			if(((min_dif_drop==-1)||(cur_dif_drop<min_dif_drop))&&(cur_dif_drop>=0)&&(min_dif_width!=-1))
			{
				min_dif_drop=cur_dif_drop;
				sel_drop=prices_arr[2][i];
				price=prices_arr[3][i];
			}
	}
	return price;
}

function GetMaxWidth(prices_arr, drop)
{
	var max_width=0;
	var min_dif_drop=-1;
	var sel_drop=-1;
	for(i=0;i<prices_arr[0].length;i++)
	{
		var cur_dif_drop=prices_arr[2][i]-drop;
		if(((min_dif_drop==-1)||(cur_dif_drop<min_dif_drop))&&(cur_dif_drop>=0))
		{
			min_dif_drop=cur_dif_drop;
			sel_drop=prices_arr[2][i];
			max_width=0;
		}
		
		if((prices_arr[2][i]==sel_drop)&&(max_width<prices_arr[1][i]))
			max_width=prices_arr[1][i];
	}
	return max_width;
}
	
function GetCustomPrice()
{
	var custom_width=parseInt(document.form_calcvertical.custom_width.value);
	var custom_drop=parseInt(document.form_calcvertical.custom_drop.value);
	if((min_width>custom_width)||(max_width<custom_width)||(isNaN(custom_width)))
	{
		alert("Please enter width between "+min_width+"mm (min) and "+max_width+"mm (max)");
		return false;
	}
	if((min_drop>custom_drop)||(max_drop<custom_drop)||(isNaN(custom_drop)))
	{
		alert("Please enter drop between "+min_drop+"mm (min) and "+max_drop+"mm (max)");
		return false;
	}
	
	//find louvre
	var louvre=-1;
	for(i=0;i<vertical_arr.length; i++)
	{
		if(vertical_arr[i][0]==document.form_calcvertical.louvre_value.value)
			louvre=i;
	}
	if(louvre<0)
		return;
	
	price=GetPrice(vertical_arr[louvre][6], custom_width, custom_drop);
	
	if(price==0)
	{
		var strMaxWidth=GetMaxWidth(vertical_arr[louvre][6], custom_drop);
		alert("Maximum width for the selected drop is "+strMaxWidth+" mm");
		return;
	}

  //control price
	var controls_price = 0;
	var controls = document.form_calcvertical.controls.value;
	if(controls == "3" || controls == "5") {
		if(custom_drop <= 500)
			controls_price = 0.56;
		else if(custom_drop > 500 && custom_drop <= 1000)
			controls_price = 1.12;
		else if(custom_drop > 1000 && custom_drop <= 1500)
			controls_price = 1.68;
		else if(custom_drop > 1500 && custom_drop <= 2000)
			controls_price = 2.25;
		else if(custom_drop > 2000 && custom_drop <= 2500)
			controls_price = 2.81;
		else if(custom_drop > 2500)
			controls_price = 4.04;
	}
  controls_price = controls_price / (1 - discount_);


	// HEADRAIL price
	/* ******************************************************* */
  var sel_brackets = document.form_calcvertical.bracket.value;
	
	var sel_headrail = document.form_calcvertical.headrail.value;
  var sel_slat = vertical_arr[louvre][1];
	// NO VOGUE FOR 127mm SLATS
	if (sel_slat == "127mm" && (sel_headrail == 5 || sel_headrail == 6 || sel_headrail == 7 || sel_headrail == 8)){
		alert("Sorry, Vogue headrail is available for 89mm slats only!");
		document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
		sel_headrail = document.form_calcvertical.headrail.value;
	}

	var headrail_price = 0;

	if(sel_headrail == 5) { // white vogue headrail
		if(custom_width <= 1100)
			headrail_price = 0.92;
		else if(custom_width <= 1400)
			headrail_price = 1.19;
		else if(custom_width <= 1600)
			headrail_price = 1.33;
		else if(custom_width <= 1800)
			headrail_price = 1.54;
		else if(custom_width <= 2000)
			headrail_price = 1.67;
		else if(custom_width <= 2300)
			headrail_price = 1.92;
		else if(custom_width <= 2500)
			headrail_price = 2.05;
		else if(custom_width <= 2800)
			headrail_price = 2.30;
		else if(custom_width <= 3200)
			headrail_price = 2.57;
		else if(custom_width <= 3700)
			headrail_price = 3.02;
		else if(custom_width <= 4000)
			headrail_price = 3.19;
		else if(custom_width <= 4300)
			headrail_price = 3.43;
		else if(custom_width <= 4500)
			headrail_price = 3.57;
		else {
      alert("Sorry, White Vogue headrail is available for sizes of up to 4500mm wide!");
      document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
      sel_headrail = document.form_calcvertical.headrail.value;
    }
		headrail_price = headrail_price / (1 - discount_);
	} // end if vogue headrail
  if(sel_headrail == 6 || sel_headrail == 7) { // black vogue headrail || gold vogue headrail

    if (sel_brackets == 0) {

      if (custom_drop <= 1000) {
        if(custom_width <= 500)
          headrail_price = 8.37;
        else if(custom_width <= 1000)
          headrail_price = 13.32;
        else if(custom_width <= 1200)
          headrail_price = 15.11;
        else if(custom_width <= 1500)
          headrail_price = 21.36;
        else if(custom_width <= 2000)
          headrail_price = 24.51;
        else if(custom_width <= 2500)
          headrail_price = 32.52;
        else if(custom_width <= 3000)
          headrail_price = 37.53;
        else if(custom_width <= 3500)
          headrail_price = 45.54;
        else if(custom_width <= 4000)
          headrail_price = 50.53;
        else if(custom_width <= 4500)
          headrail_price = 58.56;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 2000) {
        if(custom_width <= 500)
          headrail_price = 8.7;
        else if(custom_width <= 1000)
          headrail_price = 13.65;
        else if(custom_width <= 1200)
          headrail_price = 15.46;
        else if(custom_width <= 1500)
          headrail_price = 21.71;
        else if(custom_width <= 2000)
          headrail_price = 24.86;
        else if(custom_width <= 2500)
          headrail_price = 32.88;
        else if(custom_width <= 3000)
          headrail_price = 37.86;
        else if(custom_width <= 3500)
          headrail_price = 45.87;
        else if(custom_width <= 4000)
          headrail_price = 50.76;
        else if(custom_width <= 4500)
          headrail_price = 58.89;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3000) {
        if(custom_width <= 500)
          headrail_price = 9.02;
        else if(custom_width <= 1000)
          headrail_price = 14.01;
        else if(custom_width <= 1200)
          headrail_price = 15.79;
        else if(custom_width <= 1500)
          headrail_price = 22.04;
        else if(custom_width <= 2000)
          headrail_price = 25.19;
        else if(custom_width <= 2500)
          headrail_price = 33.21;
        else if(custom_width <= 3000)
          headrail_price = 38.19;
        else if(custom_width <= 3500)
          headrail_price = 46.2;
        else if(custom_width <= 4000)
          headrail_price = 51.18;
        else if(custom_width <= 4500)
          headrail_price = 59.22;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3600) {
        if(custom_width <= 500)
          headrail_price = 9.24;
        else if(custom_width <= 1000)
          headrail_price = 14.22;
        else if(custom_width <= 1200)
          headrail_price = 16.03;
        else if(custom_width <= 1500)
          headrail_price = 22.25;
        else if(custom_width <= 2000)
          headrail_price = 25.4;
        else if(custom_width <= 2500)
          headrail_price = 33.53;
        else if(custom_width <= 3000)
          headrail_price = 38.4;
        else if(custom_width <= 3500)
          headrail_price = 46.41;
        else if(custom_width <= 4000)
          headrail_price = 51.39;
        else if(custom_width <= 4500)
          headrail_price = 59.43;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else {
        alert("Sorry, the maximum drop for this headrail is 3600mm!");
        document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
        sel_headrail = document.form_calcvertical.headrail.value;
      }
    }
    else if (sel_brackets == 1) {
      if (custom_drop <= 1000) {
        if(custom_width <= 500)
          headrail_price = 9.66;
        else if(custom_width <= 1000)
          headrail_price = 14.64;
        else if(custom_width <= 1200)
          headrail_price = 16.43;
        else if(custom_width <= 1500)
          headrail_price = 23.97;
        else if(custom_width <= 2000)
          headrail_price = 27.17;
        else if(custom_width <= 2500)
          headrail_price = 36.5;
        else if(custom_width <= 3000)
          headrail_price = 41.48;
        else if(custom_width <= 3500)
          headrail_price = 50.78;
        else if(custom_width <= 4000)
          headrail_price = 55.79;
        else if(custom_width <= 4500)
          headrail_price = 65.12;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 2000) {
        if(custom_width <= 500)
          headrail_price = 9.99;
        else if(custom_width <= 1000)
          headrail_price = 14.99;
        else if(custom_width <= 1200)
          headrail_price = 16.78;
        else if(custom_width <= 1500)
          headrail_price = 24.3;
        else if(custom_width <= 2000)
          headrail_price = 27.5;
        else if(custom_width <= 2500)
          headrail_price = 36.82;
        else if(custom_width <= 3000)
          headrail_price = 41.81;
        else if(custom_width <= 3500)
          headrail_price = 51.14;
        else if(custom_width <= 4000)
          headrail_price = 56.12;
        else if(custom_width <= 4500)
          headrail_price = 65.45;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3000) {
        if(custom_width <= 500)
          headrail_price = 10.34;
        else if(custom_width <= 1000)
          headrail_price = 15.32;
        else if(custom_width <= 1200)
          headrail_price = 17.11;
        else if(custom_width <= 1500)
          headrail_price = 24.65;
        else if(custom_width <= 2000)
          headrail_price = 27.82;
        else if(custom_width <= 2500)
          headrail_price = 37.15;
        else if(custom_width <= 3000)
          headrail_price = 42.14;
        else if(custom_width <= 3500)
          headrail_price = 51.47;
        else if(custom_width <= 4000)
          headrail_price = 56.45;
        else if(custom_width <= 4500)
          headrail_price = 65.78;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3600) {
        if(custom_width <= 500)
          headrail_price = 10.55;
        else if(custom_width <= 1000)
          headrail_price = 15.53;
        else if(custom_width <= 1200)
          headrail_price = 17.32;
        else if(custom_width <= 1500)
          headrail_price = 25;
        else if(custom_width <= 2000)
          headrail_price = 28.04;
        else if(custom_width <= 2500)
          headrail_price = 37.37;
        else if(custom_width <= 3000)
          headrail_price = 42.35;
        else if(custom_width <= 3500)
          headrail_price = 51.68;
        else if(custom_width <= 4000)
          headrail_price = 56.66;
        else if(custom_width <= 4500)
          headrail_price = 65.99;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else {
        alert("Sorry, the maximum drop for this headrail is 3600mm!");
        document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
        sel_headrail = document.form_calcvertical.headrail.value;
      }
    }

    headrail_price = headrail_price / (1 - discount_);
  }
  

  if(sel_headrail == 8) { // silver vogue headrail
    
    if (sel_brackets == 0) {

      if (custom_drop <= 1000) {
        if(custom_width <= 500)
          headrail_price = 6.86;
        else if(custom_width <= 1000)
          headrail_price = 10.86;
        else if(custom_width <= 1200)
          headrail_price = 10.86;
        else if(custom_width <= 1500)
          headrail_price = 17.39;
        else if(custom_width <= 2000)
          headrail_price = 19.58;
        else if(custom_width <= 2500)
          headrail_price = 26.11;
        else if(custom_width <= 3000)
          headrail_price = 30.13;
        else if(custom_width <= 3500)
          headrail_price = 36.64;
        else if(custom_width <= 4000)
          headrail_price = 40.63;
        else if(custom_width <= 4500)
          headrail_price = 47.16;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 2000) {
        if(custom_width <= 500)
          headrail_price = 7.19;
        else if(custom_width <= 1000)
          headrail_price = 11.2;
        else if(custom_width <= 1200)
          headrail_price = 12.6;
        else if(custom_width <= 1500)
          headrail_price = 17.72;
        else if(custom_width <= 2000)
          headrail_price = 17.72;
        else if(custom_width <= 2500)
          headrail_price = 26.46;
        else if(custom_width <= 3000)
          headrail_price = 30.46;
        else if(custom_width <= 3500)
          headrail_price = 36.35;
        else if(custom_width <= 4000)
          headrail_price = 40.98;
        else if(custom_width <= 4500)
          headrail_price = 47.52;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3000) {
        if(custom_width <= 500)
          headrail_price = 7.54;
        else if(custom_width <= 1000)
          headrail_price = 11.54;
        else if(custom_width <= 1200)
          headrail_price = 12.95;
        else if(custom_width <= 1500)
          headrail_price = 18.07;
        else if(custom_width <= 2000)
          headrail_price = 20.26;
        else if(custom_width <= 2500)
          headrail_price = 26.79;
        else if(custom_width <= 3000)
          headrail_price = 30.79;
        else if(custom_width <= 3500)
          headrail_price = 37.32;
        else if(custom_width <= 4000)
          headrail_price = 41.31;
        else if(custom_width <= 4500)
          headrail_price = 47.85;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3600) {
        if(custom_width <= 500)
          headrail_price = 7.73;
        else if(custom_width <= 1000)
          headrail_price = 11.75;
        else if(custom_width <= 1200)
          headrail_price = 13.16;
        else if(custom_width <= 1500)
          headrail_price = 18.28;
        else if(custom_width <= 2000)
          headrail_price = 20.47;
        else if(custom_width <= 2500)
          headrail_price = 27;
        else if(custom_width <= 3000)
          headrail_price = 31;
        else if(custom_width <= 3500)
          headrail_price = 37.53;
        else if(custom_width <= 4000)
          headrail_price = 41.52;
        else if(custom_width <= 4500)
          headrail_price = 48.03;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else {
        alert("Sorry, the maximum drop for this headrail is 3600mm!");
        document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
        sel_headrail = document.form_calcvertical.headrail.value;
      }
    }
    else if (sel_brackets == 1) {
      if (custom_drop <= 1000) {
        if(custom_width <= 500)
          headrail_price = 7.66;
        else if(custom_width <= 1000)
          headrail_price = 11.99;
        else if(custom_width <= 1200)
          headrail_price = 13.4;
        else if(custom_width <= 1500)
          headrail_price = 19.65;
        else if(custom_width <= 2000)
          headrail_price = 21.83;
        else if(custom_width <= 2500)
          headrail_price = 29.49;
        else if(custom_width <= 3000)
          headrail_price = 33.49;
        else if(custom_width <= 3500)
          headrail_price = 41.15;
        else if(custom_width <= 4000)
          headrail_price = 45.14;
        else if(custom_width <= 4500)
          headrail_price = 52.82;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 2000) {
        if(custom_width <= 500)
          headrail_price = 7.99;
        else if(custom_width <= 1000)
          headrail_price = 12.31;
        else if(custom_width <= 1200)
          headrail_price = 13.72;
        else if(custom_width <= 1500)
          headrail_price = 19.98;
        else if(custom_width <= 2000)
          headrail_price = 22.18;
        else if(custom_width <= 2500)
          headrail_price = 29.85;
        else if(custom_width <= 3000)
          headrail_price = 33.84;
        else if(custom_width <= 3500)
          headrail_price = 41.5;
        else if(custom_width <= 4000)
          headrail_price = 45.5;
        else if(custom_width <= 4500)
          headrail_price = 53.16;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3000) {
        if(custom_width <= 500)
          headrail_price = 8.34;
        else if(custom_width <= 1000)
          headrail_price = 12.67;
        else if(custom_width <= 1200)
          headrail_price = 14.08;
        else if(custom_width <= 1500)
          headrail_price = 20.33;
        else if(custom_width <= 2000)
          headrail_price = 22.51;
        else if(custom_width <= 2500)
          headrail_price = 30.17;
        else if(custom_width <= 3000)
          headrail_price = 34.17;
        else if(custom_width <= 3500)
          headrail_price = 41.83;
        else if(custom_width <= 4000)
          headrail_price = 45.83;
        else if(custom_width <= 4500)
          headrail_price = 53.49;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else if (custom_drop <= 3600) {
        if(custom_width <= 500)
          headrail_price = 8.55;
        else if(custom_width <= 1000)
          headrail_price = 12.88;
        else if(custom_width <= 1200)
          headrail_price = 14.29;
        else if(custom_width <= 1500)
          headrail_price = 20.54;
        else if(custom_width <= 2000)
          headrail_price = 22.72;
        else if(custom_width <= 2500)
          headrail_price = 30.39;
        else if(custom_width <= 3000)
          headrail_price = 34.38;
        else if(custom_width <= 3500)
          headrail_price = 42.04;
        else if(custom_width <= 4000)
          headrail_price = 46.04;
        else if(custom_width <= 4500)
          headrail_price = 53.7;
        else {
          alert("Sorry, this headrail is available for sizes of up to 4500mm wide!");
          document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
          sel_headrail = document.form_calcvertical.headrail.value;
        }
      }
      else {
        alert("Sorry, the maximum drop for this headrail is 3600mm!");
        document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
        sel_headrail = document.form_calcvertical.headrail.value;
      }
    }

    headrail_price = headrail_price / (1 - discount_);
  }

  if(sel_headrail == 9 || sel_headrail == 10) { // matching/contrasting headrail
		if(custom_width <= 500)
			headrail_price = 1.65;
		else if(custom_width <= 1000)
			headrail_price = 2.82;
		else if(custom_width <= 1500)
			headrail_price = 4;
		else if(custom_width <= 2000)
			headrail_price = 5.64;
		else if(custom_width <= 2500)
			headrail_price = 7.05;
		else {
      alert("Sorry, this headrail is available for sizes of up to 2500mm wide!");
      document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
      sel_headrail = document.form_calcvertical.headrail.value;
    }
    headrail_price = headrail_price / (1 - discount_);
  }

  if ( (sel_headrail == 1) && ($('valance_color') != undefined) && ($('valance_color').value != 0) ) {
		if(custom_width <= 500)
			headrail_price = 1.65;
		else if(custom_width <= 1000)
			headrail_price = 2.82;
		else if(custom_width <= 1500)
			headrail_price = 4;
		else if(custom_width <= 2000)
			headrail_price = 5.64;
		else if(custom_width <= 2500)
			headrail_price = 7.05;
		else {
      alert("Sorry, the colour valance is available for sizes of up to 2500mm wide!");
      //document.form_calcvertical.headrail.selectedIndex = 0; // select slimline
      //sel_headrail = document.form_calcvertical.headrail.value;
      new Combo('valance_color_container', {handler:'event_handler', populate_data:null, input:'valance_color'});
    }
    headrail_price = headrail_price / (1 - discount_);
  }
  if ( (sel_headrail == 1) && ($('valance_color') != undefined) && ($('valance_color').value == 0) ) {
    if(custom_width <= 2500)
      dd.get_valance($('verticalmm_sample').value, $('headrail').value);
  }
	
	// [END] HEADRAIL
	/* ******************************************************* */

	price += headrail_price + controls_price;
	
	//document.form_calcvertical.price.value = formatDecimal(price*(1-vertical_arr[louvre][7]), true, 2);
	//document.form_calcvertical.saveprice.value = formatDecimal(price*vertical_arr[louvre][7], true, 2);
	document.form_calcvertical.price.value = formatDecimal(price*(1-discount_), true, 2);
	document.form_calcvertical.saveprice.value = formatDecimal(price*discount_, true, 2);
	document.form_calcvertical.addtobasket.disabled=false;
	
	RRP.get();
}
//-----------------------------------------------------------------------------------
function getDiscount()
{
	return discount_;
}

function findLouvre()
{
	var louvre=-1;
	for(i=0;i<vertical_arr.length; i++)
	{
		if(vertical_arr[i][0]==document.form_calcvertical.louvre_value.value)
			louvre=i;
	}
	if(louvre<0)
		return;	
	return louvre;
}

function bracketPrice(){ return 0;}

function headrailPrice()
{
	var sel_headrail = document.form_calcvertical.headrail.value;
	var headrail_price = 0;
	if(sel_headrail == 5) { // vogue headrail
		if(custom_width <= 1100)
			headrail_price = 0.92;
		else if(custom_width <= 1400)
			headrail_price = 1.19;
		else if(custom_width <= 1600)
			headrail_price = 1.33;
		else if(custom_width <= 1800)
			headrail_price = 1.54;
		else if(custom_width <= 2000)
			headrail_price = 1.67;
		else if(custom_width <= 2300)
			headrail_price = 1.92;
		else if(custom_width <= 2500)
			headrail_price = 2.05;
		else if(custom_width <= 2800)
			headrail_price = 2.30;
		else if(custom_width <= 3200)
			headrail_price = 2.57;
		else if(custom_width <= 3700)
			headrail_price = 3.02;
		else if(custom_width <= 4000)
			headrail_price = 3.19;
		else if(custom_width <= 4300)
			headrail_price = 3.43;
		else if(custom_width <= 4500)
			headrail_price = 3.57;
	    headrail_price = headrail_price / (1 - discount_);
	} // end if vogue headrail	
	return headrail_price;
}
//-----------------------------------------------------------------------------------



function VerifyVerticalMMForm(form)
{
	if(form.price.value<=0)
	{
		alert('Please insert width and drop first and click the button "Calculate Price"');
		return false;
	}
	return true; 
}

function ConvertInchToMm()
{
	var custom_inches=document.form_calcvertical.custom_inches;
	var custom_mm=document.form_calcvertical.custom_mm;
	
	custom_mm.value=formatDecimal(parseFloat(custom_inches.value.replace(",",".").replace(",","."))*25.4, false, 0);
}

function GetSlatValue(form){ // radul
	var louvre_value;
	for (i=0;i<form.louvre.length;i++) {
		if (form.louvre[i].checked)
			louvre_value = form.louvre[i].value;
	}
	return louvre_value;
}


