<!---

function openInstructions()
{
	window.open('instructions.php', '', 'resizable=no,scrollbars=yes,width=480,height=330');
}

function doDates()
{
	window.open('dates.php', '', 'resizable=no,scrollbars=yes,width=500,height=530');
}

function closeSearch() 
{
	window.opener.document.frmAppointment.area.value = document.frmSuburb.selId.value;
	window.opener.document.frmAppointment.suburb.value = document.frmSuburb.selSuburb.value;
	window.close();
}

function validateModification()
{
	fs = new formValidator();
	//date validation 
	var d = new Date();
	Year = new String(d.getFullYear());
  
	Month = d.getMonth()+1;
	if (Month < 10)
		Month = "0"+Month;
	
	Day = d.getDate();
	if (Day < 10)
		Day = "0"+Day;

	aVal = Year+Month+Day;
  
	bVal = Year+"-"+Month+"-"+Day;
  
	if (!fs.isEmpty("appt_datetime"))
	{
  		var dateString = new String(document.frmAppointment.appt_datetime.value);
		var dateStringArray = dateString.split(document.frmAppointment.appt_datetime.value);
	
		var apptDate = dateString.substr(0, dateString.lastIndexOf("-")+3);
		
		var apptYear = apptDate.substr(0, 4);
		var apptMonth = apptDate.substr(5, 2);
		var apptDay = apptDate.substr(8,2);

  		var apptTime = dateString.substr(dateString.lastIndexOf("-")+4, dateString.length);
		
		//check appointment is not after or on same day as departure
		if (apptYear+apptMonth+apptDay >= fs.findObj("appt_departure_year").value+fs.findObj("appt_departure_month").value+fs.findObj("appt_departure_day").value)
			fs.raiseError("Appointment dates can only be made prior to your departure date.\n --- Please reconsider your appointment date.");

		//check appointment is not before today
		if (apptYear+apptMonth+apptDay <= aVal)
			fs.raiseError("Appointment dates can only be made for future dates.\n --- Please reconsider your appointment date.");

	}
	else
  		fs.raiseError("Please select the date & time you would like to schedule the appointment for.");
	//end date Validation
	
	if (fs.numErrors() > 0)
	{
		fs.displayErrors();
		return false;
	}
	else
	  return true;;
	  
	  

}

function validateLogin()
{
	fs = new formValidator();
	if (fs.isEmpty("passport_digits"))
		fs.raiseError("The Last 6 digits of your passport number must be specified.");
	
	if(fs.findObj("passport_digits").value.length < 6)
		fs.raiseError("Not enough digits to match your passport number to our database.");
	
	if (fs.numErrors() > 0)
	{
		fs.displayErrors();
		return false;
	}
	else
	  return true;
	
}

function validateAppointment()
{
	fs = new formValidator();
	
	if (fs.isEmpty("appt_name"))
		fs.raiseError("Your first name must be specified.");
	
	if (fs.isEmpty("appt_surname"))
		fs.raiseError("Your surname must be specified.");
		
	if (fs.isEmpty("applicant_address"))
		fs.raiseError("Your address must be specified.");
		
	if (!fs.isEmpty("appt_tel_no"))
	{
		if (!fs.isNumber("appt_tel_no"))
			fs.raiseError("Your contact number must be specified, in numeric format");
	}
	else
		fs.raiseError("Your contact number must be specified.");
	
	if (!fs.isEmpty("appt_email"))
	{
  		if (!fs.isEmailAddress("appt_email"))
			fs.raiseError("A valid email address must be specified");
	}
	else
		fs.raiseError("An email address must be specified");

	if (!fs.isEmpty("appt_no_applicant"))
	{
		if (!fs.isNumber("appt_no_applicant"))
			fs.raiseError("The number of applicants must be specified, in numeric format");
	}
	else
		fs.raiseError("The number of applicants must be specified.");
	//date validation 
	var d = new Date();
	Year = new String(d.getFullYear());
  
	Month = d.getMonth()+1;
	if (Month < 10)
		Month = "0"+Month;
	
	Day = d.getDate();
	if (Day < 10)
		Day = "0"+Day;

	aVal = Year+Month+Day;
  
	bVal = Year+"-"+Month+"-"+Day;
  	
	departureDate = formatDate("YYYYMMDD", document.frmAppointment.appt_departure_day.value, document.frmAppointment.appt_departure_month.value, document.frmAppointment.appt_departure_year.value);

  	//check if departure day is less than today
	if (departureDate < aVal)
  		fs.raiseError("departure dates can only be for the future.\n --- Please check your departure dates");
  	
	//check if departure day is equal to today
	if (departureDate == aVal)
  		fs.raiseError("departure dates can only be for the future.\n --- Please check your dates");

	var apptDate = "";
	if (!fs.isEmpty("appt_datetime"))
	{
  		var dateString = new String(document.frmAppointment.appt_datetime.value);
		var dateStringArray = dateString.split(document.frmAppointment.appt_datetime.value);
	
		apptDate = dateString.substr(0, dateString.lastIndexOf("-")+3);
		apptDate = formatDate("YYYYMMDD", apptDate.substr(8,2), apptDate.substr(5,2), apptDate.substr(0,4));
		
  		var apptTime = dateString.substr(dateString.lastIndexOf("-")+4, dateString.length);
		
		//check if departure date is less than appointment date
		if (departureDate < apptDate)
	  		fs.raiseError("You cannot depart before your appointment.\n --- Please check your dates");
			
		//check if departure date is = than appointment date
		if (departureDate == apptDate)
		{
			alert(departureDate == apptDate);
	  		fs.raiseError("You cannot depart before your appointment.\n --- Please check your dates");
		}
		
		//check appointment is not before today
		if (apptDate < aVal)
			fs.raiseError("Appointment dates can only be made for future dates.\n --- Please reconsider your appointment date.");

	}
	else
  		fs.raiseError("Please select the date & time you would like to schedule the appointment for.");
		
	if (!fs.isEmpty("passport_digits"))
	{
		if (!fs.isNumber("passport_digits"))
			fs.raiseError("The Last 6 digits of your passport number must be specified, in numeric format");
		
		if(fs.findObj("passport_digits").value.length < 6)
			fs.raiseError("Please check the number of digits in your passport number.");
	}
	else
		fs.raiseError("The Last 6 digits of your passport number must be specified.");
	
	if (fs.numErrors() > 0)
	{
		fs.displayErrors();
		return false;
	}
	else
	  return true;
}

//determines todays date
function determineDate(aDateStr) {
	theDate = new String(aDateStr);

	// format the date entered to the appropriate date format...		
	day = theDate.substring(0, 2);
	month = theDate.substring(3, 5);
	year = theDate.substring(6, 10);

	properDate = new Date(day+'/'+month+'/'+year);
	return properDate;
}

/**
 * DHTML date validation script for dd/mm/yyyy. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

//returns a boolean if the passed variable
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}


//strips white space
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

//returns days in feb
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("The date entered is invalid - please check the month and day you have specified.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("The date entered is invalid - please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}	

//simply formats the date
function formatDate(dateformat, day, month, year) {
	if (dateformat == "DD/MM/YYYY")
		return day+"/"+month+"/"+year;
	else
	if (dateformat == "YYYYMMDD")
	  	return year+month+day;
	else
	if (dateformat == "YYYYMM")
	  	return year+month;
	else  
		return month+"/"+day+"/"+year;
}

-->