var FLAG_SENDING = 0;
var FLAG_OK = 1;
var FLAG_ERROR = 2;
var stepTela = 1;
var flagEmpresa = false;
var URL_SAVE = 'plugins/others/save.php';
var vlMesa    = [2000,1600];
var vlConvite = [200,160];
var vlAssunto = ['Compra de Mesas','Compra de convites'];

StartVariables = function()
{
   stepTela = 1;
   StepAbsolute(1);
}

CheckQualidade = function()
{
  Result = $('form.Qualidade input.Required:checked').size() == 17;
  if (!Result)
   alert('Preencha o questionario corretamente.');
  else
   $("form.Qualidade strong").show();
  return Result;
}

CheckExistingEmailCredenciamento = function()
{
    $('#ErroCredenciamento').hide();
	$.ajax({
		url:URL_SAVE,
		data:'Action=CheckExistingEmail&Email=' + $('input#Email').val(),
		cache:false,
		beforeSend:function()
		{
		   $('#CheckingCredenciamento').show();
		},
		success:function(CodeHtml)
		{
			$('#CheckingCredenciamento').hide();
            if (CodeHtml=='Error')
              $('#ErroCredenciamento').show();
		}
	 });	    
}

CheckCredenciamento = function(ObjForm)
{
    var Retorno = CheckForm(ObjForm);
    
    if (Retorno)
      if ($('div#ErroCredenciamento:visible').size()==1)
      {
        Retorno = false;
        $('.SendingInformation').hide();
        alert('Utilize um email diferente do informado.');
        $('input#Email').focus();
      }  
    return Retorno;
}

CheckForm = function(ObjForm)
{
   var NomeForm = '#' + $(ObjForm).attr('id');
   return CheckFields($(NomeForm + " .Required"), 1);
}

CheckFields = function(Obj, flagAlert)
{
	var FieldError = '';
    Obj.each(function() {
		$(this).removeClass('ErrorField');
		if ($(this).val()=='')
		  { 
		     if (FieldError=='')
			   FieldError = $(this).attr('id');
			 $(this).addClass('ErrorField');
		  }
    });
	if ((FieldError!='') && ((flagAlert==1) || (flagAlert==2)))
	{
	  alert('Preencha os campos corretamente');
	  $("#" + FieldError).focus();
	}
	else if (flagAlert == 1)
      Comunicacao(FLAG_SENDING);
	return (FieldError=='');	
}

Comunicacao = function(Estado)
{
	 $('.ContactMessagesOk').hide();
	 $('.ContactMessagesError').hide();
	 $('.SendingInformation').hide();
	 switch(Estado) {
		case 0: {
   	       $('.SendingInformation').show();
		   break;	
		}
		case 1: {
   	       $('.ContactMessagesOk').show();
		   break;	
		}
		case 2: {
   	       $('.ContactMessagesError').show();
		   break;	
		}
	 }
}

function CreateBookmarkLink() {
 title = "Sindicarga";
 // Blogger - Replace with <$BlogItemTitle$>
 // MovableType - Replace with <$MTEntryTitle$>

 url = "http://www.sindicarga.org.br";
 // Blogger - Replace with <$BlogItemPermalinkURL$>
 // MovableType - Replace with <$MTEntryPermalink$>
 // WordPress -

 if (window.sidebar) { // Mozilla Firefox Bookmark
 window.sidebar.addPanel(title, url,"");
 } else if( window.external ) { // IE Favorite
 window.external.AddFavorite( url, title); }
 else if(window.opera && window.print) { // Opera Hotlist
 return true; }
} 

NextStep = function()
{
    MoveStep(1);	
}

PreviousStep = function()
{
	MoveStep(-1);
}

var stNext = '';

MoveStep = function(Step)
{
	if (stNext == '')
	  stNext = $("#btnNext").val();
	var lStep = stepTela + Step;
	StepAbsolute(lStep);
}

