/**************************************************************************
Programa: 	        contacto.js
Directorio: 	    /web/webhost/tcard/htdocs/toditocard/js
Creacion:	        16-Octubre-2006 Fernando Garza
Modificaciones:    
**************************************************************************/

function validaDatos(){
	if (document.getElementById('nombre').value == ""){
		alert("El nombre no puede estar vacio");
		return false;
	}
	if (document.getElementById('telefono').value == ""){
		alert("El telefono no puede estar vacio");	
		return false;
	}
	if (document.getElementById('email').value == ""){
		alert("El correo electronico no puede estar vacio");
		return false;
	}
	if (document.getElementById('asunto').value == "" || document.getElementById('asunto').value == 0){
		alert("Debe elegir un asunto");
		return false;
	}
	if (document.getElementById('asunto').value == 1 || document.getElementById('asunto').value == 2){
		if (document.getElementById('username').value == ""){
			alert("El nombre de usuario no puede estar vacio");
			return false;
		}
	}
	if (document.getElementById('mensaje').value == ""){
		alert("El mensaje no puede estar vacio");
		return false;
	}
	if (!validaCorreo(document.getElementById('email'))){
		return false;
	}
	if (document.getElementById('telefono').value.length < 10){
		alert("El telefono debe contener 10 digitos:\n\nclave de la localidad + numero local");
		return false;
	}
	
	document.getElementById('datos').submit();
	return 0;
}

function validaCorreo(input){
	if(input.value != ""){
		var formato = /^([0-9a-zA-Z]|_|\.|-)+@[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)+$/;
		if (!formato.exec(input.value)){
			window.alert("El correo electronico no es valido!\n");
			input.select();
			return false;
		}
		return true;
	}
}
