function register_move_to( form, regStep){form.RegisterStep.value = regStep;form.submit();return true;}
function register_validate_college(form){if( util_menu_compare_value( form.app_courseStartDate, "Please Select" ) ){alert("Please select a start date.");form.app_courseStartDate.focus();return false;}}
function register_validate_form( form )
{
	if( util_menu_compare_value( form.app_partnerCollege, "Please Select" ) )
	{
		alert("Please select a partner college.");
		form.app_partnerCollege.focus();
		return false;
	}
	if( form.app_familyName.value.length == 0 )
	{
		alert("Please enter your family name.");
		form.app_familyName.focus();
		return false;
	}
	if( form.app_firstName.value.length == 0 )
	{
		alert("Please enter your first name.");
		form.app_firstName.focus();
		return false;
	}
	if( form.app_gender.value.length == 0 )
	{
		alert("Please select your gender.");
		form.app_gender.focus();
		return false;
	}
	if( form.app_address.value.length == 0 )
	{
		alert("Please enter your street address.");
		form.app_address.focus();
		return false;
	}
	if( !util_menu_compare_value( form.app_province, "City / Country Outside Canada" )  && form.app_city.value.length == 0 )
	{
		alert("Please enter your city.");
		form.app_city.focus();
		return false;
	}
	if( util_menu_compare_value( form.app_province, "Please Select" ) )
	{
		alert("Please select your province.");
		form.app_province.focus();
		return false;
	}
	if( util_menu_compare_value( form.app_province, "City / Country Outside Canada" ) )
	{
		if( form.app_city_country_other.value.length == 0 )
		{
			alert("Please enter your city or country");
			form.app_city_country_other.focus();
			return false;
		}
	}
	if( !util_menu_compare_value( form.app_province, "City / Country Outside Canada" )  && form.app_postalCode.value.length == 0 )
	{
		alert("Please enter your postal code.");
		form.app_postalCode.focus();
		return false;
	}
	if( !util_validate_phone("app_workPhone",false) )
		return false;
		
	if( !util_validate_numeric( form.app_workExtension, false ) )
	{
		alert("Please enter a valid extension.");
		form.app_workExtension.focus();
		return false;	
	}
	if( !util_validate_phone("app_homePhone",true) )
		return false;	
		
	if( form.app_email.value.length == 0 ||	!util_validate_email( form.app_email ) )
	{
		alert("Please enter a valid email address.");
		form.app_email.focus();
		return false;
	}
	if( !util_validate_date("app_dateOfBirth", false) )
		return false;

	if( !util_validate_date("app_dateOfEntry", true) )
		return false;		
	return true;
}

function update_city_field( inputObject, targetObject )
{
	if( inputObject.value == "City / Country Outside Canada" )
	{
		divObj = document.getElementById("cityCountryOtherTitle");
		divObj.style.display = "";
		divObj = document.getElementById("cityCountryOther");
		divObj.style.display = "";
		targetObject.focus();
		document.form_application.app_postalCode.value = "N/A";
	}
	else
	{
		divObj = document.getElementById("cityCountryOtherTitle");
		divObj.style.display = "none";
		divObj = document.getElementById("cityCountryOther");
		divObj.style.display = "none";	
		targetObject.value = "";
	}
}


function register_validate_payment( form )
{
	if( util_menu_compare_value( form.app_chargeType, "Please Select" ) )
	{
		alert("Please select your credit card.");
		form.app_chargeType.focus();
		return false;
	}
	if( form.app_chargeNum.value.length == 0 ||	!util_validate_numeric(form.app_chargeNum,false)  )
	{
		alert("Please enter your credit card number.");
		form.app_chargeNum.focus();
		return false;
	}
	if( form.app_chargeHolder.value.length == 0 )
	{
		alert("Please enter you name as is appears on the credit card.");
		form.app_chargeHolder.focus();
		return false;
	}
	
	if( util_menu_compare_value( form.app_chargeType, "Please Select" ) )
	{
		alert("Please select your credit card.");
		form.app_chargeType.focus();
		return false;
	}
	if( util_menu_compare_value( form.app_chargeExpiry_Month, "--" ) )
	{
		alert("Please select a valid expiration date.");
		form.app_chargeExpiry_Month.focus();
		return false;
	}
	if( util_menu_compare_value( form.app_chargeExpiry_Year, "--" ) )
	{
		alert("Please select a valid expiration date.");
		form.app_chargeExpiry_Year.focus();
		return false;
	}
	return true;
}

