/// <reference path="jquery-vsdoc2.js" />

function onSearchWithinResult()
{
    var withinResultsObj = document.getElementById('ctl00_SearchTopStrip_chkWithinResults');
	var storeObj = document.getElementById('ctl00_SearchTopStrip_Store');
	var currentURL = document.getElementById('ctl00_SearchTopStrip_currentURL').value;
	var Arry=currentURL.replace(/.aspx$/,"").split("_");
	
	storeObj.disabled=withinResultsObj.checked;
	
	if(storeObj.disabled)
    	for(i=Arry.length/2;i<Arry.length;i++)
	    {
	        if(Arry[i]=="Store")
	        {
	            storeObj.value=Arry[i-(Arry.length/2)];
	            break;
            }
	    }	
}





//this function is called when clicking on the 
//Go button in the free search area
function goFreeTextSearch(freeTextValue,withinResults)
{
	var currentURL = document.getElementById('ctl00_SearchTopStrip_currentURL').value;
	var StoreValue = document.getElementById('ctl00_SearchTopStrip_Store').value;
	if (freeTextValue == 'Type in your keyword(s) or Style Number' || freeTextValue == ''||freeTextValue=='Search within results')
	{
	    alert('Type in your keyword(s) or Style Number in Search Box');
		return false;
	}
		
	freeTextValue = encodeURIComponent(freeTextValue.replace(' ','-').replace('&','').replace('"',''));

	var dt = new Date();

	var cannedTrigger = document.getElementById('ctl00_SearchTopStrip_cannedTrigger');
	
	if (withinResults & currentURL!='')
	{
	  //if withing results, take the current url and add the free text to it
		Keys='_Text-'+ dt.getMinutes()+dt.getSeconds();
		Values=freeTextValue;

		if (cannedTrigger) 
		{
			if (cannedTrigger.value != "")
			{
			    Keys +='_Canned';
				Values += '_' + cannedTrigger.value;
			}
		}

		tmp=currentURL.split("_");
		for(i=0;i<tmp.length/2;i++)
		{
		    Keys+='_'+ tmp[(tmp.length/2)+i];
		    Values+='_'+ tmp[i];
		}
		var url = Values+Keys;
		
		window.location.href= url;
	}
	else
	{
	  //if new free search, take the basic url and the free text to it 
	  window.location.href = freeTextValue  + '_' + StoreValue + '_Text-' + dt.getMinutes()+dt.getSeconds() + '_Store' + '.aspx';
	}	
	
	return false;
}

//this function is being called when clicking the sort button
function goSort(obj)
{
    var value=obj.value;
    // DMH 20080630 - modified to work in the CMC 
	var baseURL = document.getElementById('ctl00_SearchTopStrip_currentURL').value; 
	//var baseURL = document.URL;
    // DMH 20080630: this trims existing sort if it exists
    if(value!='Relevance')
    {
        Keys='_Sort';
        Values=value.replace(' (Ascending)','-ASC').replace(' (Descending)','-DESC');
    }
    else
    {
        Keys='';
        Values='';
    }
    
    tmp=baseURL.split('_');
    for(i=0;i<tmp.length/2;i++)
    {
        if(tmp[(tmp.length/2)+i]!='Sort' && tmp[(tmp.length/2)+i]!='Start')
        {
            Keys+='_'+ tmp[(tmp.length/2)+i];
		    Values+='_'+ tmp[i];
		}
    }
    if(Values.substr(0,1)=='_')
        Values=Values.substr(1);
	url=Values+Keys;
	window.location.href ='/'+ url;
}

function goDisplay(obj)
{
    var value=obj.value;
    // DMH 20080630 - modified to work in the CMC 
	var baseURL = document.getElementById('ctl00_SearchTopStrip_currentURL').value; 
	//var baseURL = document.URL;
    // DMH 20080630: this trims existing sort if it exists
    if(value!='50')
    {
        Keys='_Display';
        Values=value;
    }
    else
    {
        Keys='';
        Values='';
    }
    
    tmp=baseURL.split('_');
    for(i=0;i<tmp.length/2;i++)
    {
        if(tmp[(tmp.length/2)+i]!='Display' && tmp[(tmp.length/2)+i]!='Start')
        {
            Keys+='_'+ tmp[(tmp.length/2)+i];
		    Values+='_'+ tmp[i];
		}
    }
    if(Values.substr(0,1)=='_')
        Values=Values.substr(1);
	url=Values+Keys;
	window.location.href ='/'+ url;
}

