
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

ajax=new Ajax();
pag_orden=0;
function abrirVideo(orden)
{
	pag_orden=orden;
	var imgs=document.getElementsByName('img_galerias');

	var v_ant='visible';
	if (orden==0)
		var v_ant='hidden';
	
	var v_sig='visible';
	if (orden==imgs.length-1)
		v_sig='hidden';
			
	
	
	img=imgs[orden].src.replace('_pq','_gr');
	pie=imgs[orden].alt;


	var contenido='<table width="500" height="530" border="0" cellspacing="4" cellpadding="0" background="../images/fondo_loading.gif" style="background-repeat: no-repeat; background-position: center center;"><tr><td height="500" align="center"><a onclick="ajax.hideModal();"><img id="img_ampliada" src="'+img+'" alt="cerrar" title="cerrar"/></a></td></tr>'+
			'<tr><td valign="bottom" height="30" align="center"><span id="img_pie" style="color:#999999; font: normal 11px Helvetica">'+pie+'</span><br>'+
			'<a id="img_ant" style="visibility:'+v_ant+'" href="Javascript:paginado(pag_orden-1);" class="antsig">&#9668;</a>&nbsp;&nbsp;<a id="img_sig" style="visibility:'+v_sig+'" href="Javascript:paginado(pag_orden+1);" class="antsig">&#9658;</a>'+
			'</td></tr></table>' 

	ajax.showModal(contenido);
}

function paginado(orden)
{
	pag_orden=orden;
	
	var imgs=document.getElementsByName('img_galerias');
	if (orden==0)
		document.getElementById('img_ant').style.visibility='hidden';
	else
		document.getElementById('img_ant').style.visibility='visible';
	
	if (orden==imgs.length-1)
		document.getElementById('img_sig').style.visibility='hidden';
	else
		document.getElementById('img_sig').style.visibility='visible';

	img=imgs[orden].src.replace('_pq','_gr');
	pie=imgs[orden].alt;
	document.getElementById('img_ampliada').src=img;
	document.getElementById('img_pie').innerHTML=pie;
	
}

function abrirMapa(id)
{
	ajax.showModalURL('/v4/php/map.php?itop='+id,540,460);
}

function abrirMapaAg(id)
{
	ajax.showModalURL('/v4/php/map.php?iagenda='+id,540,460);
}

function enviarAmigo(id)
{
	ajax.showModalURL('/v4/php/envio.php?itop='+id,540,460);
}

function enviarComentario(id)
{
	ajax.showModalURL('/v4/php/comentario.php?itop='+id,540,460);
}

function enviarAmigoAg(id)
{
	ajax.showModalURL('/v4/php/envio.php?iagenda='+id,540,460);
}


function enviarMinotodo()
{
	ids=document.getElementById('enviar_minotodo').value;
	ajax.showModalURL('/v4/php/envio.php?imini='+ids,540,460);
}

function imprimir(id)
{
	if(document.all)
		window.open('/v4/php/imprimetelotop.php?itop='+id);
	else
		document.getElementById('imprime').src='/v4/php/imprimetelotop.php?itop='+id;
}

function imprimirAg(id)
{
	if(document.all)
		window.open('/v4/php/imprimeteloagenda.php?iagenda='+id);
	else
		document.getElementById('imprime').src='/v4/php/imprimeteloagenda.php?iagenda='+id;
}

		
function abrirVideoPortada()
{
	ajax.showModalURL('/v4/php/video.php',600,380);
}


function siTeGusta(id)
{
	document.getElementById('gusto').style.display='block';
}

function noticiasRelacionadas(id)
{
	document.getElementById('relacionadas').style.display='block';
}

//registro
function limpiarRegistro(obj,cadena)
{
	if(obj.value==cadena)
		obj.value='';
}

function escribirRegistro(obj,cadena)
{
	if(obj.value=='')
		obj.value=cadena;
}

function registrate()
{
	email=document.getElementById('registro_notodo');
	if (validaEmail(email))
	{
		window.open('http://www.notodo.com/cgi/php/altasbajasnew.php?site=notodo&email='+email.value);
	}
}

