﻿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?ProductID=" + 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";
}