/**
 * @author Josemar Davi Luedke
 */
function noNumbers(e, bloq) {
	var tecla=new Number();
	var e = e || event;
	var k = e.keyCode || e.which;
	if (!k > 47 && k < 58) {
		window.event.keyCode = 0;
	}
	
	if (k == 13) {	}
	else {
		if (window.event) {
			tecla = e.keyCode;
		}
		else 
			if (e.which) {
				tecla = e.which;
			}
			else {
				return true;
			}
		if (((tecla < 48) || (tecla > 57)) && (tecla != 8)) {
			return false;
		}
	}

}
function ValUser(){
		if (document.getElementById('login').value.length <  3){
			$('#loading-area').css("width","280px");
			$('#loading-area').css("margin-left","-130px");
			$('#message-area-inner').html('Digite um usu&aacute;rio valido, m&iacute;nimo 3 caracteres.');
	        $('#loading-area').show();
			document.getElementById('msgLogin').className = 'msgError';
			document.getElementById('login').focus();
			setTimeout(hideError, 4000);
			return false;
		}
		else {
			$('#loading-area').hide();
			document.getElementById('msgLogin').className = 'msgYes';
			return true;
		}
}
function ValPass(){
		if (document.getElementById('senha').value.length < 2){
			$('#loading-area').css("width","280px");
			$('#loading-area').css("margin-left","-130px");
			$('#message-area-inner').html('Digite uma senha valida, m&iacute;nimo 2 caracteres.');
	        $('#loading-area').show();
			document.getElementById('msgSenha').className = 'msgError';
			document.getElementById('senha').focus();
			setTimeout(hideError, 4000);
			return false;
		}
		else {
			$('#loading-area').hide();
			document.getElementById('msgSenha').className = 'msgYes';
			return true;
		}
}
function ValInst() {
		if (document.getElementById('inst').value.length < 4){
			$('#loading-area').css("width","300px");
			$('#loading-area').css("margin-left","-150px");
			$('#message-area-inner').html('Digite uma institui&ccedil;&atilde;o valida, m&iacute;nimo 4 caracteres.');
	        $('#loading-area').show();
			document.getElementById('msgInst').className = 'msgError';			
			document.getElementById('inst').focus();
			setTimeout(hideError, 4000);
			return false;
		}
		else {
			$('#loading-area').hide();
			document.getElementById('msgInst').className = 'msgYes';
			return true;
		}
}

function ValFormLogin() {
		if (ValUser() == false) {
			$('#loading-area').css("width","280px");
			$('#loading-area').css("margin-left","-130px");
			$('#message-area-inner').html('Digite um usu&aacute;rio valido, m&iacute;nimo 3 caracteres.');
	        $('#loading-area').show();
			document.getElementById('msgLogin').className = 'msgError';
			document.getElementById('login').focus();
			setTimeout(hideError, 4000);
			return false;
		}	
		else if(ValPass() == false) {
			$('#loading-area').css("width","280px");
			$('#loading-area').css("margin-left","-130px");
			$('#message-area-inner').html('Digite uma senha valida, m&iacute;nimo 2 caracteres.');
	        $('#loading-area').show();
			document.getElementById('msgSenha').className = 'msgError';
			document.getElementById('senha').focus();
			setTimeout(hideError, 4000);
			return false;
		} else if (document.getElementById('inst').value.length < 4){
			$('#loading-area').css("width","300px");
			$('#loading-area').css("margin-left","-150px");
			$('#message-area-inner').html('Digite uma institui&ccedil;&atilde;o valida, m&iacute;nimo 4 caracteres.');
	        $('#loading-area').show();
			document.getElementById('msgInst').className = 'msgError';			
			document.getElementById('inst').focus();
			setTimeout(hideError, 4000);
			return false;
		} else {
			return 'OK';
		}	
}
function loading(){
	$('#loading-area').css("width","100px");
	$('#loading-area').css("margin-left","-40px");
	$('#message-area-inner').html('<img src="imagens/bg/load.gif" width="15" align="texttop" /> Carregando...');
    $('#loading-area').show();
}
function errorPagNotfound(){
	$('#loading-area').css("width","230px");
	$('#loading-area').css("margin-left","-100px");
    $('#message-area-inner').html('A p&aacute;gina solicitada n&atilde;o foi encontrada!');
	$('#loading-area').show();
}
function error(){
	$('#loading-area').css("width","230px");
	$('#loading-area').css("margin-left","-100px");
    $('#message-area-inner').html('N&atilde;o foi possivel efetuar sua a&ccedil;&atilde;o!');
	$('#loading-area').show();	
}

