// JavaScript Document

function lnk(url)
{
	document.location.href=url;
}

function trocaLingua(lingua)
{
	document.location.href='../'+lingua+'/';
}

function envia_contato()
{
    if(!valida_contato())
	{	return false;	}

    $('img_carrega').style.visibility = "visible";
    
	new Ajax.Request('../../admin/envia_dados.php', {
	parameters: $('form_contato').serialize(true),
	onSuccess: function(transport){
		alert(transport.responseText);
		$('nome').value = "";
		$('email').value = "";
		$('assunto').value = "";		
		$('mensagem').value = "";
		$('img_carrega').style.visibility = "hidden";
		$('caracteres_restantes').innerHTML = "300";
	} });
}

function envia_trabalhe()
{
    if(!valida_trabalhe())
	{	return false;	}
	
	$('img_carrega').style.visibility = "visible";

	if($('curriculo').value != "")
		{	ajax_upload('form_trabalhe','../../admin/upload_curriculo.php','status_upload',"Fazendo Upload do Arquivo...","Erro ao Enviar o arquivo !");	}

	new Ajax.Request('../../admin/envia_dados.php', {
	parameters: $('form_trabalhe').serialize(true),
	onSuccess: function(transport){
		alert(transport.responseText);
        $('motivo').value = "";
		$('qualidades').value = "";
		$('curriculo').value = "";	
		$('img_carrega').style.visibility = "hidden";
	} });
}

function envia_projeto()
{
	if(!valida_projeto())
	{	return false;	}
	
	$('img_carrega').style.visibility = "visible";

    if($('plano').value != "")
		{	ajax_upload('form_projeto','../../admin/upload_plano.php','status_upload',"Fazendo Upload do Arquivo...","Erro ao Enviar o arquivo !");	}

	if($('projeto').value != "")
		{	ajax_upload2('form_projeto','../../admin/upload_projeto.php','status_upload',"Fazendo Upload do Arquivo...","Erro ao Enviar o arquivo !");	}
			
	new Ajax.Request('../../admin/envia_dados.php', {
	parameters: $('form_projeto').serialize(true),
	onSuccess: function(transport){
		alert(transport.responseText);
		$('nome').value = "";
		$('email').value = "";
		$('ddd1').value = "";
		$('ddd2').value = "";
		$('telefone').value = "";
		$('celular').value = "";
		$('projeto').value = "";
		$('plano').value = "";
		$('nome_projeto').value = "";
		$('descricao').value = "";
		$('segmento').value = "";
		$('pessoa_contato').value = "";
		$('como_conheceu').value = "";		
		$('arq_plano').value = "";
		$('arq_projeto').value = "";
		$('img_carrega').style.visibility = "hidden";
	} });
}

function altera_aba(secao)
{
	var img1 = $('aba_foco_inter');
	var img2 = $('aba_foco_local');
	var div1 = $('foco_inter');
	var div2 = $('foco_local');
	
	switch(secao)
	{
		case "foco_inter":
		img1.src = "img/aba_foco11.gif";
		img2.src = "img/aba_foco2.gif";
		div1.style.display = "block";
		div2.style.display = "none";
		break;
		
		case "foco_local":
		img1.src = "img/aba_foco1.gif";
		img2.src = "img/aba_foco21.gif";
		div1.style.display = "none";
		div2.style.display = "block";
		break;
		
		case "caracteristicas":
		img1.src = "img/aba_foco1.gif";
		img2.src = "img/aba_foco2.gif";
		div1.style.display = "none";
		div2.style.display = "none";
		break;
	}
}



// VALIDAÇÕES DOS FORMULÁRIOS

function pega_nome(origem,destino)
{
	var data = new Date();
	var valor_org = $(origem).value;
	var tipo = valor_org.substring(valor_org.length-4,valor_org.length);
	if(tipo.substring(0,1) != ".")
	{	var tipo = valor_org.substring(valor_org.length-5,valor_org.length);	}
	var nome_final = data.getTime() + tipo;
	$(destino).value = nome_final;
}

