
/******** popup charge window attibutes  ******/

var chargeWindow = new Object();
var chargeWinWidth = 500;
var chargeWinHeight = 400;
var chargeWinParams = 'width=' + chargeWinWidth + ',height=' + chargeWinHeight;

/********  drop down attributes ********/

var onesOffset = 78;
var tensOffset = 88;
var hundredsOffset = 98;
var thousandsOffset = 108;
var tenThousandsOffset = 118;
var centsOffset = 128;

var onesID = "id[24]";
var tensID = "id[25]";
var hundredsID = "id[26]";
var thousandsID = "id[27]";
var tenThousandsID = "id[28]";
var centsID = "id[29]";
var centsValue = "";
var customProductNumber = 191;
var customProductID = "products_id=" + customProductNumber;

/******************************************/

function checkForCustomOrder()
{	
	if(false == chargeWindow.closed) 
	 {
		chargeWindow.close();
	 }
	
	var pageAddress = window.location.href;
	if(pageAddress.indexOf(customProductID) != -1)
	{
		chargeWindow = window.open('monthly_charge.html','monthlycharge', chargeWinParams);
	}
	
	/*
	if(document.getElementById(onesID) || document.getElementsByName(onesID))
	{
		chargeWindow = window.open('monthly_charge.html','monthlycharge','width=250,height=250');
	}
	*/
}

function submitCustomOrder(dollars, cents)
{
    centsValue = cents;
	processDollars(dollars);
	chargeWindow.close();
}

/**********  Process Dollars  **********/

function processDollars(dlr)
{
	if(dlr.length == 5)
	{
		setTenThousands(dlr.substring(0,1))
		setThousands(dlr.substring(1,2));
		setHundreds(dlr.substring(2,3));
		setTens(dlr.substring(3,4));
		setOnes(dlr.substring(4,5));
	}
	else if(dlr.length == 4)
	{
		setThousands(dlr.substring(0,1));
		setHundreds(dlr.substring(1,2));
		setTens(dlr.substring(2,3));
		setOnes(dlr.substring(3,4));
	}
	else if(dlr.length == 3)
	{
		setHundreds(dlr.substring(0,1));
		setTens(dlr.substring(1,2));
		setOnes(dlr.substring(2,3));
	}
	else if(dlr.length == 2)
	{
		setTens(dlr.substring(0,1));
		setOnes(dlr.substring(1,2));
	}
	else if(dlr.length == 1)
	{
		setOnes(dlr.substring(0,1));
	}
}


/************ set dropdowns ***********/

function setTenThousands(tenThousands)
{
	/*
	var tenThousandsDropdown = document.getElementById(tenThousandsID);
	tenThousandsDropdown.value = parseInt(tenThousands) + tenThousandsOffset;
	*/

	var tenThousandsDropdown = document.getElementsByName(tenThousandsID);
	tenThousandsDropdown[0].value = parseInt(tenThousands) + tenThousandsOffset;
}

function setThousands(thousands)
{
	/*
	var thousandsDropdown = document.getElementById(thousandsID);
	thousandsDropdown.value = parseInt(thousands) + thousandsOffset;
	*/
	var thousandsDropdown = document.getElementsByName(thousandsID);
	thousandsDropdown[0].value = parseInt(thousands) + thousandsOffset;
}

function setHundreds(hundreds)
{
	/*
	var hundredDropdown = document.getElementById(hundredsID);
	hundredDropdown.value = parseInt(hundreds) + hundredsOffset;
	*/

	var hundredDropdown = document.getElementsByName(hundredsID);
	hundredDropdown[0].value = parseInt(hundreds) + hundredsOffset;
}

function setTens(tens)
{
	/*
	var tensDropdown = document.getElementById(tensID);
	tensDropdown.value = parseInt(tens) + tensOffset;
	*/

	var tensDropdown = document.getElementsByName(tensID);
	tensDropdown[0].value = parseInt(tens) + tensOffset;
}

function setOnes(ones)
{
	/*
	var onesDropdown = document.getElementById(onesID);
	onesDropdown.value = parseInt(ones) + onesOffset;
	*/
	var onesDropdown = document.getElementsByName(onesID);
	onesDropdown[0].value = parseInt(ones) + onesOffset;

	setCents();
}

function setCents()
{
	/*
	var centsDropDown = document.getElementById(centsID);
	centsDropDown.value = parseInt(cents) + centsOffset;	
	*/

	var centsDropDown = document.getElementsByName(centsID);
	centsDropDown[0].value = parseInt(centsValue) + centsOffset;	

	document.forms.cart_quantity.submit();
}
