var persistclose=0
var startX=25
var startY=25
var verticalpos="fromtop"


var divs_duplicado = new Array(10); 

function iecompattest(){
	return(document.compatMode&&document.compatMode!="BackCompat")? document.documentElement : document.body}
function get_cookie(Name){
	var search=Name+"="
	var returnvalue=""
	if(document.cookie.length>0){
		offset=document.cookie.indexOf(search)
		if(offset !=-1){
			offset+=search.length
			end=document.cookie.indexOf(";",offset)
			if(end==-1)end=document.cookie.length
			returnvalue=unescape(document.cookie.substring(offset,end))}}
	return returnvalue
}

function iecompattestIframe(){
	return(parent.document.compatMode&&parent.document.compatMode!="BackCompat")? parent.document.documentElement : parent.document.body}
function get_cookie(Name){
	var search=Name+"="
	var returnvalue=""
	if(parent.document.cookie.length>0){
		offset=parent.document.cookie.indexOf(search)
		if(offset !=-1){
			offset+=search.length
			end=parent.document.cookie.indexOf(";",offset)
			if(end==-1)end=parent.document.cookie.length
			returnvalue=unescape(parent.document.cookie.substring(offset,end))}}
	return returnvalue
}



var fWidth;
function getLeftLightbox(divcito){
	//For old IE browsers
	if(document.all)
		fWidth = document.body.clientWidth;
	//For DOM1 browsers
	else if(document.getElementById &&!document.all)
		fWidth = innerWidth;
	else if(document.getElementById)
		fWidth = innerWidth;
	//For Opera
	else if (is.op)
		fWidth = innerWidth;
	//For old Netscape
	else if (document.layers)
		fWidth = window.innerWidth;
		
	var widthdivcito = obtenerEstilo(divcito,"width");
	return ((fWidth/2)-(widthdivcito/2))+"px";
}

function getLeftLightboxIframe(divcito){
	//For old IE browsers
	if(document.all)
		fWidth = parent.document.body.clientWidth;
	//For DOM1 browsers
	else if(parent.document.getElementById &&!document.all)
		fWidth = parent.innerWidth;
	else if(parent.document.getElementById)
		fWidth = parent.innerWidth;
	//For Opera
	else if (is.op)
		fWidth = parent.innerWidth;
	//For old Netscape
	else if (parent.document.layers)
		fWidth = window.innerWidth;		
	var widthdivcito = obtenerEstiloIframe(divcito,"width");
	return ((fWidth/2)-(widthdivcito/2))+"px";
}

function obtenerEstilo(elemento,estilo){
	if(elemento.width)
	   return elemento.width;
	
	style = estilo;
	value=elemento.style.estilo;
	if (!value) {
		  if (document.defaultView && document.defaultView.getComputedStyle) {
			var css = document.defaultView.getComputedStyle(elemento, null);
			value = css ? css[style] : null;
		  } else if (elemento.currentStyle) {
			value = elemento.currentStyle[style];
		  }
	}
	if(isNaN(value))
	   return elemento.offsetWidth;
	else if(value)
		return value.replace("px","");
	else
		return 0;
}

function obtenerEstiloIframe(elemento,estilo){
	if(elemento.width)
	   return elemento.width;
	
	style = estilo;
	value=elemento.style.estilo;
	if (!value) {
		  if (parent.document.defaultView && parent.document.defaultView.getComputedStyle) {
			var css = parent.document.defaultView.getComputedStyle(elemento, null);
			value = css ? css[style] : null;
		  } else if (elemento.currentStyle) {
			value = elemento.currentStyle[style];
		  }
	}
	if(isNaN(value))
	   return elemento.offsetWidth;
	else if(value)
		return value.replace("px","");
	else
		return 0;
}