function testar_tamanho()
{
	var quantidade = $('descricao').value.length;
	var restante = 250 - quantidade;
	if(restante < 0)
	{	$('descricao').value = $('descricao').value.substring(0,250);  }
	else
	{	$('caracteres_restantes').innerHTML = restante;	}
}

function testar_tamanho_contato()
{
	var quantidade = $('mensagem').value.length;
	var restante = 300 - quantidade;
	if(restante < 0)
	{	$('mensagem').value = $('mensagem').value.substring(0,300);  }
	else
	{	$('caracteres_restantes').innerHTML = restante;	}
}

function valida_projeto() 
{
	if(critica_nome() && critica_email() && critica_telefone() && critica_celular() && critica_projeto() && critica_nome_projeto() && critica_descricao() && critica_segmento() && critica_como_conheceu() && critica_pessoa_harpia() && critica_plano())
	{	return true;	}
	else
	{	return false;	}
}

function valida_contato()
{
	if(critica_nome() && critica_email() && critica_assunto() && critica_mensagem())
	{	return true;	}
	else
	{	return false;	}
}

function valida_trabalhe()
{
	if(critica_motivo() && critica_qualidade() && critica_curriculo())
	{	return true;	}
	else
	{	return false;	}
}


// CRÍTICAS DE DADOS

