﻿// JScript File


/*
Comment: 
below code is used to refresh home page or start again book page with new values.
say if user is on other pages (eg select-your-bus tab) and clicks browser back, then default page doesn't get
refreshed with new values. so for that below code refreshes the page
   
How it Works: it checks for the defined set of page url and if they are found it doesn't refresh the page
but in case these pages are not in url then it refreshes that page again as new
                 
*/

//alert(get_cookie ( 'perimeterbusbackrefresh' ))


var PerimeterPaymentPageUrl = 'payment';
var PerimeterSelectBusUrl = 'select-your-bus';
var PerimeterPassengerUrl = 'passenger-details';
var PerimeterReceiptUrl = 'confirmation-receipt';
var LiftTicketUrl = 'lift-tickets';
var PerimeterBookingPageAdminUrl = 'admin';

var _WINHREF = window.location.href.toLowerCase();

if (_WINHREF.indexOf(PerimeterSelectBusUrl) == -1 && _WINHREF.indexOf(PerimeterPassengerUrl) == -1
    && _WINHREF.indexOf(PerimeterPaymentPageUrl) == -1 && _WINHREF.indexOf(PerimeterReceiptUrl) == -1 && _WINHREF.indexOf(PerimeterBookingPageAdminUrl) == -1 && _WINHREF.indexOf(LiftTicketUrl) == -1) {
    var perimeterbusbackrefresh = get_cookie("perimeterbusbackrefresh"); //Plz check the logout button and login button for this cookie
    if (perimeterbusbackrefresh != null) {
        delete_cookie("perimeterbusbackrefresh")
        window.location.href = window.location.href;
    }
}



//    var PerimeterBookingPageUrl = 'perimeter-reservations';
//    var PerimeterPaymentPageUrl = 'perimeter-payment';
//    var PerimeterSecureReservationPageUrl = 'securereservations';
//   
//     var PerimeterBookingPageAdminUrl = 'admin';
//    var _WINHREF = window.location.href.toLowerCase();
//    
//    if(_WINHREF.indexOf(PerimeterBookingPageUrl) == -1 && _WINHREF.indexOf(PerimeterBookingPageAdminUrl) == -1 && _WINHREF.indexOf(PerimeterPaymentPageUrl) == -1 && _WINHREF.indexOf(PerimeterSecureReservationPageUrl) == -1)
//    {
//           var perimeterbusbackrefresh = get_cookie ( "perimeterbusbackrefresh" );//Plz check the logout button and login button for this cookie
//            if(perimeterbusbackrefresh!=null)
//            {
//                delete_cookie ( "perimeterbusbackrefresh" )
//                window.location.href=window.location.href;
//            }
//    }


function set_cookie(name, value) {
    document.cookie = name + "=" + escape(value);
}

function get_cookie(cookie_name) {
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if (results)
        return (unescape(results[2]));
    else
        return null;
}

