var skinPath = '';

var ns4 = (document.layers) ? true : false;
var ie5 = (w3c && document.all) ? true : false;
var ns6 = (w3c && !document.all) ? true : false;
var w3c = (document.getElementById) ? true : false;
var mousePos = null;

function mouseMove(ev) {
    ev = ev || window.event;
    mousePos = mouseCoords(ev);
    if (document.getElementById('ProcessingDiv')) {
        var adiv = document.getElementById('ProcessingDiv');
        adiv.style.top = mousePos.y;
        adiv.style.left = mousePos.x - 32;
    }
    trackmouse(ev);
}
function mouseCoords(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft :
		                                                        document.body.scrollLeft),
        y: ev.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop :
                                                                document.body.scrollTop)
    };
}

WindowSizeParams =
    function() {
        this.x = 0;
        this.y = 0;
    };

function WindowSize() {
    var winSize = new WindowSizeParams();
    if (parseInt(navigator.appVersion) > 3) {
        if (navigator.appName == "Netscape") {
            winSize.x = window.innerWidth;
            winSize.y = window.innerHeight;
            return winSize;
        }
        if (navigator.appName.indexOf("Microsoft") != -1)
            winSize.x = document.body.offsetWidth;
        winSize.y = document.body.offsetHeight;
        return winSize;
    }
}

function trackmouse(evt) {
    mx = (ie5) ? event.clientX + d.body.scrollLeft : evt.pageX;
    my = (ie5) ? event.clientY + d.body.scrollTop : evt.pageY;
    if (!ns6)
        movepopup();
    if ((currIDb != null) || (currRS != null))
        return false;
}

var offset = (navigator.userAgent.indexOf("Mac") != -1 ||
                  navigator.userAgent.indexOf("Gecko") != -1 ||
                  navigator.appName.indexOf("Netscape") != -1) ? 0 : 4;
window.moveTo(-offset, -offset);
window.resizeTo(screen.availWidth + (2 * offset), screen.availHeight + (2 * offset));

var win = WindowSize();
mousePos = { x: win.x / 2, y: win.y / 2 };

document.onmousemove = mouseMove;

//popup members & functions

var w3c = (document.getElementById) ? true : false;
var ns4 = (document.layers) ? true : false;
var ie5 = (w3c && document.all) ? true : false;
var ns6 = (w3c && !document.all) ? true : false;
var d = document;
currIDb = null; xoff = 0; yoff = 0;
currRS = null; rsxoff = 0; rsyoff = 0;
oldac = null; newac = null; zdx = 999; mx = 0; my = 0;
var currFb = null; var currFs = null; var currFID = 0; var currFcnt = 0;
var cidlist = new Array();
//images
var minImg = skinPath + 'min.gif';
var maxImg = skinPath + 'max.gif';
var clsImg = skinPath + 'close.gif';
var rsImg = skinPath + 'resize.gif';
var errorImg = skinPath + 'error.png';
var succImg = skinPath + 'success.png';

//******* START OF EXPOSED FUNCTIONS. THESE CAN BE USED IN HYPERLINKS. *******\\

function InitImages() {
    minImg = skinPath + 'min.gif';
    maxImg = skinPath + 'max.gif';
    clsImg = skinPath + 'close.gif';
    rsImg = skinPath + 'resize.gif';
    errorImg = skinPath + 'error.png';
    succImg = skinPath + 'success.png';
}

function hidebox(id, btnClose) {
    if (w3c) {
        if (btnClose == 'NOACTION')
            return false;
        d.getElementById(id + '_b').style.display = 'none';
        d.getElementById(id + '_s').style.display = 'none';
        for (var i = 0; i < cidlist.length; i++)
            if (cidlist[i].split(';')[0] == id) {
            cidlist.splice(i, 1);
            break;
        }

        if (btnClose != "null" && btnClose != "undefined" && btnClose)
            if (document.getElementById(btnClose).dispatchEvent) {
            var e = document.createEvent("MouseEvents");
            e.initEvent("click", true, true);
            document.getElementById(btnClose).dispatchEvent(e);
        }
        else
            document.getElementById(btnClose).click();
    }
}

function movePopup(idElem, x, y) {
    if (w3c) {
        var idb = document.getElementById(idElem + '_b');
        var ids = document.getElementById(idElem + '_s');
        idb.style.left = x + 'px';
        ids.style.left = x + 8 + 'px';
        idb.style.top = y + 'px';
        ids.style.top = y + 8 + 'px';
        for (var i = 0; i < cidlist.length; i++)
            if (cidlist[i].split(';')[0] == idElem)
            cidlist[i] = cidlist[i].split(';')[0] + ';' + x + ';' + y;
    }
}

