var fieldVal = null;

function valSignIn()
{
	errors = new Array();
	errors[0] = checkEmail('email', 1);
	errors[1] = checkPassword('password', 1);
	errors[2] = checkPassword('retype_password', 1);
	if (errors[2] == "") {
		if ($('password').value != $('retype_password').value) {
			errors[3] = 'Passwords Must Match';
			handleErrorDIVs('retype_password', 'Passwords Must Match');
		}
		else {
			errors[3] = '';
			handleErrorDIVs('retype_password', '');
		}
	}
	if (searchErrors(errors) == 0)
	{
		$('checkout_form').submit();
	}
}

function valShipBill() {
	errors = new Array();
	errors[0] = checkName("first_nameS", 1);
	errors[1] = checkName("last_nameS", 1);
	errors[2] = checkAddress("address1S", 1);
	errors[3] = checkAddress("address2S", 0);
	errors[4] = checkCity("cityS", 1);
	if (document.checkout_form.shipto[0].checked == true)
	{
		errors[5] = checkGeneric("stateS", 1);
		errors[6] = checkUSZip("zipS", 1);
		errors[7] = checkGeneric("countryS", 0);
		errors[8] = checkUSPhone("phoneS", 1);
		checkProvince("provinceS", 0);
		
	}
	else
	{
		errors[5] = checkProvince("provinceS", 1);
		errors[6] = checkIntZip("zipS", 1);
		errors[7] = checkGeneric("countryS", 1);
		errors[8] = checkIntPhone("phoneS", 1);
		checkGeneric("stateS", 0);
	}
	
	errors[9] = checkName("first_nameB", 1);
	errors[10] = checkName("last_nameB", 1);
	errors[11] = checkAddress("address1B", 1);
	errors[12] = checkAddress("address2B", 0);
	errors[13] = checkCity("cityB", 1);
	if (document.checkout_form.billto[0].checked == true)
	{
		errors[14] = checkGeneric("stateB", 1);
		errors[15] = checkUSZip("zipB", 1);
		errors[16] = checkGeneric("countryB", 0);
		errors[17] = checkUSPhone("phoneB", 1);
		checkProvince("provinceB", 0);
		
	}
	else
	{
		errors[14] = checkProvince("provinceB", 1);
		errors[15] = checkIntZip("zipB", 1);
		errors[16] = checkGeneric("countryB", 1);
		errors[17] = checkIntPhone("phoneB", 1);
		checkGeneric("stateS", 0);
	}
	if (searchErrors(errors) == 0)
	{
		document.getElementById('checkout_form').submit();	
	}
}



function setShipDomestic() {
	document.checkout_form.provinceS.disabled = true;
	document.checkout_form.countryS.disabled = true;
	document.checkout_form.countryS.options[236] = new Option("United States", "238");
	document.checkout_form.countryS.value = "238";
	$("number_formatS").innerHTML = "555-343-6789 Format Please.";
	document.checkout_form.stateS.disabled = false;
	document.checkout_form.stateS.options[52] = null;
}

function setShipInt() {
	document.checkout_form.provinceS.disabled = false;
	document.checkout_form.stateS.options[52] = new Option("Not Applicable", "NA");
	document.checkout_form.stateS.value = "NA";
	document.checkout_form.stateS.disabled = true;
	document.checkout_form.countryS.disabled = false;
	$("number_formatS").innerHTML = "";
	document.checkout_form.countryS.options[236] = null;
}

function setBillDomestic() {
	document.checkout_form.provinceB.disabled = true;
	document.checkout_form.countryB.disabled = true;
	document.checkout_form.countryB.options[236] = new Option("United States", "238");
	document.checkout_form.countryB.value = "238";
	$("number_formatB").innerHTML = "555-343-6789 Format Please.";
	document.checkout_form.stateB.disabled = false;
	document.checkout_form.stateB.options[52] = null;
}

function setBillInt() {
	document.checkout_form.provinceB.disabled = false;
	document.checkout_form.stateB.options[52] = new Option("Not Applicable", "NA");
	document.checkout_form.stateB.value = "NA";
	document.checkout_form.stateB.disabled = true;
	document.checkout_form.countryB.disabled = false;
	$("number_formatB").innerHTML = "";
	document.checkout_form.countryB.options[236] = null;
}

function copyInfo(isChecked)
{
	if (isChecked == true)
	{
		$('first_nameB').value = $('first_nameS').value;
		$('last_nameB').value = $('last_nameS').value;
		$('address1B').value = $('address1S').value;
		$('address2B').value = $('address2S').value;
		$('cityB').value = $('cityS').value;
		$('stateB').value = $('stateS').value;
		$('provinceB').value = $('provinceS').value;
		$('zipB').value = $('zipS').value;
		$('countryB').value = $('countryS').value;
		$('phoneB').value = $('phoneS').value;
		document.checkout_form.billto[0].checked = document.checkout_form.shipto[0].checked;
		document.checkout_form.billto[1].checked = document.checkout_form.shipto[1].checked;
		if (document.checkout_form.billto[1].checked == true)
		{
			document.checkout_form.provinceB.disabled = false;
			document.checkout_form.stateB.options[52] = new Option("Not Applicable", "0");
			document.checkout_form.stateB.value = "0";
			document.checkout_form.stateB.disabled = true;
			document.checkout_form.countryB.disabled = false;
			document.checkout_form.countryB.options[236] = null;
			document.checkout_form.countryB.value = document.checkout_form.countryS.value
			$("number_formatB").innerHTML = "";
		}
		else
		{
			document.checkout_form.provinceB.disabled = true;
			document.checkout_form.stateB.disabled = false;
			document.checkout_form.stateB.value = document.checkout_form.stateS.value
			document.checkout_form.stateB.options[52] = null;
			document.checkout_form.countryB.disabled = true;
			document.checkout_form.countryB.options[236] = new Option("United States", "238");
			document.checkout_form.countryB.value = "238";
			$("number_formatB").innerHTML = "555-343-6789 Format Please.";
		}
	}
	else
	{
		$('first_nameB').value = "";
		$('last_nameB').value = "";
		$('address1B').value = "";
		$('address2B').value = "";
		$('cityB').value = "";
		$('stateB').value = "";
		$('provinceB').value = "";
		$('zipB').value = "";
		$('countryB').value = "";
		$('phoneB').value = "";
		
		if (document.checkout_form.billto[1].checked == true)
		{
			document.checkout_form.provinceB.disabled = true;
			document.checkout_form.stateB.disabled = false;
			document.checkout_form.stateB.value = "";
			document.checkout_form.stateB.options[52] = null;
			document.checkout_form.countryB.disabled = true;
			document.checkout_form.countryB.options[236] = new Option("United States", "238");
			document.checkout_form.countryB.value = "238";
			$("number_formatB").innerHTML = "";	
		}
		else
		{
			document.checkout_form.countryB.options[236] = new Option("United States", "238");
			document.checkout_form.countryB.value = "238";	
			
		}
		$("number_formatB").innerHTML = "555-345-6789 Format Please.";	
		document.checkout_form.billto[0].checked = true;
	}
}

