	function IsEmpty(tsId, tsMsg){
		if(document.getElementById(tsId).value == ''){
			alert(tsMsg);
			document.getElementById(tsId).focus();
		}
		return (document.getElementById(tsId).value == '');
	}

	function IsNumeric(tsId, tsMsg){
		sText = document.getElementById(tsId).value;
		var ValidChars = "0123456789";
		var IsNumber = true;
		var Char;
		for (i = 0; i < sText.length && IsNumber == true; i++){
			Char = sText.charAt(i);
			if (ValidChars.indexOf(Char) == -1){
				IsNumber = false;
			}
		}
		if (!IsNumber){
			alert(tsMsg);
			document.getElementById(tsId).focus();
		}
		return IsNumber;
	}
	
	function IsEmail(tsId, tsMsg){
		texto = document.getElementById(tsId).value;
		var mailres = true;
		var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
		var arroba = texto.indexOf("@",0);
		if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
		
		var punto = texto.lastIndexOf(".");
		for (var contador = 0 ; contador < texto.length ; contador++){
			if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
				mailres = false;
				break;
			}
		}
		if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
			mailres = true;
		else{
			mailres = false;
			alert(tsMsg);
			document.getElementById(tsId).focus();
		}
    	return mailres;
	}
	
	function valForm(){
		if (!IsEmpty('first_name', 'Por favor, escriba su nombre.')){
			if (!IsEmpty('last_name', 'Por favor, escriba su apellido.')){
				if ((!IsEmpty('home_phone', 'Por favor, escriba su telefono.')) && IsNumeric('home_phone', 'Telefono Invalido.')){
					if ((!IsEmpty('mobile_phone', 'Por favor, escriba su celular.')) && IsNumeric('mobile_phone', 'Mobile Invalido.')){
						if (!IsEmpty('email', 'Por favor, escriba su email.') && IsEmail('email', 'Email Invalido.')){
							if (!IsEmpty('state', 'Por favor, escoja su Estado.')){
								if (!IsEmpty('best_time_to_call', 'Por favor, escoja una hora para llamar.')){
									if (!IsEmpty('unsecured_debt', 'Le faltraon las Deudas.')){
										if ((!IsEmpty('zip_code', 'Por favor, escriba su zip code.')) && IsNumeric('zip_code', 'Zip Code Invalido.')){
											if (!IsEmpty('monthly_payment', 'Por favor, escriba su pago mensual.')){
												document.getElementById('frmContact').submit();
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
