﻿function search(searchText, RootURL, defaultURL)
{     
    if (searchText != defaultURL)
    {
        if (searchText==""||searchText==null||searchText.trim=="") 
        {
             searchText="enter_search_phrase";
        }
        
        searchText=searchText.replace(/ /g,"_");
	searchText = replaceChars(searchText);     
                
        window.location = RootURL+searchText;          
    }
}

function brandJump(dropdown, RootURL)
{	
	var myindex  = dropdown.selectedIndex;
	var SelValue = dropdown.options[myindex].value;
	if (SelValue != '0')
    {
        SelValue = replaceChars(SelValue);
        SelValue=SelValue.replace(/ /g,"_");
        window.location = RootURL+SelValue+'/';
    }	
}

function endecaBrandJump(dropdown, RootURL)
{	
	var myindex  = dropdown.selectedIndex;
	var SelValue = dropdown.options[myindex].value;
	if (SelValue != '0')
    {
        window.location = RootURL.replace("manufacturer",SelValue);

    }	
}



function replaceChars(value) 
{
    out = ":"; // replace this
    add = "~~"; // with this
    temp = "" + value; // temporary holder

    while (temp.indexOf(out)>-1) 
        {
            pos= temp.indexOf(out);
            temp = "" + (temp.substring(0, pos) + add + 
            temp.substring((pos + out.length), temp.length));
    }
	
    out = '"'; // replace this
    add = ""; // with this
    
    while (temp.indexOf(out)>-1) 
        {
            pos= temp.indexOf(out);
            temp = "" + (temp.substring(0, pos) + add + 
            temp.substring((pos + out.length), temp.length));
    }
    return temp;
}


function customerBasketSettings(dropdown, RootURL)
{	
    
	var myindex  = dropdown.selectedIndex;
	var SelValue = dropdown.options[myindex].value;
	if (SelValue != '0')
    {
        SelValue=SelValue.replace(/ /g,"_");
        window.location = RootURL+SelValue;
    }	
}

function customerSettings(dropdown1, dropdown2, dropdown3, RootURL, Rn)
{	
	var myindex1  = dropdown1.selectedIndex;
	var SelValue1 = dropdown1.options[myindex1].value;
	
	var myindex2  = dropdown2.selectedIndex;
	var SelValue2 = dropdown2.options[myindex2].value;
	
	var myindex3  = dropdown3.selectedIndex;
	var SelValue3 = dropdown3.options[myindex3].value;
			     
    window.location = RootURL+'?lang='+SelValue3+'&dest='+SelValue1+'&curr='+SelValue2+'&rn='+Rn;    	
}

// Function to detect on keypress event of search box
function searchKeyPress(e, searchText, RootURL, defaultURL)
{
    var keynum;
    var keychar;
    var numcheck;
    var ret;
   
    if(window.event) // IE
    {
    keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
    keynum = e.which;
    }    
    ret = true;
    if (keynum == 13 || keynum == 1)
    {
    search(searchText, RootURL, defaultURL)    
    ret = false;
    }
    
    return ret;
}