﻿// JScript File

var blnErrorTopMsg = new Boolean(false);

//---------------------------------------------------------------
//  Purpose: Validate for empty input fields (textboxes)
//---------------------------------------------------------------
function validateEmpty(ptxtInput, plblInput, pstrMsg, plblErrMsg, blnIsDateCalendar)
{
    var txtInput = document.getElementById(ptxtInput);
    var lblInput = document.getElementById(plblInput);
    
    if (trimStr(txtInput.value) == "")
    {        
        txtInput.className = 'texfield2';
        
        lblInput.innerHTML = "<label style='color: red'>" + pstrMsg + "</label>";
        
        generateTopErrMsg(plblErrMsg, pstrMsg, ptxtInput);
        
        window.event.returnValue = false;
    } else {
        txtInput.className = 'texfield2';
        
        lblInput.innerHTML = '';
        return false;
    }
}

//---------------------------------------------------------------
//  Purpose: Trim input string (left and right trims)
//---------------------------------------------------------------
function trimStr(str)
{
    //left trim
    while (str.substring(0, 1) == ' ')
    {
        str = str.substring(1, str.length);
    }
    
    //right trim
    while (str.substring(str.length - 1, str.length) == ' ')
    {
        str = str.substring(0, str.length - 1);
    }
    
    return str;
}

//---------------------------------------------------------------
//  Purpose: Count the number of characters in text area
//---------------------------------------------------------------
function charsTypedCount(ptxtInput, ptxtCount, pintMaxLength)
{
    var txtInput = document.getElementById(ptxtInput);
    var txtCount = document.getElementById(ptxtCount);
    
    if (txtInput.value.length > pintMaxLength)
    {
        txtInput.value = txtInput.value.substring(0, pintMaxLength);
    } else {
        txtCount.value = pintMaxLength - txtInput.value.length;
    }
}

