<!--

attachCss("reserve");

function attachCss(txtFilename)
{
	document.write("<link rel='stylesheet' href='css/" + txtFilename + ".css' type='text/css'>");
}

function chkSubmit()
{
	var blnSubmitValid;
    toShowAlerts = false;
	objForm = document.forms[0];
    blnSubmitValid = isEmail("Email Address", objForm.inpEmail);
    blnSubmitValid = isPhone("Fax", objForm.inpFax, false);
    blnSubmitValid = isPhone("Business Phone", objForm.inpBH, true);
    blnSubmitValid = isPhone("Home Phone", objForm.inpAH, false);
    blnSubmitValid = isFullName("Your Name", objForm.inpName);
    //blnSubmitValid = isRadioChosen("Smoking Preference", objForm.inpSmoking.value);
    blnSubmitValid = isLength("Number of Child(ren)", objForm.inpChildCount.value, 'digit', 1, 0);
    blnSubmitValid = isLength("Number of Adult(s)", objForm.inpAdultCount.value, 'digit', 1, 0);
    blnSubmitValid = isLength("Number of Room(s)", objForm.inpRoomCount.value, 'digit', 1, 0);
	blnSubmitValid = isTime("Departure Time", objForm.inpDepHr, objForm.inpDepMin, objForm.inpDepHrType)
	blnSubmitValid = isValidDate("Departure Date", objForm.inpDepDD, objForm.inpDepMM, objForm.inpDepYY)
	blnSubmitValid = isTime("Arrival Time", objForm.inpArrHr, objForm.inpArrMin, objForm.inpArrHrType)
	blnSubmitValid = isValidDate("Arrival Date", objForm.inpArrDD, objForm.inpArrMM, objForm.inpArrYY)
    blnSubmitValid = isRadioChosen("Reservation Type", objForm.inpType.value);
	blnSubmitValid = (strAlerts == "");
	toShowAlerts = true;
	if (blnSubmitValid)
	{
		//alert ("Your reservation request has been sent.");
		//alert ("Note: reservation is NOT sent in this propotype. Reservation will be sent to Enquiries@guestlink.com.au when guestlink.com.au is online.");
		objForm.submit();
	}
	else
	{
		displayAlert( strAlerts );
		strAlerts = "";
	}
	return false;
}

var today = new Date();
var toShowAlerts = true;
var strAlerts = "";

