var HOSTJS = "http://www.diariopanorama.com/panoramatv/";

function getResultadosSeccion(SeccPtvID, seccion){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {   
  	query = "videos.php?SeccPtvID="+SeccPtvID;
    xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		 if(xmlHttp.readyState == 0) { document.getElementById("listavideos").innerHTML = "Sending Request..."; }   
		 if(xmlHttp.readyState == 1) { document.getElementById("listavideos").innerHTML = "Cargando..."; }   
		 if(xmlHttp.readyState == 2) { document.getElementById("listavideos").innerHTML = "Cargando..."; }   
		 if(xmlHttp.readyState == 3) { document.getElementById("listavideos").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("listavideos");
					PlaceHolder.innerHTML = response;
				}
			}else{alert("Error de lectura de respuesta del servidor.")}
		  } 
	}	
    xmlHttp.send(null);
 } 
}

function getResultadosHome(dia, mes, anio){
 if(dia<10) dia = "0"+dia;
 if(mes<10) mes = "0"+mes; 
	
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {   
  	if(anio!="" && mes!="" && dia!=""){
  		query = HOSTJS + "ultimosvideos.php?anio="+anio+"&mes="+mes+"&dia="+dia;
	}else query = HOSTJS + "ultimosvideos.php";

    xmlHttp.open("GET", query, true);	
 	xmlHttp.onreadystatechange = function (){
		 if(xmlHttp.readyState == 0) { document.getElementById("listavideos").innerHTML = "Sending Request..."; }   
		 if(xmlHttp.readyState == 1) { document.getElementById("listavideos").innerHTML = "Cargando..."; }   
		 if(xmlHttp.readyState == 2) { document.getElementById("listavideos").innerHTML = "Cargando..."; }   
		 if(xmlHttp.readyState == 3) { document.getElementById("listavideos").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("listavideos");
					PlaceHolder.innerHTML = response;
				}
			}else{alert("Error de lectura de respuesta del servidor.")}
		  } 
	}	
    xmlHttp.send(null);
  }  		
}


function getCalendario(mes, anio){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {
	if(mes!="" && anio!=""){
  		query = HOSTJS+"calendario.php?nuevo_mes="+mes+"&nuevo_year="+anio;
	}else query = HOSTJS+"calendario.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{alert("Error de lectura de respuesta del servidor.")}
		  } 
	}	
    xmlHttp.send(null);	
  } 
}

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);
}

// 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;
}

//Muestra los resultados de tombola
function PronosticoExt1(CodLocation, tipoSav){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {
	
		if(CodLocation=="SASE")
		query = HOSTJS+"clima/isotermaxml.php?opc=1";	
		else query = HOSTJS+"clima/headerxml.php?opc=1&CodLocation="+CodLocation+"&tipoSav="+tipoSav;
	
	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);
  }		
}

//Muestra los resultados de tombola
function PronosticoExt2(CodLocation, tipoSav){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {
	  
	query = HOSTJS+"clima/extendidoxml.php?opc=1&CodLocation="+CodLocation+"&tipoSav="+tipoSav;	
	
	if(xmlHttp.readyState == 0) { document.getElementById("ExtHoy2").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 1) { document.getElementById("ExtHoy2").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 2) { document.getElementById("ExtHoy2").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 3) { document.getElementById("ExtHoy2").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("ExtHoy2");
					PlaceHolder.innerHTML = response;
				}
			}else{alert("Error de lectura de respuesta del servidor.")}
		  } 
	}	
    xmlHttp.send(null);
  }		
}

//Muestra los resultados de tombola
function PronosticoExt3(CodLocation, tipoSav){
 var xmlHttp = createXmlHttpRequestObject(); // Referencia al Objeto XMLHttpRequest
  if (xmlHttp && (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)) {
	  
	query = HOSTJS+"clima/extendidoxml.php?opc=3&CodLocation="+CodLocation+"&tipoSav="+tipoSav;	
	
	if(xmlHttp.readyState == 0) { document.getElementById("ExtHoy3").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 1) { document.getElementById("ExtHoy3").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 2) { document.getElementById("ExtHoy3").innerHTML = "Cargando..."; }   
	if(xmlHttp.readyState == 3) { document.getElementById("ExtHoy3").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("ExtHoy3");
					PlaceHolder.innerHTML = response;
				}
			}else{alert("Error de lectura de respuesta del servidor.")}
		  } 
	}	
    xmlHttp.send(null);
  }		
}

function getClima(op){
	switch(op){
		case 1: 
			var CodLocation = document.getElementById("select_sgo").value;
			var CiudadIndex = document.getElementById("select_sgo");			
			var tipoSav = 1;
		break;
		case 2: 
			var CodLocation = document.getElementById("select_arg").value;
			var CiudadIndex = document.getElementById("select_arg");						
			var tipoSav = 1;
		break;
		case 3: 
			var CodLocation = document.getElementById("select_mundo").value;
			var CiudadIndex = document.getElementById("select_mundo");									
			var tipoSav = 2;
		break;		
	}	
	
	if(CodLocation!=""){
		PronosticoExt1(CodLocation, tipoSav);
		PronosticoExt2(CodLocation, tipoSav);
		PronosticoExt3(CodLocation, tipoSav);
		
		document.getElementById("ciudadID").innerHTML = CiudadIndex[CiudadIndex.selectedIndex].text;
		
	}else alert("Debe seleccionar una ciudad");
}

