// File Name : fadein.js
// Usage : used to display the window fadein functionality in Hover Ad

ie  = (document.all && document.getElementById); // stores type of browser
ns6 = (!document.all && document.getElementById); // stores type of browser
var dom=document.getElementById // stores type of browser
var ns4=document.layers // stores type of browser
var calunits=document.layers? "" : "px" // stores measuring units for netscape 

var bouncelimit=32 //(must be divisible by 8) to store window bouncing limits
var direction="up" // stores the direction whether going up/down

opac = 0; // start value of opacity 
var Intime // time before the window actually appears completely
var Outtime // time before the window actually disappears completely
var Delaytime // time beofre the start of fadein functionality
opac2 = 100; // last value of opacity 
var expDays = 999; // number of days the cookie should last
var	chkshow=false;

// function is called to start the window appearance in fadein mode

function initbox()
{
	fadeIn();
}

//fades layer in

function fadeIn() {
	document.getElementById('dropin').style.visibility="visible";
	if(opac != 100){
		opac+=5;
		if(navigator.userAgent.indexOf("Opera")>0)
		{
			document.getElementById("dropin").style.visibility = 'visible'
		}
		else
		{
			if(ie) document.getElementById('dropin').filters.alpha.opacity = opac;
			if(ns6) document.getElementById('dropin').style.MozOpacity = opac/100;
			setTimeout('fadeIn()', Intime);
		}
	
	}
}

//fades layer out

function fadeOut() {
	if(opac2 > 0){
		opac2-=5;
		if(navigator.userAgent.indexOf("Opera")>0)
		{
			document.getElementById("dropin").style.visibility = 'hidden'
			document.getElementById("dropin").innerHTML=''
		}
		else
		{
			if(ie)
			{
				document.getElementById('dropin').filters.alpha.opacity = opac2;
				if(document.getElementById('dropin').filters.alpha.opacity==0)
				{
					stopsound()
				}
			}
			if(ns6)
			{
				document.getElementById('dropin').style.MozOpacity = opac2/100;
				if(document.getElementById('dropin').style.MozOpacity==0)
				{
					stopsound()
				}
			}
		}
		setTimeout('fadeOut()', Outtime);
	}
}

// function is called to close the window on close button click

function dismissbox(){
	fadeOut()
}

// function is used to stop the sound played

function stopsound()
{
	document.getElementById("dropin").innerHTML=''
}


// funciton to set the browser cookie
// parameter : name -> name of the cookie
// parameter : value -> value of the cookie

function SetCooKie(name,value)
{
	var argv=SetCooKie.arguments;		//variable for storing name of the cookie
	var argc=SetCooKie.arguments.length	//variable for storing the length of the cookie
	var expires=(argc>2) ? argv[2] : null	//expiration of cookie
	var path=(argc>3) ? argv[3] : null	//path of cookie i.e. where the cookie is getting saved
	var domain=(argc>4) ? argv[4] : null	//domain of cookie 
	var secure=(argc>5) ? argv[5] : false	//security of the cookie
	document.cookie=name + "=" +escape(value) + 
	((expires==null) ? "" :( ";expires=" + expires.toGMTString())) +
	((path==null) ? "" :( ";path=" + path)) +
	((domain==null) ? "" :( ";domain=" + domain)) +
	((secure==true) ? "; secure " : "")
	
}

// funciton to set the browser cookie

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}

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)
{  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(name)
{
var count = GetCookie(name)
	if(count == null)
	{
		SetCookie(name,'1')
		return 1
	}
	else
	{
		var newcount = parseInt(count) + 1;
		DeleteCookie(name)
		SetCookie(name,newcount,exp)
		return count
	}
}

function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount(name) {
var count = GetCookie(name);
if (count == null) {
count=1;
SetCookie(name, count, exp);
}
else {
count++;
SetCookie(name, count, exp);
chkshow=true;
   }
}


// function dropin is called from html file to bounce the window with the parameters set by the user
// parameter : main_bgcolor -> background color of the window
// parameter : main_texttype -> text font style
// parameter : main_textsize -> text font size
// parameter : main_textcolor -> text color
// parameter : textbar -> text font style
// parameter : height -> text font style
// parameter : width -> text font style
// parameter : top -> top position of the window
// parameter : left -> left position of the window
// parameter : bordercolor -> border color of the window
// parameter : borderstyle  -> border style of the window
// parameter : borderwidth  -> border width of the window
// parameter : FadeInTime -> delay seconds after which fade in window appears
// parameter : FadeOutTime -> delay seconds after which fade in window disappears
// parameter : Delay  -> delay seconds after which window appears
// parameter : showeverytime  -> true/false once for each user or not

function DropIn(main_bgcolor,main_texttype,main_textsize,main_textcolor,textbar,height,width,top,left,bordercolor,borderstyle,borderwidth,FadeInTime,FadeOutTime,Delay,showeverytime)
{
	lpos = top
	tpos = left
	hheight=height
	hwidth=width
	Intime=FadeInTime*60
	Outtime=FadeOutTime*60
	Delaytime=Delay*1000
	ans="no"
	chkshow=false;
	if (!showeverytime)
	{
		checkCount("popdrop")
	}
	else
	{
		DeleteCookie("popdrop")
	}
	if(!chkshow)
	{ 
		if (ns4)
		{
			templayer=document.layers[0]				
			templayer.left=left				
			templayer.top=top
			templayer.width=width
			templayer.height=height
		}
		else if (ns6)
		{
			if(borderstyle=="double" && borderwidth==1)
			{
				borderwidth=2
			}
			document.getElementById("tbl").style.border = bordercolor+' '+borderwidth+'px '+borderstyle
			document.getElementById("dropin").style.height=height +'px'
			document.getElementById("dropin").style.width =width +'px'
			document.getElementById("dropin").style.left =left +'px'
			document.getElementById("dropin").style.top =top +'px'
			document.getElementById("dragtext").style.backgroundColor=main_bgcolor
			document.getElementById("dragtext").style.color = main_textcolor
			document.getElementById("dragtext").style.fontFamily = main_texttype
			document.getElementById("dragtext").style.fontSize = main_textsize+'px'
			document.getElementById('dropin').style.MozOpacity = opac/100;
		}
		else 
		{
			document.getElementById("tbl").style.border = bordercolor+' '+borderwidth+'px '+borderstyle
			document.getElementById("dropin").style.height=height +'px'
			document.getElementById("dropin").style.width =width +'px'
			document.getElementById("dropin").style.left =left +'px'
			document.getElementById("dropin").style.top =top +'px'
			document.getElementById("dragtext").style.backgroundColor=main_bgcolor
			document.getElementById("dragtext").style.color = main_textcolor
			document.getElementById("dragtext").style.fontFamily = main_texttype
			document.getElementById("dragtext").style.fontSize = main_textsize+'px'
		}
		setTimeout('initbox()', Delaytime)
	}
	if(chkshow)
	{ 
		document.getElementById("dropin").innerHTML=''
	}
}