﻿// JScript File

// search
function ShopperSearch(url, queryId, categId, retailerId)
{                        
    var strParams = "";
    
    var queryObj = document.getElementById(queryId);
    if (queryObj != null && queryObj.value != "")
    {
        strParams += "&userquery=" + escape(queryObj.value);





    }
    
    var categObj = document.getElementById(categId);    
    if (categObj != null && categObj.value != "0")
    {
        strParams += "&cid=" + categObj.value;
    }
    
    var retailerObj = document.getElementById(retailerId);
    if (retailerObj != null && retailerObj.value != "0")
    {
        strParams += "&advid=" + retailerObj.value;
    }
        
    if (theForm != null && theForm != undefined)
    {        
        theForm.action = url + strParams;
        theForm.submit();
    }
}

var sid = null;
function ShopperCategoryChange(url, catId, advId, queryId, shopperId)
{
    sid = shopperId;
    var catDropDown = document.getElementById(catId);
    if (catDropDown != null)
    {       
        var cid = catDropDown.options[catDropDown.selectedIndex].value;
        url += "&cid=" + cid;
        
        var advDropDown = document.getElementById(advId);
        if (advDropDown != null)
        {
            url += "&advid=" + advDropDown.options[advDropDown.selectedIndex].value;            
        }
        
        var queryObj = document.getElementById(queryId);
        if (queryObj != null && queryObj.value != "")
        {
            url += "&userquery=" + escape(queryObj.value);





        }
        
        var req = new Request();
        req.Send(url, OnCategoryChanged);
    }
}

function OnCategoryChanged(data)
{
    var shopper = document.getElementById(sid);
    if (shopper != null)
    {
        if (shopper.outerHTML == undefined)
        {
            // firefox
            var r = shopper.ownerDocument.createRange();
            r.setStartBefore(shopper);
            var df = r.createContextualFragment(data);
            shopper.parentNode.replaceChild(df, shopper);
        }
        else
        {
            shopper.outerHTML = data;
        }
    }    
}

// browse
function ShopperBrowseByCategory(url, dropDownId)
{
    var dropDown = document.getElementById(dropDownId);
    
    if (dropDown != null)
    {
        if (dropDown.selectedIndex == 0)
        {
            return;
        }
        var strParams = "";    
        strParams += "&cid=" + dropDown.options[dropDown.selectedIndex].value;
        window.location.href = url + strParams;
    }        
}

function ShopperBrowseByAdvertiser(url, dropDownId)
{
    var dropDown = document.getElementById(dropDownId);
    
    if (dropDown != null)
    {
        if (dropDown.selectedIndex == 0)
        {
            return;
        }
        var strParams = "";    
        strParams += "&advid=" + dropDown.options[dropDown.selectedIndex].value;
        window.location.href = url + strParams;
    }        
}

