	//Cookie Functions
	//Copyright 2005-2006 Lezon Corporation

	//This script cannot be used on sites other than
	//those authorized by Lezon Corporation. 
	
	//Contact: support@lezon.com
	//Last Updated: 11/14/05
	
		
		
	var SearchEngineVariable = 'q';
	
	function KeyWordIncludeReferrer()
	{
	   try
	   {
		  var ref = document.referrer.toUpperCase();
		  if (ref.indexOf('GOOGLE.COM') > 0) { SearchEngineVariable = 'q'; return true; }
		  if (ref.indexOf('YAHOO.COM') > 0) { SearchEngineVariable = 'p'; return true; }
		  if (ref.indexOf('LOCALHOST') > 0) { SearchEngineVariable = 'q'; return true; }
	   }
	   catch (exception) { KeyWordProcessError('KeyWordIncludeReferrer',exception); }
	   return false;
	}
	
	
	function KeyWordIncludeUrl()
	{
		var Href = document.location.href.toUpperCase();
	 
		try
		{
		  if (Href.indexOf('/myfoldertoinclude/') > -1 ) { return true; }
		  if (Href.indexOf('LOCALHOST') > -1 ) { return true; }	
		}
		catch (exception) { KeyWordProcessError('KeyWordIncludeUrl',exception); }
		return false;
	}
	
	
	
	function KeyWordGetColor(idx)
	{
		var color = '#CCCCCC';
	
		switch (idx)
		{
		   case 0:
			   color='#99FF99'; break;
		   case 1:
				   color='yellow'; break;
		   case 2:
				   color='#FFCCFF'; break;
		   case 3:
				   color='#CC99FF'; break;
		   case 4:
				   color='#99CCFF'; break;
		   case 5:
				   color='#FFCC99'; break;
		   case 6:
				   color='#CCCCFF'; break;
		   case 7:
				   color='#66CCFF'; break;
		   default:
				   break;
		}
		return color;
	}
	
	
	 function KeyWordExcludePhrase(keyword)
	 {
	
		var ret = false;
	
		switch (keyword.toUpperCase())
		{
		  case 'AND' :                         return true;
		  case 'OR' :                          return true;
		  case 'SITE:EGGHEADCAFE.COM' :        return true;
		  case 'SITE:WWW.EGGHEADCAFE.COM' :    return true;
		  case '' :                            return true;
		}
			 
		return false;
	 }
	
	  
	
	function KeyWordGetKeyWordsFromQueryString()
	{
	
	   if (KeyWordIncludeReferrer() == false) { return true; }
	
	   var keywords = new Array();
	   var ref = document.referrer;
	   var pair;
	   var qIndex = 0;
	   var qs;
	   var prm;
	
	   try
	   {
	
		
		 qIndex = ref.indexOf('?');
	
		 if (qIndex < 1) { return keywords; }
		 
		 ref = KeyWordReplace(ref,'%22','');
	
		 qs = ref.substring(qIndex + 1,ref.length);
	
		 prm = qs.split('&');
	
		 for (i=0;i<prm.length;i++)
		 {
	
		   pair = prm[i].split('=');
	
		   temp = unescape(pair[0]).split('+');
		   name = temp.join(' ');
	
		   if (name != SearchEngineVariable) { continue; }
	
		   temp = unescape(pair[1]).split('+');
			 
		   for(k=0;k<temp.length;k++)
		   {
			 if (KeyWordExcludePhrase(temp[k]) == true) { continue; }
			 keywords.push(temp[k]);
		   }
			
		 }
	
	   }
	   catch (exception) { KeyWordProcessError('KeyWordGetKeyWordsFromQueryString',exception); }
	   
	   get_set_var_cookie("_keywords", keywords.join(' '));
	   return keywords;
	}
	
	
	function KeyWordHiLite()
	{ 
	 
	  if (KeyWordIncludeUrl() == false) { return true; }
	 
	  var Links;
	  var rng;
	  var before = '&nbsp;<font style="color: #000000;text-decoration:none;background-color: ';
	  var after = '</b>&nbsp;</font>&nbsp;';
	
	  try
	  {
		 
		keywords = KeyWordGetKeyWordsFromQueryString();
	
		if (keywords.length < 1) { return true; }
	 
		Links = KeyWordGetLinks();
	
		for(k=0;k<keywords.length;k++)
		{
	
		  rng = document.body.createTextRange();  
	  
		  for (i=0;rng.findText(keywords[k])!=false; i++)
		  { 
	 
			try       { rng.pasteHTML(before + KeyWordGetColor(k) + ';">&nbsp;<b>' +  rng.text + after);   }
			catch (e) { KeyWordProcessError('KeyWordHiLite Text Range',e);    }	
			finally   { rng.collapse(false); }
		  
		  }
	
		  rng.collapse(true);
		}
	
		KeyWordCleanLinks(Links);
			
	  }
	  catch (exception) { KeyWordProcessError('KeyWordHiLite',exception); }
	  
	}
	
	
	
	function KeyWordGetLinks()
	{
	
	   var Links = new Array();
	   
	   for (i=0;i<document.body.getElementsByTagName('A').length;i++)
	   {
		  Links[i] = new Array (document.body.getElementsByTagName('A')[i].href, document.body.getElementsByTagName('A')[i].innerHTML); 
	   }
	
	   return Links;
	}
	
	
	
	function KeyWordCleanLinks(Links)
	{
	  for (i=0;i<document.body.getElementsByTagName('A').length;i++)
	  { 
		document.body.getElementsByTagName('A')[i].href = Links[i][0]; 
		document.body.getElementsByTagName('A')[i].innerHTML = Links[i][1];
	  }
	}
	
	
	function KeyWordProcessError(functionName,e)
	{
	  if (e.description == null)
	  {
	//	  alert(functionName + ' ' + e.message); 
	  }
	  else
	  { 
		//  alert(functionName + ' ' + e.description);
	  }
	}
	
	function KeyWordReplace(OrgVal,SearchVal,ReplaceVal)
	{
	  var Val;
	  var RegExp = eval("/" + SearchVal + "/g");
	  if (OrgVal.indexOf(SearchVal) <1) {  return OrgVal; }
	  Val = OrgVal.replace(RegExp,ReplaceVal);
	  return Val;
	}

	
	function get_price(){
		var mPrice;
		
		mPrice=get_set_var_cookie("_price", "");
		if(mPrice==null){
			return 249.99;
		}else if(mPrice=="" || mPrice=="0"){
			return 249.99;
		}else{
			return mPrice;
		}
	} 
	
	function get_set_var_cookie(var_in, var_out){
		var current_in=getCookie("_" + var_in);
		var expdate = new Date ();
		expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 91));
		
		if(current_in==null || var_out.length > 0){
			setCookie ("_" + var_in, var_out, expdate);
			return "";
		}else{
			return current_in;
		}
	}		
	
	function get_keyword_cookie(){
		var current_keyword=getCookie("_keyword");
		var expdate = new Date ();
		expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 91));

		if(current_keyword==null){
			setCookie ("_keyword", "", expdate);
			return "";
		}else{
			return current_keyword;
		}
	}	
	
	function set_keyword_cookie(keyword_val){
		var expdate = new Date ();
		expdate.setTime (expdate.getTime() + (1000 * 60 * 60 * 24 * 91));

		setCookie ("_keyword", keyword_val, expdate);
	}
	 
	function setCookie (name, value, expires) {
        if (!expires) expires = new Date();
    	document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +  "; path=/"; 
    }  
	
	function getCookie (name) {
		var dcookie = document.cookie; 
		var cname = name + "=";
		var clen = dcookie.length;
		var cbegin = 0;
			while (cbegin < clen) {
			var vbegin = cbegin + cname.length;
				if (dcookie.substring(cbegin, vbegin) == cname) { 
				var vend = dcookie.indexOf (";", vbegin);
					if (vend == -1) vend = clen;
				return unescape(dcookie.substring(vbegin, vend));
				}
			cbegin = dcookie.indexOf(" ", cbegin) + 1;
				if (cbegin == 0) break;
			}
		return null;
    }
	
	function delCookie (name) {
	    var expireNow = new Date();
    	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
    }