var oXmlHttp;
function getData(cad, name, tipo){	
	var div = document.getElementById(name);
	var oXmlHttp = zXmlHttp.createRequest();
	if(oXmlHttp.readyState != 0){
		oXmlHttp.abort();
	}
	div.innerHTML = "<div align='center' style='height:170px;'><br/><img src='imagenes/indicator.gif' height='20' width='20'><br/>Cargando</div>";
	switch(tipo){
		case 1: oXmlHttp.open("get", "ajaxAlumno.php?"+cad, true);
				 break;
		case 2: oXmlHttp.open("get", "ajaxEmpresa.php?"+cad, true);
				  break;			
		case 3: oXmlHttp.open("get", "ajaxAdministrador.php?"+cad, true);
				  break;		
		case 4: oXmlHttp.open("get", "index.php?"+cad, true);
				  break;
	}
	oXmlHttp.onreadystatechange = function () {
				if (oXmlHttp.readyState == 4) {
					if (oXmlHttp.status == 200) {
						div.innerHTML = oXmlHttp.responseText;
					} else {
						div.innerHTML="An error occurred G: " + oXmlHttp.statusText; //statusText is not always accurate
					}
				}				
			};
			oXmlHttp.send(null);
			
}

function getDataPost(name, formulario){	
	var oForm = formulario;
	var sBody = getRequestBody(oForm);
	var div=document.getElementById(name);
	var oXmlHttp=zXmlHttp.createRequest();
	if(oXmlHttp.readyState != 0){
		oXmlHttp.abort();
	}
	div.innerHTML = "<div align='center' style='height:170px;'><br/><img src='imagenes/indicator.gif' height='20' width='20'><br/>Cargando</div>";
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	oXmlHttp.onreadystatechange = function () {
				if (oXmlHttp.readyState == 4) {
					if (oXmlHttp.status == 200) {
						div.innerHTML=oXmlHttp.responseText;						
					} else {
						div.innerHTML="An error occurred P: " + oXmlHttp.statusText; //statusText is not always accurate
					}
				}            
			};
			oXmlHttp.send(sBody);			
}

function getDataPostFile(name, formulario){
	var oForm = formulario;
	//var sBody = getRequestBody(oForm);
	var div=document.getElementById(name);
	var oXmlHttp=zXmlHttp.createRequest();	
	if(oXmlHttp.readyState != 0){
		oXmlHttp.abort();
	}
	oXmlHttp.open("post", oForm.action, true);
	oXmlHttp.setRequestHeader("Content-Type","multipart/form-data");
	
	oXmlHttp.onreadystatechange = function () {
				if (oXmlHttp.readyState == 4) {
					if (oXmlHttp.status == 200) {
						div.innerHTML=oXmlHttp.responseText;
					} else {
						div.innerHTML="An error occurred: " + oXmlHttp.statusText; //statusText is not always accurate
					}
				}            
			};
			oXmlHttp.send(sBody);
}		

function getRequestBody(oForm){
	var aParams = new Array();	
	for(var i=0 ; i <oForm.elements.length; i++){
		var sParam = encodeURIComponent(oForm.elements[i].name);
		sParam += "=";
		sParam += encodeURIComponent(oForm.elements[i].value);
		aParams.push(sParam);
	}
	return aParams.join("&");		
}