function buscar()
{
	var busca=document.getElementById('buscador').value;
	location.href="/v4/php/busca.php?cadena="+escape(busca);
}




function validaEmail(obj)
{
/* comienzo a validar el email si lo hay*/
			 if(obj.value!="")
			 {
				var checkTLD=1;
				var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|cat)$/;
				var emailPat=/^(.+)@(.+)$/;
				var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
				var validChars="\[^\\s" + specialChars + "\]";
				var quotedUser="(\"[^\"]*\")";
				var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
				var atom=validChars + '+';
				var word="(" + atom + "|" + quotedUser + ")";
				var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
				var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
				var matchArray=obj.value.match(emailPat);

				if (matchArray==null) {
				alert("La dirección de email parece incorrecta (comprueba @ y .)");
				obj.focus();
				return false;
				}
				var user=matchArray[1];
				var domain=matchArray[2];
				for (i=0; i<user.length; i++) {
				if (user.charCodeAt(i)>127) {
				alert("El nombre de usuario contiene caracteres incorrectos en la dirección de correo.");
				obj.focus();
				return false;
					 }
				}
				for (i=0; i<domain.length; i++) {
				if (domain.charCodeAt(i)>127) {
				alert("El dominio contiene caracteres incorrectos en la dirección de correo.");
				obj.focus();
				return false;
					 }
				}
				if (user.match(userPat)==null) {
				alert("El nombre de usuario no es válido en la dirección de correo.");
				obj.focus();
				return false;
				}
				var IPArray=domain.match(ipDomainPat);
				if (IPArray!=null) {
				for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
				alert("La IP de destino no es válida en la dirección de correo.");
				obj.focus();
				return false;
					 }
				}
				return true;
				}
				var atomPat=new RegExp("^" + atom + "$");
				var domArr=domain.split(".");
				var len=domArr.length;
				for (i=0;i<len;i++) {
				if (domArr[i].search(atomPat)==-1) {
				alert("El nombre del dominio no es válido en la dirección de correo.");
				obj.focus();
				return false;
					 }
				}
				if (checkTLD && domArr[domArr.length-1].length!=2 && 
				domArr[domArr.length-1].search(knownDomsPat)==-1) {
				alert("La dirección de correo debe terminar en un dominio conocido o de un país.");
				obj.focus();
				return false;
				}
				if (len<2) {
				alert("Falta el dominio en la dirección de correo.");
				objl.focus();
				return false;
				}
				/* termino de validar el email y si todo ok, devuelve true*/
				return (true);
		 }
}

