/***********************************************
* Switch Menu script- by Martial B of http://getElementById.com/
* Modified by Dynamic Drive for format & NS4/IE4 compatibility
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("navegacao").getElementsByTagName("ul"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate

/***********************TERMINA CÓDIGO DO MENU***********************/


function changeHeadline(text){
        $('headline').innerHTML = text;
}
	  
function changeHeadline(){
        parent.changeHeadline(document.getElementById('headline_text').value);

        //GreyBox hide function
        //parent.GB_hide();
        return false;
}



/*********************Para Envio do email*************************/
 var testresults;
   function check_filter(name){	  
     // var str=document.mensagem.item(name).value;	  only for IE
	  var str=document.getElementById(name).value;
	  
      var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
      if (filter.test(str))
         testresults=true;
      else{
         alert("Endereço de email inválido!")		 		
         testresults=false;
      }
      return (testresults);
   }

   function check_mail(name){
      if (document.layers||document.getElementById||document.all)	  	 
         return check_filter(name);
      else
         return true;
   }
 
/***********Validação do associe*********************/ 

function valida_campos(){ 
    var x;		
	var vetor= new Array("nome","rg","cpf_responsavel","estado_civil","endereco","cidade","email_from","profissao","atividade_atual","arquivo","arquivo2");
	var msg= new Array("digitar seu nome","digitar seu RG","digitar seu CPF","digitar seu estado civil", "digitar seu endereço", "digitar sua cidade","digitar o seu e-mail","digitar sua profissão","digirar sua atividade atual","inserir a sua foto", "inserir o seu currículo" );		
	
	 	
	for (x=0;x<vetor.length;x++)
	  {	  					
	   	if(document.getElementById(vetor[x]).value == "")
	  		{				
			alert("Faltou "+msg[x] +"!");
			document.getElementById(vetor[x]).focus();	
			return(0);
			}
		
       }	
	   
	   if (check_mail(vetor[6])) {
		   
		   if (validacpf(document.getElementById("cpf_responsavel").value)){
	 		 // document.mensagem.submit();  
	  		document.getElementById("form_associe").submit();  
		   }else{
			   alert("faltou digitar o CPF");
			   document.getElementById("cpf_responsavel").focus();	
		   }
	   }
	
 } 

 
/**************Validação do contato******************/
/**************Validação do contato******************/

function valida_contato(){ 
    var x;		
	var vetor= new Array("nome","email","mensagem");
	var msg= new Array("digitar seu nome","digitar seu email","digitar sua mensagem");		
	
	for (x=0;x<vetor.length;x++)
	  {	  					
	   	if(document.getElementById(vetor[x]).value == "")
	  		{				
			alert("Faltou "+msg[x] +"!");
			document.getElementById(vetor[x]).focus();	
			return(0);
			}
		
       }	
	   
	   if (check_mail(vetor[1])) {
		    // document.mensagem.submit();  
	  		document.getElementById("form_contato").submit();  
	   }else{
			
	   }
	
 } 
//-------------------------------------------------------------------------


function verificacpf(obj){

        if (!validacpf(obj.value)) { 	
         alert("CPF inválido!");
  		obj.value="";
         obj.focus();
         return false;

       }

 

   }

 function validacpf (cpf) {

   var soma;

   var resto;

   var i;



   if ( (cpf.length != 11) ||

     (cpf == "00000000000") || (cpf == "11111111111") ||

     (cpf == "22222222222") || (cpf == "33333333333") ||

     (cpf == "44444444444") || (cpf == "55555555555") ||

     (cpf == "66666666666") || (cpf == "77777777777") ||

     (cpf == "88888888888") || (cpf == "99999999999") ) {

     return false;

   }

   soma = 0;

   for (i = 1; i <= 9; i++) {

     soma += Math.floor(cpf.charAt(i-1)) * (11 - i);

   }

   resto = 11 - (soma - (Math.floor(soma / 11) * 11));

   if ( (resto == 10) || (resto == 11) ) {

     resto = 0;

   }

   if ( resto != Math.floor(cpf.charAt(9)) ) {

     return false;

   }

   soma = 0;

   for (i = 1; i<=10; i++) {

     soma += cpf.charAt(i-1) * (12 - i);

   }

   resto = 11 - (soma - (Math.floor(soma / 11) * 11));

   if ( (resto == 10) || (resto == 11) ) {

     resto = 0;

   }

   if (resto != Math.floor(cpf.charAt(10)) ) {

     return false;

   }

   return true;

 }

function checaCpf(campo)

 {

   var AuxStr="";

   straux = campo.value + '#';

   i = 0;

   while (straux.charAt(i)!='#')

   {

     if ((straux.charAt(i)>='0') && (straux.charAt(i)<='9'))

     {

     AuxStr += straux.charAt(i);

     }

   i++;

   }

 document.forms[0].cpf_responsavel.value=AuxStr;

// return validacpf(campo.value);

 }



 function checanum(campo)

 {

   straux = campo.value + '#';

   i = 0;

   while (straux.charAt(i)!='#')

   {

     if ( ( (straux.charAt(i)>='0') && (straux.charAt(i)<='9') ) || (straux.charAt(i)=='-') || (straux.charAt(i)=='.'))

             i++;

     else

     {

       alert('Este campo deve ser numérico.');

       campo.value = '';

       campo.focus();

       return false;

     }

   }

               return true;

 }






