function addToBasket(Source)
{
    var ElementName = "";
    var LastCheckedItem = "";
    var IncorrectSelection = false;
    var CurrentDayNum = "";
    var PreviousDayNum = "";
    var CurrentRowNum = "";
    var PreviousRowNum = "";
    
    for(i=0;i<document.f.length;i++)
    {
        ElementName = document.f.elements[i].name;
        if (ElementName.substring(0, 15) == "chkAvailability")
            if (document.f.elements[i].checked)
            {
                CurrentRowNum = ElementName.substring(15, ElementName.indexOf("_"));
                if (LastCheckedItem == "")
                    LastCheckedItem = ElementName;
                else
                {
                    CurrentDayNum = ElementName.substring(ElementName.indexOf("_") + 1, ElementName.length);
                    PreviousRowNum = LastCheckedItem.substring(15, LastCheckedItem.indexOf("_"));
                    PreviousDayNum = LastCheckedItem.substring(LastCheckedItem.indexOf("_") + 1, LastCheckedItem.length);
                    if (CurrentRowNum != PreviousRowNum || parseInt(CurrentDayNum) != parseInt(PreviousDayNum) + 1)
                        IncorrectSelection = true;
                    else
                        LastCheckedItem = ElementName;
                }
            }
        if (IncorrectSelection) i = document.f.length;
    }
    if (IncorrectSelection || LastCheckedItem == "")
        if (Source == "a")
            alert("Incorrect Selection. You must select one or several following dates.");
        else
            if (Source == "mr") alert("Incorrect Selection. You must select one service only.");
            else alert("Incorrect Selection. You must select one or several following dates from the same service.");
    else
    {
        if (Source == "ar") document.f.hidAltSelectedR.value = CurrentRowNum;
        else document.f.hidSelectedR.value = CurrentRowNum;
        if (Source == "or" || Source == "mr" || Source == "ar")
        {
            if (Source == "ar")
            {
                document.f.hidAltSelectedDS.value = document.getElementById("hidProDS" + CurrentRowNum).value;
                document.f.hidAltSelectedC.value = document.getElementById("hidProC" + CurrentRowNum).value;
                document.f.hidAltSelectedN.value = document.getElementById("hidOFS" + CurrentRowNum).value;
            }
            else
            {
                document.f.hidSelectedDS.value = document.getElementById("hidProDS" + CurrentRowNum).value;
                document.f.hidSelectedC.value = document.getElementById("hidProC" + CurrentRowNum).value;
                document.f.hidSelectedN.value = document.getElementById("hidOFS" + CurrentRowNum).value;
            }
        }
        if (document.f.cboConfig) document.f.hidPaxConfigNum.value = document.f.cboConfig.value;
        submitForm("beforeadding.aspx");
    }
}

function amendPaxConfig(List, Action)
{
    var NbRows = 0;
    var SelectedRowFound = false;
    var i = 0;
    var CheckBoxName = "";
    
    if (List == "c" || List == "e")
        if (Action == "l")
        {
            document.f.hidPaxConfigNum.value = document.f.cboConfig.value;
            document.f.hidAction.value = "lrl";
            submitForm("paxconfig.aspx");
        }
        else
        {
            document.f.hidAction.value = Action + List;
            document.f.hidCheckFirst.value = "";
            if (Action == "d" || List == "e") document.f.hidCheckFirst.value = "o";
            submitForm("updatepaxconfig.aspx");
        }
    else
    {
        if (List == "p") CheckBoxName = "chkPLRow";
        else CheckBoxName = "chkRLRow";
        for(i=0;i<document.f.length;i++)
            if (document.f.elements[i].name == CheckBoxName) NbRows += 1;
        if (Action == "a")
        {
            if (document.f.txtNbPaxToAdd.value == "") document.f.txtNbPaxToAdd.value = "1";
            SelectedRowFound = true;
        }
        else
        {
            document.f.hidSelectedRow.value = "";
            for(i=0;i<document.f.length;i++)
            {
                if (document.f.elements[i].name == CheckBoxName)
                    if (document.f.elements[i].checked)
                    {
                        SelectedRowFound = true;
                        document.f.hidSelectedRow.value = document.f.hidSelectedRow.value + document.f.elements[i].value + ".";
                    }
            }
        }
        if (SelectedRowFound)
        {
            if (List == "p") document.f.hidPLAmended.value = "o";
            else document.f.hidPCAmended.value = "o";
            document.f.hidAction.value = Action + List + "l";
            if (List + Action == "pr") document.f.hidCheckFirst.value = "o";
            document.f.hidNbRows.value = NbRows;
            submitForm("updatepaxconfig.aspx");
        }
        else alert("Please select a row to remove.");
    }
}

function amendPeriodControlStatus()
{
    if (document.f.chkAvailability.checked)
    {
        document.f.txtFrom.disabled = false;
        document.f.txtTo.disabled = false;
    }
    else
    {
        document.f.txtFrom.disabled = true;
        document.f.txtTo.disabled = true;
    }
}

function applyConfigToObject(Row)
{
    document.f.hidSelectedRow.value = Row;
    submitForm("applyconfigtoobject.aspx");
}

function askAlternatives(Row, DataSource, CodePRO, NumOFS)
{
    document.f.hidSelectedR.value = Row;
    document.f.hidSelectedDS.value = DataSource;
    document.f.hidSelectedC.value = CodePRO;
    document.f.hidSelectedN.value = NumOFS;
    memoriseSearchEngineFilter();
    submitForm("alternativesearch.aspx");
}

function askAvailability(Source, Row, DataSource, CodePRO, NumOFS)
{
    document.f.hidSelectedR.value = Row;
    document.f.hidSelectedDS.value = DataSource;
    document.f.hidSelectedC.value = CodePRO;
    document.f.hidSelectedN.value = NumOFS;
    if (Source == "pa")
    {
        document.f.hidAvailabilityFrom.value = document.getElementById("hidDate" + Row).value;
        document.f.hidAvailabilityTo.value = document.getElementById("hidDate" + Row).value;
        document.f.hidAddProcess.value = "n";
        document.f.hidNature.value = document.getElementById("hidNature" + Row).value;
    }
    else memoriseSearchEngineFilter();
    submitForm("availability.aspx");
}

function autoSubmit(e)
{
    var unicode = e.charCode? e.charCode : e.keyCode;
    if (unicode == "13") document.f.submit();
}

function cancelChangeInPL()
{
    submitForm("tempconfig.aspx?a=c");
}

function cancelChangeInPC()
{
    submitForm("tempconfig.aspx?a=c");
}

function cancelConfigChange(ConfigMode)
{
    document.f.hidMode.value = "c";
    document.f.hidAction.value = "ul";
    submitForm("paxconfig.aspx");
}

function cancelFile()
{
    if (document.f.hidRefStatus.value == "CXD")
        alert("This file has already been cancelled.");
    else
        document.location = "checkrefcxdfees.aspx";
}

function changeConfigMode(NewMode)
{
    document.f.hidMode.value = NewMode;
    if (NewMode == "pl")
        document.f.hidAction.value = "lpl";
    else
        if (NewMode == "rl")
            document.f.hidAction.value = "lrl";
        else
            document.f.hidAction.value = "ul";
    submitForm("paxconfig.aspx");
}

function checkAllocation()
{
    var ElementName = "";
    var RowList = "";
    
    for(i=0;i<document.f.length;i++)
    {
        ElementName = document.f.elements[i].name;
        if (ElementName.substring(0, 6) == "hidUpd" && document.f.elements[i].value != "")
            RowList = RowList + ElementName.substring(6, ElementName.length) + ".";
    }
    document.f.hidList.value = RowList;
    submitForm("saveallocation.aspx");
}

function checkAlternativeFilter()
{
    var ErrorFound = false;
    if (document.f.cboSecond.value == document.f.cboFirst.value)
    {
        ErrorFound = true;
        alert("Both priorities cannot be the same.");
        document.f.cboSecond.focus();
    }
    else
        if (document.f.hidNbCriteria.value != "0")
        {
            if (document.f.cboFirst.value == "p" && document.f.txtProximity)
                if (document.f.txtProximity.value == "")
                {
                    ErrorFound = true;
                    alert("The proximity is not valid.");
                    document.f.txtProximity.focus();
                }
                else
                    if (parseInt(document.f.txtProximity.value) == 0)
                    {
                        ErrorFound = true;
                        alert("The proximity is not valid.");
                        document.f.txtProximity.focus();
                    }
            
            if (document.f.cboFirst.value == "r" && document.f.txtMinRate)
                if (document.f.txtMinRate.value == "")
                {
                    ErrorFound = true;
                    alert("The minimum rate is not valid.");
                    document.f.txtMinRate.focus();
                }
                else
                    if (document.f.txtMaxRate.value == "")
                    {
                        ErrorFound = true;
                        alert("The maximum rate is not valid.");
                        document.f.txtMaxRate.focus();
                    }
                    else
                        if (parseInt(document.f.txtMaxRate.value) < parseInt(document.f.txtMinRate.value))
                        {
                            ErrorFound = true;
                            alert("The maximum rate cannot be lower than the minimum rate.");
                            document.f.txtMaxRate.focus();
                        }
            
            if (!ErrorFound && (document.f.hidNbCriteria.value == "2" || document.f.cboSecond.value == "p" || document.f.cboSecond.value == "r"))
            {
                if (document.f.cboSecond.value == "p" && document.f.txtProximity)
                    if (document.f.txtProximity.value == "")
                    {
                        ErrorFound = true;
                        alert("The proximity is not valid.");
                        document.f.txtProximity.focus();
                    }
                    else
                        if (parseInt(document.f.txtProximity.value) == 0)
                        {
                            ErrorFound = true;
                            alert("The proximity is not valid.");
                            document.f.txtProximity.focus();
                        }
                
                if (document.f.cboSecond.value == "r" && document.f.txtMinRate)
                    if (document.f.txtMinRate.value == "")
                    {
                        ErrorFound = true;
                        alert("The minimum rate is not valid.");
                        document.f.txtMinRate.focus();
                    }
                    else
                        if (document.f.txtMaxRate.value == "")
                        {
                            ErrorFound = true;
                            alert("The maximum rate is not valid.");
                            document.f.txtMaxRate.focus();
                        }
                        else
                            if (parseInt(document.f.txtMaxRate.value) < parseInt(document.f.txtMinRate.value))
                            {
                                ErrorFound = true;
                                alert("The maximum rate cannot be lower than the minimum rate.");
                                document.f.txtMaxRate.focus();
                            }
            }
        }
    if (!ErrorFound)
    {
        document.f.hidAltNbLookedFor.value = document.f.txtNbLookedFor.value;
        document.f.hidAltFirst.value = document.f.cboFirst.value;
        document.f.hidAltSecond.value = document.f.cboSecond.value;
        if (document.f.txtProximity) document.f.hidAltProximity.value = document.f.txtProximity.value;
        if (document.f.cboRateType) document.f.hidAltRateType.value = document.f.cboRateType.value;
        if (document.f.txtMinRate) document.f.hidAltMinRate.value = document.f.txtMinRate.value;
        if (document.f.txtMaxRate) document.f.hidAltMaxRate.value = document.f.txtMaxRate.value;
        submitForm("alternativesearch.aspx");
    }
}