//---------------------------------------------------------------
//  Purpose: Validate for acceptable characters in Password field
//---------------------------------------------------------------
function validatePassword(ptxtInput, plblInput, pstrMsg, plblErrMsg)
{
    var txtInput = document.getElementById(ptxtInput);
    var lblInput = document.getElementById(plblInput);
    
    var unacceptable = /[^a-zA-Z0-9!@#$%^&*()-_]/gi;
    var objRegExp = new RegExp(unacceptable);
    
    if (objRegExp.test(txtInput.value) == true)      //unacceptable chars found
    {
        lblInput.innerHTML = "<label style='color: red'>" + pstrMsg + "</label>";
        
        generateTopErrMsg(plblErrMsg, pstrMsg, ptxtInput);
        
        window.event.returnValue = false;
    } else {
        lblInput.innerHTML = '';
        return false;
    } 
}

//---------------------------------------------------------------
//  Purpose: Set the focus to a specific field
//---------------------------------------------------------------
function setFocus(ptxtInput)
{
    var txtInput = document.getElementById(ptxtInput);
    txtInput.focus();
}

//---------------------------------------------------------------
//  Purpose: Generate the top overall error msg
//---------------------------------------------------------------
function generateTopErrMsg(plblErrMsg, pstrMsg, ptxtInput)
{
    var lblErrMsg = document.getElementById(plblErrMsg);
    lblErrMsg.style.display = 'block';
    
    if (blnErrorTopMsg == false)
    {
        var span = document.createElement('span');
        span.innerHTML = "<label><b>This page could not be processed.<br />Please correct the field(s) as listed:</b><br /></label>";
        lblErrMsg.appendChild(span);
        
        blnErrorTopMsg = true;
    }
    
    var err = document.createElement('span');
    err.innerHTML = "<label style='color: red'><li><a href='#' onclick=\"setFocus('" + ptxtInput + "')\" style='color: red'>" + pstrMsg + "</a></li></label>";
    lblErrMsg.appendChild(err);
}

//---------------------------------------------------------------
//  Purpose: Clear the top overall error msg
//---------------------------------------------------------------
function clearTopErrMsg(plblMsg)
{
    var lblMsg = document.getElementById(plblMsg);
    lblMsg.innerHTML = '';
    lblMsg.innerText = '';
    lblMsg.value = '';
    //lblMsg.style.display = 'none';
    blnErrorTopMsg = false;
}

//---------------------------------------------------------------
//  Purpose: Check/Uncheck all checkboxes
//           Color ALL rows of the Datagrid on Checked
//---------------------------------------------------------------
function checkUncheckAll1(pchkAll, pchkId)
{
    var chkId = new Array();
    var intCounter = new Number(0);

    var chkAll = document.getElementById(pchkAll);
    chkId = document.getElementsByName(pchkId);

    if (chkAll.checked == true)
    {
        for (intCounter = 0; intCounter < chkId.length; intCounter++)
        {
            chkId[intCounter].checked = true;
            
        if (chkId[intCounter].checked = true) {
		chkId[intCounter].parentElement.parentElement.style.backgroundColor='#ffff66';
		    }
        }
    } else {
        for (intCounter = 0; intCounter < chkId.length; intCounter++)
        {
            chkId[intCounter].checked = false;
            
            if (intCounter % 2 == 0){
     			chkId[intCounter].parentElement.parentElement.style.backgroundColor='#ffffcc'; 
     			chkId[intCounter].parentElement.parentElement.style.color='black';
		}else{
			chkId[intCounter].parentElement.parentElement.style.backgroundColor='#ccffcc'; 
     			chkId[intCounter].parentElement.parentElement.style.color='black';
		}
        }
    }
}

//---------------------------------------------------------------
//  Purpose: Determine when top checkbox in DataGrid is unchecked
//           Color the Rows of the Datagrid if checked
//---------------------------------------------------------------
function checkUncheckAll2(pchkAll, pchkId)
{
    var chkId = new Array();
    var intCounter = new Number(0);
    var blnCheckedAll = new Boolean(true);

    var chkAll = document.getElementById(pchkAll);
    chkId = document.getElementsByName(pchkId);
    
    for (intCounter = 0; intCounter < chkId.length; intCounter++) {
       if (chkId[intCounter].checked == false) {
            blnCheckedAll = false;
            break;
    }
 }

     for (intCounter = 0; intCounter < chkId.length; intCounter++) {
       	if (chkId[intCounter].checked == false) {

		if (intCounter % 2 == 0){
     			chkId[intCounter].parentElement.parentElement.style.backgroundColor='#ffffcc'; 
     			chkId[intCounter].parentElement.parentElement.style.color='black';
		}else{
			chkId[intCounter].parentElement.parentElement.style.backgroundColor='#ccffcc'; 
     			chkId[intCounter].parentElement.parentElement.style.color='black';
		}

 
    } else {
     chkId[intCounter].parentElement.parentElement.style.backgroundColor='#ffff66';
    }
 }

    
    
    if (blnCheckedAll == false)
    {
        chkAll.checked = false;
    } else {
        chkAll.checked = true;
    }
}

//---------------------------------------------------------------
//  Purpose: Validate at least one checkbox is selected
//           For DataGrid checkboxes
//---------------------------------------------------------------
function validateChkBox1(pchkId, plblErrMsg, pstrData, pstrMgtPg, pstrDelPg)
{
    var chkId = new Array();
    var intCounter = new Number(0);
    var blnChecked = new Boolean(false);
    
    chkId = document.getElementsByName(pchkId);
    var strSelected = new String("");
    var intNumOfSelected1 = new Number(0);
    var intNumOfSelected2 = new Number(0);
    
    for (intCounter = 0; intCounter < chkId.length; intCounter++)
    {
        if (chkId[intCounter].checked == true)
        {
            intNumOfSelected1++;
        }
    }
    
    for (intCounter = 0; intCounter < chkId.length; intCounter++)
    {
        if (chkId[intCounter].checked == true)
        {
            intNumOfSelected2++;
            blnChecked = true;
            strSelected += chkId[intCounter].value;
            
            if (intNumOfSelected2 != intNumOfSelected1)
            {
                strSelected += ",";
            }
        }
    }
    
    if (blnChecked == false)
    {
        var lblErrMsg = document.getElementById(plblErrMsg);
        lblErrMsg.style.display = 'block';
        lblErrMsg.innerHTML = "<label>This page could not be processed. Please correct the field(s) as listed:<br /></label>";
        lblErrMsg.innerHTML += "<label><li><span class='red'>Please select the " + pstrData + " to delete.</span></li><br /></label>";
        
        window.event.returnValue = false;
    } else {
        confirmDelete(plblErrMsg, strSelected, pstrData, pstrMgtPg, pstrDelPg);
    }
    
    return blnChecked;
}

//---------------------------------------------------------------
//  Purpose: Validate at least one checkbox is selected
//           Not for DataGrid checkboxes
//---------------------------------------------------------------
function validateChkBox2(pchkId, pintChkLen, plblDisplay, pstrMsg, plblTop)
{
    var chkId = new Array();
    var intCounter = new Number(0);
    var blnChecked = new Boolean(false);
    var lblDisplay = document.getElementById(plblDisplay);
    
    for (intCounter = 0; intCounter < pintChkLen; intCounter++)
    {
        var chkId = document.getElementById(pchkId + '_' + intCounter);
        
        if (chkId.checked == true)
        {
            blnChecked = true;
            break;
        }
    }
    
    if (blnChecked == false)
    {
        lblDisplay.innerHTML = pstrMsg;
        generateTopErrMsg(plblTop, pstrMsg, pchkId);
        
        window.event.returnValue = false;
    } else {
        lblDisplay.innerHTML = '';
    }
}

//---------------------------------------------------------------
//  Purpose: Validate one radio button is selected
//---------------------------------------------------------------
function validateRadBtn(pchkId, pintChkLen, plblDisplay, pstrMsg, plblTop)
{
    var chkId = new Array();
    var intCounter = new Number(0);
    var blnChecked = new Boolean(false);
    var lblDisplay = document.getElementById(plblDisplay);
    
    for (intCounter = 0; intCounter < pintChkLen; intCounter++)
    {
        var chkId = document.getElementById(pchkId + '_' + intCounter);
        
        if (chkId.checked == true)
        {
            blnChecked = true;
            break;
        }
    }
    
    if (blnChecked == false)
    {
        lblDisplay.innerHTML = pstrMsg;
        generateTopErrMsg(plblTop, pstrMsg, pchkId);
        
        window.event.returnValue = false;
    } else {
        lblDisplay.innerHTML = '';
    }
    
    return blnChecked;
}

//---------------------------------------------------------------
//  Purpose: Validate dropdownlist item selected is not index 0
//---------------------------------------------------------------
function validateDropDown(plstId, plblDisplay, pstrMsg, plblTop)
{
    var lstId = document.getElementById(plstId);
    var lblDisplay = document.getElementById(plblDisplay);
    
    if (lstId.selectedIndex == 0)
    {
        lstId.className = 'texfield2';
        lblDisplay.innerHTML = "<label style='color: red'>" + pstrMsg + "</label>";
        generateTopErrMsg(plblTop, pstrMsg, plstId);
        
        window.event.returnValue = false;
    } else {
        lblDisplay.innerHTML = '';
        lstId.className = 'texfield2';
    }
}

//---------------------------------------------------------------
//  Purpose: Prevent user inputs
//---------------------------------------------------------------
function preventUserInputs(ptxtInput)
{
    var txtInput = document.getElementById(ptxtInput);
    txtInput.value = "";
        
    window.event.returnValue = false;
}

//---------------------------------------------------------------
//  Purpose: Display delete confirmation for deletion of
//           records in the DataGrid
//---------------------------------------------------------------
function confirmDelete(plblErrMsg, pstrSelected, pstrData, pstrMgtPg, pstrDelPg)
{
    var btnDeleteTop = document.getElementById('btnDeleteTop');
    btnDeleteTop.disabled = true;
    var btnDeleteBottom = document.getElementById('btnDeleteBottom');
    btnDeleteBottom.disabled = true;
    
    var lblErrMsg = document.getElementById(plblErrMsg);
    lblErrMsg.style.display = 'block';
    
    lblErrMsg.innerHTML = "Are you sure you want to delete the selected " + pstrData + "?<br />";
    lblErrMsg.innerHTML += "Click <b><a href='" + pstrDelPg + "?id=" + pstrSelected + "'>Yes</a></b> to proceed or <b><a href='" + pstrMgtPg + "'>No</a></b> to cancel.<br /><br />";
    lblErrMsg.innerHTML += "Note: Deleted " + pstrData + " will be permanently erased. You won't be able to undo the changes.";
    /*
    if (pstrMgtPg == 'frmSurveyQnsMgtAdd.aspx')
    {
        lblErrMsg.innerHTML += "<a href='" + pstrDelPg + "?id=" + pstrSelected + "&action=add'><img src='../Images/Yes.JPG' width='41' height='27' border='0' /></a> | ";
    } else if (pstrMgtPg == 'frmSurveyQnsMgt.aspx') {
        lblErrMsg.innerHTML += "<a href='" + pstrDelPg + "?id=" + pstrSelected + "&action=mgt'><img src='../Images/Yes.JPG' width='41' height='27' border='0' /></a> | ";
    } else {
        lblErrMsg.innerHTML += "<a href='" + pstrDelPg + "?id=" + pstrSelected + "'><img src='../Images/Yes.JPG' width='41' height='27' border='0' /></a> | ";
    }
    lblErrMsg.innerHTML += "<a href='" + pstrMgtPg + "'><img src='../Images/No.JPG' width='41' height='27' border='0' /></a><br><br>";
    
    if (pstrData == 'Levels')
    {
        lblErrMsg.innerHTML += "Note: Deleted " + pstrData + " and its associated Books and Book Resources will be permanently erased. You won't be able to undo the changes.<br /><br />";
        lblErrMsg.innerHTML += "The hierarchy flow is: Level > Book > Book Resource (Teacher PowerPoint Slides, Student Learning Materials).";
    } else if (pstrData == 'Strategies') {
        lblErrMsg.innerHTML += "Note: Deleted " + pstrData + " and its associated PowerPoint Slides will be permanently erased. You won't be able to undo the changes.<br /><br />";
        lblErrMsg.innerHTML += "The hierarchy flow is: Strategy > PowerPoint Slides.";
    } else if (pstrData == 'Books') {
        lblErrMsg.innerHTML += "Note: Deleted " + pstrData + " and its associated Book Resources will be permanently erased. You won't be able to undo the changes.<br /><br />";
        lblErrMsg.innerHTML += "The hierarchy flow is: Book > Book Resource (Teacher PowerPoint Slides, Student Learning Materials).";
    } else if (pstrData == 'Schools') {
        lblErrMsg.innerHTML += "Note: Deleted " + pstrData + " and its associated Student Works will be permanently erased. You won't be able to undo the changes.<br /><br />";
        lblErrMsg.innerHTML += "The hierarchy flow is: School > Student Works.";
    } else {
        lblErrMsg.innerHTML += "Note: Deleted " + pstrData + " will be permanently erased. You won't be able to undo the changes.";
    }
    */
    window.event.returnValue = false;
}

//---------------------------------------------------------------
//  Purpose: Display delete confirmation for deletion of
//           records in the Activity Log
//---------------------------------------------------------------
function confirmDeleteActivityLog(plblTop, pstrMgtPg, pstrDelPg)
{
    var btnDelete = document.getElementById('btnDelete');
    btnDelete.disabled = true;
    
    var lblTop = document.getElementById(plblTop);
    lblTop.style.display = 'block';
    
    lblTop.innerHTML = "Are you sure you want to clear the Activity Log?<br />";
    lblTop.innerHTML += "Click Yes to proceed or No to cancel.";
    lblTop.innerHTML += "<a href='" + pstrDelPg + "'>Yes</a> | ";
    lblTop.innerHTML += "<a href='" + pstrMgtPg + "'>No</a><br><br>";

    lblTop.innerHTML += "Note: Clearing the Activity Log will be permanently erased. You won't be able to undo the changes.";
        
    window.event.returnValue = false;
}

//---------------------------------------------------------------
//  Purpose: Generate Instructions
//---------------------------------------------------------------
function generateInstructions(pImg, pstrMsg)
{
    var img = document.getElementById(pImg);
    var divInstructions = document.getElementById('divInstructions');
    
    divInstructions.innerHTML = pstrMsg;
    divInstructions.style.visibility = 'visible';
    
    var posX = findPositionX(img);
    divInstructions.style.posLeft = posX + 20;
    var posY = findPositionY(img);
    divInstructions.style.posTop = posY - 25;
}

//---------------------------------------------------------------
//  Purpose: Clear Instructions
//---------------------------------------------------------------
function clearInstructions()
{
    var divInstructions = document.getElementById('divInstructions');
    
    divInstructions.innerHTML = '';
    divInstructions.style.visibility = 'hidden';
}

//---------------------------------------------------------------
//  Purpose: Find Position X (Coordinate X)
//---------------------------------------------------------------
function findPositionX(pObj)
{
    var left = 0;
    
    if (pObj.offsetParent)
    {
        left = pObj.offsetLeft;
        
        while (pObj = pObj.offsetParent)
        {
			left += pObj.offsetLeft;
		}
    }
    
    return left;
}

//---------------------------------------------------------------
//  Purpose: Find Position Y (Coordinate Y)
//---------------------------------------------------------------
function findPositionY(pObj)
{
    var top = 0;
    
    if (pObj.offsetParent)
    {
        top = pObj.offsetTop;
        
        while (pObj = pObj.offsetParent)
        {
			top += pObj.offsetTop;
		}
    }
    
    return top;
}

//---------------------------------------------------------------
//  Purpose: Validate for Numeric input fields (textboxes)
//---------------------------------------------------------------
function validateIsNumeric(ptxtInput, plblInput, pstrMsg, plblErrMsg)
{
    var txtInput = document.getElementById(ptxtInput);
    var lblInput = document.getElementById(plblInput);
    
    if (IsNumeric(txtInput.value) == false && trimStr(txtInput.value) != '')
    {
        txtInput.className = 'texfield2';
        lblInput.innerHTML = "<label style='color: red'>" + pstrMsg + "</label>";
        generateTopErrMsg(plblErrMsg, pstrMsg, ptxtInput);
        
        window.event.returnValue = false;
    } else {
        txtInput.className = 'texfield2';
        lblInput.innerHTML = '';
        return false;
    }
}

//---------------------------------------------------------------
//  Purpose: Check if a text is Numeric
//---------------------------------------------------------------
function IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1)
        {
            IsNumber = false;
        }
    }

    return IsNumber;
}

