adTime=1;  // seconds ad reminder is shown
chanceAd=1; // ad will be shown 1 in X times (put 1 for everytime)
var displaytime

var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"
var ns6=document.getElementById&&!document.all
var g_bodyText;
var f_part;
var s_part;
var tm;

adCount=0;
function delay(x)
{
	var d=new Date()
	d=d.getSeconds()+x
	if (d>=60) d=d-60
	while (true)
	{
		var d1=new Date()
		if(d==d1.getSeconds())
			break;
	}	
}
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 + "=" +escape(value) + 
	((expires==null) ? "" :( ";expires=" + expires.toGMTString())) +
	((path==null) ? "" :( ";path=" + path)) +
	((domain==null) ? "" :( ";domain=" + domain)) +
	((secure==true) ? "; secure " : "")
}

function DeleteCookie (name,path,domain) 
{
if (GetCookie(name)) {
		document.cookie = name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}



function GetCookie(name)
{	
	var arg=name + "=" 
	var alen=arg.length
	var clen=document.cookie.length
	var i=0,prev=0;next=0;
	var retval=false;
	while(true)
	{
		next=document.cookie.indexOf("; ", prev);
		if(next<=0)
		{
			var chkval=document.cookie.substring(prev,clen);
			var eqpos=chkval.indexOf("=", 0);
			if(eqpos>0)
			{
				if((chkval.substring(0,eqpos+1))==arg)
				{
					retval=true;
					break;
				}	
			}	
			break;				
		}
		if(next>0)
		{
			var chkval=document.cookie.substring(prev,next);
			var eqpos=chkval.indexOf("=", 0);
			if(eqpos>0)
			{
				if((chkval.substring(0,eqpos+1))==arg)
				{
					retval=true;
					break;
				}	
			}
			
		}
		prev=next+2;	
	}
	return retval;
}



function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf(";",offset)
	if(endstr==-1)
	{
		endstr=document.cookie.length;
	}
	return unescape(document.cookie.substring(offset,endstr));

}


// Writes the current time in the clock <div>
function setClock()
{
	if (tm >= 0)
	{
		bodyText = f_part+tm+s_part;
		document.getElementById("dragtext").innerHTML=bodyText;
		//set a timer to change the clock every second
		tm--;
		timer = setTimeout("setClock()",1000);
	}
}


function AdPopUp(pleft,ptop,pheight,pwidth,bordercolor,borderstyle,borderwidth,backgroundcolor,sec,showeverytime,bodytext,dtime)
{
displaytime = dtime;
	//if (sec>0)
	//delay(sec);
	var chkshow=false;
	if (!showeverytime)
	{
		chkshow=GetCookie('adpop');
		if (!chkshow)
			SetCooKie('adpop','added')		
	
	}
	else
	{
		DeleteCookie('adpop','','')
	}


	if(!chkshow)
	{ 		

	setTimeout("Delaynew()",(sec*1000));

	if(!ns && !ie && !w3) return;
	if(ie)		adDiv=eval('document.all.sponsorAdDiv.style');
	else if(ns)	adDiv=eval('document.layers["sponsorAdDiv"]');
	else if(w3)	adDiv=eval('document.getElementById("sponsorAdDiv").style');
	if(ie){ 
		//document.all.border2.style.color='red'
		document.all.border2.style.backgroundColor=backgroundcolor
		document.all.border1.style.backgroundColor=bordercolor 
		document.all.border1.style.border = borderwidth+'px '+borderstyle+' '+bordercolor
		document.all.border1.width=pwidth + calunit
		document.all.border2.width=(pwidth-(borderwidth * 2)) + calunit
		document.all.border1.height=pheight + calunit
		document.all.border2.height=(pheight-(borderwidth * 2)) + calunit
var tempText=bodytext.toLowerCase();
i_o = tempText.indexOf("&lt;timer&gt;");
f_part = bodytext.substr(0,i_o);
s_part = bodytext.substr(i_o+13,bodytext.length);
tm = dtime;
	}
	else if(ns6) {
		document.getElementById("border1").style.backgroundColor=bordercolor
		document.getElementById("border1").style.border = borderwidth+'px '+borderstyle+' '+bordercolor
		document.getElementById("border2").style.backgroundColor=backgroundcolor
		//document.getElementById("border2").style.color="white"
		document.getElementById("border1").style.width=pwidth + calunit
		document.getElementById("border2").style.width=pwidth + calunit
		document.getElementById("border1").style.height=pheight + calunit
		document.getElementById("border2").style.height=pheight + calunit
		document.getElementById("dragtext").innerHTML=bodytext
	}	
	randAd=Math.ceil(Math.random()*chanceAd);
      /*  if (ie||w3)
        adDiv.visibility="visible";
        else
        adDiv.visibility ="show";
	*/
	if(randAd==1) showAd(pleft,ptop,pheight,pwidth);
	}
if(i_o>0)
	setClock();
else
	document.getElementById("dragtext").innerHTML=bodytext;
	

	
}
function showAd(pleft,ptop,pheight,pwidth){
if(adCount<adTime*1){adCount+=1;
	if (ie){documentWidth  =truebody().offsetWidth/2+truebody().scrollLeft-20;
	documentHeight =truebody().offsetHeight/2+truebody().scrollTop-20;}	
	else if (ns){documentWidth=window.innerWidth/2+window.pageXOffset-20;
	documentHeight=window.innerHeight/2+window.pageYOffset-20;} 
	else if (w3){documentWidth=self.innerWidth/2+window.pageXOffset-20;
	documentHeight=self.innerHeight/2+window.pageYOffset-20;} 
	//adDiv.left=documentWidth-200+calunit;adDiv.top =documentHeight-200+calunit;
	if(pleft>0)	{adDiv.left=pleft+calunit }
	if(ptop>0)	{adDiv.top=ptop+calunit }
	if(pheight>0)	{adDiv.height=pheight+calunit }
	if(pwidth>0)	{adDiv.width=pwidth+calunit }

	//str=showAd(" + pleft + "," + ptop + "," + pheight + "," + pwidth + ")

	setTimeout("showAd(" + pleft + "," + ptop + "," + pheight + "," + pwidth + ")",(displaytime * 1000));
	}else closeAd();
}
function closeAd()
{
	if (ie||w3)
	{
		adDiv.display="none";
		document.getElementById("dragtext").innerHTML=''
	}else
	{
		adDiv.visibility ="hide";
		document.getElementById("dragtext").innerHTML=''
	}
}

function truebody(){
return (document.compatMode!="BackCompat")? document.documentElement : document.body
}
function Delaynew()
{
	if (ie||w3)
        adDiv.visibility="visible";
        else
        adDiv.visibility ="show";

	/*if (!ns)
		document.getElementById("sponsorAdDiv").style.visibility="visible";
	else
		document.sponsorAdDiv.visibility="show";
	*/
	return;
}