function critica_nome()
{
	var nome = $('nome').value;
    var lng = $('lingua').value;
	if(nome.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar seu nome ! ");
        }
        else
        {
            alert("Please let us know your name!");
        }

		$('nome').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_projeto()
{
	var projeto = $('projeto').value;
    var lng = $('lingua').value;
	if(projeto.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o arquivo do projeto ! ");
        }
        else
        {
            alert("Please attach your project's file!");
        }

		$('projeto').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_plano()
{
	var plano = $('plano').value;
    var lng = $('lingua').value;
	if(plano.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o arquivo do Plano ! ");
        }
        else
        {
            alert("Please attach bussiness plan's file!");
        }

		$('plano').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_nome_projeto()
{
	var nome_projeto = $('nome_projeto').value;
    var lng = $('lingua').value;
	if(nome_projeto.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o nome do projeto ! ");
        }
        else
        {
            alert("Please let us know your project's name!");
        }

		$('nome_projeto').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_pessoa_harpia()
{
	var pessoa_harpia = $('pessoa_contato').value;
    var lng = $('lingua').value;
	if(pessoa_harpia.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar se tem uma pessoa conhecida na Harpia Ventures ! ");
        }
        else
        {
            alert("Please inform if you know any one at Harpia Ventures!");
        }

		$('pessoa_contato').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_telefone()
{
	var ddd = $('ddd1').value;
	var telefone = $('telefone').value;
    var lng = $('lingua').value;
	if(ddd.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o ddd de seu telefone ! ");
        }
        else
        {
            alert("Please inform your phone area code!");
        }

		$('ddd1').focus();
		return false;
	}
	else
	{	
		if(isNaN(ddd))
		{
            if (lng == "pt")
            {
                alert('O ddd do telefone deve ser um número !');
            }
            else
            {
                alert("Phone area code must be a number!");
            }

            $('ddd1').focus();
			return false;
		}
		else
		{
			if(telefone.length == 0)
			{
                if (lng == "pt")
                {
                    alert("Você precisa informar o seu telefone ! ");
                }
                else
                {
                    alert("Please inform your phone!");
                }

                $('telefone').focus();
				return false;
			}
			else
			{		
				if(isNaN(telefone))
				{
                    if (lng == "pt")
                    {
                        alert('O telefone deve ser um número !');
                    }
                    else
                    {
                        alert("Phone must be a number!");
                    }

                    $('telefone').focus();
					return false;
				}
				else
				{
					return true;	
				}
			}
		}
	}
}

function critica_celular()
{
	var ddd = $('ddd2').value;
	var celular = $('celular').value;
    var lng = $('lingua').value;
	if(ddd.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o ddd de seu celular ! ");
        }
        else
        {
            alert("Please inform your cellular area code!");
        }

        $('ddd2').focus();
		return false;
	}
	else
	{	
		if(isNaN(ddd))
		{
            if (lng == "pt")
            {
                alert('O ddd do celular deve ser um número !');
            }
            else
            {
                alert("Cellular area code must be a number!");
            }

			$('ddd2').focus();
			return false;
		}
		else
		{
			if(celular.length == 0)
			{
                if (lng == "pt")
                {
                    alert("Você precisa informar o seu celular ! ");
                }
                else
                {
                    alert("Please inform your cellular!");
                }

                $('celular').focus();
				return false;
			}
			else
			{		
				if(isNaN(celular))
				{
                    if (lng == "pt")
                    {
                        alert('O celular deve ser um número !');
                    }
                    else
                    {
                        alert("Cellular must be a number!");
                    }

					$('celular').focus();
					return false;
				}
				else
				{
					return true;	
				}
			}
		}
	}
}

function critica_motivo()
{
	var motivo = $('motivo').value;
    var lng = $('lingua').value;
	if(motivo.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o porquê quer trabalhar na Harpia ! ");
        }
        else
        {
            alert("Please let us know how you heard about us!");
        }

		$('motivo').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_qualidade()
{
	var qualidades = $('qualidades').value;
    var lng = $('lingua').value;
	if(qualidades.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o porquê você acha que agregaria valor ! ");
        }
        else
        {
            alert("Please let us know why you think you belong to our team!");
        }

		$('qualidades').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_curriculo()
{
	var curriculo = $('curriculo').value;
    var lng = $('lingua').value;
	if(curriculo.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa acrescentar um currículo ! ");
        }
        else
        {
            alert("Please attach your résumé!");
        }

		$('curriculo').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_assunto()
{
	var assunto = $('assunto').value;
    var lng = $('lingua').value;
	if(assunto.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar seu assunto ! ");
        }
        else
        {
            alert("Please enter a subject to your message!");
        }

		$('assunto').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_descricao()
{
	var descricao = $('descricao').value;
    var lng = $('lingua').value;
	if(descricao.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa descrever o projeto !");
        }
        else
        {
            alert("Please let us know your project's business summary!");
        }

		$('descricao').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_segmento()
{
	var segmento = $('segmento').value;
    var lng = $('lingua').value;
	if(segmento.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o segmento do projeto ! ");
        }
        else
        {
            alert("Please let us know your project's industry!");
        }

		$('segmento').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_como_conheceu()
{
	var como_conheceu = $('como_conheceu').value;
    var lng = $('lingua').value;
	if(como_conheceu.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar como conheceu a Harpia Ventures ! ");
        }
        else
        {
            alert("Please let us know how you got to know about us!");
        }

		$('como_conheceu').focus();
		return false;
	}
	else
	{	return true;	}
}

function critica_email()
{
	var email = $('email').value;
    var lng = $('lingua').value;
	if(email.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa informar o seu Email ! ");
        }
        else
        {
            alert("Please let us know your e-mail!");
        }

		$('email').focus();
		return false;
	}
	
	var exp_reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,3})+$/;
	
	if(!exp_reg.test(email))
	{
        if (lng == "pt")
        {
            alert("O email informado é inválido! ");
        }
        else
        {
            alert("Invalid e-mail!");
        }

		$('email').focus();
		return false;	
	}
	else
	{	return true;	}
}

function critica_mensagem()
{
	var mensagem = $('mensagem').value;
    var lng = $('lingua').value;
	if(mensagem.length == 0)
	{
        if (lng == "pt")
        {
            alert("Você precisa escrever alguma mensagem ! ");
        }
        else
        {
            alert("Please type a message!");
        }

		$('mensagem').focus();
		return false;
	}
	else
	{	return true;	}
}