//---------------------------------------------------------------
//  Purpose: Reset a specified field (textbox)
//---------------------------------------------------------------
function resetTextBox(ptxt)
{
    var txt = document.getElementById(ptxt);
    txt.value = '';
    txt.className = 'textbox-normal';
    window.event.returnValue = false;
}

//---------------------------------------------------------------
//  Purpose: Remove Confirm screen's masking
//---------------------------------------------------------------
function removeMask()
{
    var lblMessage = document.getElementById('lblMessage');
    var lblMask = document.getElementById('lblMask');
    
    lblMessage.style.visibility = 'hidden';
    lblMask.style.visibility = 'hidden';
}

//---------------------------------------------------------------
//  Purpose: Display current date and time
//---------------------------------------------------------------
var dayarray=new Array ("Sunday","Monday","Tuesday","Wednesday",
               "Thursday","Friday","Saturday")

var montharray=new Array("January","February","March","April","May","June",
               "July","August","September","October","November","December")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym

var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="A.M."
if (hours>=12)
dn="P.M."
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds

var cdate= dayarray[day]
  +", "+daym+" "+montharray[month]+" "+year
  +" | "+hours+":"+minutes+":"+seconds+" "+dn

if (document.all)
document.all.lblDate.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}

//---------------------------------------------------------------
//  Purpose: Display cancel confirmation
//---------------------------------------------------------------
function confirmCancel(pstrUrl)
{
    var cancel = confirm('Are you sure you want to cancel?');
    
    if (cancel)
    {
        window.location = pstrUrl;
    }
}

