﻿
var closePanel;
var headerNavSelected;
var leftActive;

$(document).ready(function() {

    //FUNCTIONS SHOW/HIDE RIGHT NAV MENU------------------------------------------------------
    try {
        if (closePanel != null)
        { document.getElementById("ContentBody").style.width = "865px"; }
    } catch (err) { }
    //END FUCNTIONS SHOW/HIDE RIGHT NAV MENU-------------------------------------------------------


    //SETS CONTENT DIV'S HEIGHT SO IT WILL ADJUST TO DIFFERETN CONTENT CORRECTLY
    SetPageHeight();

    //FUNCTIONS SHOW/HIDE LOGIN MENU----------------------------------------------------
    var loginToggel = 0;
    $("#HrefShowLogin").click(function() {
        if (loginToggel == 0) {
            $("#LoginNavDropDownPosition").slideDown("slow");
            loginToggel = 1;
        }
        else {
            $("#LoginNavDropDownPosition").slideUp("slow");
            loginToggel = 0;
        }
    });

    $("#LoginCloseX").click(function() { $("#LoginNavDropDownPosition").slideUp("slow"); loginToggel = 0; });

    //END FUNCTIONS SHOW/HIDE LOGIN MENU FUNCTIONS------------------------------------------------------

    //FUNCTION SET THE ACTIVE SECTION BACKGROUND COLOR
    try {
        if (leftActive != null) {
            var control = document.getElementById(leftActive);
            if (control != null) {
                control.className = "activeSec";
            }
        }
    } catch (err) { }



    //SET HEADER NAV SELECTED STYLE headerNavSelected COMES FROM ApplicationControler SET IN NavigationManager
    try {
        if (headerNavSelected != null) {
            document.getElementById(headerNavSelected).className = "active";
        } else {
            //LOOP TO REMOVE STYLE CLASS
            var liArray = document.getElementById("HeaderLinkList").getElementsByTagName("li");
            for (var i = 0; i < liArray.length; i++)
            { liArray[i].className = ""; }
        }
    } catch (err) { }


    //SET Global Search Watermark Text and Style.
    try {
        //        document.getElementById('GlobalSearch').value = 'Enter your product here';
        //        document.getElementById('GlobalSearch').style.color = '#646464';
        //        document.getElementById('GlobalSearch').style.backgroundColor = '#f5f5f5';
        //   
    } catch (err) { }



});


function SwapImgIn(obj) { obj.src = obj.getAttribute("HoverSrc") }
function SwapImgOut(obj) { obj.src = obj.src.replace("_hover", ""); }


/*************Checkboxes***************/
function CheckAllCheckboxes(elementID) {
    $("#" + elementID + " :checkbox").each(function() {
        $(this).attr("checked", true);
    });
};

function CheckAllCheckboxesUncheck(elementID, additionalElement) {
    CheckAllCheckboxes(elementID);

    $("#" + additionalElement).attr("checked", false);
}

function CheckAllCheckboxesWithPositiveValueUncheck(elementID, additionalElement) {
    CheckAllCheckboxesWithPositiveValue(elementID);

    $("#" + additionalElement).attr("checked", false);
}

function CheckAllCheckboxesWithPositiveValue(elementID) {
    $("#" + elementID + " :checkbox").each(function() {
        if ($(this).attr('id') < 0) {
            $(this).attr("checked", false);
        }
        else {
            $(this).attr("checked", true);
        }
    });
}

function ClearAllContainedCheckboxes(elementID) {
    $("#" + elementID + " :checkbox").each(function() {
        $(this).attr("checked", false);
    });
};

function ClearAllCheckboxes(elementID) {
    $("#" + elementID + " :checkbox").each(function() {
        $(this).attr("checked", false);
    });
};

function CheckAllClearAllCheckboxes(elementID, masterCheckbox) {
    $("#" + elementID + " :checkbox").each(function() {
        $(this).attr("checked", $("#" + masterCheckbox).is(":checked"));
    });
};

function ClearAllCheckboxes(elementID, masterCheckbox) {
    if ($("#" + masterCheckbox).attr("checked") == true) {
        $("#" + elementID + " :checkbox").each(function() {
            $(this).attr("checked", false);
        });
        $("#" + masterCheckbox).attr("checked", true);
    }
};

function ClearAllSubCheckboxes(elementID, masterCheckbox, subMasterCheckbox) {
    if ($("#" + subMasterCheckbox).attr("checked") == true) {
        $("#" + elementID + " :checkbox").each(function() {
            $(this).attr("checked", false);
        });
        $("#" + masterCheckbox).attr("checked", false);
        $("#" + subMasterCheckbox).attr("checked", true);
    }
};

