// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it

function validaCPF(cpf) 
 {
   erro = new String;
 
 	if (cpf.value.length == 11)
 	{	
 			cpf.value = cpf.value.replace('.', '');
 			cpf.value = cpf.value.replace('.', '');
 			cpf.value = cpf.value.replace('-', '');
 
 			var nonNumbers = /\D/;
 	
 			if (nonNumbers.test(cpf.value)) 
 			{
 					erro = "A verificacao de CPF suporta apenas números!"; 
 			}
 			else
 			{
 					if (cpf.value == "00000000000" || 
 							cpf.value == "11111111111" || 
 							cpf.value == "22222222222" || 
 							cpf.value == "33333333333" || 
 							cpf.value == "44444444444" || 
 							cpf.value == "55555555555" || 
 							cpf.value == "66666666666" || 
 							cpf.value == "77777777777" || 
 							cpf.value == "88888888888" || 
 							cpf.value == "99999999999") {
 							
 							erro = "Número de CPF inválido!"
 					}
 	
 					var a = [];
 					var b = new Number;
 					var c = 11;
 
 					for (i=0; i<11; i++){
 							a[i] = cpf.value.charAt(i);
 							if (i < 9) b += (a[i] * --c);
 					}
 	
 					if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
 					b = 0;
 					c = 11;
 	
 					for (y=0; y<10; y++) b += (a[y] * c--); 
 	
 					if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
 	
 					if ((cpf.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])) {
 						erro = "Número de CPF inválido.";
 					}
 			}
 	}
 	else
 	{
 		if(cpf.value.length == 0)
 			return false
 		else
 			erro = "Número de CPF inválido.";
 	}
 	if (erro.length > 0) {
 			//alert(erro);
 			cpf.focus();
 			return false;
 	} 	
 	return true;	
 }
 
 //envento onkeyup
 function maskCPF(CPF) {
 	var evt = window.event;
 	kcode=evt.keyCode;
 	if (kcode == 8) return;
 	if (CPF.value.length == 3) { CPF.value = CPF.value + '.'; }
 	if (CPF.value.length == 7) { CPF.value = CPF.value + '.'; }
 	if (CPF.value.length == 11) { CPF.value = CPF.value + '-'; }
 }
 
 // evento onBlur
 function formataCPF(CPF)
 {
 	with (CPF)
 	{
 		value = value.substr(0, 3) + '.' + 
 				value.substr(3, 3) + '.' + 
 				value.substr(6, 3) + '-' +
 				value.substr(9, 2);
 	}
 }
 function retiraFormatacao(CPF)
 {
 	with (CPF)
 	{
 		value = value.replace (".","");
 		value = value.replace (".","");
 		value = value.replace ("-","");
 		value = value.replace ("/","");
 	}
 }
 
function valButton(btn) {
	var cnt = -1;
	for (var i=btn.length-1; i > -1; i--) {
		if (btn[i].checked) {
			cnt = i;
			i = -1;
		}
	}
	if (cnt > -1)
		return btn[cnt].value;
	else
		return null;
}

function verificacampos()
{ 
//VARIÁVEIS DO FORMULÁRIO 1 -> DADOS GERAIS
var indice1 = document.busca.campo.selectedIndex

  if(document.busca.campo.options[indice1].value == 0) {
    	alert('É preciso especificar uma \"Loja\"');
		document.busca.codloja.focus();
    	return false;
  }
  else
      return true;
}
  


function verificacamposrevista()
{ 
//VARIÁVEIS DO FORMULÁRIO 1 -> DADOS GERAIS
var indice1 = document.revista.cod_produto.selectedIndex

  if(document.revista.cod_produto.options[indice1].value == 0) {
    	alert('É preciso especificar uma \"Revista Nutrição em Pauta\"');
		document.revista.cod_produto.focus();
    	return false;
  }
  else
  {
	  document.forms['revista'].submit();
      return true;
  }
}

function verificacamposcd()
{ 
//VARIÁVEIS DO FORMULÁRIO 1 -> DADOS GERAIS
var indice1 = document.cd.cod_produto.selectedIndex

  if(document.cd.cod_produto.options[indice1].value == 0) {
    	alert('É preciso especificar um \"CD\"');
		document.cd.cod_produto.focus();
    	return false;
  }
  else
  {
	  document.forms['cd'].submit();
      return true;
  }
}

function verificacamposmegaevento()
{ 
//VARIÁVEIS DO FORMULÁRIO 1 -> DADOS GERAIS
var indice1 = document.megaevento.cod_produto.selectedIndex

  if(document.megaevento.cod_produto.options[indice1].value == 0) {
    	alert('É preciso especificar um \"Mega Evento\"');
		document.megaevento.cod_produto.focus();
    	return false;
  }
  else
  {
	  document.forms['megaevento'].submit();
      return true;
  }
}

