function foco(elemento) {
 //elemento.style.border = "1px solid #A6A6A6";
  elemento.style.border = "1px solid #79767c";
  elemento.style.backgroundColor="#F5D077";
/* document.getElementById(elemento.name).style.color="#444444";*/
}

function no_foco(elemento) {
 elemento.style.border = "1px solid #19415C";
 elemento.style.backgroundColor="#FFFFFF";
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function ValidaUsuario(formulario)
 {
   var alfanumerico=/\w/;
   var user=/^[a-zd_]{5,15}$/i;
   var pass=/(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{5,15})$/;
   var correo=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
   
   if(alfanumerico.test(formulario.UNombre.value)) {
	   document.Usuario.UNombre.style.backgroundColor="white";
   }
   else {
	   alert("Please verify your information, name field is blank");
	   document.Usuario.UNombre.style.backgroundColor="#8C8C8C";
	
   }
   if(user.test(formulario.ULogin.value)) {
	   document.Usuario.ULogin.style.backgroundColor="white";
   }
   else {
	   alert("Please verify your information, username field is blank");
	   document.Usuario.ULogin.style.backgroundColor="#8C8C8C";
   }
   if(pass.test(formulario.UContrasena.value)) {
	   document.Usuario.UContrasena.style.backgroundColor="white";
   }
   else {
	   alert("Please verify your information, password field is blank");
	   document.Usuario.UContrasena.style.backgroundColor="#8C8C8C";
   }
   
   if(correo.test(formulario.UCorreo.value)) {
	   document.Usuario.UCorreo.style.backgroundColor="white";
   }
   else {
	   document.Usuario.UCorreo.style.backgroundColor="#8C8C8C";
   }
   if(alfanumerico.test(formulario.UNombre.value) && user.test(formulario.ULogin.value) && pass.test(formulario.UContrasena.value) && correo.test(formulario.UCorreo.value)) {
	 return true;
   }
   else {
     return false;
   }  
 }
 
 
  function ValidaContacto(formulario)
 {
   var alfanumerico=/\w/;
   var user=/^[a-zd_]{5,15}$/i;
   var pass=/(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{5,15})$/;
   var correo=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
   
   if(alfanumerico.test(formulario.CNombre.value)) {
	   document.Contacto.CNombre.style.backgroundColor="white";
   }
   else {
	   document.Contacto.CNombre.style.backgroundColor="#8C8C8C";
	
   }
   if(correo.test(formulario.CCorreo.value)) {
	   document.Contacto.CCorreo.style.backgroundColor="white";
   }
   else {
	   document.Contacto.CCorreo.style.backgroundColor="#8C8C8C";
   }
   if(alfanumerico.test(formulario.CAsunto.value)) {
	   document.Contacto.CAsunto.style.backgroundColor="white";
   }
   else {
	   document.Contacto.CAsunto.style.backgroundColor="#8C8C8C";
   }
   if(alfanumerico.test(formulario.CMensaje.value)) {
	   document.Contacto.CMensaje.style.backgroundColor="white";
   }
   else {
	   document.Contacto.CMensaje.style.backgroundColor="#8C8C8C";
	
   }
   if(alfanumerico.test(formulario.CNombre.value) && correo.test(formulario.CCorreo.value) && alfanumerico.test(formulario.CAsunto.value) && alfanumerico.test(formulario.CMensaje.value)) {
	 return false;
   }
   else {
     return false;
   }  
 }
 
 
 
 
 
 $(document).ready(function()
{
	$("#login_form").submit(function()
	{
		
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Validando usuario...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("ajax_login.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() },function(data)
        {
		  if(data=='yes') //if correct login detail
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Autenticando ...').addClass('messageboxok').fadeTo(900,1,
              function()
			  { 
			  	 //redirect to secure page
				 document.location='galeria.php';
			  });
			  
			});
		  }
		  else if(data=='disabled')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Cuenta de Usuario Deshabilitada').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else if(data=='disabled2')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Existe una sesión activa').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else 
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Usuario y/o Contrase&ntilde;a incorrectos').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
				
        });
 		return false; //not to post the  form physically
	});
});