function ClearMasterCheckbox(instanceCheckbox, masterCheckbox) {
    if (instanceCheckbox["checked"] == true) {
        $("#" + masterCheckbox).attr("checked", false);
    }
};

function ClearMasterAndSubMasterCheckbox(instanceCheckbox, masterCheckbox, subMasterCheckbox) {
    if (instanceCheckbox["checked"] == true) {
        $("#" + masterCheckbox).attr("checked", false);
        $("#" + subMasterCheckbox).attr("checked", false);
    }
};

function requiredFieldValidator(targetTextBox, errorMessageTarget) {

    if (targetTextBox == null)
        return false;

    var str = targetTextBox.value;
    str = jQuery.trim(str);

    var isValid = (str.length > 0);

    if (isValid)
        errorMessageTarget.style.display = "none";
    else
        errorMessageTarget.style.display = "block";

    return isValid;
}

function ToggleVisibility(controlID) {
    $("#" + controlID.toString()).toggle();
    SetPageHeight();
};

var currentTabList = "TechnologiesList";
function BrowseTabChanged(tabListName) {
    currentTabList = tabListName;
}

function DoFilter(letter, linkClicked) {
    var liTags = $("#" + currentTabList + " div a");

    if (letter == "#") {
        for (i = 0; i < liTags.length; i++) {
            var tag = liTags[i];
            if ($(tag).text().startsWith("0") || $(tag).text().startsWith("1") || $(tag).text().startsWith("2") || $(tag).text().startsWith("3") || $(tag).text().startsWith("4") || $(tag).text().startsWith("5") || $(tag).text().startsWith("6") || $(tag).text().startsWith("7") || $(tag).text().startsWith("8") || $(tag).text().startsWith("9")) {
                tag.parentNode.style.display = "block";
            }
            else {
                tag.parentNode.style.display = "none";
            }
        }
    }
    else if (letter.toUpperCase() == "ALL") {
        for (i = 0; i < liTags.length; i++) {
            liTags[i].parentNode.style.display = "block";
        }
    }
    else {
        for (i = 0; i < liTags.length; i++) {
            var tag = liTags[i];
            if ($(tag).text().toUpperCase().startsWith(letter.toUpperCase())) {
                tag.parentNode.style.display = "block";
            }
            else {
                tag.parentNode.style.display = "none";
            }

        }
    }
}

function openFeedback(serviceCode) {
    var w = 1024, h = 768;
    w = document.body.clientWidth;
    h = document.body.clientHeight;
    var popW = 350, popH = 400;
    var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;
    feedbackwindow = window.open("/Members/Feedback/" + serviceCode, "feedbackwindow", "width=350, height=400, scrollbars=0, menubar=0,toolbar=0, top=" + topPos + ", left=" + leftPos); //, "width=350, height=200, scrollbars=0, menubar=0,toolbar=0", ""
}

function SetPageHeight() {
    try {
        if (document.getElementById("ContentWrap").offsetHeight < document.getElementById("ContentBody").offsetHeight) {
            if (navigator.appName == 'Microsoft Internet Explorer') {
                document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 40) + "px";
            } else {
                document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 22) + "px";
            }
        }
    } catch (err) { }
}


function SetPageRenderHeight() {
    try {
        if (document.getElementById("ContentWrap").offsetHeight < document.getElementById("ContentBody").offsetHeight) {
            if (navigator.appName == 'Microsoft Internet Explorer') {
                document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 40) + "px";
            } else {
                document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 22) + "px";
            }
        }
    } catch (err) { }
}

//function SetPageRenderHeight() {
//    try {
//        if (navigator.appName == 'Microsoft Internet Explorer') {
//            document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 40) + "px";
//        }
//        else {
//            document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 22) + "px";
//        }

//    } catch (err) { }
//}


function adjustHeightMI(offsetValue) {

    try {
        if (navigator.appName == 'Microsoft Internet Explorer') {
            if (document.getElementById("ContentBody").offsetHeight >= 720)
            { document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + 30 + offsetValue) + "px"; }
            else
            { document.getElementById("ContentWrap").style.height = "720px"; }
        } else {
            if (document.getElementById("ContentBody").offsetHeight <= 721)
            { document.getElementById("ContentWrap").style.height = "720px"; }
            else {
                offsetValue = 25;
                //alert(document.getElementById("ContentBody").offsetHeight);
                //alert(offsetValue);

                document.getElementById("ContentWrap").style.height = (document.getElementById("ContentBody").offsetHeight + offsetValue) + "px";
                //alert(document.getElementById("ContentWrap").style.height);
            }
        }
    } catch (err) { }
}
