﻿function validarRegistoCamposEmpresa()
{
        if($("#nomeEmpresa").val() == '' || $("#nomeEmpresa").val() == 'Nome Empresa')
	    {
	        alert("Por favor introduza o nome da empresa.");
	        $("#nomeEmpresa").focus();
	        return false;
	    } 
	    
	    if(!isNumber(document.getElementById("telemovel").value))
	    {
	        alert("Por favor de introduza o numero de telemóvel.");
	    
	        $("#telemovel").focus();
	    
	        return false;
	    }
	    if($("#telemovel").val() == '' || !isNumber(document.getElementById("telemovel").value) || $("#telemovel").val() == 'Telemóvel')
	    {
	        alert("Por favor de introduza o numero de telemóvel.");
	        $("#telemovel").focus();
	        return false;
	    } 
	    
	    if($("#ncolaboradores").val() == '' || !isNumber(document.getElementById("ncolaboradores").value) || $("#ncolaboradores").val() == 'Número de Colaboradores')
	    {
	        alert("Por favor introduza o numero de colaboradores.");
	        $("#ncolaboradores").focus();
	        return false;
	    } 
	    
	    if($("#email").val() == '' || !ValidateEmail(document.getElementById("email").value) || $("#email").val() == 'Email')
	    {
	        alert("Por favor introduza um email válido.");
	        $("#email").focus();
	        return false;
	    } 
	    
	    if($("#nif").val() == '' || !isNumber(document.getElementById("nif").value) || $("#nif").val() == 'NIF')
	    {
	        alert("Por favor introduza o NIF.");
	        $("#nif").focus();
	        return false;
	    } 
	    
	    if($("#morada").val() == '' || $("#morada").val() == 'Morada')
	    {
	        alert("Por favor introduza uma morada.");
	        $("#morada").focus();
	        return false;
	    } 
	    
	    if($("#pessoaContacto").val() == '' || $("#pessoaContacto").val() == 'Pessoa de Contacto')
	    {
	        alert("Por favor introduza uma Pessoa de Contacto.");
	        $("#pessoaContacto").focus();
	        return false;
	    }
	    
	    if($("#codigoPostal").val() == '' || !isNumber(document.getElementById("codigoPostal").value) || $("#codigoPostal").val() == 'Código Postal')
	    {
	        alert("Por favor introduza o código postal.");
	        $("#codigoPostal").focus();
	        return false;
	    }
	    
	    if($("#codigoPostal2").val() == '' || !isNumber(document.getElementById("codigoPostal2").value))
	    {
	        alert("Por favor introduza o código postal.");
	        $("#codigoPostal2").focus();
	        return false;
	    }
	    
	    if($("#codigoPostal3").val() == '')
	    {
	        alert("Por favor introduza o código postal.");
	        $("#codigoPostal3").focus();
	        return false;
	    }
	    
	    if($("#telefone").val() == '' || !isNumber(document.getElementById("telefone").value) || $("#telefone").val() == 'Telefone')
	    {
	        alert("Por favor introduza o numero de telefone.");
	        $("#telefone").focus();
	        return false;
	    }
	    
	    if($("#localidade").val() == '' || $("#localidade").val() == 'Localidade')
	    {
	        alert("Por favor introduza uma localidade.");
	        $("#localidade").focus();
	        return false;
	    }
	    
	    return true;
}

function validarRegistoCamposIndividual()
{
        if($("#nomeIndividual").val() == '' || $("#nomeIndividual").val() == 'Nome')
	    {
	        alert("Tem de introduzir o nome.");
	        $("#nomeIndividual").focus();
	        return false;
	    } 
	    
	    if($("#telemovelIndividual").val() == '' || !isNumber(document.getElementById("telemovelIndividual").value) || $("#telemovelIndividual").val() == 'Telemóvel')
	    {
	        alert("Tem de introduzir o numero de telemóvel.");
	        $("#telemovelIndividual").focus();
	        return false;
	    } 
	    
        if($("#EmailIndividual").val() == '' || !ValidateEmail(document.getElementById("EmailIndividual").value) || $("#EmailIndividual").val() == 'Email')
	    {
	        alert("Tem de introduzir um email válido.");
	        $("#EmailIndividual").focus();
	        return false;
	    } 
	    
	    if($("#nifIndividual").val() == '' || !isNumber(document.getElementById("nifIndividual").value) || $("#nifIndividual").val() == 'NIF')
	    {
	        alert("Tem de introduzir o NIF.");
	        $("#nifIndividual").focus();
	        return false;
	    } 
	    
	    
	    if($("#moradaIndividual").val() == '' || $("#moradaIndividual").val() == 'Morada')
	    {
	        alert("Tem de introduzir uma morada.");
	        $("#moradaIndividual").focus();
	        return false;
	    } 
	        
	    
	    if($("#codigoPostalIndividual").val() == '' || !isNumber(document.getElementById("codigoPostalIndividual").value) || $("#codigoPostalIndividual").val() == 'Código Postal')
	    {
	        alert("Tem de introduzir o código postal.");
	        $("#codigoPostalIndividual").focus();
	        return false;
	    }
	    
	    if($("#codigoPostal2Individual").val() == '' || !isNumber(document.getElementById("codigoPostal2Individual").value))
	    {
	        alert("Tem de introduzir o código postal.");
	        $("#codigoPostal2Individual").focus();
	        return false;
	    }
	    
	    if($("#codigoPostal3Individual").val() == '')
	    {
	        alert("Tem de introduzir o código postal.");
	        $("#codigoPostal3Individual").focus();
	        return false;
	    }
	    
	    
	    if($("#telefoneIndividual").val() == '' || !isNumber(document.getElementById("telefoneIndividual").value) || $("#telefoneIndividual").val() == 'Telefone')
	    {
	        alert("Tem de introduzir o numero de telefone.");
	        $("#telefoneIndividual").focus();
	        return false;
	    }
	    
	    
	    
	    if($("#localidadeIndividual").val() == '' || $("#localidadeIndividual").val() == 'Localidade')
	    {
	        alert("Tem de introduzir uma localidade.");
	        $("#localidadeIndividual").focus();
	        return false;
	    }
	    
	    return true;
}