function abrirLightbox(windowID, borrarContenido, contenedorcampos){
	if(borrarContenido==1){
	          document.getElementById(contenedorcampos).innerHTML = divs_duplicado[windowID].innerHTML;
    }
    
   	ponerVelo();
	this.id=windowID
	barheight=document.getElementById(this.id).offsetHeight
	var ns=(navigator.appName.indexOf("Netscape")!=-1)|| window.opera
	var d=document
	function ml(id){
		var el=d.getElementById(id)
		if(!persistclose || persistclose&&get_cookie("remainclosed")=="")
		el.style.display="block"
		if(d.layers)el.style=el
//		el.sP=function(x,y){this.style.left=x+"%";this.style.top=y+"px";}
		//el.sP=function(x,y){this.style.left="5%";this.style.top=y+"px";}
		el.sP=function(x,y){this.style.left=getLeftLightbox(el);this.style.top=y+"px";}
		el.x=startX
		if(verticalpos=="fromtop")
		el.y=startY
		else{
			el.y=ns ? pageYOffset+innerHeight : iecompattest().scrollTop+iecompattest().clientHeight
			el.y-=startY}
		return el}
	window.stayTopLeft=function(){
		if(verticalpos=="fromtop"){
			var pY=ns ? pageYOffset : iecompattest().scrollTop
			ftlObj.y+=(pY+startY-ftlObj.y)/8}
		else{
			var pY=ns ? pageYOffset+innerHeight-barheight: iecompattest().scrollTop+iecompattest().clientHeight-barheight
			ftlObj.y+=(pY-startY-ftlObj.y)/8}
		ftlObj.sP(ftlObj.x,ftlObj.y)
		setTimeout("stayTopLeft()",10)}
	ftlObj=ml(this.id)
	stayTopLeft()
}

function abrirLightboxcontac(windowID, borrarContenido, contenedorcampos, titulo){
	if(borrarContenido==1){
	   	   	
        document.getElementById(contenedorcampos).innerHTML = divs_duplicado[windowID].innerHTML;
       
    }
     
   	ponerVelo();
	this.id=windowID
	
	document.getElementById("tipoContacto").innerHTML = titulo;
		
	barheight=document.getElementById(this.id).offsetHeight
	var ns=(navigator.appName.indexOf("Netscape")!=-1)|| window.opera
	var d=document
	function ml(id){
		var el=d.getElementById(id)
		if(!persistclose || persistclose&&get_cookie("remainclosed")=="")
		el.style.display="block"
		if(d.layers)el.style=el
		el.sP=function(x,y){this.style.left=x+"%";this.style.top=y+"px";}
		el.x=startX
		if(verticalpos=="fromtop")
		el.y=startY
		else{
			el.y=ns ? pageYOffset+innerHeight : iecompattest().scrollTop+iecompattest().clientHeight
			el.y-=startY}
		return el}
	window.stayTopLeft=function(){
		if(verticalpos=="fromtop"){
			var pY=ns ? pageYOffset : iecompattest().scrollTop
			ftlObj.y+=(pY+startY-ftlObj.y)/8}
		else{
			var pY=ns ? pageYOffset+innerHeight-barheight: iecompattest().scrollTop+iecompattest().clientHeight-barheight
			ftlObj.y+=(pY-startY-ftlObj.y)/8}
		ftlObj.sP(ftlObj.x,ftlObj.y)
		setTimeout("stayTopLeft()",10)}
	ftlObj=ml(this.id)
	stayTopLeft()
}

