// Bloqueia eventos do botao direito do mouse

function UploadImagem(a,i,t,p){

	if (a == 'REM') {	
		w = window.confirm('Deseja realmente excluir a imagem?');
		if (w == true) {
			window.open('UpLoadImagemRem.asp?id='+i+'&tbl='+t+'&PaginaRetorno='+p,'Mini','width=100 height=100');
		}
	} else {
		window.open('UpLoadImagem.asp?id='+i+'&tbl='+t+'&PaginaRetorno='+p,'Mini','width=600 height=410');
	}
}


function MoedaVerifica(valor, campo) {

  var ValorFormat = valor;
  var campo       = eval("document."+campo);

  LenValorFormat    = ValorFormat.length;
  VerifPagtoUsuario = LenValorFormat - 3;
  ValorIncorreto    = ValorFormat.charAt(VerifPagtoUsuario);
                        
  // a vigula NAO esta antes das 2 casas do centavos ?
     if (ValorIncorreto != ",") {
     alert("O valor informado parece estar incorreto. \n Digite um valor no formato 0.00");

	campo.value = "0.00";
    campo.focus();

  //TrocoUsuario.value = "";
    return false;
    }
    FindPonto2 = ValorFormat.indexOf("..");

	if (FindPonto2 != -1) {
	alert("O valor informado parece estar incorreto. \n Não deve conter (..) \n Digite um valor no formato 0.00");
	//campo.value = "0.00";
	campo.focus();              
	}

}

/*---------------------------------------------*/
// funcao somente ponto
	function SomenteNumeroPonto(e,punct)
	{		
		if (document.all){var evt=event.keyCode;}
		else{var evt = e.charCode;}
		var min_key = (punct?43:47);
		if ((evt <20) || (evt >min_key && evt<58) || (evt==46)){return true;}
		return false;
	}



/*---------------------------------------------*/
function tabAutomatico(cO,mL,cD){
var cD   = eval("document."+cD);

	if ( cO == mL ) {
		 cD.focus();   
	}
}

/*  ------------------------  formata moeda  ------------------ */ 
function FormataMoeda(CampoCent) {
	//A formatacao da moeda foi alterada. agora utilizando ponto como separador de casa decimais - 25-7-2006

	var valor = eval("document."+CampoCent);

	if ((valor.value=='') || (isNaN(valor.value)) || (valor.value == "0") || (valor.value == 0 ) ) {
		valor.value = "R$ 0.00";
	} else
		
		valor.value = valor.value.replace(",", ".");
		valor.value = valor.value.replace("R$ ", "");

		lenvalor  = valor.value.length;
		AchaPonto = valor.value.indexOf(".")
	
	    if (AchaPonto == -1)  {

			valor.value = valor.value + ".00";

		} else {

			LenTroco =  valor.value.length;
			
			CharCorreto = AchaPonto + 3;
			
			if (LenTroco > CharCorreto) {

				//alert(CharCorreto);
				valor.value = Left(valor.value,CharCorreto);
				
			} else if (LenTroco == CharCorreto) {	

				valor.value = valor.value;

			} else if (LenTroco < CharCorreto) {

				valor.value = valor.value+"0";

			}
			
		}			
		valor.value = "R$ " + valor.value;
	} // valor = ""
/*------------------------------ fim de formata moeda ------------------- */


function PaginaManutencao() {
	alert('Desculpe, Página em Desenvolvimento!');
	}
function Bloqueia(e) {
	if (window.event) {
		var X = window.event.keyCode;
		var Ctrl = window.event.ctrlKey;
		if (Ctrl && X == 78 || X == 116 || X == 122) {
			window.event.keyCode = 8;
			if (window.event.keyCode == 8) {
				window.event.cancelBubble = true;
			    window.event.returnValue = false;
			    return false;
			}
		}
	}
	else {
		var X = e.which;
		if (X == 110) return(false);
	}	

	if (navigator.appName == 'Netscape') {
	  window.captureEvents(Event.KEYPRESS);
	  window.onkeypress = Bloqueia;
	}
}


