/**
 * ajax.js
 *
 */

//global variables
var req;
var reqa;
var which;
var pollingTimeout = 5000;
var tryPolling = 0;
var maxtry = 3;


/**
 * Get the contents of the URL via an Ajax call
 * url - to get content from (e.g. /struts-ajax/sampleajax.do?ask=COMMAND_NAME_1) 
 * nodeToOverWrite - when callback is made
 * nameOfFormToPost - which form values will be posted up to the server as part 
 *					of the request (can be null)
*/
function retrieveURL(url, rtype) {
	if (window.XMLHttpRequest) { // Non-IE browsers
    	req = new XMLHttpRequest();
      	try {
      		if(req){
      			req.onreadystatechange = processStateChange;
       			req.open(rtype, url, true); 
       			req.send(null);
       		}
      	} catch (e) {
     		document.getElementById('bodydivs').innerHTML = showErrorPage();
      	}
   	} else if (window.ActiveXObject) { // IE
    	req = new ActiveXObject("Microsoft.XMLHTTP");
      	try{
      		if (req) {
      			req.onreadystatechange = processStateChange;
        		req.open(rtype, url, true);
        		req.send();
        	}
     	}catch(E){
    		document.getElementById('bodydivs').innerHTML = showErrorPage();
    	}	
   	}
}

function retrieveURLForState(url, rtype) {
	if (window.XMLHttpRequest) { // Non-IE browsers
    	req = new XMLHttpRequest();
        try {
         	if(req){
         		req.onreadystatechange = processStateChangeForState;
          		req.open(rtype, url, true); 
          		req.send(null);
          	}
         } catch (e) {
        	alert(serverCommunicationMessage + " " +e);
         }
  	} else if (window.ActiveXObject) { // IE
        req = new ActiveXObject("Microsoft.XMLHTTP");
        try{
         	if (req) {
        		req.onreadystatechange = processStateChangeForState;
           		req.open(rtype, url, true);
           		req.send();
           	}
        }catch(E){
       		alert(serverCommunicationMessage + " " +e);
       	}	
  	}
}
/*
 * Set as the callback method for when XmlHttpRequest State Changes 
 * used by retrieveUrl
 */
function processStateChanges() {
	if (req.readyState == 4) { // Complete
    	if (req.status == 200) { // OK response
    	  	document.getElementById('1').innerHTML = req.responseText;
     	} else {
        	alert(serverResponseMessage + " " + req.statusText);
	   	}
   	}
}



/**
 * Get the contents of the URL via an Ajax call
 * url - to get content from (e.g. /struts-ajax/sampleajax.do?ask=COMMAND_NAME_1) 
 * nodeToOverWrite - when callback is made
 * nameOfFormToPost - which form values will be posted up to the server as part 
 *					of the request (can be null)
*/
function submitPreCheckout(url, rtype) {
	if (window.XMLHttpRequest) { // Non-IE browsers
    	req = new XMLHttpRequest();
      	try {
      		if(req){
      			req.onreadystatechange = processStateChangeForPreCheckout;
       			req.open(rtype, url, true); 
       			req.send(null);
       		}
      	} catch (e) {
      	 alert("error"); 
     		//document.getElementById('bodydivs').innerHTML = showErrorPage();
      	}
   	} else if (window.ActiveXObject) { // IE
    	req = new ActiveXObject("Microsoft.XMLHTTP");
      	try{
      		if (req) {
      			req.onreadystatechange = processStateChangeForPreCheckout;
        		req.open(rtype, url, true);
        		req.send();
        	}
     	}catch(E){
     	alert("error");
    		//document.getElementById('bodydivs').innerHTML = showErrorPage();
    	}	
   	}
}



/*
 * Set as the callback method for when XmlHttpRequest State Changes 
 * used by retrieveUrl
 */
function processStateChangeForPreCheckout() {
	if (req.readyState == 4) { // Complete
    	if (req.status == 200) { // OK response
				var responsetxt = req.responseText;
				if(responsetxt.match("<")){
				  document.getElementById('bodydivs').innerHTML = responsetxt;    	
				}else{
				  document.getElementById("control").value = responsetxt;
				  document.getElementById("expressCheckout").submit();
				}
    	 //alert(req.responseText);
     	} else {
     	alert("error");
        	//alert(serverResponseMessage + " " + req.statusText);
	   	}
   	}
}


 
/**  
 * gets the contents of the form as a URL encoded String
 * suitable for appending to a url
 * @param formName to encode
 * @return string with encoded form values , beings with &
 */ 