//this function is being called when clicking the sort button
function goPage(event,obj)
{
    if(event.keyCode==13)
    {
        var value=obj.value;
        // DMH 20080630 - modified to work in the CMC 
        	var baseURL = document.getElementById('ctl00_SearchTopStrip_currentURL').value; 
	    //var baseURL = document.URL.replace(/.aspx$/,""); 
        // DMH 20080630: this trims existing sort if it exists
        
        var PerPageValue=document.getElementById('ctl00_PageContent_cmbDisplayOptions').value;
        
        if(parseInt(value,0))
        {   
            if(value<1)
                value=1;
        	    
	            if(value!="1")
	            {
                    Keys='_Start';
                    Values=((value-1)*PerPageValue)+1;
                    
                    tmp=baseURL.split('_');
                    for(i=0;i<tmp.length/2;i++)
                    {
                        if(tmp[(tmp.length/2)+i]!='Start')
                        {
                            Keys+='_'+ tmp[(tmp.length/2)+i];
		                    Values+='_'+ tmp[i];
		                }
                    }
	                var url=Values+Keys;
                }
                else
                {
                    var url = baseURL;
                }
        	
	        window.location.href = url;
        }
        return false;
	}
	return true;
}



////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// This function is used for why costume4less banner ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////

/***********************************************
* Show Hint script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
		
var horizontal_offset="9px" //horizontal offset of hint box from anchor link

/////No further editting needed

var vertical_offset="0" //horizontal offset of hint box from anchor link. No need to change.
var ie=document.all
var ns6=document.getElementById&&!document.all

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-30 : window.pageXOffset+window.innerWidth-40
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetWidth+parseInt(horizontal_offset)
}
else{
var windowedge=ie && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetHeight
}
return edgeoffset
}

function showhint(menucontents, obj, e, tipwidth){
if ((ie||ns6) && document.getElementById("hintbox")){
dropmenuobj=document.getElementById("hintbox")
dropmenuobj.innerHTML=menucontents
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+obj.offsetWidth+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+"px"
dropmenuobj.style.visibility="visible"
obj.onmouseout=hidetip
}
}

function hidetip(e){
dropmenuobj.style.visibility="hidden"
dropmenuobj.style.left="-500px"
}

function createhintbox(){
var divblock=document.createElement("div")
divblock.setAttribute("id", "hintbox")
document.body.appendChild(divblock)
}

if (window.addEventListener)
window.addEventListener("load", createhintbox, false)
else if (window.attachEvent)
window.attachEvent("onload", createhintbox)
else if (document.getElementById)
window.onload=createhintbox


//------------------------
$(function() {
    function SetTitle(dv) {
        $(dv).children('div:not(.Refine_Div3)')
        .attr("title", function() {
            return ($(dv).find('div.Refine_Div1>div').hasClass('Cat_Att_Right') ? "Expand - " : "Collapse - ")
            + $(dv).find('div.Refine_Div2>span').text();
        });
    }

    $('.Refine_Div3').parent().children('div:not(.Refine_Div3)').click(function() {
        $(this).parent().find('div.Refine_Div1>div.Cat_Att_Down').toggleClass('Cat_Att_Right');
        $(this).parent().children('div.Refine_Div3').stop(true, true).toggle(100);
        SetTitle($(this).parent());
    });
    $('.Refine_Div3').parent().each(function() { SetTitle(this) });

    $('.Refine_Div2 a').click(function() {
        if ($(this).attr("href") != undefined)
            document.location = $(this).attr("href");
        return false;
    });

    $('div.Att_Collapse').click(function() {
        $(this)
            .toggleClass('Att_Expand')
            .attr("title", function() { return ($(this).hasClass("Att_Expand") ? "Expand - " : "Collapse - ") + $(this).siblings('a').text() })
            .siblings('div:last').toggle(100);
    });
    $('div.Att_Collapse').each(function() {
        $(this)
            .toggleClass('Att_Expand')
            .attr("title", function() { return ($(this).hasClass("Att_Expand") ? "Expand - " : "Collapse - ") + $(this).siblings('a').text() })
            .siblings('div:last').toggle(100);
    });
});



