function trim(s) 
{
	while (s.substring(0,1) == ' ') 
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ') 
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}
/////////////////////////////////////////
function isValidDate(day,month,year){
	var dteDate;

	//set up a Date object based on the day, month and year arguments
	//javascript months start at 0 (0-11 instead of 1-12)
	dteDate=new Date(year,month,day);


	return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}
/////////////////////////////////////////
function compareDates(startDateStr, endDateStr)
{
	/* create new date objects */
	var StartDate = new Date( startDateStr );
	var EndDate = new Date( endDateStr );
	
//	alert (StartDate);
//	alert (EndDate);
	if (StartDate >= EndDate)
	{
		//alert(StartDate >= EndDate);
		return false;
	}
	else
	{
		//alert(StartDate >= EndDate);
		return true;
	}

}
////////////////////////
function checkEmail(myString) 
{
	var newString = myString.match(/\b(^(\S+@\S+)+((.com)|(.biz)|(.net)|(.edu)|(.mil)|(.gov)|(.org)|(\..{2,2}))$)\b/gi);
	if (!newString) 
		return false;
	else 
	{
		return true;
	}
}
///////////////////////
function checkPI(f)
{

	if (trim(f.FirstName.value)=='')
	{
		alert("First name is a compulsory field. \n\nPlease enter your first name in the field provided in order to continue.");
		f.FirstName.focus();
		return false;
	}
	if (trim(f.LastName.value)=='')
	{
		alert("Last name is a compulsory field. \n\nPlease enter your last name in the field provided in order to continue.");
		f.LastName.focus();
		return false;
	}
	if (trim(f.Phone.value)=='')
	{
		alert("Contact phone number is a compulsory field. \n\nPlease ensure your correct phone number is entered in order to continue.");
		f.Phone.focus();
		return false;
	}
	if (!checkEmail(f.Email.value))
	{
		alert("Your email address is a compulsory field. \n\nPlease ensure that you correct email address is entered in order to continue.");
		f.Email.focus();
		return false;
	}
	if ((trim(f.Street1.value)=="") && (trim(f.Street2.value)==""))
	{
		alert("Your mailing address appears incomplete.\n\nPlease fill out at least one of the street fields provided.");
		f.Street1.focus();
		return false;
	}
	if (trim(f.Suburb.value)=="")
	{
		alert("Your mailing address appears incomplete.\n\nPlease enter suburb in the field provided.");
		f.Suburb.focus();
		return false;
	}
	if ((trim(f.State.value)=="") && (trim(f.Country.value)==""))
	{
		alert("Your mailing address appears incomplete.\n\nPlease specify either a state or a country in order to continue.");
		f.State.focus();
		return false;
	}
	if (trim(f.PostCode.value)=="")
	{
		alert("Your mailing address appears incomplete.\n\nPlease enter post code in the field provided.");
		f.PostCode.focus();
		return false;
	}

	
	return true;
}
/////////////////////////////////////

function checkPC(f)
{
	if (trim(f.OldPassword.value)=="")
	{
		alert("Old Password is a compulsory field.\n\n Please enter your current password in this field in order to continue.");
		f.OldPassword.focus();
		return false;
	}
	var newPwd = String(trim(f.NewPassword.value))
	if (newPwd.length < 6)
	{
		alert("New Password is a compulsory field.\n\n Please note that your password should be at least 6 characters long and you should use a mix ofletters and numbers.\n\nPlease enter your noew password in order to continue.");
		f.NewPassword.focus();
		return false;
	}
	if (f.NewPassword.value != f.NewPassword1.value)
	{
		alert("Repeated Password does not match New Password. \n\nPlease ensure that you type the same password in both fields in order to continue.");
		f.NewPassword1.focus();
		return false;
	}

}
/////////////////////////////
function retrievePassword(f1,f2)
{
	if (!checkEmail(f1.Email.value))
	{
		alert("The email specified does not appear to be a valid email address.\n\nPlease correct this entry and try again.");
		f1.Email.focus();
		return false;
	}else
	{
		f2.Email.value = f1.Email.value;
		return true;
	}
}

/////////////////////////////
function checkNewPI(f)
{

	if (trim(f.FirstName.value)=='')
	{
		alert("First name is a compulsory field. \n\nPlease enter your first name in the field provided in order to continue.");
		f.FirstName.focus();
		return false;
	}
	if (trim(f.LastName.value)=='')
	{
		alert("Last name is a compulsory field. \n\nPlease enter your last name in the field provided in order to continue.");
		f.LastName.focus();
		return false;
	}
	if (trim(f.Phone.value)=='')
	{
		alert("Contact phone number is a compulsory field. \n\nPlease ensure your correct phone number is entered in order to continue.");
		f.Phone.focus();
		return false;
	}
	if (!checkEmail(f.Email.value))
	{
		alert("Your email address is a compulsory field. \n\nPlease ensure that you correct email address is entered in order to continue.");
		f.Email.focus();
		return false;
	}
	var newPwd = String(trim(f.NewPassword.value))
	if (newPwd.length < 6)
	{
		alert("Password is a compulsory field.\n\n Please note that your password should be at least 6 characters long and you should use a mix of letters and numbers.\n\nPlease enter your noew password in order to continue.");
		f.NewPassword.focus();
		return false;
	}
	if (f.NewPassword.value != f.NewPassword1.value)
	{
		alert("Repeated Password does not match the original Password entry. \n\nPlease ensure that you type the same password in both fields in order to continue.");
		f.NewPassword1.focus();
		return false;
	}
	if ((trim(f.Street1.value)=="") && (trim(f.Street2.value)==""))
	{
		alert("Your mailing address appears incomplete.\n\nPlease fill out at least one of the street fields provided.");
		f.Street1.focus();
		return false;
	}
	if (trim(f.Suburb.value)=="")
	{
		alert("Your mailing address appears incomplete.\n\nPlease enter suburb in the field provided.");
		f.Suburb.focus();
		return false;
	}
	if ((trim(f.State.value)=="") && (trim(f.Country.value)==""))
	{
		alert("Your mailing address appears incomplete.\n\nPlease specify either a state or a country in order to continue.");
		f.State.focus();
		return false;
	}
	if (trim(f.PostCode.value)=="")
	{
		alert("Your mailing address appears incomplete.\n\nPlease enter post code in the field provided.");
		f.PostCode.focus();
		return false;
	}

	
	return true;
}