StepAbsolute = function(lStep)
{
	var stepError = 0;
	var Limit = flagEmpresa ? 4:6;
	if (lStep>=1 && lStep <=Limit)
	{
		var CheckValue = true;
		if (lStep > stepTela && !flagEmpresa)
		  for (i=1;i<lStep;i++)
		    {
		      CheckValue = CheckStep(i);
			  if (!CheckValue)
			    {
			      stepError = i;
			      break;
				}
			}
		if (CheckValue)
		{
		  $("#btnPrevious").attr('disabled',(lStep==1 ? 'disabled':''));
		  if (flagEmpresa)
		    $("#btnNext").css('disabled',(lStep>=4 ? 'disabled':''));
		  else
		    $("#btnNext").css('display',(lStep>=5 ? 'none':'inline'));
		  
		  $("#btnSalvar").css('display',(lStep>=5 ? 'inline':'none'));
		  
			$("#frmCurriculo .Steps:visible").hide();
			$("#frmCurriculo #stp_" + lStep.toString()).show();
			ChangeStep(lStep,stepTela);
			stepTela = lStep;
			if (lStep > 1)
			  $("#LoginCadastro").html($("#Email").val());
		}
		else
		{
			ChangeStep(stepError,stepTela);
			stepTela = stepError;
			$(".Steps:visible").hide();
			$("#stp_" + stepError.toString()).show();			
			alert('Preencha os campos corretamente');
		}
	}
}

MudarSenha = function()
{
	if (CheckFields($("#frmCurriculo .Required"),2))
	  if (ComparePasswordChange())
		 {
		   $('.classSavedData').hide();
		   Comunicacao(FLAG_SENDING);
		   $("#frmCurriculo").submit();
		 }
}

EnviarDados = function()
{
   if (ComparePassword())
	 {
	   Comunicacao(FLAG_SENDING);
	   $("#frmCurriculo").submit();
	 }
}

EvaluateObject = function(Obj)
{
	var Retorno = isDate(Obj.val());
	Obj.removeClass('ErrorField');
	if (!Retorno)
	  Obj.addClass('ErrorField');
	return Retorno;
}

EvaluateDate = function(Campo)
{
	return EvaluateObject($('#' + Campo));
}

CheckStep = function(ValueStep)
{
   var Retorno = CheckFields($("#stp_" + ValueStep.toString() + " .Required"),0);
   if (Retorno)
     switch(ValueStep) {
		case 1: {
		   Retorno = EvaluateDate('Nascimento'); 
		   break;	
		}
		case 4: {
		   $(".DateCheck").each(function() {
	          if ($(this).val()!='')
			    Retorno = Retorno && EvaluateObject($(this));
		   });
		   break;	
		}
	 }
   return Retorno;
}

ChangeStep = function(Active, Inactive)
{
	FileActive = 'steps_over_' + Active.toString() + '.jpg';
	FileInactive = 'steps_' + Inactive.toString() + '.jpg';
	
	if (flagEmpresa && Active == 4)
	  FileActive = 'step_empresa_over_4.jpg';
	  
	if (flagEmpresa && Inactive == 4)
	  FileInactive = 'step_empresa_4.jpg';	  
	
   	$("#Step" + Inactive.toString()).attr('src','plugins/curriculo/css/image/' + FileInactive);
	$("#Step" + Active.toString()).attr('src','plugins/curriculo/css/image/' + FileActive);
}

CheckLoginEmpresa = function(Obj)
{
		Email = $("#EmailEmpresa").val();
		Senha = $("#SenhaEmpresa").val();
		
		$.ajax({
			url:URL_SAVE,
			data:'Action=LogInEmpresa&Email=' + Email + '&Senha=' + Senha,
			cache:false,
			beforeSend:function()
			{
				$(Obj).children("#divEmailEnviadoLogin").hide();
			},
			success:function(CodeHtml)
			{
				Comunicacao(3);
				if (CodeHtml!='Logged')
				  $(Obj).children("#divEmailEnviadoLogin").html('<div id="EmailError">Usu&aacute;rio e/ou senha incorreto(s).</div>').show(); 
				else
   				  location='site.php?idPagina=40';
			}
		 });	
    return false;
}


