//Abre un popup de tamaño (x,y), en el centro de la pantalla 
function OpenWindow(query, nom, x, y){
	x1=screen.availWidth;
	y1=screen.availHeight;
	var opciones="toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no,width="+(x-7)+",height="+(y-7)+",top="+(y1-y)/2+",left="+(x1-x)/2;
	window.open(query, nom, opciones);
}

//Envio de comentarios en notas
function limpiarFormComentario(){
	setTimeout('document.formComent.reset()',1000);
	return false;
}

function sendFormComentario(){	
	errors = '';
	var Nombre = document.getElementById("Nombre").value;
	var Mail = document.getElementById("Mail").value;	
	var Comentario = document.getElementById("ComentarioTxt").value;	
	if(Nombre == ""){
		document.getElementById("NombreID").innerHTML = "&nbsp;Debe completar su Nombre";
		errors = 'error';
	}	
	if(Mail == ""){
		document.getElementById("MailID").innerHTML = "&nbsp;Debe ingresar su Mail";
		errors = 'error';
	}	
	if(Comentario == ""){
		document.getElementById("ComentarioID").innerHTML = "Debe ingresar un comentario<BR />";
		errors = 'error';
	}			
	if(errors=='') limpiarFormComentario();
	document.MM_returnValue = (errors == '');
}

// Devuelve la fecha del día
function time(){
	var all;
	var month;
	var period;
	var day;
	
	var currentDate=new Date()
	year=currentDate.getFullYear() 
	hour=currentDate.getHours()
	date=currentDate.getDate()
	switch(currentDate.getMonth()){
			case 0:month="Enero";break;
			case 1:month="Febrero";break;
			case 2:month="Marzo";break;
			case 3:month="Abril";break;
			case 4:month="Mayo";break;
			case 5:month="Junio";break;
			case 6:month="Julio";break;
			case 7:month="Agosto";break;
			case 8:month="Septiembre";break;
			case 9:month="Octubre";break;
			case 10:month="Noviembre";break;
			case 11:month="Diciembre";break;
	}
	
	switch(currentDate.getDay()){
			case 0:day="Domingo";break;
			case 1:day="Lunes";break;
			case 2:day="Martes";break;
			case 3:day="Miercoles";break;
			case 4:day="Jueves";break;
			case 5:day="Viernes";break;
			case 6:day="Sabado";break;
	}
	
	var all= day + " " + date + ", <BR/>"+ month + " de " + year;
	document.write(all);
}

/*Slide de noticias en Home*/
function InitSlide(){
	var flecha = "Flecha_1";
	document.getElementById("fotoSlider").style.left = 0;
	document.getElementById("pieSlider").style.left = 0;	
	document.getElementById(flecha).style.visibility = "visible";
}

function slideIt(pos){
	var slidingDiv = document.getElementById("fotoSlider");
	var slidingDiv2 = document.getElementById("pieSlider");
	var stopPosition = 1800;
	var incremento = ((pos-1) * 454);	
	var incremento2 = Math.abs((pos-1) * 620 - incremento);	
	var posicion_actual = slidingDiv.style.left;	
	if (parseInt(posicion_actual) > -(stopPosition) ){
		slidingDiv.style.left =  -(incremento) + "px";
		slidingDiv2.style.left =  -(incremento) - incremento2 + "px";
	}else{
		slidingDiv.style.left =  incremento + "px";
		slidingDiv2.style.left =  incremento + incremento2 + "px";
	}
}

function _mOvr(obj, pos){
	var flecha = "Flecha_";
	var hover = "Slider_";
	obj1 = obj.id;
	for(var i = 1; i<=4; i++){		
		if(obj1==document.getElementById(hover+i).id){
			document.getElementById(flecha+i).style.visibility = "visible";	
			document.getElementById(hover+i).className = "btn_Slider_Act";
			document.getElementById("btn_SliderAntTit_" + i).className = "btn_SliderAntTit_Act";			
			slideIt(pos);
		}else{
			document.getElementById(flecha+i).style.visibility = "hidden";	
			document.getElementById(hover+i).className = "btn_Slider";			
			document.getElementById("btn_SliderAntTit_" + i).className = "btn_SliderAntTit";			
		}
	}	
}

