//use to add any custom javascripts to this site
//function: set height of left nav using jquery
function setHeight() {

    if (document.getElementById("discoverContent")) {

        var height = $("#discoverContent").height();

        if (height > 240) {
            $("#featuredContent").css("height", height + "px");
        }
    }

    if (document.getElementById("innerContentHolder")) {

        var height = $("#innerContentHolder").height();

        if (height > 100) {
            /*
            the next if statement checks to see if it's a landing page or inner page and 
            then sets the hight accordingly
            */
            if (document.getElementById("landingPagesHdr")) {
                var imgdivHeight = $("#landingPagesHdr").height();
                //height of the page - the height of the landing pages image
                var innerheight = height - imgdivHeight;

                $("#middleColumn").css("height", innerheight + "px");
                $(".singleRightColumn").css("height", innerheight + "px");
            }
            else {
                //alert("HI");
                $("#middleColumn").css("height", height + "px");
                $(".singleRightColumn").css("height", height + "px");
            }
            //alert(height);
            //left navigation only
            var menuHdrHeight = $("#ctl00_ucSubNav_leftNavHdr").height();
            var leftNavHeight = height - menuHdrHeight;
            $("#leftNav").css("height", leftNavHeight + "px");
        }
    }

    if (document.getElementById("smallCCholder")) {

        var height = $("#smallCCholder").height();
        //alert(height);
        $(".smallContentColumn").css("height", height + "px");
        
    }
}


// function: add png class for PNG images
function addPNGfix() {
    //alert("images # " + document.images.length);
    for (i = 0; i < document.images.length; i++) {
        //get image extension
        imgSrc = document.images[i].src
        //alert(imgSrc)
        arrParts = imgSrc.split(".")
        ext = arrParts[arrParts.length - 1].toLowerCase()

        //if image is a PNG
        if (ext == "png") {
            //alert(ext);
            //if button is a png
            $(document.images[i]).addClass("png");
        }
    }
}

function init() {

    setHeight(); //set height of leftnav
    addPNGfix(); //add PNG fix
}
window.onload = init;

/////////////////////////////////////////////////////////////
// the following three functions are used as default functions
// for setting over and out mouseover states for top nav
/////////////////////////////////////////////////////////////
    function menuOver(img) {
        //get file type
        strFileType = getFileType(img.src)
        if (img.src.indexOf("On." + strFileType) == -1) {
            img.src = img.src.replace("." + strFileType, "Over." + strFileType)
        }
    }
    function menuOut(img) {
        //get file type
        strFileType = getFileType(img.src)
        if (img.src.indexOf("Over." + strFileType) != -1) {
            img.src = img.src.replace("Over." + strFileType, "." + strFileType)
        }
    }

    function getFileType(strFileName){
        strFileType = ""
        arrParts = strFileName.split(".")
        strFileType = arrParts[arrParts.length-1]
        return strFileType
       
    }

/////////////////////////////////////////////////////////////
// END
/////////////////////////////////////////////////////////////

    // function: to clear text fields (generic)
    function clearField(e) {
        if (e.defaultValue == e.value) {
            e.value = '';
        }
        else if (e.value == '') {
            e.value = e.defaultValue;
        }
    }
    
function forceClick(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {
      
        searchSite();
        return false;
    }

    return true;
}

function forceClickF(e, elemId) {
    var elem = document.getElementById(elemId);
    var evt = (e) ? e : window.event;
    var intKey = (evt.which) ? evt.which : evt.keyCode;

    if (intKey == 13) {

        searchSite404();
        return false;
    }

    return true;
}

function searchSite() {
    
    if (document.getElementById("siteSearchBox")){
        if (document.getElementById("siteSearchBox").value != ""){
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBox").value) + "&ustype=0"
        }
    }
}
function searchSite404() {

    if (document.getElementById("siteSearchBoxF")) {
        if (document.getElementById("siteSearchBoxF").value != "") {
            location.href = "/Search.aspx?usterms=" + escape(document.getElementById("siteSearchBoxF").value) + "&ustype=0"
        }
    }
}
