/* --------------------------  Popup ---------------------------- */

function abrirVentana (URL){ 

   window.open (URL,"ventana1","width=500,height=400,scrollbars=yes,resizable=no") 

}
function abrirVentana2 (URL){ 

   window.open (URL,"ventana1","width=350,height=280,scrollbars=yes,resizable=no") 

}

function abrirVentana3 (URL){ 

   window.open (URL,"ventana1","width=350,height=280,scrollbars=yes,resizable=no") 

}

function calcularIMC()
{
	var Kg = document.getElementById("Kg").value;
	var Cm = document.getElementById("CM").value;
	if (Kg != "" && Cm != "")
	{
		var metros = Cm/100;
		var IMC = Math.round((Kg/(metros * metros))*100)/100;
		
		if (IMC < 19)
			var texto = "estás delgado/a";
		else if (IMC <= 25)
			var texto = "estás en un rango normal";
		else if (IMC <= 30)
			var texto = "tienes sobrepeso";
		else if (IMC <= 35)
			var texto = "tienes obesidad";
		else if (IMC <= 40)
			var texto = "tienes obesidad severa";
		else if (IMC > 40)
			var texto = "tienes obesidad muy severa";
		

		alert ("Tu IMC es: "+IMC+", "+texto+".");
	}
	
	  	 
}


function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

/*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
/////// AJAX
function createRequestObject(){
	  var peticion;
	  var browser = navigator.appName;
			if(browser == "Microsoft Internet Explorer"){
				  peticion = new ActiveXObject("Microsoft.XMLHTTP");
			}else{
				  peticion = new XMLHttpRequest();
}
return peticion;
}

var http = new Array();
function ObtDatos(url)
{
	var act = new Date();
	http[act] = createRequestObject();
	http[act].open('get', url);
	http[act].onreadystatechange = function() 
	{
		if (http[act].readyState == 4) 
		{
			if (http[act].status == 200 || http[act].status == 304) 
			{
				var texto;
				texto = http[act].responseText;
				var DivDestino = document.getElementById("laEncuesta");
				if (texto != "Error")
					DivDestino.innerHTML = '<div>'+texto+'</div>';
			}
		}
	}
	http[act].send(null);
}
 
function encuesta(accion) {
	
	  var voto = getCheckedValue(document.formencuesta.voto);
	  var ID_encuesta = document.formencuesta.ID_encuesta.value;
	  
	  
	  var DivDestino = document.getElementById("laEncuesta");
	  //document.getElementById("botonvotar").style.display = "none";
	  
	  DivDestino.innerHTML = "<div></div>";
	  if (accion) 
	  {
		  	ObtDatos("ajax_encuesta.php?accion="+accion+"&voto="+voto+"&ID_encuesta="+ID_encuesta);
	  } 
}

function encuestaMostrar(ID_encuesta) {
	  var DivDestino = document.getElementById("laEncuesta"); 
	  var resultados = document.getElementById("resultados").value;
	  
	  DivDestino.innerHTML = "<div></div>";
   	  ObtDatos("ajax_encuesta.php?ID_encuesta="+ID_encuesta+"&resultados="+resultados);
}
