﻿var constQuote = '"';
var constColourEZGreen = "#9CB86E";
var constColourEZBlue = "#99C0D0";
var constColourEZLightishGreen = "#D5DFC6";
var constColourEZLightGreen = "#F5FFE6";
var constColourEZDarkGreen = "#71893F";
var constColourEZExtraDarkGreen = "#51691F";
var constColourEZLightBlue = "#99C0D0";
var constColourEZDarkBlue = "#77858A";
var constColourEZLighterBlue = "#C3D7E3";
var constColourDisabled = "silver";
var constColourSelected = "#D68D41";
var constMonthArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var constDayArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

var g_iBodyWidth, g_iBodyHeight;

var g_sBrowserType;
var g_iBrowserVersion;
var g_iLoggedInUserID;
var g_iLoggedInUserName;
var g_iOrgID;
var g_iBobUserID = 0;
var g_iAdminMode = 0;
var g_iSelectedSlotTypeID = 0;
var g_iSelectedResourceID = 0;
var g_iSelectedResourceGroupID = 0;
var g_bIsOrgAdmin;
var g_bIsOrgMember;
var g_iUserSelectedOrgID;
var g_sOrgFolderName;
var g_sOrgName;
var g_sAdminOrgList;
var g_bOrgListBuilt = false;

var g_xmlServerGet = null;
var g_dCalendarMonth = null;
var g_dCalendarSelectedDay = null;
var g_selectedDateCell = null;

var g_sTabPreviousClassName = "";
var g_sSubTabPreviousClassName = "";
var g_iNumDays = 1;

var g_aResourceChooseSelectedID = new Array();

var g_sBLS = "0000";
var g_sListSort = "a1";

function fnAppInit() {

    fnCommonInit();
}

function fnCommonInit() {

    g_dCalendarSelectedDay = new Date();

    var sSelectedDate = fnGetMasterElem("hfCalendarSelectedDate").value;
    if (sSelectedDate != "") {
        g_dCalendarSelectedDay = fnUtilGetDate(sSelectedDate);
    }

    g_sBrowserType = fnGetMasterElem("hfBrowserType").value;
    g_iBrowserVersion = fnGetMasterElem("hfBrowserVersion").value;
    g_iLoggedInUserID = fnGetMasterElem("hfUserID").value;
    g_iLoggedInUserName = fnGetMasterElem("hfUserName").value;
    g_iOrgID = fnGetMasterElem("hfOrgID").value;
    g_bIsOrgAdmin = fnGetMasterElem("hfIsOrgAdmin").value == "True";
    g_bIsOrgMember = fnGetMasterElem("hfIsOrgMember").value == "True";
    g_sOrgName = fnGetMasterElem("hfOrgName").value;
    g_sOrgFolderName = fnGetMasterElem("hfOrgFolderName").value;
    g_iSelectedSlotTypeID = fnGetMasterElem("hfSlotTypeID").value;
    g_iSelectedResourceID = fnGetMasterElem("hfResourceID").value;
    g_iSelectedResourceGroupID = fnGetMasterElem("hfResourceGroupID").value;
    g_iBobUserID = fnGetMasterElem("hfBobUserID").value;
    g_iAdminMode = fnGetMasterElem("hfAdminMode").value;
    g_sAdminOrgList = fnGetMasterElem("hfAdminOrgList").value;
    g_sBLS = fnGetMasterElem("hfBLS").value;
    g_sListSort = fnGetMasterElem("hfLS").value;

    g_iUserSelectedOrgID = fnGetMasterElem("hfUserSelectedOrgID").value;

    if (g_iOrgID == 0) {
        g_iOrgID = g_iUserSelectedOrgID;
    }

}