/*Galeria de Imagenes y Videos*/
function showImg(ID){
	document.getElementById("galImagenA"+ID).style.display = "block";
	document.getElementById("galVideoA"+ID).style.display = "none";	
	document.getElementById("paginadoGalv").style.display = "none";
}

function showVid(ID){
	document.getElementById("galImagenA"+ID).style.display = "none";
	document.getElementById("paginadoGalv").style.display = "block";
	document.getElementById("galVideoA"+ID).style.display = "block";	
}


/*GALERIA DE VIDEOS*/
function Galeria_videos(fcontent, flvfile, jpgfile, epigrafe, idNota){
	var divFlash = fcontent;	
	var src = flvfile;
	var jpg = jpgfile;
	var swfObj;
	var divNro = document.getElementById("divNro"+idNota);
	var actual = 0;

	this.setVideo = setVideo;
	function setVideo(nn) {
		actual = nn;
		var skin = "bright.swf";		
		var swfObj = new SWFObject("player.swf", "ply"+idNota, 300, 200, "8");
		swfObj.addParam("flashvars","stretching=fill&menu=false&file="+src[actual]+"&image="+jpg[actual]+"&backcolor=333333&frontcolor=ffffff&controlbar=over&skin="+skin);
		swfObj.addParam("allowfullscreen","true");
		swfObj.addParam("allowscriptaccess","always");
		swfObj.addParam("wmode","transparent");
		swfObj.write(divFlash);		
		epigrafevideo = document.getElementById("epigrafe_video"+idNota);
		epigrafevideo.innerHTML = epigrafe[actual] != '' ? epigrafe[actual] : '';
		if(epigrafe[actual]==""){
			epigrafevideo.style.display = "none";
		}else epigrafevideo.style.display = "block";		
		if(divNro) divNro.innerHTML = actual + 1;
	}

	this.nextVid = nextVid;
	function nextVid() {
		if (actual < src.length - 1)
			setVideo(actual + 1);
		else
			setVideo(0);
	}

	this.antVid = antVid;
	function antVid() {
		if (actual > 0)
			setVideo(actual - 1);
		else
			setVideo(src.length - 1);
	}	
}


function Galeria_videos2(fcontent, flvfile, jpgfile, epigrafe, idNota){
	var divFlash = fcontent;	
	var src = flvfile;
	var jpg = jpgfile;
	var swfObj;
	var divNro = document.getElementById("divNro"+idNota);
	var actual = 0;

	this.setVideo = setVideo;
	function setVideo(nn) {
		actual = nn;
		var skin = "bright.swf";		
		var swfObj = new SWFObject("player.swf", "ply"+idNota, 400, 290, "8");
		swfObj.addParam("flashvars","stretching=fill&menu=false&file="+src[actual]+"&image="+jpg[actual]+"&backcolor=333333&frontcolor=ffffff&controlbar=over&skin="+skin);
		swfObj.addParam("allowfullscreen","true");
		swfObj.addParam("allowscriptaccess","always");
		swfObj.addParam("wmode","transparent");
		swfObj.write(divFlash);		
		epigrafevideo = document.getElementById("epigrafe_video"+idNota);
		epigrafevideo.innerHTML = epigrafe[actual] != '' ? epigrafe[actual] : '';
		if(epigrafe[actual]==""){
			epigrafevideo.style.display = "none";
		}else epigrafevideo.style.display = "block";		
		if(divNro) divNro.innerHTML = actual + 1;
	}

	this.nextVid = nextVid;
	function nextVid() {
		if (actual < src.length - 1)
			setVideo(actual + 1);
		else
			setVideo(0);
	}

	this.antVid = antVid;
	function antVid() {
		if (actual > 0)
			setVideo(actual - 1);
		else
			setVideo(src.length - 1);
	}	
}


/*GALERIA DE FOTOS*/
function Galeria_Imagenes(ff, ss, ee, nroid){
	var foto = ff;
	var epigrafe = ee;
	var	src = ss;
	var idnro = nroid;
	var divNro = document.getElementById("divNroImg"+idnro);
	var actual = 0;

	this.setFoto = setFoto;
	function setFoto(nn) {
		actual = nn;
		foto.src = src[actual];		
		divepigrafe = document.getElementById("epigrafe_imagen"+nroid);		
		divepigrafe.innerHTML = epigrafe[actual] != '' ? epigrafe[actual] : '';
		if(epigrafe[actual]==""){
			divepigrafe.style.display = "none";
		}else divepigrafe.style.display = "block";		
		if(divNro) divNro.innerHTML = actual + 1;
 	}

	this.sgtFoto = sgtFoto;
	function sgtFoto() {
		if (actual < src.length - 1)
			setFoto(actual + 1);
		else
			setFoto(0);
	}

	this.antFoto = antFoto;
	function antFoto() {
		if (actual > 0)
			setFoto(actual - 1);
		else
			setFoto(src.length - 1);
	}
}

