// 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 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 ) { 
			}  
			
/*---------------------------------------------*/
// 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) {
	//alert(eval(document.+CampoCent+.value));
//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;
}




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
//----------------------------------------------------------------------------------
//###################################################################################
//Função para Validação de Campos
function Validar(Form,Valor) 
{
	//alert(Form);
	var ArrayCampo = new String(Valor); 
	var ArrayCampo = ArrayCampo.split(",");
		for(i=0;i<ArrayCampo.length; i++) 
		{
			//alert(ArrayCampo.length);
			var Ly = 'Linha'+ArrayCampo[i];
	//		alert(Ly);
			var x = 0;
			if(document.getElementById(ArrayCampo[i]).value=="")
			{
			document.getElementById(Ly).style.display="";
			return false;
			x = x + 1;
			}
		}
		if(x==0){
			//alert(i+"<br>"+ArrayCampo.length);
		document.getElementById(Form).submit();	
			}

}

function ExibeLinha(Linha) {
	alert(Linha);
/*		var Linha = document.getElementById('LinhaFoto'+Linha);
		if(Linha.style.display=='none') {
				Linha.style.display='';
		}else {
				Linha.style.display='none';
		}*/
}
function exibeMidia(modo, tb) { 

var visao = document.getElementById(tb).style.display;
if(modo=="1") { 
	document.getElementById(tb).style.display = 'block';	
} 
else { 
	document.getElementById(tb).style.display = 'none';	
	} 
 }



function marca(campo, valor) { 
	for (i=0; i<valor; i++)
//		if (campo[i].value == valor){ 
			if(campo[i].checked==false) { 
			 	campo[i].checked = true ; 
		}	
		else { 
			 	campo[i].checked = false; 
		}
		 } 

