// JavaScript Document

function Multimidia(codigo, acao, tipo) {

	if( acao == 'stream' ) {

		if( tipo == 'audio' ) {

			radio = window.open( "stream_audio.php?id=" + codigo, "Radio", "toolbar=no,menubar=no,status=no,scroll=no,scrollbar=no,width=177,height=200");

			radio.focus();

		}

		if( tipo == 'video' ) {

			radio = window.open( "stream_video.php?id=" + codigo, "TV", "toolbar=no,menubar=no,status=no,scroll=no,scrollbar=no,width=270,height=370");

			radio.focus();

		}

	} else if( acao == 'download' ) {

		window.open( "download.php?id=" + codigo );

	}

}

function galeria_direita2_DoFSCommand(command, args) {

	alert(command);

	if (command == "galeria") {

		var opcoes=split(args,',');

		Galeria(opcoes[0],opcoes[1]);

	}

}



function Galeria(idgal,idfoto) {

	var gal = window.open( "galeria.php?id="+idgal+"&idfoto="+idfoto, 'Galeria'+idgal, 'toolbars=no,menubar=no,status=yes,width=690,height=480' );

	gal.focus();

	return;

}



function fsize(size,unit,id){

  var vfontsize = document.getElementById(id);

  if(vfontsize){

   vfontsize.style.fontSize = size + unit;

  }

}



function checkPass(){

    var x = document.getElementById('senha_a').value;

    var y = document.getElementById('senha_b').value;



    if(x==y){

        document.getElementById('green').style.display = '';

    }else{

        document.getElementById('green').style.display = 'none';

    }

}

 function validarCPF(cpf_text){
   var cpf = cpf_text;
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   
   cpf = remove_char_cpf(cpf, ".");
   cpf = remove_char_cpf(cpf, "-");
    
   if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
	  cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  cpf == "88888888888" || cpf == "99999999999"){
	  window.alert("CPF inválido. Tente novamente.");
	  return false;
   }

   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
	 window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
     window.alert("CPF inválido. Tente novamente.");
	 return false;
   }
   return true;
 }
 
 function remove_char_cpf(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove_char_cpf(str.substring(i + sub.length), sub);
   return r;
 }

function validateFormCad(){

    var e       = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

    var nome    = document.getElementById('nome');

    var email   = document.getElementById('email');
	
	var cpf   = document.getElementById('cpf');

    var senha_a = document.getElementById('senha_a');

    var senha_b = document.getElementById('senha_b');

    



    if(nome.value == ''){

        alert('O campo nome não pode ficar vazio');

        nome.focus();

        return false;

    }

    

    if(!e.test(email.value)){

        alert('E-mail inválido');

        email.focus();

        return false;

    }


    if(senha_a.value == ''){

        alert('O campo senha não pode ficar vazio');

        nome.focus();

        return false;

    }
	
    if(senha_b.value == ''){

        alert('O campo senha não pode ficar vazio');

        nome.focus();

        return false;

    }	
	
    if(senha_a.value != senha_b.value){

        alert('Senhas não conferem');

        senha_a.focus();

        return false;

    }
	
    if(cpf.value == ''){

        alert('O campo CPF não pode ficar vazio');

        cpf.focus();

        return false;

    } else {
		if (!validarCPF(cpf.value)) {
			return false;
		}
	}

    return true;

}
