// Javascript file to populate shipping field when
// checkbox is clicked.

// File: same_as.js

// Function to populate shipping field information.
function same_as(theForm)
{
	if(theForm.elements["SAMEAS"].checked)
	{
		var first_name = getElement(theForm, "FCONTACT");
		var last_name = getElement(theForm, "LCONTACT");
		var company = getElement(theForm, "COMPANY");
		var address_1 = getElement(theForm, "ADDRESS1");
		var address_2 = getElement(theForm, "ADDRESS2");
		var city = getElement(theForm, "CITY");
		
		var state = theForm.elements["FieldValues[ADDRSTATE]"].selectedIndex;
		var country = theForm.elements["FieldValues[COUNTRY]"].selectedIndex;

		var zip = getElement(theForm, "ZIP");

		setElement(theForm, first_name, "SFCONTACT");
		setElement(theForm, last_name, "SLCONTACT");
		setElement(theForm, company, "SCOMPANY");
		setElement(theForm, address_1, "SADDRESS1");
		setElement(theForm, address_2, "SADDRESS2");
		setElement(theForm, city, "SCITY");
		
		theForm.elements["FieldValues[SSTATE]"].selectedIndex = state;
		theForm.elements["FieldValues[SCOUNTRY]"].selectedIndex = country;
		
		setElement(theForm, zip, "SZIP");
	}
	
	return true;
}

function clear_shipping(theForm)
{
	if(theForm.elements["ClearShipping"].checked)
	{

		setElement(theForm, " ", "SFCONTACT");
		setElement(theForm, " ", "SLCONTACT");
		setElement(theForm, " ", "SCOMPANY");
		setElement(theForm, " ", "SADDRESS1");
		setElement(theForm, " ", "SADDRESS2");
		setElement(theForm, " ", "SCITY");

		theForm.elements["FieldValues[SSTATE]"].selectedIndex = 0;
		theForm.elements["FieldValues[SCOUNTRY]"].selectedIndex = 0;

		setElement(theForm, " ", "SZIP");
	}
	return true;
}

function getElement(theForm, theText)
{
	return theForm.elements["FieldValues["+theText+"]"].value;
}

function setElement(theForm, newText, theName)
{
	theForm.elements["FieldValues["+theName+"]"].value = newText;
}

function cheater(theForm)
{
	setElement(theForm, "Jerry", "FCONTACT");
	setElement(theForm, "Springer", "LCONTACT");
	setElement(theForm, "Spring, Inc.", "COMPANY");
	setElement(theForm, "1001 Springer Way", "ADDRESS1");
	setElement(theForm, "Apt. 1", "ADDRESS2");
	setElement(theForm, "Beverly Hills", "CITY");
	setElement(theForm, "90210", "ZIP");
}

function displayComment()
{
	var ele = document.getElementById('Comment');
	var checkEle = document.getElementById('toDisplay');
	
	if(checkEle.checked)
	{
		ele.style.display = 'block';
	}
	else
	{
		ele.style.display = 'none';
	}
	
}