function resizePopup(ids, rx, ry) {
    if (w3c) {
        if (d.getElementById(ids + '_rs').rsEnable) {
            d.gEl = d.getElementById;
            d.gEl(ids + "_extWA").style.display = "block";
            d.gEl(ids + "_rs").style.left = Math.max(rx, ((ie5) ? 88 : 92)) + 'px';
            d.gEl(ids + "_rs").style.top = Math.max(ry, ((ie5) ? 68 : 72)) + 'px';
            d.gEl(ids + "_b").style.width = Math.max(rx + ((ie5) ? 12 : 8), 100) + 'px';
            d.gEl(ids + "_b").style.height = Math.max(ry + ((ie5) ? 12 : 8), 80) + 'px';
            d.gEl(ids + "_t").style.width = Math.max(rx + ((ie5) ? 4 : 3), ((ns6) ? 95 : 92)) + 'px';
            d.gEl(ids + "_btt").style.left = parseInt(d.gEl(ids + "_t").style.width) - 48 + 'px';
            d.gEl(ids + "_s").style.width = Math.max(rx + 12, ((ie5) ? 100 : 104)) + 'px';
            d.gEl(ids + "_s").style.height = Math.max(ry + ((ie5) ? 12 : 13), ((ie5) ? 80 : 86)) + 'px';
            d.gEl(ids + "_c").style.width = Math.max(rx - ((ie5) ? -5 : 5), ((ie5) ? 92 : 87)) + 'px';
            d.gEl(ids + "_c").style.height = Math.max(ry - ((ie5) ? 24 : 28), 44) + 'px';
            d.gEl(ids + "_max").h = parseInt(d.gEl(ids + "_b").style.height);
        }
    }
}

//******* END OF EXPOSED FUNCTIONS *******\\

function minimize() {
    if (w3c) {
        d.getElementById(this.cid + "_b").style.height = (ie5) ? '28px' : '24px';
        d.getElementById(this.cid + "_s").style.height = '28px';
        d.getElementById(this.cid + "_c").style.display = 'none';
        d.getElementById(this.cid + "_rs").style.display = 'none';
        ns6bugfix();
    }
}

function restore() {
    if (w3c) {
        d.getElementById(this.cid + "_b").style.height = this.h + 'px';
        d.getElementById(this.cid + "_s").style.height = (ie5) ? this.h + 'px' : this.h + 5 + 'px';
        d.getElementById(this.cid + "_c").style.display = 'block';
        d.getElementById(this.cid + "_rs").style.display = 'block';
        ns6bugfix();
    }
}

function ns6bugfix() {
    if (navigator.userAgent.indexOf("Netscape/6") > 0)
        setTimeout('self.resizeBy(0, 1); self.resizeBy(0, -1);', 100);
}

function movepopup() {
    if ((currIDb != null) && w3c)
        movePopup(currIDb.cid, mx + xoff, my + yoff);
    if ((currRS != null) && w3c)
        resizePopup(currRS.cid, mx + rsxoff, my + rsyoff);
    return false;
}

function stopRS() {
    d.getElementById(this.cid + "_extWA").style.display = "none";
    currRS = null;
}

function startRS(evt) {
    var ex = (ie5) ? event.clientX + d.body.scrollLeft : evt.pageX;
    var ey = (ie5) ? event.clientY + d.body.scrollTop : evt.pageY;
    rsxoff = parseInt(this.style.left) - ex;
    rsyoff = parseInt(this.style.top) - ey;
    currRS = this;
    if (ns6)
        d.getElementById(this.cid + "_c").style.overflow = 'hidden';
    return false;
}

function changez(v) {
    var th = (v != null) ? v : this;
    if ((oldac != null) && (oldac != th)) {
        if (d.getElementById(oldac.cid + "_t"))
            d.getElementById(oldac.cid + "_t").style.backgroundColor = oldac.inactivecolor;
        oldac = th;
    }
    if (ns6)
        d.getElementById(th.cid + "_c").style.overflow = 'auto';
    d.getElementById(th.cid + "_t").style.backgroundColor = th.activecolor;
    d.getElementById(th.cid + "_s").style.zIndex = ++zdx;
    d.getElementById(th.cid + "_b").style.zIndex = ++zdx;
    if (d.getElementById(th.cid + "_rs"))
        d.getElementById(th.cid + "_rs").style.zIndex = ++zdx;
}

function stopdrag() {
    currIDb = null;
    document.getElementById(this.cid + "_extWA").style.display = "none";
    ns6bugfix();
}

function grab_id(evt) {
    var ex = (ie5) ? event.clientX + d.body.scrollLeft : evt.pageX;
    var ey = (ie5) ? event.clientY + d.body.scrollTop : evt.pageY;
    xoff = parseInt(d.getElementById(this.cid + "_b").style.left) - ex;
    yoff = parseInt(d.getElementById(this.cid + "_b").style.top) - ey;
    currIDb = d.getElementById(this.cid + "_b");
    currIDs = d.getElementById(this.cid + "_s");
    d.getElementById(this.cid + "_extWA").style.display = "block";
    return false;
}

function subBox(x, y, w, h, bgc, id) {
    var v = d.createElement('div');
    v.setAttribute('id', id);
    v.style.position = 'absolute';
    v.style.left = x + 'px';
    v.style.top = y + 'px';
    v.style.width = w + 'px';
    v.style.height = h + 'px';
    if (bgc != '')
        v.style.backgroundColor = bgc;
    v.style.display = 'block';
    v.style.padding = '0px';
    return v;
}