function hideError(){
	$('#loading-area').hide();
}

function FlashBanner(swf, width, height)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{
		document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+swf+'"/><param name="quality" value="best"/><param name="bgcolor" value="#FFFFFF"/><param name="menu" value="false"/><param name="salign" value="LT"/><param name="wmode" value="opaque"/><param name="allowScriptAccess" value="sameDomain"/></object>');
	}
	else
	{
		document.write('<embed src="'+swf+'" quality="best" bgcolor="#FFFFFF" width="'+width+'" height="'+height+'" menu="false" salign="LT" wmode="opaque" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>');
	}
}

function openWindow(largura, altura, link) {
	janela_largura_x = largura ;
	janela_altura_y = altura;
	posx = (window.screen.width/2)-(janela_largura_x/2);
	posy = (window.screen.height/2)-(janela_altura_y/2);	
	window.open(link,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left='+posx+',top='+posy+',width='+janela_largura_x+',height='+janela_altura_y);
}

function mouseOver(id, bg, colorBg, bd, colorBd){
	if (bg){
		id.style.backgroundColor=colorBg;	
	}
	if (bd){
		id.style.borderColor=colorBd;	
	}
}
function mouseOut(id, bg, colorBg, bd, colorBd){
		id.style.backgroundColor=colorBg;
}

function validateName(name){
    var er = new RegExp(/^[a-zA-Z]+[' '][a-zA-Z]+?/);

    if(er.test(name.value)){
	        return true; 
	}else{
	    return false;
	}
}

function replaceToken(str, token, newtoken){
	//token 	= [".", "/", "-"];
	//newtoken 	= ["", "", ""];

	for(i=0;i<newtoken.length;i++){
		while (str.indexOf(token[i]) != -1) {
			str = str.replace(token[i], newtoken[i]);
		}
	}

	return str;
}

function validateMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

    if(er.test(mail.value)){
	        return true; 
	}else{
	    return false;
	}
}





function ValidateCPF(CPF){

	//Set values to replace
	token 		= [".", "/", "-", "_"];
	newtoken 	= ["", "", "", ""];
	str 		= CPF.value;

	//Replace
	var CPF = replaceToken(str, token, newtoken);

	if(CPF.length >= 11){
	
		//Vars to multiply
		var comparateNumbers = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2];

		//Pass CPF to a new array
		var newCPF = new Array();
		for(i=0;i<11;i++){
			 newCPF[i] = CPF.charAt(i);	
		}

		//Multiply CPF with comparate numbers -> FIRST verificator digit
		var result = new Number;
		for(i=0;i<9;i++){
			result += newCPF[i] * comparateNumbers[i+1];
		}

		//Figure out the 1º digit verificator
		var rest;
		var checkDigit = new Array();
		
		if((rest = result % 11) < 2){
			checkDigit[0] = 0;
		}else{
			checkDigit[0] = [11 - rest];
		}

		//Set value of the first digit verificator
		newCPF[9] = checkDigit[0];

		//Multiply CPF w/ comparate numbers -> SECOND verificator digit
		result = 0;
		for(i=0;i<10;i++){
			result += newCPF[i] * comparateNumbers[i];
		}

		//Figure out the 2º digit verificator
		var rest = 0;

		if((rest = result % 11) < 2){
			checkDigit[1] = 0;
		}else{
			checkDigit[1] = [11 - rest];
		}

		//Set value of the first digit verificator
		newCPF[10] = checkDigit[1];

		if((CPF.charAt(9) != newCPF[9]) || (CPF.charAt(10) != newCPF[10])){
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
}

function ValidateCNPJ(CNPJ){

	//Set values to replace
	token 		= [".", "/", "-", "_"];
	newtoken 	= ["", "", "", ""];
	str 		= CNPJ.value;

	//Replace
	var CNPJ = replaceToken(str, token, newtoken);

	if(CNPJ.length >= 14){
	
		//Vars to multiply
		var comparateNumbers = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];

		//Pass CNPJ to a new array
		var newCNPJ = new Array();
		for(i=0;i<14;i++){
			 newCNPJ[i] = CNPJ.charAt(i);	
		}

		//Multiply CNPJ with comparate numbers -> FIRST verificator digit
		var result = new Number;
		for(i=0;i<12;i++){
			result += newCNPJ[i] * comparateNumbers[i+1];
		}

		//Figure out the 1º digit verificator
		var rest;
		var checkDigit = new Array();
		
		if((rest = result % 11) < 2){
			checkDigit[0] = 0;
		}else{
			checkDigit[0] = [11 - rest];
		}

		//Set value of the first digit verificator
		newCNPJ[12] = checkDigit[0];

		//Multiply CNPJ w/ comparate numbers -> SECOND verificator digit
		result = 0;
		for(i=0;i<13;i++){
			result += newCNPJ[i] * comparateNumbers[i];
		}

		//Figure out the 2º digit verificator
		var rest = 0;

		if((rest = result % 11) < 2){
			checkDigit[1] = 0;
		}else{
			checkDigit[1] = [11 - rest];
		}
		
		//Set value of the first digit verificator
		newCNPJ[13] = checkDigit[1];

		if((CNPJ.charAt(13) != newCNPJ[13]) || (CNPJ.charAt(12) != newCNPJ[12])){
			return false;
		}else{
			return true;
		}
	}else{
		return false;
	}
}

