﻿function clickclear(thisfield, defaulttext) 
{
    if (thisfield.value == defaulttext) 
    {
    thisfield.value = "";
    }
}

function clickrecall(thisfield, defaulttext) 
{
    if (thisfield.value == "") 
    {
    thisfield.value = defaulttext;
    }
}

function DoSearch()
{
    //alert("dosearch");
    var search_term = $('#searchtextEntry').val();
    if (search_term == '')
    {
        alert('Please enter at least one search term');
    }
    else
    { 
        top.location.href = "/search.aspx?term=" + encodeURIComponent(search_term) + ""; 
    }
    
    return false;
}

function CheckSearchSubmit(e)
{ 
    //alert("CheckSearchSubmit");
    var characterCode;
    
    if (e && e.which)
    { 
        characterCode = e.which; 
    }
    else
    {
        characterCode = e.keyCode; 
    }
    
    // Check if user hit the enter/return key
    if(characterCode == 13)
    {
        return DoSearch();
    }
    else
    { 
        return true;
    }       
}


// HEADER SEARCH AUTOCOMPLETE - start
function findValue(li) {
    return row[0];
}

function selectItem(li) {
	findValue(li);
}

function formatItem(row) {
    var dropdownHTML1 = '<span id="results-wrap"><img src="';
    var dropdownHTML2 = '" alt="" />';
    var dropdownHTML3 = '</span>';
	return "" + dropdownHTML1  +"" + row[1] + "" + dropdownHTML2  + "" + row[0] + "" + dropdownHTML3 + "";
}
// HEADER SEARCH AUTOCOMPLETE - end


function LoadSearchDropdown()
{
     // HEADER SEARCH AUTOCOMPLETE
     $("#searchtextEntry").autocomplete("/services/search.ashx",
		{   delay:10,
			minChars:2,
			matchSubset:1,
			matchContains:1,
			cacheLength:10,
			onItemSelect:selectItem,
			onFindValue:findValue,
			formatItem:formatItem,
			scrollHeight:480,
			autoFill:true
		}
	).result(function(event,row){location.href = row[3] + "";});
}

function ToggleDesc(divShowId,divHideId)
{
    var divShow=document.getElementById(divShowId);
    var divHide=document.getElementById(divHideId);
    divShow.style.display='inline';
    divHide.style.display='none';
}

function EscapeString(OriginalString)
{                
    if(OriginalString.length > 0)
    {
        return OriginalString.replace(/'/g,"&#39;");
    }
    
    return OriginalString;     
}

function PopUpWindow(url) 
{
	newwindow=window.open(url,'name','height=200,width=250');
	if (window.focus) {newwindow.focus()}
	return false;
}