function popUp(x, y, w, h, cid, contentDiv, title, date, btnClose) {
    x = x * 1.0;
    y = y * 1.0;
    y = y + (document.documentElement.scrollTop ? document.documentElement.scrollTop :
                                                                document.body.scrollTop);
    w = w * 1.0;
    h = h * 1.0;
    if (w3c) {
        var parent = window.ActiveXObject ? contentDiv.parentElement : contentDiv.parentNode;
        if (document.getElementById(cid + '_b')) {
            h = h + 36;
            w = (ie5) ? w + 7 : w + 13;
        }
        var found = false;
        for (var i = 0; i < cidlist.length; i++) {
            var varCid = cidlist[i].split(';')[0];
            if (varCid == cid) {
                x = cidlist[i].split(';')[1] * 1.0;
                y = cidlist[i].split(';')[2] * 1.0;
                cidlist.splice(i, 1);
                found = true;
            }
        }
        cidlist[cidlist.length] = cid + ';' + x + ';' + y;
        w = Math.max(w, 100);
        h = Math.max(h, 80);
        var rdiv = new subBox(w - ((ie5) ? 12 : 8), h - ((ie5) ? 12 : 8), 7, 7, '', cid + '_rs');
        rdiv.innerHTML = '<img src="' + rsImg + '" width="7" height="7">';
        rdiv.style.cursor = 'move';
        rdiv.rsEnable = true;
        var tw = (ie5) ? w : w + 4;
        var th = (ie5) ? h : h + 6;
        var shadow = new subBox(x + 8, y + 8, tw, th, "black", cid + '_s');
        if (ie5)
            shadow.style.filter = "alpha(opacity=50)";
        else
            shadow.style.MozOpacity = .5;
        var outerdiv = new subBox(x, y, w, h, 'lightgrey', cid + '_b');
        outerdiv.style.display = "block";
        outerdiv.style.borderStyle = "outset";
        outerdiv.style.borderWidth = "2px";
        outerdiv.style.borderColor = "lightgrey";
        tw = (ie5) ? w - 8 : w - 5;
        th = (ie5) ? h + 4 : h - 4;
        var titlebar = new subBox(2, 2, tw, 20, '#6DBAF3', cid + '_t');
        titlebar.style.overflow = "hidden";
        titlebar.style.cursor = "default";
        var tmp = '<img src="' + minImg + '" width="16" height="16" id="' + cid + '_min"><img src="' + maxImg + '" width="16" height="16"  id="' + cid + '_max">';
        titlebar.innerHTML = '<span style="position:absolute; left:3px; top:1px; font:bold 10pt sans-serif; color:white; height:18px; overflow:hidden; clip-height:16px;">' + title + (date != '' ? ' for ' + date : '') + '</span><div id="' + cid + '_btt" style="position:absolute; width:48px; height:16px; left:' + (tw - 48) + 'px; top:2px; text-align:right">' + tmp + '<img src="' + clsImg + '" width="16" height="16" id="' + cid + '_cls"></div>';
        tw = (ie5) ? w - 7 : w - 13;

        var content = parent.removeChild(contentDiv);
        content.style.position = 'absolute';
        content.style.left = 2 + 'px';
        content.style.top = 24 + 'px';
        content.style.width = tw + 'px';
        content.style.height = (h - 36) + 'px';
        content.style.display = 'inline';
        content.style.borderColor = "lightgrey";
        content.style.borderWidth = "2px";
        if (ie5)
            content.style.scrollbarBaseColor = "#6DBAF3";
        content.style.borderStyle = "inset";
        content.style.overflow = "auto";
        content.style.padding = "0px 2px 0px 4px";
        content.style.font = '10pt sans-serif';
        content.id = cid + '_c';

        var extWA = new subBox(2, 24, 0, 0, '', cid + '_extWA');
        extWA.style.display = "none";
        extWA.style.width = '100%';
        extWA.style.height = '100%';
        outerdiv.appendChild(titlebar);
        outerdiv.appendChild(content);
        outerdiv.appendChild(extWA);
        outerdiv.appendChild(rdiv);
        if (document.getElementById(cid + '_b')) {
            parent = window.ActiveXObject ? document.getElementById(cid + '_b').parentElement : document.getElementById(cid + '_b').parentNode;
            parent.removeChild(document.getElementById(cid + '_b'));
            parent.removeChild(document.getElementById(cid + '_s'));
        }
        for (var i = 0; i < cidlist.length; i++)
            if (parent.id == cidlist[i].split(';')[0]) {
            parent = window.ActiveXObject ? parent.parentElement : parent.parentNode;
            break;
        }
        parent.appendChild(shadow);
        parent.appendChild(outerdiv);
        var wB = d.getElementById(cid + '_b');
        wB.cid = cid;
        wB.isExt = false;
        var wT = d.getElementById(cid + '_t');
        wT.cid = cid;
        var wRS = d.getElementById(cid + '_rs');
        wRS.cid = cid;
        var wMIN = d.getElementById(cid + '_min');
        wMIN.cid = cid;
        var wMAX = d.getElementById(cid + '_max');
        wMAX.h = h;
        wMAX.cid = cid;
        wMIN.onclick = minimize;
        wMAX.onclick = restore;
        wRS.onmousedown = startRS;
        wRS.onmouseup = stopRS;
        var wCLS = d.getElementById(cid + '_cls');
        var wEXTWA = d.getElementById(cid + '_extWA');
        wB.activecolor = '#FF7A28';
        wB.inactivecolor = '#FF7A28'; //"#6DBAF3";
        if ((oldac != null) && d.getElementById(oldac.cid + "_t")) {
            d.getElementById(oldac.cid + "_t").style.backgroundColor = oldac.inactivecolor;
            changez(oldac);
        }
        else {
            d.getElementById(cid + "_t").style.backgroundColor = wB.activecolor;
            changez(wB);
        }
        if (!found)
            oldac = wB;
        wCLS.onclick = new Function("hidebox('" + cid + "', '" + btnClose + "');");
        wB.onmousedown = function() { changez(this) }
        wT.onmousedown = grab_id;
        wT.onmouseup = stopdrag;
        if (outerdiv.cid == 'divAvailableDays')
            outerdiv.style.zIndex = ++zdx;
    }
}