function checkAvailabilityBeforeSending()
{
    document.getElementById("aConfirm").href = "javascript:empty();";
    document.location.href = "checkavailabilitybeforesending.aspx";
}

function checkAvailabilityFilter()
{
    if (!isValidDate(document.f.txtAvailabilityFrom.value))
    {
        alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
        document.f.txtAvailabilityFrom.focus();
    }
    else
        if (!isValidDate(document.f.txtAvailabilityTo.value))
        {
            alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
            document.f.txtAvailabilityTo.focus();
        }
        else
            if (isDateBefore(document.f.txtAvailabilityTo.value, document.f.txtAvailabilityFrom.value))
            {
                alert("The period is not valid.");
                document.f.txtAvailabilityTo.focus();
            }
            else
            {
                document.f.hidAvailabilityFrom.value = document.f.txtAvailabilityFrom.value;
                document.f.hidAvailabilityTo.value = document.f.txtAvailabilityTo.value;
                submitForm("availability.aspx");
            }
}

function checkBeforeAdding(NextPage)
{
    var Link = document.getElementById("aAdd").href;
    document.getElementById("aAdd").href = "javascript:empty();";
    if (document.f.hidPUDetailRequired.value == "o")
    {
        if (document.f.txtDepTime.value == "" || document.f.txtDepTime.value == "00:00")
        {
            alert("The departure time is required.");
            document.getElementById("aAdd").href = Link;
        }
        else
            if (!isValidTime(document.f.txtDepTime.value))
            {
                alert("The departure time is not valid.");
                document.getElementById("aAdd").href = Link;
            }
            else
                if (document.f.txtDepLoc.value == "")
                {
                    alert("The departure location is required.");
                    document.getElementById("aAdd").href = Link;
                }
                else
                    if (document.f.txtArrLoc.value == "" && document.f.hidNature.value != "To")
                    {
                        alert("The arrival location is required.");
                        document.getElementById("aAdd").href = Link;
                    }
                    else
                        submitForm(NextPage);
    }
    else submitForm(NextPage);
}

function checkBookingDetails()
{
    if (document.f.txtStartTime.value == document.f.hidStartTime.value && document.f.txtEndTime.value == document.f.hidEndTime.value && document.f.txtDepTime.value == document.f.hidDepTime.value && document.f.txtDepLoc.value == document.f.hidDepLoc.value && document.f.txtArrLoc.value == document.f.hidArrLoc.value && !document.f.cboDriverName && document.f.txtServiceInfo.value == document.f.hidServiceInfo.value && parseInt(document.f.hidNbServices.value) <= 1)
        submitForm("bookingdetails.aspx");
    else
        if (!isValidTime(document.f.txtStartTime.value))
        {
            alert("The start time is not valid.");
            document.f.txtStartTime.focus();
        }
        else
            if (!isValidTime(document.f.txtEndTime.value))
            {
                alert("The end time is not valid.");
                document.f.txtEndTime.focus();
            }
            else
                if (!isValidTime(document.f.txtDepTime.value))
                {
                    alert("The departure time is not valid.");
                    document.f.txtDepTime.focus();
                }
                else
                    if (document.f.txtDepLoc.value == "" && document.f.hidIsPUDetail.value == "o")
                    {
                        alert("The departure location is required.");
                        document.f.txtDepLoc.focus();
                    }
                    else
                        if (document.f.txtArrLoc.value == "" && document.f.hidIsPUDetail.value == "o" && document.f.hidNature.value != "To")
                        {
                            alert("The arrival location is required.");
                            document.f.txtArrLoc.focus();
                        }
                        else
                        {
                            var Error = false;
                            if (parseInt(document.f.hidNbServices.value) > 1)
                            {
                                i = 1;
                                while (!Error && i <= parseInt(document.f.hidNbServices.value))
                                {
                                    if (document.getElementById("txtService" + i + "Time").value != document.getElementById("hidService" + i + "Time").value)
                                        if (!isValidTime(document.getElementById("txtService" + i + "Time").value))
                                        {
                                            alert("At least one service timing is not valid.");
                                            document.getElementById("txtService" + i + "Time").focus();
                                            Error = true;
                                        }
                                    i += 1;
                                }
                            }
                            if (!Error) submitForm("savedetails.aspx");
                        }
}

function checkBookingMail()
{
    if (document.f.hidDepartureMissing.value == "o")
        alert("At least one departure information is required but missing.");
    else submitForm("checkbookingmail.aspx");
}

function checkBookingsFilter()
{
    if (document.f.chkPeriod.checked) checkPeriodFilter(document.f.txtFrom.value, document.f.txtTo.value, 0, "printbookings.aspx");
    else submitForm("printbookings.aspx");
}

function checkDemoUser(Action)
{
    if (document.f.txtName.value == "")
    {
        alert("Please enter your name.");
        document.f.txtName.focus();
    }
    else
        if (document.f.txtEmail.value == "")
        {
            alert("Please enter your email address.");
            document.f.txtEmail.focus();
        }
        else
        {
            document.f.hidAction.value = Action;
            submitForm("checkdemouser.aspx");
        }
}

function checkFileRef()
{
    if (document.f.txtFileRef.value == "")
    {
        alert("The file reference cannot be empty.");
        document.f.txtFileRef.focus();
    }
    else saveFileRef();
}

function checkInternalFilter(Source)
{
	switch(Source)
	{
		case "o":
		{
            if (!isValidDate(document.f.txtFrom.value))
            {
                alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
                document.f.txtFrom.focus();
            }
            else
                if (!isValidDate(document.f.txtTo.value))
                {
                    alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
                    document.f.txtTo.focus();
                }
                else
                    if (isDateBefore(document.f.txtTo.value, document.f.txtFrom.value))
                    {
                        alert("The period is not valid.");
                        document.f.txtTo.focus();
                    }
                    else
                    {
                        document.f.hidLoadList.value = "o";
                        submitForm("internalboard.aspx");
                    }
		    break;
		}
		case "n":
		{
		    if (document.f.cboClient.value == "all")
		        alert("No client has been selected.");
		    else
		    {
		        var ClientKey = document.f.cboClient.value;
		        ClientKey = ClientKey.substring(ClientKey.indexOf(".") + 1);
		        ClientKey = ClientKey.substring(ClientKey.indexOf(".") + 1);
		        if (ClientKey == "y")
		            alert("File creation for inactive clients is not allowed.");
		        else
		            submitForm('newref.aspx');
		    }
		    break;
		}
		case "a":
		{
		    if (document.f.cboClient.value == "all")
		        alert("No client has been selected.");
		    else
		        submitForm("checkavailability.aspx");
		    break;
		}
		case "np":
		{
		    if (document.f.cboClient.value == "all")
		        alert("No client has been selected.");
		    else
		    {
		        var ClientKey = document.f.cboClient.value;
		        ClientKey = ClientKey.substring(ClientKey.indexOf(".") + 1);
		        ClientKey = ClientKey.substring(ClientKey.indexOf(".") + 1);
		        if (ClientKey == "y")
		            alert("File creation for inactive clients is not allowed.");
		        else
		            submitForm('newprop.aspx');
		    }
		    break;
		}
	}
}

function checkMappingFilter()
{
    var Error = true;
    
    if (document.f.optIn.checked)
    {
        if (!isValidDate(document.f.txtINFrom.value))
        {
            alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
            document.f.txtINFrom.focus();
        }
        else
            if (!isValidDate(document.f.txtINTo.value))
            {
                alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
                document.f.txtINTo.focus();
            }
            else
                if (isDateBefore(document.f.txtINTo.value, document.f.txtINFrom.value))
                {
                    alert("The period is not valid.");
                    document.f.txtINTo.focus();
                }
                else Error = false;
    }
    else
        if (document.f.optLast.checked)
        {
            if (!isValidDate(document.f.txtLastFrom.value))
            {
                alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
                document.f.txtLastFrom.focus();
            }
            else
                if (!isValidDate(document.f.txtLastTo.value))
                {
                    alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
                    document.f.txtLastTo.focus();
                }
                else
                    if (isDateBefore(document.f.txtLastTo.value, document.f.txtLastFrom.value))
                    {
                        alert("The period is not valid.");
                        document.f.txtLastTo.focus();
                    }
                    else Error = false;
        }
        else
            if (document.f.txtRootRef.value == "")
            {
                alert("The reference is required.");
                document.f.txtRootRef.focus();
            }
            else Error = false;
    if (!Error)
    {
        document.f.hidScreenResolution.value = screen.width;
        document.f.hidLoad.value = "y";
        submitForm("mapping.aspx");
    }
}

function checkNewContact()
{
    if (document.f.txtContactName.value == "")
    {
        alert("The contact name cannot be empty.");
        document.f.txtContactName.focus();
    }
    else
        if (document.f.txtContactEmail.value == "")
        {
            alert("The e-mail address cannot be empty.");
            document.f.txtContactEmail.focus();
        }
        else submitForm("savecontact.aspx");
}

