﻿function ReceiveServerData(arg, context) {
}


//obj1 = checkbox
//obj2 = image
function essentialSwitch(obj1, obj2, checkboxcollection, imgClassOn, imgClassOff, tooltipOn, tooltipOff, checkboxExact, imgExact) {
    var chkBoxCollection = checkboxcollection.split('|');
    var essFlag = document.getElementById(obj1);
    var essImage = document.getElementById(obj2);
    var allOnFlag = true;
    
    
    if (essFlag.checked == true) {
        essFlag.checked = false;
        essImage.alt = tooltipOff;
        essImage.title = tooltipOff;
        essImage.className = imgClassOff;
        //essImage.src = imgOff;
        for (var i = 0; i < chkBoxCollection.length; i++)
        {
            if (!document.getElementById(chkBoxCollection[i]).checked){
                allOnFlag = false;
                break;
            }   
        }
        if (!allOnFlag) {
            document.getElementById(checkboxExact).checked = false;
            document.getElementById(imgExact).className = imgClassOff + "Exact";
        }
    }
    else {
        essFlag.checked = true;
        essImage.alt = tooltipOn;
        essImage.title = tooltipOn;
        //essImage.src = imgOn;
        essImage.className = imgClassOn;
        //essImage.setAttribute("class", imgClassOn);
        for (var i = 0; i < chkBoxCollection.length; i++)
        {
            if (!document.getElementById(chkBoxCollection[i]).checked){
                allOnFlag = false;
                break;
            }   
        }
        if (allOnFlag) {
            document.getElementById(checkboxExact).checked = true;
            document.getElementById(imgExact).className = imgClassOn + "Exact";
        }
    }
}

function essentialSwitchAll(initcheckbox, initimg, checkboxcollection, imgcollection, imgClassOn, imgClassOff, tooltipOn, tooltipOff, fromCheckBox, bReset) {
    var chkBoxCollection = checkboxcollection.split('|');
    var imgCollection = imgcollection.split('|');
    var essFlag = document.getElementById(initcheckbox);
    var essImage = document.getElementById(initimg);
    var currStat = essFlag.checked;

    //it is from hitting the checkbox, therefor invert the status
    if (fromCheckBox.toLowerCase() === 'true')
        currStat = !essFlag.checked;
    
    //it is a reset, therefor fake a false, to set everything to true
    if (bReset.toLowerCase() === 'true')
        currStat = false;
    
    //set to false
    if (currStat == true) {
        //essImage.src = imgOff;
        essImage.className =  imgClassOff + "Exact";
        essFlag.checked = false;
        for (var i = 0; i < chkBoxCollection.length; i++) 
            document.getElementById(chkBoxCollection[i]).checked = false;

        for (var i = 0; i < imgCollection.length; i++) {
            //document.getElementById(imgCollection[i]).src = imgOff;
            document.getElementById(imgCollection[i]).className = imgClassOff;
            document.getElementById(imgCollection[i]).alt = tooltipOff;
            document.getElementById(imgCollection[i]).title = tooltipOff;
        }

    } else {
        //essImage.src = imgOn;
        essImage.className = imgClassOn + "Exact";
        essFlag.checked = true;
        for (var i = 0; i < chkBoxCollection.length; i++)
            document.getElementById(chkBoxCollection[i]).checked = true;

        for (var i = 0; i < imgCollection.length; i++) {
            //document.getElementById(imgCollection[i]).src = imgOn;
            document.getElementById(imgCollection[i]).className = imgClassOn;
            document.getElementById(imgCollection[i]).alt = tooltipOn;
            document.getElementById(imgCollection[i]).title = tooltipOn;
        }
    }
}

//onblur and pa
function loadFieldTempValue(obj, objStyle, defaultText) {
    var ttobj = document.getElementById(obj);
    if (ttobj.value == '' || ttobj.value == defaultText) {
        ttobj.className = objStyle + "A";
        ttobj.value = defaultText;
    }
}