function bookingRequestsOnChange(intNumberOfBookings)
{
    var intMaxNumberOfBookings=10;
    var i=0;
   
    intNumberOfBookings=parseInt(intNumberOfBookings); 
    
    for (i=1;i<=intNumberOfBookings;i++)
    {
        document.getElementById('tblStep2Fields'+i).style.display='block';
    }
    
    for (i=intNumberOfBookings+1;i<=intMaxNumberOfBookings;i++)
    {
        document.getElementById('tblStep2Fields'+i).style.display='none';
    }
}

function userAccountsOnChange(intNumberOfAccounts)
{
    var intMaxNumberOfAccounts=10;
    var i=0;
     
    intNumberOfAccounts=parseInt(intNumberOfAccounts);
    
    for (i=1;i<=intNumberOfAccounts;i++)
    {
        document.getElementById('tblAccount'+i).style.display='block';
    }
    
    for (i=intNumberOfAccounts+1;i<=intMaxNumberOfAccounts;i++)
    {
        document.getElementById('tblAccount'+i).style.display='none';
    }
}

function bookingRequestsValidate(intNumberOfBookings)
{
    var intMaxNumberOfBookings=10;
    var i=0;
    
    for (i=1;i<=intNumberOfBookings;i++)
    {
        validateDropDown('lstSalutation'+i, 'lblSalutationErr'+i, 'Please select the Salutation for Booking #'+i+'.', 'lblErrMessage');
        validateEmpty('txtName'+i, 'lblNameErr'+i, 'Please enter the Name for Booking #'+i+'.', 'lblErrMessage', false);
        validateEmpty('txtPhone'+i, 'lblPhoneErr'+i, 'Please enter the Phone for Booking #'+i+'.', 'lblErrMessage', false);
        validateEmpty('txtDate'+i, 'lblDateErr'+i, 'Please enter the Date for Booking #'+i+'.', 'lblErrMessage', false);
        if (document.getElementById('lstTimeHour'+i).selectedIndex == 0)
        {
            validateDropDown('lstTimeHour'+i, 'lblTimeErr'+i, 'Please select the Time for Booking #'+i+'.', 'lblErrMessage');
        } else {
            validateDropDown('lstTimeMin'+i, 'lblTimeErr'+i, 'Please select the Time for Booking #'+i+'.', 'lblErrMessage');
        }
        if (document.getElementById('lstTransferType').value == 'Airport Arrival' || document.getElementById('lstTransferType').value == 'Airport Departure')
        {
            validateEmpty('txtFlightNumber'+i, 'lblFlightNumberErr'+i, 'Please enter the Flight Number for Booking #'+i+'.', 'lblErrMessage', false);
        }
        validateEmpty('txtPickupAddress'+i, 'lblPickupAddressErr'+i, 'Please enter the Pick-up Address for Booking #'+i+'.', 'lblErrMessage', false);
        validateEmpty('txtDestination'+i, 'lblDestinationErr'+i, 'Please enter the Destination Address for Booking #'+i+'.', 'lblErrMessage', false);
    }
    
    if (document.getElementById('lstModeOfPayment') != null)
    {
        validateDropDown('lstModeOfPayment', 'lblModeOfPaymentErr', 'Please select the Mode Of Payment.', 'lblErrMessage');
        if (document.getElementById('lstModeOfPayment').value == 'Credit Card' || document.getElementById('lstModeOfPayment').value == 'SMRT Charge Card')
        {
            validateEmpty('txtCreditCardNumber', 'lblCreditCardNumberErr', 'Please enter the Credit/Charge Card Number.', 'lblErrMessage', false);
            if (document.getElementById('lstModeOfPayment').value == 'Credit Card')
            {
                validateDropDown('lstTypeOfCreditCard', 'lblTypeOfCreditCardErr', 'Please select the Type Of Credit Card.', 'lblErrMessage');
            }
            validateEmpty('txtCardExpiryDate', 'lblCardExpiryDateErr', 'Please enter the Card Expiry Date.', 'lblErrMessage', false);
        }
    }
}

