/**************************************************************************************************
*  dropin.js 
*
*   Funciones javascript necesarias para los mensajes de alertas (animacion de layer que cae)
**/



var ie=document.all
var dom=document.getElementById
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var calunits=document.layers? "" : "px"

var bouncelimit=32 //(must be divisible by 8)
var direction="up"
var lpos

/**********
* update_iframe_position
*  iguala los estilos del iframe con el layer utilizado para hacer la animación
**/
function update_iframe_position(crossobj){
		var IfrRef = document.getElementById('DivShim'); //iframe para colocar la capa sobre windowed controls
		var __tb_message_box = document.getElementById('__tb_message_box');
		IfrRef.style.top=crossobj.top;
		IfrRef.style.height=__tb_message_box.scrollHeight+5;
		IfrRef.style.width=__tb_message_box.scrollWidth+5;
     	IfrRef.style.visibility= crossobj.visibility;
}

function initbox(id){
	if (!dom&&!ie&&!ns4)
	   return
	   
	crossobj=(dom)?document.getElementById(id).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"
	update_iframe_position(crossobj);
	
	dropstart=setInterval("dropin()",50)
}

function dropin(){
	scroll_top=(ie)? truebody().scrollTop : window.pageYOffset
	if (parseInt(crossobj.top)<lpos){
		crossobj.top=parseInt(crossobj.top)+25+calunits
		//--- frame para cubrir los windowed controls
     	update_iframe_position(crossobj);
	}else{
		clearInterval(dropstart)
		bouncestart=setInterval("bouncein()",50)
	}
}

function bouncein(){
	crossobj.top=parseInt(crossobj.top)-bouncelimit+calunits
	//--- frame para cubrir los windowed controls
	update_iframe_position(crossobj);
	if (bouncelimit<0)
		bouncelimit+=8
	bouncelimit=bouncelimit*-1
	if (bouncelimit==0){
		clearInterval(bouncestart)
	}
}
//---- ocultamos/muestra el iframe que sirve como cubierta de controles de formulario
 function DivSetVisible(state) {
   var DivRef = document.getElementById('message_box');
   var IfrRef = document.getElementById('DivShim');
   var __tb_message_box = document.getElementById('__tb_message_box');

   if(state)  {
    DivRef.style.display = "block";
    IfrRef.style.width = DivRef.offsetWidth;
    IfrRef.style.height = DivRef.offsetHeight;
    IfrRef.style.top = DivRef.style.top;
    IfrRef.style.left = DivRef.style.left;
    IfrRef.style.width = DivRef.style.width;
    IfrRef.style.height = __tb_message_box.style.height;
    IfrRef.style.zIndex = DivRef.style.zIndex - 1;
    IfrRef.style.display = "block";


   }  else   {
    DivRef.style.display = "none";
    IfrRef.style.display = "none";
   }
  }

function dismissbox(){
		if (window.bouncestart) clearInterval(bouncestart)
		crossobj.visibility="hidden"
		
        DivSetVisible(false);
}

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;
	}	
}
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));

}
function Delaynew(id)
{
	if (!ns4)
	{	
		document.getElementById(id).style.visibility="visible";
			
	}	
	else
		document.dropin.visibility="show";
	
	return;
}


function dropCenter(id,height,width){
	    
		var winW = 630, winH = 460;
		if (parseInt(navigator.appVersion)>3) {
		 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth;
		  winH = window.innerHeight;
		 }
		 if (navigator.appName.indexOf("Microsoft")!=-1) {
		  winW = document.body.offsetWidth;
		  winH = document.body.offsetHeight;
		 }
		}
        var  x = (winW - width)/ 2;
	    DropIn(id,'#FFFFFF','Arial',14,'#000000','',height,width,'150',x,'#000000','none',1,0,true);
}


function DropIn(id,main_bgcolor,main_texttype,main_textsize,main_textcolor,textbar,height,width,top,left,bordercolor,borderstyle,borderwidth,sec,showeverytime)
{
	lpos = top
	ans="no"
	var IfrRef = document.getElementById('DivShim'); //iframe para colocar la capa sobre windowed controls
	//delay(sec)
	var chkshow=false;
	if (!showeverytime)	{
		chkshow=getCookie('popDropin');
		if (!chkshow){
			setCookie('popDropin','added')
		}
	}else{
		deleteCookie('popalert1','','')
	}
		
	
	if(!chkshow)	{ 
		if (ns4){
			templayer=document.layers[0]				
			templayer.left=left				
			templayer.top=top
			templayer.width=width
			templayer.height=height
		}
		else if (ns6){
			document.getElementById(id).style.height=height +'px'
			document.getElementById(id).style.width =width +'px'
			document.getElementById(id).style.left =left +'px'
			document.getElementById(id).style.top =top +'px'
			
			IfrRef.style.height=height +'px';
			IfrRef.style.width =width +'px';
			IfrRef.style.left =left +'px';
			IfrRef.style.top =top +'px';
		}else {
			document.getElementById(id).style.height=height +'px'
			document.getElementById(id).style.width =width +'px'
			document.getElementById(id).style.left =left +'px'
			document.getElementById(id).style.top =top +'px'
		    IfrRef.style.height=height +'px';
			IfrRef.style.width =width +'px';
			IfrRef.style.left =left +'px';
			IfrRef.style.top =top +'px';
		}
		setTimeout("initbox('"+id+"')",(sec*1000));	
	}
}