function delete_cookie(cookie_name) {
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

//***************************************************
// To make display on Screen Center
//***************************************************

function showcenterdivAlert(Xwidth, Yheight, divid) {

    // First, determine how much the visitor has scrolled 
    //alert(divid.id)
    var scrolledX, scrolledY;

    if (self.pageYoffset) {
        scrolledX = self.pageXoffset;
        scrolledY = self.pageYoffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window 
    var bws = getBrowserHeight();

    var centerX, centerY;
    centerX = bws.width;
    centerY = bws.height;

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    //var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
    var leftoffset = (centerX + scrolledX) / 2 - (Xwidth / 2);
    //var topoffset = scrolledY + (centerY - Yheight) / 2;
    var topoffset = scrolledY + ((centerY) / 2 - (Yheight / 2));
    // the initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 

    var o = divid;
    var r;

    if (o.style) {
        r = o.style;
    }
    else {
        r = document.getElementById(o).style;
    }

    r.position = 'absolute';
    if (divid.id == 'dvBlockedSlotsSch') {
        r.top = '0px';
    }
    else {
        r.top = topoffset + 'px';
    }
    r.left = leftoffset + 'px';
}

function getBrowserHeight() {
    var intH = 0;
    var intW = 0;

    if (typeof window.innerWidth == 'number') {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        intH = document.documentElement.clientHeight;
        intW = document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }

    return { width: parseInt(intW), height: parseInt(intH) };
}

//***************************************************
// To make display on Screen Center Ends
//***************************************************

function CheckAngularBrackets(obj) {
    var arguments = getObjSW(obj);

    var Str = new String(arguments.Value);
    var mikExp = /[\<\>]/;
    if (Str.search(mikExp) != -1)
        return false; // invalid string 
    else
        return true; // valid string  
}


function checkValUserName(obj) {
    var mikExp = /[\`\~\!\@\#\$\%\^\&\*\(\)\+\=\|\\\{\}\[\]\:\;\"\'\<\>\,\/\?\' ']/;
    if (mikExp.test(getObjSW(obj).value)) {
        return false;
    }
    return true;
}

function validateAlphaNumeric(source, arguments) {
    var str;
    var str = new String(arguments.Value);

    var objRegExp = /^[a-zA-Z0-9\s]+$/;
    var flag = str.match(objRegExp);

    if (flag == null) {
        arguments.IsValid = false;
        return; // invalid string
    }
    else {
        arguments.IsValid = true;
        return; // valid string
    }
}

function CheckSpaceInUserName(obj) {

    if (getObjSW(obj).value.indexOf(' ') == -1)
        return true;
    else
        return false;

}



function doBeforePaste(control) {
    var maxLength = control.getAttribute("MLength");
    if (maxLength) {
        event.returnValue = false;
    }
}
function doPaste(control) {
    var maxLength = control.getAttribute("MLength");
    value = control.value;
    if (maxLength) {
        event.returnValue = false;
        maxLength = parseInt(maxLength);
        var oTR = control.document.selection.createRange();
        var iInsertLength = maxLength - value.length + oTR.text.length;
        var sData = window.clipboardData.getData("Text").substr(0, iInsertLength);
        oTR.text = sData;
    }
}
function LimitInput(control) {
    if (control.value.length >= control.getAttribute("MLength")) {
        control.value = control.value.substring(0, control.getAttribute("MLength"));
    }
}


var first = 'fst';
var RatingPoint = '';
function getObjSW(objID, sParameter) {

    var sParam = 'cphContent';
    if (sParameter != null)
        sParam = sParameter;

    if (document.getElementById) {
        if (document.getElementById(objID) == null) {

            if (document.getElementById("ctl00" + "_" + sParam + "_" + objID) == null) {
                if (document.getElementById("ctl00" + "_" + sParam + "_" + "ctrlAddDriver_" + objID) != null)
                    objID = "ctl00" + "_" + sParam + "_" + "ctrlAddDriver_" + objID;
                else if (document.getElementById("ctl00" + "_" + sParam + "_" + "ctrlAddOnLiftTicket_" + objID) != null)
                    objID = "ctl00" + "_" + sParam + "_" + "ctrlAddOnLiftTicket_" + objID;
                else if (document.getElementById("ctl00" + "_" + "usrctrlBookingHeader_" + objID) != null)
                    objID = "ctl00" + "_" + "usrctrlBookingHeader_" + objID;
            }
            else
                objID = "ctl00" + "_" + sParam + "_" + objID;

            // objID="ctl00"+"_"+sParam+"_"+objID; 
        }
        if (document.getElementById(objID) == null) {
            objID = objID.replace("ctrlAddDriver_", "ctl00_usrctrlBookingHeader_");
            objID = objID.replace("cphContent_", "usrctrlBookingHeader_");

            //	     ctl00_usrctrlBookingHeader_txtReturningDate
        }
        return document.getElementById(objID)
    }
    else if (document.all) {
        if (document.all(objID) == null) {
            objID = "ctl00_" + sParam + "_" + objID;
        }

        if (document.getElementById(objID) == null) {
            objID = objID.replace(/cphContent/, "usrctrlBookingHeader");
        }

        return document.all[objID];
    }
    else if (document.layers) {
        if (document.layers(objID) == null) {
            objID = "ctl00_" + sParam + "_" + objID;
        }

        if (document.getElementById(objID) == null) {
            objID = objID.replace(/cphContent/, "usrctrlBookingHeader");
        }

        return document.layers[objID];
    }
}


function AlertMessage(status)  // status = 1 then activate, 2- deactivate , 3 - suspend 4 - delete
{
    if (status == 1) {
        return confirm("Are you sure you want to activate this account?");
    }
    else if (status == 2) {

        return confirm("Are you sure you want to deactivate this account?");
    }
}

//For checking Re-Enter Password.
function RequiredConfirmPassword(sender, args) {
    inputStr1 = document.getElementById("ctl00_cphContent_txtPassword").value;
    inputStr2 = document.getElementById("ctl00_cphContent_txtConfirmPassword").value;

    if (inputStr1.length > 0) {
        if (inputStr2.length < 1) {
            args.IsValid = false;
            return;
        }
    }
    args.IsValid = true;
    return;
}

//For Enter Button in multiple line textbox
function enterSubmit() {

    DisableSubmitButtonID = eval("document.getElementById('ctl00_DisableSubmitButtonID').value");

    if (DisableSubmitButtonID != '0') {
        var SubmitButtonIDid = eval("document.getElementById('ctl00_SubmitButtonID').value");
        if (SubmitButtonIDid == '')
            return;
        else if (SubmitButtonIDid.indexOf(',') != -1) {
            var obtnId = new Array();
            obtnId = SubmitButtonIDid.split(',');
            for (i = 0; i < obtnId.length; i++) {
                if (document.getElementById(obtnId[i])) {
                    if (getObj('trAccessRights')) {
                        if (getObj('trAccessRights').style.visibility == "hidden") {
                            getObj('btnSave').focus();
                            getObj('btnSave').click();
                        }
                        else {
                            getObj('btnSaveAccess').focus();
                            getObj('btnSave').click();
                        }
                        return;
                    }
                    else {
                        document.getElementById(obtnId[i]).focus();
                    }
                }
            }
        }
        else
            document.getElementById(SubmitButtonIDid).focus();
    }
}

function disableSubmit() {


    document.getElementById('ctl00_DisableSubmitButtonID').value = "0";
}

function enableSubmit() {


    document.getElementById('ctl00_DisableSubmitButtonID').value = "1";
}


function checkBlank(obj) {
    if (obj.value == '')
        document.getElementById(obj.id).value = '0.00';
}

function CompareDate(sender, args) {
    if (document.getElementById('txtDateFrom') == null) {
        inputStr1 = new Date(document.getElementById('ctl00_cphContent_txtDateFrom').value);
        inputStr2 = new Date(document.getElementById('ctl00_cphContent_txtDateTo').value);
    }
    else {
        inputStr1 = new Date(document.getElementById('txtDateFrom').value);
        inputStr2 = new Date(document.getElementById('txtDateTo').value);
    }

    if (inputStr1 != "") {
        if (inputStr2 != "") {
            if (inputStr1 > inputStr2) {
                args.IsValid = false;
                return;
            }
        }
    }
    args.IsValid = true;
    return;
}

function validateBackDate(source, arguments)//Function For checking if entered date is less then current date
{
    currdate = new Date()
    userdate = new Date(arguments.Value)

    currdate.setDate(currdate.getDate())

    year = currdate.getFullYear();
    month = currdate.getMonth();
    day = currdate.getDate();

    onlydatenotime = new Date(year, month, day);


    if (userdate < onlydatenotime) {
        arguments.IsValid = false;
        return;
    }
    else {
        arguments.IsValid = true;
        return;
    }
}

function ValidateContentText(source, args) {
    var fckBody = FCKeditorAPI.GetInstance('ctl00_cphContent_txtMessage');

    if (fckBody.GetXHTML() == "" || fckBody.GetXHTML() == "<br />") {
        args.IsValid = false;
        return;
    }
    else {
        args.IsValid = true;
        return;
    }
}

//Function for Redirecting the page to specified loacation within some time specified.

function SplashScreenSeconds(url, msg) {
    var TARG_ID = "spanSplashScreenSeconds"; //Span declared in html form
    var DEF_MSG = "Redirecting...";
    if (!msg) {
        msg = DEF_MSG;
    }
    if (!url) {
        throw new Error('You didn\'t include the "url" parameter');
    }
    var e = document.getElementById(TARG_ID);

    if (!e) {
        throw new Error('"spanSplashScreenSeconds" element id not found');
    }

    var cTicks = parseInt(e.innerHTML);
    var timer = setInterval(function() {
        if (cTicks) {
            e.innerHTML = --cTicks;
        }
        else {
            clearInterval(timer);
            //document.body.innerHTML = msg;
            location = url;
        }

    }, 1000);
}

var color;
function changeRowStyle(gridID, rowID) {
    color = document.getElementById("ctl00_cphContent_" + gridID + "_Row" + rowID).style.backgroundColor;
    document.getElementById("ctl00_cphContent_" + gridID + "_Row" + rowID).style.backgroundColor = '#62b997';
}

function changeBackRowStyle(gridID, rowID) {
    document.getElementById("ctl00_cphContent_" + gridID + "_Row" + rowID).style.backgroundColor = color;
}





// JScript File
//function to check whether user has entered phone number in primry phone or not
function txtPrimaryPhone() {
    inputStr1 = document.getElementById("ctl00_cphContent_txtPhone1").value;
    inputStr2 = document.getElementById("ctl00_cphContent_txtPhone2").value;
    inputStr3 = document.getElementById("ctl00_cphContent_txtPhone3").value;

    if (inputStr1.length != 0 || inputStr2.length != 0 || inputStr3.length != 0) {
        if (inputStr1.length != 3 || inputStr2.length != 3 || inputStr3.length != 4) {
            //					args.IsValid=false;
            return false;
        }
    }

    //			args.IsValid=true;
    return true;
}


//To stop right click behaviour in textbox
var diablepastemessage = "";

function rightClickDisable() {
    if (this.layers) {
        this.captureEvents(Event.MOUSEDOWN);
        this.onmousedown = clickNS;

    }
    else {
        this.onmouseup = clickNS;
        this.oncontextmenu = clickIE;

    }

    this.oncontextmenu = new Function("return false");

}
function clickIE() {
    if (this.all) {
        (diablepastemessage);
        return false;
    }
}

function clickNS(e) {
    if (this.layers || (this.getElementById && !this.all)) {
        if (e.which == 2 || e.which == 3) {
            (diablepastemessage);
            return false;
        }
    }
}

//To enable right click, after blur out from textbox
function rightClickEnable() {
    if (this.layers) {
        this.captureEvents(Event.MOUSEDOWN);
        this.onmousedown = true;
    }
    else {
        this.onmouseup = true;
        this.oncontextmenu = true;
    }

    this.oncontextmenu = new Function("return true");
}

function checkCtrlPaste(e) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;

    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }

    if (key == 118 && isCtrl)
        return false;
    else
        return true;
    //if (isNaN(key)) return true;

}


//To stop paste behaviour on textbox (ctrl + v)
function fncKeyStop(e) {

    // Check if the control key is pressed.
    // If the Netscape way won't work (event.modifiers is undefined),
    // try the IE way (event.ctrlKey)

    var ctrl = typeof e.modifiers == 'undefined' ?
    e.ctrlKey : e.modifiers & Event.CONTROL_MASK;

    // Check if the 'V' key is pressed.
    // If the Netscape way won't work (event.which is undefined),
    // try the IE way (event.keyCode)

    var v = typeof e.which == 'undefined' ?
    e.keyCode == 86 : e.which == 86;
    // If the control and 'V' keys are pressed at the same time
    if (ctrl && v) {
        // ... discard the keystroke and clear the text box
        document.getElementById('ctl00_cphContent_txtConfirmPassword').value = '';
        return false;
    }

    return true;
}


function extractNumber(obj, decimalPlaces, allowNegative) {
    var temp = obj.value;

    // avoid changing things if already formatted correctly
    var reg0Str = '[0-9]*';
    if (decimalPlaces > 0) {
        reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
    } else if (decimalPlaces < 0) {
        reg0Str += '\\.?[0-9]*';
    }
    reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
    reg0Str = reg0Str + '$';
    var reg0 = new RegExp(reg0Str);
    if (reg0.test(temp)) return true;

    // first replace all non numbers
    var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
    var reg1 = new RegExp(reg1Str, 'g');
    temp = temp.replace(reg1, '');

    if (allowNegative) {
        // replace extra negative
        var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
        var reg2 = /-/g;
        temp = temp.replace(reg2, '');
        if (hasNegative) temp = '-' + temp;
    }

    if (decimalPlaces != 0) {
        var reg3 = /\./g;
        var reg3Array = reg3.exec(temp);
        if (reg3Array != null) {
            // keep only first occurrence of .
            //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
            var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
            reg3Right = reg3Right.replace(reg3, '');
            reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
            temp = temp.substring(0, reg3Array.index) + '.' + reg3Right;
        }
    }

    obj.value = temp;
}

function extractNumberFixlength(obj, decimalPlaces, allowNegative, noOfDigit) {
    var temp = obj.value;
    var positiveNo = 0;
    if (obj.value.indexOf(".") > -1)
        positiveNo = obj.value.substring(0, obj.value.indexOf("."));
    else
        positiveNo = obj.value
    if (positiveNo.length > noOfDigit)
        positiveNo = positiveNo.substr(0, noOfDigit);
    var negativeNo = "";
    if (obj.value.indexOf(".") > -1) {
        if (obj.value.substr(obj.value.indexOf(".") + 1, obj.value.length - obj.value.indexOf(".")) != "")
            negativeNo = obj.value.substr(obj.value.indexOf(".") + 1, obj.value.length - obj.value.indexOf("."));
        if (negativeNo != "" || negativeNo == 0)
            temp = positiveNo + '.' + negativeNo;
        else
            temp = positiveNo + '.'
    }
    else
        temp = positiveNo;
    obj.value = temp;
    // avoid changing things if already formatted correctly
    var reg0Str = '[0-9]*';
    if (decimalPlaces > 0) {
        reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
    } else if (decimalPlaces < 0) {
        reg0Str += '\\.?[0-9]*';
    }
    reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
    reg0Str = reg0Str + '$';
    var reg0 = new RegExp(reg0Str);
    if (reg0.test(temp)) return true;

    // first replace all non numbers
    var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
    var reg1 = new RegExp(reg1Str, 'g');
    temp = temp.replace(reg1, '');

    if (allowNegative) {
        // replace extra negative
        var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
        var reg2 = /-/g;
        temp = temp.replace(reg2, '');
        if (hasNegative) temp = '-' + temp;
    }

    if (decimalPlaces != 0) {
        var reg3 = /\./g;
        var reg3Array = reg3.exec(temp);
        if (reg3Array != null) {
            // keep only first occurrence of .
            //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
            var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
            reg3Right = reg3Right.replace(reg3, '');
            reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
            temp = temp.substring(0, reg3Array.index) + '.' + reg3Right;
        }
    }

    obj.value = temp;
}

function blockNonNumbers(obj, e, allowDecimal, allowNegative) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;

    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }

    if (isNaN(key)) return true;

    keychar = String.fromCharCode(key);

    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl) {
        return true;
    }

    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

    return isFirstN || isFirstD || reg.test(keychar);
}

function blockNonNumbersSearch(obj, e, allowDecimal, allowNegative) {
    var key;
    var isCtrl = false;
    var keychar;
    var reg;
    //	document.getElementById("ctl00_ctrlHeader_txtFromDate").value="";
    //    document.getElementById("ctl00_ctrlHeader_txtToDate").value="";	
    if (window.event) {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if (e.which) {
        key = e.which;
        isCtrl = e.ctrlKey;
    }

    if (isNaN(key)) return true;

    keychar = String.fromCharCode(key);

    // check for backspace or delete, or if Ctrl was pressed
    if (key == 8 || isCtrl) {
        return true;
    }

    reg = /\d/;
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;

    return isFirstN || isFirstD || reg.test(keychar);
}


function blockSpace(ctrl, e) {
    var isIE = document.all ? true : false;
    var isNS = document.layers ? true : false;
    var key = (isIE) ? window.event.keyCode : e.which;
    var position = ctrl.value.charAt(0);

    if (key == 32 && ctrl.value.length == 0 && position == '') {
        return false;
    }

    else {

        return true;
    }
}

function blockSpecialCharacter(ctrl, e) {
    var isIE = document.all ? true : false;
    var isNS = document.layers ? true : false;
    var key = (isIE) ? window.event.keyCode : e.which; s

    var isNum = ((key > 47 && key < 58) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key == 45 || key == 46 || key == 95) ? true : false;
    if (key < 32)
        return true;
    return (isNum);
}


//Generating Pop-up Print Preview page
function getPrint(print_area) {
    //Creating new page
    var pp = window.open();
    //Adding HTML opening tag with <HEAD> … </HEAD> portion 
    pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
    pp.document.writeln('<LINK href=App_Themes/Style/StyleSheet.css  type="text/css" rel="stylesheet">')
    //pp.document.writeln('<LINK href=App_Themes/Style/PrintStyle.css  type="text/css" rel="stylesheet" media="print"><base target="_self">')
    pp.document.writeln('</HEAD>')
    //Adding Body Tag
    pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" >');
    //Adding form Tag
    pp.document.writeln('<form  method="post">');
    //Creating two buttons Print and Close within a table
    //pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
    //Writing print area of the calling page
    //pp.document.writeln('<center>');

    //pp.document.writeln(document.getElementById(print_area).innerHTML);
    str = new String(document.getElementById(print_area).innerHTML);
    str = str.replace(/class=ContentDivStory/i, "class=PrintContentDivStory");
    str = str.replace(/class=ContentDiv/i, "class=PrintContentDiv");
    str = str.replace(/<HR>/i, "");
    str = str.replace(/align=center/i, "");


    pp.document.writeln(str);
    //pp.document.body.replaceAdjacentText('<DIV class=ContentDivStory style="WIDTH: 100%">','<DIV  style="WIDTH: 100%">');
    //pp.document.writeln('</center>');
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</form></body></HTML>');
    pp.onload = window.print();

}
function autoTab(input, len, e) {
    var keyCode = (isNN) ? e.which : e.keyCode;
    var filter = (isNN) ? [0, 8, 9] : [0, 8, 9, 16, 17, 18, 37, 38, 39, 40, 46];
    if (input.value.length >= len && !containsElement(filter, keyCode)) {
        input.value = input.value.slice(0, len);
        input.form[(getIndex(input) + 1) % input.form.length].focus();
    }
}



var BOX_TITLE = "Perimeter Bus Reservations";
var oBoxalert = false;

if (document.getElementById) {

    window.alert = function(txt) {
        createCustomBox(txt, 1);
    }

}
function createCustomBox(txt, objNo) {
    d = document;

    if (d.getElementById("BoxDiv")) return;
    mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
    mObj.id = "BoxDiv";
    mObj.style.height = d.documentElement.scrollHeight + "px";

    BoxObj = mObj.appendChild(d.createElement("div"));
    BoxObj.id = "Box";
    BoxObj.style.top = document.documentElement.scrollTop + 80 + "px";
    BoxObj.style.left = (((d.documentElement.scrollWidth - BoxObj.offsetWidth) / 2) - 150) + "px";

    //BoxObj.style.left = '500px';
    BoxObj.style.visiblity = "visible";

    h1 = BoxObj.appendChild(d.createElement("h1"));
    h1.appendChild(d.createTextNode(BOX_TITLE));
    h2 = BoxObj.appendChild(d.createElement("h2"));
    msg = BoxObj.appendChild(d.createElement("p"));
    msg.appendChild(d.createTextNode(txt));


    TblObj = document.createElement("table");
    TblBody = document.createElement("tbody");
    TR1 = document.createElement("tr");
    TD1 = document.createElement("td");
    TD2 = document.createElement("td");

    BoxObj.appendChild(TblObj)
    TblObj.appendChild(TblBody)
    TblBody.appendChild(TR1)
    TR1.appendChild(TD1)

    TblObj.id = "tblBox";

    btn1 = TD1.appendChild(d.createElement("img"));
    btn1.id = "OkBtn";
    btn1.src = RelativePath() + "images/btn-ok.jpg";


    btn1.onmouseover = function() { this.src = RelativePath() + "images/btn-ok-o.jpg"; }
    btn1.onmouseout = function() { this.src = RelativePath() + "images/btn-ok.jpg"; }

    if (objNo == 2) {
        TR1.appendChild(TD2)
        TD2.style.paddingLeft = "3px";

        btn2 = TD2.appendChild(d.createElement("img"));
        btn2.id = "CancelBtn";
        btn2.src = "images/buttons/btn-cancel.jpg";

        btn1.onclick = function() { removeCustomAlert(); oBoxalert = true; }
        btn2.onmouseover = function() { this.src = "images/buttons/btn-cancel-o.jpg"; }
        btn2.onmouseout = function() { this.src = "images/buttons/btn-cancel.jpg"; }
        btn2.onclick = function() { removeCustomAlert(); return false; }

    }
    else {
        btn1.onclick = function() { removeCustomAlert(); return false; }
    }

    h3 = BoxObj.appendChild(d.createElement("h3"));
    BoxObj.style.display = "block";

    try {
        var oSelect = document.all.tags("SELECT");
        if (oSelect != null) {
            //for (i=0; i<oSelect.length; i++) 
            //			oSelect[i].style.visibility = "hidden";
        }
    }
    catch (Error) { }

    btn1.focus();
    //if(!oBoxalert) {oBoxalert = false; return false;}
}
function removeCustomAlert() {
    try {
        var oSelect = document.all.tags("SELECT");
        if (oSelect != null) {
            for (i = 0; i < oSelect.length; i++)
                oSelect[i].style.visibility = "visible";
        }
    }
    catch (Error) { }
    document.getElementsByTagName("body")[0].removeChild(document.getElementById("BoxDiv"));
}

//Generating Pop-up Print Preview page
function getPrint(print_area) {
    //Creating new page
    var pp = window.open();
    //Adding HTML opening tag with <HEAD> … </HEAD> portion 
    pp.document.writeln('<HTML><HEAD><title>Print Preview</title>')
    pp.document.writeln('<link href="App_Themes/Style/StyleSheet.css" type="text/css" rel="stylesheet" />')
    pp.document.writeln('<link href="App_Themes/Style/booking_pageTicket.css" type="text/css" rel="stylesheet" />')
    //pp.document.writeln('<LINK href=App_Themes/Style/PrintStyle.css  type="text/css" rel="stylesheet" media="print"><base target="_self">')
    pp.document.writeln('</HEAD>')
    //Adding Body Tag
    pp.document.writeln('<body MS_POSITIONING="GridLayout" bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0" >');
    //Adding form Tag
    pp.document.writeln('<form  method="post">');
    //Creating two buttons Print and Close within a table
    //pp.document.writeln('<TABLE width=100%><TR><TD></TD></TR><TR><TD align=right><INPUT ID="PRINT" type="button" value="Print" onclick="javascript:location.reload(true);window.print();"><INPUT ID="CLOSE" type="button" value="Close" onclick="window.close();"></TD></TR><TR><TD></TD></TR></TABLE>');
    //Writing print area of the calling page
    //pp.document.writeln('<center>');

    //pp.document.writeln(document.getElementById(print_area).innerHTML);
    str = new String(document.getElementById(print_area).innerHTML);

    pp.document.writeln(str);
    //pp.document.body.replaceAdjacentText('<DIV class=ContentDivStory style="WIDTH: 100%">','<DIV  style="WIDTH: 100%">');
    //pp.document.writeln('</center>');
    //Ending Tag of </form>, </body> and </HTML>
    pp.document.writeln('</form></body></HTML>');
    pp.onload = window.print();


}

function handleVisibility(elementid)//to handle visibility of controls which need not to show on live or test site
{
    var url = self.location.href;
    url = url.toLowerCase();

    // determine the server   
    var local = '/localhost/';
    var live = 'perimeter-com.sitepreview.ca/';
    var Testlive = 'perimeter-com.sitepreview.ca/'

    if (getObjSW(elementid) != null) {
        if (url.lastIndexOf(live) == -1) {
            if (elementid.indexOf('trPromoCode') > -1) {
                // getObjSW(elementid).style.display="";
            }
            else {
                getObjSW(elementid).style.display = "inline";
            }
        }
        else {
            getObjSW(elementid).style.display = "none"
        }
    }

}


function showcenterdiv(Xwidth, Yheight, divid) {

    // First, determine how much the visitor has scrolled 
    //alert(divid.id)
    var scrolledX, scrolledY;


    if (self.pageYoffset) {
        scrolledX = self.pageXoffset;
        scrolledY = self.pageYoffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window 
    var bws = getBrowserHeight();

    var centerX, centerY;
    centerX = bws.width;
    centerY = bws.height;
    //alert(centerY+','+scrolledY)
    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    //var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
    var leftoffset = (centerX + scrolledX) / 2 - (Xwidth / 2);
    //var topoffset = scrolledY + (centerY - Yheight) / 2;
    var topoffset = scrolledY + ((centerY) / 2 - (Yheight / 2));
    // the initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 

    var o = divid;
    var r;

    if (o.style) {
        r = o.style;
    }
    else {
        r = document.getElementById(o).style;
    }

    r.position = 'absolute';
    if (divid.id == 'dvBlockedSlotsSch') {
        r.top = '0px';
    }
    else {
        r.top = topoffset + 'px';
    }
    r.left = leftoffset + 'px';
    //if (window.navigator.userAgent.indexOf("Firefox") <= -1)
    //    r.top = (centerY  )+ 'px'; 
    //setLayerPosition(divid);
}


function getBrowserHeight() {
    var intH = 0;
    var intW = 0;

    if (typeof window.innerWidth == 'number') {
        intH = window.innerHeight;
        intW = window.innerWidth;
    }
    else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        intH = document.documentElement.clientHeight;
        intW = document.documentElement.clientWidth;
    }
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        intH = document.body.clientHeight;
        intW = document.body.clientWidth;
    }

    return { width: parseInt(intW), height: parseInt(intH) };
}
function checkTelephoneFormat(ctrl) {
    var str = ctrl.split(',');
    obj1 = str[0];
    obj2 = str[1];
    obj3 = str[2];
    obj4 = str[3];
    if (getObjSW(obj1).value != "" || getObjSW(obj2).value != "" || getObjSW(obj3).value != "" || getObjSW(obj4).value != "") {
        if (getObjSW(obj1).value.length < 3 || getObjSW(obj2).value.length < 3)
            return false;
        if (getObjSW(obj3).value.length < 4)
            return false;
        return true;
    }
    else
        return true;
}
function trim(str) {
    return str.replace(/^[\s]+/, '').replace(/[\s]+$/, '').replace(/[\s]{2,}/, ' ');
}
function changeTab(e, len, obj1, obj2) {
    var KeyID = (window.event) ? event.keyCode : e.which;

    if (KeyID == 8 || KeyID == 46 || KeyID == 9 || (KeyID >= 37 && KeyID <= 40))
        return true;
    if (getObjSW(obj1).value.length == len) {
        if (getObjSW(obj2) != null)
            getObjSW(obj2).focus();
    }
}
function checkTelephoneNumber(objCtrl) {

    var varLength = objCtrl.split(',');
    if (getObjSW(varLength[0]).value.length < varLength[1])
        return false;
    else
        return true;
}
function CheckConfirmEmail(firstTextBox, secondTextBox) {
    if (trim(getObjSW('txtEmailAddress1').value) == "")
        result = false;
    else if (getObjSW('txtEmailAdress').value.toLowerCase() != getObjSW('txtEmailAddress1').value.toLowerCase())
        return false;

    return true;
}
function ClearDateControl(ctrl) {
    getObjSW(ctrl).value = "";
} function GetDate(ddlMonthId, ddlDayId, ddlYearId) {
    var elmyear = document.getElementById(ddlYearId);
    var elmdays = document.getElementById(ddlDayId);
    var elmmonth = document.getElementById(ddlMonthId);
    var date = document.getElementById("ctl00_cphContent_txtBirthdayDate");
    if (elmmonth.value != "-1" && elmdays.value != "0" && elmyear.value != "-1") {
        date.value = elmmonth.value + "/" + elmdays.value + "/" + elmyear.value;
    }
    else {
        date.value = "";
    }
}

function SetDay(ddlMonthId, ddlDayId, ddlYearId) {
    var elmyear = document.getElementById(ddlYearId);
    var elmdays = document.getElementById(ddlDayId);
    var elmmonth = document.getElementById(ddlMonthId);
    if (elmyear !== null && elmdays !== null && elmmonth !== null) {
        var year = 0;
        year = elmyear.value;
        if (elmmonth.selectedindex != -1) {
            var days = GetDaysInMonth(elmmonth.value, year);
            var selectedvalue = "";
            if (elmdays.value != "") {
                selectedvalue = elmdays.value;
            }
            PopulateDays(elmdays, days);
            if (selectedvalue != "") {
                if (selectedvalue != "-1") {
                    elmdays.value = selectedvalue;
                }
            }
            if (elmdays.value == "") {
                elmdays.value = days;
            }
        }
    }
    GetDate(ddlMonthId, ddlDayId, ddlYearId);
}
function PopulateDays(elmdays, days) {
    elmdays.length = 0;
    elmdays.options[0] = new Option("Day", 0, false, true);
    for (var i = 1; i <= days; i++) {
        elmdays.options[i] = new Option(i, i, false, false);
    }
}
function GetDaysInMonth(month, year) {
    var days = 0;
    if (month == "-1") {
        return 31;
    }
    if (month == 1) { days = 31; }
    else if (month == "2") {
        if (year % 4 === 0) { days = 29; }
        else { days = 28; }
    }
    else if (month == "3") { days = 31; }
    else if (month == "4") { days = 30; }
    else if (month == "5") { days = 31; }
    else if (month == "6") { days = 30; }
    else if (month == "7") { days = 31; }
    else if (month == "8") { days = 31; }
    else if (month == "9") { days = 30; }
    else if (month == "10") { days = 31; }
    else if (month == "11") { days = 30; }
    else if (month == "12") { days = 31; }
    return days;
}
