// Início Pop-up com e sem scrollbar
function abrir(url, width, height)
{
	var lado = (screen.width - width) / 2;
	var topo = (screen.height - height) / 2;
	window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,menubar=no,top='+topo+',left='+lado+',width=' + width + ',height=' + height)
}

function abrirnb(url, width, height)
{
	var lado = (screen.width - width) / 2;
	var topo = (screen.height - height) / 2;
	window.open(url,'_blank','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,top='+topo+',left='+lado+',width=' + width + ',height=' + height)
}
// Fim Pop-up com e sem scrollbar


function criaMascara(_RefObjeto, _Modelo)
{
	var valorAtual = _RefObjeto.value;        
	var valorNumerico = '';
	var nIndexModelo = 0;
	var nIndexString = 0;
	var valorFinal = '';
	var adicionarValor = true;
    
     
	// limpa a string valor atual para verificar 
	// se todos os caracteres são números
	for (i=0;i<_Modelo.length;i++){
		if (_Modelo.substr(i,1) != '#'){
			valorAtual = valorAtual.replace(_Modelo.substr(i,1),'');
  		}
 	}
      
 	// verifica se todos os caracteres são números
 	for (i=0;i<valorAtual.length;i++){
  		if (!isNaN(parseFloat(valorAtual.substr(i,1)))){
			valorNumerico = valorNumerico + valorAtual.substr(i,1);
  		}
 	}
      
 	// aplica a máscara ao campo informado usando
 	// o modelo de máscara informado no script
 	for (i=0;i<_Modelo.length;i++){
  		if (_Modelo.substr(i,1) == '#'){
    			if (valorNumerico.substr(nIndexModelo,1) != ''){
				valorFinal = valorFinal + valorNumerico.substr(nIndexModelo,1);
				nIndexModelo++;nIndexString++;
    			} 
    			else {
        			adicionarValor = false;
    			}
  		}
  		else {
     			if (adicionarValor && valorNumerico.substr(nIndexModelo,1) != ''){
  				valorFinal = valorFinal + _Modelo.substr(nIndexString,1)
				nIndexString++;
     			}
  		}
 	}
    
 	_RefObjeto.value = valorFinal 
}

function FormataValor(campo,tammax,teclapres)
{
    	var tecla = teclapres.keyCode;
    	vr = campo.value;
    	vr = vr.replace( "/", "" );
    	vr = vr.replace( "/", "" );
    	vr = vr.replace( ",", "" );
    	vr = vr.replace( ".", "" );
    	vr = vr.replace( ".", "" );
    	vr = vr.replace( ".", "" );
    	vr = vr.replace( ".", "" );
    	tam = vr.length;

    	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 <= 2 ){
             		campo.value = vr; }
         	if ( (tam > 2) && (tam <= 5) ){
             		campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
         	if ( (tam >= 6) && (tam <= 8) ){
           		campo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, 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 - 2, 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 - 2, 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 );}
    	}            
}

function FormataValorOut(campo){
	var vr = campo.value;
	if (vr.length <= 2){
		vr = vr.replace( "/", "" );
		vr = vr.replace( "/", "" );
		vr = vr.replace( ",", "" );
		vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );
	    	vr = vr.replace( ".", "" );
		vr = vr.replace( ".", "" );

		if (vr.length <= 2 && vr.length != 0){
			vr = vr + "00";
		}
		tam = vr.length;
		if (tam > 0 ){
			campo.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam );
		}
	}
}

