﻿
function querySt(ji) 
{
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i = 0; i < gy.length; i++) 
	{
		ft = gy[i].split("=");
		if (ft[0] == ji) 
		{
		    return ft[1].replace(/%20/gi, " ");
		}
	}
	return "";
}

var getLocale_locale = "";
var getLocale_locale_initialized = false;

function getLocale()
{
	if (getLocale_locale_initialized == false)
	{
		var path = location.href.toLowerCase();
		if (path.indexOf("/en-us/") >= 0)
		{
			getLocale_locale= "en-us";
		}
		else if (path.indexOf("/es-mx/") >= 0)
		{
			getLocale_locale= "es-mx";
		}
		getLocale_locale_initialized = true;
	}		
	return getLocale_locale;
}

function QuickSearch_Initialize()
{
    var path = "/search/pages/sitesearch.aspx";
    var pos = location.href.toLowerCase().indexOf(path);
    if (pos >= 0)
    {
        var siteSearch = document.getElementById("QuickSearch_SiteSearch");
        siteSearch.checked = true;
    }
    
    var box = document.getElementById("QuickSearch_SearchTerm");
    var kw = querySt("k");
    if (kw == "" || kw == undefined)
    {
    	var locale = getLocale();
    	if (locale == "es-mx")
    	{
    		box.value = "Código postal";
    	}
    	else
    	{
	    	box.value = "Zip Code";
	    }
   	}
	else
	{	
	    box.value = kw;
	    box.style.color = "black";
	}
}

function QuickSearch_SearchBox_OnClick()
{
    var box = document.getElementById("QuickSearch_SearchTerm");
    if (box.value == "Zip Code" || box.value == "Código postal")
        box.value = "";
    box.style.color = "black";
}

function QuickSearch_SiteSearch_OnClick()
{
    var box = document.getElementById("QuickSearch_SearchTerm");
    if (box.value == "Zip Code" || box.value == "Código postal")
        box.value = "";
    box.style.color = "black";
}

function QuickSearch_SalonSearch_OnClick()
{
    var box = document.getElementById("QuickSearch_SearchTerm");
    if (box.value == "")
    {
    	var locale = getLocale();
    	if (locale == "es-mx")
    	{
    		box.value = "Código postal";
    	}
    	else
    	{
	    	box.value = "Zip Code";
	    }
        box.style.color = "gray";
    }
}

function QuickSearch_Search_OnClick()
{
    var box = document.getElementById("QuickSearch_SearchTerm");
    if (box.value == "undefined" || box.value == "" || box.value == "Zip Code" || box.value == "Código postal")
    {
        var msg = document.getElementById("QuickSearch_MessageLabel");
        msg.innerText = "Please enter search criteria.";
    }
    else
    {
	    var siteSearch = document.getElementById("QuickSearch_SiteSearch");
	    var isSiteSearch = siteSearch.checked == true;
		var locale = getLocale();
		if (locale != "")
		{
			locale = "/" + locale;
		}
        if (isSiteSearch)
        {
            location.href = locale + "/search/Pages/SiteSearch.aspx?k=" + box.value;
        }
        else
        {
            location.href = locale + "/search/Pages/SalonSearch.aspx?k=" + box.value;
        }
    }            
    return false;
}

function salonAndSchools_SalonSearch_OnClick(locale)
{
    var box = document.getElementById("salonLocator_ZipCode");
    
	var locale = getLocale();
	if (locale != "")
	{
		locale = "/" + locale;
	}

	location.href = locale + "/search/Pages/SalonSearch.aspx?k=" + box.value;

	return false;
}