function getFormAsString(formName){
   
	returnString ="";
 	 
 	 //Get the form values	
 	 formElements=document.forms[formName].elements;
 	
 	 //loop through the array , building up the url	
 	 for ( var i=formElements.length-1; i>=0; --i ){
 		 //we escape (encode) each value
 		 returnString=returnString+"?"+escape(formElements[i].name)+"="+escape(formElements[i].value);
 	 }

 	 //return the values
 	 return returnString; 
}
 
/**
 * Splits the text into <span> elements
 * @param the text to be parsed
 * @return array of <span> elements - this array can contain nulls
 */
function splitTextIntoSpan(textToSplit)
{
	//Split the document
   	returnElements=textToSplit.split("</span>")
 	
 	//Process each of the elements 	
 	for ( var i=returnElements.length-1; i>=0; --i ){
 		
 		//Remove everything before the 1st span
 	 	spanPos = returnElements[i].indexOf("<span>");		
 		
 	 	//if we find a match , take out everything before the span
 	 	if(spanPos>0){
 		 	 subString=returnElements[i].substring(spanPos);
 		 	 returnElements[i]=subString;
 	 	} 
 	}
 	return returnElements;
}

/*
 * Replace html elements in the existing (ie viewable document)
 * with new elements (from the ajax requested document)
 * WHERE they have the same name AND are <span> elements
 * @param newTextElements (output of splitTextIntoSpan)
 *					in the format <span id=name>texttoupdate
 */
function replaceExistingWithNewHtml(newTextElements){
   //loop through newTextElements
 	 for ( var i=newTextElements.length-1; i>=0; --i ){
     //check that this begins with <span
 		 if(newTextElements[i].indexOf("<span")>-1){
 		   //get the name - between the 1st and 2nd quote mark
 			 startNamePos=newTextElements[i].indexOf('"')+1;
 			 endNamePos=newTextElements[i].indexOf('"',startNamePos);
 			 name=newTextElements[i].substring(startNamePos,endNamePos);
 		
 		   //get the content - everything after the first > mark
 			 startContentPos=newTextElements[i].indexOf('>')+1;
 			 content=newTextElements[i].substring(startContentPos);
 			
 			 //Now update the existing Document with this element
 		   //check that this element exists in the document
	 		 if(document.getElementById(name)){
	 			document.getElementById(name).innerHTML = content;
	 		 } else {
	 			 alert("Element:"+name+"not found in existing document");
	 		 }
 		 }
	}
}

var orig;				
function showProgress(name, imgsrc)
{
	prg = " <div style='width:100%; margin-top:200px; text-align:center'><img src="+imgsrc+"alt=\"\" title=\"\"></div>";
	progressViewer = document.getElementById(name);
	orig=progressViewer.innerHTML;
	progressViewer.innerHTML = prg;
}

function hideProgress(name)
{
	progressViewer = document.getElementById(name);
	//progressViewer.innerHTML = orig;
}
	
function retrieveLeftMenu(url, rtype) {
	if (window.XMLHttpRequest) { // Non-IE browsers
    	reqa = new XMLHttpRequest();
      	try {
      		if(reqa){
	      		reqa.onreadystatechange = processMenuStateChange;
	       		reqa.open(rtype, url, true); 
	       		reqa.send(null);
       		}
      	} catch (e) {
     		alert(serverCommunicationMessage + " " +e);
      	}
   	} else if (window.ActiveXObject) { // IE
      	reqa = new ActiveXObject("Microsoft.XMLHTTP");
      	try{
      		if (reqa) {
	      		reqa.onreadystatechange = processMenuStateChange;
	        	reqa.open(rtype, url, true);
	        	reqa.send();
        	}
     	}catch(E){
    		alert(serverCommunicationMessage + " " +e);
    	}	
   	}
}
	
function processMenuStateChange() {
	
	if (reqa.readyState == 4) { // Complete
		if (reqa.status == 200) { // OK response
			try{
				
			}catch(e){
				alert(e.message);
			}
			document.getElementById('menudivs').innerHTML = reqa.responseText;
 			//hideProgress("bodydivs");
			document.getElementById('tagCloudComp').innerHTML = "";
		} else {
  			alert(serverResponseMessage + " " + reqa.statusText);
		}
	}
}
 		