function fu_mascara_valor(campooriginal,decimais)
{
  	var posicaoPontoDecimal;
  	var campo = '';
  	var resultado = '';
  	var pos,sep,dec;

        if(isNaN(campooriginal.value)) {
                campooriginal.value = '';
        }

	//Retira possiveis separadores de milhar
	for (pos=0; pos < campooriginal.value.length; pos ++)
  	{
    	if (campooriginal.value.charAt(pos)!='.')
        	campo = campo + campooriginal.value.charAt(pos);
  	}

	//Formata valor monetário com decimais
  	posicaoPontoDecimal = campo.indexOf(',');
  	if (posicaoPontoDecimal != -1)
   	{
      		sep = 0;
      		for (pos=posicaoPontoDecimal-1;pos >= 0;pos--)
      		{
        		sep++;
        		if (sep > 3)
        		{
           			resultado = '.' + resultado;
           			sep = 1;
        		}

        		resultado = campo.charAt(pos) + resultado;
      		}

      		// Trata parte decimal
      		if (parseInt(decimais) > 0 )
      		{
         		resultado = resultado + ',';
         		pos=posicaoPontoDecimal+1;
         		for (dec = 1;dec <= parseInt(decimais); dec++)
         		{
           			if (pos < campo.length)
           			{
              				resultado = resultado + campo.charAt(pos);
              				pos++;
           			}
           			else
              				resultado = resultado + '0';
         		}

      		} // trata decimais
   	}
   	// Trata valor monetário sem decimais
   	else
   	{
      		sep = 0;
      		for (pos=campo.length-1;pos >= 0;pos--)
      		{
        		sep ++;
        		if (sep > 3)
        		{
           			resultado = '.' + resultado;
           			sep = 1;
        		}
        		resultado = campo.charAt(pos) + resultado;
      		}
      		// Trata parte decimal
      		if (parseInt(decimais) > 0 )
      		{
         		resultado = resultado + ',';
         		for (dec = 1;dec <= parseInt(decimais); dec++)
         		{
              			resultado = resultado + '0';
         		}
      		} // trata decimais
   	}
   	campooriginal.value = resultado;
}


function soNums(e,args)
{        
//  onKeyPress ="return (soNums(event,'(/){,}.'));"
	var valid_chars    = new Array();
   	if (document.all){
		var evt = event.keyCode;
	}
	else{
		var evt = e.charCode;
	}
   	var chr= String.fromCharCode(evt);
   	
	if (evt <20 || (evt >47 && evt<58) || (args.indexOf(chr)>-1 ) ){return true;}
   	return false;
} 


function imgload() {
	var d=document;
	if(d.images){
    		if(!d.MM_p)
      			d.MM_p=new Array();
    		var i,j=d.MM_p.length,a=imgload.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];
      			}
  		}
}




// Início do upload de imagem
	var maxWidth = 200;
	var maxHeight = 200;
	var fileTypes = ["bmp","gif","png","jpg","jpeg"];
	var outImage = "previewField";
	var defaultPic = "../../imagens/x.jpg";


	function preview(what)
	{
		var source = what.value;
  		var ext = source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  		for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  		globalPic=new Image();
  		if (i<fileTypes.length) globalPic.src=source;
  		else {
    			globalPic.src = defaultPic;
    			alert("Formato inválido de imagem\nEsscolha uma das seguintes extesões:\n\n"+fileTypes.join(", "));
  		}
  		setTimeout("applyChanges()",200);
	}

	var globalPic;
	function applyChanges()
	{
  		var field = document.getElementById(outImage);
  		var x = parseInt(globalPic.width);
  		var y = parseInt(globalPic.height);
  		if (x > maxWidth){
    			y *= maxWidth/x;
    			x = maxWidth;
  		}
  		if (y > maxHeight) {
    			x *= maxHeight/y;
    			y = maxHeight;
  		}
  		field.style.display = (x<1 || y<1)?"none":"";
  		field.src = globalPic.src;
  		field.width = x;
  		field.height = y;
	}
// Fim de upload de imagem



// Início Validação de Formulário

function validacao(formulario){

for(i=0;i<=formulario.length-1;i++){
	if ((formulario[i].type=="textarea")||(formulario[i].type=="file")||(formulario[i].type=="hidden")||(formulario[i].type=="text")||(formulario[i].type=="password")){
		if ((formulario[i].wmsg!="")&&(formulario[i].wmsg!=undefined)){
			if (formulario[i].email=="sim"){
				if((formulario[i].value=="")||(formulario[i].value.indexOf('@')==-1)||(formulario[i].value.indexOf('.')==-1)){
					alert(formulario[i].wmsg);
					try{
						formulario[i].focus();
					}
					catch(e){
						}				
				    return false
				}	
			}else{
				if(formulario[i].value==""){
					alert(formulario[i].wmsg);
					try{
						formulario[i].focus();
					}
					catch(e){

						}
				
					return false
				}
			}
		}
	}	
}

}