function ShowErrorMessage(errMessage, msgType, width, height) {
    if (w3c) {
        cid = 'divError';
        cidlist[cidlist.length] = cid;
        var w = 300;
        if (width && width != null)
            w = width;
        var h = 150;
        if (height && height != null)
            h = height;
        var win = WindowSize();
        var x = (win.x - w) / 2;
        var y = (win.y - h) / 2 + (document.documentElement.scrollTop ? document.documentElement.scrollTop :
                                                                        document.body.scrollTop);
        var tw = (ie5) ? w : w + 4;
        var th = (ie5) ? h : h + 6;
        var shadow = new subBox(x + 8, y + 8, tw, th, "black", cid + '_s');
        if (ie5)
            shadow.style.filter = "alpha(opacity=50)";
        else
            shadow.style.MozOpacity = .5;
        shadow.style.zIndex = ++zdx;
        var outerdiv = new subBox(x, y, w, h, 'lightgrey', cid + '_b');
        outerdiv.style.display = "block";
        outerdiv.style.borderStyle = "outset";
        outerdiv.style.borderWidth = "2px";
        outerdiv.style.borderColor = "lightgrey";
        outerdiv.style.zIndex = ++zdx;
        tw = (ie5) ? w - 8 : w - 5;
        th = (ie5) ? h + 4 : h - 4;
        var titlebar = new subBox(2, 2, tw, 20, '#4E4C4F', cid + '_t');
        titlebar.style.overflow = "hidden";
        titlebar.style.cursor = "default";
        var table = '<table width="100%" cellpadding="0" cellspacing="0"><tr><td>';
        table += '<div style="position:absolute;left:1px;top:2px"><img src="'
        var titleMsg = '';
        var color = '';
        if ((!msgType) || msgType == 'undefined' || msgType == 'False') {
            table += errorImg;
            titleMsg = "Error";
            color = "red";
        }
        else {
            table += succImg;
            titleMsg = "Success";
            color = "green";
        }
        table += '" width="16" height="16"></div>';
        table += '<span style="position:absolute;left:20px;top : 0; font:bold 10pt sans-serif; color:white; height:18px; overflow:hidden; clip-height:16px;">' + titleMsg + '</span><div id="' + cid + '_btt" style="position:absolute; width:48px; height:16px; left:' + (tw - 48) + 'px; top:2px; text-align:right"><img src="' + clsImg + '" width="16" height="16" id="' + cid + '_cls"></div>';
        titlebar.innerHTML = table + '</td></tr></table>';
        tw = (ie5) ? w - 7 : w - 13;

        var content = new subBox(w - ((ie5) ? 12 : 8), h - ((ie5) ? 10 : 8), 7, 7, '#e1e1e1', cid + '_c');
        content.style.position = 'absolute';
        content.style.left = 2 + 'px';
        content.style.top = 24 + 'px';
        content.style.width = tw + 'px';
        content.style.height = (h - 32) + 'px';
        content.style.display = 'inline';
        content.style.borderColor = "lightgrey";
        content.style.borderWidth = "2px";
        if (ie5)
            content.style.scrollbarBaseColor = "#6DBAF3";
        content.style.borderStyle = "inset";
        content.style.overflow = "auto";
        content.style.padding = "0px 2px 0px 4px";
        content.style.font = '10pt sans-serif';

        var errorDiv = document.createElement('DIV');
        errorDiv.style.width = '100%';
        errorDiv.style.height = '100%';
        errorDiv.style.color = color;
        var errorTable = '<table width="100%" height="100%" cellspacing="0" cellpadding="0"><tr><td valign="middle" align="center" style="color:' + color + '">';
        errorTable += '<B>' + errMessage + '</B>';
        errorTable += '</td></tr></table>';
        errorDiv.innerHTML = errorTable;

        var extWA = new subBox(2, 24, 0, 0, '', cid + '_extWA');
        extWA.style.display = "none";
        extWA.style.width = '100%';
        extWA.style.height = '100%';
        content.appendChild(errorDiv);
        outerdiv.appendChild(titlebar);
        outerdiv.appendChild(content);
        outerdiv.appendChild(extWA);
        if (document.getElementById(cid + '_s'))
            d.body.removeChild(document.getElementById(cid + '_s'));
        if (document.getElementById(cid + '_b'))
            d.body.removeChild(document.getElementById(cid + '_b'));
        d.body.appendChild(shadow);
        d.body.appendChild(outerdiv);
        d.gEl = d.getElementById;
        var wB = d.gEl(cid + '_b');
        wB.cid = cid;
        wB.isExt = false;
        var wT = d.gEl(cid + '_t');
        wT.cid = cid;
        var wCLS = d.gEl(cid + '_cls');
        var wEXTWA = d.gEl(cid + '_extWA');
        wCLS.onclick = new Function("hidebox('" + cid + "');");
        wB.onmousedown = function() { changez(this) }
        wT.onmousedown = grab_id;
        wT.onmouseup = stopdrag;
    }
}