/*Amplia y reduce el tamaño de fuente en el cuerpo de una noticia*/
var tam=10;
function tamFont(accion){	
	if(accion=='+'){		
		if(tam < 21){
			tam=tam + 3;		
			var size="\'"+tam+"px\'";
			document.getElementById("textoCuerpo").style.fontSize = eval(size);
		}
	}else{		
		if(tam > 14){
			tam = tam - 3;
			var size="\'"+tam+"px\'";
			document.getElementById("textoCuerpo").style.fontSize = eval(size);
		}		
	}
}

// Crea una instancia XMLHttpRequest
function createXmlHttpRequestObject(){
  var xmlHttp;
  try {
    xmlHttp = new XMLHttpRequest(); // Intenta crear el objeto
  }
  catch(e)
  {
	// Para IE6 o versiones anteriores
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");

    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) {
      try { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }

  if (!xmlHttp)
    alert("Error creando Objeto XMLHttpRequest.");
  else return xmlHttp;
}

/*Paginado Comentario noticias*/
function getComentarioNoticias(NotID, page){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {
	  
	query = "comentarios.php?action=nextCom&NotID="+NotID+"&page="+page;	
	
    xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		  if (xmlHttp.readyState == 4){ 
			if (xmlHttp.status == 200){ 
			  response = xmlHttp.responseText; // read the response
			  //server error?
			  if (response.indexOf("ERRNO") >= 0 || response.length == 0){
				alert(response.length == 0 ? "Server serror." : response); // Muestra un mensja de error
				return;
			  }

				if(response!=""){
					var PlaceHolder = document.getElementById("listaComentarios");
					PlaceHolder.innerHTML = response;
				}
			}
		  } 
	}	
    xmlHttp.send(null);
  }		
}

/*Encuestas*/
function VotarEncuesta(Encuesta, opc){
	if(opc){
		registrarVoto(Encuesta, opc);
	}else{alert("Seleccione una Opción");}	
}

function getEncuesta(encuesta){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {   
  	query = "registravotos.php?a=show&ID="+encuesta;
	
	xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		  if (xmlHttp.readyState == 4){ 
			if (xmlHttp.status == 200){ 
			  response = xmlHttp.responseText; // read the response
			  //server error?
			  if (response.indexOf("ERRNO") >= 0 || response.length == 0){
				alert(response.length == 0 ? "Server serror." : response); // Muestra un mensja de error
				return;
			  }
		  				
				if(response!=""){
					var PlaceHolder = document.getElementById("contenedorEncuesta");
					PlaceHolder.innerHTML = response;
				}
			}
		  } 
	}	
    xmlHttp.send(null);
  }
}

function registrarVoto(encuesta, opcionelegida){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {   
  	query = "registravotos.php?a=v&ID="+encuesta+"&Opc="+opcionelegida;
	
	xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		  if (xmlHttp.readyState == 4){ 
			if (xmlHttp.status == 200){ 
			  response = xmlHttp.responseText; // read the response
			  //server error?
			  if (response.indexOf("ERRNO") >= 0 || response.length == 0){
				alert(response.length == 0 ? "Server serror." : response); // Muestra un mensja de error
				return;
			  }
		  				
				if(response!=""){
					var PlaceHolder = document.getElementById("contenedorEncuesta");
					PlaceHolder.innerHTML = response;
				}
			}
		  } 
	}	
    xmlHttp.send(null);
  }
}

/*Dispara la búsqueda en el sitio*/
function search(aEvent){ 
query = document.getElementById("sbi").value; 
var myEvent = window.event ? window.event : aEvent; 
if(myEvent.keyCode==13){ 
	if(query!=""){ 
		location = "index.php?a=s&query="+query; 
		document.MM_returnValue = false;
	}else{ 
		if(query!="" && tipoBusqueda==false){ 
			document.formg.submit();
		}
	}
}else{ 
	if(query!=""){ 
		location = "index.php?a=s&query="+query; 
		document.MM_returnValue = false;
	}else{ 
		if(query!="" && tipoBusqueda==false){ 
			document.formg.submit();
		}
	}
}
document.MM_returnValue = false;
}