CheckLogin = function(Obj)
{
	if (CheckForm(Obj))
	{
		Email = $("#EmailCheck").val();
		Senha = $("#SenhaCheck").val();
		$.ajax({
			url:'plugins/curriculo/cadastro.php',
			data:'Action=LoginCurriculos&Email=' + Email + '&Senha=' + Senha,
			cache:false,
			beforeSend:function()
			{
				$("#divEmailEnviadoLogin").hide();
			},
			success:function(CodeHtml)
			{
				Comunicacao(3);
				if (CodeHtml=='__false__')
				  $("#divEmailEnviadoLogin").html('<div id="EmailError">Usu&aacute;rio e/ou senha incorreto(s).</div>').show(); 
				else
				  {
					$("#TelaDados").html(CodeHtml);
					ChangeScreen(3);
				  }
			}
		 });	
    }
    return false;
}

ChangeScreen = function(idScreen)
{
   $(".Screen:visible").hide();
   $(".Screen:eq(" + idScreen.toString() + ")").show();
}

CheckExistingEmail = function(Value, idCurriculo)
{
   $("#divEmailEnviado").hide();
   if ((!flagEmpresa) && (Value != $("#EmailAtual").val()))
   {
	 $("#OkEmail").val('');
	 $("#EmailUtilizado").hide();
	 if (Value == '' || Value.indexOf('@')==-1)
	   $("#divEmailEnviado").html('<div id="Attention">Entre com o email corretamente</div>').show();
	 else
	   $.ajax({
		   url:URL_SAVE,
		   data:'Action=CheckAvaliabilityEmail&Email=' + Value + '&idCurriculo=' + idCurriculo,
		   cache:false,
		   beforeSend:function() {
			  $("#divEmailEnviado").html('<div id="Searching">Verificando se o email j&aacute; est&aacute; em uso...</div>').show();
		   },
		   success:function(CodeHtml)
		   {
			  $("#divEmailEnviado").hide();
			  if (CodeHtml == 'InUse')
				$("#EmailUtilizado").show();
			  else
				$("#OkEmail").val('Ok');
		   }
	   })	
   }
}

RequestPassword = function(Obj,SuccessObj)
{
   Value = Obj.val();
   
   if (Value == '' || Value.indexOf('@')==-1)
     {
	   alert('Entre com o email corretamente.');
	   Obj.focus();
	 }
   else
     $.ajax({
		url:URL_SAVE,
		data:'Action=SendEmailPassword&Email=' + Value,
		cache:false,
		beforeSend:function()
		{
			$("#frmLoginCurriculos .SendingInformation").show();
			SuccessObj.hide();
		},
		success:function(CodeHtml)
		{
			$("#frmLoginCurriculos .SendingInformation").hide();
			SuccessObj.html(CodeHtml).show();
		}
	 });
}

RequestPasswordEmpresa = function(Obj,SuccessObj)
{
   Value = Obj.val();
   
   if (Value == '' || Value.indexOf('@')==-1)
     {
	   alert('Entre com o email corretamente.');
	   Obj.focus();
	 }
   else
     $.ajax({
		url:URL_SAVE,
		data:'Action=SendEmailPasswordEmpresa&Email=' + Value,
		cache:false,
		beforeSend:function()
		{
			$("#frmLoginCurriculosEmpresa .SendingInformation").show();
			SuccessObj.hide();
		},
		success:function(CodeHtml)
		{
			$("#frmLoginCurriculosEmpresa .SendingInformation").hide();
			SuccessObj.html(CodeHtml).show();
		}
	 });
}

ComparePasswordChange = function()
{
	var Senha_1 = $("#Senha").val();
	var Senha_2 = $("#ConfirmarSenha").val();
	var Frase = '';
	
	if (Senha_1 != Senha_2)
	   Frase = 'As senhas n&atilde;o coincidem. Corrija por favor.';
	else if (Senha_1.length < 6 || Senha_1.length > 20)
	   Frase = 'A senha deve possuir entre 6 e 20 caracteres (letras, n&uacute;meros e/ou caracteres especiais).';
	
	$("#SenhaNaoConfere").html(Frase).css('display',(Frase != '' ? 'block':'none'));
	return (Frase == '');
}

