function getHTTPObject(){
 var xmlhttp = null;
 //Internet Explorer
 try {
	  xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
 }
 catch (e) {
	  try  {
		   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }	
	  catch (e)
	  {
		   xmlhttp = null;
	  }
 }

 //Mozilla y Safari

 if ((xmlhttp == null) && (typeof XMLHttpRequest != 'undefined')){
	  try {
	   xmlhttp = new XMLHttpRequest();
	  }
	  catch (e){
		   xmlhttp = null;
	  }
 }
 return xmlhttp;
}


function invierteFechaSQL(fecha,caracter){
	fechaT = fecha.split(caracter);
	var nuevaFecha = fechaT[2]+"-"+fechaT[1]+"-"+fechaT[0];
	return nuevaFecha;
}


function desconectarusuario(){
	var reqProducto = getHTTPObject();
	reqProducto.open("get","desconectarusuario.php",false);
	reqProducto.send(null);
	try{
		
		document.getElementById("sesionusr").innerHTML=reqProducto.responseText;
		document.location.reload();
	}
	catch(e){ 
	//nada
	}
}

function conectarusuario(){
	var elusuario = document.getElementById("usr").value;
	var elpass = document.getElementById("pass").value;
	var reqProducto = getHTTPObject();
	reqProducto.open("post","conectarusuario.php",false);
	reqProducto.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	reqProducto.send("usr="+elusuario+"&pass="+elpass);
	//alert(reqProducto.responseText);
	if(reqProducto.responseText=="no")document.getElementById("errordeconexion").style.display="";
	else{
	try{
		
		document.getElementById("sesionusr").innerHTML=reqProducto.responseText;
		document.location.reload();
	}
	catch(e){ 
	//nada
	}
	}
}

function controlDeFormularios(obj){
		for(a in obj.elements){
			var objComp =obj.elements[a];
			try{
				if(objComp.getAttribute("obligatorio").toUpperCase()=="SI"){
					if(objComp.value.length==0){
						alert("Hay campos Obligatorios no rellenados\nReviselos.  Por Favor");
						objComp.onfocus = function (){
							objComp.style.backgroundColor="#FF0000";
						}
						objComp.onblur = function (){
							objComp.style.backgroundColor="#FFFFFF";
							objComp.onfocus=function (){return true};
						}
						objComp.focus();
						return false;
					}
				}
			}
			catch(e){}
		}
		return true;
}