﻿
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";
            var userAgentString = navigator.userAgent.toString();
            
            if (userAgentString.indexOf("MSIE 6.0") != -1) {
                document.getElementById("ContentBody").style.width = "884px";
            }
            if ((userAgentString.indexOf("MSIE 6.0") != -1) || (userAgentString.indexOf("MSIE 7.0") != -1)){
                document.getElementById("ContentLeft").style.display = "none";
            }
            
        }
    }
    catch (err) { }
    //END FUCNTIONS SHOW/HIDE RIGHT NAV MENU-------------------------------------------------------


    //SETS CONTENT DIV'S HEIGHT SO IT WILL ADJUST TO DIFFERENT 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; });
});


function SwapImgIn(obj) { obj.src = obj.getAttribute("HoverSrc") }
function SwapImgOut(obj) { obj.src = obj.src.replace("_hover", ""); }

function swapImageIn(element) {
    var src = element.src;
    var lastSlash = src.lastIndexOf("/");
    if (lastSlash === -1) {
        lastSlash = 0;
    }

    var formatStart = src.lastIndexOf(".");
    if (formatStart === -1) {
        return;
    }

    var newElementSrc = src.substring(lastSlash, formatStart) + "_hover";
    element.src = src.replace(src.substring(lastSlash, formatStart), newElementSrc);
}

function swapImageOut(element) {
    var src = element.src;
    var hoverStartIndex = src.lastIndexOf("_hover");

    if (hoverStartIndex === -1) {
        return;
    }

    src = src.replace("_hover", "");
    element.src = src;
}

function loadBlogWindow(updateTargetId) {
    $.ajax({
        url: "/Home/BlogItems",
        type: "GET",
        dataType: "html",
        success: function(msg) {
            updateTargetInnerHtml(msg, updateTargetId);
        },
        error: function(msg) {
            return false;
        }
    });
}

function updateTargetInnerHtml(html, id) {
    $("#" + id).empty();
    $("#" + id).append(html);
}

/*************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 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) { }
}

