﻿var BaseURL;
var height, width;
//var browse, browse_MO, partsbreakdown, partsbreakdown_MO;
//var browseLG, browse_MOLG, partsbreakdownLG, partsbreakdown_MOLG, canadianpriceLG, canadianprice_MOLG;

if (document.images) {
//    browse = new Image(38, 24);
//    browse.src = "images/content/Browse.gif";
//    browse_MO = new Image(38, 24);
//    browse_MO.src = "images/content/Browse_MO.gif";

//    partsbreakdown = new Image(38, 34);
//    partsbreakdown.src = "images/content/Parts.gif";
//    partsbreakdown_MO = new Image(38, 34);
//    partsbreakdown_MO.src = "images/content/Parts_MO.gif";

//    //Large Images
//    browseLG = new Image(60, 60);
//    browseLG.src = "images/main/LG-btn-browse.jpg";
//    browse_MOLG = new Image(60, 60);
//    browse_MOLG.src = "images/main/LG-btn-browse_MO.jpg";

//    partsbreakdownLG = new Image(60, 60);
//    partsbreakdownLG.src = "images/main/LG-Btn-Parts.jpg";
//    partsbreakdown_MOLG = new Image(60, 60);
//    partsbreakdown_MOLG.src = "images/main/LG-Btn-Parts_MO.jpg";

//    canadianpriceLG = new Image(60, 60);
//    canadianpriceLG.src = "images/main/LG-Btn-CDNPrice.jpg";
//    canadianprice_MOLG = new Image(60, 60);
//    canadianprice_MOLG.src = "images/main/LG-Btn-CDNPrice_MO.jpg";
}

Init = function() {
    try {
        InitDisplay();
        
    } catch (e) {
        alert(e.description);
    }
}

MM_openBrWindow = function(theURL, winName, features) {
    window.open(theURL, winName, features);
}

MM_openSupportWindow = function(theURL) {
    window.open(theURL, 'New', 'width=350,height=445,scrollbars=yes');
}

MM_openSupportWindowUS = function(theURL) {
    window.open(theURL, 'New', 'width=625,height=650,scrollbars=yes');
}

SwapImage = function(imageID, imageID2) {
    document.getElementById(imageID).src = eval(imageID2 + ".src");
//    if (document.images) {
//        document.images[imageID].src = eval(imageID2 + ".src");
//    }
}

JumpToNewURL = function(zURL) {
    try {
        self.location.href = zURL;
        //window.location = zURL
    }
    catch (e) {
        document.clear
        document.location.href = zURL;
    }
}

checkEnter = function(evt) {
    var code;
    var objInputSearch;
    var NS4;

    NS4 = (document.layers) ? true : false;

    try {
        objInputSearch = document.getElementById("InputSearch");

        if (NS4) {
            code = evt.keyChar;
            alert(code);
        }
        else {
            code = evt.keyCode;
        }

        if (code == 13) {
            //alert(code);
            //JumpToNewURL(BaseURL + '?Page=Search&PartNum=' + Search.value);
            if (objInputSearch.value != "") {
                JumpToNewURL(BaseURL + '?Page=Search&PartNum=' + objInputSearch.value); //BaseURL + '?Page=Search&PartNum=' + objInputSearch.value);
            }
        }
    }
    catch (e) {
        alert("Error=" + e.message);
    }
}

SearchArrowClick = function() {
    var objInputSearch;

    try {
        objInputSearch = document.getElementById("InputSearch");
        JumpToNewURL(BaseURL + '?Page=Search&PartNum=' + objInputSearch.value);
    }
    catch (e) {
        //alert("Search.value=" + Search.value);
        alert("Search Arrow Click e.description=" + e.message);
    }
}

ResizeDocument = function() {
    var viewportHeight;
    var headerHeight;
    var footerHeight;

    headerHeight = 34;
    footerHeight = 20;

    if (typeof window.innerWidth != 'undefined') {
        viewportheight = window.innerHeight
    }
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportheight = document.documentElement.clientHeight
    }
    else {
        viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }

    if (document.getElementById('Header') != null) {
        $('#ContentBox').height(viewportHeight - (headerHeight + footerHeight));
    }
}


function searchFocus() {
    searchFocusCode('#InputSearch');
    searchFocusCode('#ctl00_InputSearch');
}

function searchFocusCode(searchBoxId) {
    var searchBox = jQuery(searchBoxId);
    searchBox.css('color', '#666');
    var searchValue = searchBox.attr('value'); 
    searchBox.blur(function() {
        searchValue = searchBox.attr('value');
        searchHasValue(searchValue) == true ? jQuery(this).css('color', '#fff') : jQuery(this).attr('value', 'search').css('color', '#666');
    });
    searchBox.focus(function() {
        searchValue = searchBox.attr('value');
        searchHasValue(searchValue) == false ? jQuery(this).attr('value', '').css('color', '#fff') : jQuery(this).css('color', '#fff');
    });
}

function searchHasValue(myValue) {
    if (myValue == "" || myValue == "SEARCH" || myValue == "search") {
        return false;
    } else {
        return true;
    };
}

$(document).ready(function() {
    searchFocus();
})

