// Valid canadian postal code
var pcodeexp = /^[g,h,j,k,l,m,n,p,t,v][0-9][a-z][0-9][a-z][0-9]$/i ;
var iens6 = document.all || document.getElementById ? true : false;
var ns4 = document.layers ? true : false;

function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}
var isIE = document.all?true:false;
var isNS = document.layers?true:false;
function onlyDigits(e) {
var _ret = true;
if (isIE) {
if (window.event.keyCode < 46 || window.event.keyCode > 57) {
window.event.keyCode = 0;
_ret = false;
}
}
if (isNS) {
if (e.which < 46 || e.which > 57) {
e.which = 0;
_ret = false;
}
}
return (_ret); 
}
function FamilyApp_onsubmit() 
{	
	if ( document.FamilyApp.Username.value == "" )
	{
		window.alert("Please enter your username.");
		document.FamilyApp.Username.focus();
		return false;
	}
	if ( document.FamilyApp.Password.value == "" )
	{
		window.alert("Please enter a password.");
		document.FamilyApp.Password.focus();
		return false;
	}
	if ( document.FamilyApp.Address.value == "" )
	{
		window.alert("Please enter your address");
		document.FamilyApp.Address.focus();
		return false;
	}
	if ( document.FamilyApp.City.value == "" )
	{
		window.alert("Please enter your city");
		document.FamilyApp.City.focus();
		return false;
	}
	if ( document.FamilyApp.Province.selectedIndex == 0 )
	{
		window.alert("Please select your province");
		document.FamilyApp.Province.focus();
		return false;
	}	
	if ( document.FamilyApp.PostalCode.value == "" )
	{
		window.alert("Please fill in your Postal Code");
		document.FamilyApp.PostalCode.focus();
		return false;
	}
	else
	{
        if (!/[A-Z][0-9][A-Z][\s-]?[0-9][A-Z][0-9]/i.test(document.FamilyApp.PostalCode.value))
        {
			alert("The Postal Code entered is invalid. Please enter it in one of the following formats: M4S 2G9  M4S2G9 M4S-2G9 ");
			document.FamilyApp.PostalCode.focus();
			return false;
        }
    } 
	if (document.FamilyApp.FamilyEmail.value == "" || !(/[\w-_]+@[\w-_]+\.\w{2,}/i.test(document.FamilyApp.FamilyEmail.value)))
	{
		window.alert("Please enter a valid email address!");
		document.FamilyApp.FamilyEmail.focus();
		return false;
	}	
	else
	{
		var atsymbol = parseInt(document.FamilyApp.FamilyEmail.value.indexOf("@"));
		var periodchar = parseInt(document.FamilyApp.FamilyEmail.value.indexOf("."));
		var courriel_len = parseInt(document.FamilyApp.FamilyEmail.value.length);
		if (document.FamilyApp.FamilyEmail.value == "" || atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar)  
		{
			alert("Please enter a valid email address");
			document.FamilyApp.FamilyEmail.focus();
			return (false);
		}
	}
	
	if ( String(document.FamilyApp.FamilyAreaCode.value + document.FamilyApp.FamilyPhone1.value + document.FamilyApp.FamilyPhone2.value ).length != 10 || !(/\d{10}/.test(String(document.FamilyApp.FamilyAreaCode.value + document.FamilyApp.FamilyPhone1.value + document.FamilyApp.FamilyPhone2.value))))
	{
		window.alert("Please enter your at least one phone number so that our customer service team can contact you.");
		document.FamilyApp.FamilyAreaCode.focus();
		return false;
	}
}