function checkNewPassword()
{
    if (document.f.txtOldPassword.value == "")
    {
        alert("Please enter your current password.");
        document.f.txtOldPassword.focus();
    }
    else
        if (document.f.txtNewPassword1.value == "")
        {
            alert("Please enter your new password.");
            document.f.txtNewPassword1.focus();
        }
        else
            if (document.f.txtNewPassword2.value == "")
            {
                alert("Please enter the confirmation of your password.");
                document.f.txtNewPassword2.focus();
            }
            else
                if (document.f.txtNewPassword2.value == document.f.txtNewPassword1.value)
                    submitForm("savepwd.aspx");
                else
                {
                    alert("The confirmation does not match the new password.");
                    document.f.txtNewPassword2.focus();
                }
}

function checkNewProp()
{
    if (document.f.txtPropHeading.value == "")
    {
        alert("The proposal heading cannot be empty.");
        document.f.txtPropHeading.focus();
    }
    else
        if (document.f.cboRequestor)
        {
            if (document.f.cboRequestor.value == "-")
            {
                alert("A client contact must be selected.");
                document.f.cboRequestor.focus();
            }
            else
                if (!isValidDate(document.f.txtDateRequestReceived.value))
                {
                    alert("The request date is not valid. The date format must be DD/MM/YY.");
                    document.f.txtDateRequestReceived.focus();
                }
                else submitForm("createprop.aspx");
        }
        else submitForm("createprop.aspx");
}

function checkNewRef()
{
    if (document.f.txtRootRef.value == "")
    {
        alert("The root reference cannot be empty.");
        document.f.txtRootRef.focus();
    }
    else
        if (document.f.txtBookingName.value == "")
        {
            alert("The booking heading cannot be empty.");
            document.f.txtBookingName.focus();
        }
        else
            if (document.f.cboRequestor)
            {
                if (document.f.cboRequestor.value == "-")
                {
                    alert("A client contact must be selected.");
                    document.f.cboRequestor.focus();
                }
                else
                    if (!isValidDate(document.f.txtDateRequestReceived.value))
                    {
                        alert("The request date is not valid. The date format must be DD/MM/YY.");
                        document.f.txtDateRequestReceived.focus();
                    }
                    else submitForm("createref.aspx");
            }
            else submitForm("createref.aspx");
}

function checkObjectRates()
{
    if (document.f.txtPP.value == "") document.f.txtPP.value = "0";
    if (document.f.txtSS.value == "") document.f.txtSS.value = "0";
    if (document.f.txtDC.value == "") document.f.txtDC.value = "0";
    if (document.f.txtTR.value == "") document.f.txtTR.value = "0";
    if (document.f.txtQR.value == "") document.f.txtQR.value = "0";
    if (document.f.txtC1.value == "") document.f.txtC1.value = "0";
    if (document.f.txtC2.value == "") document.f.txtC2.value = "0";
    submitForm("saveobjectrates.aspx");
}

function checkOpenRefFilter()
{
    if (document.f.optOpenRoot.checked)
        if (document.f.txtRootRef.value == "")
        {
            alert("A reference must been entered.");
            document.f.txtRootRef.focus();
        }
        else
        {
            document.f.hidRoot.value = document.f.txtRootRef.value;
            document.f.hidRootIsOK.value = "n";
            submitForm("checkfile.aspx");
        }
    else checkPeriodFilter(document.f.txtFrom.value, document.f.txtTo.value, 0, "openref.aspx");
}

function checkPaxConfig()
{
    var RowList = "";
    var NbRows = 0;
    for(i=0;i<document.f.length;i++)
    {
        ElementName = document.f.elements[i].id;
        if (ElementName.substring(0, 8) == "chkRLRow")
        {
            RowList = RowList + ElementName.substring(8, ElementName.length) + ".";
            NbRows += 1;
        }
    }
    if (NbRows == 0)
        alert("No room found.");
    else
    {
        document.f.hidSelectedRow.value = RowList;
        document.f.hidAction.value = "srl";
        document.f.hidCheckFirst.value = "pc";
        document.f.hidNbRows.value = NbRows;
        submitForm("updatepaxconfig.aspx");
    }
}

function checkPaxList()
{
    var RowList = "";
    var NbRows = 0;
    for(i=0;i<document.f.length;i++)
    {
        ElementName = document.f.elements[i].id;
        if (ElementName.substring(0, 8) == "chkPLRow")
        {
            RowList = RowList + ElementName.substring(8, ElementName.length) + ".";
            NbRows += 1;
        }
    }
    if (NbRows == 0)
        alert("No pax found.");
    else
    {
        document.f.hidSelectedRow.value = RowList;
        document.f.hidAction.value = "spl";
        document.f.hidCheckFirst.value = "pl";
        document.f.hidNbRows.value = NbRows;
        submitForm("updatepaxconfig.aspx");
    }
}

function checkPaxListAndConfig(DestinationPage)
{
    var NbRows = 0;
    for(i=0;i<document.f.length;i++)
    {
        ElementName = document.f.elements[i].id;
        if (ElementName.substring(0, 8) == "chkRLRow") NbRows += 1;
    }
    if (NbRows == 0) alert("Please first create the pax configuration.");
    else submitForm("tempconfig.aspx?a=s&d=" + DestinationPage);
}

function checkPeriodFilter(From, To, NoPastDates, ActionPage)
{
    var FromIsValid = false;
    var ToIsValid = false;
    var Today = new Date();
    
    FromIsValid = isValidDate(From);
    ToIsValid = isValidDate(To);
    if (!FromIsValid)
    {
        alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
        document.f.txtFrom.focus();
    }
    else
        if (!ToIsValid)
        {
            alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
            document.f.txtTo.focus();
        }
        else
            if (isDateBefore(To, From))
            {
                alert("The period is not valid.");
                document.f.txtTo.focus();
            }
            else
                if (NoPastDates == 1 && isDateBefore(From, getDateToDDMMYY(Today)))
                {
                    alert("The search cannot be done in the past.");
                    document.f.txtFrom.focus();
                }
                else submitForm(ActionPage);
}

function checkPropShortRef()
{
    if (document.f.txtRootRef.value == "")
    {
        alert("The short reference cannot be empty.");
        document.f.txtRootRef.focus();
    }
    else submitForm("createref.aspx");
}

function checkProRefFilter()
{
    document.f.hidProvider.value = document.f.cboProvider.value;
    if (!isValidDate(document.f.txtFrom.value))
    {
        alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
        document.f.txtFrom.focus();
    }
    else
        if (!isValidDate(document.f.txtTo.value))
        {
            alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
            document.f.txtTo.focus();
        }
        else
            if (isDateBefore(document.f.txtTo.value, document.f.txtFrom.value))
            {
                alert("The period is not valid.");
                document.f.txtTo.focus();
            }
            else
            {
                document.f.hidLoad.value = "o";
                submitForm("checkproref.aspx");
            }
}

function checkProviderFilter(Reset, Source)
{
    if (Reset == "o") document.f.hidProKey.value = "";
    document.f.hidReset.value = Reset;
    if (Source == "ss") submitForm("suppliercontractperiod.aspx");
    else checkPeriodFilter(document.f.txtFrom.value, document.f.txtTo.value, 0, "supplierallocations.aspx");
}

function checkRefererFilter()
{
    if (!isValidDate(document.f.txtFrom.value))
    {
        alert("The 'From' date is not valid. The date format must be DD/MM/YY.");
        document.f.txtFrom.focus();
    }
    else
        if (!isValidDate(document.f.txtTo.value))
        {
            alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
            document.f.txtTo.focus();
        }
        else
            if (isDateBefore(document.f.txtTo.value, document.f.txtFrom.value))
            {
                alert("The period is not valid.");
                document.f.txtTo.focus();
            }
            else
            {
                document.f.hidLoad.value = "o";
                submitForm("referer.aspx");
            }
}

