var jassonReturn;
function getSearchResult(event) {

if(event.keyCode==13 && JSON.parse(jassonReturn.responseText).length== 1){
  	location.href=JSON.parse(jassonReturn.responseText)[0]['showURL'];
	}else if(event == 'click' && JSON.parse(jassonReturn.responseText).length== 1){
		
		location.href=JSON.parse(jassonReturn.responseText)[0]['showURL'];	
	}
	else{
	
		var	searchStr = document.getElementById('search').value;
		if (searchStr.trim().length != 0) {
			var searchURL = "/searchlistview.do?searchStr=" + searchStr.trim();
			jassonReturn = asyncGetJson(searchURL, handleSearchResults,	handleSearchErrors);
			} else{
	 			//alert("No result found");
			}
	}	
}

function strtrim() {
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
String.prototype.trim = strtrim;

function handleSearchErrors(req) {
	alert('An error occured while fetching the data');
}

function handleSearchResults(results) {
	htmlCode = "";
	htmlCode +='<table align="left" cellpadding="0" cellspacing="0" border="0">';
	htmlCode +='<tr>';
	htmlCode +='<td align="left" valign="top" class="search_topbg"><img src="images/point.gif" alt="" width="959" height="19" border="0"</td>';
	htmlCode +='</tr>';
	htmlCode +='<tr>';
	htmlCode +='<td align="left" valign="top" class="search_middlebg">';
	htmlCode +='<table align="left" cellpadding="0" cellspacing="0" border="0">';
	htmlCode +='<tr>';
	htmlCode +='<td align="left" valign="top"><img src="images/point.gif" alt="" width="17" height="1" border="0"></td>';
	htmlCode +='<td align="left" valign="top">';
	htmlCode +='<table align="left" cellpadding="0" cellspacing="0" border="0">';
	htmlCode +='<tr>';
	htmlCode +='<td align="left" colspan="2" valign="middle"><img src="images/point.gif" alt="" width="50" height="1" border="0"></td>';
	htmlCode += '<td  align="right"><a href="/listview.do"> <font size= "2">Back To List View</font></a></td>'
	htmlCode +='</tr>';
	
	if(results.length > 0) {
	for( var i=0; i<results.length; i++ ){
	
	htmlCode +='<tr>';
	htmlCode +='<td align="right" valign="middle" width="207" height="30" class="home_search_list_hd">'+results[i]['channelName'] +':</td>';
	htmlCode +='<td align="left" valign="middle"><img src="images/point.gif" alt="" width="7" height="1" border="0"></td>';
	htmlCode +='<td align="left" valign="middle" width="709" height="30"><a href="'+results[i]['showURL']+'" class="link13">'+results[i]['showName']+'</a></td>';
	htmlCode +='</tr>';
	
	}
	} else
	{
	
	htmlCode +='<tr>';
	htmlCode +='<td align="left" valign="middle"><img src="images/point.gif" alt="" width="300" height="1" border="0"></td>';
	htmlCode +='<td align="right" colspan=""  valign="middle" width="300" height="30" class="home_search_list_hd">No results found</td>';
	htmlCode +='<td align="left" valign="middle" width="709" height="30"></td>';
	htmlCode +='</tr>';
	
	}
	htmlCode +='</table>'
	htmlCode +='</td>'
	htmlCode +='<td align="left" valign="top"><img src="images/point.gif" alt="" width="20" height="1" border="0"></td>'
	htmlCode +='</tr>'
	htmlCode +='</table>'
	htmlCode +='</td>'
	htmlCode +='</tr>'
	htmlCode +='<tr>'
	htmlCode +='<td align="left" valign="top" class="search_bottombg"><img src="images/point.gif" alt="" width="959" height="19" border="0"</td>'
	htmlCode +='</tr>'
	htmlCode +='</table>'
	htmlCode +='</td>'
	htmlCode +='<td align="left" valign="top"><img src="images/point.gif" alt="" width="13" height="1" border="0"></td>'
	htmlCode +='</tr>'
	htmlCode +='</table>';



	document.getElementById('listDiv').innerHTML=htmlCode;
	document.getElementById('listDiv').style.display='block';
	
	
}