function abrirLightboxvotar(windowID, borrarContenido, contenedorcampos,otro){
	if(borrarContenido==1){
	   	   	
        document.getElementById(contenedorcampos).innerHTML = divs_duplicado[windowID].innerHTML;
       
    }    
  	ponerVelo();
	this.id=windowID
	if(otro==0)
	  document.getElementById("mensajevotar").innerHTML = "Sólo se permite un voto por usuario";
	else
	  document.getElementById("mensajevotar").innerHTML = "Gracias por tu Calificaci&oacute;n!!!";
		
	barheight=document.getElementById(this.id).offsetHeight
	var ns=(navigator.appName.indexOf("Netscape")!=-1)|| window.opera
	var d=document
	function ml(id){
		var el=d.getElementById(id)
		if(!persistclose || persistclose&&get_cookie("remainclosed")=="")
		el.style.display="block"
		if(d.layers)el.style=el
		el.sP=function(x,y){this.style.left=x+"%";this.style.top=y+"px";}
		el.x=startX
		if(verticalpos=="fromtop")
		el.y=startY
		else{
			el.y=ns ? pageYOffset+innerHeight : iecompattest().scrollTop+iecompattest().clientHeight
			el.y-=startY}
		return el}
	window.stayTopLeft=function(){
		if(verticalpos=="fromtop"){
			var pY=ns ? pageYOffset : iecompattest().scrollTop
			ftlObj.y+=(pY+startY-ftlObj.y)/8}
		else{
			var pY=ns ? pageYOffset+innerHeight-barheight: iecompattest().scrollTop+iecompattest().clientHeight-barheight
			ftlObj.y+=(pY-startY-ftlObj.y)/8}
		ftlObj.sP(ftlObj.x,ftlObj.y)
		setTimeout("stayTopLeft()",10)}
	ftlObj=ml(this.id)
	stayTopLeft()
}
function cerrarLightboxVotar(windowID){
    document.getElementById("mensajevotar").innerHTML = '';
    cerrarLightbox(windowID);
}
function cerrarLightbox(windowID){
	quitarVelo();
	this.id=windowID
	if(persistclose)
	document.cookie="remainclosed=1"
	document.getElementById(this.id).style.display="none"    
}
function JSWindow(windowID){
	document.getElementById('vermask').className='layerlightver'
	oTable=document.createElement("table")
	oTable.cellSpacing=0
	oTable.cellPadding=0
	oTable.border=0
	var windowdiv=document.getElementById(windowID)
	var urlight=document.getElementById(windowID)
	while(windowdiv.hasChildNodes())windowdiv.removeChild(windowdiv.firstChild)
	windowdiv.appendChild(oTable)
	var oTR=oTable.insertRow(0)
	oTD=oTR.insertCell(0)
	oTD.innerHTML="<img src='"+urlight.value+"' border=0>"}

function ponerVelo(){
   document.getElementById('vermask').className='layerlightver';
}
function ponerVeloIframe(){
  parent.velo.className='layerlightver';
}

function quitarVelo(){
   document.getElementById('vermask').className='';
}
function mostrarRecursoMultimedia(respuesta){
   var divmulti = document.getElementById("contenidoReproductor").innerHTML=respuesta;
   abrirLightbox("lightboxMultimedia",0);
}