//Funcao para Exlcuir Registros 
function ExcluirRegistro(id,Item, tbl,PaginaRetorno, PaginaOrigem ) {
	
	var confirmacao = window.confirm('Deseja Realmente excluir '+Item+' ?');
	if (confirmacao == true) { 
		if (PaginaOrigem != undefined) {
		document.location.href = PaginaOrigem+'?id='+id;
		}else{	
		document.location.href = 'ExcluirRegistro.asp?Id='+id+'&tbl='+tbl+'&PaginaRetorno='+PaginaRetorno;
		}
	}
}

//Funcao Logoff
function Logoff() {
	var confirmacao = window.confirm('Deseja realmente Sair ?');
	if (confirmacao == true) { 
	document.location.href = 'logoff.asp';	
    }
	else{	
   	document.location.href='#';
  }
}

function Opener(url) { 
  opener.location.href=url;
  window.close();
}

function EnviaFormPopup(f,a, w,h){
/*
	f -> form
	a -> Ação ( open / close )
	w -> largura
	h -> altura
*/	


	var form = eval("document."+f);

	if (a == "open") {
		window.open('','Mini','width='+w+', height='+h);
		
	}else if (a == "close") {
		window.close;
	}
	form.submit();
}



// FORMATAÇÃO DE CAIXAS DE TEXTO (UNIVERSAL)
function txtBoxFormat(objForm, strField, sMask, evtKeyPress,punct) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

      if(document.all) {
        nTecla = evtKeyPress.keyCode; }
      else if(document.layers) {
        nTecla = evtKeyPress.which;
      }

      sValue = objForm[strField].value;

      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;

      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;
	  }

//Função de validação de CPF
function validaCPF(cpf) {
		 
		 if (cpf == "") {
		 
		 VarCpf = document.Form.CPF;
		 cpf = document.Form.CPF.value;
		 
		 
		 }else{
		 VarCpf = eval("document.Form."+cpf);
		 cpf = eval("document.Form."+cpf+".value");
		 
		 }
		 cpf = cpf.replace(".", "");
		 cpf = cpf.replace(".", "");
		 cpf = cpf.replace(".", ""); 
		 cpf = cpf.replace("-", ""); 
		 
		 erro = new String;
		 if ((cpf.length < 11) && (cpf != "")) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
		 var nonNumbers = /\D/;
		 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros!"+ cpf+ " \n\n"; 
		 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
				erro += "Numero de CPF invalido!"
	   }
	   var a = [];
	   var b = new Number;
	   var c = 11;
	   for (i=0; i<11; i++){
			  a[i] = cpf.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.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			   erro +="Digito verificador com problema!";
	   }
	   if (erro.length > 0){
			   alert(erro);
			   VarCpf.focus();
			   return false;
			   
	   }
	return true;
	Maskcpf = cpf.substr(0, 3) + '.' + cpf.substr(3, 6) + '.' + cpf.substr(6, 9) + '-' + cpf.substr(9, 11);
	VarCpf.value = Maskcpf;
	
}
// ---------- funcao para adicionar itens ao carrinho de compras (bandeija) -------------------
// funcao somente numeros
function SomenteNumeros(e,punct)
	{		
		if (document.all){var evt=event.keyCode;}
		else{var evt = e.charCode;}
		var min_key = (punct?43:47);
		if (evt <20 || (evt >min_key && evt<58)){return true;}
		return false;
	}
	
//------------- Email CORRETO ---------------




