function trim(str) {
	return str.replace(/^\s+|\s+$/g, "");
}

function vazio(campo, nome)
{
	if (trim(campo.value) == "") {
		alert("Por favor preencha o campo " + nome + "!");
		campo.focus();
		return true;
	}

	campo.value = trim(campo.value);
	return false;
}

function parado(campo, nome)
{
	if ( campo.selectedIndex == 0 ) {
		alert("Por favor selecione algo no campo " + nome + "!");
		campo.focus();
		return true;
	}

	return false;
}

function checkMail(mail)
{
	var er = new RegExp(
			/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

	if( typeof(mail) == "string" )
	{
		if (er.test(mail))
			return true;
	}
	else if( typeof (mail) == "object" )
	{
		if (er.test(mail.value))
			return true;
	}

	if( typeof (mail) == "object" )
		mail.focus();

	alert('E-mail inválido!');
	return false;
}


function exibe_contato(){
    if( $('#div_contato').css('display') != 'none' )
        $('#div_contato').dialog('open');
    else
        $('#div_contato').dialog('close');
}

function exibe_fotografo()
{
    if( $('#div_fotografo').css('display') != 'none' )
        $('#div_fotografo').dialog('open');
    else
        $('#div_fotografo').dialog('close');
}

$(document).ready(function(){
    $('#div_contato').dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        width: 395,
        height: 430
        /* draggable: false */
    });

    $('#div_fotografo').dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        width: 600,
        height: 345
        /* draggable: false */
    });

	$('#frm_contato').submit(function(){
		if( vazio( document.frm_contato.nome, 'Nome' ) )
			return false;
		else if( vazio( document.frm_contato.email, 'E-mail' ) )
			return false;
		else if( !checkMail( document.frm_contato.email ) )
			return false;
		else if( vazio( document.frm_contato.telefone, 'Telefone' ) )
			return false;
		else if( vazio( document.frm_contato.evento, 'Evento' ) )
			return false;
		else
			return true;
	});
});
