// JavaScript Document
function validateForm()
{
	copyPhone('day');
	copyPhone('night');
	ordForm =  document.getElementById('orderform');
	
	if(ordForm.nvcfirstname.value == "")
	{
		alert("First name is required.");
		ordForm.nvcfirstname.focus();
		ordForm.nvcfirstname.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvclastname.value == "")
	{
		alert("Last name is required.");
		ordForm.nvclastname.focus();
		ordForm.nvclastname.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcshipaddress1.value == "")
	{
		alert("Address Line 1 is required.");
		ordForm.nvcshipaddress1.focus();
		ordForm.nvcshipaddress1.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcshipCity.value == "")
	{
		alert("City is required.");
		ordForm.nvcshipCity.focus();
		ordForm.nvcshipCity.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.intShipstate.options[ordForm.intShipstate.selectedIndex].value == "")
	{
		alert("You must select a state.");
		ordForm.intShipstate.focus();
		ordForm.intShipstate.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcshipzip.value == "")
	{
		alert("Zip code is required.");
		ordForm.nvcshipzip.focus();
		ordForm.nvcshipzip.style.backgroundColor = 'red';
		return false;
	}
	if(document.getElementById("BillToShip").checked != true)
	{
		//mfireCopyToBilling();
	}
	if(ordForm.vcBillingFirstName.value == "")
	{
		alert("Billing First name is required.");
		ordForm.vcBillingFirstName.focus();
		ordForm.vcBillingFirstName.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.vcBillingLastName.value == "")
	{
		alert("Billing Last name is required.");
		ordForm.vcBillingLastName.focus();
		ordForm.vcBillingLastName.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcbilladdress1.value == "")
	{
		alert("Billing Address Line 1 is required.");
		ordForm.nvcbilladdress1.focus();
		ordForm.nvcbilladdress1.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcbillCity.value == "")
	{
		alert("Billing City is required.");
		ordForm.nvcbillCity.focus();
		ordForm.nvcbillCity.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.intbillstate.options[ordForm.intbillstate.selectedIndex].value == "")
	{
		alert("You must select a billing state.");
		ordForm.intbillstate.focus();
		ordForm.intbillstate.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcbillzip.value == "")
	{
		alert("Billing Zip code is required.");
		ordForm.nvcbillzip.focus();
		ordForm.nvcbillzip.style.backgroundColor = 'red';
		return false;
	}
	
	if(ordForm.nvcemail.value == "")
	{
		alert("Email is required.");
		ordForm.nvcemail.focus();
		ordForm.nvcemail.style.backgroundColor = 'red';
		return false;
	}
	if(valEmail(ordForm.nvcemail) == true)
	{
		return(false);
	}
	
	if(ordForm.nvcphone_Addr.value == "")
	{
		alert("Daytime phone is required.");
		ordForm.dayPhoneF3.focus();
		ordForm.dayPhoneF3.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.id_ShippingType.options)
	{
		if(ordForm.id_ShippingType.options[ordForm.id_ShippingType.selectedIndex].value == "")
		{
			alert("You must select a shipping option.");
			ordForm.id_ShippingType.focus();
			ordForm.id_ShippingType.style.backgroundColor = 'red';
			return false;
		}
	}
	if(ordForm.intType.options[ordForm.intType.selectedIndex].value == "")
	{
		alert("You must select a credit card type.");
		ordForm.intType.focus();
		ordForm.intType.style.backgroundColor = 'red';
		return false;
	}
	
	if(ordForm.nvcCCNumber.value == "")
	{
		alert("Credit card number is required.");
		ordForm.nvcCCNumber.focus();
		ordForm.nvcCCNumber.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.nvcCardID.value == "")
	{
		alert("Credit card security code is required.");
		ordForm.nvcCardID.focus();
		ordForm.nvcCardID.style.backgroundColor = 'red';
		return false;
	}
	
	
	if(ordForm.TOS.checked != true)
	{
		alert("You must agree to all the terms and conditions.");
		ordForm.TOS.style.backgroundColor = 'red';
		document.getElementById("TOStext").style.fontWeight = 'bold';
		ordForm.TOS.focus();
		return false;
	}

	
	document.getElementById("submitButton").disabled = true;	
	return true;
	
	
}
function mfireCopyToBilling()
{
	var form = document.getElementById('orderform');
	form.vcBillingFirstName.value = form.nvcfirstname.value;
	form.vcBillingLastName.value = form.nvclastname.value;
	form.nvcbilladdress1.value = form.nvcshipaddress1.value;
	form.nvcbilladdress2.value = form.nvcshipaddress2.value;
	hi = form.intShipstate.options.selectedIndex;
	for (x = 0; x < form.intbillstate.options.length; x++)
	{
		if (form.intShipstate.options[hi].text == form.intbillstate.options[x].text)
			form.intbillstate.options.selectedIndex = x;
	}
	form.nvcbillCity.value = form.nvcshipCity.value;
	form.nvcbillzip.value = form.nvcshipzip.value;
}
function toggleBilling()
{
	//billInfo = document.getElementById("BillingInfo");
	checkBoxes = document.getElementById("BillToShip")
	if(!checkBoxes.checked)
	{
		changecss('.billInfo','display','none'); 
		
	}
	else
	{
		changecss('.billInfo','display','');
		
		
	}
}

function changecss(theClass,element,value) 
{
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
		document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
}
