﻿function viewLarge(productid)
{
    window.open("EnlargePhoto.aspx?ProductID=" + productid, null, "height=700,width=955,location=no,menubar=no,statusbar=no,scrollbars=no,resizable=no,left=50,top=50");
}

function ajax_call(el,url, xmlparsercallback)
{
    var xmlHttp;
    try { xmlHttp=new XMLHttpRequest(); }
    catch (e)
    {
        try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e)
        { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
    }
  
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            xmlparsercallback(el,xmlHttp.responseXML);
        }
    }
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function okp_query(target,src,e)
{
    var ele = document.getElementById(target);
    if (src.value.length > 2)
        search(ele,src.value);
    else
        ele.style.display = "none";
        
    document.body.onclick = function(){ ele.style.display = "none"; }
    ele.onclick = function (e) { if (!e) var e = window.event; e.cancelBubble = true; if (e.stopPropagation) e.stopPropagation(); }
}

function hardSearch(rel,val)
{
    window.location.href = rel + "/Browse.aspx?Search=" + val;
}

function search(el,query)
{
    ajax_call(el,"Ajax.ashx?action=search&query=" + query, search_callback);
}

function search_callback(parent,xmlDoc)
{   
    var products = xmlDoc.getElementsByTagName("product");
    if (products.length == 0)
        parent.style.display = "none";
    else
        parent.style.display = "block";
        
    var el = parent.childNodes[1];
    el.innerHTML = "";
   
    for(var i = 0; i < products.length; i++)
    {
        var newDiv = document.createElement('div');
        newDiv.setAttribute("class", "item");
        newDiv.innerHTML = "<a href='View.aspx?SelectorID=" + products[i].childNodes[1].firstChild.nodeValue + "'>" + products[i].childNodes[0].firstChild.nodeValue + "<br><img src='ProductPhotos/Small/" + products[i].childNodes[2].firstChild.nodeValue + "' border='0' /></a>";
        el.appendChild(newDiv);
    }
}

function hideDiv(el)
{
    document.getElementById(el).style.display = "none";
}

function searchProds(control,partnum)
{
    var query = document.getElementById(control).value;
    internal_searchProds(query, partnum);
}

function internal_searchProds(query, partnum)
{
    window.location.href = "SearchResults.aspx?query=" + query;
}

function enterFix_searchKeyword(e)
{
	if (!e) var e = window.event;

    var code;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if (code == 13)
	{
        var targ;
	    if (e.target) targ = e.target;
	    else if (e.srcElement) targ = e.srcElement;
	    if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;
		    
        internal_searchProds(targ.value, false);
    }
}

function enterFix_searchPartNo(e)
{
	if (!e) var e = window.event;

    var code;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if (code == 13)
	{
        var targ;
	    if (e.target) targ = e.target;
	    else if (e.srcElement) targ = e.srcElement;
	    if (targ.nodeType == 3) // defeat Safari bug
		    targ = targ.parentNode;
		    
        internal_searchProds(targ.value, true);
    }
}