ComparePassword = function()
{
	var Retorno = ($("#ConfirmarSenha").size() == 0);
    if (!Retorno)
	{
	  if (CheckStep(5))
	  {
		var Senha_1 = $("#Senha").val();
		var Senha_2 = $("#ConfirmarSenha").val();
		var Frase = '';
		
		if (Senha_1 != Senha_2)
		   Frase = 'As senhas n&atilde;o coincidem. Corrija por favor.';
		else if (Senha_1.length < 6 || Senha_1.length > 20)
		   Frase = 'A senha deve possuir entre 6 e 20 caracteres (letras, n&uacute;meros e/ou caracteres especiais).';
		
		$("#SenhaNaoConfere").html(Frase).css('display',(Frase != '' ? 'block':'none'));
		$("#SenhasOk").val((Frase=='' ? '1':''));
		Retorno = (Frase == '');
	  }
	  else
	    alert('Preencha os campos corretamente');
	}
	return Retorno;
}

DisableAllControls = function()
{
	$("#frmCurriculo input:text, #frmCurriculo select, #frmCurriculo textarea").keypress(function()
	{
		return false;
	});
   flagEmpresa = true;
}

LogOut = function()
{
    $.ajax({
	    url:URL_SAVE,
		data:'Action=LogOut',
		success:function()
		{
		     location='site.php?idPagina=' + xidPagina.toString();	
		}
	});
}

LogOutEmpresa = function(idPagina)
{
    $.ajax({
	    url:URL_SAVE,
		data:'Action=LogOutEmpresa',
		success:function()
		{
		     location='site.php?idPagina=' + idPagina.toString();	
		}
	});
}

ShowCurriculo = function(idCurriculo)
{
  $.ajax({
	  url:'plugins/curriculo/cadastro.php',
	  data:'idCurriculo=' + idCurriculo.toString(),
	  cache:false,
	  beforeSend:function()
	  {
		 $('#OpenCV').show();
	  },
	  success:function(CodeHtml)
	  {
		 StartVariables();
		 $('#OpenCV').hide();
         $("#Pesquisa").html(CodeHtml);
	  }
   });	
}

ShowCandidatos = function()
{
   $("#Pesquisa").html('');
   ChangeScreen(1);	
}

PrintCurriculos = function()
{
	Obj = ifrCandidatos.$(".CheckCurriculo:checked");
	var Ids = "";
	if (Obj.size() == 0)
	  alert('Selecione ao menos 1 para imprimir');
	else
	  {
		Obj.each(function()
		{
		   Ids += "&id[]="+ $(this).val();
		});
		alert(Ids);
	  }
}


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}

NovoCurriculo = function()
{
    $.ajax({
     	url:'plugins/curriculo/cadastro.php',
	    cache:false,
		success:function(CodeHtml)
		{
           $("#MntControlPanel").html(CodeHtml);			
		   StartVariables();
		}
    });
}

ResultadoPesquisa = function()
{
	 ForceFullSizePanels();
	 RunAjaxUniversal('plugins/others/resultadoqualidade.php','');
}

ConfirmacaoPresenca = function()
{
 ForceFullSizePanels();
 RunAjaxUniversal('plugins/others/listagempresenca.php','');
}

ShowAllPeople = function()
{
	if ($('.ListagemEmpresas:visible').size() > 0)
		$('.ListagemEmpresas').hide();
	else
		$('.ListagemEmpresas').show();
	$(".Result").each(function()
	{
	   Field = $(this).attr('id');
	   Option = $(this).attr('rel');
	   if (parseInt(Option) > 0)
	     GetPeople($(this),Field,Option);
	});
}

GetPeople = function(Place, Field, Option, ShowField)
{
   if ($(Place).parent().children('.ListagemEmpresas').size()==0)
	   $.ajax({
		 url:URL_SAVE,
		 data:'Action=GetPessoas&Field=' + Field + '&Option=' + Option.toString(),
		 beforeSend:function()
		 {
		   $(Place).parent().append('<div class="ListagemEmpresas"><center><img src="core/images/ajax-wait.gif"> Colentando a lista...</center></div>');
		 },
		 success:function(HtmlCode)
		 {
			 $(Place).parent().children('.ListagemEmpresas').html(HtmlCode);
		 }
	   });
   else
     if (ShowField)
	    $(Place).parent().children('.ListagemEmpresas').toggle();
}

