function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// Apogee code

function setCookie(c_name,value)
{
	var exdate=new Date();
	// Cookie Expires in 1000 days
	exdate.setTime(exdate.getTime()+(1000*60*60*24*1000));
	document.cookie=c_name + "=" + escape(value) + (";expires="+exdate.toGMTString()) + ";path=/;domain=nimsoft.com;";
} 

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	  { 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
	  } 
	}
	return "";
} 

function checkCookie(name)
{
	value=getCookie(name);
	return value;
}

function getRef()
{
	if (document.referrer != "")
	{
		return unescape(document.referrer);
	}
	else
	{
		return "None";
	}
}

function getPaidKeywordKK()
{
	page_url = unescape(location.href);
	paidKeyword = "None";
	s_index = page_url.indexOf("_kk=");
	
	if(s_index > -1)
	{
		// find the index of the next "&" after "_kk="
		// if it exists, take this section for a cookie
		// otherwise take the rest of the string
		
		next_amp = page_url.indexOf("&", s_index);
		
		if(next_amp > -1)
		{
			paidKeyword = page_url.substr((s_index + 4), (next_amp - (s_index+4)));
		}
		else
		{
			paidKeyword = page_url.substr((s_index + 4));
		}	
	}
		
	return paidKeyword;
}

function getPaidKeyword()
{
	page_url = unescape(location.href);
	paidKeyword = "None";
	s_index = page_url.indexOf("porigin=");
	
	if(s_index > -1)
	{
		// find the index of the next "&" after "porigin="
		// if it exists, take this section for a cookie
		// otherwise take the rest of the string
		
		next_amp = page_url.indexOf("&", s_index);
		
		if(next_amp > -1)
		{
			paidKeyword = page_url.substr((s_index + 8), (next_amp - (s_index+8)));
		}
		else
		{
			paidKeyword = page_url.substr((s_index + 8));
		}	
	}
	else
	{
		paidKeyword = getPaidKeywordKK();
	}
		
	return paidKeyword;
}

function getNaturalKeyword()
{
	ref_url = getRef();
	naturalKeyword = "None";
	s_param = "";
	
	ref_url = ref_url.replace(/aq=/i, "qa=");
	
	// Look for Google or Yahoo in the referring URL
	if( (ref_url.indexOf("google") > -1)&&(ref_url.indexOf("q=") > -1))
	{
		s_param = "q=";
	}
	else
	{
		if((ref_url.indexOf("yahoo") > -1)&&(ref_url.indexOf("p=") > -1))
		{
			s_param = "p=";
		}
	}
	
	// Don't bother searching if it's not a Google or Yahoo query
	if(s_param != "")
	{
		sp_index = ref_url.indexOf(s_param);
		if(sp_index > -1)
		{
			// find the index of the next "&" after the search parameter
			// if it exists, take this section for a cookie
			// otherwise take the rest of the string
			
			next_amp = ref_url.indexOf("&", sp_index);
			
			if(next_amp > -1)
			{
				naturalKeyword = ref_url.substr((sp_index + 2), (next_amp - (sp_index+2)));
			}
			else
			{
				naturalKeyword = ref_url.substr((sp_index + 2));
			}	
		}
	}
	naturalKeyword = naturalKeyword.replace(/\+/g, " ");	
	return naturalKeyword;
}

// writeCookie
// if the cookie has been written once before, don't touch it

if(checkCookie("ref") == "")
{	
	name = "ref";
	value = getRef();
	setCookie(name, value);
	
	name = "pkw";
	value = getPaidKeyword();
	setCookie(name, value);
	
	name = "nkw";
	value = getNaturalKeyword();
	setCookie(name, value);
}


// apogee enquisite code, 29th april 2009

var enqsiteid = '125dca-lqym645';
var enqhost = (window.location.protocol == "https:")
    ? "https://logssl" : "http://log";
document.writeln('<'+'script src="'+ enqhost
    +'.enquisite.com/log.js?id='+ enqsiteid
    +'" type="text/javascript"><'+'\/script>');