function checkSearchEngineFilter(Nature, UserType)
{
    var ErrorFound = false;
    if (Nature == "Cr")
    {
        if (document.f.cboToLocation.value == "_")
        {
            alert("Please select both Pick Up & Drop Off locations.");
            ErrorFound = true;
        }
        else
            if (!isValidDate(document.f.txtFromDate.value))
            {
                alert("The pick up date is not valid. The date format must be DD/MM/YY.");
                ErrorFound = true;
                document.f.txtFromDate.focus();
            }
            else
                if (!isValidDate(document.f.txtToDate.value))
                {
                    alert("The drop off date is not valid. The date format must be DD/MM/YY.");
                    ErrorFound = true;
                    document.f.txtFromDate.focus();
                }
                else
                    if (isDateBefore(document.f.txtToDate.value, document.f.txtFromDate.value))
                    {
                        alert("The period is not valid.");
                        ErrorFound = true;
                        document.f.txtToDate.focus();
                    }
                    else
                        if (!isValidTime(document.f.txtFromTime.value))
                        {
                            alert("The pick up time is not valid. The time format must be HH:mm.");
                            ErrorFound = true;
                            document.f.txtFromTime.focus();
                        }
                        else
                            if (!isValidTime(document.f.txtToTime.value))
                            {
                                alert("The drop off time is not valid. The time format must be HH:mm.");
                                ErrorFound = true;
                                document.f.txtToTime.focus();
                            }
                            else
                                if (document.f.txtToDate.value == document.f.txtFromDate.value && document.f.txtToTime.value == document.f.txtFromTime.value)
                                {
                                    alert("The timing is not valid.");
                                    ErrorFound = true;
                                    document.f.txtToTime.focus();
                                }
    }
    else
    {
        if (!isValidDate(document.f.txtFrom.value))
        {
            alert("The availability start date is not valid. The date format must be DD/MM/YY.");
            ErrorFound = true;
            document.f.txtFrom.focus();
        }
        else
        {
            if (UserType != "i")
            {
                var Limit = new Date();
                Limit.setFullYear(2007, 10, 1);
                var SearchPeriodStart = new Date();
                SearchPeriodStart.setFullYear(extractYearFromDate(document.f.txtFrom.value), extractMonthFromDate(document.f.txtFrom.value), extractDayFromDate(document.f.txtFrom.value));
                if (SearchPeriodStart < Limit)
                {
                    alert("The availability start date is not valid. The date cannot be prior to 01/11/07.");
                    ErrorFound = true;
                    document.f.txtFrom.focus();
                }
            }
            if (!ErrorFound)
            {
                if (!isValidDate(document.f.txtTo.value))
                {
                    alert("The availability end date is not valid. The date format must be DD/MM/YY.");
                    ErrorFound = true;
                    document.f.txtFrom.focus();
                }
                else
                    if ((Nature == "Acc" || Nature == "Res" || Nature == "To" || Nature == "Vis" || Nature == "Trf" || Nature == "Spg" || Nature == "Rai") && isDateBefore(document.f.txtTo.value, document.f.txtFrom.value))
                    {
                        alert("The availability period is not valid.");
                        ErrorFound = true;
                        document.f.txtTo.focus();
                    }
                    else
                        if (Nature == "Acc" || Nature == "Res")
                        {
                            if (document.f.optSearchText.checked && document.f.txtSupplier.value == "")
                            {
                                alert("A supplier name must been entered.");
                                ErrorFound = true;
                                document.f.txtSupplier.focus();
                            }
                        }
                        else
                            if (Nature == "Trf")
                                if (document.f.cboToLocation.value == "_")
                                {
                                    alert("Please select both Pick Up & Drop Off locations.");
                                    ErrorFound = true;
                                }
            }
        }
        if (!ErrorFound && (Nature == "Acc" || Nature == "Res" || Nature == "To" || Nature == "Trf" || Nature == "Vis" || Nature == "Rai"))
        {
            if (document.f.txtBudgetMin.value == "") document.f.txtBudgetMin.value = "0";
            if (document.f.txtBudgetMax.value == "") document.f.txtBudgetMax.value = "99999";
            if (parseInt(document.f.txtBudgetMax.value) < parseInt(document.f.txtBudgetMin.value))
            {
                alert("The maximum rate cannot be lower than the minimum rate.");
                ErrorFound = true;
                document.f.txtBudgetMax.focus();
            }
        }
    }
    if (ErrorFound)
        document.f.hidLoadResult.value = "n";
    else
    {
        memoriseSearchEngineFilter();
        submitForm("searchengine.aspx");
    }
}

function checkSignIn(Source)
{
    if (document.f.hidMaintenance.value == "o" || document.f.hidTechnicalProblem.value == "o")
        alert("Apologies - our website is currently unavailable. Please try again later.");
    else
        if (document.f.txtEmail.value == "" || (document.f.txtPassword.value == "" && Source == "si"))
            if (Source == "si") alert("Please enter both e-mail address and password.");
            else alert("Please enter your e-mail address.");
        else
            if (Source == "si") submitForm("checkuser.aspx");
            else submitForm("sendpwd.aspx");
}

function checkSS(NISOrMRS)
{
    NISOrMRS = NISOrMRS.toUpperCase();
    if (document.getElementById("cbo" + NISOrMRS + "OFS").value == "" || document.getElementById("cbo" + NISOrMRS + "OFS").value == "-")
    {
        alert("No service has been selected.");
        document.getElementById("cbo" + NISOrMRS + "OFS").focus();
    }
    else
        if (!isValidDate(document.getElementById("txt" + NISOrMRS + "Date").value))
        {
            alert("The service date is not valid. The date format must be DD/MM/YY.");
            document.getElementById("txt" + NISOrMRS + "Date").focus();
        }
        else
        {
            document.getElementById("hid" + NISOrMRS + "OFS").value = document.getElementById("cbo" + NISOrMRS + "OFS").value;
            document.f.hidObjectDate.value = document.getElementById("txt" + NISOrMRS + "Date").value;
            if (NISOrMRS == "NIS")
                submitForm("addnis.aspx");
            else
            {
                if (document.f.txtPP.value == "") document.f.txtPP.value = "0";
                if (document.f.txtC1.value == "") document.f.txtC1.value = "0";
                if (document.f.txtC2.value == "") document.f.txtC2.value = "0";
                if (document.f.txtDC.value == "") document.f.txtDC.value = "0";
                if (document.f.txtEF.value == "") document.f.txtEF.value = "0";
                if (document.f.txtED.value == "") document.f.txtED.value = "0";
                submitForm("addmrs.aspx");
            }
        }
}

function checkTM()
{
    if (!isValidDate(document.f.txtTMDate.value))
    {
        alert("The date is not valid. The date format must be DD/MM/YY.");
        document.f.txtTMDate.focus();
    }
    else
    {
        for(i=0;i<document.f.length;i++)
            if (document.f.elements[i].name == "optTM")
                if (document.f.elements[i].checked)
                {
                    document.f.hidProDS.value = document.getElementById("hidProDS" + document.f.elements[i].value).value;
                    document.f.hidProC.value = document.getElementById("hidProC" + document.f.elements[i].value).value;
                    document.f.hidNumOFS.value = document.getElementById("hidNumOFS" + document.f.elements[i].value).value;
                    document.f.hidNature.value = document.getElementById("hidNature" + document.f.elements[i].value).value;
                }
        document.f.hidObjectDate.value = document.getElementById("txtTMDate").value;
        document.f.hidPaxConfigNum.value = document.f.cboConfig.value;
        submitForm("beforeaddingtm.aspx");
    }
}

function secureCancellation()
{
    document.getElementById("aConfirm").href = "javascript:empty();";
    submitForm("cancelfile.aspx");
}

function confirmProvisionalBooking(Row)
{
    document.f.hidSelectedRow.value = Row;
    submitForm("confirmprovisional.aspx");
}

