jQuery(function($)
{	
	$("#b_save").click(function(){	
		band=ValidarForm($("#formulario"));
		if(!band){$("#msg_error").text("por favor corrija los campos de color rojo");
		$("#msg_error").css({color:"#FF0000"});
		}
		else $("#msg_error").text(" ");
		return band	});
	$("#b_preview").toggle(
		function(){	previewForm($("#formulario"));		$(this).val("Cancel Preview");	},
		function(){	cancelPreview($("#formulario"));	$(this).val("Preview");	});
	
});
	
function ValidarForm(form)
{
	var band=true;
	$(form).children(".not_null").each(function(i)
	{
		if($(this).val()=="" || $(this).val()=="NULL" || $(this).val()=="campo obligatorio")
		{
			$(this).not(":file").css({color:"#FF0000"}).val("campo obligatorio").one("focus",function(e)
				{
					$(this).css({color:"#000"});
					if($(this).not("select")){	$(this).val("");}				
				});
			band=false;
		}
	});
	$(form).children(".number").each(function(i)
	{
		if($(this).val()=="") ;
		else
		if(!(/^[0-9]+$/.test($(this).val())))
		{
			$(this).val("Solo Numeros").css({color:"#FF0000"}).one("focus",function()
			{
				$(this).css({color:"#000"}).val("");
			});
			band=false;
			
		}		
	});
	$(form).children(".email").each(function(i)
	{
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+.[A-Za-z0-9_.]+[A-za-z]$/;		
  		if(!(filter.test($(this).val())))
  		{
  			$(this).val("Incluya@").css({color:"#FF0000"}).one("focus",function(){ $(this).css({color:"#000"}); });
			band=false;
  		}
	});
	return band;
}