function valida_email(c) {
var FormEmail = eval("document."+ c);

//alert(FormEmail.value);

if (FormEmail.value == "") {
} else {
  prim = FormEmail.value.indexOf("@")
  if(prim < 2) {
  alert("O e-mail informado não contem @.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("@",prim + 1) != -1) {
  alert("O e-mail informado parece não conter um PROVEDOR valido depois do @.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf(".") < 1) {
  alert("O e-mail informado parece não conter um ponto (.) indicando seu provedor.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf(" ") != -1) {
  alert("O e-mail informado parece não estar correto.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("zipmeil.com") > 0) {
  alert("O e-mail informado parece não estar correto.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("hotmeil.com") > 0) {
  alert("O e-mail informado parece não estar correto.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf(".@") > 0) {
  alert("O valor inserido ( .@ ) iFormado parece não estar correto.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("@.") > 0) {
  alert("O e-mail informado parece não estar correto.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf(".com.br.") > 0) {
  alert("O e-mail informado parece não estar correto.");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("/") > 0) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( / )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("[") > 0) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( [ )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("]") > 0) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( ] )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("(") > 0) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( ( )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf(")") > 0) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( ) )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("..") > 0) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( .. )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
  if(FormEmail.value.indexOf("www") != -1) {
  alert("O e-mail informado parece não estar correto. Caracter ilegal ( .www. )");
  FormEmail.focus();
  FormEmail.select();
  return false;
  }
}
  return true;
}



function CaractereIlegal (e,punct)	{		

  if (document.all){
  var evt=event.keyCode;
  }else{
  var evt = e.charCode;}
  if (evt==39){
  return false;
  }
  return true;
}




// VERIFICA CAMPOS EM BRANCO
function checkCampos(form,valor){

	var frm = eval("document."+form);
	
	var ValorCampo = valor;
	
	var ArrayCampo = new String(ValorCampo) 
	
	ArrayCampo = ArrayCampo.split(",");

	var nomedocampo = ArrayCampo;
	var descricao = ArrayCampo;

	var msgAlert = "Por favor complete os seguintes Campos:\n\n";
	var msg = msgAlert.length;
	
	for (var i = 0; i < nomedocampo.length; i++){
		var objetos = frm.elements[nomedocampo[i]];
		var Ly = "Linha" + nomedocampo[i];
		var ExibeIcone = null;
	
		//alert(Ly);
		document.getElementById(Ly).style.display = "none";
		if (objetos){
			switch(objetos.type){
			case "select-one":
				if (objetos.selectedIndex == -1 || 
					objetos.options[objetos.selectedIndex].text == "" || objetos.value == ""){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
				break;
			case "select-multiple":
				if (objetos.selectedIndex == -1){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
				break;

			case "text":
			case "textarea":
			case "password":
			
				if (objetos.value == "" || objetos.value == null ){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
				break;
			default:
			}
			if (objetos.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < objetos.length; j++){
					if (objetos[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
			}
		}
	}

	if (msgAlert.length == msg){
		//alert('Todos os Campos estão Preenchidos!');
		frm.submit();
		return true;
	}else{
		//alert(msgAlert);
		return false;
	}
	
} //checkCampos
									
//----------------------------------------------------------------------------------
function checkCamposValida(form,valor){

	var frm = eval("document."+form);
	
	var ValorCampo = valor;
	
	var ArrayCampo = new String(ValorCampo) 
	
	ArrayCampo = ArrayCampo.split(",");

	var nomedocampo = ArrayCampo;
	var descricao = ArrayCampo;

	var msgAlert = "Por favor complete os seguintes Campos:\n\n";
	var msg = msgAlert.length;
	
	for (var i = 0; i < nomedocampo.length; i++){
		var objetos = frm.elements[nomedocampo[i]];
		var Ly = "Linha" + nomedocampo[i];
	
		//alert(Ly);
		document.getElementById(Ly).style.display = "none";
		if (objetos){
			switch(objetos.type){
			case "select-one":
				if (objetos.selectedIndex == -1 || 
					objetos.options[objetos.selectedIndex].text == "" || objetos.value == ""){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
					
				}
				break;
			case "select-multiple":
				if (objetos.selectedIndex == -1){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
				break;

			case "text":
			case "textarea":
			case "password":
				if (objetos.value == "" || objetos.value == null ){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
				break;
			default:
			}
			if (objetos.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < objetos.length; j++){
					if (objetos[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					msgAlert += " - " + descricao[i] + "\n";
					document.getElementById(Ly).style.display = "";
				}
			}
		}
	}

	if (msgAlert.length == msg){
		//alert('Todos os Campos estão Preenchidos!');
		return true;
	}else{
		//alert(msgAlert);
		return false;
	}
	
} //checkCampos
//-------------------------------------------------------------------

// Funcao para verificar Senha e confirmacao de Senha
function ValidaSenha(Senha,SenhaX) {

if (Senha.value == "") {

	alert('Preencha o campo Senha para continuar!');
	Senha.focus();
	return (false);
	
}else{
	
	if (Senha.value != SenhaX.value) {

	alert('A confirmação da senha, não coincide com a senha digitada');
	SenhaX.value = "";
	Senha.value = "";
	Senha.focus();
	return (false);
	}					
  }
} // ValidaSenha

function AlertaOper() {
	alert('Por favor, clique em Salvar e selecione esta opção Novamente.');
}
//----------------------------------------------------------------------------------
function AbreImagem(img, w, h) {
	window.open ("Visualizar_imagem.asp?ImagemNome="+img,"","width="+w+", height="+h+", scrollbars=no, resizable=no");
}
//----------------------------------------------------------------------------------
function MostraTR(lugar) {
	if(document.getElementById(lugar).style.display == "none"){
		document.getElementById(lugar).style.display = "block";
	}else{
		document.getElementById(lugar).style.display = "none";
	}
}

//----------------------------------------------------------------------------------
function MostraTRimg(linha,imagem, img1, img2) {

	var linha = document.getElementById(linha);
	
	  if (linha.style.display=='none') {
		   linha.style.display='';
	       if(imagem != null) 
		   	 imagem.src='../<%=Application("URLimagem")%>'+img2+'.gif';
	  } else {
		   linha.style.display='none';
	       if(imagem != null) 
		     imagem.src='../<%=Application("URLimagem")%>'+img1+'.gif';
      }

}
//----------------------------------------------------------------------------------
function MostraDiv( Ly, y){
var Ly
	if (y==1) { 
			void(document.all[Ly].style.visibility='visible');
	} else {
			void(document.all[Ly].style.visibility='hidden')
	}
}
//----------------------------------------------------------------------------------
function ExibeImagem(campo,img) { 
	img.src = campo.value;
}


//------------------------- FUNCAO PARA FORMATAR MOEDA -----------------
function LimparCampoMoeda(valor, validos) { 
// retira caracteres invalidos da string 
	var result = ""; 
	var aux; 
	for (var i=0; i < valor.length; i++) { 
		aux = validos.indexOf(valor.substring(i, i+1)); 
		if (aux>=0) { 
			result += aux; 
		} 
	} 
	return result; 
} 

//Formata número tipo moeda usando o evento onKeyDown 

function FormataCampoMoeda(campo,tammax,teclapres,decimal) { 
var tecla = teclapres.keyCode; 
vr = LimparCampoMoeda(campo.value,"0123456789"); 
tam = vr.length; 
dec=decimal 

if (tam < tammax && tecla != 8){ 
	tam = vr.length + 1 ; 
	} 

if (tecla == 8 ) { 
	tam = tam - 1 ; 
	} 

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) { 
	
		if ( tam <= dec ) 	{ 
		campo.value = vr ; 
		} 
		
		if ( (tam > dec) && (tam <= 5) )	{ 
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ; 
			} 
		if ( (tam >= 6) && (tam <= 8) ){ 
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
			} 
		if ( (tam >= 9) && (tam <= 11) ){ 
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
			} 
		if ( (tam >= 12) && (tam <= 14) ){ 
			campo.value = vr.substr( 0, tam - 11 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 
			} 
		if ( (tam >= 15) && (tam <= 17) ){ 
			campo.value = vr.substr( 0, tam - 14 ) + "." + vr.substr( tam - 14, 3 ) + "." + vr.substr( tam - 11, 3 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - 2, tam ) ;
			} 
		
	}  //	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) { 

}  //FormataCampoMoeda
//----------------------------------------------------------------------------------
//###################################################################################