DeleteAgenda77 = function(id)
{
   if (confirm('Excluir ?'))
		$.ajax({
			url:URL_SAVE,
			data:'Action=DeleteAgenda&id=' + id.toString(),
			cache:false,
      		success:function()
			{
				$('tr#idAgenda_' + id.toString()).remove();
			}
		 });	
}

PrintListagemPresenca = function()
{
  window.open('plugins/others/imprimirpresenca.php','', 'height=300, width=700');
}

Masks = function()
{
   $('.CNPJ').mask('99.999.999/9999-99');
   $('.CPF').mask('999.999.999-99');
   $('.DATA').mask('99/99/9999');
}

GetCobrancasCNPJ = function()
{
  var lCNPJ = $("form#frmCobrancaCNPJ input#CNPJ");
  if (lCNPJ.val() == '')
  {
    lCNPJ.focus();
    alert('Insira o CNPJ corretamente.');
  }
  else
    $.ajax({
       url:'plugins/others/cobrancas.php',
       data:'CNPJ=' + lCNPJ.val(),
       beforeSend:function()
       {
          $("div#ListagemCobrancas").html('<div class="Wait">Consultando no banco de dados...</div>');
       },
       success:function(HtmlResult) {
          $("div#ListagemCobrancas").html(HtmlResult);
       } 
    });
  return false;
}

GotoPageArquivo = function(Categoria, PaginaAtual)
{
    $.ajax({
       url:'plugins/arquivos/arquivos.php',
       data:'Categoria=' + Categoria + '&PaginaAtual=' + PaginaAtual.toString(),
       beforeSend:function()
       {
          $("td#WaitBox").html('<div class="Wait">Consultando...</div>');
       },
       success:function(HtmlResult) {
          $("div#divPaginasArquivos").html(HtmlResult);
       } 
    });	
}

ChangeAmount = function(Amount)
{
    Value = parseFloat($('input#Qtde').val()) + Amount;
    if (Value < 1)
      Value = 1;
    else if (Value > 99)
      Value = 99;
    $('input#Qtde').val(Value);
    if (Amount > 0)
      insertNewName();
    else  
      removeLastName();
    ChangePrice();
}

ChangePrice = function()
{
    if ($('input#Qtde').val()=='')
      $('input#Qtde').val('1');
    
    iIndex = parseInt($('#AssociadoSindicarga').val());
    Qtde = parseFloat($('input#Qtde').val());
    Price = vlConvite[iIndex];
    if ($('#btn_select_1:visible').size() != 0)
      $("#ValorUnitario").val(Price.toFixed(2).replace('.',','));
    Total = Price * Qtde; 
    $('label#lblValorTotal').html('R$ ' + Total.toFixed(2).replace('.',','))
}

showPanel = function(idPanel) 
{
    if (CheckForm($('#frmContato')))
    {
        $('.csNextPage').show();
        $('div.pnlPaineis').hide();
        $('div#pnlEscolha' + idPanel.toString()).show();
        
        $('.imgSelect').hide();
        $('.imgNormal').show();
        
        $('#btn_' + idPanel).hide();
        $('#btn_select_' + idPanel).show();
        $('#opcTipo').val(idPanel);
        $('#Assunto').val(vlAssunto[idPanel]); 
        
        iIndex = parseInt($('#AssociadoSindicarga').val());
        if (idPanel==1)
          $("#ValorUnitario").val(vlConvite[iIndex].toFixed(2).replace('.',','));
        else
          $("#ValorUnitario").val(vlMesa[iIndex].toFixed(2).replace('.',','));
    }
}

selectMesa = function(idMesa)
{
    objMesa = $('a#Mesa_' + idMesa.toString());
    if (objMesa.hasClass('csMesaDisponivel'))
   	  objMesa.removeClass('csMesaDisponivel').addClass('csMesaSelecionada');
    else
   	  objMesa.addClass('csMesaDisponivel').removeClass('csMesaSelecionada');
    catchValoresMesas();
}