function sendInformacaoEmpresarial()
{
    if(validarRegistoCamposEmpresa())
    {
        SendInformacaoEmpresarial();
    }
}

function sendInformacaoPessoal()
{
    if(validarRegistoCamposIndividual())
    {
        SendInformacaoIndividual();
    }
}

function SendInformacaoEmpresarial()
{
    $.ajax({url:"/AJAX/assinaturas.aspx", 
    type:"POST",
    dataType:"text",
    async: false,
    data:{request: "assinaturaEmpresarial",
            nomeEmpresa:$("#nomeEmpresa").val(),
            telemovel:$("#telemovel").val(),
            numeroColaboradores:$("#ncolaboradores").val(),
            email:$("#email").val(),
            nif:$("#nif").val(),
            morada:$("#morada").val(),
            pessoaContacto:$("#pessoaContacto").val(),
            codigoPostal1:$("#codigoPostal").val(),
            codigoPostal2:$("#codigoPostal2").val(),
            codigoPostal3:$("#codigoPostal3").val(),
            telefone:$("#telefone").val(),
            localidade:$("#localidade").val(),
            segurancaSim:$("input[@id='seguranca1']")[0].checked,
            segurancaNao:$("input[@id='seguranca2']")[0].checked,
            pagamentoTranferencia:document.getElementById("pagamento2").checked,
            pagamentoCheque:document.getElementById("pagamento1").checked,
            ajuda:$("#ajudaEntrega").val(),
            conhecimento:$("#conhecimentoOJE").val(),
            dadosMegafin:document.getElementById("confirmaDados").checked
            
    },
    success:function(result){
        if(result == "true")
        {
            document.getElementById("TabbedPanels6").style.display = "none";
            document.getElementById("divAssinaturasSucesso").style.display = "block";
        }
        else
        {
            document.getElementById("divAssinaturasErro").style.display = "block";
            document.getElementById("TabbedPanels6").style.display = "none";
        }
    },
    error:function(req,error,ex){
    }
  });
}

function SendInformacaoIndividual()
{
    $.ajax({url:"/AJAX/assinaturas.aspx", 
    type:"POST",
    dataType:"text",
    async: false,
    data:{request: "assinaturaIndividual",
            nomeIndividual:$("#nomeIndividual").val(),
            telemovel:$("#telemovelIndividual").val(),
            email:$("#EmailIndividual").val(),
            nif:$("#nifIndividual").val(),
            morada:$("#moradaIndividual").val(),
            codigoPostal1:$("#codigoPostalIndividual").val(),
            codigoPostal2:$("#codigoPostal2Individual").val(),
            codigoPostal3:$("#codigoPostal3Individual").val(),
            telefone:$("#telefoneIndividual").val(),
            localidade:$("#localidadeIndividual").val(),
            pagamentoIndividualTranferencia:document.getElementById("pagamentoIndividual2").checked,
            pagamentoIndividualCheque:document.getElementById("pagamentoIndividual1").checked,
            conhecimento:$("#conhecimentoOJEIndividual").val(),
            dadosMegafin:document.getElementById("confirmaDadosIndividual").checked
            
    },
    success:function(result){
        
        if(result == "true")
        {
            document.getElementById("TabbedPanels6").style.display = "none";
            document.getElementById("divAssinaturasSucesso").style.display = "block";
        }
        else
        {
            document.getElementById("divAssinaturasErro").style.display = "block";
            document.getElementById("TabbedPanels6").style.display = "none";
        }
    },
    error:function(req,error,ex){
    }
  });
}