function userAccountsValidate(intNumberOfAccounts)
{
   for (var i=1;i<=intNumberOfAccounts;i++)
   {
        validateEmpty('txtClientReference'+i, 'lblClientReferenceErr'+i, 'Please enter the User Name for User Account #'+i+'.', 'lblErrMessage', false);
        if (trimStr(document.getElementById('txtClientReference'+i).value) != '')
        {
            validatePassword('txtClientReference'+i, 'lblClientReferenceErr'+i, 'Please do not key in spaces for the User Name for User Account #'+i+'.', 'lblErrMessage');
        }
        validateEmpty('txtPassword'+i, 'lblPasswordErr'+i, 'Please enter the Password for User Account #'+i+'.', 'lblErrMessage', false);
        validateEmpty('txtClientRef'+i, 'lblClientRefErr'+i, 'Please enter the Client Ref. for User Account #'+i+'.', 'lblErrMessage', false);
        if (trimStr(document.getElementById('txtClientRef'+i).value) != '')
        {
            validatePassword('txtClientRef'+i, 'lblClientRefErr'+i, 'Please do not key in spaces for the Client Ref. for User Account #'+i+'.', 'lblErrMessage');
        }
        validateEmpty('txtEmail'+i, 'lblEmailErr'+i, 'Please enter the Email for User Account #'+i+'.', 'lblErrMessage', false);
        validateDropDown('lstRolee'+i, 'lblRoleeErr'+i, 'Please select the Role for User Account #'+i+'.', 'lblErrMessage');
   }
}

