// original is http://www.weightwatchers.com.au/include/search.js
// this script has been modified to include full path to the shop (2 lines)

var message = tmpSearchText
var kObj=null;
var cObj=null;

function RunSearch(cid,kid,e){ 
    var category, keyword;   
     
    if(document.getElementById){ 

        kObj = document.getElementById(kid); 
        cObj = document.getElementById(cid); 

        category = cObj.options[cObj.selectedIndex].value; 
        kObj.value = Trim(kObj.value);
        keyword = kObj.value; 
        
        if (category == "0"){
            if (ErrCheck(kObj)) return false;
        }
        Redirect(category,keyword); 

        if (kObj.value == message) kObj.value = "";
    } 
} 

function Redirect(category, keyword)
{
	if (category == "0")
		// modified to include full path
		parent.location.href = "http://www.weightwatchers.com.au/search/sitewide.aspx?cat=0&search=" + encodeURIComponent(keyword);
	else
		// modified to include full path
		parent.location.href = "http://www.weightwatchers.com.au/search/category.aspx?cat=" + category + "&search=" + encodeURIComponent(keyword);	
}

function ErrCheck(obj){ 
    if(!obj.value || obj.value == message){ 
        obj.value = message; 
        obj.blur(); 
        return true; 
    } 
    return false; 
} 

function Trim(str){ 
   return str.replace(/^\s+|\s+$/g,""); 
} 

function OnFocusClearField(kid){
    if(document.getElementById){
        kObj = document.getElementById(kid);
        if(kObj.value == message) kObj.value = "";
    }
}

//This method was created for 6.0components and it get text 
//entered in textBoxId and submit page to search page using
//Redirect method
function RunSearchTextBox(textBoxId, catId, validationMessage)
{
	var textBoxObject;
	var keyword;
	
	if(document.getElementById)
	{
		textBoxObject = document.getElementById(textBoxId);
		keyword = textBoxObject.value;
		if(keyword)
		{
			Redirect(catId, keyword);
		}
		else
		{
			if(validationMessage)
			{
				alert(validationMessage);
			}
			textBoxObject.focus();
			return false;
		}
	}
}