//onfocus
function clearFieldTempValue(obj, objStyle, objStyleAlt, defaultText) {
    var ttobj = document.getElementById(obj);
    if (ttobj.className == objStyle) {
        ttobj.value = '';
        ttobj.className = objStyleAlt;
    }
}

//Reset DDL
function resetDropDownList(obj, defaultValue) {
    var ttobj = document.getElementById(obj);
    ttobj.selectedindex = 0
    ttobj.options[0].selected = true;

    for (var i = 0; i < ttobj.options.length; i++) {
        if (ttobj.options[i].value == defaultValue) {
            ttobj.options[i].selected = true;
            return;
        }
    }
}
function hideResultsGrid(obj) {
    var ttobj = document.getElementById(obj);
    if (ttobj)
        ttobj.className = 'displayNone';
}

//Clear textbox
function clearTextBox(obj) {
    var ttobj = document.getElementById(obj);
    ttobj.value = '';
}

function getPageSizeWithScroll() {
    if (window.innerHeight && window.scrollMaxY) {
        // Firefox         
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    }
    else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    arrayPageSizeWithScroll = new Array(xWithScroll, yWithScroll);
    //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
    return arrayPageSizeWithScroll;
}

//returns the available height and width of the screen
function getViewPort() {
    var viewportwidth;
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
          viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
        //viewportheight = document.documentElement.clientHeight - use offsetHeight instead, seems to work better
           viewportheight = (document.documentElement.clientHeight > document.body.offsetHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
           viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    arrayViewPort = new Array(viewportwidth, viewportheight);
    //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
    return arrayViewPort;

}

//returns the available size of window, the height betwen the menus at the top and the scrollbar at the bottom, as you see it.
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    arrayWindowSize = new Array(myWidth, myHeight);
    return arrayWindowSize;

}


function DisplayLogoutPopUp() {
    var loadUrl = "/secure/LogoutPopup.aspx";
    var ajax_load = "<img src='/i/progress_indicator.gif' alt='loading...' />";
    $("#modalBody")
            .html(ajax_load)
            .load(loadUrl + " #Signout");
}

function DisplayDeleteUserPopUp(tableRow, divMessage, lblMessage, userId, userName, activeUserCount, TotalUserCount, enabledClass) {
    var loadUrl = "/secure/administration/DeleteUserPopup.aspx?tr=" + tableRow + "&dm=" + divMessage + "&lm=" + lblMessage + "&uid=" + userId + "&un=" + userName + "&auc=" + activeUserCount + "&tuc=" + TotalUserCount + "&ec=" + enabledClass + "";
    var ajax_load = "<img src='/i/progress_indicator.gif' alt='loading...' />";
    $("#modalBody")
            .html(ajax_load)
            .load(loadUrl + " #DeleteUser");
}




//doSplash('modalPage', 'modalContainer', 'modal', '300', '500', 'modalPageiframe')
function doSplash(obj1, obj2, obj3, iwidth, iheight, iframe, background) {
    
    var el1 = document.getElementById(obj1);
    var el2 = document.getElementById(obj2);
    var el3 = document.getElementById(obj3);
    var el4 = document.getElementById(iframe);

    scroll(0, 0)
    el1.style.display = 'block';
    el3.style.width = iwidth + "px";
    
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#' + iframe + '').css({ 'width': maskWidth, 'height': maskHeight });
    $('#' + background + '').css({ 'width': maskWidth, 'height': maskHeight });

    //transition effect
    $('#' + iframe + '').show();
    $('#' + background + '').css('opacity', 0.8).show();
    $('#' + obj2 + '').show();

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();

    
    //Set the popup window to center
    $('#' + obj2 + '').css('top', winH / 2 - $('#' + obj2 + '').height() / 2);
    $('#' + obj2 + '').css('left', winW / 2 - $('#' + obj2 + '').width() / 2);

}





function hideSplash(obj1) {
    var el = document.getElementById(obj1);
    if (el) {
        el.style.display = 'none';
    }
}


