function ValidValue(val)
{
	return (val != null && val != "" && val != "undefined");
}

function ValidNumber(val)
{
	return (val != null && val != "" && val != "undefined" && !isNaN(val));
}

function ValidEmail(email)
{
	var reg = /^(\w+(?:(\.|\-)\w+)*)@((?:\w+(?:(\.|\-)\w+)*\.)+)([a-z\d]{2,})$/i;
	return reg.test(email);
}

function Error(id, desc)
{
	this.id = id;
	this.desc = desc;
	
	return this;
}

function ValidTextValueFocusedMsg(idElem, msgError)
{
	var elem = document.getElementById(idElem);
	
	if (!ValidValue(elem.value))
		throw new Error(idElem, msgError);
}

function ValidEmailFieldFocusedMsg(idElem, msgError)
{
	var elem = document.getElementById(idElem);
	
	if (!ValidEmail(elem.value))
		throw new Error(idElem, msgError);
}

function ValidIntegerFieldFocusedMsg(idElem, msgError)
{
	var elem = document.getElementById(idElem);
	
	if (!ValidNumber(elem.value))
		throw new Error(idElem, msgError);
}

function ValidationTextField(elemID, errorName, errorMsg)
{
	if (document.getElementById(elemID).value == "")
	{
		document.getElementById(elemID).focus();
		throw new Error(errorName, errorMsg);
	}
	return true;
}

function ValidationInfoForm(formID)
{
	try
	{
		ValidTextValueFocusedMsg("name", "Campo%20de%20preenchimento%20obrigat%C3%B3rio.");
		ValidTextValueFocusedMsg("surname", "Campo%20de%20preenchimento%20obrigat%C3%B3rio.");
		ValidEmailFieldFocusedMsg("email", "Email%20inv%C3%A1lido.");		
		ValidTextValueFocusedMsg("phone", "Campo%20de%20preenchimento%20obrigat%C3%B3rio.");
		ValidIntegerFieldFocusedMsg("n_pass", "Valor%20inv%C3%A1lido.");
		document.getElementById(formID).submit();
	}
	catch(e)
	{
		alert(decodeURI(e.desc));
		document.getElementById(e.id).focus();		
	}
}

function SubmitWeddingListForm()
{
	var ERROR_registration = '<span class="registoFormLabel">* O campo </span><span class="registoFormLabel" style="color:red;">Destino desejado </span><span class="registoFormLabel">&#233; de preenchimento obrigat&#243;rio.</span>';
	
	try
	{		
		ValidationTextField("pref_destination", "ERROR_registration", ERROR_registration);
		
		document.getElementById("error_DIV").style.display = "none";
		document.getElementById('weddingListForm').submit();
	}
	catch (e)
	{
		document.getElementById("error_DIV").innerHTML = e.desc;
		document.getElementById("error_DIV").style.display = "block";
	}
}