//==============================================================================
//Admin end

function admin_validate_app_list_delete( form, cbstr )
{
	var numApplications = 0;
	for( var i =0; i<form.elements.length; i++ )
	{
		if( (form.elements[i].type == 'checkbox') &&
			form.elements[i].checked &&
			(form.elements[i].name.substr(0,cbstr.length) == cbstr ) )
			numApplications++;
	}
	if( numApplications == 0 )
	{
		alert("Please select applications from the list.");
		return false;
	}

	if( !confirm( "Are you sure you want to permanently delete the selected applications ?" ) )
		 return false;
	return true;
}

function admin_validate_app_delete( form ){if( !confirm( "Are you sure you want to permanently delete this application ?" ) ){return false;}return true;}
function admin_validate_form( form )
{
	var studentObj = document.getElementById( 'StudentId' );
	if( studentObj != null )
	{
		if( form.stuFamilyName.value.length == 0 )
		{
			alert("Please enter the family name.");
			form.stuFamilyName.focus();
			return false;
		}
		if( form.stuFirstName.value.length == 0 )
		{
			alert("Please enter the first name.");
			form.stuFirstName.focus();
			return false;
		}
		if( form.stuGender.value.length == 0 )
		{
			alert("Please sleect a gender.");
			form.stuFirstName.focus();
			return false;
		}
		if( form.stuAddress.value.length == 0 )
		{
			alert("Please enter the street address.");
			form.stuAddress.focus();
			return false;
		}
		if( !util_menu_compare_value( form.stuProvince, "City / Country Outside Canada" )  && form.stuCity.value.length == 0 )
		{
			alert("Please enter the city.");
			form.stuCity.focus();
			return false;
		}
		if( util_menu_compare_value( form.stuProvince, "Please Select" ) )
		{
			alert("Please select the province.");
			form.stuProvince.focus();
			return false;
		}
		if( form.stuPostalCode.value.length == 0 )
		{
			alert("Please enter the postal code.");
			form.stuPostalCode.focus();
			return false;
		}
		if( !util_validate_phone("stuWorkPhone",false) )
			return false;
			
		if( !util_validate_numeric( form.stuWorkExtension, false ) )
		{
			alert("Please enter a valid extension.");
			form.stuWorkExtension.focus();
			return false;
		}
		if( !util_validate_phone("stuHomePhone",true) )
			return false;				

		if( form.stuEmail.value.length == 0 ||	!util_validate_email( form.stuEmail ) )
		{
			alert("Please enter your email address.");
			form.stuEmail.focus();
			return false;
		}
		//these will not be available unless we are an EA.
		var edSin = document.getElementsByName('stuSin');
		if( edSin != null && edSin.length != 0 )
		{
			if( !util_validate_date("stuDateOfBirth", false) )
				return false;
			if( !util_validate_date("stuDateOfEntry", true) )
				return false;				
		}
	}
	
	//validate denied
	if( util_menu_compare_value( form.appStatus, "Lead: Denied" ) )
	{
		if( form.appComments.value.length == 0 )
		{
			alert("Please enter the denial reason.");
			form.appComments.focus();
			return false;
		}
	}
	return true;
}
function admin_validate_profile_form( form ){if( form.email.value.length == 0){alert("Please enter an email address");form.email.focus();return false;}if( form.proNewPass.value.length > 0 ){if( form.proCurPass.value.length == 0 ){alert("Please enter your current password.");form.proCurPass.focus();return false;}if( form.proNewPass.value.length == 0 ){alert("Please enter your new password.");form.proNewPass.focus();return false;}if( form.proNewPass2.value.length == 0 ){alert("Please re-enter your new password.");form.proNewPass2.focus();return false;}}return true;}

//==============================================================================