function fnAppWindowResize() {

    if (self.innerHeight) // all except Explorer
    {
        g_iBodyWidth = self.innerWidth * 1;
        g_iBodyHeight = self.innerHeight * 1;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
    {
        g_iBodyWidth = document.documentElement.clientWidth;
        g_iBodyHeight = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        g_iBodyWidth = document.body.clientWidth;
        g_iBodyHeight = document.body.clientHeight;
    }

    var sHeight = g_iBodyHeight - 100 + "px";
    fnGetClientElem("divMain").style.height = sHeight;

    fnPageResize();
}

function fnPageResize() {


}

function fnUtilXMLEscape(sText) {

    var re = new RegExp("&", "gi");
    sText = sText.replace(re, "&amp;");

    re = new RegExp(">", "gi");
    sText = sText.replace(re, "&gt;");

    re = new RegExp("<", "gi");
    sText = sText.replace(re, "&lt;");

    re = new RegExp(constQuote, "gi");
    sText = sText.replace(re, "&quot;");

    return sText;
}

function fnUtilDateGetString(theDate) {

    var sDate = theDate.getFullYear() + fnUtilPadZeroes(theDate.getMonth() + 1, 2) + fnUtilPadZeroes(theDate.getDate(), 2);
    return sDate;
}

function fnUtilDateGetDisplayDate(theDate, iFormat) {

    var sDate = "";

    switch (iFormat) {
        case 1:
            sDate += constDayArray[theDate.getDay()].substr(0, 3) + " " + theDate.getDate() + " " + constMonthArray[theDate.getMonth()].substr(0, 3)
            break;
        case 2:
            sDate += theDate.getDate();
            break;
    }

    return sDate;
}


function fnUtilGetDate(sDateString) {

    var dDate = new Date(sDateString.substr(0, 4), sDateString.substr(4, 2) - 1, sDateString.substr(6, 2));
    return dDate;
}


function fnUtilPadZeroes(iNum, iNumDigits) {

    var sString = iNum.toString();
    while (sString.length < iNumDigits) {
        sString = "0" + sString;
    }

    return sString;
}

function fnTrim(sStringToTrim) {
    return sStringToTrim.replace(/^\s+|\s+$/g, "");
}

function fnGetElem(sID) {

    return document.getElementById("ctl00_cphMain_" + sID);
}

function fnGetClientElem(sID) {

    return document.getElementById(sID);
}

function fnGetMasterElem(sID) {

    return document.getElementById("ctl00_" + sID);
}

function fnInputGetValue(sFieldName) {

    var sReturn = "";
    var theInput = fnGetElem("txt" + sFieldName);
    if (theInput != null) {
        sReturn = fnTrim(theInput.value);
    }

    fnErrorLabel(sFieldName, "");
    return sReturn;
}

function fnErrorLabel(sFieldName, sErrorText) {

    fnGetElem("lbl" + sFieldName + "Error").innerHTML = sErrorText;
    var bValid = true;
    if (sErrorText != "") {
        bValid = false;
        var theInput = fnGetElem("txt" + sFieldName);
        if (theInput != null) {
            fnGetElem("txt" + sFieldName).focus();
        }
    }
    return bValid;
}


function fnCreateOrgValidate() {

    var bValid = true;

    if (g_iLoggedInUserID == 0) {
        bValid = fnUserInfoCreateValidate();
    }

    if (fnInputGetValue("OrgName") == "") {
        bValid = fnErrorLabel("OrgName", "please enter a business name");
    }

    return bValid;

}

function fnGrow2010Validate() {

    var bValid = true;


    fnErrorLabel("Terms", "");
    if (fnGetElem("chkTerms").checked == false) {
        bValid = fnErrorLabel("Terms", "please confirm you have read and understood the Terms and Conditions");
        fnGetElem("chkTerms").focus();
    }


    if (fnInputGetValue("ConfirmPassword") == "") {
        bValid = fnErrorLabel("ConfirmPassword", "please confirm your password");
    }

    if (fnInputGetValue("Password") == "") {
        bValid = fnErrorLabel("Password", "please enter a password");
    } else {
        if (fnInputGetValue("Password").length < 8) {
            bValid = fnErrorLabel("Password", "password must be at least 8 characters");
        } else {
            if (fnInputGetValue("Password") != fnInputGetValue("ConfirmPassword")) {
                bValid = fnErrorLabel("ConfirmPassword", "confirmation password does not match");
            }
        }
    }

    if (fnInputGetValue("OrgName") == "") {
        bValid = fnErrorLabel("OrgName", "please enter a business name");
    }


    if (fnInputGetValue("PostCode") == "") {
        bValid = fnErrorLabel("PostCode", "please enter a postcode");
    }

    if (fnInputGetValue("City") == "") {
        bValid = fnErrorLabel("City", "please enter a city");
    }

    if (fnInputGetValue("Suburb") == "") {
        bValid = fnErrorLabel("Suburb", "please enter a suburb");
    }

    if (fnInputGetValue("Address") == "") {
        bValid = fnErrorLabel("Address", "please enter an address");
    }


    bValid = fnCheckIsMobile("Work", bValid);

    bValid = fnCheckIsEmail("Email", bValid);

    if (fnInputGetValue("FirstName") == "") {
        bValid = fnErrorLabel("FirstName", "please enter a first name");
    }

    if (fnInputGetValue("LastName") == "") {
        bValid = fnErrorLabel("LastName", "please enter a last name");
    }

    if (fnGetElem("rbMemberYes").checked == false && fnGetElem("rbMemberNo").checked == false) {
        bValid = fnErrorLabel("MemberSelect", "please enter yes or no");
    } else {
        fnErrorLabel("MemberSelect", "");
    }

    if (fnGetElem("rbPaymentWeekly").checked == false && fnGetElem("rbPaymentMonthly").checked == false) {
        bValid = fnErrorLabel("PaymentSelect", "please enter weekly or monthly");
    } else {
        fnErrorLabel("PaymentSelect", "");
    }


    return bValid;


}

function fnUserInfoCreateValidate() {

    var bValid = true;

    fnErrorLabel("Terms", "");
    if (fnGetElem("chkTerms").checked == false) {
        bValid = fnErrorLabel("Terms", "please confirm you have read and understood the ezybook User Terms and Conditions");
        fnGetElem("chkTerms").focus();
    }

    if (fnInputGetValue("ConfirmPassword") == "") {
        bValid = fnErrorLabel("ConfirmPassword", "please confirm your password");
    }

    if (fnInputGetValue("Password") == "") {
        bValid = fnErrorLabel("Password", "please enter a password");
    } else {
        if (fnInputGetValue("Password").length < 8) {
            bValid = fnErrorLabel("Password", "password must be at least 8 characters");
        } else {
            if (fnInputGetValue("Password") != fnInputGetValue("ConfirmPassword")) {
                bValid = fnErrorLabel("ConfirmPassword", "confirmation password does not match");
            }
        }
    }

    bValid = fnCheckIsMobile("Mobile", bValid);

    if (fnInputGetValue("Email") != fnInputGetValue("ConfirmEmail")) {
        bValid = fnErrorLabel("ConfirmEmail", "confirmation email address does not match");
    }

    bValid = fnCheckIsEmail("Email", bValid);

    if (fnInputGetValue("FirstName") == "") {
        bValid = fnErrorLabel("FirstName", "please enter a first name");
    }

    if (fnInputGetValue("LastName") == "") {
        bValid = fnErrorLabel("LastName", "please enter a last name");
    }

    return bValid;
}

function fnUserInfoUpdateValidate() {

    var bValid = true;

    fnErrorLabel("Terms", "");
    if (fnGetElem("chkTerms").checked == false) {
        bValid = fnErrorLabel("Terms", "please confirm you have read and understood the ezybook User Terms and Conditions");
        fnGetElem("chkTerms").focus();
    }

    if (fnInputGetValue("NewPassword") != "") {
        if (fnInputGetValue("ConfirmNewPassword") == "") {
            bValid = fnErrorLabel("ConfirmNewPassword", "please confirm your new password");
        } if (fnInputGetValue("NewPassword").length < 8) {
            bValid = fnErrorLabel("NewPassword", "password must be at least 8 characters");
        } else {
            if (fnInputGetValue("NewPassword") != fnInputGetValue("ConfirmNewPassword")) {
                bValid = fnErrorLabel("ConfirmNewPassword", "confirmation password does not match");
            }
        }
    }

    if (fnInputGetValue("ExistingPassword") == "") {
        bValid = fnErrorLabel("ExistingPassword", "please enter your existing password");
    }

    if (fnGetElem("hfEmailOriginal").value != fnGetElem("txtEmail").value) {
        fnGetElem("trConfirmEmail").style.display = "inline";
        if (fnInputGetValue("ConfirmEmail") != fnInputGetValue("Email")) {
            if (fnInputGetValue("ConfirmEmail") == "") {
                bValid = fnErrorLabel("ConfirmEmail", "please confirm the updated email address");
            } else {
                bValid = fnErrorLabel("ConfirmEmail", "email address does not match");
            }
        } else {
            fnErrorLabel("ConfirmEmail", "");
        }
    } else {
        fnGetElem("trConfirmEmail").style.display = "none";
    }

    bValid = fnCheckIsMobile("Mobile", bValid);
    bValid = fnCheckIsEmail("Email", bValid);

    if (fnInputGetValue("FirstName") == "") {
        bValid = fnErrorLabel("FirstName", "please enter a first name");
    }

    if (fnInputGetValue("LastName") == "") {
        bValid = fnErrorLabel("LastName", "please enter a last name");
    }

    return bValid;
}

function fnContactUsValidate() {

    var bValid = true;

    if (fnInputGetValue("Name") == "") {
        bValid = fnErrorLabel("Name", "please enter a name");
    }

    bValid = fnCheckIsEmail("Email", bValid);

    if (fnInputGetValue("Message") == "") {
        bValid = fnErrorLabel("Message", "please enter a message");
    }

    return bValid;
}

function fnSendPasswordValidate() {

    var bValid = true;
    bValid = fnCheckIsEmail("Email", bValid);
    return bValid;
}

function fnCustomerUpdateValidate() {

    var bValid = true;

    if (fnInputGetValue("Email") != "") {
        bValid = fnCheckIsEmail("Email", bValid);
    }

    if (fnInputGetValue("FirstName") == "") {
        bValid = fnErrorLabel("FirstName", "please enter a first name");
    }

    //	if (fnInputGetValue("LastName") == "") {
    //		bValid = fnErrorLabel("LastName", "please enter a last name");
    //	}

    return bValid;
}

function fnCheckIsMobile(sFieldName, bValid) {

    fnErrorLabel(sFieldName, "");

    var sMobile = fnInputGetValue(sFieldName);
    if (sMobile.length < 7) {
        bValid = fnErrorLabel(sFieldName, "please enter a valid phone number");
    }

    return bValid;
}

function fnCheckIsEmail(sFieldName, bValid) {

    fnErrorLabel(sFieldName, "");

    var sEmail = fnInputGetValue(sFieldName).toLowerCase();
    if (sEmail == "") {
        bValid = fnErrorLabel(sFieldName, "please enter an email address");
    } else {
        var re = new RegExp("[a-z0-9!#$%&'*+/=?^_6.css{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_6.css{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
        if (re.test(sEmail) == false) {
            bValid = fnErrorLabel(sFieldName, "please enter a valid email address");
        }
    }

    return bValid;
}


function fnCalendarBuildTable(theTable) {

    var x;
    for (x = 1; x < 7; x++) {
        var newCell = theTable.rows[2].cells[0].cloneNode(true);
        theTable.rows[2].appendChild(newCell);
    }

    var y;
    for (y = 1; y < 6; y++) {
        var newRow = theTable.rows[2].cloneNode(true);
        theTable.tBodies[0].appendChild(newRow);
    }
}


function fnCalendarSetMonth(dMonth) {

    var dCalMonth = new Date(dMonth);

    fnCalendarPopulateTable("tblCal1", "tdCalMonth1", dCalMonth);
    if (fnGetClientElem("tblCal2") != null) {
        dCalMonth.setMonth(dCalMonth.getMonth() + 1);
        fnCalendarPopulateTable("tblCal2", "tdCalMonth2", dCalMonth);
    }
}

function fnCalendarPopulateTable(sTableID, sMonthLabelID, dMonth) {

    var dDay = new Date(dMonth);
    dDay.setDate(1);

    var iDayOffset = dDay.getDay();
    if (iDayOffset == 0) { iDayOffset = 7 }

    var x;
    var y;
    var bStarted = false;
    var bFinished = false;
    var theTable = fnGetClientElem(sTableID);
    var theMonth = fnGetClientElem(sMonthLabelID);
    theMonth.innerHTML = constMonthArray[dDay.getMonth()] + " " + dDay.getFullYear();

    var dToday = new Date();

    for (y = 2; y < 8; y++) {
        for (x = 0; x < 7; x++) {
            var theCell = theTable.rows[y].cells[x];

            if ((x >= iDayOffset - 1 || bStarted) && !bFinished) {
                bStarted = true;
            } else {
                theCell.innerHTML = "&nbsp;";
            }

            if (g_dCalendarSelectedDay.toDateString() == dDay.toDateString() && bStarted) {
                theCell.style.backgroundColor = constColourEZDarkGreen;
                theCell.style.color = constColourEZLightGreen;
                g_selectedDateCell = theCell;
            } else {
                theCell.style.backgroundColor = "";
                theCell.style.color = "";
            }

            theCell.style.borderColor = "";

            if (bStarted) {
                if (dToday.toDateString() == dDay.toDateString()) {
                    theCell.style.borderColor = constColourSelected;
                }

                var iDate = dDay.getDate();
                theCell.innerHTML = iDate
                theCell.fulldate = fnUtilDateGetString(dDay);
                dDay.setDate(iDate + 1);

                if (dDay.getDate() == 1) {
                    bFinished = true;
                    bStarted = false;
                }
            }
        }
    }

}

function fnCalendarSetDate(theDate) {

    g_dCalendarSelectedDay = new Date(theDate);
    fnGetMasterElem("hfCalendarSelectedDate").value = fnUtilDateGetString(g_dCalendarSelectedDay);
}



function fnCalClick(theCell) {

    if (theCell.fulldate == null) { return }

    if (g_selectedDateCell != null) {
        g_selectedDateCell.style.backgroundColor = "";
        g_selectedDateCell.style.color = "";
    }

    theCell.style.backgroundColor = constColourSelected;
    theCell.style.color = constColourEZLightGreen;
    g_selectedDateCell = theCell;

    fnCalendarSetDate(fnUtilGetDate(theCell.fulldate));
    fnCalendarDateSelected();
}


function fnTimeDayBuildDateString(theDate) {

    var sDateString = constDayArray[theDate.getDay()] + ", ";
    sDateString += theDate.getDate();
    sDateString += " " + constMonthArray[theDate.getMonth()] + " " + theDate.getFullYear();

    return sDateString;
}

function fnDatePickerDown() {

    g_dCalendarMonth.setMonth(g_dCalendarMonth.getMonth() - 1);
    fnCalendarSetMonth(g_dCalendarMonth);
}

function fnDatePickerUp() {

    g_dCalendarMonth.setMonth(g_dCalendarMonth.getMonth() + 1);
    fnCalendarSetMonth(g_dCalendarMonth);
}

function fnBookLink(iOrgID, iSlotTypeID, iResourceID) {

    var sURL = "/book/makeabooking.aspx";
    sURL += "?o=" + iOrgID;
    sURL += "&s=" + iSlotTypeID;
    sURL += "&r=" + iResourceID;
    window.location = sURL;
}

function fnAdminBookOnBehalf() {

    fnBOBBookLink(g_iOrgID, g_iSelectedSlotTypeID, g_iBobUserID);
}

function fnBOBBookLink(iOrgID, iSlotTypeID, iUserID) {

    var sURL = "/book/makeabooking.aspx";
    sURL += "?o=" + iOrgID;
    sURL += "&s=" + iSlotTypeID;
    sURL += "&r=" + g_iSelectedResourceID;
    sURL += "&u=" + iUserID;
    sURL += "&d=" + fnUtilDateGetString(g_dCalendarSelectedDay);
    sURL += "&a=1";
    sURL += "&bls=" + g_sBLS;
    sURL += "&ls=" + g_sListSort;
    sURL += "&rg=" + g_iSelectedResourceGroupID;

    window.location = sURL;
}

function fnEzyAdminClick() {

    fnBookingListClick();
}

function fnEzyAccountPageClick() {

    var sURL = "/ezyadmin/ezyaccount.aspx" + fnAdminGetQueryString();
    window.location = sURL
}

function fnHomeClick() {

    var sURL = "/pages/" + g_sOrgFolderName + "/";
    window.location = sURL;
}

function fnWelcomeClick() {

    var sURL = "/";
    window.location = sURL;
}

function fnAboutClick() {

    var sURL = "/about.aspx";
    window.location = sURL;
}

function fnDemoClick() {

    var sURL = "/demo.aspx";
    window.location = sURL;
}

function fnTellMeMoreClick() {

    var sURL = "/tellmemore.aspx";
    window.location = sURL;
}

function fnSignMeUpClick() {

    var sURL = "/signmeup.aspx";
    window.location = sURL;
}

function fnPartnersClick() {

    var sURL = "/ourpartners.aspx";
    window.location = sURL;
}

function fnHelpClick() {

    var sURL = "/support.aspx";
    window.location = sURL;
}

function fnCommunityClick() {

    var sURL = "/community";
    window.location = sURL;
}

function fnFindABusinessClick() {

    var sURL = "/community";
    window.location = sURL;
}

function fnListMyBusinessClick() {

    var sURL = "/community/listmybusiness.aspx";
    window.location = sURL;
}

function fnHomePageInit() {

    g_dCalendarSelectedDay = new Date();

    var sQueryString = window.location.search;
    sQueryString = sQueryString.substr(1, sQueryString.length - 1);

    if (sQueryString != "") {
        var aQueryString = sQueryString.split("&");
        var x;
        for (x = 0; x < aQueryString.length; x++) {
            var aPair = aQueryString[x].split("=");
            switch (aPair[0]) {
                case "o":
                    g_iOrgID = aPair[1] * 1;
                    break;
                case "d":
                    g_dCalendarSelectedDay = fnUtilGetDate(aPair[1]);
                    break;
                case "s":
                    g_iSelectedSlotTypeID = aPair[1] * 1;
                    break;
                case "r":
                    g_iSelectedResourceID = aPair[1] * 1;
                    break;
            }
        }
    }
}

function fnOrgHomePageClick() {

    sURL = "/pages/" + g_sOrgFolderName;
    //+ "/" + fnGetBaseQueryString();
    window.location = sURL;
}

function fnOrgBookingsClick(iOrgID) {

    if (iOrgID == null) {
        iOrgID = g_iOrgID;
    } else {
        g_iOrgID = iOrgID;
    }

    var sURL = "/book/makeabooking.aspx" + fnGetBaseQueryString();
    window.location = sURL;
}

function fnOrgContactUsClick(iOrgID) {

    if (iOrgID == null) {
        iOrgID = g_iOrgID;
    }

    var sURL = "/contactus.aspx";
    sURL += "?o=" + iOrgID;

    window.location = sURL;
}

function fnBookingLinkClick(iOrgID, iSlotTypeID, iResourceID) {

    var sURL = "/book/makeabooking.aspx?o=" + iOrgID;
    sURL += "&s=" + iSlotTypeID;
    sURL += "&r=" + iResourceID;
    sURL += "&d=" + fnUtilDateGetString(g_dCalendarSelectedDay);
    window.location = sURL;
}

function fnOrgHomeAdminMode() {

    fnGetClientElem("divTab4").style.display = "inline";
    fnGetClientElem("divTab4Blank").style.display = "none";

}

function fnHomePageEzyAdminClick() {

    var sURL = "/ezyadmin/" + fnGetBaseQueryString();
    window.location = sURL
}

function fnMyClick() {

    var sURL = "/myezybook";
    window.location = sURL;
}

function fnUpcomingBookingsClick() {

    var sURL = "/myezybook/default.aspx?t=upcoming";
    window.location = sURL;
}

function fnPastBookingsClick() {

    var sURL = "/myezybook/default.aspx?t=past";
    window.location = sURL;
}

function fnCustomerListClick() {

    var sURL = "/ezyadmin/customersearch.aspx" + fnAdminGetQueryString();
    window.location = sURL;
}

function fnAdminHomePageClick() {

    var sURL = "/pages/" + g_sOrgFolderName + "/" + fnGetBaseQueryString();
    //var sURL = "/book/makeabooking.aspx" + fnGetBaseQueryString();
    window.location = sURL;
}

function fnGetBaseQueryString() {

    if (g_iSelectedSlotTypeID == "") {
        g_iSelectedSlotTypeID = 0;
    }

    if (g_iSelectedResourceID == "") {
        g_iSelectedResourceID = 0;
    }

    var sURL = "?o=" + g_iOrgID;
    sURL += "&s=" + g_iSelectedSlotTypeID;
    sURL += "&r=" + g_iSelectedResourceID;
    sURL += "&d=" + fnUtilDateGetString(g_dCalendarSelectedDay);
    return sURL;
}


function fnAdminGetQueryString() {

    var sURL = fnGetBaseQueryString();
    sURL += "&u=" + g_iBobUserID;
    sURL += "&a=1";
    sURL += "&bls=" + g_sBLS;
    sURL += "&ls=" + g_sListSort;
    sURL += "&rg=" + g_iSelectedResourceGroupID;
    return sURL;
}

function fnBookingListClick() {

    var sURL = "/ezyadmin/" + fnAdminGetQueryString();
    window.location = sURL;
}

function fnEditWebPageClick() {

    var sURL = "/ezyadmin/editwebpage.aspx" + fnAdminGetQueryString();
    window.location = sURL;
}

function fnUserInfoClick() {

    var sReturnPage = window.location;
    var sURL = "/userinfo.aspx";
    if (g_sOrgName != "") {
        sURL += "?returnpage=" + escape(sReturnPage) + "&name=" + escape(g_sOrgName);
    }
    window.location = sURL;
}

function fnValidate() {

    var sReturnPage = window.location;
    var sURL = "/emailconfirm.aspx";
    if (g_sOrgName != "") {
        sURL += "?returnpage=" + escape(sReturnPage) + "&name=" + escape(g_sOrgName);
    }

    window.location = sURL;
}


function fnEmailConfirmationCodeClick() {

    var sURL = "/emailconfirm.aspx";
    window.location = sURL;
}


function fnEnterConfirmation() {

    window.location = "/emailconfirm.aspx";
}

function fnUtilGetTimeAmPm(dDate) {

    var sAmPm = "a.m.";
    var iHours = dDate.getHours();
    if (iHours > 11) {
        sAmPm = "p.m.";
        iHours = iHours - 12;
    }

    if (iHours == 0) {
        iHours = "12";
    }

    return fnUtilPadZeroes(iHours, 2) + ":" + fnUtilPadZeroes(dDate.getMinutes(), 2) + sAmPm;

}


function fnCalendarDayUpDown(iDir) {

    g_dCalendarSelectedDay.setDate(g_dCalendarSelectedDay.getDate() + iDir);

    if (g_dCalendarSelectedDay.getMonth() != g_dCalendarMonth.getMonth() && g_dCalendarSelectedDay.getMonth() != g_dCalendarMonth.getMonth() + 1) {
        g_dCalendarMonth = new Date(g_dCalendarSelectedDay);
        g_dCalendarMonth.setDate(1);
    }

    fnCalendarSetMonth(g_dCalendarMonth);
    fnCalendarSetDate(g_dCalendarSelectedDay);
    fnCalendarDateSelected();
}


function fnTabMouseOver(theTab) {

    g_sTabPreviousClassName = theTab.className;
    var sOn = g_sTabPreviousClassName.substr(g_sTabPreviousClassName.length - 2, 2);
    if (sOn != "On") {
        theTab.className = g_sTabPreviousClassName + "On";
    }
}

function fnTabMouseOut(theTab) {

    if (g_sTabPreviousClassName == "") {
        var sClassName = theTab.className;
        sClassName = sClassName.substr(0, sClassName.length - 2);
        theTab.className = sClassName;
    } else {
        theTab.className = g_sTabPreviousClassName;
    }
}

function fnSubTabMouseOver(theTab) {

    g_sSubTabPreviousClassName = theTab.className;
    theTab.className = "spnSubTabOn";
}

function fnSubTabMouseOut(theTab) {

    if (g_sSubTabPreviousClassName == "") {
        theTab.className = "spnSubTab";
    } else {
        theTab.className = g_sSubTabPreviousClassName;
    }
}

function fnButtonMouseOver(theTab) {

    theTab.className = "inpAButOn";
}

function fnButtonMouseOut(theTab) {

    theTab.className = "inpABut";
}

function fnCancelEnter(e) {

}

function fnRowMouseOver(theRow) {

    g_sPopupRowPreviousClass = theRow.className;
    theRow.className = "trPopupListSelectedRow";
}

function fnRowMouseOut(theRow) {

    theRow.className = g_sPopupRowPreviousClass;
}

function fnGetResourceNameFromID(iResourceID) {

    var sName = "";
    var aResourceID = g_sResourceIDList.split("|");
    var x;
    for (x = 0; x < aResourceID.length; x++) {
        if (aResourceID[x] == iResourceID) {
            sName = g_sResourceNameList.split("|")[x];
        }
    }

    return sName;
}

function fnGetGroupIDForResource(iResourceID) {

    var iGroupID = 0;
    var aResourceID = g_sOrgResourceIDList.split("|");
    var x;
    for (x = 0; x < aResourceID.length; x++) {
        if (aResourceID[x] == iResourceID) {
            iGroupID = g_sOrgResourceGroupIDList.split("|")[x] * 1;
        }
    }

    return iGroupID;
}

function fnGetResourceGroupNameFromID(iResourceGroupID) {

    var sName = "";
    var aResourceGroupID = g_sResourceGroupIDList.split("|");
    var x;
    for (x = 0; x < aResourceGroupID.length; x++) {
        if (aResourceGroupID[x] == iResourceGroupID) {
            sName = g_sResourceGroupNameList.split("|")[x];
        }
    }

    return sName;
}

function fnMouseOver(theObject) {

    sClass = theObject.className;
    theObject.className = sClass + "MO";
}

function fnMouseOut(theObject) {

    sClass = theObject.className;
    theObject.className = sClass.substring(0, sClass.length - 2);
}

function fnInputFocus(theObject) {

    theObject.style.borderColor = constColourSelected;
    return;
}

function fnInputBlur(theObject) {

    theObject.style.borderColor = "";
    return;

}

function fnLoginFrameCheckAdmin() {

    if (fnGetClientElem("hfAdminMode").value == "1") {
        parent.fnOrgHomeAdminMode();
    }
}

function fnAdminOrgListClick() {

    var aOrgList = g_sAdminOrgList.split("|");

    if (aOrgList.length > 1) {
        var divPopup = fnGetClientElem("divAdminSelectOrgPopup");
        if (divPopup.style.display == "none" || divPopup.style.display == "") {
            divPopup.style.display = "inline";
            if (!g_bOrgListBuilt) {
                g_bOrgListBuilt = true;
                var divPopup = fnGetClientElem("divAdminSelectOrgPopup");
                var iHeight = aOrgList.length * 18;
                if (iHeight > 126) {
                    iHeight = 126;
                }

                divPopup.style.height = iHeight + "px";

                var divFirstRow = fnGetClientElem("divAdminSelectOrgRow");
                var x;
                for (x = 0; x < aOrgList.length; x++) {
                    var iOrgID = aOrgList[x].split("~")[0];
                    var sOrgName = aOrgList[x].split("~")[1];
                    if (x == 0) {
                        divFirstRow.innerHTML = sOrgName
                        divFirstRow.orgid = iOrgID;
                    } else {
                        var divNewRow = fnGetClientElem("divAdminSelectOrgRow").cloneNode(true);
                        divPopup.appendChild(divNewRow);
                        divNewRow.id = "";
                        divNewRow.innerHTML = sOrgName
                        divNewRow.orgid = iOrgID;
                    }
                }
            }
        } else {
            divPopup.style.display = "none";
        }
    }
}

function fnAdminSelectOrgRowClick(divClicked) {

    var iOrgID = divClicked.orgid;
    g_iOrgID = iOrgID;
    g_iSelectedSlotTypeID = 0;
    g_iSelectedResourceID = 0;
    g_iBobUserID = 0;
    window.location = fnAdminGetQueryString();
}

function fnTrimEndChars(sText, iNumChars) {

    return sText.substring(0, sText.length - iNumChars);
}

function fnResourceChooseSelect(iResourceListMode, iResourceID) {

    var iResourceSelectedID = 0
    var x;
    for (x = 0; x < g_aResourceChooseSelectedID.length; x++) {
        if (g_aResourceChooseSelectedID[x][0] == iResourceListMode) {
            iResourceSelectedID = g_aResourceChooseSelectedID[x][1];
            g_aResourceChooseSelectedID[x][1] = iResourceID;
        }
    }

    var divResourcePanel = fnGetClientElem("divResourceBox" + iResourceListMode + "-" + iResourceSelectedID);
    divResourcePanel.style.display = "none";

    var divSelectRow = fnGetClientElem("divResourceSelectRow" + iResourceListMode + "-" + iResourceSelectedID);
    divResourcePanel.style.display = "none";
    divSelectRow.className = "divBookingResourceChooseItem";

    divResourcePanel = fnGetClientElem("divResourceBox" + iResourceListMode + "-" + iResourceID);
    divResourcePanel.style.display = "inline";

    divSelectRow = fnGetClientElem("divResourceSelectRow" + iResourceListMode + "-" + iResourceID);
    divSelectRow.className = "divBookingResourceChooseItemSELECTEDMO";

    if (iResourceSelectedID == 0) {

        g_aResourceChooseSelectedID[g_aResourceChooseSelectedID.length] = new Array();
        g_aResourceChooseSelectedID[g_aResourceChooseSelectedID.length - 1][0] = iResourceListMode;
        g_aResourceChooseSelectedID[g_aResourceChooseSelectedID.length - 1][1] = iResourceID;
    }

}

function fnCalendarPopup(bClose) {

    var theDiv = fnGetClientElem("divCalendarPopup");

    if (theDiv.style.visibility != "visible" && !bClose) {
        theDiv.style.visibility = "visible";
    } else {
        theDiv.style.visibility = "hidden";
    }
}

function fnDateLink(iMode) {

    g_dCalendarSelectedDay = new Date();

    switch (iMode) {
        case 1:
            g_dCalendarSelectedDay.setHours(24);
            break;
        case 2:
            g_dCalendarSelectedDay.setHours(24);
            while (g_dCalendarSelectedDay.getDay() != 1) {
                g_dCalendarSelectedDay.setHours(24);
            }
            break;
        case 3:
            g_dCalendarSelectedDay.setHours(24);
            while (g_dCalendarSelectedDay.getDate() != 1) {
                g_dCalendarSelectedDay.setHours(24);
            }
            break;
    }

    fnCalendarDateSelected();

}

function fnCapitaliseFirst(theField) {

    var sValue = theField.value;
    if (sValue.length == 1) {
        theField.value = sValue.toUpperCase();
    }
}