
// JavaScript Document
date = new Date();
var Mes = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
var Dia = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
var tipo_grafico
var indice 

function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) { xmlhttp = false; }
    }
    return xmlhttp;
}


function open_me(id,titulo){
	//var my_top = (screen.width/2) - (440/2);
	//var my_left =(screen.height/2) - (650/2)
	window.open('visor.asp?id='+id+'&titulo='+titulo,'Nuevo','width=650,top=150,left=220,scrollbars=no,height=483');
}

//torta
function ver_encuesta(tipo,id_encuesta){
	var my_top = (screen.width/2) - (600/2);
	var my_left =(screen.height/2) - (390/2);	
	window.open('encuesta.asp?id_encuesta=' + id_encuesta + '&tipo='+tipo ,'Nuevo','width=600,top='+my_top+',left='+my_left+',scrollbars=no,height=390');
}
//barra
function ver_encuesta2(tipo,id_encuesta){
	var my_top = (screen.height/2) - (600/2);
	var my_left = parseInt((screen.width/2) - (485/2));	
	window.open('encuesta.asp?id_encuesta=' + id_encuesta + '&tipo='+tipo ,'Nuevo','width=600,top='+my_top+',left='+my_left+',scrollbars=no,height=485');
}

function seleccionar_grafico(tipo,id){	
	if(tipo == "1"){
		ver_encuesta(tipo,id)
	}else{
		ver_encuesta2(tipo,id)
	}

}




var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
var myStream 


function votar(ID){
		
	  tipo_grafico  = ID;	
	  if (!enProceso && http)
	 {
				if (myform.id_opc.value == 0){
					alert("Debe seleccionar una Opción como respuesta");
					return;
				}else{																							
					var url = 'grabaencuesta.asp?opcion=' + myform.id_opc.value;
					http.open("GET", url, true);
					http.onreadystatechange = handleHttpResponse;
					enProceso = true;
					http.send(null);	       
				}	
	 }
	

}

function codificar(texto)
{
	texto = texto.replace('á','a');
	texto = texto.replace('é','e');	
	texto = texto.replace('í','i');
	texto = texto.replace('ó','o');	
	texto = texto.replace('ú','u');
	
	texto = texto.replace('Á','A');
	texto = texto.replace('É','E');	
	texto = texto.replace('Í','I');
	texto = texto.replace('Ó','O');	
	texto = texto.replace('Ú','U');
		
	return texto;
}

function seleccioname(id){
	myform.id_opc.value = id;		
}

function handleHttpResponse() { 
    if (http.readyState == 4) { 
       if (http.status == 200) { 
          if (http.responseText.indexOf('invalid') == -1) 
		  	{
           																		 			 			 				 			 
				MyStream = http.responseText
				if (MyStream != ''){					
					if(confirm('¡Gracias por su Voto!\n¿Desea ver los resultados?')){						
					 if (tipo_grafico == "1"){
						    ver_encuesta(1,MyStream);
						}else{
							ver_encuesta2(2,MyStream);
						}
					}										
				}
																							
				 enProceso = false;				
          }else{alert( http.responseText.value );}
		  
       }else{alert('error 200'); enProceso = false;}
    }else{/*alert('error 4');*/}
}

function buscar(){
		
	if (myform.txtbuscar.value == '' ){
		alert('Debe introducir un parametro de busqueda');
		myform.txtbuscar.focus();
		return;		
	}
	
	myform.action = "buscador.asp?b=1&opcion=2&txtBusqueda=" + myform.txtbuscar.value		
	myform.submit();
	
}

function cargaXML(url) {

	if(url==''){
		return;
	}
	//	Mozilla
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send(null);
	//	Internet Explorer
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", url, true);
			req.send();
		}
	}
}

function processReqChange(){
	var detalles = document.getElementById("detalles");
	//var loading = document.getElementById("loading");
	if(req.readyState == 4){
		detalles.innerHTML = req.responseText;
	} else {
		detalles.innerHTML = '<font color="#FFFFFF" size="-1"><b><img src="/img/loading.gif" valing="middle" align="center" /><br>Cargando...</b></font>';
	}
}