// Fim Validação de Formulário



// Início funções by Hargon

	var anterior = '';
	var num = 0;
	
	function abrirsubmenu(camada){
		if(anterior != camada){
			document.getElementById(camada).style.display = 'block';
			if(anterior != ""){ 
				document.getElementById(anterior).style.display = 'none';
			}
			anterior = camada;
		}
	}

	function mostraritem(camada,camada2){
		document.getElementById(camada).style.display = 'block';
		document.getElementById(camada2).style.display = 'none';
	}

	function apagar(p,codigo)
	{
		var resp = confirm("Você tem certeza que deseja excluir este registro?") 
		if(resp){
			window.location="admin.asp?p="+p+"&id=7&codigo="+codigo;	
		} 
	}

	function setImagem(link1,img1,id,imgbtn){
		if (id == 2){
			id = id - 1;
		}else{
			id = id + 1;
		}
		document.getElementById(img1).src='imagens/btn'+imgbtn+id+'.gif';
		document.getElementById(link1).href="javascript:setImagem('"+link1+"','"+img1+"',"+id+",'"+imgbtn+"');";
	}


	function setImagemDestaque(id,total){
		var dt1, dt2;
		for(i=1; i <= total; i++){
			if (id == i){
				dt1 = 2;
				dt2 = 1;
			}else{
				dt1 = 1;
				dt2 = 2;
			}
			document.getElementById("imgd"+i).src='../../imagens/btndestaque'+dt1+'.gif';
			document.getElementById("linkd"+i).href="javascript:setImagemDestaque('"+i+"',"+total+");";				
		}
	}

	function setconfirmacao(id){
		document.getElementById(id).style.display='none';
	}

	function EnabledDisabled(valor){
		tam = valor.length;
		var chr = "txtvlsubgrupo";
		if (tam > 0){
			document.forms[0].chkcdprecopadrao.disabled = "";
			for(var i = 0; i < document.forms[0].elements.length; i++) {
				var args = document.forms[0].elements[i].name;
				if (args.indexOf(chr) == 0){
					document.forms[0].elements[i].disabled = "";
				}
			}
		}else{
			document.forms[0].chkcdprecopadrao.disabled = "disabled";
			for(var i = 0; i < document.forms[0].elements.length; i++) {
				var args = document.forms[0].elements[i].name;
				if (args.indexOf(chr) == 0){
					document.forms[0].elements[i].disabled = "disabled";
				}
			}
		}
	}

	function marcatodos(valor){
		var chr = "txtvlsubgrupo";
		tam = valor.length;
		if (tam > 0){
			for(var i = 0; i < document.forms[0].elements.length; i++) {
				var args = document.forms[0].elements[i].name;
				var chr2 = document.forms[0].elements[i].value;
				if ((args.indexOf(chr) == 0) && (chr2.length == 0)){
					document.forms[0].elements[i].value = "0";
				}
			}	
		}
	}

	function ContaCaracteres(tamanho,form,campo,campo2){
	   	var campo = document.forms[form].elements[campo];
	   	var campo2 = document.forms[form].elements[campo2];
   		intCaracteres = tamanho - campo.value.length;
		if (intCaracteres > 0){
			campo2.value = intCaracteres;
		      	return true;
		}
		else {
			campo2.value = 0;
      			campo.value = campo.value.substr(0,tamanho);
      			return false;
   		}
	}


	function apagararquivo(t,codigo,cdfoto)
	{
		var resp=confirm("Você tem certeza que deseja excluir este arquivo?") 
		if(resp){
			window.location="uploadex.asp?t="+t+"&codigo="+codigo+"&cdfoto="+cdfoto;
		} 
	}


	function apagarbanner(codigo)
	{
		var resp=confirm("Você tem certeza que deseja excluir este banner?") 
		if(resp){
			window.location="uploadex.asp?codigo="+codigo;
		} 
	}

	function apagarimagem(codigo,cdfoto)
	{
		var resp=confirm("Você tem certeza que deseja excluir esta imagem?") 
		if(resp){
			window.location="uploadex.asp?cdfoto="+cdfoto+"&codigo="+codigo;
		} 
	}

	function apagardestaque(codigo)
	{
		var resp=confirm("Você tem certeza que deseja excluir esta imagem?") 
		if(resp){
			window.location="uploadex.asp?t=1&codigo="+codigo;
		} 
	}

	function apagardestaquemenor(codigo)
	{
		var resp=confirm("Você tem certeza que deseja excluir esta imagem?") 
		if(resp){
			window.location="uploadex.asp?t=2&codigo="+codigo;
		} 
	}

