//Funções para a Tobias Ribeiro
//////////////////////////////////////////////


//valida formulário Teste
function validavulnerabilidade(teste_vulnerabilidade,evento)
{
	
	if(teste_vulnerabilidade.nome.value.length<=1)
  {
   alert("O campo Nome deve estar preenchido corretamente.");
   teste_vulnerabilidade.nome.focus();
   return false;
   }
   
   if(teste_vulnerabilidade.cargo.value.length<=1)
  {
   alert("O campo Cargo Atual deve estar preenchido corretamente.");
   teste_vulnerabilidade.cargo.focus();
   return false;
   }
   
   if(teste_vulnerabilidade.escola.value.length<=1)
  {
   alert("O campo Escola deve estar preenchido corretamente.");
   teste_vulnerabilidade.escola.focus();
   return false;
   }
   
    
   if(teste_vulnerabilidade.cidade.value.length<=1)
  {
   alert("O campo Cidade deve estar preenchido corretamente.");
   teste_vulnerabilidade.cidade.focus();
   return false;
   }


	var str_email = teste_vulnerabilidade.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	teste_vulnerabilidade.email.focus();
    	return false;
	}
	
	 if ( fnTestaCampo ( "Pergunta 1" , teste_vulnerabilidade.necessidade_satisfacao , 0 , 'R' ) == false ) return false ;

	 if ( fnTestaCampo ( "Pergunta 2" , teste_vulnerabilidade.necessidade , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 3" , teste_vulnerabilidade.posicao_a_abaixo , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 4" , teste_vulnerabilidade.vigilanciia_dos_concorrentes , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 5" , teste_vulnerabilidade.empresa , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 6" , teste_vulnerabilidade.forca , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 7" , teste_vulnerabilidade.marketing , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 8" , teste_vulnerabilidade.crescimento , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 9" , teste_vulnerabilidade.orcamento , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 10" , teste_vulnerabilidade.flutuacoes , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 11" , teste_vulnerabilidade.controle , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 12" , teste_vulnerabilidade.financeiramente , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 13" , teste_vulnerabilidade.analise , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 14" , teste_vulnerabilidade.grau , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 15" , teste_vulnerabilidade.bolsas , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 16" , teste_vulnerabilidade.produtividade , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 17" , teste_vulnerabilidade.conhecida , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 18" , teste_vulnerabilidade.necessidade_satisfacaoo , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 19" , teste_vulnerabilidade.cooperacao , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 20" , teste_vulnerabilidade.produtiva , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 21" , teste_vulnerabilidade.nota , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 22" , teste_vulnerabilidade.avaliacao , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 23" , teste_vulnerabilidade.eficazmente , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 24" , teste_vulnerabilidade.potencial , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 25" , teste_vulnerabilidade.remuneracao , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pergunta 26" , teste_vulnerabilidade.quadro , 0 , 'R' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos Fortes 1" , teste_vulnerabilidade.observacao_forte , 0 , 'T' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos fracos 1" , teste_vulnerabilidade.observacao_fraca , 0 , 'T' ) == false ) return false ;
	
	 if ( fnTestaCampo ( "Pontos Fortes 2" , teste_vulnerabilidade.observacao_forte2 , 0 , 'T' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos fracos 2" , teste_vulnerabilidade.observacao_fraca2 , 0 , 'T' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos Fortes 3" , teste_vulnerabilidade.observacao_forte3 , 0 , 'T' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos fracos 3" , teste_vulnerabilidade.observacao_fraca3 , 0 , 'T' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos Fortes 4" , teste_vulnerabilidade.observacao_forte4 , 0 , 'T' ) == false ) return false ;
	 
	 if ( fnTestaCampo ( "Pontos fracos 4" , teste_vulnerabilidade.observacao_fraca4 , 0 , 'T' ) == false ) return false ;
}

///////////////////////////////////////////////
//valida formulário Contato
function validaform_contato(contato){
	
	if(contato.nome.value.length<=1)
  {
   alert("O campo Nome deve estar preenchido corretamente.");
   contato.nome.focus();
   return false;
   }

	
	 var str_email = contato.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail deve ser preenchido corretamente");
    	contato.email.focus();
    	return false;
	}
	

	if(contato.telefone.value.length<=1)
  {
   alert("O campo Telefone deve estar preenchido corretamente.");
   contato.telefone.focus();
   return false;
   }
	
	
	if(contato.cidade.value.length<=1)
  {
   alert("O campo Cidade deve estar preenchido corretamente.");
   contato.cidade.focus();
   return false;
   }
   
   
   if(contato.estado.value.length<=1)
  {
   alert("O campo Estado deve estar preenchido corretamente.");
   contato.estado.focus();
   return false;
   }
	
	
	if(contato.mensagem.value.length<=1)
  {
   alert("O campo Mensagem deve estar preenchido corretamente.");
   contato.mensagem.focus();
   return false;
   }
	

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida Newsletter
  
