var colors=["#DEB887","#B0EDEE","#FEE4C3","#87CEFA","#DDA0DC","#FED700","#ADFF30","#00BFFE","#FF69B3","#FF7F50","#9ACD32","#B8860B","#FF00FE","#7EFFD4","#8EBC8B","#32CD33","#AED8E6","#6594EC","#609DA0","#BDB76B","#F0E78C","#01CED1","#FF4500","#9AFA98","#D3691F","#DCDCDC","#FFB6C1","#778898","#9470DC","#FFA500","#DC7092","#BC8E8E","#FA8071","#D1B48C","#FAEBD6"];

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
    
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)

  var lastchar = "";
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  
  if(searchTerm.indexOf("~")!=-1)
  {
        var color=searchTerm.substring(searchTerm.indexOf("~")+1);
       
        lcSearchTerm=searchTerm.substring(0,searchTerm.indexOf("~")).toLowerCase();
        
        // the highlightStartTag and highlightEndTag parameters are optional
        if ((!highlightStartTag) || (!highlightEndTag)) 
        {
            if(color < colors.length && color >= 0)
            {
                highlightStartTag = "<font style='color:black; background-color:" + colors[color] + ";'>";
                highlightEndTag = "</font>";
            }
            else
            {
                highlightStartTag = "<font style='color:black; background-color:yellow;'>";
                highlightEndTag = "</font>";
            }
        }
  }
  else
  {
        // the highlightStartTag and highlightEndTag parameters are optional
      if ((!highlightStartTag) || (!highlightEndTag)) {
    //    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
        highlightStartTag = "<font style='color:black; background-color:yellow;'>";
        highlightEndTag = "</font>";
      }
  }

  var lcBodyText = bodyText.toLowerCase();
    
while (bodyText.length > 0) 
{
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) 
    {
      newText += bodyText;
      bodyText = "";
    } 
    else 
    {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) 
      {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          //skip if not full word
/*
         lastchar = bodyText.substr(i + lcSearchTerm.length, 1);
         if (isalphanumeric(lastchar)) {
         alert(lastchar+'yes')
         } else {
         alert(lastchar+'no')
         }
*/
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, lcSearchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + lcSearchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually


	var s1 = unescape(window.location);
//	alert(s1);
        if (s1.indexOf("aa") == -1)
        {
        return false;
        }


    var n1 = s1.lastIndexOf('=');
//    alert(n1);
//	alert(n1+' len = '+s1.length);
	var n2 = s1.substring(n1+1,s1.length);
//	alert('aavvv= ['+n2+']');
	if (n2.length > 1 ){
		searchText = n2;
	}else{
		return true;
	}
 
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split("$$");
  }


var tmp;
for(x=0;x<searchArray.length;x++)
{
	for(i=0;i<searchArray.length;i++)
	{
	
		if(searchArray[x].length > searchArray[i].length)
		{
				
			tmp=searchArray[i];
			searchArray[i]=searchArray[x];
			searchArray[x]=tmp;
		}
	}
}


  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }

    return false;
  }

  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
	}
  document.body.innerHTML = bodyText;
  return true;
}
//onload ="Response.Write(sSearchSTR)%>">
function getsearchstring()
{
	var s1 = decodeURI(window.location);
	alert(s1);
//	var spgurly = spgurlz.replace('/%/2/0',' ');
    var n1 = s1.indexOf('=',1);
	alert(n1);
	var n2 = s1.substring(n1+1,s1.len);
	alert(n2);
}