function validaFormPadrao(form){

	//var checkedInteresse = false;
	var checkedInteresse = true;
	$('.interesse').each(function(){
		if(this.checked == true)
			checkedInteresse = true;
	});

	if ($('#nome').val() == ''){		
	    $('#nome').focus();
	    alert("Você deve preencher seu nome!");
	    return false;
	}if ($('#NameHidden').val() == 'incorreto'){
	    $('#nome').focus();
	    alert("Você deve preencher seu nome completo!");
	    return false;
	}if ($('#email').val() == ''){
	    $('#email').focus();
	    alert("Você deve preencher seu email!");
	    return false;
	}if ($('#EmailHidden').val() == 'incorreto'){
	    $('#email').focus();
	    alert("Você deve preencher um email correto!");
	    return false;
	}if ($('#fixo').val() == ''){
	    $('#fixo').focus();
	    alert("Você deve preencher um telefone fixo!");
	    return false;
	}if ($('#estado').val() == 'Selecione'){		
	    $('#estado').focus();
	    alert("Você deve preencher seu estado!");
	    return false;
	}if ($('#instituicao').val() == ''){
	    $('#instituicao').focus();
	    alert("Você deve preencher o nome da instituição!");
	    return false;
	}/*if ($('#CNPJHidden').val() == 'incorreto'){
	    $('#cnpj').focus();
	    alert("Você deve preencher um CNPJ!");
	    return false;
	}if ($('#cnpj').val() == ''){
	    $('#cnpj').focus();
	    alert("Você deve preencher o CNPJ!");
	    return false;
	}if ($('#nfuncionarios').val() == ''){
	    $('#nfuncionarios').focus();
	    alert("Você deve preencher o nº de funcionários!");
	    return false;
	}if ($('#nusuarios').val() == ''){
	    $('#nusuarios').focus();
	    alert("Você deve preencher o nº de usuários!");
	    return false;
	}if ($('#cargo').val() == ''){
	    $('#cargo').focus();
	    alert("Você deve preencher o cargo!");
	    return false;
	}if (checkedInteresse == false) {
		alert('Você deve preencher seu interesse');
		return false;
	}if ($('#conheceScopi').val() == ''){
	    $('#conheceScopi').focus();
	    alert("Você deve preencher como conheceu o Scopi!");
	    return false;
	}if ($('#suasNecessidades').val() == ''){
	    $('#suasNecessidades').focus();
	    alert("Você deve preencher sobre suas necessidades!");
	    return false;
	}*/

}

