if (document.getElementById("noMatchData")) { document.getElementById("noMatchData").style.display = "block"; }

function checkEnter() {
    if (document.all) {
        if (event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
            //document.getElementById("btnGo").click();
        }
    }
}

function load_bodySearch() {
    resizeImages();
    loadSearch();
    highLightSearch();
}
function expand() {
    HideTheBox();
    document.getElementById("pnlClickResults").className = "clsHide";
    document.getElementById("pnlResultheader").className = "clsHide";
    document.getElementById("lblInstructions2").className = "clsHide";
    document.getElementById("pnlReadMore").className = "pnlReadMoreShow";
    document.getElementById("<%=txtUserInput.ClientID%>").value = "Enter your search here";
    document.getElementById("<%=txtUserInput.ClientID%>").select();
}

function contract() {
    HideTheBox();
    document.getElementById("pnlReadMore").className = "clsHide";
    document.getElementById("lblInstructions2").className = "lblReadMore";
    document.getElementById("<%=txtUserInput.ClientID%>").value = "Enter your search here";
    document.getElementById("<%=txtUserInput.ClientID%>").select();
}

function doGo() {
    HideTheBox();
    document.getElementById(varPrefix + "pnlImage").className = "clsHide";

    document.getElementById("noMatchData").style.display = "none";  // these 2 are in HideTheBox(), but they
    document.getElementById("spanOutput").style.display = "none";  // are showing up anyway.

    document.getElementById(varPrefix + "hdnGo").value = "go";
    //document.MainForm.submit();
    //document.getElementById("txtUserInput").value = "";
}

function goTo() {
    var sURL = "/apps/questions/default.aspx?Type=6&Title=Search%20Help%20Request&Subject=Searching%20For%3A%20" + document.getElementById("hdnURL").value;
    //doLog("goTo: " + sURL);
    window.location = sURL;
}



function highLightSearch() {
    if (document.all) {
        document.getElementById(varPrefix + "txtUserInput").select();
    }
    
}

function resizeImages() {
    for (var i = 0; i < document.images.length; i++) {
        var name = document.images[i].name;
        if (name.length > 8 && name.substring(0, 8).toLowerCase() == "srchprod") {
            var width = document.images[i].width;
            var height = document.images[i].height;

            if (width >= height && width > 100) {
                //alert("resize width");
                document.images[i].width = 100;
            }

            else if (height > width && height > 100) {
                //alert("resize height");
                document.images[i].height = 100;
            }
        }
    }
    document.getElementById(varPrefix + "txtUserInput").focus();
}

function doHilite(ctrl) {
    //toggles between:
    //search_r1_c1.gif
    //search_r1_c1_f2.gif
    var sUrl = ctrl.src;
    var sNoExt = sUrl.substring(0, sUrl.length - 4)
    var sRight = sUrl.substring(sNoExt.length - 3, sNoExt.length);
    if (sRight == "_f2") {
        sUrl = sNoExt.substring(0, sNoExt.length - 3) + ".gif";
    }
    else {
        sUrl = sNoExt + "_f2.gif";
    }
    ctrl.src = sUrl;
}

function changePic(ctrl) {
    var sUrl = ctrl.src;
    var sImg = sUrl.substring(sUrl.length - 5, sUrl.length);
    if (sImg == "1.gif") {
        ctrl.src = "/siteimages/buttons/cantfind_2.gif";
    }
    else {
        ctrl.src = "/siteimages/buttons/cantfind_1.gif";
    }
}

//start image resizing. 

var sTheURL;
var iImgWidth;
var iImgHeight;

function ShowUp(img, isTrue) {
    //doLog("ShowUp");
}
function showPic(sURL, ctrl) {
    ctrl.style.backgroundColor = "#D2E4FC";
    //ctrl.style.cursor="hand";
    ShowThisPic(sURL);

}
function ShowThisPic(sURL) {
    var ImgControl = document.getElementById("ctl00_ContentPlaceHolder1_imgClick");
    ImgControl.className = "clsHide";
    //alert(document.getElementById("ctl00_ContentPlaceHolder1_imgClick"));

    if (sURL != "") {
        img = new Image();
        img.id = "imgTest";
        sTheURL = sURL;

        //img.onload Needed for firefox, but not ie:  http://www.codingforums.com/showthread.php?t=76568
        var somethingIsTrue = true;
        img.onload = (function(bool) {
            return function() { ShowUp(this, bool); }
        })(somethingIsTrue);

        //alert(sURL);    


        img.src = sTheURL;
        iImgWidth = img.width;
        iImgHeight = img.height;
        imgResize();
        var ImgControl = document.getElementById("ctl00_ContentPlaceHolder1_imgClick");
        ImgControl.src = sTheURL;
        ImgControl.width = iImgWidth;
        ImgControl.height = iImgHeight;
        ImgControl.className = "clsShow";
    }
}









function imgResize() {
    //doLog("imgResize");
    if (iImgWidth > 110) {
        var iProportion = iImgHeight / iImgWidth;
        iImgWidth = 110;
        iImgHeight = iProportion * iImgWidth;
    }
    if (iImgHeight > 125) {
        var iProportion = iImgHeight / iImgWidth;
        iImgHeight = 125;
        iImgWidth = iImgHeight / iProportion;
    }
}

//end image resizing. 

function hidePic(ctrl) {
    ctrl.style.backgroundColor = "white";
    ctrl.style.cursor = "pointer";
}

function doInstructions(sCase) {
		var host = window.location.host;
		document.domain = host;
    var s;
    switch (sCase) {
        case "ProductSearch":
            s = "You can search by product description, or catalog number by simply entering a word. " +
			"As you type, results will begin to display after your third typed in character. Your typed in " +
			"characters will be highlighted so that you can easily spot them. Scroll through the listing " +
			"with the up and down arrows, or by moving your mouse over each listed item without clicking. " +
			"While doing this you will see a small image of that highlighted item. If you see the item you " +
			"are looking for, click on it and you will go straight to that page.<br><br> " +
			"If you cannot locate something that closely matches what you are searching for,click the Search " +
			"button so that the words you typed in are actual fed through a total site search.<br><br>" +
			"If any search you do doesn't return the results you are looking for, you can even send us a note " +
			"by clicking on Contact Us or on the button located to the right.&nbsp;&nbsp;&nbsp";
            document.getElementById("lblReadInstructions").innerHTML = s;
            expand();
            break;

        case "AZIndex":
            window.location = "/apps/index_classic/azindex.aspx";
            break;

        case "MSDS":
            s = "By simply entering the CRL Catalog Number or beginning of the Catalog Number results will " +
			"begin to display. If there are related documents or drawings for that Catalog Number, there " +
			"will be a link that says 'View Additional Documentation that is Available for This Product.' Click " +
			"on this link to view what is available.&nbsp;&nbsp;&nbsp";
            window.location = "/apps/MSDS/MSDS_search.aspx";
            break;
            break;

        case "ViewCatalog":
            window.location = "/apps/contentloader/default.aspx?content=" + host + "/adv/cataloglibrary/index.html";
            break;
        case "TruckSliders":
            window.location = "/apps/slider/default.aspx";
            break;
        case "Charts":
            window.location = "/apps/contentloader/default.aspx?content=" + host + "/adv/allsearch/charts_us.html";
            break;
    } //switch
}

function doAction(sAction) {
    document.getElementById("hdnAction").value = sAction;
    document.MainForm.submit()
}
	