


//MODIFICABLES/////////////////////////////////////////////////
///////////////////////////////////////////////////////////////


//SETEA EL TITULO
function titleInit(title){

	title.className="titulo_popup"
	title.style.background="#0E3C5D"
	title.innerHTML="<a href='javascript:popUP.closePop()' title='Close'>Close</a>";
	
}

//SETEA EL CONTENEDOR
function contentInit(content){
	content.style.border="#0E3C5D 5px solid"
	
}

//SETEA EL IFRAME
function iframeInit(iframe){
	//iframe.style.border="#0000ff 1px solid"
}

//FIN_MODIFICABLES/////////////////////////////////////////////
///////////////////////////////////////////////////////////////





//CÓDIGO FIJO/////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////



var INIT=false
var popUP = new Object()
popUP.destoyObject=null
popUP.tps=500;//tiempo en que tarda en aparecer la capa de sombra
popUP.w=null
popUP.h=null
popUP.content=null
popUP.cw=null//content width
popUP.ch=null//content height
popUP.th=30//title height
popUP.opacity=80 //transparencia del fondo
//DETECCIÓN DE IE6
nav_detection=navigator.userAgent.search(/MSIE 6/)
if(nav_detection>0)var IE6=true
else var IE6=false

nav_detection=navigator.userAgent.search(/MSIE 7/)
if(nav_detection>0)var IE7=true
else var IE7=false


/*window.onload=function(){
	popUP.iframe("http://www.google.com",780)
}*/


//HABRE UN IFRAME
popUP.iframe=function(url,width,height){
	

	this.w=document.documentElement.clientWidth;
	this.h=document.documentElement.clientHeight;

	if(typeof width=="undefined") this.cw=Math.round(this.w*0.8)
	else this.cw=width
	if(typeof height=="undefined") this.ch=Math.round(this.h*0.8)
	else this.ch=height
	if(this.cw>Math.round(this.w*0.8)) this.cw=Math.round(this.w*0.8)
	if(this.ch>Math.round(this.h*0.8))this.ch=Math.round(this.h*0.8)
	popUP.init()
	setTimeout("popUP.openFrame('"+url+"','"+this.cw+"','"+this.ch+"')",popUP.tps);


	
}

popUP.openFrame=function(url){


	//CREA EL IFRAME
	var iframe = document.createElement('iframe'); 
	iframe.setAttribute("src",url)
	iframe.setAttribute("id","iframe_popup")
	iframe.setAttribute("frameBorder","no")
	//PONE EL IFRAME EN LA PAGINA Y LO COLOCA
	popUP.content.appendChild(iframe)
	iframe.style.width=this.cw+"px"
	iframe.style.height=(this.ch-this.th)+"px"
	iframeInit(iframe)
	
	if(IE6==true || IE7==true){
		setTimeout("popUP.openContent("+this.cw+","+this.ch+")",1000);
	}else {
		iframe.onload=function(){
		popUP.openContent(this.cw,this.ch)}
	}
	
	
	
	
	
}
popUP.openContent=function(){
	changeStyle("width",this.cw,"content_popup")
	//changeStyle("height",Math.round(height-200),"content_popup")
	//sizeTo("width","content_popup", width, width, 0)
	sizeTo("height","content_popup", 100, this.ch,50)
	opacity("content_popup",0,100, 400)
}
//CREA LA CAPA DE SOMBRA SI NO EXITE, Y la pone en su sitio.


popUP.closePop=function(){
	opacity("sombra_popup",popUP.opacity,0, popUP.tps)
	opacity(this.destroyObject.id,100,0, popUP.tps)
	if(IE6===true)	post_ie6()
	setTimeout("document.body.removeChild(popUP.destroyObject)",popUP.tps)
}