function Ajax(){

// FUNCIONAMIENTO GENERAL (XML) /////////////////////////////////////////////

	// VARIABLES LOCALES /////////////////////

	var intentos=0;
	var self;
	var indicemodal=0;
	var indicetooltip=0;



	// VARIABLES LOCALES /////////////////////

	var label;
	var modal2Html = '';
	var tooltipTimeout;
	

	// PROPIEDADES ///////////////////////////
	
	this.hideTimeout = 2;
	this.errorTimeout = 5;


		// Ventana modal centrada
	this.showModal = function(html,estilo){
		indicemodal++;
		bgTrans();
		var idventana = '_ajax_modalcontent_'+this.id+'_'+indicemodal;
		
		if(!$(idventana))
		{
			
			var modalcontent = document.createElement('DIV');
			modalcontent.style.cssText = 'position:absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index:'+((1000*indicemodal)+1)+';';
			modalcontent.id = idventana;
			document.body.appendChild(modalcontent);
//			visionCombos('hidden');
		}
		
		$(idventana).innerHTML = '<table border="0" width="100%" height="100%" align="center"><tr><td align="center"><div class="modalstyle'+(estilo?' '+estilo:'')+'">'+html+'</div></td></tr></table>';
		document.body.style.height = '100%'
		$(idventana).style.top = getScrollY() + 'px'

		/*if(document.all)
			document.body.style.overflow = 'hidden';
		else
			window.onscroll = function(){
				if($(idventana)){
					$(idventana).style.top = getScrollY();
				}
			}*/
	}
	
	
	// Ventana modal centrada que carga un iframe con el contenido url con ancho y alto
	this.showModalURL = function(url,ancho,alto){
		this.showModal('<iframe name="frame_ajax" width="'+ancho+'" height="'+alto+'" scrolling="no" src="'+url+'" frameborder="no"></iframe>');
	}	
	
	

	// Ocultar ventanas modales
	this.hideModal = function(){
		visionCombos('visible');
		
		if($('_ajax_modal2_'+this.id+'_'+indicemodal)){
			document.body.removeChild($('_ajax_modal2_'+this.id+'_'+indicemodal));
			document.body.removeChild($('_ajax_trans_'+this.id+'_'+indicemodal));
			indicemodal--;
		}else if($('_ajax_modalcontent_'+this.id+'_'+indicemodal)){
			document.body.removeChild($('_ajax_modalcontent_'+this.id+'_'+indicemodal));
			document.body.removeChild($('_ajax_trans_'+this.id+'_'+indicemodal));
			indicemodal--;
		}

		if(indicemodal>0 && $('_ajax_modalcontent_'+this.id+'_'+indicemodal))
			$('_ajax_modalcontent_'+this.id+'_'+indicemodal).style.top = getScrollY();
	}

	



	function bgTrans(){
		if(!$('_ajax_trans_'+self.id+'_'+indicemodal))
		{
			var modal = document.createElement('DIV');
			if(document.all)
				modal.style.filter = 'Alpha(Opacity=95)';
			else
				modal.style.MozOpacity='0.95';
			
				/*
				modal.style.backgroundColor = 'transparent'; 
				modal.style.backgroundImage = 'url(/images/px.gif)';
				modal.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader (src="/images/px.png", sizingMethod="scale")';
				*/

				/* modal.style.backgroundImage = 'url(/images/px.png)'; */
			
			//modal.style.backgroundColor = self.transBgColor;
			modal.style.position = 'absolute';
			//modal.style.height = (document.body.scrollHeight?document.body.scrollHeight:document.documentElement.scrollHeight)+'px';
			modal.style.height = '2600px';
			modal.style.top = '0px';
			modal.style.left = '0px';
			modal.style.zIndex = 1000*indicemodal;
			modal.style.width = '100%';
			modal.className = 'ajax_trans';
			modal.id = '_ajax_trans_'+self.id+'_'+indicemodal;


			document.body.appendChild(modal);
			visionCombos('hidden');
		}
	}

	function visionCombos(opcion){
		if(document.all){
			if(indicemodal<=1)
				var arr = document.getElementsByTagName('select');
			else
				if($('_ajax_modal2_'+self.id+'_'+(indicemodal-1)))
					var arr = $('_ajax_modal2_'+self.id+'_'+(indicemodal-1)).getElementsByTagName('select');
				else
					if($('_ajax_modalcontent_'+self.id+'_'+(indicemodal-1)))
						var arr = $('_ajax_modalcontent_'+self.id+'_'+(indicemodal-1)).getElementsByTagName('select');

			for(i = 0; i < arr.length; i++)
				arr[i].style.visibility = opcion;
				
		}

		// También para flash
		if(document.all)
			var arr = document.getElementsByTagName('object');
		else
			var arr = document.getElementsByTagName('embed');
		
		for(i = 0; i < arr.length; i++)
			arr[i].style.visibility = opcion;
	}

	
	function getScrollY(){
		var scrollY = 0;
		
		if ( document.documentElement && document.documentElement.scrollTop )		{
			scrollY = document.documentElement.scrollTop;
		}else if ( document.body && document.body.scrollTop ){
			scrollY = document.body.scrollTop;
		}else if ( window.pageYOffset ){
			scrollY = window.pageYOffset;
		}else if ( window.scrollY ){
			scrollY = window.scrollY;
		}
		
		return scrollY;
	}
	
	function $(id){return document.getElementById(id);}

	// Necesario para poder instanciar la clase en el onreadystatechange
	self = this;
}

//--------------------------------------

function ver(){
	document.getElementById('info_autor').style.display="block"; 
}

function nover(){
	document.getElementById('info_autor').style.display="none"; 
}
//--------------------------------------