/*Muestra formulario de busqueda avanzada*/
function showBusquedaAvanzada(){
	document.getElementById("contenedorBusquedaAvanzada").style.display = "block";
}

/*Oculta formulario de busqueda avanzada*/
function cerrarBusquedaAvanzada(){
	document.getElementById("contenedorBusquedaAvanzada").style.display = "none";
}

/**************************************************************
Máscara de entrada. Script creado por Tunait! (21/12/2004)
Si quieres usar este script en tu sitio eres libre de hacerlo con la condición de que permanezcan intactas estas líneas, osea, los créditos.
No autorizo a distribuír el código en sitios de script sin previa autorización
Si quieres distribuírlo, por favor, contacta conmigo.
Ver condiciones de uso en http://javascript.tunait.com/
tunait@yahoo.com 
****************************************************************/
var patron = new Array(4,2,2)
function mascara(d, sep, pat, nums){
if(d.valant != d.value){
	val = d.value
	largo = val.length
	val = val.split(sep)
	val2 = ''
	for(r=0;r<val.length;r++){
		val2 += val[r]	
	}
	if(nums){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
		}
	}
	val = ''
	val3 = new Array()
	for(s=0; s<pat.length; s++){
		val3[s] = val2.substring(0,pat[s])
		val2 = val2.substr(pat[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q]
		}
		else{
			if(val3[q] != ""){
				val += sep + val3[q]
				}
		}
	}
	d.value = val
	d.valant = val
	}
}

/*FUNCION PARA CALENDARIO*/
function getCalendario(fecha){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {
	if(fecha!=""){
  		query = "preparacalendario.php?fecha="+fecha;
	}else query = "preparacalendario.php";
	
	
    xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		 if(xmlHttp.readyState == 0) { document.getElementById("calendarioContent").innerHTML = "Sending Request..."; }   
		 if(xmlHttp.readyState == 1) { document.getElementById("calendarioContent").innerHTML = "Cargando..."; }   
		 if(xmlHttp.readyState == 2) { document.getElementById("calendarioContent").innerHTML = "Cargando..."; }   
		 if(xmlHttp.readyState == 3) { document.getElementById("calendarioContent").innerHTML = "Cargando..."; }  			
		
		  if (xmlHttp.readyState == 4){ 
			if (xmlHttp.status == 200){ 
			  response = xmlHttp.responseText; // read the response
			  //server error?
			  if (response.indexOf("ERRNO") >= 0 /*|| response.indexOf("error") >= 0*/ || response.length == 0){
				alert(response.length == 0 ? "Server serror." : response); // Muestra un mensja de error
				return;
			  }
				if(response!=""){
					var PlaceHolder = document.getElementById("calendarioContent");
					PlaceHolder.innerHTML = response;					
				}
			}else{document.getElementById("calendarioContent").innerHTML = "Error al generar calendario. Vuelva a cargar la p&aacute;gina";}
		  } 
	}	
    xmlHttp.send(null);	
  } 
}

function PronosticoExt1(){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {

	query = "clima/isotermaxml.php?opc=1";	
	  
	if(xmlHttp.readyState == 0) { document.getElementById("ExtHoy").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 1) { document.getElementById("ExtHoy").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 2) { document.getElementById("ExtHoy").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 3) { document.getElementById("ExtHoy").innerHTML = "Cargando..."; }  	
	
    xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		  if (xmlHttp.readyState == 4){ 
			if (xmlHttp.status == 200){ 
			  response = xmlHttp.responseText; // read the response
			  //server error?
			  if (response.indexOf("ERRNO") >= 0 || response.length == 0){
				alert(response.length == 0 ? "Server serror." : response); // Muestra un mensja de error
				return;
			  }
		  				
				if(response!=""){
					PlaceHolder = document.getElementById("ExtHoy");
					PlaceHolder.innerHTML = response;
				}
			}else{alert("Error de lectura de respuesta del servidor.")}
		  } 
	}	
    xmlHttp.send(null);
  }		
}