function CSAAccountsValidate(intNumberOfAccounts)
{
    for (var i=1;i<=intNumberOfAccounts;i++)
    {
        validateEmpty('txtUserName'+i, 'lblUserNameErr'+i, 'Please enter the User Name for CSA Account #'+i+'.', 'lblErrMessage', false);
        validateEmpty('txtPassword'+i, 'lblPasswordErr'+i, 'Please enter the Password for CSA Account #'+i+'.', 'lblErrMessage', false);
        validateEmpty('txtEmail'+i, 'lblEmailErr'+i, 'Please enter the Email for CSA Account #'+i+'.', 'lblErrMessage', false);
    }  
}

function checkFlightNumberDisplay(intNumOfTaxi, intTransferTypeSelectedValue)
{
   if (intTransferTypeSelectedValue == 'Airport Arrival' || intTransferTypeSelectedValue == 'Airport Departure')
   {
        if (intNumOfTaxi == 1)
        {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
        } else if (intNumOfTaxi == 2) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
        } else if (intNumOfTaxi == 3) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
        } else if (intNumOfTaxi == 4) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
        } else if (intNumOfTaxi == 5) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
            
            trFlightNo51.style.display = 'block';
            trFlightNo52.style.display = 'block';
            trFlightNo53.style.display = 'block';
        } else if (intNumOfTaxi == 6) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
            
            trFlightNo51.style.display = 'block';
            trFlightNo52.style.display = 'block';
            trFlightNo53.style.display = 'block';
            
            trFlightNo61.style.display = 'block';
            trFlightNo62.style.display = 'block';
            trFlightNo63.style.display = 'block';
        } else if (intNumOfTaxi == 7) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
            
            trFlightNo51.style.display = 'block';
            trFlightNo52.style.display = 'block';
            trFlightNo53.style.display = 'block';
            
            trFlightNo61.style.display = 'block';
            trFlightNo62.style.display = 'block';
            trFlightNo63.style.display = 'block';
            
            trFlightNo71.style.display = 'block';
            trFlightNo72.style.display = 'block';
            trFlightNo73.style.display = 'block';
        } else if (intNumOfTaxi == 8) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
            
            trFlightNo51.style.display = 'block';
            trFlightNo52.style.display = 'block';
            trFlightNo53.style.display = 'block';
            
            trFlightNo61.style.display = 'block';
            trFlightNo62.style.display = 'block';
            trFlightNo63.style.display = 'block';
            
            trFlightNo71.style.display = 'block';
            trFlightNo72.style.display = 'block';
            trFlightNo73.style.display = 'block';
            
            trFlightNo81.style.display = 'block';
            trFlightNo82.style.display = 'block';
            trFlightNo83.style.display = 'block';
        } else if (intNumOfTaxi == 9) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
            
            trFlightNo51.style.display = 'block';
            trFlightNo52.style.display = 'block';
            trFlightNo53.style.display = 'block';
            
            trFlightNo61.style.display = 'block';
            trFlightNo62.style.display = 'block';
            trFlightNo63.style.display = 'block';
            
            trFlightNo71.style.display = 'block';
            trFlightNo72.style.display = 'block';
            trFlightNo73.style.display = 'block';
            
            trFlightNo81.style.display = 'block';
            trFlightNo82.style.display = 'block';
            trFlightNo83.style.display = 'block';
            
            trFlightNo91.style.display = 'block';
            trFlightNo92.style.display = 'block';
            trFlightNo93.style.display = 'block';
        } else if (intNumOfTaxi == 10) {
            trFlightNo11.style.display = 'block';
            trFlightNo12.style.display = 'block';
            trFlightNo13.style.display = 'block';
            
            trFlightNo21.style.display = 'block';
            trFlightNo22.style.display = 'block';
            trFlightNo23.style.display = 'block';
            
            trFlightNo31.style.display = 'block';
            trFlightNo32.style.display = 'block';
            trFlightNo33.style.display = 'block';
            
            trFlightNo41.style.display = 'block';
            trFlightNo42.style.display = 'block';
            trFlightNo43.style.display = 'block';
            
            trFlightNo51.style.display = 'block';
            trFlightNo52.style.display = 'block';
            trFlightNo53.style.display = 'block';
            
            trFlightNo61.style.display = 'block';
            trFlightNo62.style.display = 'block';
            trFlightNo63.style.display = 'block';
            
            trFlightNo71.style.display = 'block';
            trFlightNo72.style.display = 'block';
            trFlightNo73.style.display = 'block';
            
            trFlightNo81.style.display = 'block';
            trFlightNo82.style.display = 'block';
            trFlightNo83.style.display = 'block';
            
            trFlightNo91.style.display = 'block';
            trFlightNo92.style.display = 'block';
            trFlightNo93.style.display = 'block';
            
            trFlightNo101.style.display = 'block';
            trFlightNo102.style.display = 'block';
            trFlightNo103.style.display = 'block';
        }
   } else {
        if (intNumOfTaxi == 1)
        {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
        } else if (intNumOfTaxi == 2) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
        } else if (intNumOfTaxi == 3) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
        } else if (intNumOfTaxi == 4) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
        } else if (intNumOfTaxi == 5) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
            
            trFlightNo51.style.display = 'none';
            trFlightNo52.style.display = 'none';
            trFlightNo53.style.display = 'none';
        } else if (intNumOfTaxi == 6) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
            
            trFlightNo51.style.display = 'none';
            trFlightNo52.style.display = 'none';
            trFlightNo53.style.display = 'none';
            
            trFlightNo61.style.display = 'none';
            trFlightNo62.style.display = 'none';
            trFlightNo63.style.display = 'none';
        } else if (intNumOfTaxi == 7) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
            
            trFlightNo51.style.display = 'none';
            trFlightNo52.style.display = 'none';
            trFlightNo53.style.display = 'none';
            
            trFlightNo61.style.display = 'none';
            trFlightNo62.style.display = 'none';
            trFlightNo63.style.display = 'none';
            
            trFlightNo71.style.display = 'none';
            trFlightNo72.style.display = 'none';
            trFlightNo73.style.display = 'none';
        } else if (intNumOfTaxi == 8) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
            
            trFlightNo51.style.display = 'none';
            trFlightNo52.style.display = 'none';
            trFlightNo53.style.display = 'none';
            
            trFlightNo61.style.display = 'none';
            trFlightNo62.style.display = 'none';
            trFlightNo63.style.display = 'none';
            
            trFlightNo71.style.display = 'none';
            trFlightNo72.style.display = 'none';
            trFlightNo73.style.display = 'none';
            
            trFlightNo81.style.display = 'none';
            trFlightNo82.style.display = 'none';
            trFlightNo83.style.display = 'none';
        } else if (intNumOfTaxi == 9) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
            
            trFlightNo51.style.display = 'none';
            trFlightNo52.style.display = 'none';
            trFlightNo53.style.display = 'none';
            
            trFlightNo61.style.display = 'none';
            trFlightNo62.style.display = 'none';
            trFlightNo63.style.display = 'none';
            
            trFlightNo71.style.display = 'none';
            trFlightNo72.style.display = 'none';
            trFlightNo73.style.display = 'none';
            
            trFlightNo81.style.display = 'none';
            trFlightNo82.style.display = 'none';
            trFlightNo83.style.display = 'none';
            
            trFlightNo91.style.display = 'none';
            trFlightNo92.style.display = 'none';
            trFlightNo93.style.display = 'none';
        } else if (intNumOfTaxi == 10) {
            trFlightNo11.style.display = 'none';
            trFlightNo12.style.display = 'none';
            trFlightNo13.style.display = 'none';
            
            trFlightNo21.style.display = 'none';
            trFlightNo22.style.display = 'none';
            trFlightNo23.style.display = 'none';
            
            trFlightNo31.style.display = 'none';
            trFlightNo32.style.display = 'none';
            trFlightNo33.style.display = 'none';
            
            trFlightNo41.style.display = 'none';
            trFlightNo42.style.display = 'none';
            trFlightNo43.style.display = 'none';
            
            trFlightNo51.style.display = 'none';
            trFlightNo52.style.display = 'none';
            trFlightNo53.style.display = 'none';
            
            trFlightNo61.style.display = 'none';
            trFlightNo62.style.display = 'none';
            trFlightNo63.style.display = 'none';
            
            trFlightNo71.style.display = 'none';
            trFlightNo72.style.display = 'none';
            trFlightNo73.style.display = 'none';
            
            trFlightNo81.style.display = 'none';
            trFlightNo82.style.display = 'none';
            trFlightNo83.style.display = 'none';
            
            trFlightNo91.style.display = 'none';
            trFlightNo92.style.display = 'none';
            trFlightNo93.style.display = 'none';
            
            trFlightNo101.style.display = 'none';
            trFlightNo102.style.display = 'none';
            trFlightNo103.style.display = 'none';
        }
   }
}

