// VALIDAR FORMULARIO


function isEmail(smail) {
	
	var re=/^[a-z0-9\-\.]+@[a-z0-9\-\.]+\.[a-z]{2,}$/i;
	
	if(smail.match(re))	{
		
		return false;
		
	} else {
				
		return true;
		
	}
}




function mensajeRespuesta(capa){


	var obj = document.getElementById(capa);
	
	obj.innerHTML="<h2>Contactar / <span class='color_rosa'>contact us</span></h2><div class='texto'><div><span class='color_rosa'>gracias</span> por contactar con nosotros, </div><br /><div>....en breve nos pondremos en <span class='color_rosa'>contacto con usted</span></div></div>";
	
}

// AJAX


function nuevo_ajax(){
	
	
	//Crear una variable de Bool para comprobar si se está usando Internet Explorer.
	var xmlhttp = false;
	
	//Comprobar si se está usando IE.
	try {
		//Si la versión de javascript es superior a la 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
	} catch (e) {
		//Si no, utilizar el tradicional objeto ActiveX.
		try {
			//Si se está usando Internet Explorer.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		
		} catch (E) {
			//En caso contrario no se debe estar usando Internet Explorer.
			xmlhttp = false;
		}
	}
	
	//Si no se está usando IE, crear una instancia ActiveX del objeto.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		
		xmlhttp = new XMLHttpRequest();
		
	}
	
	return xmlhttp;
	
}



function formulario(serverPage, objID,nombre,apellidos,telefono,mail,comentarios) {
	
		
		var xmlhttp = nuevo_ajax();
		
		var obj = document.getElementById(objID);
		
		var url = serverPage+"?nombre="+nombre+"&apellidos="+apellidos+"&telefono="+telefono+"&mail="+mail+"&comentarios="+comentarios+"&fuente=xhtml";
		
		xmlhttp.open("GET", url, true);
		
		xmlhttp.onreadystatechange = function() {
			
			if(xmlhttp.readyState == 1){
				
					obj.innerHTML = "Cargando...";	
					
			} else {
			
				if ( xmlhttp.readyState == 4 && xmlhttp.status == 200 ) {
					
					obj.innerHTML = xmlhttp.responseText;
			
				} 
			}
		
		}
		
		xmlhttp.send(null);
		
	}
	
	function validarFormulario(iden, pagina){
	
	
	var marca = 0;
	
	if(document.getElementById('nombre').value=="")marca=1;
		
	if(document.getElementById('mail').value=="")marca=1;

	
	if(marca==0){
		
		if(!isEmail(document.getElementById('mail').value)){
			
			//document.getElementById('contactar_form').submit();
			
			var nombre = document.getElementById('nombre').value;
			
			var apellidos = document.getElementById('apellidos').value;
			
			var telefono = document.getElementById('telefono').value;
			
			var mail = document.getElementById('mail').value;
			
			var comentarios = document.getElementById('comentarios').value;
		
			formulario(pagina, iden, nombre, apellidos, telefono, mail, comentarios);

		}else{
			
			alert("error mail");
			
		}
		
	}else{
	
		alert("rellene todos los datos");
		
	}
	
}


function openPopUp(pagina){

	window.open(pagina,'','toolbar=0,location=0,directories=0,status=yes,menubar=0,scrollbars=yes,resizable=yes,width=600,height=625,titlebar=yes');
	
}

