frmObj = document.form;
/*-- \\\ Begin Tracking Referrer String \\\ -*/
if (document.referrer) {
	//document.writeln('<input type=hidden name=Referrer value="'+document.referrer+'">');
	frmObj.Referrer.value = document.referrer;
}
else {
	//document.writeln('<input type=hidden name=Referrer value="No Referrer">');
	frmObj.Referrer.value = "No Referrer";
}
/*-- /// Finished Tracking Referrer String /// --*/
/*-- \\\ Begin Keyword Extraction Code \\\ --*/
	var SearchEngineVariable = 'q';
	var SearchEngineName = '';
	
	function ReturnSearchEngine()
	{
		if (!document.referrer) {
			return "No Referrer used or allowed to be read.";
		}
		try
		{
			var ref = document.referrer.toLowerCase();
			if (ref.indexOf('google.com') > 0) { SearchEngineName = 'Google.com'; }
			else if (ref.indexOf('yahoo.com') > 0) { SearchEngineName = 'Yahoo.com'; }
			else if (ref.indexOf('aol.com') > 0) { SearchEngineName = 'AOL.com'; }
			else if (ref.indexOf('msn.com') > 0) { SearchEngineName = 'MSN.com'; }
			else if (ref.indexOf('overture.com') > 0) { SearchEngineName = 'Overture.com'; }
			else if (ref.indexOf('oingo.com') > 0) { SearchEngineName = 'Oingo.com'; }
			else if (ref.indexOf('att.net') > 0) { SearchEngineName = 'ATT.net'; }
			else if (ref.indexOf('sba.org') > 0) { SearchEngineName = 'SBA.org'; }
			else if (ref.indexOf('googlesyndication.com') > 0) { SearchEngineName = 'GoogleSyndication.com'; }
			else if (ref.indexOf('myway.com') > 0) { SearchEngineName = 'MyWay.com'; }
			else if (ref.indexOf('netscape.com') > 0) { SearchEngineName = 'Netscape.com'; }
			else if (ref.indexOf('accoona.com') > 0) { SearchEngineName = 'Accoona.com'; }
			else if (ref.indexOf('dogpile.com') > 0) { SearchEngineName = 'Dogpile.com'; }
			else if (ref.indexOf('infospace.com') > 0) { SearchEngineName = 'Infospace.com'; }
			else if (ref.indexOf('verizon.net') > 0) { SearchEngineName = 'Verizon.net'; }
			else if (ref.indexOf('webcrawler.com') > 0) { SearchEngineName = 'Webcrawler.com'; }
			else if (ref.indexOf('business.com') > 0) { SearchEngineName = 'Business.com'; }
			else if (ref.indexOf('mywebsearch.com') > 0) { SearchEngineName = 'MyWebSearch.com'; }
			else if (ref.indexOf('earthlink.net') > 0) { SearchEngineName = 'Earthlink.net'; }
			
			else if (ref.indexOf('alltheweb.com') > 0) { SearchEngineName = 'AllTheWeb.com'; }
			else if (ref.indexOf('searchhippo.com') > 0) { SearchEngineName = 'SearchHippo.com'; }
			else if (ref.indexOf('ask.com') > 0) { SearchEngineName = 'AskJeeves.com'; }
			else if (ref.indexOf('altavista.com') > 0) { SearchEngineName = 'Altavista.com'; }
			else if (ref.indexOf('metacrawler.com') > 0) { SearchEngineName = 'Metacrawler.com'; }
			else if (ref.indexOf('kanoodle.com') > 0) { SearchEngineName = 'Kanoodle.com'; }
			else if (ref.indexOf('metaeureka.com') > 0) { SearchEngineName = 'MetaEureka.com'; }
			else if (ref.indexOf('lycos.com') > 0) { SearchEngineName = 'Lycos.com'; }
			else if (ref.indexOf('teoma.com') > 0) { SearchEngineName = 'Teoma.com'; }
			else if (ref.indexOf('hotbot.com') > 0) { SearchEngineName = 'HotBot.com'; }
			else if (ref.indexOf('gigablast.com') > 0) { SearchEngineName = 'GigaBlast.com'; }
			else if (ref.indexOf('looksmart.com') > 0) { SearchEngineName = 'LookSmart.com'; }
			else if (ref.indexOf('dmoz.org') > 0) { SearchEngineName = 'Dmoz.org'; }
			else if (ref.indexOf('wisenut.com') > 0) { SearchEngineName = 'WiseNut.com'; }
			else if (ref.indexOf('clusty.com') > 0) { SearchEngineName = 'Clusty.com'; }
			
			else if (ref.indexOf('business-advance.com') > 0) { SearchEngineName = 'Business Cash Advance'; }
			else { 
				ref_array = ref.split("/"); // split by "/"
				SearchEngineName = ref_array[2]; // domain should be in position 2 
			}
			return SearchEngineName;
		}
		catch (exception) { KeyWordProcessError('ReturnSearchEngine',exception); }
		return false;
	}
	
	function KeyWordIncludeReferrer()
	{
	   try
	   {
		  var ref = document.referrer.toLowerCase();
		  if (ref.indexOf('google.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('yahoo.com') > 0) { SearchEngineVariable = 'p'; return true; }
		  else if (ref.indexOf('aol.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  else if (ref.indexOf('msn.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('overture.com') > 0) { SearchEngineVariable = 'Keywords'; return true; }
		  else if (ref.indexOf('oingo.com') > 0) { SearchEngineVariable = 's'; return true; }
		  else if (ref.indexOf('att.net') > 0) { SearchEngineVariable = 's'; return true; }
		  else if (ref.indexOf('sba.org') > 0) { SearchEngineVariable = 'show'; return true; }
		  else if (ref.indexOf('googlesyndication.com') > 0) { SearchEngineVariable = 'kw'; return true; }
		  else if (ref.indexOf('myway.com') > 0) { SearchEngineVariable = 'searchfor'; return true; }
		  else if (ref.indexOf('netscape.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  else if (ref.indexOf('accoona.com') > 0) { SearchEngineVariable = 'qt'; return true; }
		  else if (ref.indexOf('dogpile.com') > 0) { SearchEngineVariable = 'web'; return true; }
		  else if (ref.indexOf('infospace.com') > 0) { SearchEngineVariable = 'web'; return true; }
		  else if (ref.indexOf('verizon.net') > 0) { SearchEngineVariable = 'web'; return true; }
		  else if (ref.indexOf('webcrawler.com') > 0) { SearchEngineVariable = 'web'; return true; }
		  else if (ref.indexOf('business.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  else if (ref.indexOf('mywebsearch.com') > 0) { SearchEngineVariable = 'searchfor'; return true; }
		  else if (ref.indexOf('earthlink.net') > 0) { SearchEngineVariable = 'q'; return true; }
		  
		  else if (ref.indexOf('alltheweb.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('searchhippo.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('ask.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('altavista.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('metacrawler.com') > 0) { SearchEngineVariable = 'web'; return true; }
		  else if (ref.indexOf('kanoodle.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  else if (ref.indexOf('metaeureka.com') > 0) { SearchEngineVariable = 'terms'; return true; }
		  else if (ref.indexOf('lycos.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  else if (ref.indexOf('teoma.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('hotbot.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  else if (ref.indexOf('gigablast.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('looksmart.com') > 0) { SearchEngineVariable = 'qt'; return true; }
		  else if (ref.indexOf('dmoz.com') > 0) { SearchEngineVariable = 'search'; return true; }
		  else if (ref.indexOf('wisenut.com') > 0) { SearchEngineVariable = 'q'; return true; }
		  else if (ref.indexOf('clusty.com') > 0) { SearchEngineVariable = 'query'; return true; }
		  
		  else if ( ( ref.indexOf('business-advance.com') > 0) && (ref.indexOf('ovraw') > 0) ) { SearchEngineVariable = 'OVRAW'; return true; }
		  else if (ref.indexOf('business-advance.com') > 0) { SearchEngineVariable = 'lp'; return true; }
		  else { 
		  	ref_array = ref.split("/"); // split by "/"
			SearchEngineVariable = ref_array[3]; // domain should be in position 3 
		  }
	   }
	   catch (exception) { KeyWordProcessError('KeyWordIncludeReferrer',exception); }
	   return false;
	}
	
	function KeyWordGetKeyWordsFromQueryString()
	{
	
	   if (KeyWordIncludeReferrer() == false) { return "Unable to extract keywords, please see Referrer"; }
	
	   var keywords = new Array();
	   var ref = document.referrer;
	   var pair;
	   var qIndex = 0;
	   var qs;
	   var prm;
	   var outputwords;
	
	   try
	   {
		 qIndex = ref.indexOf('?');

		 if ( qIndex < 1 && SearchEngineVariable != 'web' ) { return "Unable to extract keywords, please see Referrer"; }
		 
		 ref = KeyWordReplace(ref,'%22','');
		 ref = KeyWordReplace(ref,'%24','$'); // replacing %24 with $
		 ref = KeyWordReplace(ref,'%25','%'); // replacing %25 with %
		 ref = KeyWordReplace(ref,'%26','&'); // replacing %26 with &
		 ref = KeyWordReplace(ref,'%2B','+'); // replacing %2B with +
		 ref = KeyWordReplace(ref,'%2F','/'); // replacing %2F with /
		 ref = KeyWordReplace(ref,'%3A',':'); // replacing %3A with :
		 ref = KeyWordReplace(ref,'%3D','='); // replacing %3D with =
		 ref = KeyWordReplace(ref,'%3F','?'); // replacing %3F with ?
		 ref = KeyWordReplace(ref,'%40','@'); // replacing %40 with @
		 
		 if ( qIndex < 1 && SearchEngineVariable == 'web' ) { // handle strange referrers
			temp = ''; // will hold what comes after web/
		 	ref_array = ref.split("/"); // split by "/"
			for ( i=0; i<ref_array.length; i++ )
		 	{
				if( ref_array[i] == 'web' )	{temp = ref_array[i+1]; break;}
			}
			for ( i=0; temp.indexOf('+') > 0; i++ ) // as long as there's a + in the string
			{
				//document.writeln("Loop Count " + i );
				temp = temp.replace('+',' '); // replace + with a space
			}
			return temp;
		 }
	
		 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); }
	   outputwords = keywords.join(" "); // put spaces between words
	   if ( outputwords == '' ) { outputwords = "No keywords to extract"; }
	   return outputwords;
	}
	
	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;
	}

/*-- /// Finished Keyword Extraction Code /// --*/

/*-- \\\ Begin Returning Search Engine Name \\\ -*/

	//document.writeln('<input type=hidden name=SearchEngine value="'+ ReturnSearchEngine() + '">');
	frmObj.SearchEngine.value = ReturnSearchEngine();
	//alert(ReturnSearchEngine());

/*-- /// Finished Returning Search Engine Name /// --*/

/*-- \\\ Begin Performing Keyword Extaction \\\ --*/

	//document.writeln('<input type=hidden name=Keywords value="'+ KeyWordGetKeyWordsFromQueryString() + '">');
	frmObj.Keywords.value = KeyWordGetKeyWordsFromQueryString();
	//alert(KeyWordGetKeyWordsFromQueryString());
/*-- /// Finished Performing Keyword Extaction /// --*/