function enviarNuevoError(idform){
   
    form =  document.getElementById(idform);
    
    //para tomar el enlace de la pagian en la que se encuentra
    var link = form.redireccion.value;
    
    var nombreusua=form.nombreUsu.value;
	var correousua=form.correoUsu.value;
	var mensaje=form.mensajeUsu.value; 
	
    var barra_mensaje = document.getElementById("mensaje_error_reportar_amigo");
   
	if(isEmpty(nombreusua))
	{
		barra_mensaje.innerHTML = "Por favor, escribe tu nombre";
		return;
	}
	
	if(!isEmail(correousua))
	{
		barra_mensaje.innerHTML = "Tu dirección de correo electrónico no es válida";
		return;
	}

	if(isEmpty(mensaje))
	{
		barra_mensaje.innerHTML = "Por favor, escribe tu  mensaje";
		return;
	}	
	 document.getElementById("contentcamposError").innerHTML = "<br><br><br><h1>Un momento por favor. Estamos enviando sus observaciones a nuestro equipo editorial.</h1><br><br><br>";
     incluirObjeto("ENVIAR_ERROR",nombreusua, correousua, mensaje, link, "contentcamposError");
                
  } 
  function enviarContacto(idform, tipoContacto){
   
    form =  document.getElementById(idform);
    
    var nombreusua=form.nombreUsu.value;
    var cedulausua = form.cedulaUsu.value;
    var telefonousua = form.telefonoUsu.value;
    var correousua=form.correoUsu.value;
	var mensaje=form.mensajeUsu.value; 
	
	if(isEmpty(nombreusua))
	{
		alert("Por favor, escribe tu nombre");
		return;
	}
	
	if(isEmpty(cedulausua))
	{
		alert("Por favor, escribe tu cédula");
		return;
	}
	
	if(isEmpty(telefonousua))
	{
		alert("Por favor, escribe tu teléfono");
		return;
	}
	
	if(!isEmail(correousua))
	{
		alert("Tu dirección de correo electrónico no es válida");
		return;
	}

	if(isEmpty(mensaje))
	{
		alert("Por favor, escribe tu  mensaje");
		return;
	}
     //tomo el tipo de contacto 	
	 var tipo = document.getElementById("tipoContacto").innerHTML;
	  	
	 document.getElementById("contentcamposcontact").innerHTML = "<br><br><br><h1>Enviando reporte, por favor espere...</h1><br><br><br>";
     incluirObjeto("ENVIAR_CONTACTO",nombreusua, cedulausua, telefonousua, correousua, mensaje,tipo,"contentcamposcontact");
                
  } 
  
  function enviarAmigo(idform, idRecurso){
   
    form =  document.getElementById(idform);
    
    //para tomar el enlace de la pagian en la que se encuentra
    var link = document.getElementById("redireccion").value;
    
    var nombreorigen=form.nombreor.value;
	var mailorigen=form.mailor.value;
	var nombredestino=form.nombredes.value;
    var maildestino=form.maildes.value;
  	var mensajemail=form.mensaje.value;
	 
	

	if(isEmpty(nombreorigen))
	{
		alert("Por favor, escribe tu nombre");
		return;
	}
	
	if(!isEmail(mailorigen))
	{
		alert("Tu dirección de correo electrónico no es válida");
		return;
	}
    if(isEmpty(nombredestino))
	{
		alert("Por favor, escribe el nombre de tu amigo");
		return;
	}
	
	if(!isEmail(maildestino))
	{
		alert("La dirección de correo electrónico de tu amigo no es válida");
		return;
	}
	if(isEmpty(mensajemail))
	{
		alert("Por favor, escribe tu mensaje");
		return;
	}	
	 document.getElementById("contentcamposAmigo").innerHTML = "<div class='uncamporegistro'><br><br><br><h1>Un momento por favor. Estamos enviando la informaci&oacute;n.</h1><br><br><br></div>";
     incluirObjeto("ENVIAR_AMIGO",nombreorigen,mailorigen,nombredestino,maildestino,mensajemail, link,idRecurso, "contentcamposAmigo");
                
  } 
  
  function enviarInformanos(idform){
   
    form =  document.getElementById(idform);
    
    //para tomar el enlace de la pagian en la que se encuentra
    var link = document.getElementById("redireccion").value;
    
    var infonombre=form.infoNombre.value;
    var infoapellido=form.infoApellido.value;
	var infomail=form.infoMail.value;
    var infotipo=form.infoTipo.value;
    var infodirec=form.infoDirec.value;
    var infotele=form.infoTele.value;
    var infocelu=form.infoCelu.value;
    var infociudad=form.infoCiudad.value;
	var infomensaje=form.infoMensaje.value;

	if(isEmpty(infonombre))
	{
		alert("Por favor, escribe tu nombre");
		return;
	}
	if(isEmpty(infoapellido))
	{
		alert("Por favor, escribe tu apellido");
		return;
	}
	
	if(!isEmail(infomail))
	{
		alert("Tu dirección de correo electrónico no es válida");
		return;
	}
    if(isEmpty(infotipo))
	{
		alert("Por favor, elije un tipo");
		return;
	}
	
	if(isEmpty(infodirec))
	{
		alert("Por favor, escribe tu dirección");
		return;
	}
	
	if(isEmpty(infotele))
	{
		alert("Por favor, escribe tu teléfono");
		return;
	}
	if(isEmpty(infocelu))
	{
		alert("Por favor, escribe tu  celular");
		return;
	}
	
	if(isEmpty(infociudad))
	{
		alert("Por favor, escribe tu  Ciudad");
		return;
	}
	
	if(isEmpty(infomensaje))
	{
		alert("Por favor, escribe tu  mensaje");
		return;
	}	
	 document.getElementById("contentcamposInformanos").innerHTML = "<div class='uncamporegistro'><br><br><br><h1>Un momento por favor. Estamos enviando la informaci&oacute;n a nuestro equipo editorial.</h1><br><br><br></div>";
     incluirObjeto("ENVIAR_INFORMANOS",infonombre,infoapellido,infomail,infotipo,infodirec,infotele,infocelu,infociudad,infomensaje,"contentcamposInformanos");
                
  } 
  
  
  function isEmail (s)
  {
    if (isEmpty(s)) 
      if (isEmail.arguments.length == 1) return false;
      else return (isEmail.arguments[1] == true);
      var i = 1;
      var sLength = s.length;
      while ((i < sLength) && (s.charAt(i) != "@")) i++;
      
      if ((i >= sLength) || (s.charAt(i) != "@")) return false;
      else i += 2;
      
      while ((i < sLength) && (s.charAt(i) != "."))i++;
      
      if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
      else return true;
  }
    
  function isEmpty(s)
  {   
	return ((s == null) || (s.length == 0));
  }