function Blink(controlID) {
    if (document.getElementById(controlID))
        if (!ie5) {
        if (document.getElementById(controlID).parentNode.innerHTML.indexOf('disabled') < 0)
            document.getElementById(controlID).style.color = ((document.getElementById(controlID).style.color.toUpperCase() == '#4E4C4F') ||
                                                        (document.getElementById(controlID).style.color.toLowerCase() == 'rgb(78, 76, 79)')
                                                                ? '#FF7A28' : '#4E4C4F');
    }
    else
        document.getElementById(controlID).style.color = ((document.getElementById(controlID).style.color.toUpperCase() == '#4E4C4F') ||
                                                        (document.getElementById(controlID).style.color.toLowerCase() == 'rgb(78, 76, 79)')
                                                                ? '#FF7A28' : '#4E4C4F');
    setTimeout('Blink("' + controlID + '")', 500);
}

if (ns6)
    setInterval('movepopup()', 40);

if (w3c) {
    d.onmouseup = new Function("currRS = null");
}

//Cancel Postback
Sys.Application.add_load(ApplicationLoadHandler);

function EndRequestHandler(sender, args) {
    ActivateAlertDiv('none', 'ProcessingDiv');
}
function ActivateAlertDiv(visstring, elem) {
    var adiv = document.getElementById(elem);
    adiv.style.top = mousePos.y;
    adiv.style.left = mousePos.x - 32;
    adiv.style.zIndex = zdx + 10;
    adiv.style.display = visstring;
}

function ApplicationLoadHandler(sender, args) {
    try {
        Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(CheckStatus);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    } catch (ex) { }
}

function CheckStatus(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    if (prm.get_isInAsyncPostBack())
        args.set_cancel(true);
    else
        ActivateAlertDiv('inline', 'ProcessingDiv');
}

if (typeof (Sys) !== "undefined")
    Sys.Application.notifyScriptLoaded();





/////

function LoadWaiting() {
    if (!mousePos) {
        setTimeout('LoadWaiting()', 50);
        return false;
    }
    var win = WindowSize();
    var divWidth = 350;
    var divHeight = 300;
    var x = (1.0 * win.x - 1.0 * divWidth) / 2;
    var y = (1.0 * win.y - 1.0 * divHeight) / 2;
    var xwin = new popUp(x, y, 350, 300, 'divWaiting', document.getElementById('divWaiting_c'), 'Please wait ...', '', 'NOACTION');
}

/**********PHONE VALIDATION - MASK*******************/

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object) {
    phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object) {
    phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object, e) {
    if (e) {
        e = e
    } else {
        e = window.event
    }
    if (e.which) {
        var keycode = e.which
    } else {
        var keycode = e.keyCode
    }

    ParseForNumber1(object)

    if (keycode >= 48) {
        ValidatePhone(object)
    }
}

function backspacerDOWN(object, e) {
    if (e) {
        e = e
    } else {
        e = window.event
    }
    if (e.which) {
        var keycode = e.which
    } else {
        var keycode = e.keyCode
    }
    ParseForNumber2(object)
}

function GetCursorPosition() {

    var t1 = phonevalue1;
    var t2 = phonevalue2;
    var bool = false
    for (i = 0; i < t1.length; i++) {
        if (t1.substring(i, 1) != t2.substring(i, 1)) {
            if (!bool) {
                cursorposition = i
                bool = true
            }
        }
    }
}

function ValidatePhone(object) {

    var p = phonevalue1

    p = p.replace(/[^\d]*/gi, "")

    if (p.length < 3) {
        object.value = p
    } else if (p.length == 3) {
        pp = p;
        d4 = p.indexOf('(')
        d5 = p.indexOf(')')
        if (d4 == -1) {
            pp = "(" + pp;
        }
        if (d5 == -1) {
            pp = pp + ")";
        }
        object.value = pp;
    } else if (p.length > 3 && p.length < 7) {
        p = "(" + p;
        l30 = p.length;
        p30 = p.substring(0, 4);
        p30 = p30 + ")"

        p31 = p.substring(4, l30);
        pp = p30 + p31;

        object.value = pp;

    } else if (p.length >= 7) {
        p = "(" + p;
        l30 = p.length;
        p30 = p.substring(0, 4);
        p30 = p30 + ")"

        p31 = p.substring(4, l30);
        pp = p30 + p31;

        l40 = pp.length;
        p40 = pp.substring(0, 8);
        p40 = p40 + "-"

        p41 = pp.substring(8, l40);
        ppp = p40 + p41;

        object.value = ppp.substring(0, maxphonelength);
    }

    GetCursorPosition()

    if (cursorposition >= 0) {
        if (cursorposition == 0) {
            cursorposition = 2
        } else if (cursorposition <= 2) {
            cursorposition = cursorposition + 1
        } else if (cursorposition <= 5) {
            cursorposition = cursorposition + 2
        } else if (cursorposition == 6) {
            cursorposition = cursorposition + 2
        } else if (cursorposition == 7) {
            cursorposition = cursorposition + 4
            e1 = object.value.indexOf(')')
            e2 = object.value.indexOf('-')
            if (e1 > -1 && e2 > -1) {
                if (e2 - e1 == 4) {
                    cursorposition = cursorposition - 1
                }
            }
        } else if (cursorposition < 11) {
            cursorposition = cursorposition + 3
        } else if (cursorposition == 11) {
            cursorposition = cursorposition + 1
        } else if (cursorposition >= 12) {
            cursorposition = cursorposition
        }

        var txtRange = object.createTextRange();
        txtRange.moveStart("character", cursorposition);
        txtRange.moveEnd("character", cursorposition - object.value.length);
        txtRange.select();
    }

}

