function SubmitContactForm(FORM)
{
	var State = FORM.State.options[FORM.State.options.selectedIndex].value;
	var FirstName = FORM.FirstName.value;
	var LastName = FORM.LastName.value;
	var Company = FORM.Company.value;
	var Telephone = FORM.Telephone.value;
	var Email = FORM.Email.value;
	var Email2 = FORM.Email2.value;
	var Street1 = FORM.Street1.value;
	var Street2 = FORM.Street2.value;
	var City = FORM.City.value;
	var Zip = FORM.Zip.value;
	var Country = FORM.Country.value;
	var TimeFrame = FORM.TimeFrame;
	
	var Errors = false;		
	if (FirstName.length==0)
	{
		document.getElementById("FirstNameLabel").className="Emphasize";
		Errors=true;
	}
	if (LastName.length==0)
	{
		document.getElementById("LastNameLabel").className="Emphasize";
		Errors=true;
	}
	if (Telephone.length==0)
	{
		document.getElementById("TelephoneLabel").className="Emphasize";
		Errors=true;
	}
	if (Email.length < 6 || Email.indexOf("@") == -1 || Email.indexOf(".") == -1 || (Email.lastIndexOf(".") < Email.lastIndexOf("@")))
	{
		document.getElementById("EmailLabel").className="Emphasize";
		document.getElementById("Email").className="Emphasize";
		Errors=true;
	}
	else if (Email != Email2)
	{
		document.getElementById("Email2Label").className="Emphasize";
		document.getElementById("Email2").className="Emphasize";
		Errors=true;
	}
	
	if (Street1.length==0)
	{
		document.getElementById("Street1Label").className="Emphasize";
		Errors=true;
	}
	if (City.length==0)
	{
		document.getElementById("CityLabel").className="Emphasize";
		Errors=true;
	}
	if (Zip.length < 5)
	{
		document.getElementById("ZipLabel").className="Emphasize";
		Errors=true;
	}
	if (Country.length==0)
	{
		document.getElementById("CountryLabel").className="Emphasize";
		Errors=true;
	}
	if (TimeFrame.selectedIndex==0)
	{
		document.getElementById("TimeFrameLabel").className="Emphasize";
		Errors=true;
	}
	
	if (Errors || !somechecked)
	{
		if (!somechecked)
		{
			alert("You must select at least one class of interest.");
		}
		else
		{
			alert("Please fix the highlighted errors.");
		}
		return false;
	}
	else
	{
		return true;
	}
}

function ShowOutline(COURSEID,PARTNERID)
{
	var OutlineWin = window.open("Courses/" + COURSEID + ".cfm?PartnerID=" + PARTNERID,OutlineWin,"height=500,width=500,scrollbars=1,resizable=1,top=10,left=10");	
	OutlineWin.focus();
}

function Register(FORM)
{
	var Errors=true;
	for (i=0; i<FORM.elements.length; i++)
	{
		if (FORM.elements[i].checked)
		{
			return true;
		}
	}
	alert("Please select at least one course.");
	return false;
}

var discounts = new Array();  //has to stay in sync with VARIABLES.arrDiscounts in AyopRegisterPage.cfc
discounts["1"] = 0;
discounts["2"] = .1;
discounts["3-4"] = .15;
discounts["5-9"] = .2;
discounts["10-24"] = .25;
discounts["25-49"] = .3;
discounts["50-99"] = .35;
discounts["100-199"] = .4;
discounts["200+"] = .5;


function setAyopPrice(FORM)
{
	var numStudents = FORM.NumStudents.options[FORM.NumStudents.selectedIndex].value;
	var seriesPerStudent = getNumSeries(FORM.SeriesList.value);
	var numSeries = numStudents * seriesPerStudent;
	document.getElementById("numSeriesCell").innerHTML = numSeries;
	var tp = numStudents * FORM.PricePerStudent.value/(1-FORM.StudentDiscount.value);
	
	var discount = 0;
	var discountMarker = "";
	var i=0;
	for (d in discounts) //Sets the discount;
	{
		i++;
		if (numSeries >= parseInt(d))
		{
			discount = discounts[d];
			discountMarker = "Discount" + i;
		}
	}

	var i=0;
	for (d in discounts)
	{
		i++;
		document.getElementById("Discount" + i).className="UnselectedDiscount";	
	}	
	document.getElementById(discountMarker).className="SelectedDiscount";
	var couponDiscount = FORM.CouponDiscount.value;
	
	tp *= (1-discount);
	tp *= (1-couponDiscount);
	FORM.Discount.value = discount;
	FORM.TotalPrice.value=tp;
	document.getElementById("TotalPriceSpan").innerHTML=DollarFormat(tp);
	document.getElementById("DollarPricePerSeries").innerHTML=DollarFormat(tp/numSeries);
}