function verificacamposforumnacional()
{ 
//VARIÁVEIS DO FORMULÁRIO 1 -> DADOS GERAIS
var indice1 = document.forumnacional.cod_produto.selectedIndex

  if(document.forumnacional.cod_produto.options[indice1].value == 0) {
    	alert('É preciso especificar um \"Fórum Nacional\"');
		document.forumnacional.cod_produto.focus();
    	return false;
  }
  else
  {
	  document.forms['forumnacional'].submit();
      return true;
  }
}

function verificacamposatualizacao()
{ 
//VARIÁVEIS DO FORMULÁRIO 1 -> DADOS GERAIS
var indice1 = document.atualizacao.cod_produto.selectedIndex

  if(document.atualizacao.cod_produto.options[indice1].value == 0) {
    	alert('É preciso especificar um \"Curso de Atualização\"');
		document.atualizacao.cod_produto.focus();
    	return false;
  }
  else
  {
	  document.forms['atualizacao'].submit();
      return true;
  }
}


function verifica_login() {
	
	// Validação de email
	if (document.forms['identificacao'].elements['cliente_login'].value < 1 || document.forms['identificacao'].elements['cliente_login'].value.indexOf('@', 0) == -1 || document.forms['identificacao'].elements['cliente_login'].value.indexOf('.', 0) == -1) {
		alert("Email inválido!");
		document.forms['identificacao'].elements['cliente_login'].focus();
		return (false);
	} else {
		var btn = valButton(document.forms['identificacao'].elements['cliente_cadastrado']);
		if (btn == 1 && document.forms['identificacao'].elements['cliente_senha'].value < 1) {
			alert("Por favor, preencha o campo senha!");
			document.forms['identificacao'].elements['cliente_senha'].focus();
			return (false);
		}
		if (btn == 0 && document.forms['identificacao'].elements['cep'].value < 1) {
			alert("Por favor, preencha o campo CEP!");
			document.forms['identificacao'].elements['cep'].focus();
			return (false);
		}
	}	
	document.forms['identificacao'].submit();	
	return (true);
}
// FIM VERIFICA LOGIN NA PÁGINA INDEX 

//VERIFICA CADASTRO  
function verifica_cadastro()
	{
		/*if (document.forms['cadastro'].elements['nome_completo'].value < 1)
			{
				alert("Preencha o campo nome completo!");
				document.forms['cadastro'].elements['nome_completo'].focus();
				return (false);
			}*/
		
			
		/*if (document.forms['cadastro'].elements['senha'].value < 1)
			{
				alert("Preencha o campo senha!");
				document.forms['cadastro'].elements['senha'].focus();
				return (false);
			}
		if (document.forms['cadastro'].elements['senha_confirma'].value < 1)
			{
				alert("Confirme a senha!");
				document.forms['cadastro'].elements['senha_confirma'].focus();
				return (false);
			}*/
			
		/*if (document.forms['cadastro'].elements['endereco'].value < 1)
			{
				alert("Preencha o campo endereço!");
				document.forms['cadastro'].elements['endereco'].focus();
				return (false);
			}
		if (document.forms['cadastro'].elements['cep'].value < 1)
			{
				alert("Preencha o campo cep!");
				document.forms['cadastro'].elements['cep'].focus();
				return (false);
			}						
		if (document.forms['cadastro'].elements['bairro'].value < 1)
			{
				alert("Preencha o campo bairro!");
				document.forms['cadastro'].elements['bairro'].focus();
				return (false);
			}
		if (document.forms['cadastro'].elements['cidade'].value < 1)
			{
				alert("Preencha o campo cidade!");
				document.forms['cadastro'].elements['cidade'].focus();
				return (false);
			}
		if (document.forms['cadastro'].elements['estado'].value < 1)
			{
				alert("Preencha o campo estado!");
				document.forms['cadastro'].elements['estado'].focus();
				return (false);
			}*/
		if(validaCPF(document.forms['cadastro'].elements['cpf']))
		{
		document.forms['cadastro'].submit();	
		return (true);
		}
	}	
// FIM VERIFICA CADASTRO NA PÁGINA CLIENTES_CADASTRO 


// VERIFICA PEDIDO 
function verifica_pedido(f) {
		document.forms['pedido'].submit();	
		return (true);
}

// FIM VERIFICA PEDIDO 

// ABRE POP-UP PADRÃO DO DREAMWEAVER 
function MM_openBrWindow(theURL,winName,features)
	{
		window.open(theURL,winName,features);
	}
// FIM ABRE POP-UP PADRÃO DO DREAMWEAVER 

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}
	


