	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', 'Complete the First Name.')){
			if (!IsEmpty('last_name', 'Complete the Last Name.')){
				if ((!IsEmpty('home_phone', 'Complete the Home Phone.')) && IsNumeric('home_phone', 'Invalid Home Phone.')){
					if ((!IsEmpty('mobile_phone', 'Complete the Mobile Phone.')) && IsNumeric('mobile_phone', 'Invalid Mobile Phone.')){
						if (!IsEmpty('email', 'Complete the Email.') && IsEmail('email', 'Invalid Email Address.')){
							if (!IsEmpty('state', 'Complete the State.')){
								if (!IsEmpty('best_time_to_call', 'Complete the Best Time to Call.')){
									if (!IsEmpty('unsecured_debt', 'Complete the Unsecured Debt.')){
										if ((!IsEmpty('zip_code', 'Complete the Zip Code.')) && IsNumeric('zip_code', 'Invalid Zip Code.')){
											if (!IsEmpty('monthly_payment', 'Complete the Monthly Payment.')){
												document.getElementById('frmContact').submit();
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