popUP.init=function(){
	if(IE6===true)	pre_ie6()
	if(INIT==false){
		var sombra = document.createElement('div'); 
		sombra.appendChild(document.createTextNode(' ')); 
		sombra.setAttribute("id","sombra_popup")
		sombra.onclick=function(){popUP.closePop()}
		document.body.appendChild(sombra)
		INIT=true
	}
	
	this.init_html_element("sombra_popup",998)
	changeOpac(0, "sombra_popup")
	//PONER EL ESTILO DE SOMBRA CORRECTO
	sombra=document.getElementById("sombra_popup");
	if(IE6==true){
		sombra.style.width=document.body.clientWidth+"px"
		sombra.style.height=document.body.clientHeight+"px"
	}else {
		sombra.style.width=screen.availWidth+"px"
		sombra.style.height=screen.availHeight+"px"
	}
	
	sombra.style.backgroundColor="#FFFFFF";
	opacity("sombra_popup",0,popUP.opacity, popUP.tps)
	this.content = document.createElement('div'); 
	this.content.setAttribute("id","content_popup")
	this.content.className="clearfix";
	contentInit(this.content)
	document.body.appendChild(this.content)
	popUP.init_html_element("content_popup",999)
	
	this.content.style.width=this.cw+"px"
	this.content.style.height="100px"
	this.content.style.background="#FFFFFF"
	//CENTRA EL IFRAME

	this.content.style.overflow="hidden"
	centrar(this.content,this.cw,this.ch)
	
	//BARRA DE TITULO
	this.title = document.createElement('div'); 
	this.title.style.height=this.th+"px"
	this.content.appendChild(this.title)
	titleInit(this.title)
	this.destroyObject=popUP.content
	
}



function centrar(object,width,height){
	centrado_horizontal(object,width)
	centrado_vertical(object,height)
}

function centrado_horizontal(object,width){
	object.style.marginLeft=((popUP.w-width)/2)+"px"
}

function centrado_vertical(object,height){
	if(IE6===true)object.style.marginTop=(((popUP.h-height)/2)+document.documentElement.scrollTop)+"px"
	else object.style.marginTop=((popUP.h-height)/2)+"px"
}
//COLOCA UN ELEMENTO POR ENCIMA DE TODO, en el punto 0,0
popUP.init_html_element=function(id,zindex){
	var elem=document.getElementById(id);
	
	if(IE6==true){
		elem.style.position="absolute"
	}else {
		elem.style.position="fixed"
	}
	elem.style.zIndex=zindex
	elem.style.left="0px"
	elem.style.top="0px"
	changeOpac(0, id)
	
}

//PARA QUE SE VEA BIEN EN IE6////////////////////////
function pre_ie6(){
	for(j=0;j<document.forms.length;j++){
		form=document.forms[j]
		for(i=0;i<form.length;i++){
			
			var c = form[i]
			if(c.type=="select-one" ){
				c.style.visibility="hidden"
			}
		
		}
	}

}

function post_ie6(){
	for(j=0;j<document.forms.length;j++){
		form=document.forms[j]
		for(i=0;i<form.length;i++){
			
			var c = form[i]
			if(c.type=="select-one" ){
				c.style.visibility=""
			}
		
		}
	}
	
}
///////////////////////////////////////////////////



///FUNCIONES DE RESIZE/////////////////////////////

function sizeTo(variable,id, Start, End, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(Start > End) {
		for(i = Start; i >= End; i--) {
			setTimeout("changeStyle('"+variable+"'," + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		
	} else if(Start < End) {
		for(i = Start; i <= End; i++)
			{
			setTimeout("changeStyle('"+variable+"'," + i + ",'" + id + "')",(timer * speed));
			timer++;
			}
			
	}
}

function changeStyle(variable,valor,id){
	var object = document.getElementById(id); 
	
	object.style[variable]=valor+"px";
	
	if(variable=="width")centrado_horizontal(object,valor)
	if(variable=="height")centrado_vertical(object,valor)
}

//FUNCIONES DE TRANSPARENCIA ///////////////////////////////////////////////////////////////////////
function shiftOpacity(id, millisec,opa) {
      //SI El elemento es visible lo muestra, sino lo oculta
      if(document.getElementById(id).style.opacity == 0) {
            
			opacity(id, 0, opa, millisec);
      } else {
		  	
            opacity(id, opa, 0, millisec);
      }
}

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
			}
			
	}
}






//Aplica transparencia compatible con la mayoría de navegadores
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	if(opacity<1) document.getElementById(id).style.display="none";
	if(opacity>1) document.getElementById(id).style.display="block";
}


