function sortArrayPrice(a,b){
	return(a-b)
}
var myarray = blackout_arr[3];
var minPrice = eval('Array('+myarray.sort(sortArrayPrice)+')');


function getMinimumPrice(){
	//alert('wgergwg');
	document.getElementById('minprice').innerHTML = (minPrice[0].toFixed(2) * (1-blackout_arr[0])).toFixed(2);
	}

// disable sau enable link pe butonul Add to Basket - radul
function ControlAddBasket(){
    		button.onclick = function(){document.forms[0].submit(); return false;};
}
	
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((width!="") && (typeof(width) != "undefined"))
	{
		document.form_calcblackout.customwidth.value = unescape(width);
		AddDrops(document.form_calcblackout.customwidth.value);
	}
	if((drop!="") && (typeof(drop) != "undefined"))
	{
		document.form_calcblackout.customdrop.value = unescape(drop);
		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_calcblackout.price.value = '';
	document.form_calcblackout.saveprice.value = '';
	for(i=0; i<blackout_arr[1].length; i++)
	{
		if(document.form_calcblackout.customwidth.value == blackout_arr[1][i] && document.form_calcblackout.customdrop.value == blackout_arr[2][i])
		{ 
			var salesave = blackout_arr[3][i] * blackout_arr[0];
			var saleprice = blackout_arr[3][i] - salesave;
			document.form_calcblackout.price.value=formatDecimal(saleprice, true, 2);
			document.form_calcblackout.saveprice.value=formatDecimal(salesave, true, 2);
			document.form_calcblackout.blackout.value=i+1;
		}
	}
	RRP.get();
}

function AddWidths()
{
	sel_width = document.form_calcblackout.customwidth.value;
	sel_width_poz = document.form_calcblackout.customwidth.selectedIndex;
	sel_drop = document.form_calcblackout.customdrop.value;

	for(k=document.form_calcblackout.customwidth.options.length-1; k>=0; k--)
		document.form_calcblackout.customwidth.options[k]=null;

	for(i=0; i<blackout_arr[1].length; i++)
	{
		var found=false;
		for(j=0; j<document.form_calcblackout.customwidth.options.length; j++)
			if(document.form_calcblackout.customwidth.options[j].value==blackout_arr[1][i])
				found=true;
		if(!found)
		{
			if (sel_width_poz == j || sel_width == blackout_arr[1][i])
			{
				document.form_calcblackout.customwidth.options[document.form_calcblackout.customwidth.options.length]=new Option(blackout_arr[1][i]+"mm", blackout_arr[1][i], true, true);
			}
			else
				document.form_calcblackout.customwidth.options[document.form_calcblackout.customwidth.options.length]=new Option(blackout_arr[1][i]+"mm", blackout_arr[1][i]);
		}
	}
	AddDrops(document.form_calcblackout.customwidth.value, sel_drop);
}

function AddDrops(width, sel_drop)
{
	for(k=document.form_calcblackout.customdrop.options.length-1; k>=0; k--)
		document.form_calcblackout.customdrop.options[k]=null;
	
	for(i=0; i<blackout_arr[2].length; i++)
	{
		if (blackout_arr[1][i] == width)
			if (sel_drop == blackout_arr[2][i])
				document.form_calcblackout.customdrop.options[document.form_calcblackout.customdrop.options.length]=new Option(blackout_arr[2][i]+"mm", blackout_arr[2][i], true, true);
			else
				document.form_calcblackout.customdrop.options[document.form_calcblackout.customdrop.options.length]=new Option(blackout_arr[2][i]+"mm", blackout_arr[2][i]);
	}
	GetCustomPrice();
}

function VerifyBlackoutForm()
{
	if(document.form_calcblackout.price.value==0)
	{
		alert("Please select a ready made blind!");
		return false;
	}
	return true;
}

function SelectProdType(prodtype)
{
		window.location = prodtype;
}

