function ValidValue(val)
{
	return (val != null && val != "" && val != "undefined");
}

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 FormSugestionsValidation(formID)
{
	try
	{
		ValidTextValueFocusedMsg("assunto", "Campo de preenchimento obrigatório.");
		ValidTextValueFocusedMsg("nome", "Campo de preenchimento obrigatório.");
		ValidTextValueFocusedMsg("apelido", "Campo de preenchimento obrigatório.");
		ValidEmailFieldFocusedMsg("email", "Email inválido.");
		ValidTextValueFocusedMsg("comentario", "Campo de preenchimento obrigatório.");		
		document.getElementById(formID).submit();
	}
	catch(e)
	{
		alert(e.desc);
		document.getElementById(e.id).focus();		
	}
}

function FormEventInscValidation(formID)
{
	try
	{
		ValidEmailFieldFocusedMsg("email", "Email inválido.");
		ValidTextValueFocusedMsg("nome", "Campo de preenchimento obrigatório.");
		ValidTextValueFocusedMsg("tel", "Campo de preenchimento obrigatório.");
		document.getElementById(formID).submit();
	}
	catch(e)
	{
		alert(e.desc);
		document.getElementById(e.id).focus();		
	}
}

function FormDEICardValidation(formID)
{
	try
	{
		ValidTextValueFocusedMsg("name", "Campo de preenchimento obrigatório.");
		ValidEmailFieldFocusedMsg("email", "Email inválido.");		
		document.getElementById(formID).submit();
	}
	catch(e)
	{
		alert(e.desc);
		document.getElementById(e.id).focus();		
	}
}

function SetElemValue(elem, value)
{
	elem.value = value;
}

function SetValidDate(elemName)
{
	try
	{
		var dateV = new Date(document.getElementsByName(elemName)[0].value, document.getElementsByName(elemName)[1].value, document.getElementsByName(elemName)[2].value);
		SetElemValue(document.getElementsByName(elemName)[0], dateV.getFullYear());
		SetElemValue(document.getElementsByName(elemName)[1], dateV.getMonth());
		SetElemValue(document.getElementsByName(elemName)[2], dateV.getDate());
	}
	catch(e)
	{}	
}

function SetDateValue(id, year, month, day, hour, minutes)
{
	document.getElementById(id).value = year + "-" + month + "-" + day + " " + hour + ":" + minutes;	
}


function UpdateDate(id)
{
	var year = document.getElementById(id + "_Year").value;
	var month = document.getElementById(id + "_Month").value;
	var day = document.getElementById(id + "_Day").value;
	var hour = document.getElementById(id + "_Hour").value;
	var minutes = document.getElementById(id + "_Minutes").value;
	SetDateValue(id, year, month, day, hour, minutes)
}


							
	