function updateToHomeLeft(refVal)
{
   retrieveLeftMenu("updateLeftHomeMenu.do?refreshBookTile="+refVal,"GET");
}
	
function updateToBookLeft()
{
	//progressViewer = document.getElementById(name);
	//progressViewer.innerHTML = orig;
}	

function keyPressCheck(e, formName){
    
	if(e.type=='keypress'){
		var unicode=e.keyCode? e.keyCode : e.charCode;
		if(unicode==13){
 			if (formName == 'searchForm') {
				startSearch();
			} else if (formName == 'saveSearch') {
				saveSearches();
			} else {
				submitsearch(formName, 'GET');
			}
  			return false;
   		}
   	}
}

function encodeHTML(text) {
	
	if (typeof(text) != "string")
		text = text.toString();
		text = text.replace(
		/&/g, "&amp;").replace(
		/"/g, "&quot;").replace(
		/</g, "&lt;").replace(
		/>/g, "&gt;").replace(
		/\+/g, "&#43;");

	return text;
}

function encode(obj) {
	var unencoded = obj;
	return escape(unencoded);
}

function decode(obj) {
	var encoded = obj;
	return unescape(encoded.replace(/\+/g,  " "));
}
   
function updateSearchTileToHome(){
	return "<form action=\"search.do\" method=\"get\" id=\"searchForm\" style=\"margin-top:0px; margin-bottom:0px;\"><table><tr><td><strong>rightMenu.label.search</strong> :</td><td><input type=\"text\" id=\"searchTerm\" name=\"searchTerm\" class=\"searchText\" size=\"50\" maxlength=\"200\" value=\"${sessionScope.searchCriteria.allwords}\" onkeypress=\"return keyPressCheck(event, 'searchForm');\"/><input type=\"hidden\" id=\"optionValue\" name=\"optionValue\" value=\"2\" /><input type=\"hidden\" name=\"home\" id=\"home\" value=\"true\" /></td><td><img src=\"publisher/images/search_button.gif\" id=\"searchImg\" border=\"0\" alt=\"Search\" title= \"Search\" onclick=\"javascript:startSearch()\"></td><td><a href=\"advancesearchHome.do\" class=\"leftlinks\">rightMenu.label.advancedsearch</a></td></tr></table></form>";
}

function updateSearchTileToHome_withoutsearchbox(){
	return "<form action=\"search.do\" method=\"get\" id=\"searchForm\" style=\"margin-top:0px; margin-bottom:0px;\"><table><tr><td><input type=\"text\" id=\"searchTerm\" name=\"searchTerm\" class=\"searchText\" size=\"25\" maxlength=\"200\" value=\"${sessionScope.searchCriteria.allwords}\" onkeypress=\"return keyPressCheck(event, 'searchForm');\"/><input type=\"hidden\" id=\"optionValue\" name=\"optionValue\" value=\"2\" /><input type=\"hidden\" name=\"home\" id=\"home\" value=\"true\" /></td><td><img src=\"publisher/images/search_button.gif\" alt=\"Search\" title= \"Search\" id=\"searchImg\" border=\"0\" alt=\"\" title= \"\" onclick=\"javascript:startSearch()\"></td><td><a href=\"advancesearchHome.do\" class=\"leftlinks\">rightMenu.label.advancedsearch</a></td></tr></table></form>";
}
	
