﻿function CNSetHomePage(useCurrentPage)
{
   document.body.style.behavior='url(#default#homepage)';
   
   if (useCurrentPage)
		document.body.setHomePage(window.location.href);
	else
		document.body.setHomePage("http://www.stylefinder.com?bookmark=true");
}

function ImageMouseOver(ElementType, linkid, imageid, image)
{
    //unselect all links
    var LinkCollection = new Array();

    LinkCollection = document.getElementById(ElementType).getElementsByTagName("a");
    
    for (var i = 0; i < LinkCollection.length; i++)
    {
        LinkCollection[i].className = "LinkUnSelected";
    }    
    
    //select new link
    document.getElementById(imageid).src = image;
    document.getElementById(linkid).className = "LinkSelected";
}
/*Search bar*/
function SearchBar_GetSearchString (ItemID, ColourID, ShopID)
{
    //get selected values from dropdowns
    var Item = CNDropDownGetSelectedValue(ItemID);
    var Colour = CNDropDownGetSelectedValue(ColourID);
    var Shop = CNDropDownGetSelectedValue(ShopID);
    
    //build query
    var separator = '?'
    var link = "/search/"
    if (Item)
    {
        link += separator + "p=" + encodeURIComponent(Item);
        separator = "&";
    }
    if (Colour)
    {
        link += separator + "cl=" + encodeURIComponent(Colour);
        separator = "&";
    }
    if (Shop)
    {
        
        link += separator + "l=" + encodeURIComponent(Shop);
        separator = "&";
    }

    //set link
    if (Item=="Any" & Colour=="Any" & Shop=="Any")
        alert('Please select at least one option in the dropdowns');
    else
       location.href = link+"&txt=false&qs=";
}
function SearchBar_GetQuickSearchString()
{
    if (document.forms[0].txtSearch.value == "" | document.forms[0].txtSearch.value == null)
    {
        alert("Please enter in some search criteria");
    }
    else
    {
        window.location = "/search/default.aspx?txt=false&s=&qs="+encodeURIComponent(document.forms[0].txtSearch.value);
    }
}
function SearchBar_GetTrendString(TrendID)
{
    var itemlink = "/trends/trend.aspx?id=";
    var anylink = "/trends/";
    var link;
    var dValue = CNDropDownGetSelectedValue(TrendID);
    if (dValue=="Any")
        link = anylink;
    else
        link = itemlink + dValue;
     location.href = link;
}
/*end search bar */

function QuickSearchSection(keywords, section)
{
    if (keywords.value == "" | keywords.value == null)
    {
        alert("Please enter in some search criteria");
    }
    else
    {
        window.location = "/search/default.aspx?txt=true&qs="+ encodeURIComponent(keywords.value) +"&s=" + section;
    }
}

/*Fix IE6 hover background image flicker*/
function fixBackgroundImageCache()
{
try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
}

cnAddEvent(document,'load',fixBackgroundImageCache);

function QuickSearchCheckEnter(e)
{ 
    var characterCode

    if(e && e.which)
    { 
        e = e
    characterCode = e.which 
    }
    else
    {
        e = event
        characterCode = e.keyCode
    }

    if(characterCode == 13)
    {
        SearchBar_GetQuickSearchString();
        return false;
    }
    else
    {
        return true;
    }

}