var g_applicationPopup = null;
function application_popup_view(urlToOpen){if ( g_applicationPopup != null && !g_applicationPopup.closed ){g_applicationPopup.location.href = urlToOpen.toString();}else{var width = 800;var height = 550;var xPos =  (screen.width) ? (screen.width-width)/2 : 0;var yPos = (screen.height) ? (screen.height-height)/2 : 0;g_applicationPopup = open( urlToOpen.toString(), "EcaAppsPopupView","resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,fullscreen=no,width="+width+",height="+height+",left="+xPos+",top="+yPos,true );if( g_applicationPopup.opener == null ){g_applicationPopup.opener = self;}}g_applicationPopup.focus();}
function application_delete(index)
{
	if( confirm("Are you sure you want to permanently delete this registration ?") )
	{
		url = "" + $F('appdurl');
		p1 = "" + $F('appid_' + index);
		p2 = "" + $F('apphash_'+index);
		if( p1.length > 0 && p2.length > 0 )
		{
			new Ajax.Request(url, {
				method:'post',
				parameters:{appid:p1,apphash:p2},
				onSuccess:function(transport)
				{
					var json = transport.responseText.evalJSON(true);
					if( json.error != null )
					{	Messenger.notice("" + json.error);	}
					else
					{
						if( json.deleted != null )
						{
							new Effect.Fade('approw_' + index);
							Messenger.notice("Registration deleted", Messenger.timeout);
							
							t = parseInt( $F("tapp"), 10 ); t = t-1;
							if( t == 0 )
							{	location.reload();	}
							else
							{	$('tapp').value = t;	}
						}
						else
						{
							new Effect.Highlight('approw_' + index);
							Messenger.notice("Unable to delete Registration", Messenger.timeout);
						}
					}
				},
				onFailure:function(transport)
				{
					new Effect.Highlight('approw_' + index);
					Messenger.notice("Unable to delete Registration", Messenger.timeout);
				}
			});
		}
	}
}

function updateStartEndDates(inputObj){document.form_application.app_courseStartDate.selectedIndex = inputObj.selectedIndex;document.form_application.app_courseEndDate.selectedIndex = inputObj.selectedIndex;}
function updateRegEndDates(inputObj)
{
	deadlineObj = document.getElementById("app_courseDeadline");
	deadlineTEXTObj = document.getElementById("courseDeadlineTEXT");
	deadlineNS6Obj = document.getElementById("deadline_NETSCAPE6");
	
	endDateObj = document.getElementById("app_courseEndDate");
	endDateTEXTObj = document.getElementById("courseEndDateTEXT");	
	endDateNS6Obj = document.getElementById("endDate_NETSCAPE6");	

	deadlineObj.selectedIndex = inputObj.selectedIndex;
	endDateObj.selectedIndex = inputObj.selectedIndex;

	if( parseInt(inputObj.selectedIndex) == 0 )
	{
		deadlineTEXTObj.value = "";
		endDateTEXTObj.value = "";
	}
	else
	{
		if( deadlineObj.value == "1900-01-01 00:00:00")
		{	deadlineTEXTObj.value = "Continuous";	}
		else
		{
			var myDateReg  = getDateFromFormat(deadlineObj.value, "yyyy-MM-dd HH:mm:ss");
			var toPrintReg = formatDate(myDateReg, "dd-NNN-yyyy");
			deadlineTEXTObj.value = toPrintReg;
		}
		deadlineNS6Obj.value = deadlineObj.value;
		
		if( endDateObj.value == "1900-01-01 00:00:00")
		{	endDateTEXTObj.value = "Continuous";	}
		else
		{
			var myDateEnd  = getDateFromFormat(endDateObj.value, "yyyy-MM-dd HH:mm:ss");
			var toPrintEnd = formatDate(myDateEnd, "dd-NNN-yyyy");
			endDateTEXTObj.value = toPrintEnd;
		}
		endDateNS6Obj.value = endDateObj.value;
	}
}

function updateRegStartDates(inputObj){document.form_application.app_courseStartDate.selectedIndex = inputObj.selectedIndex;document.form_application.app_courseDeadline.selectedIndex = inputObj.selectedIndex;}
