function muestraMenu(menu) {
	ajustarMenu(menu,160);	
}

function ocultaMenu(menu) {
	ajustarMenu(menu,25);	
}

function ocultaMenu2(menu) {
	ajustarMenu(menu,160);	
}

function ajustarMenu (menu,ancho) {
	menu.style.width=ancho + "px";
}

function EvaluateText(cadena, obj, e){
opc = false;
tecla = (document.all) ? e.keyCode : e.which;
if (cadena == "%d")
if (tecla > 47 && tecla < 58)
opc = true;
if (cadena == "%f"){
if (tecla > 47 && tecla < 58)
opc = true;
if (obj.value.search("[.*]") == -1 && obj.value.length != 0)
if (tecla == 46)
opc = true;
}
return opc;
}

function Validate_String(string, return_invalid_chars)
         {
         valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         invalid_chars = '';
         
         if(string == null || string == '')
            return(true);
         
         //For every character on the string.   
         for(index = 0; index < string.length; index++)
            {
            char = string.substr(index, 1);                        
            
            //Is it a valid character?
            if(valid_chars.indexOf(char) == -1)
              {
              //If not, is it already on the list of invalid characters?
              if(invalid_chars.indexOf(char) == -1)
                {
                //If it's not, add it.
                if(invalid_chars == '')
                   invalid_chars += char;
                else
                   invalid_chars += ', ' + char;
                }
              }
            }                     
            
         //If the string does not contain invalid characters, the function will return true.
         //If it does, it will either return false or a list of the invalid characters used
         //in the string, depending on the value of the second parameter.
         if(return_invalid_chars == true && invalid_chars != '')
           {
           last_comma = invalid_chars.lastIndexOf(',');
           
           if(last_comma != -1)
              invalid_chars = invalid_chars.substr(0, $last_comma) + 
              ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
                      
           return(invalid_chars);
           }
         else
           return(invalid_chars == ''); 
         }


function validarEmail(email_address)
         {
         //Assumes that valid email addresses consist of user_name@domain.tld
         at = email_address.indexOf('@');
         dot = email_address.indexOf('.');
         
         if(at == -1 || 
            dot == -1 || 
            dot <= at + 1 ||
            dot == 0 || 
            dot == email_address.length - 1)
            return(0);
            
         user_name = email_address.substr(0, at);
         domain_name = email_address.substr(at + 1, email_address.length);                  
         
         if(Validate_String(user_name) === false || 
            Validate_String(domain_name) === false)
            return(0);                     
         
         return(1);
         }



function validar(){
	
		String.prototype.trim= function() {//Agrega la función trim al objeto String
		   return this.replace(/(^\s*)|(\s*$)/g,""); //elimina espacios a izquierda y derecha
   		}

	
		var nombre="";
		var telefono="";
		var correo_electronico="";
		var asunto="";
	
		if( document.getElementById('nombre')){
			nombre = document.getElementById('nombre').value;
		}
		
		if( document.getElementById('telefono')){
			telefono = document.getElementById('telefono').value;
		}
		
		if( document.getElementById('correo_electronico')){
			var valor= validarEmail(document.getElementById('correo_electronico').value);
			correo_electronico = document.getElementById('correo_electronico').value;
		}
		
		if( document.getElementById('asunto')){
			asunto = document.getElementById('asunto').value;
		}
		
		var entrar = 1;
		
		if(nombre=='' && nombre.replace(/\s/g,"") == ""){
			entrar = 0;
		}
		
		if(telefono=='' && telefono.replace(/\s/g,"") == ""){
			entrar=0;	
		}
		
		if(entrar && valor){
			
				/*xmlhttp=GetXmlHttpObject();
				if (xmlhttp==null)
				  {
				  alert ("Browser does not support HTTP Request");
				  return;
				  }
				  
				var url="ajax_email.php";
				
				url=url+"?nombre="+nombre;
				url=url+"&telefono="+telefono;
				if(correo_electronico!=""){
					url=url+"&correo_electronico="+correo_electronico;
				}
				if(asunto!=""){
					url=url+"&asunto="+asunto;
				}
				url=url+"&sid="+Math.random();
				
				xmlhttp.onreadystatechange=stateChanged;
				xmlhttp.open("GET",url,true);
				xmlhttp.send(null);*/
				
				 document.formulario_contacto.submit(); 
			
				
			}else{
				alert('Alguno de los dos campos obligatorios, Nombre o Telefono, le falta por rellenar o puede que su email sea incorrecto. Gracias.');			
			}
		
	
		
	}
	
function stateChanged()
{
if (xmlhttp.readyState==4)
{
	if(xmlhttp.responseText=="1"){
		location.href='http://www.limonpublicidad.com/gracias.php';
		/*alert(xmlhttp.responseText);
		alert('Email enviado correctamente. En breves nos pondremos en contacto con usted. Gracias.');
		document.getElementById('nombre').value="";
		document.getElementById('telefono').value="";
		document.getElementById('correo_electronico').value="";
		document.getElementById('asunto').value="";*/
	}else{
		alert('Alguno de los dos campos obligatorios, Nombre o Telefono, le falta por rellenar o puede que su email sea incorrecto. Gracias.');	
	}
}
}
	
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}