﻿function trackEvent(eventName, detail) {
    try {
        pageTracker._trackEvent(eventName, detail)
    }
    catch (e) { }
}

function StandardButtonClicked_Back() {
    trackEvent("StandardButtonClicked", "Back");
    Qww.Button.Mgr.CallStandardAction(null, 'BCK', true);
};

function StandardButtonClicked_Forward() {
    trackEvent("StandardButtonClicked", "Fwd");
    Qww.Button.Mgr.CallStandardAction(null, 'FWD', true);
};

function StandardButtonClicked_Clear() {
    trackEvent("StandardButtonClicked", "Clear");
    Qww.Button.Mgr.CallStandardAction(null, 'CA', true);
};


function openAffiliateLink(url, id) {

    trackEvent("ProductClicked", id);
    //window.open("Redirect.aspx?url=" + url, '', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=500,height=500,left = 390,top = 150', false);
    window.open(url);    
}

function getResultsSummary(numberOfMatchedProducts, totalNumberOfProducts, maxNumberOfProductsToDisplay)
{
    //alert(numberOfMatchedProducts + ", " + totalNumberOfProducts + ", " + maxNumberOfProductsToDisplay);
    
    var itemsString = "Items";
           
    if(numberOfMatchedProducts == 1)
    {
        itemsString = "Item";
    }

    var res = "";
    
    if(maxNumberOfProductsToDisplay >= numberOfMatchedProducts)
    {
        res = "Matched " + numberOfMatchedProducts + " " + itemsString + ".";
    }
    else
    {
        res = "Matched " + numberOfMatchedProducts + " " + itemsString + " (" + maxNumberOfProductsToDisplay + " shown).";
        
        //res += " Please refine your search further."
    }
    
    return res;
}



function onRenderRecord(flexiGrid, record, numberOfResults)
{
    var cells = record.Cells;

    var img = cells[4].Text;

    if (numberOfResults > 2) {
        img = img.replace("220x308", "110x154")
        img = "<img border='0' style='width:110px;height:154px' src='" + img + "' />";
    }
    else {
        img = "<img border='0' src='" + img + "' />";
    }
    
    var div = document.createElement("div");
    
    div.setAttribute("style", "border:solid 1px #bf1616;padding:3px 3px 3px 3px; width:110px;height:154px; cursor:pointer");
    div.className = "productTile";
    
//    div.onclick = function()
//    {
//        flexiGrid.SelectSingleRecord(record.RecordNumber);
//    };

    div.onclick = function()
    {
        openAffiliateLink(cells[6].Text, cells[0].Text);
    }

    var largeImage = cells[4].Text;
    var productName = cells[1].Text;
    var desc = cells[3].Text;
    var rating = 'No ratings'; //cells[9].Text;
    var price = cells[5].Text; //'Price not here'; //cells[7].Text;
    var brand = cells[2].Text;
    
    div.onmouseover = function(){showtrail(largeImage, brand, productName, desc, rating, price, 200);};
    div.onmouseout = function(){hidetrail();};
    div.innerHTML = img;
    
    var obj = {Element: div};
    
    return obj;
};

