// JavaScript Document

/////// CODE FOR POP UP BASED ON BROWSING HISTORY ////////

function nameDefined(ckie,nme)
{
   var splitValues;
   var i;
   for (i=0;i<ckie.length;++i)
   {
      splitValues=ckie[i].split("=")
      if (splitValues[0] == nme) 
	  {
	  	return true;
	  }
   }
   return false;
}

function delBlanks(strng)
{
   var result="";
   var i;
   var chrn;
   for (i=0;i<strng.length;++i) 
   {
      chrn=strng.charAt(i);
      if (chrn != " ") 
	  	result += chrn;
   }
   return result;
}

function getCookieValue(ckie,nme)
{
   var splitValues;
   var i;
   for(i=0;i<ckie.length;++i) 
   {
      splitValues = ckie[i].split("=");
      if (splitValues[0] == nme)
	  	return splitValues[1]
   }
   return "";
}

function insertCounter(popup,type,file) 
{
	 readCookie();
	 displayCounter(popup,type,file);
}

function displayCounter(popup,type,file) 
{
	 if (counter == 1)
	 {
		if (type == 'doc')
		{
			window.location = 'admin/uploads/pdfs/'+file;
		}
		else
		{
			window.open('invitation/'+popup,'theHamelsFoundation','width=900px,height=550px,resizable=no,scrollbars=1');
		}
	}
}

function readCookie() 
{
	 var cookie = document.cookie;
	 counter = 0;
	 var chkdCookie = delBlanks(cookie);  //are on the client computer
	 var nvpair = chkdCookie.split(";");
	 if (nameDefined(nvpair,"pageCount"))
	 {
	 	counter = parseInt(getCookieValue(nvpair,"pageCount"));
	 }
	 ++counter;
	 var futdate = new Date();
	 var expdate = futdate.getTime();
	 expdate += 3600000 * 24 *30;  //expires in 1 hour
	 futdate.setTime(expdate);
	
	 var newCookie="pageCount="+counter;
	 newCookie += "; expires=" + futdate.toGMTString();
	 window.document.cookie=newCookie;
}

//Scroller class
function Scroller(id)
{
	this.id = document.getElementById(id);
	this.timer = null;
	this.speed = 200;
	this.scroll();

	this.obj = this;
	this.obj.onmouseover = function(){obj.stop_scroll();};
	this.obj.onmouseout = function(){obj.scroll();};
}

Scroller.prototype.scroll = function()
{
	var text = this.id.firstChild.nodeValue;
	if (text.length > 0) {
		text = text.substring(1, text.length) + text.substring(0, 1);
		this.id.firstChild.nodeValue = text;
		
		var obj = this;
		this.timer = setTimeout(function(){obj.scroll();}, this.speed);
	}
}

Scroller.prototype.stop_scroll = function()
{
if (this.timer)
{
clearTimeout(this.timer);
}
}
