// JavaScript Document

//Change cursor to pointer
function cursor_url(e) 
{
	e.style.cursor='pointer';
}

// Returns the cursor to the default pointer
function cursor_clear() 
{
	document.body.style.cursor = 'default';
}

//Create new cookie
function createCookie(name,value,days) 
{
	if (days) 
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

//Read cookie
function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//-- Auto/Organic Sources and Keywords
var _uOsr=new Array();
var _uOkw=new Array();
_uOsr[0]="google";	_uOkw[0]="q";
_uOsr[1]="yahoo";	_uOkw[1]="p";
_uOsr[2]="msn";		_uOkw[2]="q";
_uOsr[3]="aol";		_uOkw[3]="query";
_uOsr[4]="lycos";	_uOkw[4]="query";
_uOsr[5]="ask";		_uOkw[5]="q";
_uOsr[6]="altavista";	_uOkw[6]="q";
_uOsr[7]="search";	_uOkw[7]="q";
_uOsr[8]="netscape";	_uOkw[8]="query";
_uOsr[9]="earthlink";	_uOkw[9]="q";
_uOsr[10]="cnn";	_uOkw[10]="query";
_uOsr[11]="looksmart";	_uOkw[11]="key";
_uOsr[12]="about";	_uOkw[12]="terms";
_uOsr[13]="excite";	_uOkw[13]="qkw";
_uOsr[14]="mamma";	_uOkw[14]="query";
_uOsr[15]="alltheweb";	_uOkw[15]="q";
_uOsr[16]="gigablast";	_uOkw[16]="q";
_uOsr[17]="voila";	_uOkw[17]="kw";
_uOsr[18]="virgilio";	_uOkw[18]="qs";
_uOsr[19]="teoma";	_uOkw[19]="q";


_ur=document.referrer;

//-- Auto/Organic Keywords to Ignore
var _uOno=new Array();
//_uOno[0]="urchin";
//_uOno[1]="urchin.com";
//_uOno[2]="www.urchin.com";

function _uOrg() 
{
	 if (_ur=="0" || _ur=="" || _ur=="-") return "";
	 var i=0,h,k;
	 if ((i=_ur.indexOf("://")) < 0) return "";
	 h=_ur.substring(i+3,_ur.length);
	 if (h.indexOf("/") > -1) 
	 {
  		h=h.substring(0,h.indexOf("/"));
 	 }
 	for (var ii=0;ii<_uOsr.length;ii++) 
	{
  		if (h.toLowerCase().indexOf(_uOsr[ii].toLowerCase()) > -1) 
		{
   			if ((i=_ur.indexOf("?"+_uOkw[ii]+"=")) > -1 || (i=_ur.indexOf("&"+_uOkw[ii]+"=")) > -1) 
			{
    			k=_ur.substring(i+_uOkw[ii].length+2,_ur.length);
    			if ((i=k.indexOf("&")) > -1) k=k.substring(0,i);
   		 		for (var yy=0;yy<_uOno.length;yy++) 
				{
    	 			if (_uOno[yy].toLowerCase()==k.toLowerCase()) { _ufno=1; break; }
   	 			}
    			return h+'|'+unescape(k);
   			}
  		}
 	}
    return _ur;
}

function replacechars(k) 
{
	out = "+"; // replace this
	add = " "; // with this
	temp = "" + k; // temporary holder
	
	while (temp.indexOf(out)>-1) 
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function GetDomain ()
{

	_cd = document.location.href;

	 if (_cd=="0" || _cd=="" || _cd=="-") return "";
	 var i=0,h,k;
	 if ((i=_cd.indexOf("://")) < 0) return "";
	 h=_cd.substring(i+3,_cd.length);
	 if (h.indexOf("/") > -1) 
	 {
		h=h.substring(0,h.indexOf("/"));
	 }
	 
	 if (i=h.indexOf("www.") > -1) 
	 {
		h=h.substring(i+4,h.length);
	 }
	 
	 return h;
}

function init_quote ()
{
	d =  GetDomain ();
	if ( readCookie(d) == null )
	{		
		k = _uOrg();
		k = replacechars(k);
		createCookie(d.toLowerCase(),k,14); 
	}
		
}

window.onload = init_quote;