// Fim funções by Hargon










// Função de mascara de moeda
function Moeda(fld, e) 
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{ 
		var milSep = "."; 
		var decSep = ","; 
		var sep = 0; 
		var key = ''; 
		var i = j = 0; 
		var len = len2 = 0; 
		var strCheck = '0123456789'; 
		var aux = aux2 = ''; 
		var whichCode = (window.Event) ? e.which : e.keyCode; 

		if (whichCode == 13) 
			return true; 

		key = String.fromCharCode(whichCode); 

		if (strCheck.indexOf(key) == -1) 
			return false; 

		len = fld.value.length; 

		for (i = 0; i < len; i++) 
		if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) 
		break; 

		aux = ''; 

		for (; i < len; i++) 
			if (strCheck.indexOf(fld.value.charAt(i))!=-1) 
				aux += fld.value.charAt(i); 

		aux += key; 
		len = aux.length; 

		if (len == 0) 
			fld.value = ''; 

		if (len == 1) 
			fld.value = '0'+ decSep + '0' + aux; 

		if (len == 2) 
			fld.value = '0'+ decSep + aux; 

		if (len > 2){ 
			aux2 = ''; 

		for (j = 0, i = len - 3; i >= 0; i--){ 
			if (j == 3){ 
				aux2 += milSep; 
				j = 0; 
			} 
			aux2 += aux.charAt(i); 
			j++; 
		} 

		fld.value = ''; 
		len2 = aux2.length; 

		for (i = len2 - 1; i >= 0; i--) 
			fld.value += aux2.charAt(i); 
		fld.value += decSep + aux.substr(len - 2, len); 
	} 

	return false; 

	} 
	else 
	{
		if (e.keyCod != 8) { // backspace
			e.keyCode = 0;
		}
	}
}



// Função de mascara e bloqueio de teclas não numéricas
function formata(valor)
{
	if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
	{ 
		if (document.getElementById(valor).value.length == 2 || document.getElementById(valor).value.length == 5 ){
			document.getElementById(valor).value += "/";
		}	
	}
	else {
		if (window.event.keyCod != 8) { // backspace
			window.event.keyCode = 0;
			alert("Utilize apenas números!");
		}
	}
}



function enviando(tipo) {
	this.document.getElementById('btnEnviar').value="Aguarde um instante...";
	this.document.getElementById('btnEnviar').disabled="true";
}

function combourl(url){
	window.location=url;
}



function gerarswf(arquivo,largura,altura,id){
    document.writeln('    <object id="globalnav-object" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + largura + '" height="' + altura + '" id="' + id + '" name="' + id + '">');
    document.writeln('        <param name="movie" value="' + arquivo + '" />');
    document.writeln('        <param name="FlashVars" value="loc=en_US&htmlApp=false&gatewayURL=gwurl" />');
    document.writeln('        <param name="menu" value="false" />');
    document.writeln('        <param name="quality" value="high" />');
    document.writeln('        <param name="salign" value="tl" />');
    document.writeln('        <param name="scale" value="noscale" />');
    document.writeln('        <param name="wmode" value="transparent" />');
    document.writeln('        <embed id="globalnav-embed" src="' + arquivo + '" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" flashvars="loc=en_US&htmlApp=false&gatewayURL=gwurl" bgcolor="#ffffff" menu="false" quality="high" salign="tl" scale="noscale" id="' + id + '" width="' + largura + '" height="' + altura + '"></embed>');
    document.writeln('    </object>');
}