function NannyApp_onsubmit() 
{	
	if ( document.NannyApp.Username.value == "" )
	{
		window.alert("Please enter your username.");
		document.NannyApp.Username.focus();
		return false;
	}
	if ( document.NannyApp.Password.value == "" )
	{
		window.alert("Please enter a password.");
		document.NannyApp.Password.focus();
		return false;
	}
	if ( document.NannyApp.NannyFName.value == "" )
	{
		window.alert("Please enter your first name.");
		document.NannyApp.NannyFName.focus();
		return false;
	}
	if ( document.NannyApp.NannyLName.value == "" )
	{
		window.alert("Please enter your last name.");
		document.NannyApp.NannyLName.focus();
		return false;
	}
	if ( document.NannyApp.Address.value == "" )
	{
		window.alert("Please enter your address");
		document.NannyApp.Address.focus();
		return false;
	}
	if ( document.NannyApp.City.value == "" )
	{
		window.alert("Please enter your city");
		document.NannyApp.City.focus();
		return false;
	}
	if ( document.NannyApp.Province.selectedIndex == 0 )
	{
		window.alert("Please select your province");
		document.NannyApp.Province.focus();
		return false;
	}	
	if ( document.NannyApp.PostalCode.value == "" )
	{
		window.alert("Please fill in your Postal Code");
		document.NannyApp.PostalCode.focus();
		return false;
	}
	else
	{
        if (!/[A-Z][0-9][A-Z][\s-]?[0-9][A-Z][0-9]/i.test(document.NannyApp.PostalCode.value))
        {
			alert("The Postal Code entered is invalid. Please enter it in one of the following formats: M4S 2G9  M4S2G9 M4S-2G9 ");
			document.NannyApp.PostalCode.focus();
			return false;
        }
    } 
	if (document.NannyApp.HomeEmail.value == "" || !(/[\w-_]+@[\w-_]+\.\w{2,}/i.test(document.NannyApp.HomeEmail.value)))
	{
		window.alert("Please enter a valid email address!");
		document.NannyApp.HomeEmail.focus();
		return false;
	}	
	else
	{
		var atsymbol = parseInt(document.NannyApp.HomeEmail.value.indexOf("@"));
		var periodchar = parseInt(document.NannyApp.HomeEmail.value.indexOf("."));
		var courriel_len = parseInt(document.NannyApp.HomeEmail.value.length);
		if (document.NannyApp.HomeEmail.value == "" || atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar)  
		{
			alert("Please enter a valid email address");
			document.NannyApp.HomeEmail.focus();
			return (false);
		}
	}
	
	if ( String(document.NannyApp.HomeAreaCode.value + document.NannyApp.HomePhone1.value + document.NannyApp.HomePhone2.value ).length != 10 || !(/\d{10}/.test(String(document.NannyApp.HomeAreaCode.value + document.NannyApp.HomePhone1.value + document.NannyApp.HomePhone2.value))))
	{
		window.alert("Please enter your phone number.");
		document.NannyApp.HomeAreaCode.focus();
		return false;
	}
	if ( document.NannyApp.EmergName.value == "" )
	{
		window.alert("Please enter the name of your emergency contact.");
		document.NannyApp.EmergName.focus();
		return false;
	}
	if ( String(document.NannyApp.ContactAreaCode.value + document.NannyApp.ContactPhone1.value + document.NannyApp.ContactPhone2.value ).length != 10 || !(/\d{10}/.test(String(document.NannyApp.ContactAreaCode.value + document.NannyApp.ContactPhone1.value + document.NannyApp.ContactPhone2.value))))
	{
		window.alert("Please enter a phone number for your emergency contact.");
		document.NannyApp.ContactAreaCode.focus();
		return false;
	}
	
	//Validation of My Employment Preferences
	var PreferLiveIn = false;
	for (counter = 0;  counter < NannyApp.PreferLiveIn.length; counter++)
	{
	if (NannyApp.PreferLiveIn[counter].checked)
	PreferLiveIn = true; 
	}
	if (!PreferLiveIn)
	{
		alert("Do you prefer to live inside or outside the employment home?");
		return (false);
	}
	var NewbornExperience = false;
	for (counter = 0;  counter < NannyApp.NewbornExperience.length; counter++)
	{
	if (NannyApp.NewbornExperience[counter].checked)
	NewbornExperience = true; 
	}
	if (!NewbornExperience)
	{
		alert("Do you have any newborn experience?");
		return (false);
	}

	var SpecialNeeds = false;
	for (counter = 0;  counter < NannyApp.SpecialNeeds.length; counter++)
	{
	if (NannyApp.SpecialNeeds[counter].checked)
	SpecialNeeds = true; 
	}
	if (!SpecialNeeds)
	{
		alert("Do you have any special needs experience?");
		return (false);
	}		
	
	//Validation of Additional Information
	var CurrentCertificates = false;
	for (counter = 0;  counter < NannyApp.CurrentCertificates.length; counter++)
	{
	if (NannyApp.CurrentCertificates[counter].checked)
	CurrentCertificates = true; 
	}
	if (!CurrentCertificates)
	{
		alert("Do you have current First Aid/CPR certificates?");
		return (false);
	}
	var WillingCertificates = false;
	for (counter = 0;  counter < NannyApp.WillingCertificates.length; counter++)
	{
	if (NannyApp.WillingCertificates[counter].checked)
	WillingCertificates = true; 
	}
	if (!WillingCertificates)
	{
		alert("Are you willing to take a First Aid/CPR course?");
		return (false);
	}	
	var Swimmer = false;
	for (counter = 0;  counter < NannyApp.Swimmer.length; counter++)
	{
	if (NannyApp.Swimmer[counter].checked)
	Swimmer = true; 
	}
	if (!Swimmer)
	{
		alert("Are you a competent swimmer?");
		return (false);
	}
	var Smoker = false;
	for (counter = 0;  counter < NannyApp.Smoker.length; counter++)
	{
	if (NannyApp.Smoker[counter].checked)
	Smoker = true; 
	}
	if (!Smoker)
	{
		alert("Are you a smoker, social or otherwise?");
		return (false);
	}
	var Pets = false;
	for (counter = 0;  counter < NannyApp.Pets.length; counter++)
	{
	if (NannyApp.Pets[counter].checked)
	Pets = true; 
	}
	if (!Pets)
	{
		alert("Are you comfortable with pets?");
		return (false);
	}
	var OwnChildren = false;
	for (counter = 0;  counter < NannyApp.OwnChildren.length; counter++)
	{
	if (NannyApp.OwnChildren[counter].checked)
	OwnChildren = true; 
	}
	if (!OwnChildren)
	{
		alert("Do you have children of your own?");
		return (false);
	}
	
	var Allergies = false;
	for (counter = 0;  counter < NannyApp.Allergies.length; counter++)
	{
	if (NannyApp.Allergies[counter].checked)
	Allergies = true; 
	}
	if (!Allergies)
	{
		alert("Do you have any allergies?");
		return (false);
	}
	//Validation of drivers/vehicles information
	var DriverLicense = false;
	for (counter = 0;  counter < NannyApp.DriverLicense.length; counter++)
	{
	if (NannyApp.DriverLicense[counter].checked)
	DriverLicense = true; 
	}
	if (!DriverLicense)
	{
		alert("Do you have a full Canadian Driver's License?");
		return (false);
	}	
	var LicenseSuspended = false;
	for (counter = 0;  counter < NannyApp.LicenseSuspended.length; counter++)
	{
	if (NannyApp.LicenseSuspended[counter].checked)
	LicenseSuspended = true; 
	}
	if (!LicenseSuspended)
	{
		alert("Have you ever had your license suspended?");
		return (false);
	}	
	var ExperiencedDriver = false;
	for (counter = 0;  counter < NannyApp.ExperiencedDriver.length; counter++)
	{
	if (NannyApp.ExperiencedDriver[counter].checked)
	ExperiencedDriver = true; 
	}
	if (!ExperiencedDriver)
	{
		alert("Are you an experienced driver?");
		return (false);
	}
	var StandardTransmission = false;
	for (counter = 0;  counter < NannyApp.StandardTransmission.length; counter++)
	{
	if (NannyApp.StandardTransmission[counter].checked)
	StandardTransmission = true; 
	}
	if (!StandardTransmission)
	{
		alert("Can you drive a standard transmission/shift?");
		return (false);
	}
	//Validation of legal information
	var CriminalRecord = false;
	for (counter = 0;  counter < NannyApp.CriminalRecord.length; counter++)
	{
	if (NannyApp.CriminalRecord[counter].checked)
	CriminalRecord = true; 
	}
	if (!CriminalRecord)
	{
		alert("Do you have a criminal record?");
		return (false);
	}
	var PoliceCheck = false;
	for (counter = 0;  counter < NannyApp.PoliceCheck.length; counter++)
	{
	if (NannyApp.PoliceCheck[counter].checked)
	PoliceCheck = true; 
	}
	if (!PoliceCheck)
	{
		alert("Are you willing to have a police check?");
		return (false);
	}
	if (document.NannyApp.OptIn.checked == false)
	{
		alert('Please acknowledge that the information provided is true.');
		document.NannyApp.OptIn.focus();
		return false;
	} 
	var agree = confirm("Thank you for submitting your application to Shelly's Nannies Inc. Please click 'Agree' to continue.");
	//if (agree == false)

	if (agree)
	{
		return true ;
	}
	else
	{
		return false ;
	}
}

function isValid(pattern, str) 
{
    if ( !pattern.test(str) )
       {
            return false;
       }
    else
            return true;
}
	                
function ltrim( cStr )
{
	cStr	=	String(cStr);
	if ( cStr == "0" || cStr == 'null' || cStr.substr(0,3) == '000' )
		return "";
	var oReg = /^(\s+)/;
	return cStr.replace(oReg,'');
}


function rtrim( cStr )
{
	cStr	=	String(cStr);
	var oReg = /(\s+)$/;
	return cStr.replace(oReg,'');
}


function alltrim( cStr )
{
	if (String(cStr) == 'null' )
		return "";
	else
		return ltrim(rtrim(cStr));
}

function strtran( cStr )
{
	cStr	=	String(cStr);
	if ( cStr == '')
		return "";
		
	var oReg = /\s/g;
	return cStr.replace(oReg,'');

}

function checkLength(curr, next)
	{
	if (curr.value.length == curr.maxLength && iens6)
		{
		next.focus();
		}
	}
//-->