catchValoresMesas = function()
{
    iIndex = parseInt($('#AssociadoSindicarga').val());
    
    // Mostra lista de mesas
    Total = 0;
    Html = '';
    if ($('#btn_select_0:visible').size() != 0)
      $("#ValorUnitario").val(vlMesa[iIndex].toFixed(2).replace('.',','));
    
    $('.csMesaSelecionada').each(function() {
       lidMesa = $(this).attr('rel');
       Html += '<input type="hidden" value="' + lidMesa + '" name="MesaSelecionada[]" />'; 
       Html += '<div class="csListaMesaSelecionada">Mesa ' + lidMesa + '<span style="float:right">R$ ' + vlMesa[iIndex].toFixed(2).replace('.',',') + '</span></div>'; 
       Total += vlMesa[iIndex];
    });
    Html += '<div class="csListaMesasTotal">Total <span style="float:right;font-weight:bold">R$ ' + Total.toFixed(2).replace('.',',') + '</span></div>'; 
    
    if (Total==0)
      Html = '';
    $('div#MesasSelecionadas').html(Html);
}

insertNewName = function()
{
    nextId = $('#ListaConvidados div').size() + 1;
    Html = '<div class="csNomeConvidado" id="idName' + nextId.toString() + '">' + nextId.toString() + ' - <input id="txtNome' + nextId.toString() + '" type="text" name="Convidado[]" value="" size="60" /><span style="float:right">';
    Html += '<select id="selTipoIdade' + nextId.toString() + '" name="TipoIdade[]" onchange="ShowIdade($(this).val(),' + nextId.toString() + ')"><option value="0" selected="selected">Adulto</option><option value="1">Crian&ccedil;a a partir de 6 anos</option></select>';
    Html += '<label id="Idade_' + nextId.toString() + '" style="display:none">Idade: <input id="IdadeCrianca' + nextId.toString() + '" size="5" maxlength="2" type="text" name="IdadeCrianca[]" value="" /></label>';
    Html += '</span></div>';
    $('div#ListaConvidados').append(Html);
}

removeLastName = function()
{
    RemoveId = $('#ListaConvidados div').size();
    if (RemoveId > 1)
      $('#idName' + RemoveId.toString()).remove();
}

ShowIdade = function(Value, id)
{
   if (Value==1)
     $('label#Idade_' + id).show();
   else
     $('label#Idade_' + id).hide();
}

CheckReserva = function()
{
    var Result = CheckForm($('#frmContato'));
    if (Result)
      if ($('#opcTipo').val()==0)
      {
         // Verificar mesas
         Result = ($('.csListaMesaSelecionada').size()!=0);
         if (!Result)
           alert('Selecione ao menos uma mesa.');
      }
      else
      {
         // Verificar convites
         Qtde = parseFloat($('#Qtde').val());
         for (i=1;i<=Qtde;i++)
         {
            lNome = $('#txtNome' + i.toString()).val();
            lTipoIdade = $('#selTipoIdade' + i.toString()).val();
            lIdade = $('#IdadeCrianca' + i.toString()).val(); 
            
            if (lNome == '')
            {
                Result = false;
                alert('Insira o nome do convidado corretamente.');
                break;
            } else if (lTipoIdade==1 && lIdade=='') {
                Result = false;
                alert('Se o convidado for menor, por favor, informe a idade.');
                break;
            }
         } 
      }
    
    if (Result)
      Result = confirm('Confirmar?');
    
    return Result; 
}

ChangeIdadeFrase = function(id, Value)
{
    if ($('#opcTipo').val()==0)
    {
        Obs = $('td#Obs' + id.toString());
        if (Value=='')
          Obs.html('');
        else
        {
           iIdade = parseFloat(Value);
           if (!iIdade)
             Obs.html('');
           else if (iIdade > 5)
             Obs.html('Paga valor integral do convite.');
           else
             Obs.html('N&atilde;o paga convite.');
        }
    }
}