function validaFormRepresentar(){
    //dados da pessoais
	if ($('#nome').val() == ''){
        $('#nome').focus();
        alert("Você deve preencher seu nome!");
        return false;
    }if ($('#NameHidden').val() == 'incorreto'){
	    $('#nome').focus();
	    alert("Você deve preencher seu nome completo!");
	    return false;
	}if ($('#email').val() == ''){
        $('#email').focus();
        alert("Você deve preencher seu email!");
        return false;
    }if ($('#EmailHidden').val() == 'incorreto'){
	    $('#email').focus();
	    alert("Você deve preencher um email correto!");
	    return false;
	}if ($('#telefone').val() == ''){
        $('#telefone').focus();
        alert("Você deve preencher o telefone!");
        return false;
    }if ($('#cpf').val() == ''){
        $('#cpf').focus();
        alert("Você deve preencher o cpf!");
        return false;
    }if ($('#CPFHidden').val() == 'incorreto'){
        $('#cpf').focus();
        alert("Você deve preencher o cpf correto!");
        return false;
    }if ($('#pais').val() == ''){
        $('#pais').focus();
        alert("Você deve preencher um País!");
        return false;
    }if ($('#estado').val() == ''||$('#estado').val() == 'Selecione'){
        $('#estado').focus();
        alert("Você deve preencher o estado!");
        return false;
    }if ($('#cidade').val() == ''||$('#cidade').val() == 'Selecione'){
        $('#cidade').focus();
        alert("Você deve preencher uma cidade!");
        return false;
    }if ($('#endereco').val() == ''){
        $('#endereco').focus();
        alert("Você deve preencher um endereço!");
        return false;
    }

    //dados da empresa
    if ($('#razaoSocial').val() == ''){
        $('#razaoSocial').focus();
        alert("Você deve preencher Razão Social!");
        return false;
    }if ($('#cnpj').val() == ''){
        $('#cnpj').focus();
        alert("Você deve preencher o cnpj!");
        return false;
    }if ($('#CNPJHidden').val() == 'incorreto'){
	    $('#cnpj').focus();
	    alert("Você deve preencher um CNPJ correto!");
	    return false;
	}if ($('#dataFundacao').val() == ''){
        $('#dataFundacao').focus();
        alert("Você deve preencher a Data de Fundação!");
        return false;
    }if ($('#emailEmpresa').val() == ''){
        $('#emailEmpresa').focus();
        alert("Você deve preencher o email da empresa!");
        return false;
    }if ($('#EmailEmpresaHidden').val() == 'incorreto'){
	    $('#emailEmpresa').focus();
	    alert("Você deve preencher um email correto!");
	    return false;
	}if ($('#telefoneEmpresa').val() == ''){
        $('#telefoneEmpresa').focus();
        alert("Você deve preencher o telefone da empresa!");
        return false;
    }if ($('#paisEmpresa').val() == ''){
        $('#paisEmpresa').focus();
        alert("Você deve preencher o País da empresa!");
        return false;
    }if ($('#estadoEmpresa').val() == '' || $('#estadoEmpresa').val() == 'Selecione'){
        $('#estadoEmpresa').focus();
        alert("Você deve preencher o Estado da empresa!");
        return false;
    }if ($('#cidadeEmpresa').val() == '' || $('#cidadeEmpresa').val() == 'Selecione'){
        $('#cidadeEmpresa').focus();
        alert("Você deve preencher a cidade da empresa!");
        return false;
    }if ($('#enderecoEmpresa').val() == ''){
        $('#enderecoEmpresa').focus();
        alert("Você deve preencher o endereco da empresa!");
        return false;
    }
    
    //Questionário
    if ($('#regioesInteresse').val() == ''){
        $('#regioesInteresse').focus();
        alert("Você deve preencher as regiões de interesse!");
        return false;
    }if ($('#formacaoArea').val() == ''){
        $('#formacaoArea').focus();
        alert("Você deve preencher a formação!");
        return false;
    }if ($('#segmentoAtua').val() == ''){
        $('#segmentoAtua').focus();
        alert("Você deve preencher o segmento em que atua!");
        return false;
    }if ($('#representanteOutroProduto').val() == ''){
        $('#representanteOutroProduto').focus();
        alert("Você deve preencher se ja é representante!");
        return false;
    }if ($('#associadoInstituicao').val() == ''){
        $('#associadoInstituicao').focus();
        alert("Você deve preencher se ja é associado a alguma Instituição!");
        return false;
    }if ($('#motivos').val() == ''){
        $('#motivos').focus();
        alert("Você deve preencher os motivos!");
        return false;
    }if ($('#volumeClientes').val() == ''){
        $('#volumeClientes').focus();
        alert("Você deve preencher o volume de clientes!");
        return false;
    }if ($('#clientesReferenciais').val() == ''){
        $('#clientesReferenciais').focus();
        alert("Você deve preencher os clientes referenciais!");
        return false;
    }
}

function validaSugestao(){;
	if ($('#nome').val() == ''){		
	    $('#nome').focus();
	    alert("Você deve preencher seu nome!");
	    return false;
	}if ($('#NameHidden').val() == 'incorreto'){		
	    $('#nome').focus();
	    alert("Você deve preencher seu nome completo!");
	    return false;
	}if ($('#email').val() == ''){
	    $('#email').focus();
	    alert("Você deve preencher seu email!");
	    return false;
	}if ($('#EmailHidden').val() == 'incorreto'){		
	    $('#email').focus();
	    alert("Você deve preencher seu email correto!");
	    return false;
	}if ($('#fone').val() == ''){
	    $('#fone').focus();
	    alert("Você deve preencher seu telefone!");
	    return false;
	}if ($('#institute').val() == ''){
	    $('#institute').focus();
	    alert("Você deve preencher a razão social!");
	    return false;
	}if ($('#sugestao').val() == ''){
	    $('#sugestao').focus();
	    alert("Você deve preencher uma mensagem!");
	    return false;
	}
}