function validaform_newsletter ()
{
    // recebe os valores dos objetos
    var str_nome  = newsletter.nome ;
    var str_email = newsletter.email ;
    
    // verifica se o nome esta correto
    if (( str_nome.value.length <= 1 ) || ( str_nome.value == "Nome:" ))
    {
        alert ( "O campo Nome deve estar preenchido corretamente." ) ;
        str_nome.focus () ;
        return false ;
    }
    
    // verifica se o email esta correto
    if (( str_email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email.value == 'E-mail:' ))
	{
    	alert ( "O campo E-mail deve ser preenchido corretamente" ) ;
    	str_email.focus () ;
    	return false ;
	}
    
    // nenhum erro, envia
	return true;
}


////////////////////////////////////////////////////////////////////////////////////////////////

//Função Adiciona a Favoritos
function fnAdicionaFavoritos()
{
	str_titulo = "Tobias Ribeiro - Assessoria em Gestão Estratégica";
	str_url = "http://www.tobiasribeiro.com.br";
	//FireFox
	if (window.sidebar)
	{
   		window.sidebar.addPanel(str_titulo, str_url,"");
	}
	//IE
	else if( window.external )
	{
  		window.external.AddFavorite( str_url, str_titulo);
	}
	//Opera
	else if(window.opera && window.print)
	{
   		return true;
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////

//Função de popup

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

////////////////////////////////////////////////////////////////////////////////////////////////

// Função de Máscara de Campos
function FormatMask(objForm, strField, sMask, evtKeyPress) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

  if(window.event) { // Internet Explorer
    nTecla = evtKeyPress.keyCode; }
  else if(evtKeyPress.which) { // Nestcape
    nTecla = evtKeyPress.which;
  }

  sValue = objForm[strField].value;

  // Limpa todos os caracteres de formatação que
  // já estiverem no campo.
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( "-", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( ".", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "/", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( "(", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( ")", "" );
  sValue = sValue.toString().replace( " ", "" );
  sValue = sValue.toString().replace( " ", "" );
  fldLen = sValue.length;
  mskLen = sMask.length;

  i = 0;
  nCount = 0;
  sCod = "";
  mskLen = fldLen;

  if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
      return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
    else { // qualquer caracter...


  while (i <= mskLen) {
     bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
     bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

     if (bolMask) {
       sCod += sMask.charAt(i);
       mskLen++; }
     else {
       sCod += sValue.charAt(nCount);
       nCount++;
     }

     i++;
   }

   objForm[strField].value = sCod;

      return true;
    } }
  else {
    return true;
  }
}

 var win=null;
function newWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
	win.focus();
}

/////////////////////////////////////////////////////////////////////////////////////////////////

function fnFlash(str_url, int_largura, int_altura)
{
	document.writeln('<object type="application/x-shockwave-flash" data="' + str_url + '" width="' + int_largura + '" height="' + int_altura + '">');
	document.writeln('<param name="movie" value="' + str_url + '">');
	document.writeln('<param name="quality" value="high">');
	document.writeln('<param name="wmode" value="transparent">');
	document.writeln('</object>');
}

/***********************************************************************
FUNÇÃO PRINCIPAL DA MASCARA
-------------------------------------------------------------------
Função: fnTestaCampo
Dados de Entrada: strLblCampo(Texto que deve ir no alert),strCampo(Nome do campo no formulario),intTamanho(Tamanho que a funcao tem que validar),strTipo(o tipo que deseja testar)
Dados de Saída:
Processamento: Quando o usuario der o enviar chama a funcao para validar campo a campo

Uso no formulário: 

Responsavél: Marcelo Abib Cardoso
Data: 17/08/2006
************************************************************************/
	function fnTestaCampo(strLblCampo,strCampo,intTamanho,strTipo)
	{
		//T - Input Text Caracter
		//N - Input Text Inteiro
		//R - Radio Button
		//C - Checkbox
		//S-Select
        //E - Input Text Caracter E-Mail
		
		if ((strTipo == "T") || (strTipo == "E"))
		{
			if (strCampo.value.length == 0 || strCampo.value.length < intTamanho)
			{
				alert("Por favor, preencha o campo " + strLblCampo + " corretamente.");
				strCampo.focus();
				return false;
			}
            else if (strTipo == "E")
            {
                //	
                if ((strCampo.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) || (strCampo.value == "Email:") || (strCampo.value == "E-mail:")) 
            	{
            		alert("Por favor, preencha o campo " + strLblCampo + " corretamente.");
                    strCampo.focus();
            		return false;
            	}
            }
		}
        else if ( strTipo == "R" )
		{
            var contador ;
            var flag ;
            
            flag = false ;
            
            for ( contador = 0 ; contador < strCampo.length ; contador ++ )
            {
                if ( strCampo[contador].checked )
                {
                    flag = true ;
                }
            }
            
            if ( flag == false )
            {
                alert("Por favor, preencha o campo " + strLblCampo + ".");
                return false ;
            }
		}
		else if ( strTipo == "C" )
		{
			if ( strCampo.checked  == false )
			{
				alert("Por favor, preencha o campo " + strLblCampo + " corretamente.");
				return false ;
			}
		}
		else if ( strTipo == "S" )
		{
			if ( strCampo.selectedIndex == -1 || strCampo.value == "" || strCampo.options[strCampo.selectedIndex].text == "")
			{
				alert("Por favor, preencha o campo " + strLblCampo + " corretamente.");
				return false;
			}
		}
	}
