


// ------------------------------ FUNCOES PARA MENU --------------------------------------




function SubMenu(lugar, TotCat ) {

    //TotCat = <%=TotCat%>;
	urlImagem = 'http://www.cinedigital.com.br/images/';
	NomeDiv = "item" ;
	img1 = 'icoCatMais';
	img2 = 'icoCatMenos';
	for (i=1; i<=TotCat; i++) {
			DivFor = NomeDiv+""+i;
			//alert(NomeDiv+""+i);
			imagem = document.getElementById('img'+DivFor);
			if (DivFor != lugar) {
			if(document.getElementById(DivFor).style.display == ""){
				document.getElementById(DivFor).style.display = "none";
			   	imagem.src=urlImagem+img1+'.gif';
			}
			}
	}
	
   imagem = document.getElementById('img'+lugar);
	if(document.getElementById(lugar).style.display == "none"){
		document.getElementById(lugar).style.display = "";
	       if(imagem != null) 
		   	 imagem.src=urlImagem+img2+'.gif';
	}else{
		document.getElementById(lugar).style.display = "none";
	       if(imagem != null) 
		   	 imagem.src=urlImagem+img1+'.gif';
	}
}

function MostraTRimg(linha,imagem, img1, img2) {
	var urlImagem = 'http://www.cinedigital.com.br/images/';
	var linha = document.getElementById(linha);
	
	  if (linha.style.display=='none') {
		   linha.style.display='';
	       if(imagem != null) 
		   	 imagem.src=urlImagem+img2+'.gif';
	  } else {
		   linha.style.display='none';
	       if(imagem != null) 
		     imagem.src=urlImagem+img1+'.gif';
      }

}








// ------------------------------ FIM DE FUNCOES PARA AJAX --------------------------------------

function MostraTRLoop(lugar, id, qtdTR) {

	for (i=1;i<=qtdTR;i++){
	///alert(lugar + i);
	document.getElementById(lugar + i).style.display = "none";
	}
	document.getElementById(lugar + id).style.display = "";
}

function MostraTRcontrole(lugar, controle) {
	
	if(controle == 1 ){
		document.getElementById(lugar).style.display = "";
	}else{
		document.getElementById(lugar).style.display = "none";
	}
}
//------------------------------------------

function OnEnter(evt)
{
    var key_code = evt.keyCode  ? evt.keyCode  :
                       evt.charCode ? evt.charCode :
                       evt.which    ? evt.which    : void 0;


	//alert(key_code);
    if (key_code == 13)
    {
        return true;
    }
}

// Validando a tecla ENTER para uso do botão "BUSCAR"
function EnviaBusca(e)
{
    if(OnEnter(e))
    {
       //document.getElementById("btBusca").click();
	   abreProduto('ValorBusca=' + document.getElementById('ValorBusca').value);
       return false;
    }
    else
    {
        return true;
    }
}

//------------------------------------------
function LimitaCaractere(qtd){
    limite = qtd;
    myTextArea = document.forms[0].Resumo;

    if (myTextArea.value.length > limite) {
        myTextArea.value = myTextArea.value.substr(0, (myTextArea.value.length - (myTextArea.value.length - limite)));
    }
}

//------------------------------------------
function MostraTR(lugar) {
	if(document.getElementById(lugar).style.display == "none"){
		document.getElementById(lugar).style.display = "";
	}else{
		document.getElementById(lugar).style.display = "none";
	}
}

//------------------------------------------
function TrocaTR(div1, div2) {

if(document.getElementById(div1).style.display == "none"){
		document.getElementById(div1).style.display = "";
		document.getElementById(div2).style.display = "none";
	}else{
		document.getElementById(div1).style.display = "none";
		document.getElementById(div2).style.display = "";
	}
}
// ------------------------------ FIM DE FUNCOES PARA AJAX --------------------------------------
function UploadImagem(a,i,t,p){

	if (a == 'REM') {	
		w = window.confirm('Deseja realmente excluir a imagem?');
		if (w == true) {
			window.open('UpLoadImagemRemover.asp?id='+i+'&tbl='+t+'&PaginaRetorno='+p,'Mini','width=400,height=300');
		}
	} else {
		window.open('UpLoadImagem.asp?id='+i+'&tbl='+t+'&PaginaRetorno='+p,'Mini','width=600,height=410');
	}
}

function UploadFoto(a,i,t,p){

	document.getElementById("iframeMini").style.display = '';
	if (a == 'REM') {	
		w = window.confirm('Deseja realmente excluir a imagem?');
		if (w == true) {
			window.open('UpLoadFotoRemover.asp?id='+i+'&tbl='+t+'&PaginaRetorno='+p,'Mini','width=400,height=300');
		}
	} else {
		window.open('UpLoadFoto.asp?id='+i+'&tbl='+t+'&PaginaRetorno='+p,'Mini','width=600,height=410');
	}
}

//-----------------------------------------------------------
// 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();   
	}
}

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 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);
    var urlImg = 'http://www.cinedigital.com.br/images/';
	  if (linha.style.display=='none') {
		   linha.style.display='';
	       if(imagem != null) 
		   	 imagem.src= urlImg +img2+'.gif';
	  } else {
		   linha.style.display='none';
	       if(imagem != null) 
		     imagem.src= urlImg +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;
}



