function checkContactForm() {
	var cname, cemail, cphone, cmessage;
	var errMsg = "";
   

	cname    = document.getElementById('contact').Name;
	cemail   = document.getElementById('contact').Email;
	cphone   = document.getElementById('contact').Phone;
	cmessage = document.getElementById('contact').Message;

	if (cname.value == "Name") {
		errMsg += "You must enter your name.\n";
	}

	if (cemail.value == "E-mail") {
		errMsg += "You must enter your e-mail address.\n";
	} else if (!checkEmail(cemail.value)) {
		errMsg += 'You must enter a valid e-mail address.\n';
	}

	if (cphone.value == "Phone Number") {
		errMsg += "You must enter your phone number.\n";
	}

	if (cmessage.value == "Message") {
		errMsg += "You must enter a brief message.\n";
	}

	if (errMsg != "") {
		alert(errMsg);
		return false;
	} else {
		// If we are going to submit the form, then we should
		// clear up any fields that were not filled out properly
		
		if (document.getElementById('contact').Company.value == "Company") { document.getElementById('contact').Company.value = ""; }
		return true;
	}

}



function checkEmail(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	
	if (str.indexOf(at)==-1){
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    return false
	 }
	
	 return true					
}


function activateField(field, str) {

	field.style.color = '#00407A';
	field.style.border = 'solid 1px #00407A';
	if (str != '') {
		if (field.value == str) {
			field.value = '';
		}
	}
}


function deactivateField(field, str) {

	field.style.border = 'solid 1px #CCCCCC';
	if (field.value == '') {
		field.style.color = '#999999';
		field.value = str;
	}
}


function checkPaymentForm() {
	var cname, cemail, cpaymenttype, ccardtype, cardname, ccardnumber, ccardexpirymonth, ccardexpiryyear;
	var errMsg = "";
   
	cname    = document.getElementById('payment').Name;
	cemail   = document.getElementById('payment').Email;
	cpaymenttype = document.getElementById('payment').PaymentType;
	ccardtype = document.getElementById('payment').CardType.options[document.getElementById('payment').CardType.selectedIndex];
	ccardname = document.getElementById('payment').CardName;
	ccardnumber = document.getElementById('payment').CardNumber;
	ccardexpirymonth = document.getElementById('payment').CardExpiryMonth;
	ccardexpiryyear = document.getElementById('payment').CardExpiryYear;
	
	cquotenumber = document.getElementById('payment').QuoteNumber;
	cquoteamount = document.getElementById('payment').QuoteAmount;

	cinvoicenumber = document.getElementById('payment').InvoiceNumber;
	cpaymentamount = document.getElementById('payment').PaymentAmount;

	cwebhostingoption = document.getElementById('payment').WebhostingOption.options[document.getElementById('payment').WebhostingOption.selectedIndex];

	cmaintenanceoption = document.getElementById('payment').MaintenanceOption.options[document.getElementById('payment').MaintenanceOption.selectedIndex];

	if (cname.value == "Your name") {
		errMsg += "You must enter your name.\n";
	}

	if (cemail.value == "Your e-mail address") {
		errMsg += "You must enter your e-mail address.\n";
	} else if (!checkEmail(cemail.value)) {
		errMsg += 'You must enter a valid e-mail address.\n';
	}

	if (cpaymenttype.value == "none") {
		errMsg += "You must select a payment type.\n"; 
	} else if (cpaymenttype.value == "deposit") {
		if (cquotenumber.value == "####") {
			errMsg += "You must enter an quote number.\n";
		}
		if (cquoteamount.value == "XXXX.XX") {
			errMsg += "You must enter an quote amount.\n";
		}
	} else if (cpaymenttype.value == "invoice") {
		if (cinvoicenumber.value == "####") {
			errMsg += "You must enter an invoice number.\n";
		}
		if (cpaymentamount.value == "XXXX.XX") {
			errMsg += "You must enter a payment amount.\n";
		}
	} else if (cpaymenttype.value == "hosting") {
		if (cwebhostingoption.value == "") {
			errMsg += "You must select a webhosting option.\n";
		}
	} else if (cpaymenttype.value == "maintenance") {
		if (cmaintenanceoption.value == "") {
			errMsg += "You must select a maintenance option.\n";
		}
	}

	if ((ccardtype.value == "") || (ccardtype.value == "BLANK")) {
		errMsg += "You must select a credit card type.\n";
	}

	if (ccardname.value == "Exact name on credit card") {
		errMsg += "You must enter the exact name on the credit card.\n";
	}

	if (ccardnumber.value == "16 digit card number") {
		errMsg += "You must enter the credit card number.\n";
	}

	if (ccardexpirymonth.value == "MM") {
		errMsg += "You must enter the credit card expiry month.\n";
	}

	if (ccardexpiryyear.value == "YY") {
		errMsg += "You must enter the credit card expiry year.\n";
	}

	if (errMsg != "") {
		alert(errMsg);
		return false;
	} else {
		// If we are going to submit the form, then we should
		// clear up any fields that were not filled out properly
		
		if (document.getElementById('payment').Company.value == "Your company name") { document.getElementById('payment').Company.value = ""; }
		if (document.getElementById('payment').Phone.value == "Your phone number") { document.getElementById('payment').Phone.value = ""; }
		if (document.getElementById('payment').Notes.value == "Enter any additional notes you may have") { document.getElementById('payment').Notes.value = ""; }

		return true;
	}

}


function calcDeposit() {

	document.getElementById('payment').DepositRequired.value = Math.round((document.getElementById('payment').EstimateAmount.value/2) * 100) / 100;

}

