var XmlHttpRequestInstance = false;
var XmlHttpRequestResponseHandlerFunction = "";

function SendXMLHttpRequest(URL,ResponseHandlerFunction)
{   
    ////////////////////////////////
    XmlHttpRequestResponseHandlerFunction = ResponseHandlerFunction;
    try
    {
        this.XmlHttpRequestInstance = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
            try
            {
                XmlHttpRequestInstance = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(E)
            {
                XmlHttpRequestInstance = false;
            }
    }
    if(!XmlHttpRequestInstance && typeof XMLHttpRequest!='undefined')
    {
        XmlHttpRequestInstance = new XMLHttpRequest();
    }
    if (!XmlHttpRequestInstance && window.createRequest)
    {
	    try
	    {
		    XmlHttpRequestInstance = window.createRequest();
	    }
	    catch(e)
	    {
		    XmlHttpRequestInstance=false;
	    }
	 } 
	///////////////////////////////
    if(XmlHttpRequestInstance)
    {
        XmlHttpRequestInstance.open("GET",URL,false);
        XmlHttpRequestInstance.onreadystatechange = ReceiveXMLHttpResponse;
        XmlHttpRequestInstance.send("");
    }
    else
    {
        alert("Can Not Initiate HTTP Request.");
    }
    ////////////////////////////////
}

function ReceiveXMLHttpResponse(ResponseHandlerFunction)
{
    if (XmlHttpRequestInstance.readyState==4)
    {
        if (XmlHttpRequestInstance.status==200)
        {
            //eval(XmlHttpRequestResponseHandlerFunction + "('123')");
            eval(XmlHttpRequestResponseHandlerFunction + "('" + XmlHttpRequestInstance.responseText + "')");
        }
        else
        {
            alert("Bad HTTP Request");
        }
    }
}


// JScript File

var BaseEQuotePublicSearchCategoryURL = "../equote/XMLHttpRequestCategory.aspx";
        
SendXMLHttpRequest(BaseEQuotePublicSearchCategoryURL+"?ParentCategoryID=1",'PopulateParentCategory');

function PopulateParentCategory(ResponseString)
{
   var CategoryArray = new Array();
   var count;
   var i=0;
   var j=1;
   var objSel = document.getElementById('EQuotePublicSearchParentCategory'); 
   objSel.options.length=0;
   CategoryArray = ResponseString.split("||||");
   count = CategoryArray.length; 
   objSel.options[0]=new Option("All Categories", "-1", false, false);
   while(i<count)
   {
        if(CategoryArray[i]!=null)
        {
            if(CategoryArray[i].toString().length>0)
            {
                name = CategoryArray[i].toString().split("|||")[0].toString();
                value = CategoryArray[i].toString().split("|||")[1].toString();
                objSel.options[j]=new Option(name, value, false, false);
                j=j+1;
            }
        }
        i=i+1;
   }
}

function PopulateChildCategory(ResponseString)
{
   var CategoryArray = new Array();
   var count;
   var i=0;
   var j=1;
   var objSel = document.getElementById('EQuotePublicSearchChildCategory'); 
   objSel.options.length=0;
   CategoryArray = ResponseString.split("||||");
   count = CategoryArray.length; 
   objSel.options[0]=new Option("All Categories", "-1", false, false);
   while(i<count)
   {
        if(CategoryArray[i]!=null)
        {
            if(CategoryArray[i].toString().length>0)
            {
                name = CategoryArray[i].toString().split("|||")[0].toString();
                value = CategoryArray[i].toString().split("|||")[1].toString();
                objSel.options[j]=new Option(name, value, false, false);
                j=j+1;
            }
        }
        i=i+1;
   }
}

function EQuotePublicSearchParentCategoryChange()
{
    var objSel = document.getElementById('EQuotePublicSearchParentCategory');
    var URL = BaseEQuotePublicSearchCategoryURL + "?ParentCategoryID=" + objSel.options[objSel.selectedIndex].value;
    SendXMLHttpRequest(URL,'PopulateChildCategory');
}

function EQuotePublicSearchImageClick()
{
    var ParentCategory = 1;
    var KeyWord = "";
    var objSel = document.getElementById('EQuotePublicSearchChildCategory');

    //if(document.getElementById('EQuotePublicSearchParentCategory').value ==-1 & document.getElementById('EQuotePublicSearchChildCategory').value ==-1)
    //{
    //    alert("Please select a category to search.");
    //    return;
    //}


    if(objSel.options[objSel.selectedIndex].value>0)
    {
        ParentCategory = objSel.options[objSel.selectedIndex].value;
    }
    else
    {
        objSel = document.getElementById('EQuotePublicSearchParentCategory');
        if(objSel.options[objSel.selectedIndex].value>0)
        {
            ParentCategory = objSel.options[objSel.selectedIndex].value;
        }
    }
    KeyWord = document.getElementById('EQuotePublicSearchKeyword').value;
    document.location.href = "../EQuote/CategoryProductSearch.aspx?ParentCategory=" + ParentCategory + "&KeyWord=" + KeyWord;
}