function recargarObjeto2(nombre_objeto, div_respuesta, o, pordefecto, cual){
   
    //Quitar el foco de la pestaña a la que le hicieron click
     //o.style.display='block';
     //o.blur(); 
     o.parentNode.style.display='block';
     o.parentNode.blur();
             
    //Quitarle el estilo a la pestaña actual
    var list = document.getElementById('NavigationMiPortafolio').getElementsByTagName("li");
    for (var i = 0; i < list.length; i++) {
		if (list[i].className == pordefecto) {
			list[i].className = "";	
		}
	}
	//clase a la pestaña del click
	//o.className = pordefecto;
    o.parentNode.className = pordefecto;
    
    incluirObjeto(nombre_objeto, cual, div_respuesta);   
}  

function eliminarFavorito(idrecurso){
	abrirLightbox('lightboxEliminarFav',0,'contenteliminarFav');
	document.getElementById("contenteliminarFav").innerHTML = "<p><center>Espere unos segundos.</center></p>";
  	incluirObjeto("ELIMINAR_FAVORITO",idrecurso,'contenteliminarFav');	

}

function agregarAlerta(){
	abrirLightbox('lightboxAgregarAl',0,'contentagregaral');
	/*document.getElementById("contenteliminarFav").innerHTML = "<p><center>Espere unos segundos.</center></p>";
  	incluirObjeto("AGREGAR_ALERTA",idrecurso,'contenteliminarFav');	*/

}

function agregarAlerta2(idform){
   
    form =  document.getElementById(idform);
    
    var alerta = form.alerta.value;
    var estado = form.estado;
    var estado2 = form.estado.value;
	
	if(isEmpty(alerta))
	{
		alert("Por favor, escribe su alerta");
		return;
	}
	
	if (estado.options[estado.selectedIndex].value == "")
	{
		alert("Por favor, elija un estado para su alerta");
		return;
	}
	  	
	 document.getElementById("contentagregaral").innerHTML = "<br><br><br><h1>Agregando alerta, por favor espere...</h1><br><br><br>";
     incluirObjeto("AGREGAR_ALERTA",alerta, estado2, "contentagregaral");
                
}

