function getMinimumPrice()
{	
	var minprice=cellular_rm_arr[4][3][0];
	for(var i=0;i<cellular_rm_arr[4][3].length;i++)
	{
		if(cellular_rm_arr[4][3][i]<minprice)
		{
			minprice=cellular_rm_arr[4][3][i];
		}
	}
	document.getElementById('minprice').innerHTML = (minprice* (1-discountrm)).toFixed(2);
}

/**********************************************************/
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 LoadParams()
{
	params = getParams();
	width = params["width"];
	drop = params["drop"];
	if((drop!="") && (typeof(drop) != "undefined"))
	{
		document.form_calc_cellular_rm.customdrop.value = unescape(drop);
		AddWidths(document.form_calc_cellular_rm.customdrop.value, document.form_calc_cellular_rm.customwidth.value);
	}
	if((width!="") && (typeof(width) != "undefined"))
	{
		document.form_calc_cellular_rm.customwidth.value = unescape(width);
		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 GetCustomPrice()
{
	document.form_calc_cellular_rm.price.value = '';
	document.form_calc_cellular_rm.saveprice.value = '';
	for(i=0; i<cellular_rm_arr[4][1].length; i++)
	{
		if(document.form_calc_cellular_rm.customwidth.value == cellular_rm_arr[4][1][i] && document.form_calc_cellular_rm.customdrop.value == cellular_rm_arr[4][2][i])
		{
			var salesave = cellular_rm_arr[4][3][i]*discountrm;
			var saleprice = cellular_rm_arr[4][3][i]-salesave;
			document.form_calc_cellular_rm.price.value=formatDecimal(saleprice, true, 2);
			document.form_calc_cellular_rm.saveprice.value=formatDecimal(salesave, true, 2);
			document.form_calc_cellular_rm.cellularrm.value=i+1;
		}
	}
}

function AddWidths()
{
	sel_width = document.form_calc_cellular_rm.customwidth.value;
	sel_width_poz = document.form_calc_cellular_rm.customwidth.selectedIndex;
	sel_drop = document.form_calc_cellular_rm.customdrop.value;

	for(k=document.form_calc_cellular_rm.customwidth.options.length-1; k>=0; k--)
		document.form_calc_cellular_rm.customwidth.options[k]=null;

	for(i=0; i<cellular_rm_arr[4][1].length; i++)
	{
		var found=false;
		for(j=0; j<document.form_calc_cellular_rm.customwidth.options.length; j++)
			if(document.form_calc_cellular_rm.customwidth.options[j].value==cellular_rm_arr[4][1][i])
				found=true;
		if(!found)
		{
			if (sel_width_poz == j || sel_width == cellular_rm_arr[4][1][i])
			{
				document.form_calc_cellular_rm.customwidth.options[document.form_calc_cellular_rm.customwidth.options.length]=new Option(cellular_rm_arr[4][1][i]+"mm", cellular_rm_arr[4][1][i], true, true);
			}
			else
				document.form_calc_cellular_rm.customwidth.options[document.form_calc_cellular_rm.customwidth.options.length]=new Option(cellular_rm_arr[4][1][i]+"mm", cellular_rm_arr[4][1][i]);
		}
	}
	
	AddDrops(document.form_calc_cellular_rm.customwidth.value, sel_drop);
}

function AddDrops(width, sel_drop)
{
	for(k=document.form_calc_cellular_rm.customdrop.options.length-1; k>=0; k--)
		document.form_calc_cellular_rm.customdrop.options[k]=null;
	
	for(i=0; i<cellular_rm_arr[4][2].length; i++)
	{
		if (cellular_rm_arr[4][1][i] == width)
			if (sel_drop == cellular_rm_arr[4][2][i])
				document.form_calc_cellular_rm.customdrop.options[document.form_calc_cellular_rm.customdrop.options.length]=new Option(cellular_rm_arr[4][2][i]+"mm", cellular_rm_arr[4][2][i], true, true);
			else
				document.form_calc_cellular_rm.customdrop.options[document.form_calc_cellular_rm.customdrop.options.length]=new Option(cellular_rm_arr[4][2][i]+"mm", cellular_rm_arr[4][2][i]);
	}
	GetCustomPrice();
}

function VerifyCellularrmForm()
{
	if(document.form_calc_cellular_rm.price.value==0)
	{
		alert("Please select a ready made blind!");
		return false;
	}
	return true;
}

function SelectProdType(prodtype)
{
		window.location = prodtype;
}