﻿String.prototype.startsWith = function(str){     return (this.indexOf(str) === 0); }  

function hideJSError()
{
    obj = document.getElementById('divJSError');
    if (obj) {
        obj.style.display = 'none';
        obj.style.visibility = 'hidden';
    }
}

function setDisplay()
{
    var obj = document.getElementById('divDisplay');
    if (obj){
	    obj.style.display='block';
	    obj.style.visibility='visible';
	    }
}

var PopupIFrame;


function disableTab() {
    if (window.event.keyCode == 9) {
        if (typeof handleTabs == "function") { return handleTabs(); }
        else { return false; }
    }
}

function IsIE() {
    return (navigator.appName == "Microsoft Internet Explorer");
}

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}
function disableSelect(v) {
    if (typeof v == "undefined") v = true;
    var aTags = document.getElementsByTagName("SELECT");
    if (aTags != null) {
        for (i = 0; i < aTags.length; i++) {
            aTags[i].disabled = v;
        }
    }
}

function enableSelect() { disableSelect(false); }

var jvLoadingPanel;
var jvLoadingPanelInitialDelayTime;
function showLoading() {
    if (typeof interceptLoading == "function") {
        if (interceptLoading()) { return false }
    }
    setTimeout('jvLoadingPanel.style.display=\'block\'', jvLoadingPanelInitialDelayTime);
    setTimeout('jvLoadingPanel.style.visibility=\'visible\'', jvLoadingPanelInitialDelayTime);
}

function setLoading() {
    var aTags = document.getElementsByTagName("A");
    if (aTags != null) {
        for (i = 0; i < aTags.length; i++) {
            if (aTags[i].href &&
	        aTags[i].href.indexOf('AsyncRequest') < 0 && aTags[i].href.indexOf('AjaxNS') < 0 && //don't do if it's an ajax'd link
	        aTags[i].href.indexOf('#nlp') < 0 &&  // tag to prevent loading panel
	        aTags[i].href.indexOf('ThickClient') < 0 &&
	        aTags[i].href.indexOf('javascript:void') < 0 && //ignore dead links
	        aTags[i].className != 'NoLoadingPanel' &&
	        aTags[i].target == '') { //only do if opening in current window
                if (typeof aTags[i].onclick != "function") {   //don't attach the event if the link already has an onclick event.  if the loading panel needs to show, we can call showLoading ourselves
                    if (aTags[i].detachEvent) {
                        aTags[i].detachEvent('onclick', showLoading);
                        aTags[i].attachEvent('onclick', showLoading);
                    }
                    else {
                        aTags[i].removeEventListener('click', showLoading, false);
                        aTags[i].addEventListener('click', showLoading, false);
                    }
                }
            }
            if (aTags[i].href.indexOf('javascript:') >= 0) {
                aTags[i].onmouseover = LinkMouseover;
                aTags[i].onmouseout = LinkMouseout;
            }
        }
    }
}


function LeftNavOver(i,obj)
{
	obj.className="left_nav_over";
}
function LeftNavOut(i,obj)
{
	obj.className="left_nav";
}

function TopNavOver(i,obj)
{
	obj.className="top_nav_over";
}
function TopNavOut(i,obj)
{
	obj.className="top_nav";
}


function HidePopupDiv(divID) {
    var divPopup;
    divPopup = document.getElementById(divID);
    divPopup.style.visibility = "hidden";

    if (IsIE()) {
        if (PopupIFrame) {
            divPopup.parentNode.removeChild(PopupIFrame);
            PopupIFrame = null;
        }
    }
    if (document.detachEvent) { document.detachEvent("onkeydown", disableTab); }
    else { document.removeEventListener("keydown", disableTab, false) }
}

