/*
Created by Franco Risso for 720desarrollos.com.ar
Dependes on jquery>1.0

*/

function check_email(val)
{
	if(!(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(val)))
	{
		return false;
	}
	else
		return true;
}

function check_justLetters(val)
{
	var num=val.length;
	if(!(/\D{2,}/.test(val)) || (/\d{2,}/.test(val)))
	{
		return false;
	}
	else
		return true;
}

function check_numbers(val)
{
	var num=val.length;
	if(!(/(\D?\d\D?){10,}/.test(val)))
	{
		return false;
	}
	else
		return true;
}
var erasas;
function submit_form(f)
{
	var error=false;
	$("#error-display").css("display","none");
	$(".valid").each(function(){
		
		if(this.value==this.title)
		{
			error=true;
			errorMsg="Por favor completa los campos resaltados.";
			this.style.background='#f9b0b0';
		}
		else
			this.style.background='#FFF';
	});
	if(!error)
	{
		$(".email").each(function(){
			if(this.value.length)
			{
				if(!check_email(this.value))
				{
					error=true;
					errorMsg="Formato de e-mail incorrecto";
					this.style.background='#f9b0b0';
				}
				else
				this.style.background='#FFF';
			}
		});
	}
	var code=$("#code").val();
	$.post("includes/validCaptcha.php",{code:code},function(res){
		if(error)
		{
			window.alert(errorMsg);
			
		}
		else if(!parseInt(res))
		{
			errorMsg="Codigo de validacion incorrecto.";
			window.alert(errorMsg);
		}
		else
		{
			$("#"+f).submit();
		}
	});
}


function submit_form2(f)
{
	var error=false;
	$(".valid").each(function(){
		
		if(this.value==this.title)
		{
			error=true;
			errorMsg="Please Complete the highlighted fields.";
			this.style.background='#f9b0b0';
		}
		else
			this.style.background='#FFF';
	});
	
	if(error)
	{
		window.alert(errorMsg);
		
	}
	else
	{
		$("#"+f).submit();
	}
	
	return true;
}