function isFullName(strFieldname, objField)
{
    var strValue = objField.value;
    var blnResult = false;
	var isRightLength;
    var strRegExp1 = /\w+/; // valid
    var strRegExp2 = /\ +/; // valid
    var strRegExp3 = /([0-9\\\|\:\;\<\>\(\)\[\]\{\}\^\$\&\@\~\#\%\=\/\`\*\+\?\!])+/; // not valid
    isFound1 = strRegExp1.test(strValue);
    isFound2 = strRegExp2.test(strValue);
    isFound3 = strRegExp3.test(strValue);
    isRightLength = isLength(strFieldname, strValue, 'characters', 5, 0);
    if (isFound1 && isFound2 && !isFound3 && isRightLength)
    {   blnResult = true;   }
    else if (!isFound2 && strValue.length > 0)
    {   displayAlert("Please include your first name and last name in " + strFieldname + "." );    }
    else if (isFound3 && strValue.length > 0)
    {   displayAlert("You have entered an invalid " + strFieldname + ". Please remove any numbers and symbols." );    }
    else if (isRightLength)
    {   displayAlert("You have entered an invalid " + strFieldname + ". Please re-enter.");    }
    return (blnResult);
}

function isPhone(strFieldname, objField, isCompulsory)
{
    var strValue = objField.value
    var blnResult = false;
    var strRegExp1 = /([0-9 -\ \(\)\+])+/; // valid for phone number in the real world
    var strRegExp2 = /([a-zA-Z\\\|\:\;\<\>\[\]\{\}\^\$\&\@\~\#\%\=\/\`\*\?\!])+/; // not valid for phone number in the real world
    isFound1 = strRegExp1.test(strValue);
    isFound2 = strRegExp2.test(strValue);
    if (isFound1 && !isFound2)
    {
        strNewValue = strValue.replace(/[ \-\(\)\+]+/g, "");
        if (!isLength(strFieldname, strNewValue, "numbers", 8, 11))
        {   blnResult = false;	}
        else
        {	blnResult = true;	}
    }
    else if (isFound2)
    {
        displayAlert("You have entered an invalid " + strFieldname + ".  Please remove any letters or symbols." );
        blnResult = false;
    }
    else if (strValue.length > 0)
    {
        displayAlert("You have entered an invalid " + strFieldname + ". Please re-enter.");
        blnResult = false;
    }
    else if (isCompulsory)
    {
        displayAlert("Please enter the " + strFieldname + ". It cannot be blank.");
        blnResult = false;
    }
    return (blnResult);
}

function isEmail(strFieldname, objField)
{
    var strValue = objField.value;
    var blnResult = false;
    var strRegExp1 = /^.+\@(\[?)[0-9a-zA-Z\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid // /([0-9a-zA-Z_-])+@([0-9a-zA-Z_-])+(\.[0-9a-zA-Z_-])+/
    var strRegExp2 = /([\\\|\,\:\;\<\>\(\)\[\]\{\}\^\$\&\~\#\%\=\/\`\+\*\?\!])+/; // not valid
    var strRegExp3 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
    isFound1 = strRegExp1.test(strValue);
    isFound2 = strRegExp2.test(strValue);
    isFound3 = strRegExp3.test(strValue);
    if (isFound1 && !isFound2 && !isFound3)
    {   blnResult = true; }
    else if (isFound2)
    {
        displayAlert("Please remove the following symbols:\n  \ | , : ; < > ( ) [ ] { } ^ $ & ~ # % = / ` + * ? !" );
        displayAlert("You have entered an invalid " + strFieldname + "." );
    }
    else if (strValue.length > 0)
    {
        displayAlert("You have entered an invalid " + strFieldname + ". Please re-enter." );
    }
    else
    {
        displayAlert("Please enter the " + strFieldname + ". It cannot be blank." );
    }
    return (blnResult);
}

function isValidDate(strFieldname, objdd, objmm, objyy)
{
    var blnResult = true;
	var blnResult1 = true;
	var blnResult2 = true;
	var blnResult3 = true;
	if (objdd.selectedIndex == null || objdd.selectedIndex < 0)
	{	displayAlert("Please select a day in " + strFieldname + ".");	}
	if (objmm.selectedIndex == null || objmm.selectedIndex < 0)
	{	displayAlert("Please select a month in " + strFieldname + ".");	}
	if (objyy.selectedIndex == null || objyy.selectedIndex < 0)
	{	displayAlert("Please select a year in " + strFieldname + ".");	}
	if (objdd.selectedIndex == null || objmm.selectedIndex == null || objyy.selectedIndex == null)
	{	blnResult1 = false;	}
	else if (objdd.selectedIndex < 0 || objmm.selectedIndex < 0 || objyy.selectedIndex < 0)
	{	blnResult1 = false;	}
	else
	{
		var intyy = parseInt(objyy.options[objyy.selectedIndex].value);
		var intmm = parseInt(objmm.options[objmm.selectedIndex].value);
		var intdd = parseInt(objdd.options[objdd.selectedIndex].value);
		numDays = [29,31,28,31,30,31,30,31,31,30,31,30,31];
		if (intyy % 4 == 0 && intmm == 2 && intdd > numDays[0])
   		{	blnResult2 = false;	}
		else if (!(intyy % 4 == 0 && intmm == 2) && intdd > numDays[intmm])
    	{	blnResult2 = false;	}
		else if ( intyy == (today.getYear()) )
		{
			if ( intmm < (today.getMonth()+1) )
			{	blnResult3 = false;	}
			else if ( intmm == (today.getMonth()+1) && intdd <= today.getDate())
			{	blnResult3 = false; 	}
		}
	}
	if (!blnResult2)
	{	displayAlert("You have entered an invalid " + strFieldname + ".  Please re-enter.");	}
	if (!blnResult3)
    {   displayAlert("You have entered a past date in " + strFieldname + ".  Please re-enter."); }
    if (!blnResult1 || !blnResult2 || !blnResult3)
	{	blnResult = false;	}
	return blnResult;
}

function isTime(strFieldname, objHr, objMin, objHrType)
{
	if (objHr.selectedIndex >= 0 && objMin.selectedIndex >= 0 && objHrType.selectedIndex >= 0 )
	{
		blnResult = true;
	}
	else
	{
        displayAlert("Please select the " + strFieldname + ".");
        blnResult = false;
	}
	return blnResult;
}

function isRadioChosen(strFieldname, strValue)
{
	if (strValue.length == 0)
	{
        displayAlert("Please choose an option in the " + strFieldname + ".");
        blnResult = false;
	}
    else
    {
        blnResult = true;
    }
    return (blnResult);
}

function isOptionSelected(strFieldname, objSelect)
{
	if (objSelect.selectedIndex < 0)
	{
        displayAlert("Please select an option in the " + strFieldname + ".");
        blnResult = false;
	}
    else
    {
        blnResult = true;
    }
    return (blnResult);
}

function isLength(strFieldname, strValue, strType, intMinLength, intMaxLength)
{
    if (strValue.length == 0 && intMinLength > 0)
    {
        displayAlert("Please enter the " + strFieldname + ". It cannot be blank.");
        blnResult = false;
    }
    else if ( (strValue.length < intMinLength) && (intMaxLength == 0) )
    {
        displayAlert("The " + strFieldname + " cannot be less than " + intMinLength + " " + strType + " long. Please re-enter.");
        blnResult = false;
    }
    else if ( (strValue.length < intMinLength || strValue.length > intMaxLength) && (intMinLength == intMaxLength) && (intMaxLength != 0) )
    {
        displayAlert("The " + strFieldname + " must be " + intMinLength + " " + strType + " long. Please re-enter.");
        blnResult = false;
    }
    else if ( (strValue.length < intMinLength || strValue.length > intMaxLength) && (intMaxLength != 0) )
    {
        displayAlert("The " + strFieldname + " must be between " + intMinLength + " and " + intMaxLength + " " + strType + " long. Please re-enter.");
        blnResult = false;
    }
    else
    {
        blnResult = true;
    }
    return (blnResult);
}

function displayAlert(strAnAlert)
{
    if (toShowAlerts)
    {   alert (strAnAlert); }
    else
    {   strAlerts = "- " + strAnAlert + "\n" + strAlerts;  }
}

//-->
