/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


/**
*  
*  Javascript function to to validate the Search Content.
*
**/
function searchStart()
{
    var searchKey = document.getElementById('searchColumn').value;	
	var channelLink = document.getElementById('searchChannelURL').value;	
	var regularExpTokens = new RegExp("[&%#]");
    
    if(searchKey==null || searchKey.length==0 || trim(searchKey).length==0) {
		alert('Please Enter valid Search Content');
        document.getElementById('searchColumn').focus();		      
		return false;
	}
	else {		
      if(regularExpTokens.test(searchKey))
	   {
		//var modSearchKey = searchKey.replace(/#|&|/g,"\\");			
		var modSearchKey = searchKey.replace(/%/g,"%25");	
		modSearchKey=modSearchKey.replace(/#/g,"%23");
		modSearchKey=modSearchKey.replace(/&/g,"%26");		
	   window.location.href=channelLink+"?searchKey="+modSearchKey;
	   }
	   else
	   {		  
	    window.location.href=channelLink+"?searchKey="+searchKey;
	   }
	}
}
