function IsEmptyMod(input)
{
	if (input == undefined)
		return true;

	else if ($(input).val() == false || input == false)
		return true;

	else if (input.lenght == 0)
		return true;

	else
		return false;
}

function IsEmailMod(input)
{
	if (IsEmptyMod(input))
		return false;

	else
	{
		if (IsValidEmailMod(input))
			return true;
		else
			return false;
	}
}

function IsValidEmailMod(input)
{
	var rx = new RegExp("^[\\w-_\.+]*[\\w-_\.]\@([\\w]+\\.)+[\\w]+[\\w]$");
	return rx.test(input);
}

function CheckInput(type, element, error, main_error)
{
	if (error != undefined)
	{
		try
		{
			error = $(error);
			var show_erros = true;
		}
		catch (ex)
		{
			if (console)
				console.debug(ex);
		}
	}

	if (main_error != undefined)
	{
		try
		{
			main_error = $(main_error);
			var clear_main_error = true;
		}
		catch (ex)
		{
			if (console)
				console.debug(ex);
		}
	}
	
	if (type != undefined && element != undefined)
	{
		$(document).ready(function(){

			$(element).click(function(){
				if (show_erros)
				{
					if (error.is(":visible"))
					{
						error.fadeOut("fast");
						error.html("");
					}
				}

				if (clear_main_error)
					main_error.html("");
			});

			$(element).keyup(function(){
				if (show_erros)
				{
					if (error.is(":visible"))
						error.hide();
				}
			});

			$(element).blur(function(){
				if (type == "email")
				{
					if (!IsEmailMod($(this).val()) && show_erros)
					{
						error.html("<span style=\"color: red;\">Please specify a valid email.</span>");
						error.fadeIn("fast");
					}
				}

				else if (type == "field")
				{
					if (IsEmptyMod($(this).val()) && show_erros)
					{
						error.html("<span style=\"color: red;\">Please specify a value.</span>");
						error.fadeIn("fast");
					}
				}
			});
		});
	}
}