function getErrorPage(){
    return "<table width=\"100%\" height=\"100%\"  border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td height=\"10\" colspan=\"2\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"7\" background=\"publisher/images/headingbg.gif\"><img src=\"publisher/images/headingleft1.gif\" width=\"7\" height=\"36\" alt=\"\" title=\"\" /></td><td width=\"50%\" style=\"background-image:url(publisher/images/headingbg.gif); background-repeat:repeat-x;\" class=\"tabheading\">category</td><td width=\"50%\" align=\"right\" class=\"tabheading\" style=\"background-image:url(publisher/images/headingbg.gif); background-repeat:repeat-x;\">&nbsp;</td><td width=\"7\" align=\"right\" background=\"publisher/images/headingbg.gif\"><img src=\"publisher/images/headingright1.gif\" alt=\"\" title=\"\"width=\"7\" height=\"36\" /></td><td>&nbsp;</td></tr></table></td></tr><tr><td colspan=\"2\" valign=\"top\"><table cellspacing=\"0\" cellpadding=\"3\" width=\"100%\" border=\"0\"><tbody><tr><td align=\"middle\">&nbsp;</td></tr><tr><td align=\"middle\"><TABLE cellSpacing=0 cellPadding=0 width=328 border=0><TBODY><TR><TD vAlign=bottom align=center background=\"publisher/images/signin_box1.gif\" height=33><TABLE cellSpacing=0 cellPadding=0 width=\"94%\" border=0><TBODY><TR><TD class=welcometext align=left height=25><strong>simpleSearch.label.emptyheading</strong></TD></TR></TBODY></TABLE></TD></TR><TR><TD align=center background=\"publisher/images/signin_box2.gif\"><TABLE cellSpacing=0 cellPadding=4 width=\"92%\" border=0><TBODY><TR></TR><TR><TD class=textelevenarial align=center><TABLE width=\"100%\" height=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\"><TR><TD width=\"12%\" rowspan=\"2\" align=\"center\" valign=\"top\" class=textelevenarial><img src=\"publisher/images/icon_alert.gif\" alt=\"alert\" title=\"alert\"/></TD><TD width=\"88%\" class=\"textelevenarial\">simpleSearch.label.emptymessage</TD></TR></TABLE></TD></TR><TR><TD class=textelevenarial align=center></TD></TR></TBODY></TABLE></TD></TR><TR><TD align=center background=\"publisher/images/signin_box3.gif\" height=11></TD></TR></TBODY></TABLE></td></tr></tbody></table></td></tr></table>"
}
  
String.prototype.replaceAll = function(v1,v2)
{
    var temp = this;
    var i = temp.indexOf(v1);
    while(i > -1)
    {
	  	temp = temp.replace(v1, v2);
  		i = temp.indexOf(v1, i + v2.length + 1);
    }
    return temp;
}

function startPolling(pollingInterval){
    if(pollingInterval!=null){
    	pollingTimeout =  pollingInterval;
    }
    var t=setTimeout("doPolling('poll.do?pollreq=working','GET')", pollingTimeout);
}


function doPolling(url, rtype){ 
  if (window.XMLHttpRequest) { // Non-IE browsers
    reqa = new XMLHttpRequest();
    try {
      if(reqa){
        reqa.onreadystatechange = processPollingStateChange;
        reqa.open(rtype, url, true); 
        reqa.send(null);
      }
    } catch (e) {
	tryPolling = tryPolling+1;
	if(tryPolling<=maxtry){
		startPolling(pollingTimeout);
	}else{
	  //alert("Server is gone away");
	}
    }
  } else if (window.ActiveXObject) { // IE
    reqa = new ActiveXObject("Microsoft.XMLHTTP");
    try{
      if (reqa) {
        reqa.onreadystatechange = processPollingStateChange;
        reqa.open(rtype, url, true);
        reqa.send();
      }
    }catch(E){
	tryPolling = tryPolling+1;
	if(tryPolling<=maxtry){
		startPolling(pollingTimeout);
	}else{
	  //alert("Server is gone away");
	}
    }	 
  }
}

function processPollingStateChange() {
	
	if (reqa.readyState == 4) { // Complete
		if (reqa.status == 200) { // OK response
			try{
				
			}catch(e){
				alert(e.message);
			}
			startPolling(pollingTimeout);
			//document.getElementById('menudivs').innerHTML = reqa.responseText;
 			//hideProgress("bodydivs");  			
		} else {
		        tryPolling = tryPolling+1;
		        if(tryPolling<=maxtry){
                          startPolling(pollingTimeout);
		        }else{
		          //alert("Server is gone away");
		        }
  			
		}
	}
}
var varisbn="";
function showChapters(url, rtype,isbn) {	
		varisbn=isbn;

		rtype="GET";
	if (window.XMLHttpRequest) { // Non-IE browsers
    	req = new XMLHttpRequest();
      	try {
      		if(req){
      			req.onreadystatechange = chapterDetail;
       			req.open(rtype, url, true); 
       			req.send(null);
       		}
      	} catch (e) {
			alert(e);     		
      	}
   	} else if (window.ActiveXObject) { // IE
    	req = new ActiveXObject("Microsoft.XMLHTTP");
      	try{
      		if (req) {
      			req.onreadystatechange = chapterDetail;
        		req.open(rtype, url, true);
        		req.send();
        	}
     	}catch(E){    		
    	}	
   	}
}