function editarAlerta(alerta,estado){
	abrirLightbox('lightboxModificarAl',0,'contentmodificaral');
	/*document.getElementById("contenteliminarFav").innerHTML = "<p><center>Espere unos segundos.</center></p>";*/
  	incluirObjeto("MODIFICAR_ALERTA",alerta,estado,'contentmodificaral');	

}

function editarAlerta2(idformal){
   
    form =  document.getElementById(idformal);
    
    var alerta = form.alerta.value;
    var estado = form.estado;
    var palabra_anterior = form.palabra_anterior.value;
    var estado2 = form.estado.value;
	
	if(isEmpty(alerta))
	{
		alert("Por favor, escribe su alerta");
		return;
	}
	
	if (estado.options[estado.selectedIndex].value == "")
	{
		alert("Por favor, elija un estado para su alerta");
		return;
	}
	  	
	 document.getElementById("contentmodificaral").innerHTML = "<br><br><br><h1>Modificando alerta, por favor espere...</h1><br><br><br>";
     incluirObjeto("MODIFICAR_ALERTA2",alerta, estado2, palabra_anterior, "contentmodificaral");
                
}

function eliminarAlerta(palabra){
	abrirLightbox('lightboxEliminarAl',0,'contenteliminarAl');
	document.getElementById("contenteliminarAl").innerHTML = "<p><center>Espere unos segundos.</center></p>";
  	incluirObjeto("ELIMINAR_ALERTA",palabra,'contenteliminarAl');	

} 


function abrirLightboxIframe(windowID, borrarContenido, contenedorcampos){
	if(borrarContenido==1){
	          document.getElementById(contenedorcampos).innerHTML = divs_duplicado[windowID].innerHTML;
    }
    ponerVeloIframe();
	this.id=windowID
	barheight=parent.document.getElementById(this.id).offsetHeight
	var ns=(navigator.appName.indexOf("Netscape")!=-1)|| window.opera
	var d=parent.document
	function ml(id){
		var el=d.getElementById(id)
		if(!persistclose || persistclose&&get_cookie("remainclosed")=="")
		el.style.display="block"
		if(d.layers)el.style=el
		//el.sP=function(x,y){this.style.left=x+"%";this.style.top=y+"px";}
		//el.sP=function(x,y){this.style.left="5%";this.style.top=y+"px";}
   		 el.sP=function(x,y){this.style.left=getLeftLightboxIframe(el);this.style.top=y+"px";}
		 el.x=startX
		if(verticalpos=="fromtop")
		el.y=startY
		else{
			el.y=ns ? pageYOffset+innerHeight : iecompattest().scrollTop+iecompattest().clientHeight
			el.y-=startY}
		return el}
	window.stayTopLeft=function(){
		if(verticalpos=="fromtop"){
			var pY=ns ? parent.pageYOffset : iecompattestIframe().scrollTop
			ftlObj.y+=(pY+startY-ftlObj.y)/8}
		else{
			var pY=ns ? pageYOffset+innerHeight-barheight: iecompattestIframe().scrollTop+iecompattestIframe().clientHeight-barheight
			ftlObj.y+=(pY-startY-ftlObj.y)/8}
		ftlObj.sP(ftlObj.x,ftlObj.y)
		setTimeout("stayTopLeft()",10)}
	ftlObj=ml(this.id)
	stayTopLeft()
}
    
function pintarIframeEncuesta(id_encuesta){
  var urlencuesta='http://www.eltiempo.com/sondeos/admin/user-statistics.php?sid='+id_encuesta;
  parent.document.getElementById('iframeId').src=urlencuesta;

}

function abrirBarra(){
	$("div#mibarra").slideDown("slow");
	document.getElementById("mibarra").innerHTML = '<div class="opciones-login"><div class="form2"><div class="dato dato1"><input type="checkbox" class="inputCheckbox" name="recordar" id="recordar"/><label for="recordar">Recordar mi clave en este equipo</label><a class="vinculo-especial" href="" >Olvidé mi clave</a></div></div><div class="clear"></div></div>';
}
