function pickRecentProgID(idList, enabledList){ 
    // found progID flag 
	var o2Store;
    var bFound = false; 
    for(var i=0; i < idList.length && !bFound; i++){ 
        try{ 
            var oDoc = new ActiveXObject(idList[i]); 
            o2Store = idList[i]; 
            bFound = true;            
        }catch (objException){ 
            // trap; try next progID 
        }; 
    };     
    idList = null; 
    return o2Store; 
};


_XMLHTTP_PROGID = pickRecentProgID(["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"], [["XMLHTTP", 4]]);


if(!window.XMLHttpRequest){ 
    /** 
     * Emulate XMLHttpRequest 
     * @constructor 
     */ 
    function XMLHttpRequest(){ 
        return new ActiveXObject(_XMLHTTP_PROGID); 
    }; 
};

function popup(url,ancho,alto,name){
	if(typeof(name)=='undefined')
		name='msgbox';
	var ventana=window.open(url,name,'width='+ancho+',height='+alto+',toolbar=no,scrollbars=yes,status=no');
	var left = (screen.width-ancho)/2;
	var top = (screen.height-alto)/2;
	ventana.moveTo(left, top);
	ventana.focus();
}

function popupMaximizado(url,name){
	if(typeof(name)=='undefined')
		name='msgbox';
	var ventana=window.open(url,name,'toolbar=no,scrollbars=yes,status=no,fullscreen=yes');
	ventana.focus();
}

// Funci?n para realizar peticiones (s?ncronas) a p?ginas. No parsea el
// resultado
// Par?metros:
//	method: cadena GET o POST.
//	url: cadena con la url a llamar.
//	params: cadena con los par?metros de la llamada, en formato param=valor separados por &.
// 	Si se elige GET, la url a llamar ser? url?params, luego
//  ojo de no duplicar esos par?metros al meterlos en la url.
// Si se elige POST, no poner nunca par?metros en url.
function doHttpRequest(method, url, params) {
	if (method.toUpperCase() == "GET" || method.toUpperCase() == "POST") {
		var send = '';
		var contentType = '';
		if (method.toUpperCase() == "GET")
			url = url + '?' + params;
		else {
			send = params;
			contentType = 'application/x-www-form-urlencoded'; 
		}
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open(method, url, false); // as?ncrono
		if (method.toUpperCase() == "POST")
			xmlhttp.setRequestHeader('Content-Type', contentType);
		xmlhttp.send(send);
		result = xmlhttp.responseText;
		return result;			
	} else 
		return null;
}

var genxmlhttp = new XMLHttpRequest();
function doAsyncHttpRequest(method, url, params,funcion) {
	if (method.toUpperCase() == "GET" || method.toUpperCase() == "POST") {
		var send = '';
		var contentType = '';
		if (method.toUpperCase() == "GET") 
			url = url + '?' + params;
		else {
			send = params;
			contentType = 'application/x-www-form-urlencoded'; 
		}
		genxmlhttp.onreadystatechange=funcion;
		genxmlhttp.open(method, url, true); // as?ncrono
		if (method.toUpperCase() == "POST") 
			genxmlhttp.setRequestHeader('Content-Type', contentType);
		genxmlhttp.send(send);
		return true;			
	} else 
		return false;
}

function generar_aleatoria(min,max,pass,conf_pass,noAjax){
	min=6;
	max=12;
	var generarpass='si';
	var usuario=document.getElementById('usuario').value;
	var method = 'POST';
	var clave='';
	var aleatorio=0;
	var diferencia=max-min;
	var longitud=min+parseInt(Math.random()*diferencia);
	caracteres=new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
				"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
				"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
				"u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
				"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
				"U", "V", "W", "X", "Y", "Z");
	do{
		aleatorio=Math.random();
		clave=clave+caracteres[parseInt(62*aleatorio)];
	}while(clave.length<longitud);

	//document.getElementById('contra').type='text';
	document.getElementById('contra').value=clave;
	document.getElementById('confirmar_password').value=clave;

}

function contadorTiempo(){
	var tiempo=document.getElementById('tiempo').value;
	
	tiempo--;
	
	if(tiempo == 0 || tiempo<0){
		document.getElementById("contador").innerHTML="Tiempo: <div>Tiempo agotado</div>";
		clearInterval(intervalo);
		document.getElementById('tiempo').value=0;
		alert("Se te ha acabado el tiempo.");
		document.getElementById('pagina').value=document.getElementById('totalPreguntas').value;
		paginacion(1);
	}else{
		document.getElementById('tiempo').value=tiempo;
					
		tiempo=parseInt(tiempo);
		
		var min=parseInt(tiempo/60);
		var seg=parseInt(tiempo%60);
		
		if(min<10){
			min='0'+min;
		}
		
		if(seg<10){
			seg='0'+seg;
		}
		
		document.getElementById("contador").innerHTML="Tiempo: <div>"+min+":"+seg+"</div>";
	}
}
function abrirVentanaServicio(ruta,titulo,popup) {
	if(!popup){
		window.open(ruta,titulo.split(" ").join("_"));
		return;
	}
    var alto;
    var ancho;
    var anchomedio;
    var propiedades
    alto = window.screen.height;
    ancho = window.screen.width;
    anchomedio = ancho/2-1007/2; 
    altomedio = alto/2-alto/2;
    propiedades = "width=1007px,height="+alto+"px,toolbar=no,directories=no,menubar=no,status=no,left="+anchomedio+"px,top="+altomedio+"px";
    window.open(ruta,titulo.replace(" ","_"), propiedades);
}
//Limita un texArea a los caracteres que le indiques
function maximoCaracteres(campo,limite){
		if(campo.value.length>=limite){
			campo.value=campo.value.substring(0,limite);
		 }
}