function ParseChar(sStr, sChar) {
    if (sChar.length == null) {
        zChar = new Array(sChar);
    }
    else zChar = sChar;

    for (i = 0; i < zChar.length; i++) {
        sNewStr = "";

        var iStart = 0;
        var iEnd = sStr.indexOf(sChar[i]);

        while (iEnd != -1) {
            sNewStr += sStr.substring(iStart, iEnd);
            iStart = iEnd + 1;
            iEnd = sStr.indexOf(sChar[i], iStart);
        }
        sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

        sStr = sNewStr;
    }

    return sNewStr;
}

/***********DATE MASK************/

// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/";
// If you are using any Java validation on the back side you will want to use the / because 
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 2; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if (navigator.appName == "Netscape") {
    if (navigator.appVersion < "5") {
        isNav4 = true;
        isNav5 = false;
    }
    else
        if (navigator.appVersion > "4") {
        isNav4 = false;
        isNav5 = true;
    }
}
else {
    isIE4 = true;
}

function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
    vDateType = dateType;
    // vDateName = object name
    // vDateValue = value in the field being checked
    // e = event
    // dateCheck 
    // True  = Verify that the vDateValue is a valid date
    // False = Format values being entered into vDateValue only
    // vDateType
    // 1 = mm/dd/yyyy
    // 2 = yyyy/mm/dd
    // 3 = dd/mm/yyyy
    //Enter a tilde sign for the first number and you can check the variable information.
    if (vDateValue == "~") {
        alert("AppVersion = " + navigator.appVersion + " \nNav. 4 Version = " + isNav4 + " \nNav. 5 Version = " + isNav5 + " \nIE Version = " + isIE4 + " \nYear Type = " + vYearType + " \nDate Type = " + vDateType + " \nSeparator = " + strSeperator);
        vDateName.value = "";
        vDateName.focus();
        return true;
    }
    var whichCode = (window.Event) ? e.which : e.keyCode;
    // Check to see if a seperator is already present.
    // bypass the date if a seperator is present and the length greater than 8
    if (vDateValue.length > 8 && isNav4) {
        if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
            return true;
    }
    //Eliminate all the ASCII codes that are not valid
    var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
    if (alphaCheck.indexOf(vDateValue) >= 1) {
        if (isNav4) {
            vDateName.value = "";
            vDateName.focus();
            vDateName.select();
            return false;
        }
        else {
            vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
            return false;
        }
    }
    if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
        return false;
    else {
        //Create numeric string values for 0123456789/
        //The codes provided include both keyboard and keypad values
        var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
        if (strCheck.indexOf(whichCode) != -1) {
            if (isNav4) {
                if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >= 1)) {
                    alert("Invalid Date\nPlease Re-Enter");
                    vDateName.value = "";
                    vDateName.focus();
                    vDateName.select();
                    return false;
                }
                if (vDateValue.length == 6 && dateCheck) {
                    var mDay = vDateName.value.substr(2, 2);
                    var mMonth = vDateName.value.substr(0, 2);
                    var mYear = vDateName.value.substr(4, 4)
                    //Turn a two digit year into a 4 digit year
                    if (mYear.length == 2 && vYearType == 4) {
                        var mToday = new Date();
                        //If the year is greater than 30 years from now use 19, otherwise use 20
                        var checkYear = mToday.getFullYear() + 30;
                        var mCheckYear = '20' + mYear;
                        if (mCheckYear >= checkYear)
                            mYear = '19' + mYear;
                        else
                            mYear = '20' + mYear;
                    }
                    var vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                    if (!dateValid(vDateValueCheck)) {
                        alert("Invalid Date\nPlease Re-Enter");
                        vDateName.value = "";
                        vDateName.focus();
                        vDateName.select();
                        return false;
                    }
                    return true;
                }
                else {
                    // Reformat the date for validation and set date type to a 1
                    if (vDateValue.length >= 8 && dateCheck) {
                        if (vDateType == 1) // mmddyyyy
                        {
                            var mDay = vDateName.value.substr(2, 2);
                            var mMonth = vDateName.value.substr(0, 2);
                            var mYear = vDateName.value.substr(4, 4)
                            vDateName.value = mMonth + strSeperator + mDay + strSeperator + mYear;
                        }
                        if (vDateType == 2) // yyyymmdd
                        {
                            var mYear = vDateName.value.substr(0, 4)
                            var mMonth = vDateName.value.substr(4, 2);
                            var mDay = vDateName.value.substr(6, 2);
                            vDateName.value = mYear + strSeperator + mMonth + strSeperator + mDay;
                        }
                        if (vDateType == 3) // ddmmyyyy
                        {
                            var mMonth = vDateName.value.substr(2, 2);
                            var mDay = vDateName.value.substr(0, 2);
                            var mYear = vDateName.value.substr(4, 4)
                            vDateName.value = mDay + strSeperator + mMonth + strSeperator + mYear;
                        }
                        //Create a temporary variable for storing the DateType and change
                        //the DateType to a 1 for validation.
                        var vDateTypeTemp = vDateType;
                        vDateType = 1;
                        var vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                        if (!dateValid(vDateValueCheck)) {
                            alert("Invalid Date\nPlease Re-Enter");
                            vDateType = vDateTypeTemp;
                            vDateName.value = "";
                            vDateName.focus();
                            vDateName.select();
                            return false;
                        }
                        vDateType = vDateTypeTemp;
                        return true;
                    }
                    else {
                        if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >= 1)) {
                            alert("Invalid Date\nPlease Re-Enter");
                            vDateName.value = "";
                            vDateName.focus();
                            vDateName.select();
                            return false;
                        }
                    }
                }
            }
            else {
                // Non isNav Check
                if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >= 1)) {
                    alert("Invalid Date\nPlease Re-Enter");
                    vDateName.value = "";
                    vDateName.focus();
                    return true;
                }
                // Reformat date to format that can be validated. mm/dd/yyyy
                if (vDateValue.length >= 8 && dateCheck) {
                    // Additional date formats can be entered here and parsed out to
                    // a valid date format that the validation routine will recognize.
                    if (vDateType == 1) // mm/dd/yyyy
                    {
                        var mMonth = vDateName.value.substr(0, 2);
                        var mDay = vDateName.value.substr(3, 2);
                        var mYear = vDateName.value.substr(6, 4)
                    }
                    if (vDateType == 2) // yyyy/mm/dd
                    {
                        var mYear = vDateName.value.substr(0, 4)
                        var mMonth = vDateName.value.substr(5, 2);
                        var mDay = vDateName.value.substr(8, 2);
                    }
                    if (vDateType == 3) // dd/mm/yyyy
                    {
                        var mDay = vDateName.value.substr(0, 2);
                        var mMonth = vDateName.value.substr(3, 2);
                        var mYear = vDateName.value.substr(6, 4)
                    }
                    if (vYearLength == 4) {
                        if (mYear.length < 4) {
                            alert("Invalid Date\nPlease Re-Enter");
                            vDateName.value = "";
                            vDateName.focus();
                            return true;
                        }
                    }
                    // Create temp. variable for storing the current vDateType
                    var vDateTypeTemp = vDateType;
                    // Change vDateType to a 1 for standard date format for validation
                    // Type will be changed back when validation is completed.
                    vDateType = 1;
                    // Store reformatted date to new variable for validation.
                    var vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                    if (mYear.length == 2 && vYearType == 4 && dateCheck) {
                        //Turn a two digit year into a 4 digit year
                        var mToday = new Date();
                        //If the year is greater than 30 years from now use 19, otherwise use 20
                        var checkYear = mToday.getFullYear() + 30;
                        var mCheckYear = '20' + mYear;
                        if (mCheckYear >= checkYear)
                            mYear = '19' + mYear;
                        else
                            mYear = '20' + mYear;
                        vDateValueCheck = mMonth + strSeperator + mDay + strSeperator + mYear;
                        // Store the new value back to the field.  This function will
                        // not work with date type of 2 since the year is entered first.
                        if (vDateTypeTemp == 1) // mm/dd/yyyy
                            vDateName.value = mMonth + strSeperator + mDay + strSeperator + mYear;
                        if (vDateTypeTemp == 3) // dd/mm/yyyy
                            vDateName.value = mDay + strSeperator + mMonth + strSeperator + mYear;
                    }
                    if (!dateValid(vDateValueCheck)) {
                        alert("Invalid Date\nPlease Re-Enter");
                        vDateType = vDateTypeTemp;
                        vDateName.value = "";
                        vDateName.focus();
                        return true;
                    }
                    vDateType = vDateTypeTemp;
                    return true;
                }
                else {
                    if (vDateType == 1) {
                        if (vDateValue.length == 2) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                        if (vDateValue.length == 5) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                    }
                    if (vDateType == 2) {
                        if (vDateValue.length == 4) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                        if (vDateValue.length == 7) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                    }
                    if (vDateType == 3) {
                        if (vDateValue.length == 2) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                        if (vDateValue.length == 5) {
                            vDateName.value = vDateValue + strSeperator;
                        }
                    }
                    return true;
                }
            }
            if (vDateValue.length == 10 && dateCheck) {
                if (!dateValid(vDateName)) {
                    // Un-comment the next line of code for debugging the dateValid() function error messages
                    //alert(err);  
                    alert("Invalid Date\nPlease Re-Enter");
                    vDateName.focus();
                    vDateName.select();
                }
            }
            return false;
        }
        else {
            // If the value is not in the string return the string minus the last
            // key entered.
            if (isNav4) {
                vDateName.value = "";
                vDateName.focus();
                vDateName.select();
                return false;
            }
            else {
                vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
                return false;
            }
        }
    }
}
function dateValid(objName) {
    var strDate;
    var strDateArray;
    var strDay;
    var strMonth;
    var strYear;
    var intday;
    var intMonth;
    var intYear;
    var booFound = false;
    var datefield = objName;
    var strSeparatorArray = new Array("-", " ", "/", ".");
    var intElementNr;
    // var err = 0;
    var strMonthArray = new Array(12);
    strMonthArray[0] = "Jan";
    strMonthArray[1] = "Feb";
    strMonthArray[2] = "Mar";
    strMonthArray[3] = "Apr";
    strMonthArray[4] = "May";
    strMonthArray[5] = "Jun";
    strMonthArray[6] = "Jul";
    strMonthArray[7] = "Aug";
    strMonthArray[8] = "Sep";
    strMonthArray[9] = "Oct";
    strMonthArray[10] = "Nov";
    strMonthArray[11] = "Dec";
    //strDate = datefield.value;
    strDate = objName;
    if (strDate.length < 1) {
        return true;
    }
    for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
        if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
            strDateArray = strDate.split(strSeparatorArray[intElementNr]);
            if (strDateArray.length != 3) {
                err = 1;
                return false;
            }
            else {
                strDay = strDateArray[0];
                strMonth = strDateArray[1];
                strYear = strDateArray[2];
            }
            booFound = true;
        }
    }
    if (booFound == false) {
        if (strDate.length > 5) {
            strDay = strDate.substr(0, 2);
            strMonth = strDate.substr(2, 2);
            strYear = strDate.substr(4);
        }
    }
    //Adjustment for short years entered
    if (strYear.length == 2) {
        strYear = '20' + strYear;
    }
    strTemp = strDay;
    strDay = strMonth;
    strMonth = strTemp;
    intday = parseInt(strDay, 10);
    if (isNaN(intday)) {
        err = 2;
        return false;
    }
    intMonth = parseInt(strMonth, 10);
    if (isNaN(intMonth)) {
        for (i = 0; i < 12; i++) {
            if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
                intMonth = i + 1;
                strMonth = strMonthArray[i];
                i = 12;
            }
        }
        if (isNaN(intMonth)) {
            err = 3;
            return false;
        }
    }
    intYear = parseInt(strYear, 10);
    if (isNaN(intYear)) {
        err = 4;
        return false;
    }
    if (intMonth > 12 || intMonth < 1) {
        err = 5;
        return false;
    }
    if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
        err = 6;
        return false;
    }
    if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
        err = 7;
        return false;
    }
    if (intMonth == 2) {
        if (intday < 1) {
            err = 8;
            return false;
        }
        if (LeapYear(intYear) == true) {
            if (intday > 29) {
                err = 9;
                return false;
            }
        }
        else {
            if (intday > 28) {
                err = 10;
                return false;
            }
        }
    }
    return true;
}
function LeapYear(intYear) {
    if (intYear % 100 == 0) {
        if (intYear % 400 == 0) { return true; }
    }
    else {
        if ((intYear % 4) == 0) { return true; }
    }
    return false;
}

