var isNav4;
var isIE4;
var isMac;

if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
	isNav4 = (navigator.appName.indexOf("Netscape") != -1 ? true : false);
	isIE4 = (navigator.appName.indexOf("Microsoft") != -1 ? true : false);
	isMac = (navigator.userAgent.indexOf("Mac") != -1 ? true : false);
}
else {
	isNav4 = true;
	isIE4 = false;
	isMac = false;
}

var blue=0;

function SetCookie (name, value)
{
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + value +
    ((expires == '') ? "" : ("; expires=Thursday, 8-April-10 13:26 GMT")) +
    ((path == '') ? "" : ("; path=" + path)) +
    ((domain == '') ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "")
}

function find_substring(needle, srclist)
{
	var i, needlen = needle.length, srclen = srclist.length
	for (i=0; i<=srclen-needlen; i++)
	{
		if (needle == srclist.substring(i,i+needlen))
		{
			return i;
		}
	}
	return false;
}

function closelist()
{
}

function setfocus()
{
	parent.swlogo.document.cogwords.word1.focus();
}

function replaceString(oldS,newS,fullS)
{
	for (var i=0; i<fullS.length; i++)
	{
		if (fullS.substring(i,i+oldS.length) == oldS)
  		{
  			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
  		}
  	}
  	return fullS;
}

function getCookieVal(offset)  //Generic function getting cookie value at a "offset"
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function personalize()
{
	parent.swlist.location='/servlet/com.surfwax.FrontEnd.PersonalSearcher?cmd=showPersonalSearcher';
	if (blue==0)
	{
		if (parent.swbottom) parent.swbottom.location='blue.htm';
		blue=1;
	}
}

function preferences()
{
	parent.swlist.location='/servlet/com.surfwax.FrontEnd.PersonalSearcher?cmd=showPrefs';
	if (blue==0)
	{
 		if (parent.swbottom) parent.swbottom.location='blue.htm';
 		blue=1;
	}
}

function fo(thevalue)  //Function called when Focus is clicked on
{
	thevalue=replaceString(' ', '+', thevalue);
	thevalue=replaceString("%27", "'", thevalue);
	thevalue=replaceString('"', '', thevalue);
	if ((thevalue!='') && (thevalue!=' '))
	{
		parent.swlist.location='/servlet/com.surfwax.FrontEnd.Focus?word='+thevalue;
	}
	else
	{
		parent.swlist.location='/help/tutorials/focus.htm';
	}
	if (blue==0)
	{
		if (parent.swbottom) parent.swbottom.location='/blue.htm';
		blue=1;
	}
}

function help()
{
	parent.swlist.location='/help/tutorials/search.htm';   //;;www.surfwax.com
	if (blue==0)
	{
		if (parent.swbottom) parent.swbottom.location='/blue.htm';
 		blue=1;
	}
}

function slinks(thevalue)  // This function adds words to search box
						   // If the phrase has a space, quotes are added
{
	var t2=parent.swlogo.document.search.search.value, t3=thevalue, t4;
	t3=replaceString('%22', '"', t3);
	t3=replaceString('%27', "'", t3);
	add=1;
	qt3=t3;
	temp=t2;
	if (t3.charAt(0)!='"') qt3='"'+qt3;
	if (t3.charAt(t3.length-1)) qt3=qt3+'"';
	if (existString(qt3, t2)) add=0;
	if (((t3.charAt(0)=='"') && (t3.charAt(t3.length-1)=='"')) && (existString(t3, t2))) add=0;
	if (add==1)
	{
		newt2='';
 		odd=0;
 		for (x=0; x<=temp.length; x++)
 		{
 			if (temp.charAt(x)=='"')
 			{
 				if (odd==0) odd=1; else odd=0;
 			}
 			else
 			{
 				if (odd==0) newt2=newt2+temp.charAt(x);
 			}
 		}
 	}
 	if (existString(t3, newt2)) add=0;
 	if (add==1)
 	{
 		t3=replaceString("%27", "'", t3);
 		t3=replaceString(" ", "_", t3);
 		t3=replaceString('|','"',t3);
 		if (existString("_", t3))
 		{
 	   		t3=replaceString("_", " ", t3);
 		}
 	  	t3=replaceString('%22', '"', t3);
 	 	b=" ";
 	 	if (t2=="")  b="";
  		t4=t2+b+t3;
  		if (t2==" ") t4=t3;
  		parent.swlogo.document.search.search.value = t4;
	}
}

function sl(thevalue)      // This function adds words to search box
						   // This functions doesn't add quotes like slinks does
{
	var t2=parent.swlogo.document.search.search.value, t3=thevalue, t4;
	add=1;
	qt3=t3;
	temp=t2;
	if (t3.charAt(0)!='"') qt3='"'+qt3;
	if (t3.charAt(t3.length-1)!='"') qt3=qt3+'"';
	if (existString(qt3, t2)) add=0;
	if (add==1)
	{
		newt2='';
 		odd=0;
 		for (x=0; x<=temp.length; x++)
 		{
 			if (temp.charAt(x)=='"')
 			{
 				if (odd==0) odd=1; else odd=0;
 			}
 			else
 			{
 				if (odd==0) newt2=newt2+temp.charAt(x);
 			}
 		}
 	}
 	if (existString(t3, newt2)) add=0;
 	if (add==1)
 	{
 		t3=replaceString("%27", "'", t3);
 		t3=replaceString(" ", "_", t3);
 		t3=replaceString('|','"',t3);
 		if (existString("_", t3))
 		{
 		if (existString("%22", t3))
 		{}
 		else
 		{
 			if (existString(" ", t3))
 			{}
 			else
 			{t3='"'+t3+'"';}
    	}
    	t3=replaceString("_", " ", t3);
   		}
  		t3=replaceString('%22', '"', t3);
  		t3=replaceString('%27', "'", t3);
  		b=" ";
  		if (t2=="")  b="";
		t4=t2+b+t3;
		if (t2==" ") t4=t3;
		parent.swlogo.document.search.search.value = t4;
	}
}

function mo(thevalue)
{
	parent.swstats.document.stats.statsdata.value=thevalue;
}

function existString(searchS,fullS)
{
	var x=0; //Says string has not been found
	for (var i=0; i<=fullS.length; i++)
	{
		if (fullS.substring(i,i+searchS.length) == searchS)
			x=1;
	}
	return x;
}

function queryString(param)
{
	var begin,end;
	if(self.location.search.length>1)
	{
		begin=self.location.search.indexOf(param + "=") +param.length+1;
		if (begin == -1) return ("");
			end=self.location.search.indexOf("&",begin);
		if(end==(-1)) end=self.location.search.length;
			return(self.location.search.substring(begin,end));
	}
	else if(self.location.hash.length>1)
	{
		begin=self.location.hash.indexOf(param) +param.length+1;
		end=self.location.hash.indexOf("&",begin);
		if(end==(-1)) end=self.location.hash.length;
			return(self.location.hash.substring(begin,end));
	}
	else return("");
}