function getNumSeries(strSeries)
{
	var arrSeries = strSeries.split(",");
	var numSeries = arrSeries.length;
	return numSeries;
}

function fillAYOPForm()
{
	var f = document.AyopForm;
	f.FirstName.value = f.BillingFirstName.value;
	f.LastName.value = f.BillingLastName.value;
	f.Telephone.value = f.BillingTelephone.value;
	f.Email.value = f.BillingEmail.value;
	f.Email2.value = f.BillingEmail.value;
	f.Street1.value = f.BillingStreet1.value;
	f.Street2.value = f.BillingStreet2.value;
	f.City.value = f.BillingCity.value;
	f.Zip.value = f.BillingZip.value;
	
	for (i=0; i < f.State.options.length; i++)
	{
		if (f.State.options[i].value == f.BillingState.value)
		{
			f.State.options[i].selected=true;
			break;
		}
	}
}

function checkFreeEmail(EMAIL,NEXTFIELD)
{	
	var userEmail = EMAIL.value;
	var freeEmail = false;
	var arrFreeEmails = new Array("rediffmail.com", "hotmail.com", "yahoo.com", "gmail.com", "excite.com", "msn.com");	
	for (email in arrFreeEmails)
	{
		if (userEmail.indexOf(arrFreeEmails[email]) > -1)
		{
			freeEmail = true;	
		}
	}
	if (freeEmail)
	{
		var response = confirm("This appears to be a free email account.  As free email accounts are often used for credit card fraud, we'll have to verify that this purchase is legitimate and it may take us longer to set up your account. We encourage you to use a trackable email account for quicker access to your courses.  If you don't have one or would prefer to use the email address you have entered, click \"Cancel\".  To enter a different email address, click \"OK\".  Thanks.");
		if (response)
		{
			setTimeout(function() { try { EMAIL.focus(); EMAIL.select(); } catch(e) {} },10);
		}
		else
		{
			NEXTFIELD.focus();
		}
	}
}

function verifyCouponCode(CODE) {
	if (typeof couponCall != "undefined")
	{
		YAHOO.util.Connect.abort(couponCall);
	}
	var theForm = CODE.form;
	var couponMessage = document.getElementById("CouponMessage");
	if (CODE.value.length == 0)
	{
		couponMessage.innerHTML = "No coupon";
		theForm.CouponDiscount.value = "0";
		setPrice(theForm);
	}
	else
	{
		var callback =
		{
		  success: responseSuccess,
		  failure: responseFailure,
		  timeout: 4000
		}
		var sUrl = "Ajax/CheckCouponCode.cfm";
		var params = "CouponCode=" + CODE.value + "&SeriesList=" + theForm.SeriesList.value;
		couponCall = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params); 	
	}
	
	function responseSuccess(o) {  //Check if response is numeric, which indicates success
		if ( !isNaN(o.responseText) )
		{
			CODE.style.color="green";
			couponMessage.className="Success";	
			theForm.CouponDiscount.value = o.responseText;
			var discount = o.responseText * 100;
			couponMessage.innerHTML = "Additional " + discount + "% discount";
			setPrice(theForm);
		}
		else
		{
			CODE.style.color="red";	
			couponMessage.className="Failed";
			theForm.CouponDiscount.value = "0";
			couponMessage.innerHTML = o.responseText;	
			setPrice(theForm);
		}
	}
	
	function responseFailure(o) {
		alert("Unable to verify coupon code.  If you are sure you are using a proper code, please delete the coupon code and re-enter it.");	
	}
}


function verifyVoucherCode(CODE) {
	if (typeof voucherCall != "undefined")
	{
		YAHOO.util.Connect.abort(voucherCall);
	}
	var theForm = CODE.form;
	var voucherMessage = document.getElementById("VoucherMessage");
	if (CODE.value.length == 0)
	{
		voucherMessage.innerHTML = "No voucher";
	}
	else
	{
		var callback =
		{
		  success: responseSuccess,
		  failure: responseFailure,
		  timeout: 4000
		}
		var sUrl = "../Ajax/CheckVoucher.cfm";
		var params = "VoucherCode=" + CODE.value + "&SeriesList=" + theForm.SeriesList.value;
		voucherCall = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params); 	
	}
	
	function responseSuccess(o) {  //Check if response is numeric, which indicates success
		if ( !isNaN(o.responseText) )
		{
			CODE.style.color="green";
			voucherMessage.className="Success";	
		}
		else
		{
			CODE.style.color="red";	
			voucherMessage.className="Failed";
		}
	}
	
	function responseFailure(o) {
		alert("Unable to verify voucher code.  If you are sure you are using a proper code, please delete the voucher code and re-enter it.");	
	}
}