var jvSiteRootPath;
function ShowPopupDiv(divID, iFrameZ, bBlock) {
    var divPopup = document.getElementById(divID);
    var iFrame;

    if (IsIE() && getInternetExplorerVersion() < 8.0) {
        iFrame = document.createElement("IFRAME");
        if (document.location.protocol == "https:")
            iFrame.setAttribute("src", "//0");
        else if (window.opera != "undefined")
            iFrame.setAttribute("src", "");
        else
            iFrame.setAttribute("src", "javascript:false");
    }

    if (typeof iFrameZ == "undefined") {
        if (iFrame) { iFrame.style.zIndex = "-1" }
        divPopup.style.zIndex = 9999;
    } else {
        if (iFrame) { iFrame.style.zIndex = iFrameZ; }
        divPopup.style.zIndex = (iFrameZ + 2);
    }


    if (typeof bBlock == "undefined" || !bBlock) {
        if (iFrame) { divPopup.parentNode.insertBefore(iFrame, divPopup); }
    } else {
        var span = document.createElement("SPAN");
        var img = document.createElement("IMAGE");
        img.src = jvSiteRootPath + "Images/transp.gif";
        img.style.background = "url(" + jvSiteRootPath + "Images/ModalImageBg.gif)";
        img.style.position = "fixed";   // jtd: move with scroll
        img.style.width = screen.width + 'px';
        img.style.height = screen.height + 'px';
        img.style.left = '0px';
        img.style.top = '0px';
        img.galleryimg = 'false';


        var windowHeight = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
        var windowWidth = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
        divPopup.style.left = ((windowWidth / 2) - (divPopup.offsetWidth / 2)) + 'px';
        divPopup.style.top = ((windowHeight / 2) - (divPopup.offsetHeight / 2)) + 'px';
        span.style.zIndex = iFrameZ;
        img.style.zIndex = (iFrameZ + 2);
        divPopup.style.zIndex = (iFrameZ + 3);
        if (iFrame) {
            iFrame.style.zIndex = (iFrameZ + 1);
            document.body.childNodes[0].insertBefore(span);
            span.insertBefore(iFrame);
            span.insertBefore(divPopup);
            document.body.childNodes[0].insertBefore(img);
            disableSelect(true);
        } else {
            document.forms[0].insertBefore(span, document.forms[0].childNodes[0]);
            span.appendChild(divPopup);
            divPopup.parentNode.insertBefore(img, divPopup);
        }
        if (document.attachEvent) { document.attachEvent("onkeydown", disableTab); if (iFrame) { document.forms[0].attachEvent("onsubmit", enableSelect); } }
        else { document.addEventListener("keydown", disableTab); if (iFrame) { document.forms[0].addEventListener("submit", enableSelect); } }
    }
    if (iFrame) {
        //Match IFrame position with divPopup
        iFrame.style.position = "absolute";
        iFrame.style.left = divPopup.offsetLeft + 'px';
        iFrame.style.top = divPopup.offsetTop + 'px';
        iFrame.style.width = divPopup.offsetWidth + 'px';
        iFrame.style.height = divPopup.offsetHeight + 'px';

        PopupIFrame = iFrame;
    }
    divPopup.style.visibility = "visible";
    if (typeof popupFocus == "function") { popupFocus(); }
}



var pawindow = 'pawindow';

function blockNewWin() {
    var tempwin;
    if (self.name != pawindow) {
        tempwin = window.open('', pawindow);
        try {
            var loc = new String(tempwin.location);
            var dom = new String(document.domain);
            if (loc.indexOf(dom) >= 0) {
                self.alert('An existing Participant Access window is open');
                self.location = 'http://www.kccllc.com';
            } else if (tempwin.location == 'about:blank') {
                tempwin.close();
                self.name = pawindow;
            } else {
                self.name = pawindow;
            }
        }
        catch (err) {
            if (tempwin != null) tempwin.name = '';
            self.name = pawindow;
        }
    }
}

function formatDecimal(txt, clearOnError) {
    numDecimals = txt.getAttribute('maxDecimals');
    numDigits = txt.getAttribute('maxDigits');
    allowText = ('true' == txt.getAttribute('allowText'));
    allowNegative = ('true' == txt.getAttribute('allowNegative'));

    strRegex = '^';
    if (allowNegative) strRegext += '\\-?';
    strRegex += '\\d{0,' + numDigits + '}';
    if (numDecimals > 0) strRegex += '(\\.\\d{0,' + numDecimals + '})?';
    strRegex += '$';
    decimalRegex = new RegExp(strRegex);

    if (decimalRegex.test(txt.value) && txt.value != '.' && txt.value != '') {
        txt.style.color = 'black';
        txt.style.textAlign = 'right';
        txt.value = (txt.value * 1).toFixed(numDecimals);
    }
    else if (allowText) {
        txt.style.color = 'black';
        txt.style.textAlign = 'left';
    }
    else if (txt.value.length > 0) {
        txt.style.textAlign = 'left';
        bc = txt.style.backgroundColor;
        txt.style.backgroundColor = 'yellow';
        alert('Decimal value must be valid and cannot have more than ' + numDigits + ' digits and ' + numDecimals + ' decimals.');
        txt.style.backgroundColor = bc;
        txt.focus();
        if (clearOnError) txt.value = '';
    }
}
