// file name : dropin.js
// Usage : used for dropIn hover ad

var ie=document.all // stores type of browser
var dom=document.getElementById // stores type of browser 
var ns4=document.layers // stores type of browser 
var ns6=document.getElementById&&!document.all // 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
var lpos // stores the left position
var expDays = 999; // number of days the cookie should last
var	chkshow=false;

//function initbox is called from dropin function that makes the windows bounces

function initbox(){
if (!dom&&!ie&&!ns4)
return
crossobj=(dom)?document.getElementById("dropin").style : ie? document.all.dropin : document.dropin
scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
crossobj.top=scroll_top-250+calunits
crossobj.visibility=(dom||ie)? "visible" : "show"

if (hheight<document.getElementById("dropin").offsetHeight)
{
	hheight=document.getElementById("dropin").offsetHeight
}
else
{
	document.getElementById("tbl").style.height=hheight
	document.getElementById("tbl_inn").style.height=hheight
	document.getElementById("dropin").style.height=hheight +'px'
}
if (hwidth<document.getElementById("dropin").offsetWidth)
{
	hwidth=document.getElementById("dropin").offsetWidth
}
else
{
	document.getElementById("tbl").style.width=hwidth
	document.getElementById("tbl_inn").style.width=hwidth
	document.getElementById("dropin").style.width=hwidth +'px'
}

dropstart=setInterval("dropin()",50)
}

// function is called from Html file to bounce the selected window

function dropin()
{
	var sheight=document.body.clientHeight
	var totheight=parseInt(lpos)+parseInt(hheight)
	if (totheight>sheight)
	{
//		lpos=(parseInt(sheight)-parseInt(hheight))-22
	}
	if (parseInt(crossobj.top)<lpos)
	{
		if((parseInt(crossobj.top)+25)>lpos)
		{
		crossobj.top=lpos
		}
		else
		{
		crossobj.top=parseInt(crossobj.top)+25+calunits
		}
	}
	else
	{
		clearInterval(dropstart)
		bouncestart=setInterval("bouncein()",50)
	}
}

// function is called from Html file to bounce in the selected window

function bouncein()
{
	crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
	if (bouncelimit<0)
		bouncelimit+=8
	bouncelimit=bouncelimit*-1
	if (bouncelimit==0)
	{
		clearInterval(bouncestart)
	}
}

// function is called to close the window on close button click

function dismissbox()
{
	if (window.bouncestart) clearInterval(bouncestart)
		crossobj.visibility="hidden"
	document.getElementById("dropin").innerHTML=''
}

// function to set the browser cookie
// parameter : name -> name of the cookie
// parameter : value -> value of the cookie

function truebody(){
return (document.compatMode!="BackCompat")? document.documentElement : document.body
}
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;
	}	
}

// 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 : sec  -> 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,sec,showeverytime)
{
	lpos = top
	hheight=height
	hwidth=width
	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.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'
		}
		else 
		{
			document.getElementById("tbl").style.border = bordercolor+' '+borderwidth+'px '+borderstyle
			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()",(sec*1000));	
	}
	if(chkshow)
	{ 
		document.getElementById("dropin").innerHTML=''
	}
}
