function ampliada(foto,legenda,tipo){
	myWindow=window.open('fotoshow.php?cod=HJNSOI2398FDKJH3487FDJH430945JLK98&imagem='+foto+'&tp='+tipo+'&id=sdflkj23897fsdkjh23487kjh45987dfgjkh','foto','scrollbars=yes,resize=no,width=560,height=530,left=100,top=100');
	myWindow.focus()
}

function toggleContent(strDivName)
{
    if (eval (document.getElementById(strDivName)).style.display != 'block')
    {
        eval (document.getElementById(strDivName)).style.display = 'block';
    }
    else
    {
        eval (document.getElementById(strDivName)).style.display = 'none';
    }
}


function masccpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function mascdata(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{2})(\d)/,"$1/$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    return v
}

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}


function soNumeros(v){
    return v.replace(/\D/g,"")
}


function CPFValido(st) {
    //cpf = eval(document.formCadastro["cpf"])? document.formCadastro["cpf"] : "";
    var ok = false;
		st = st.replace('.','')
		st = st.replace('.','')
		st = st.replace('-','')
//alert(st);
if (st=="") return (false);

    for (i=0;i<(st.length-1);i++){
        prev=st.charAt(i)
        next=st.charAt(i+1)
        if ( prev != next)
            ok=true;
    }

    if ( ok != true )
        return (false)

        l = st.length;
        st2 = "";
        for (i = 0; i < l; i++) {
                caracter = st.charAt(i,i+1)
                if ((caracter >= '0') && (caracter <= '9'))
                        st2 = st2 + caracter;
        }
   if ((st2.length > 11) || (st2.length < 10))
        return (false);
        if (st2.length==10)
                st2 = '0' + st2;
        digito1 = st2.charAt(9,10)
        digito2 = st2.charAt(10,11)

        digito1 = parseInt(digito1,10)
        digito2 = parseInt(digito2,10)

        sum = 0; mul = 10;
        for (i = 0; i < 9 ; i++) {
        digit = st2.substring(i,i+1);
                tproduct = parseInt(digit ,10)*mul;
      sum += tproduct;
                mul--;
   }
        dig1 = ( sum % 11 )
        if ( dig1==0 || dig1==1 )
                dig1=0;
        else
                dig1 = 11 - dig1

        if (dig1!=digito1)
                return (false);

        sum = 0; mul = 11;
        for (i = 0; i < 10 ; i++) {
        digit = st2.substring(i,i+1);
                tproduct = parseInt(digit ,10)*mul;
      sum += tproduct;
                mul--;
        }
        dig2 = (sum % 11)

        if ( dig2==0 || dig2==1 )
                dig2=0;
        else
                dig2 = 11 - dig2;

        if (dig2!=digito2)
                return (false);
        return (true)
}

function checkDATE(s) {
	if (s.length == 0) {
		return true;
	}

	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	if(!objRegExp.test(s)) {
		return false; //doesn't match pattern, bad date
	}

	d = parseInt(s.substr(0, 2), 10);
	m = parseInt(s.substr(3, 2), 10);
	y = parseInt(s.substr(6, 4), 10);

	bin_m = (1 << (m-1));

	// 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
	m31 = 0xAD5;

	if (( y < 1000) || (m < 1) || (m > 12) || (d < 1) || (d > 31) || ((d == 31 && ((bin_m & m31) == 0))) || ((d == 30 && m == 2)) || ((d == 29 && m == 2 && !isLeap(y))) ) {
		return false;
	}
	return true;
}

function isLeap(year) {
	return (year % 4 == 0) && (year % 100 != 0 || year % 400 == 0);
}

