//
//  ltrim() - Returns the specified string with all leading spaces removed.
//
function ltrim(str)
{ 
	for (var k=0; k<str.length && str.charAt(k)==" "; k++);
	return str.substring(k, str.length);
}

//
//  rtrim() - Returns the specified string with all trailing spaces removed.
//
function rtrim(str)
{
	for (var j=str.length-1; j>=0 && str.charAt(j)==" "; j--);
	return str.substring(0, j+1);
}

//
//  trim() - Returns the specified string with all leading and trailing spaces removed.
//
function trim(str)
{
	return ltrim(rtrim(str));
}

//
//  doProductSearch() - Trims any leading and trailing whitespace from the product search
//		textfield and submits the form.
//
function doProductSearch()
{
	var str = document.forms["productsearch"].DPN.value;
	if (str.indexOf("Description or Part No")>-1)
	{
		str = " ";
	}	
	var trimmedStr = trim(str);	
	
	if (str != trimmedStr) {
		document.forms["productsearch"].DPN.value = trimmedStr;
	}
	document.forms["productsearch"].submit();

}

//
//  doSiteSearch() - Trims any leading and trailing whitespace from the site search
//		textfield and submits the form.
//
function doSiteSearch()
{
	var str = document.forms["sitesearch"].ST.value;		
	var trimmedStr = trim(str);
	
	if (trimmedStr.length == 1 || str.indexOf("Search Site")>-1) 
	{
		alert("Please enter more than one character in the \"Site Search\" field and try your search again.");
		return false;
	}

	if (str != trimmedStr) {
		document.forms["sitesearch"].ST.value = trimmedStr;
	}
	document.forms["sitesearch"].submit();

}

//
//  doSiteSearch() - Trims any leading and trailing whitespace from the site search
//		textfield and submits the form. This is for the site map page which has a seach form also
//
function doSiteSearch2()
{
	var str = document.forms["sitesearch2"].ST.value;	
	var trimmedStr = trim(str);
	
	if (trimmedStr.length == 1 || str.indexOf("Search Site")>-1) 
	{
		alert("Please enter more than one character in the \"Site Search\" field and try your search again.");
		return false;
	}
	if (str != trimmedStr) {
		document.forms["sitesearch2"].ST.value = trimmedStr;
	}
	document.forms["sitesearch2"].submit();

}

//for left nav effects
function togglePlus(item)
{
	if (item.html() == "-")
	{	
		item.html("+");
		
	}
	else
	{
		item.html("-");

	}
		
}