/***************SSN MASK & VALIDATOR*******************/

function numVal(elem) {
    fldVal = document.getElementById(elem).value;

    for (i = 0; i < fldVal.length; i++) {
        var nom = fldVal.charAt(i);
        if (isNaN(nom) && nom != "-") {
            document.myform.myval.value = fldVal.substring(0, fldVal.length - 1);
        }
        else { chkSpacing(elem) }
    }
}


function chkSpacing(elem) {

    var fldVal = document.getElementById(elem).value;
    if ((fldVal.length == 3) || (fldVal.length == 6)) {
        document.getElementById(elem).value = fldVal + "-"
    }
    if (fldVal.length >= 12) {
        document.getElementById(elem).value = fldVal.substring(0, fldVal.length - 1);
    }
}



var varPopUp = null;
function ClosePicker(divID) {
    delete (varPopUp);
    document.getElementById(divID + '_b').style.display = 'none';
    document.getElementById(divID + '_s').style.display = 'none';
}

var controlIDX = '';

function ShowPicker(divID, controlID) {
    if (controlID)
        controlIDX = controlID;
    else controlID = '';

    var divWidth = document.getElementById(divID + '_c').style.width.replace(/px/gi, '');
    var divHeight = document.getElementById(divID + '_c').style.height.replace(/px/gi, '');
    var win = WindowSize();
    var x = (1.0 * win.x - 1.0 * divWidth) / 2;
    var y = (1.0 * win.y - 1.0 * divHeight) / 2;
    varPopUp = new popUp(x, y, divWidth, divHeight, divID, document.getElementById(divID + '_c'), "Select Date", "", null);
    document.getElementById(divID + '_b').style.zIndex = '9999';
    document.getElementById(divID + '_s').style.zIndex = '9998';
}