function deleteChapters(url, rtype,isbn,mess) {
	
		varisbn=isbn;

		var isCnfrm = confirm(mess);
		if(isCnfrm){
       rtype="GET";
		if (window.XMLHttpRequest) { // Non-IE browsers
    	req = new XMLHttpRequest();
      	try {
      		if(req){
      			req.onreadystatechange = deletenotes;
       			req.open(rtype, url, true); 
       			req.send(null);
       		}
      	} catch (e) {
			alert(e);
     		//document.getElementById('bodydivs').innerHTML = showErrorPage();
      	}
   	} else if (window.ActiveXObject) { // IE
    	req = new ActiveXObject("Microsoft.XMLHTTP");
      	try{
      		if (req) {
      			req.onreadystatechange = chapterDetail;
        		req.open(rtype, url, true);
        		req.send();
        	}
     	}catch(E){
    		//document.getElementById('bodydivs').innerHTML = showErrorPage();
    	}	
   	}
	}	
}

function chapterDetail() {

	if (req.readyState == 4) { // Complete
    	if (req.status == 200) { // OK response

    	 var element =document.getElementById(varisbn);
          element.innerHTML =  req.responseText;
          element.style.display="block";
		  var selement=document.getElementById(varisbn+"S");
		   var helement=document.getElementById(varisbn+"H");
		   var stelement=document.getElementById(varisbn+"ST");

		   var htelement=document.getElementById(varisbn+"HT");
		   if(selement!=null){
			  selement.style.display="none";
			  stelement.style.display="none";
		   }
		   if(helement!=null){
			 helement.style.display="block";
 			 htelement.style.display="block";
		   }
			 
			} else {
        	alert(serverResponseMessage + " " + req.statusText);
	   	}
   	}
}

function deletenotes() {

	if (req.readyState == 4) {
    	if (req.status == 200) {

    		var element = document.getElementById("main");		
          	element.innerHTML =  req.responseText;
		} else {
        	alert(serverResponseMessage + " " + req.statusText);
	   	}
   	}
}

function hideChapters(isbn) {

   	var element=document.getElementById(isbn);
   	if(element!=null){
		element.style.display="none";
 	}

	var selement=document.getElementById(isbn+"S");
	var helement=document.getElementById(isbn+"H");
	if(selement!=null){
		selement.style.display="block";
	}
	
	if(helement!=null){
		helement.style.display="none";
	}
	
	var stelement=document.getElementById(isbn+"ST");
	var htelement=document.getElementById(isbn+"HT");
	if(stelement!=null){
		stelement.style.display="block";
	}
	
	if(htelement!=null){
		htelement.style.display="none";
	}
}

function fetchUserOptions(divCounter, end) 
{
	var userOptionsDivId;
	var priceDivId;
	
	for (var i=1; i<=end ; i++)
	{
		userOptionsDivId = "userOptionsMenu" + i;
		priceDivId = "priceMenu" + i;
		
		if (document.getElementById(priceDivId) != null) {
			document.getElementById(priceDivId).style.display='none';
		}
		
		if (i != divCounter)
		{
			if (document.getElementById(userOptionsDivId) != null) {
				document.getElementById(userOptionsDivId).style.display='none';
			}			
		}		
	}
	
	userOptionsDivId = "userOptionsMenu" + divCounter;

	if (document.getElementById(userOptionsDivId).style.display == 'none') 
	{
		document.getElementById(userOptionsDivId).style.display='block';	
	} 
	else 
	{
		document.getElementById(userOptionsDivId).style.display='none';
	}	
}

function fetchPriceDetails(divCounter, bookId, end) 
{	
	var userOptionsDivId;
	var priceDivId;
	this.divCounter = divCounter;

	for (var i=1; i<=end ; i++)
	{
		userOptionsDivId = "userOptionsMenu" + i;
		priceDivId = "priceMenu" + i;
		
		if (document.getElementById(userOptionsDivId) != null) {
			document.getElementById(userOptionsDivId).style.display='none';
		}
		if (i != divCounter)
		{
			if (document.getElementById(priceDivId) != null) {
				document.getElementById(priceDivId).style.display='none';
			}
		}		
	}
	
	priceDivId = "priceMenu" + divCounter;
	
	if (document.getElementById(priceDivId).style.display == 'none') 
	{
		var url = "priceDisplay.do?id="+bookId;		
		getPriceDetails(url, "GET");
	} 
	else 
	{
		document.getElementById(priceDivId).style.display='none';
	}	
}
	