function validarCadastro()
{
	msgErros = '';
	cntErros = 0;
	with (document.formCadastro)
	{
		
		if (concordo.checked == false)
		{
			msgErros += "-> Você precisa estar de acordo com o regulamento para prosseguir\n";
			cntErros++;
		}
		
		if (nome.value.length < 3)
		{
			msgErros += "-> Nome\n";
			cntErros++;
		}

		if (endereco.value.length < 3)
		{
			msgErros += "-> Endereço\n";
			cntErros++;
		}	
		
		if (cidade.value.length < 3)
		{
			msgErros += "-> Cidade\n";
			cntErros++;
		}		
		
		if (telefone.value.length < 6)
		{
			msgErros += "-> Telefone\n";
			cntErros++;
		}
		
		if (email.value.length < 6)
		{
			msgErros += "-> Email\n";
			cntErros++;
		}
		else
		{
			if (email.value.indexOf('@',0)==-1 ||
				email.value.indexOf('@',0)== 0 ||
				email.value.indexOf('.',0)==-1)
      	{
            msgErros += "-> Email (é inválido)\n";
				cntErros++;
      	}
		}
		

		/*if (CPFValido(cpf.value)!=true)
		{
			msgErros += "-> CPF inválido\n";
			cntErros++;
		}
		*/
		  
		if (nascimento.value.length < 10)
		{
			msgErros += "-> Data de nascimento\n";
			cntErros++;
		}
		
		if (checkDATE(nascimento.value)!=true)
		{
			msgErros += "-> Data inválida\n";
			cntErros++;
		}
		
	
		if (cntErros > 0)
		{
			alert("Você precisa preencher corretamente o(s) campo(s)\n abaixo para poder enviar o formulário:\n" + msgErros);
		}
		else
		{
			if (confirm("Você confirma as informações contidas no formulário?"))
			{
				action = "cadastra.php";
				submit();
			}
		}
	}

}


function validarVoto()
{
	msgErros = '';
	cntErros = 0;
	with (document.formVoto)
	{
		
		if (nome.value.length < 3)
		{
			msgErros += "-> Nome\n";
			cntErros++;
		}

		if (endereco.value.length < 3)
		{
			msgErros += "-> Endereço\n";
			cntErros++;
		}	
		
		if (cidade.value.length < 3)
		{
			msgErros += "-> Cidade\n";
			cntErros++;
		}		
		
		if (email.value.length < 6)
		{
			msgErros += "-> Email\n";
			cntErros++;
		}
		else
		{
			if (email.value.indexOf('@',0)==-1 ||
				email.value.indexOf('@',0)== 0 ||
				email.value.indexOf('.',0)==-1)
	      	{
	            msgErros += "-> Email (é inválido)\n";
					cntErros++;
	      	}
		}
		
		
		if (telefone.value.length < 6)
		{
			msgErros += "-> Telefone\n";
			cntErros++;
		}
		
		  
		if (nascimento.value.length < 10)
		{
			msgErros += "-> Data de nascimento\n";
			cntErros++;
		}
		
		if (checkDATE(nascimento.value)!=true)
		{
			msgErros += "-> Data inválida\n";
			cntErros++;
		}
		
	
		if (cntErros > 0)
		{
			alert("Você precisa preencher corretamente o(s) campo(s)\n abaixo para poder enviar o formulário:\n" + msgErros);
		}
		else
		{
			if (confirm("Você confirma as informações contidas no formulário?"))
			{
				action = "vota.php";
				submit();
			}
		}
	}

}


//AJAX

var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
  {// code for Firefox, Opera, IE7, etc.
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
if (xmlhttp!=null)
  {
  xmlhttp.onreadystatechange=state_Change;
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
  }
else
  {
  alert("A versão de seu navegador é antiga e não suporta XMLHTTP.");
  }
}

function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
    {// 200 = "OK"
    document.getElementById('servicos').innerHTML=xmlhttp.responseText;
    }
  else
    {
    //alert("Problema ao carregar dados: " + xmlhttp.statusText);
    document.getElementById('servicos').innerHTML="<strong>ERRO! Problema ao carregar dados: </strong>" + xmlhttp.statusText;
    }
  }
}

// fim ajax