//dynamically switching stylessheets
function loadjscssfile(filename, filetype) {
    if (filetype == "js") { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css") { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}
function removejscssfile(filename, filetype) {
    var targetelement = (filetype == "js") ? "script" : (filetype == "css") ? "link" : "none" //determine element type to create nodelist from
    var targetattr = (filetype == "js") ? "src" : (filetype == "css") ? "href" : "none" //determine corresponding attribute to test for
    var allsuspects = document.getElementsByTagName(targetelement)
    for (var i = allsuspects.length; i >= 0; i--) { //search backwards within nodelist for matching elements to remove
        if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
            allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
    }
}
function createjscssfile(filename, filetype) {
    if (filetype == "js") { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css") { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    return fileref
}
function replacejscssfile(oldfilename, newfilename, filetype) {
    var targetelement = (filetype == "js") ? "script" : (filetype == "css") ? "link" : "none" //determine element type to create nodelist using
    var targetattr = (filetype == "js") ? "src" : (filetype == "css") ? "href" : "none" //determine corresponding attribute to test for
    var allsuspects = document.getElementsByTagName(targetelement)
    for (var i = allsuspects.length; i >= 0; i--) { //search backwards within nodelist for matching elements to remove
        if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(oldfilename) != -1) {
            var newelement = createjscssfile(newfilename, filetype)
            allsuspects[i].parentNode.replaceChild(newelement, allsuspects[i])
        }
    }
}

//change stylesheet
function changeStyle(StyleID) {
    removejscssfile("/s/1.css", "css")
    removejscssfile("/s/4.css", "css")
    removejscssfile("/s/6.css", "css")
    loadjscssfile("/s/" + StyleID + ".css", "css")
    updateCSSPost('UpdateCSS|'+ StyleID,"")
}


function updateCSSPost(val, context) {
    updateCSSOnServer(val, context);
}

function hideElement(id) {
    var me = document.getElementById(id);
    me.style.display = "none";
}

function changeTxtBoxValue(txtBox, newValue) {
    var me = document.getElementById(txtBox);
    me.value = newValue;
}


// Maximum word length
function checkWordLen(obj, wordLen) {
    var len = obj.value.split(/[\s]+/);
    if (len.length > wordLen) {
        obj.oldValue = obj.value != obj.oldValue ? obj.value : obj.oldValue;
        obj.value = obj.oldValue ? obj.oldValue : "";
        return false;
    }
    return true;
}
//Max character length
function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
}


function loactionRadiusCheck(location, radius, stdClass) {
    var loc = document.getElementById(location);
    var rad = document.getElementById(radius);

    if (loc.className == stdClass && loc.value != '' && rad.value == '') {
        if (rad.disabled == false)
            rad.value = '50';
    }

    if (loc.value == '')
        rad.value = '';

}

//round Corner Buttons
$(document).ready(function() {
    $('.btn').each(function() {
        var b = $(this);
        var tt = b.text() || b.val();
        if ($(':submit,:button', this)) {
            b = $('<a>').insertAfter(this).addClass(this.className).attr('id', this.id);
            $(this).remove();
        }
        b.text('').css({ cursor: 'pointer' }).prepend('<i></i>').append($('<span>').text(tt).append('<i></i><span></span>'));
    });
    $('.btna').each(function() {
        var b = $(this);
        var tt = b.text() || b.val();
        if ($(':submit,:button', this)) {
            b = $('<a>').insertAfter(this).addClass(this.className).attr('id', this.id);
            $(this).remove();
        }
        b.text('').css({ cursor: 'pointer' }).prepend('<i></i>').append($('<span>').text(tt).append('<i></i><span></span>'));
    });
});

function hideLoginError(errorPnl) {
    if (document.getElementById(errorPnl)) {
        document.getElementById(errorPnl).style.display = 'none';
    }
}

function showSearchingScreen() {
    $('.RG').slideUp("slow");
    var obj = $('#bodyRepeat')
    var oHeight = obj.height();
    var oWidth = obj.width();
    var searchingContent = "<div id='searchLoadingDiv' class='rgLoading' style='width:" + (oWidth - 2) + "px; height:" + oHeight + "px;'><div>Searching</div><br /><br /><img src='/i/loadingGrid.gif' alt='loading' /></div>"; ;
    obj.prepend(searchingContent).fadeIn('slow');
}

//function showSearchingScreen() {
//    $('.RG').slideUp("slow");
//    var obj = $('#bodyRepeat')
//    var oHeight = obj.height();
//    var oWidth = obj.width();
//    var obj1 = $('#searchLoadingDiv');
//    if (obj1.length == 0) {
//        var searchingContent = "<div id='searchLoadingDiv' class='rgLoading displayNone' style='width:" + (oWidth - 2) + "px; height:" + oHeight + "px;'><div>Searching</div><br /><br /><img src='/i/loadingGrid.gif' alt='loading' /></div>"; ;
//        obj.prepend(searchingContent);
//    }
//    //.fadeIn('slow')
//}



function validateSearchForm(txtFrom, lblFrom, strFromError, txtTo, lblTo, strToError, strToFromError, txtLocationRadius, lblLocationRadius, strLocRadError, txtLocation, strLocationError) {
    var Message = '';
    var star = '<span style="color:red;">*</span>'
    var fromLabel = $('#' + lblFrom + '');
    var toLabel = $('#' + lblTo + '');
    var distLabel = $('#' + lblLocationRadius + '');
    fromLabel.children().remove();
    toLabel.children().remove();
    distLabel.children().remove();
    
    var isFromInt = new Boolean(false);
    var isToInt = new Boolean(false);
    var From = document.getElementById(txtFrom).value;
    if (From != '') {
        if (!validateIsInt(From)) {
            Message += strFromError + '\n';
            fromLabel.append(star);
        }
        else {
            isFromInt = true;
        }
    }
    var To = document.getElementById(txtTo).value;
    if (To != '') {
        if (!validateIsPositiveInt(To)) {
            Message += strToError + '\n';
            toLabel.append(star);
        }
        else {
            isToInt = true;
        }
    }
    var LocationRadius = document.getElementById(txtLocationRadius).value;
    if (LocationRadius != '') {
        if (!validateIsPositiveInt(LocationRadius)) {
            Message += strLocRadError + '\n';
            distLabel.append(star);
        }
    }
    if (isFromInt == true && isToInt == true) {
        if (From >= To) {
            Message += strToFromError + '\n';
        }
    }
    
    var Location = document.getElementById(txtLocation).value;
    if (Location != '') {
        if (!SubmitSearchForm(txtLocation, 'StandardError', strLocationError)) {
            Message += strLocationError + '\n';
        }
    }
    
    if (Message != '') {
        var Message2 = 'Your search has the following error(s) \n';
        Message2 += Message
        alert(Message2);
        return false;
    }
    else {
        onclickClearFieldTempValues();
        setSearchButtonClick();
            return true;
        }
}

function validateIsPositiveInt(field) {
    PosIntpat = /^[1-9]+[0-9]*$/;
    if (!PosIntpat.test(field)) {
        return false;
    }
    return true;
}

function validateIsInt(field) {
    PosIntpat = /^\d+$/;
    if (!PosIntpat.test(field)) {
        return false;
    }
    return true;
}

//function validateSearchForm() {
//    var Message = '';
//    var star = '<span style="color:red;">*</span>'
//    var fromLabel = $('#ctl00_ctl00_ctl00_BH_SH_ScH_ucSC_lblFiltersEnumerationFrom');
//    var toLabel = $('#ctl00_ctl00_ctl00_BH_SH_ScH_ucSC_lblFiltersEnumerationTo');
//    var distLabel = $('#ctl00_ctl00_ctl00_BH_SH_ScH_ucSC_lblDistance');
//    fromLabel.children().remove();
//    toLabel.children().remove();
//    distLabel.children().remove();

//    var isFromInt = new Boolean(false);
//    var isToInt = new Boolean(false);
//    var From = document.getElementById('ctl00_ctl00_ctl00_BH_SH_ScH_ucSC_txtFiltersEnumerationFrom').value;
//    if (From != '') {
//        if (!validateIsInt(From)) {
//            Message += 'From \n';
//            fromLabel.append(star);
//        }
//        else {
//            isFromInt = true;
//        }
//    }
//    var To = document.getElementById('ctl00_ctl00_ctl00_BH_SH_ScH_ucSC_txtFiltersEnumerationTo').value;
//    if (To != '') {
//        if (!validateIsPositiveInt(To)) {
//            Message += 'To \n';
//            toLabel.append(star);
//        }
//        else {
//            isToInt = true;
//        }
//    }
//    var LocationRadius = document.getElementById('ctl00_ctl00_ctl00_BH_SH_ScH_ucSC_txtLocationRadius').value;
//    if (LocationRadius != '') {
//        if (!validateIsPositiveInt(LocationRadius)) {
//            Message += 'Location \n';
//            distLabel.append(star);
//        }
//    }
//    if (isFromInt == true && isToInt == true) {
//        if (From >= To) {
//            Message += 'ToFrom \n';
//        }
//    }
//    if (Message != '') {
//        var Message2 = 'Your search has the following error(s) \n';
//        Message2 += Message
//        alert(Message2);
//        return false;
//    }
//    else {
//        return true;
//    }
//}



var tooltip = function() {
    var id = 'tt';
    var top = 3;
    var left = 3;
    var maxw = 300;
    var speed = 10;
    var timer = 20;
    var endalpha = 95;
    var alpha = 0;
    var tt, t, c, b, h;
    var ie = document.all ? true : false;
    return {
        show: function(v, w) {
            if (tt == null) {
                tt = document.createElement('div');
                tt.setAttribute('id', id);
                t = document.createElement('div');
                t.setAttribute('id', id + 'top');
                c = document.createElement('div');
                c.setAttribute('id', id + 'cont');
                b = document.createElement('div');
                b.setAttribute('id', id + 'bot');
                tt.appendChild(t);
                tt.appendChild(c);
                tt.appendChild(b);
                document.body.appendChild(tt);
                tt.style.opacity = 0;
                tt.style.filter = 'alpha(opacity=0)';
                document.onmousemove = this.pos;
            }
            tt.style.display = 'block';
            c.innerHTML = v;
            tt.style.width = w ? w + 'px' : 'auto';
            if (!w && ie) {
                t.style.display = 'none';
                b.style.display = 'none';
                tt.style.width = tt.offsetWidth;
                t.style.display = 'block';
                b.style.display = 'block';
            }
            if (tt.offsetWidth > maxw) { tt.style.width = maxw + 'px' }
            h = parseInt(tt.offsetHeight) + top;
            clearInterval(tt.timer);
            tt.timer = setInterval(function() { tooltip.fade(1) }, timer);
        },
        pos: function(e) {
            var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
            var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
            tt.style.top = (u - h) + 'px';
            tt.style.left = (l + left) + 'px';
        },
        fade: function(d) {
            var a = alpha;
            if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
                var i = speed;
                if (endalpha - a < speed && d == 1) {
                    i = endalpha - a;
                } else if (alpha < speed && d == -1) {
                    i = a;
                }
                alpha = a + (i * d);
                tt.style.opacity = alpha * .01;
                tt.style.filter = 'alpha(opacity=' + alpha + ')';
            } else {
                clearInterval(tt.timer);
                if (d == -1) { tt.style.display = 'none' }
            }
        },
        hide: function() {
            clearInterval(tt.timer);
            tt.timer = setInterval(function() { tooltip.fade(-1) }, timer);
        }
    };
} ();


//function onActionHover() {
//    $('.ActionsMenuList').slideToggle("fast");
//    
//    //$('.ActionsMenuList').slideUp("fast");
//  }

//function onActionHover() {
//    $(".ActionsMenu").hover(function() {
//        $(".ActionsMenuList").slideToggle("slow");
//    });
//}




$(".ActionsMenu").live("hover", function() {
    $('.ActionsMenuList').slideToggle();
    }
);



