function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function delete_cookie( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

 function trash_search(id)
{
delete_cookie('_search');
  document.getElementById(id).innerHTML = "";


} 

function showUser(str)
{
 if(document.getElementById("textfield").value!=""){
   
   var v1=document.getElementById("textfield").value;
   }
 else
    return "";  
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
if(str=="bing")
xmlhttp.open("GET","bing.php?search="+v1,true);
else  
xmlhttp.open("GET","googleSearch.php?search="+v1,true);

xmlhttp.send();
}    
     
  
var mytext = document.getElementById("textfield");
    mytext.focus();
  
       
       
       
       
       var s1="";
        var s2="";
        if(document.cookie&&document.cookie!=''){
          s1=ReadCookie("_search");
        
           }
             var arr1 = s1.split(',');

        if(arr1.length>8)
        arr1.splice(1,1); 
        var k=0;
        var k1=document.getElementById("textfield").value;
        k1=k1.toLowerCase();
        if(k1&&k1!=""&&k1!=undefined){
        var l=arr1.length;
        for(var i=1;i<l;i++){
        if(arr1[i]==k1){
          arr1.splice(i,1);
            k=1;
     
            break;
            }
         }

        arr1.push(k1);
  
        for(var i=1;i<arr1.length;i++){
        s2=s2+","+arr1[i];
        }
  
      SetCookie("_search",s2,2);
      }   
       arr2 = s2.split(',');
      if(s2!=""){  
      for(var i=0;i<arr2.length;i++){
   document.write("&nbsp&nbsp<a href=\"index.php?search="+arr2[i]+"\">"+arr2[i]+"</a>");
       
      }
      document.write("&nbsp<input name='button'  class='trash-button' type='button' id='button' value='' style='cursor:pointer;cursor:hand;' onclick=trash_search('sh') />");
      }
      else if(s1!=""){
      for(var i=0;i<arr1.length;i++){
      document.write("&nbsp&nbsp<a href=\"index.php?search="+arr1[i]+"\">"+arr1[i]+"</a>");
       
      }
       
       document.write("&nbsp<input name='button'  class='trash-button' type='button' id='button' value='' style='cursor:pointer;cursor:hand;' onclick=trash_search('sh') />");
       }
             