function createNewContact(Source)
{
    var Parameters = "";
    var WindowWidth = 420;
    var WindowHeight = 200;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    switch(Source)
    {
        case "nr":
            document.f.parRoot.value = document.f.txtRootRef.value;
            document.f.parBookingName.value = document.f.txtBookingName.value;
            document.f.parRequestor.value = "";
            break;
        case "np":
            document.f.parPropHeading.value = document.f.txtPropHeading.value;
            document.f.parRequestor.value = "";
            break;
    }
    
    Parameters = "?s=" + Source + "&ds=" + document.f.hidClientDS.value + "&c=" + document.f.hidClientC.value + "&n=" + escape(document.f.hidClientN.value);
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winContact = window.open("newcontact.aspx" + Parameters, "Contact", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function dateAdd(Interval, Number, OneDate)
{
	var Result = new Date(OneDate);
	switch(Interval)
	{
		case "ms": Result.setMilliseconds(OneDate.getMilliseconds() + Number); break;
		case "s": Result.setSeconds(OneDate.getSeconds() + Number); break;
		case "mi": Result.setMinutes(OneDate.getMinutes() + Number); break;
		case "h": Result.setHours(OneDate.getHours() + Number); break;
		case "d": Result.setDate(OneDate.getDate() + Number); break;
		case "m": Result.setMonth(OneDate.getMonth() + Number); break;
		case "y": Result.setFullYear(OneDate.getFullYear() + Number); break;
	}
	return Result;
}

function dateOnly(e)
{
    var unicode = e.charCode? e.charCode : e.keyCode;
    if (".8.9.13.35.36.37.39.46.47.48.49.50.51.52.53.54.55.56.57.".indexOf("." + unicode + ".") == -1) return false;
    else return true;
}

function deleteContract(ProDS, ProC, CodeParService, codeParServiceType, LocationStarts, LocationEnds, RoomType, DateStart)
{
    document.f.hidDeleteProDS.value = ProDS;
    document.f.hidDeleteProC.value = ProC;
    document.f.hidDeleteCodeParService.value = CodeParService;
    document.f.hidDeleteCodeParServiceType.value = codeParServiceType;
    document.f.hidDeleteLocationStarts.value = LocationStarts;
    document.f.hidDeleteLocationEnds.value = LocationEnds;
    document.f.hidDeleteRoomType.value = RoomType;
    document.f.hidDeleteDateStart.value = DateStart;
    submitForm("contract.aspx");
}

function deletePendingBookingMail(Row)
{
    document.f.hidSelectedRR.value = document.getElementById("hidRR" + Row).value;
    document.f.hidSelectedWBR.value = document.getElementById("hidWBR" + Row).value;
    document.f.hidSelectedMDT.value = document.getElementById("hidMDT" + Row).value;
    document.f.hidSelectedRT.value = document.getElementById("hidRT" + Row).value;
    document.f.hidSelectedRA.value = document.getElementById("hidRA" + Row).value;
    document.f.hidSelectedRN.value = document.getElementById("hidRN" + Row).value;
    document.f.hidSelectedCA.value = document.getElementById("hidCA" + Row).value;
    document.f.hidSelectedCN.value = document.getElementById("hidCN" + Row).value;
    document.f.hidAction.value = "delete";
    submitForm("pendingmail.aspx");
}

function displayConfigLock()
{
    if (document.f.hidMode.value == "pl") alert("You must first save/cancel the changes in the pax list.");
    else alert("You must first save/cancel the changes in the roomimg list.");
}

function displayDemoMessage()
{
    alert("This function is not available in demo mode.");
}

function displayItiEdition(NumRef)
{
    var Parameters = "?fid=" + NumRef + "&sw=" + screen.width + "&db=y";
    var WindowWidth = 790;
    if (screen.width > 800) WindowWidth = 840;
    var WindowHeight = screen.height - 200;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winRatesEdition = window.open("printiti.aspx" + Parameters, "ItiEdition", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function displayOFSInfo(DataSource, CodePRO, NumOFS)
{
    var Parameters = "";
    var WindowWidth = 630;
    var WindowHeight = screen.height - 200;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    Parameters = "?ds=" + DataSource + "&c=" + CodePRO + "&o=" + NumOFS;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winOFS = window.open("objectinfo.aspx" + Parameters, "OFS", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function displayPaxConfig(ConfigNum)
{
    if (document.f.hidRefStatus.value == "CXD")
        alert("This reference has already been cancelled.");
    else
        {
            document.f.hidPaxConfigNum.value = ConfigNum;
            submitForm("paxconfig.aspx");
        }
}

function displayProviderInfo(DataSource, CodePRO, UserType)
{
    var Parameters = "";
    var WindowWidth = 760;
    var WindowHeight = 190;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    if (UserType == "i") WindowHeight = 240;
    Parameters = "?ds=" + DataSource + "&c=" + CodePRO;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winProvider = window.open("providerinfo.aspx" + Parameters, "Provider", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=no, status=no");
}

function displayProviderListPerCode(CodePARWebService)
{
    var Parameters = "";
    var WindowWidth = 760;
    var WindowHeight = 400;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    Parameters = "?cpws=" + CodePARWebService;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winProvider = window.open("providerlist.aspx" + Parameters, "ProviderList", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function displayRatesEdition()
{
    var Parameters = "";
    var WindowWidth = 760;
    var WindowHeight = screen.height - 200;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winRatesEdition = window.open("printrates.aspx", "RatesEdition", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function displayRefEdition()
{
    var Parameters = "";
    var WindowWidth = 760;
    var WindowHeight = screen.height - 200;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winRefEdition = window.open("printref.aspx", "RefEdition", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function displaySpecialCond(DataSource, CodePRO, NumOFS, Heading)
{
    var Parameters = "";
    var WindowWidth = 630;
    var WindowHeight = screen.height - 200;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    Parameters = "?ds=" + DataSource + "&c=" + CodePRO + "&o=" + NumOFS + "&h=" + Heading;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winCond = window.open("specialcond.aspx" + Parameters, "Cond", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function displaySupplierList()
{
    document.f.hidLoadSuppliers.value = "o";
    document.f.txtFrom.value = "";
    document.f.txtTo.value = "";
    submitForm("internalboard.aspx");
}

function empty() {}

function extractDayFromDate(OneDate)
{
    return parseInt("1" + OneDate.substring(0, 2)) - 100;
}

function extractMonthFromDate(OneDate)
{
    return parseInt("1" + OneDate.substring(3, 5)) - 101;
}

function extractYearFromDate(OneDate)
{
    return parseInt("20" + OneDate.substring(6, 8));
}

function getCalendarWindowHeight(OneDate)
{
    var WindowHeight = 235;
    var SelectedDate = "";
    var Today = new Date();
    var FirstDayOfMonth = new Date();
    var FirstDayOfNextMonth = new Date();
    var LastDayOfMonth = new Date();
    var NbCells = 0;
    var NbRows = 0;
    
    FirstDayOfMonth = new Date((parseInt(OneDate.substring(6, 8)) + 2000), (parseInt(OneDate.substring(3, 5)) - 1), 1);
    NbCells = FirstDayOfMonth.getDay();
    if (NbCells == 0) NbCells = 7;
    NbCells -= 1;
    FirstDayOfNextMonth = dateAdd("m", 1, FirstDayOfMonth);
    LastDayOfMonth = dateAdd("d", -1, FirstDayOfNextMonth);
    NbCells += LastDayOfMonth.getDate();
    NbRows = Math.ceil(NbCells / 7);
    if (NbRows == 5) WindowHeight = 210;
    return WindowHeight;
}

function getDateToDDMMYY(OneDate)
{
    var DateDDMMYY = "";
    var OneDay = OneDate.getDate();
    var OneMonth = OneDate.getMonth() + 1;
    var OneYear = OneDate.getFullYear();
    
    if (OneDay < 10) DateDDMMYY = "0";
    DateDDMMYY += OneDay + "/";
    if (OneMonth < 10) DateDDMMYY += "0";
    DateDDMMYY += OneMonth + "/";
    OneYear = OneYear - 2000;
    if (OneYear < 10) DateDDMMYY += "0";
    DateDDMMYY += OneYear;
    return DateDDMMYY;
}

function goBack() {history.go(-1);}

function goBackToSearch()
{
    if (document.f.hidSourceFrom.value == "pa") submitForm("checkpropavailability.aspx");
    else submitForm("searchengine.aspx");
}

function goToWebSite(WebsiteAddress)
{
    window.opener.window.open("http://" + WebsiteAddress, "");
}

function hl()
{
    document.getElementById("divLoad").style.display = "none";
}

function invoiceSupplier(Row, ProKey)
{
    document.f.hidSelectedPro.value = ProKey;
    document.f.hidSelectedRowHeading.value = document.getElementById("hidProHeading" + Row).value;
    document.f.hidWebBookingRef.value = document.getElementById("hidWebRef" + Row).value;
    document.f.hidInvoicing.value = "o";
    submitForm("invoicing.aspx");
}

function isDateBefore(FirstDate, SecondDate)
{
    day = FirstDate.substring(0, 2);
    month = FirstDate.substring(3, 5);
	year = FirstDate.substring(6, 8);
	FirstDate = year + month + day;
    day = SecondDate.substring(0, 2);
    month = SecondDate.substring(3, 5);
	year = SecondDate.substring(6, 8);
	SecondDate = year + month + day;
    return (FirstDate < SecondDate);
}

function issueVoucher(Issuing, Row, ProKey)
{
    document.f.hidSelectedPro.value = ProKey;
    document.f.hidSelectedRowHeading.value = document.getElementById("hidProHeading" + Row).value;
    document.f.hidWebBookingRef.value = document.getElementById("hidWebRef" + Row).value;
    document.f.hidIssuing.value = Issuing;
    submitForm("voucher.aspx");
}

function isValidDate(OneDate)
{
	var IsUnvalid = false;
	if (OneDate.length != 8)
		IsUnvalid = true;
	else
	{
		var Status = 0;
		var PartOfDate = "";
		var ZeroToNine = "0123456789";
		var OneToNine = "123456789";
		var ZeroToEight = "012345678";
		var Year01235679 = "01235679";
		var Month13578 = "13578";
		var Month469 = "469";
		OneDate = "20" + OneDate.substring(6, 8) + OneDate.substring(3, 5) + OneDate.substring(0, 2);
		while (OneDate != "" && !IsUnvalid)
		{
			PartOfDate = OneDate.substring(0, 1);
			OneDate = OneDate.substring(1, OneDate.length);
			switch(Status)
			{
				case 0 :
					if (PartOfDate == "2") Status = 1;
					else IsUnvalid = true;
					break;
				case 1 :
					if (PartOfDate == "0") Status = 2;
					else IsUnvalid = true;
					break;
				case 2 :
					if (PartOfDate == "0" || PartOfDate == "1") Status = 3;
					else IsUnvalid = true;
					break;
				case 3 :
					if (Year01235679.indexOf(PartOfDate) != -1) Status = 4;
					else
						if (PartOfDate == "4" || PartOfDate == "8") Status = 5;
						else IsUnvalid = true;
					break;
				case 4 :
					if (PartOfDate == "0") Status = 6;
					else
						if (PartOfDate == "1") Status = 7;
						else IsUnvalid = true;
					break;
				case 5 :
					if (PartOfDate == "0") Status = 8;
					else
						if (PartOfDate == "1") Status = 7;
						else IsUnvalid = true;
					break;
				case 6 :
					if (Month13578.indexOf(PartOfDate) != -1) Status = 9;
					else
						if (PartOfDate == "2") Status = 10;
						else
							if (Month469.indexOf(PartOfDate) != -1) Status = 11;
							else IsUnvalid = true;
					break;
				case 7 :
					if (PartOfDate == "0" || PartOfDate == "2") Status = 9;
					else
						if (PartOfDate == "1") Status = 11;
						else IsUnvalid = true;
					break;
				case 8 :
					if (Month13578.indexOf(PartOfDate) != -1) Status = 9;
					else
						if (PartOfDate == "2") Status = 12;
						else
							if (Month469.indexOf(PartOfDate) != -1) Status = 11;
							else IsUnvalid = true;
					break;
				case 9 :
					if (PartOfDate == "0") Status = 13;
					else
						if (PartOfDate == "1" || PartOfDate == "2") Status = 14;
						else
							if (PartOfDate == "3") Status = 15;
							else IsUnvalid = true;
					break;
				case 10 :
					if (PartOfDate == "0") Status = 13;
					else
						if (PartOfDate == "1") Status = 14;
						else
							if (PartOfDate == "2") Status = 16;
							else IsUnvalid = true;
					break;
				case 11 :
					if (PartOfDate == "0") Status = 13;
					else
						if (PartOfDate == "1" || PartOfDate == "2") Status = 14;
						else
							if (PartOfDate == "3") Status = 17;
							else IsUnvalid = true;
					break;
				case 12 :
					if (PartOfDate == "0") Status = 13;
					else
						if (PartOfDate == "1" || PartOfDate == "2") Status = 14;
						else IsUnvalid = true;
					break;
				case 13 : if (OneToNine.indexOf(PartOfDate) == -1) IsUnvalid = true; break;
				case 14 : if (ZeroToNine.indexOf(PartOfDate) == -1) IsUnvalid = true; break;
				case 15 : if (!(PartOfDate == "0" || PartOfDate == "1")) IsUnvalid = true; break;
				case 16 : if (ZeroToEight.indexOf(PartOfDate) == -1) IsUnvalid = true; break;
				case 17 : if (PartOfDate != "0") IsUnvalid = true; break;
			}
		}
	}
	return (!IsUnvalid);
}

function isValidTime(OneTime)
{
	var IsUnvalid = false;
	if (OneTime.length != 5)
		IsUnvalid = true;
	else
	{
		var Status = 0;
		var PartOfTime = "";
		var ZeroToNine = "0123456789";
		var ZeroToThree = "0123";
		var ZeroToFive = "012345";
		while (OneTime != "" && !IsUnvalid)
		{
			PartOfTime = OneTime.substring(0, 1);
			OneTime = OneTime.substring(1, OneTime.length);
			switch(Status)
			{
				case 0 :
					if (PartOfTime == "0" || PartOfTime == "1") Status = 1;
					else
					    if (PartOfTime == "2") Status = 2;
					    else IsUnvalid = true;
					break;
				case 1 :
					if (ZeroToNine.indexOf(PartOfTime) != -1) Status = 3;
					else IsUnvalid = true;
					break;
			    case 2 :
					if (ZeroToThree.indexOf(PartOfTime) != -1) Status = 3;
					else IsUnvalid = true;
					break;
			    case 3 :
					if (PartOfTime == ":") Status = 4;
					else IsUnvalid = true;
					break;
			    case 4 :
					if (ZeroToFive.indexOf(PartOfTime) != -1) Status = 5;
					else IsUnvalid = true;
					break;
			    case 5 :
			        if (ZeroToNine.indexOf(PartOfTime) == -1) IsUnvalid = true;
			        break;
			}
		}
	}
	return (!IsUnvalid);
}

function loadBookingDetails()
{
    document.f.hidSelectedObject.value = document.f.cboObjects.value;
    submitForm("bookingdetails.aspx");
}

function loadContract(Reset)
{
    if (Reset == "o") document.f.hidProKey.value = "";
    document.f.hidReset.value = Reset;
    submitForm("contract.aspx");
}

function loadOperatorSubCombo(Type)
{
    document.f.hidOperator.value = document.f.cboOperator.value;
    document.f.hidLoad.value = "n";
    if (Type == "supplier") document.f.hidSupplier.value = document.f.cboSupplier.value;
    else document.f.hidSupplier.value = "";
    submitForm("checkproref.aspx");
}

function loadSSSubCombo(CurrentCombo, NISOrMRS)
{
    NISOrMRS = NISOrMRS.toUpperCase();
    switch(CurrentCombo)
    {
        case "Nature":
            document.getElementById("hid" + NISOrMRS + "Nature").value = document.getElementById("cbo" + NISOrMRS + "Nature").value;
            document.getElementById("hid" + NISOrMRS + "Country").value = "-";
            document.getElementById("hid" + NISOrMRS + "OFS").value = "0";
            break;
        case "Country":
            document.getElementById("hid" + NISOrMRS + "Country").value = document.getElementById("cbo" + NISOrMRS + "Country").value;
            document.getElementById("hid" + NISOrMRS + "OFS").value = "0";
            break;
        case "OFS":
            document.getElementById("hid" + NISOrMRS + "OFS").value = document.getElementById("cbo" + NISOrMRS + "OFS").value;
            break;
    }
    document.f.hidObjectDate.value = document.getElementById("txt" + NISOrMRS + "Date").value;
    submitForm("specialservices.aspx");
}

function loadSubCombo(CurrentCombo)
{
    var ErrorFound = false;
    var CurrentNature = "";
    
    if (document.f.txtFrom)
    {
        if (!isValidDate(document.f.txtFrom.value))
        {
            alert("The start date is not valid. The date format must be DD/MM/YY.");
            ErrorFound = true;
            document.f.txtFrom.focus();
        }
        if (!ErrorFound && document.f.txtTo)
            if (!isValidDate(document.f.txtTo.value))
            {
                alert("The end date is not valid. The date format must be DD/MM/YY.");
                ErrorFound = true;
                document.f.txtTo.focus();
            }
        if (!ErrorFound && document.f.txtFrom && document.f.txtTo)
            if (isDateBefore(document.f.txtTo.value, document.f.txtFrom.value))
            {
                alert("The period is not valid.");
                ErrorFound = true;
                document.f.txtTo.focus();
            }
    }
    else
    {
        if (document.f.txtFromDate)
        {
            if (!isValidDate(document.f.txtFromDate.value))
            {
                alert("The start date is not valid. The date format must be DD/MM/YY.");
                ErrorFound = true;
                document.f.txtFromDate.focus();
            }
            if (!ErrorFound && document.f.txtToDate)
                if (!isValidDate(document.f.txtToDate.value))
                {
                    alert("The end date is not valid. The date format must be DD/MM/YY.");
                    ErrorFound = true;
                    document.f.txtToDate.focus();
                }
            if (!ErrorFound && document.f.txtFromDate && document.f.txtToDate)
                if (isDateBefore(document.f.txtToDate.value, document.f.txtFromDate.value))
                {
                    alert("The period is not valid.");
                    ErrorFound = true;
                    document.f.txtToDate.focus();
                }
        }
    }
    
    if (ErrorFound == false)
    {
        CurrentNature = document.f.hidNature.value;
        if (CurrentNature == "") CurrentNature = "Acc";
        document.f.hidNature.value = document.f.cboNature.value;
        document.f.hidLoadResult.value = "n";
        if (document.f.txtFrom) document.f.hidFrom.value = document.f.txtFrom.value;
        if (document.f.txtTo) document.f.hidTo.value = document.f.txtTo.value;
        if (document.f.txtNbResults) document.f.hidNbResults.value = document.f.txtNbResults.value;
        if (document.f.chkDisplayPreferedOnly)
        {
            if (document.f.chkDisplayPreferedOnly.checked) document.f.hidDisplayPreferedOnly.value = "on";
            else document.f.hidDisplayPreferedOnly.value = "";
        }
        
        if (document.f.cboNature.value != CurrentNature)
        {
            if (document.f.hidSupplier) document.f.hidSupplier.value = "";
            if (document.f.hidCountry) document.f.hidCountry.value = "";
            if (document.f.hidArea) document.f.hidArea.value = "";
            if (document.f.hidLocation) document.f.hidLocation.value = "";
            if (document.f.hidCategory) document.f.hidCategory.value = "";
            if (document.f.hidType) document.f.hidType.value = "";
            if (document.f.hidClientCat) document.f.hidClientCat.value = "";
            if (document.f.hidFromArea) document.f.hidFromArea.value = "";
            if (document.f.hidFromLocation) document.f.hidFromLocation.value = "";
            if (document.f.hidToCountry) document.f.hidToCountry.value = "";
            if (document.f.hidToArea) document.f.hidToArea.value = "";
            if (document.f.hidToLocation) document.f.hidToLocation.value = "";
            if (document.f.hidBudgetMin) document.f.hidBudgetMin.value = "0";
            if (document.f.hidBudgetMax) document.f.hidBudgetMax.value = "99999";
        }
        
        if (CurrentNature == "Acc" || CurrentNature == "Res")
        {
            switch(CurrentCombo)
            {
                case "Nature":
                    document.f.cboCountry.value = "ZA";
                    document.f.cboArea.value = "_";
                    document.f.cboLocation.value = "_";
                    break;
                case "Country":
                    document.f.cboArea.value = "_";
                    document.f.cboLocation.value = "_";
                    break;
                case "Area":
                    document.f.cboLocation.value = "_";
                    break;
            }
        }
        else
            if (CurrentNature == "To" || CurrentNature == "Vis" || CurrentNature == "Rai")
            {
                switch(CurrentCombo)
                {
                    case "Nature":
                        document.f.cboCountry.value = "ZA";
                        document.f.cboArea.value = "_";
                        break;
                    case "Country":
                        document.f.cboArea.value = "_";
                        break;
                }
            }
            else
                if (CurrentNature == "Trf")
                {
                    switch(CurrentCombo)
                    {
                        case "Nature":
                            document.f.cboCountry.value = "ZA";
                            document.f.cboFromArea.value = "_";
                            document.f.cboFromLocation.value = "_";
                            document.f.cboToArea.value = "_";
                            document.f.cboToLocation.value = "_";
                            break;
                        case "Country":
                            document.f.cboFromArea.value = "_";
                            document.f.cboFromLocation.value = "_";
                            document.f.cboToArea.value = "_";
                            document.f.cboToLocation.value = "_";
                            break;
                        case "FromArea":
                            document.f.cboFromLocation.value = "_";
                            document.f.cboToArea.value = "_";
                            document.f.cboToLocation.value = "_";
                            break;
                        case "FromLocation":
                            document.f.cboToArea.value = "_";
                            document.f.cboToLocation.value = "_";
                            break;
                        case "ToArea":
                            document.f.cboToLocation.value = "_";
                            break;
                    }
                }
                else
                    if (CurrentNature == "Cr")
                    {
                        switch(CurrentCombo)
                        {
                            case "Nature":
                                document.f.cboProvider.value = "_";
                                document.f.cboOFS.value = "_";
                                document.f.cboCountry.value = "_";
                                document.f.cboFromArea.value = "_";
                                document.f.cboFromLocation.value = "_";
                                document.f.cboToCountry.value = "_";
                                document.f.cboToArea.value = "_";
                                document.f.cboToLocation.value = "_";
                                break;
                            case "Provider":
                                document.f.cboOFS.value = "_";
                                document.f.cboCountry.value = "_";
                                document.f.cboFromArea.value = "_";
                                document.f.cboFromLocation.value = "_";
                                document.f.cboToCountry.value = "_";
                                document.f.cboToArea.value = "_";
                                document.f.cboToLocation.value = "_";
                                break;
                            case "OFS":
                                break;
                            case "Country":
                                document.f.cboFromArea.value = "_";
                                document.f.cboFromLocation.value = "_";
                                document.f.cboToArea.value = "_";
                                document.f.cboToLocation.value = "_";
                                break;
                            case "FromArea":
                                document.f.cboFromLocation.value = "_";
                                document.f.cboToArea.value = "_";
                                document.f.cboToLocation.value = "_";
                                break;
                            case "FromLocation":
                                document.f.cboToArea.value = "_";
                                document.f.cboToLocation.value = "_";
                                break;
                            case "ToArea":
                                document.f.cboToLocation.value = "_";
                                break;
                        }
                    }
        
        if (document.f.cboNature.value == CurrentNature)
        {
            switch(CurrentNature)
            {
                case "Acc":
                    if (document.f.optSearchText.checked) document.f.hidSearch.value = "t";
                    else document.f.hidSearch.value = "c";
                    document.f.hidSupplier.value = document.f.txtSupplier.value;
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidArea.value = document.f.cboArea.value;
                    document.f.hidLocation.value = document.f.cboLocation.value;
                    document.f.hidCategory.value = document.f.cboCategory.value;
                    document.f.hidType.value = document.f.cboType.value;
                    document.f.hidClientCat.value = document.f.cboClientCat.value;
                    document.f.hidBudgetType.value = document.f.cboBudgetType.value;
                    document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
                    document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
                    document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
                    break;
                case "Res":
                    if (document.f.optSearchText.checked) document.f.hidSearch.value = "t";
                    else document.f.hidSearch.value = "c";
                    document.f.hidSupplier.value = document.f.txtSupplier.value;
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidArea.value = document.f.cboArea.value;
                    document.f.hidLocation.value = document.f.cboLocation.value;
                    document.f.hidCategory.value = document.f.cboCategory.value;
                    document.f.hidType.value = document.f.cboType.value;
                    document.f.hidClientCat.value = document.f.cboClientCat.value;
                    document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
                    document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
                    document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
                    break;
                case "Cr":
                    document.f.hidProvider.value = document.f.cboProvider.value;
                    document.f.hidOFS.value = document.f.cboOFS.value;
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidFromArea.value = document.f.cboFromArea.value;
                    document.f.hidFromLocation.value = document.f.cboFromLocation.value;
                    document.f.hidFromDate.value = document.f.txtFromDate.value;
                    document.f.hidFromTime.value = document.f.txtFromTime.value;
                    document.f.hidToCountry.value = document.f.cboToCountry.value;
                    document.f.hidToArea.value = document.f.cboToArea.value;
                    document.f.hidToLocation.value = document.f.cboToLocation.value;
                    document.f.hidToDate.value = document.f.txtToDate.value;
                    document.f.hidToTime.value = document.f.txtToTime.value;
                    break;            
                case "To":
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidArea.value = document.f.cboArea.value;
                    document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
                    document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
                    document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
                    break;
                case "Vis":
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidArea.value = document.f.cboArea.value;
                    document.f.hidBudgetType.value = document.f.cboBudgetType.value;
                    document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
                    document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
                    document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
                    break;
                case "Trf":
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidFromArea.value = document.f.cboFromArea.value;
                    document.f.hidFromLocation.value = document.f.cboFromLocation.value;
                    document.f.hidToCountry.value = document.f.cboToCountry.value;
                    document.f.hidToArea.value = document.f.cboToArea.value;
                    document.f.hidToLocation.value = document.f.cboToLocation.value;
                    document.f.hidBudgetType.value = document.f.cboBudgetType.value;
                    document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
                    document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
                    document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
                    break;
                case "Rai":
                    document.f.hidCountry.value = document.f.cboCountry.value;
                    document.f.hidArea.value = document.f.cboArea.value;
                    document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
                    document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
                    document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
                    break;
            }
        }
        submitForm("searchengine.aspx");
    }
}

function loadSupplier()
{
    submitForm("supplierboard.aspx");
}

function markResStatus(Row)
{
    document.getElementById("hidChanges" + Row).value = "";
    if (document.getElementById("txtRef" + Row).value != document.getElementById("hidRef" + Row).value || document.getElementById("cboStatus" + Row).value != document.getElementById("hidStatus" + Row).value || document.getElementById("txtDBS" + Row).value != document.getElementById("hidDBS" + Row).value || document.getElementById("txtComment" + Row).value != document.getElementById("hidComment" + Row).value)
        document.getElementById("hidChanges" + Row).value = "o";
}

function memoriseSearchEngineFilter()
{
    document.f.hidLoadResult.value = "o";
    document.f.hidNature.value = document.f.cboNature.value;
    if (document.f.cboNature.value == "Acc" || document.f.cboNature.value == "Res" || document.f.cboNature.value == "To" || document.f.cboNature.value == "Trf" || document.f.cboNature.value == "Vis" || document.f.cboNature.value == "Rai")
    {
        document.f.hidFrom.value = document.f.txtFrom.value;
        document.f.hidTo.value = document.f.txtTo.value;
        document.f.hidNbResults.value = document.f.txtNbResults.value;
        if (document.f.chkDisplayPreferedOnly.checked) document.f.hidDisplayPreferedOnly.value = "on";
        else document.f.hidDisplayPreferedOnly.value = "";
        document.f.hidDisplayOrder.value = document.f.cboDisplayOrder.value;
    }
    switch(document.f.cboNature.value)
    {
        case "Acc":
            if (document.f.optSearchText.checked) document.f.hidSearch.value = "t";
            else document.f.hidSearch.value = "c";
            document.f.hidSupplier.value = document.f.txtSupplier.value;
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidArea.value = document.f.cboArea.value;
            document.f.hidLocation.value = document.f.cboLocation.value;
            document.f.hidCategory.value = document.f.cboCategory.value;
            document.f.hidType.value = document.f.cboType.value;
            document.f.hidClientCat.value = document.f.cboClientCat.value;
            document.f.hidBudgetType.value = document.f.cboBudgetType.value;
            document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
            document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
            document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
            break;
        case "Res":
            if (document.f.optSearchText.checked) document.f.hidSearch.value = "t";
            else document.f.hidSearch.value = "c";
            document.f.hidSupplier.value = document.f.txtSupplier.value;
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidArea.value = document.f.cboArea.value;
            document.f.hidLocation.value = document.f.cboLocation.value;
            document.f.hidCategory.value = document.f.cboCategory.value;
            document.f.hidType.value = document.f.cboType.value;
            document.f.hidClientCat.value = document.f.cboClientCat.value;
            if (document.f.cboBudgetType) document.f.hidBudgetType.value = document.f.cboBudgetType.value;
            document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
            document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
            document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
            break;
        case "Cr":
            document.f.hidProvider.value = document.f.cboProvider.value;
            document.f.hidOFS.value = document.f.cboOFS.value;
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidFromArea.value = document.f.cboFromArea.value;
            document.f.hidFromLocation.value = document.f.cboFromLocation.value;
            document.f.hidFromDate.value = document.f.txtFromDate.value;
            document.f.hidFromTime.value = document.f.txtFromTime.value;
            document.f.hidToCountry.value = document.f.cboToCountry.value;
            document.f.hidToArea.value = document.f.cboToArea.value;
            document.f.hidToLocation.value = document.f.cboToLocation.value;
            document.f.hidToDate.value = document.f.txtToDate.value;
            document.f.hidToTime.value = document.f.txtToTime.value;
            break;
        case "To":
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidArea.value = document.f.cboArea.value;
            document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
            document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
            document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
            break;
        case "Trf":
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidFromArea.value = document.f.cboFromArea.value;
            document.f.hidFromLocation.value = document.f.cboFromLocation.value;
            document.f.hidToCountry.value = document.f.cboToCountry.value;
            document.f.hidToArea.value = document.f.cboToArea.value;
            document.f.hidToLocation.value = document.f.cboToLocation.value;
            document.f.hidBudgetType.value = document.f.cboBudgetType.value;
            document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
            document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
            document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
            break;
        case "Vis":
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidArea.value = document.f.cboArea.value;
            document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
            document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
            document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
            break;
        case "Moa": document.f.hidTo.value = document.f.txtFrom.value; break;
        case "Moc": document.f.hidTo.value = document.f.txtFrom.value; break;
        case "Mog": document.f.hidTo.value = document.f.txtFrom.value; break;
        case "Rai":
            document.f.hidCountry.value = document.f.cboCountry.value;
            document.f.hidArea.value = document.f.cboArea.value;
            document.f.hidBudgetCurrency.value = document.f.cboBudgetCurrency.value;
            document.f.hidBudgetMin.value = document.f.txtBudgetMin.value;
            document.f.hidBudgetMax.value = document.f.txtBudgetMax.value;
            break;
    }
}

function memoriseUserMode(SelectedMode)
{
    document.location = "memoriseusermode.aspx?m=" + SelectedMode;
}

function modifyPaxConfig()
{
    document.f.hidLockedSide.value = "l";
    submitForm("paxconfig.aspx");
}

function nothing() {alert("Coming soon...");}

function numbersOnly(e)
{
    var unicode = e.charCode? e.charCode : e.keyCode;
    if (".8.9.13.35.36.37.39.46.48.49.50.51.52.53.54.55.56.57.".indexOf("." + unicode + ".") == -1) return false;
    else return true;
}

function openContractPeriod(Start)
{
    document.f.hidSelectedPeriodS.value = Start;
    submitForm("opencontractperiod.aspx");
}

function openFile(NumRef, OpenFirstVersion)
{
    document.f.hidNumRef.value = NumRef;
    document.f.hidRootIsOK.value = "y";
    document.f.hidOpenFirstVersion.value = OpenFirstVersion;
    submitForm("checkfile.aspx");
}

function refreshBasket(Action)
{
    if (document.f.hidDisplayCXDRows.value == "o") document.f.hidDisplayCXDRows.value = "n";
    else document.f.hidDisplayCXDRows.value = "o";
    submitForm("basket.aspx");
}

function reloadModuleInOut()
{
    document.f.hidModuleLocInShowAll.value = "n";
    if (document.f.chkModuleLocInShowAll.checked) document.f.hidModuleLocInShowAll.value = "y";
    document.f.hidModuleLocOutShowAll.value = "n";
    if (document.f.chkModuleLocOutShowAll.checked) document.f.hidModuleLocOutShowAll.value = "y";
    submitForm("fileboard.aspx");
}

function removeBasketRow()
{
    var SelectedRowFound = false;
    var i = 0;
    var RowStatus = "";
    
    if (document.f.hidRefStatus.value == "CXD")
        alert("This file has already been cancelled.");
    else
    {
        for(i=0;i<document.f.length;i++)
        {
            if (document.f.elements[i].name == "optRow")
                if (document.f.elements[i].checked)
                {
                    SelectedRowFound = true;
                    document.f.hidSelectedRow.value = document.f.elements[i].value;
                    document.f.hidSelectedRowHeading.value = document.getElementById("hidHeading" + document.f.elements[i].value).value;
                    RowStatus = document.getElementById("hidStatus" + document.f.elements[i].value).value;
                    i = document.f.length;
                }
        }
        if (SelectedRowFound)
            if (RowStatus == "CXD" || RowStatus == "CXC" || RowStatus == "ACX")
                alert("This service has already been cancelled.");
            else
            {
                if (RowStatus == "N" || RowStatus == "PR") submitForm("removerow.aspx");
                else submitForm("checkobjectcxdfees.aspx");
            }
        else alert("Please select a service to cancel.");
    }
}

function resetRates()
{
    document.f.hidResetRates.value = "o";
    submitForm("basket.aspx");
}

function saveNewContract()
{
    if (!isValidDate(document.f.txtTo.value))
    {
        alert("The 'To' date is not valid. The date format must be DD/MM/YY.");
        document.f.txtTo.focus();
    }
    else
        if (isDateBefore(document.f.txtTo.value, document.f.txtFrom.value))
        {
            alert("The period is not valid.");
            document.f.txtTo.focus();
        }
        else
            if (document.f.txtSR.value == "")
            {
                alert("The Sale And Report number is not valid.");
                document.f.txtSR.focus();
            }
            else
                if (document.f.txtReleaseSR.value == "")
                {
                    alert("The Release Sale And Report number is not valid.");
                    document.f.txtReleaseSR.focus();
                }
                else
                    if (document.f.txtMinAlloc.value == "")
                    {
                        alert("The Minimum Allocation number is not valid.");
                        document.f.txtMinAlloc.focus();
                    }
                    else
                        if (document.f.txtReleaseAlloc.value == "")
                        {
                            alert("The Release Allocation number is not valid.");
                            document.f.txtReleaseAlloc.focus();
                        }
                        else submitForm("savecontract.aspx");
}

function saveObjectConfig()
{
    document.f.hidSaveChange.value = "o";
    submitForm("applyconfigtoobject.aspx");
}

function saveProRef(NbRows)
{
    var i = 0;
    var DateError = 0;
    
    for(i=1;i<=NbRows;i++)
        if (document.getElementById("hidChanges" + i).value == "o")
            if (document.getElementById("txtDBS" + i).value != document.getElementById("hidDBS" + i).value)
                if (!isValidDate(document.getElementById("txtDBS" + i).value))
                {
                    DateError = 1;
                    i = NbRows + 1;
                }
    if (DateError == 1)
        alert("At least one status date is not valid. The date format must be DD/MM/YY.");
    else
        submitForm("saveresnum.aspx");
}

function saveRoom(Row, Action)
{
    document.f.hidSelectedRow.value = Row + ".";
    document.f.hidAction.value = Action;
    submitForm("updatepaxconfig.aspx");
}

function saveTypeRooming()
{
    var TypeRooming = "";
    var ElementName = "";
    
    for(i=0;i<document.f.length;i++)
    {
        ElementName = document.f.elements[i].name;
        if (ElementName.substring(0, 7) == "optRoom")
            if(document.f.elements[i].checked)
                TypeRooming = TypeRooming + ElementName.substring(7, ElementName.length) + "->" + document.f.elements[i].value + ".";
    }
    document.f.hidTypeRooming.value = TypeRooming;
    submitForm("beforeadding.aspx");
}

function searchForNewBooking()
{
    if (document.f.hidRefStatus.value == "CXD")
        alert("This reference has already been cancelled.");
    else
        if (document.f.hidConfigExists.value == "n")
            alert("Please first create the default pax configuration.");
        else
        {
            document.f.hidAddProcess.value = "o";
            submitForm("searchengine.aspx");
        }
}

function sendInvoiceCopy(Row, ProKey)
{
    document.f.hidSelectedPro.value = ProKey;
    document.f.hidSelectedRowHeading.value = document.getElementById("hidProHeading" + Row).value;
    document.f.hidWebBookingRef.value = document.getElementById("hidWebRef" + Row).value;
    document.f.hidInvoiceToReEdit.value = document.getElementById("hidInvoice" + Row).value;
    submitForm("sendinvoice.aspx");
}

function sendMail()
{
    if (document.f.txtName.value == "" || document.f.txtEmail.value == "" || document.f.txtSubject.value == "" || document.f.txtMessage.value == "")
        alert("All information is required.");
    else
    {
        document.f.hidSend.value = "y";
        document.f.submit();
    }
}

function sendNewMessage()
{
    if (document.f.txtMessage.value == "")
        alert("The message cannot be empty.");
    else submitForm("sendmessage.aspx");
}

function sendPendingBookingMail(Row)
{
    document.f.hidSelectedRR.value = document.getElementById("hidRR" + Row).value;
    document.f.hidSelectedWBR.value = document.getElementById("hidWBR" + Row).value;
    document.f.hidSelectedMDT.value = document.getElementById("hidMDT" + Row).value;
    document.f.hidSelectedRT.value = document.getElementById("hidRT" + Row).value;
    document.f.hidSelectedRA.value = document.getElementById("hidRA" + Row).value;
    document.f.hidSelectedRN.value = document.getElementById("hidRN" + Row).value;
    document.f.hidSelectedCA.value = document.getElementById("hidCA" + Row).value;
    document.f.hidSelectedCN.value = document.getElementById("hidCN" + Row).value;
    document.f.hidAction.value = "send";
    submitForm("pendingmail.aspx");
}

function showBasket()
{
    if (document.f.hidConfigExists.value == "n")
        alert("Please first create the default pax configuration.");
    else
        document.location = "basket.aspx";
}

function showBookingComment(CommentKey)
{
    document.f.hidCommentKey.value = CommentKey;
    submitForm("bookingcomments.aspx");
}

function showBookingDetails()
{
    var SelectedRowFound = false;
    var i = 0;
    
    for(i=0;i<document.f.length;i++)
    {
        if (document.f.elements[i].name == "optRow")
            if (document.f.elements[i].checked)
            {
                SelectedRowFound = true;
                document.f.hidSelectedObject.value = document.getElementById("hidObjectRow" + document.f.elements[i].value).value;
                i = document.f.length;
            }
    }
    if (SelectedRowFound) submitForm("bookingdetails.aspx");
    else alert("Please select a row to view.");
}

function showCalendar(Value, ObjectName, Reload)
{
    var Parameters = "";
    var WindowWidth = 185;
    var WindowHeight = 235;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    var Today = new Date();
    if (isValidDate(Value)) SelectedDate = Value;
    else SelectedDate = getDateToDDMMYY(Today);
    Parameters = "?o=" + ObjectName + "&d=" + SelectedDate + "&r=" + Reload;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winCalendar = window.open("calendar.aspx" + Parameters, "Calendar", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=no, status=no");
}

function showCXDOnPrintRef(YesOrNo)
{
    document.f.hidShowCXD.value = YesOrNo;
    submitForm("printref.aspx");
}

function showPage(NewWay)
{
    document.f.hidNbTotalRecords.value = document.f.hidNbRec.value;
    document.f.hidPagingWay.value = NewWay;
    document.f.hidNumPageToLoad.value = "";
    document.f.hidFloorData.value = "";
    switch(NewWay)
    {
        case "f": break;
        case "p":
            document.f.hidNumPageToLoad.value = document.f.hidPreviousPageNum.value;
            document.f.hidFloorData.value = document.f.hidPreviousFloor.value;
            break;
        case "n":
            document.f.hidNumPageToLoad.value = document.f.hidNextPageNum.value;
            document.f.hidFloorData.value = document.f.hidNextFloor.value;
            break;
        case "l":
            document.f.hidNumPageToLoad.value = document.f.hidNbPages.value;
            break;
    }
    document.f.submit();
}

function showPendingBookingMail(Row)
{
    var Parameters = "";
    var WindowWidth = 760;
    var WindowHeight = 350;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    Parameters = "?rr=" + document.getElementById("hidRR" + Row).value + "&wbr=" + document.getElementById("hidWBR" + Row).value + "&mdt=" + document.getElementById("hidMDT" + Row).value + "&rt=" + document.getElementById("hidRT" + Row).value;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winPendingMail = window.open("showpendingmail.aspx" + Parameters, "PendingMail", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function showProRefDetails(ProDS, ProC, ProHeading, WebBookingRef, RootRef)
{
    var Parameters = "";
    var WindowWidth = 760;
    var WindowHeight = 350;
    var LeftPosition = 0;
    var TopPosition = 0;
    
    Parameters = "?r=" + RootRef + "&wbr=" + WebBookingRef + "&pds=" + ProDS + "&pc=" + ProC + "&ph=" + ProHeading;
    LeftPosition = (screen.width) ? (screen.width - WindowWidth) / 2 : 0;
    TopPosition = (screen.height) ? (screen.height - WindowHeight) / 2 : 0;
    winProRefDetail = window.open("checkprorefdetail.aspx" + Parameters, "ProRef", "width=" + WindowWidth + ", height=" + WindowHeight + ", top=" + TopPosition + ", left=" + LeftPosition + ", resizable=yes, scrollbars=yes, status=no");
}

function showSpecialServices()
{
    if (document.f.hidConfigExists.value == "n")
        alert("Please first create the default pax configuration.");
    else
        document.location = "specialservices.aspx";
}

function showStatusIndicator(Row)
{
    if (document.getElementById("cboStatus" + Row).value != document.getElementById("hidStatus" + Row).value)
        document.getElementById("tdStatus" + Row).innerHTML = "<img src=\"images/warning.gif\" border=0 width=13px height=13px>";
    else
        document.getElementById("tdStatus" + Row).innerHTML = "";
}

function submitForm(Action)
{
    document.f.action = Action;
    document.f.submit();
}

function tickBookingsFilter(Source)
{
    switch(Source)
    {
        case "d":
            document.f.chkPeriod.checked = true;
            break;
        case "p":
            document.f.chkProvider.checked = true;
            break;
        case "o":
            document.f.chkProvider.checked = true;
            break;
        case "c":
            document.f.chkClient.checked = true;
            break;
    }
    if (Source == "p") document.f.submit();
}

function timeOnly(e)
{
    var unicode = e.charCode? e.charCode : e.keyCode;
    if (".8.9.13.35.36.37.39.46.48.49.50.51.52.53.54.55.56.57.58.".indexOf("." + unicode + ".") == -1) return false;
    else return true;
}