// ---------------------------
// countdown timer
// ---------------------------
var _currentSeconds = 0;
var _sec = 0;
var _timeoutId;
var _redirectUrl = '';
var _secondPara = '';

function initialiseCountDown(countDown, redirectUrl, secondPara)
{
    _sec = countDown;
    _redirectUrl = redirectUrl;
    _secondPara = secondPara;
     
    SetCountdownText(countDown);
    
    clearTimeout(_timeoutId);  
    _timeoutId = window.setTimeout("CountDownTick()", 1000);
}

function CountDownTick()
{
    if (_currentSeconds <= 0)
    {
        var strUrl = _redirectUrl + '?sec=' + (_sec / 60);
        
        if (_secondPara != '')
        {
            strUrl += '&' + _secondPara;
        }
        
        window.location = strUrl
    }

    SetCountdownText(_currentSeconds - 1);
    
    clearTimeout(_timeoutId);    
    _timeoutId = window.setTimeout("CountDownTick()", 1000);
}

function SetCountdownText(seconds)
{
    _currentSeconds = seconds;

    var minutes = parseInt(seconds / 60);
    seconds = (seconds % 60);
    minutes = (minutes % 60);
    
    //display in readable format
    var strText = "This page will refresh in " + AddZero(minutes) + " mins " + AddZero(seconds) + " secs";
    window.status = strText;
}

function AddZero(num)
{
    return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}

function redirectCSA(url)
{
    if (confirm("This taxi booking has been updated by another CSA. Your changes have not been made.\n\nClick OK to refresh the page."))
    {
        window.location=url;
    }
}

function redirectUser(url)
{
    if (confirm("This taxi booking has been processed and updated. Your changes have not been made.\n\nClick OK to view all bookings."))
    {
        window.location=url;
    }
}

function cancelWarning(url)
{
    if (confirm("Are you sure you want to cancel this Booking?\n\nNote: You will not be able to undo the cancellation."))
    {
        window.location=url;
    }
}

function confirmBooking(url)
{
    if (confirm("Are you sure you want to proceed with the creation of this booking?"))
    {
        window.location=url;
    } 
}