function getPriceDetails(ReqUrl, callType) 
{
    try
    {
	    getXmlHTTPReqObject();
	
		xmlHttp.onreadystatechange = processPriceDetails;
		
		xmlHttp.open("GET", ReqUrl, true);
	    xmlHttp.send(null);
			
	}
	catch (e) 
	{
	    alert(e);
	}
}
	
function processPriceDetails() 
{			
	var priceDetailsId = "priceDetails" + divCounter;
	var priceMenuId = "priceMenu" + divCounter;
	var loadingId = "loading" + divCounter;
	if (xmlHttp.readyState == 4) 
	{ 
		if (xmlHttp.status == 200) 
		{ 
		  	document.getElementById(priceMenuId).style.display='block';		
			
			document.getElementById(priceDetailsId).innerHTML = xmlHttp.responseText;			
			document.getElementById(loadingId).style.display='none';		
	    } 
	    else 
	    {
			alert(serverResponseMessage + " " + xmlHttp.statusText);
	    }
	} else {
		document.getElementById(loadingId).style.display='block';		
	}
}

function getXmlHTTPReqObject(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		isIE = true;
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function openSaveSearch() 
{
	document.getElementById("saveSearchDiv").style.display = 'block';
	document.getElementById("errorRow").height = 2;	
	document.getElementById("errorDiv").style.display = 'none';
	document.getElementById("searchTitle").value = '';
	document.getElementById("searchTitle").focus();
}

function closeSaveSearch(obj)
{
	if (document.getElementById(obj) != null) {
		document.getElementById(obj).style.display = 'none';
	}
}

function saveSearches()
{	
	var searchTitle = trimAll(document.getElementById("searchTitle").value);
	
	if (searchTitle.length > 0)
	{
		var searchUrl = "saveSearchHome.do?requestType=Save&searchTitle=" + encode(encodeHTML(searchTitle));
		saveUserSearches(searchUrl, "GET");
	} else {
		document.getElementById("errorRow").height = 20;	
		document.getElementById("errorDiv").style.display = 'block';
		document.getElementById("errorDiv").innerHTML = searchTitleRequired;
		document.getElementById("searchTitle").value = '';
	}	
}

function saveUserSearches(url, rtype) 
{
    try
    {
	    getXmlHTTPReqObject();
	
		xmlHttp.onreadystatechange = processUserSearchDetails;
		
		xmlHttp.open("GET", url, true);
	    xmlHttp.send(null);
			
	}
	catch (e) 
	{
	    document.getElementById("errorRow").height = 20;
		document.getElementById("errorDiv").style.display = 'block';
	    document.getElementById("errorDiv").innerHTML = searchTitleMessage;
	}
}

function processUserSearchDetails() 
{	
	if (xmlHttp.readyState == 4) 
	{ 
		if (xmlHttp.status == 200) 
		{ 
		  	var resp =  xmlHttp.responseText;
		  	var objt = new Function("return "+resp)();
			var result = objt.Result;
		  	
		  	if (result == 'true') {
		  		document.getElementById("saveSearchDiv").style.display = 'none';
				document.getElementById("resultDiv").style.display = 'block';
		  	} else {
		  		document.getElementById("errorRow").height = 20;
				document.getElementById("errorDiv").style.display = 'block';
		  		document.getElementById("errorDiv").innerHTML = searchTitleMessage;
			}		  		
	    } 
	    else 
	    {
			document.getElementById("errorRow").height = 20;
			document.getElementById("errorDiv").style.display = 'block';
			document.getElementById("errorDiv").innerHTML = searchTitleMessage;
	    }
	}
}

function deleteSearch(searchId)
{
	var url = "saveSearchHome.do?requestType=Delete&searchId=" + searchId;
	deleteUserSearches(url, "GET");
}

function deleteUserSearches(url, rtype) 
{
    try
    {
	    getXmlHTTPReqObject();
	
		xmlHttp.onreadystatechange = deleteUserSearchDetails;
		
		xmlHttp.open("GET", url, true);
	    xmlHttp.send(null);
			
	}
	catch (e) 
	{
	    alert(e);
	}
}

function deleteUserSearchDetails() 
{	
	if (xmlHttp.readyState == 4) 
	{ 
		if (xmlHttp.status == 200) 
		{ 
		  	document.getElementById('bodydivs').innerHTML = xmlHttp.responseText;
	    } 
	    else 
	    {
			alert(e);
	    }
	}
}