function txtBoxFormat(strField, sMask, evtKeyPress) {
	/*
	* Descrição.: formata um campo do formulário de
	* acordo com a máscara informada...
	* Parâmetros: - objForm (o Objeto Form)
	* - strField (string contendo o nome
	* do textbox)
	* - sMask (mascara que define o
	* formato que o dado será apresentado,
	* usando o algarismo "9" para
	* definir números e o símbolo "!" para
	* qualquer caracter...
	* - evtKeyPress (evento)
	* Uso.......: <input type="textbox"
	* name="xxx".....
	* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
	* Observação: As máscaras podem ser representadas como os exemplos abaixo:
	* CEP -> 99.999-999
	* CPF -> 999.999.999-99
	* CNPJ -> 99.999.999/9999-99
	* Data -> 99/99/9999
	* Tel Resid -> (99) 999-9999
	* Tel Cel -> (99) 9999-9999
	* Processo -> 99.999999999/999-99
	* C/C -> 999999-!
	* E por aí vai...
	*/
		
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	
	
	if(window.event) { // Internet Explorer
		nTecla = evtKeyPress.keyCode; }
	else if(evtKeyPress.which) { // Nestcape / firefox
		nTecla = evtKeyPress.which;
	}
	
	//se for backspace não faz nada
	if (nTecla != 8){
		sValue = document.getElementById(strField).value;
		// alert(sValue);
		// Limpa todos os caracteres de formatação que
		// já estiverem no campo.
		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( " ", "" );
		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) == "/") || (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++;
		}
		
		if(nTecla<=58 && nTecla>=47){
			document.getElementById(strField).value = sCod;
			var limpa=1
		}else{
			alert('Valor digitado é inválido');
			document.getElementById(strField).value = '';
			var limpa=0
		}
		
		if (nTecla != 8) { // backspace
			if (sMask.charAt(i-1) == "9") { // apenas números...
				return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
			else { // qualquer caracter...
				return true;
			}
		}else {
			return true;
		}
	}//fim do if que verifica se é backspace
}

function isNum(event){
	var nTecla;
	if(window.event) { // Internet Explorer
	  nTecla = event.keyCode; }
	else if(event.which) { // Nestcape / firefox
	  nTecla = event.which;
	}

	if ((nTecla >= 48 && nTecla<=57)||(nTecla==44)){
		event.returnValue = true;
	}else{
		event.returnValue = false;
	}
}

function editaExcluiCRUD(acao,action,valor,form,flag_confirmacao){
	var aux;
	var aux2;
	var aux3;
	var continua = false;
	if (flag_confirmacao){
		if (confirm("Deseja realmente executar a ação? [Ação: "+acao+"]")) {
			continua = true;
		} else {
			continua = false;
		}
	} else {
		continua = true;
	}
	
	if (continua) {
		if(action!=""){
			form.action = form.mod.value+"/"+form.crud.value+".html";
			form.target = "";
		}
		if (acao == 'detalhe'){
			form.pagina.value = "publicas/"+form.crud.value+"Detalhe.php";
		}
		form.acao.value = acao;
		//alert(acao+" - "+action+" - "+valor+" - "+form+" - "+flag_confirmacao);
		aux = valor.split("#");
		for(x=0;x<(aux.length);x++){
			aux2 = aux[x].split("%");
			aux3 = aux2[0];
			if (aux3!=""){
				document.getElementById(aux3).value = aux2[1];
			}
		}
		form.submit();
	}
}

function insRow_resp(){
	var nRows = document.getElementById('tb_resposta').rows.length;
	var x=document.getElementById('tb_resposta').insertRow(nRows);
	var x1=x.insertCell(0);
	var x2=x.insertCell(1);
	x1.innerHTML="<b>Resposta:</b>";
	x2.innerHTML="<input type='text' style='width:70%;' name='resposta[]' value=''><img src='imagens/icones/remove.gif' style='cursor:hand;' onclick='deleteRow_resp(this);' />";
}
function deleteRow_resp(r){
	var i=r.parentNode.parentNode.rowIndex
	document.getElementById('tb_resposta').deleteRow(i)
}

	function data(){
		vDay = new Date();
		datatual = vDay.getDay();
		if(datatual==0) strdata = "Domingo, ";
		if(datatual==1) strdata = "Segunda-feira, ";
		if(datatual==2) strdata = "Terça-feira, ";
		if(datatual==3) strdata = "Quarta-feira, ";
		if(datatual==4) strdata = "Quinta-feira, ";
		if(datatual==5) strdata = "Sexta-feira, ";
		if(datatual==6) strdata = "Sábado, ";
		vMes = vDay.getMonth()
		if(vMes==0) strmes = "Janeiro ";
		if(vMes==1) strmes = "Fevereiro ";
		if(vMes==2) strmes = "Março ";
		if(vMes==3) strmes = "Abril ";
		if(vMes==4) strmes = "Maio ";
		if(vMes==5) strmes = "Junho ";
		if(vMes==6) strmes = "Julho ";
		if(vMes==7) strmes = "Agosto ";
		if(vMes==8) strmes = "Setembro ";
		if(vMes==9) strmes = "Outubro ";
		if(vMes==10) strmes = "Novembro ";
		if(vMes==11) strmes = "Dezembro ";
		strlinha = "" + strdata + vDay.getDate()+ " de " + strmes + " de " + vDay.getYear();
		document.write("" + strlinha + "&nbsp;&nbsp;&nbsp;");
}	


/************************************************************************************************************/
/***************************************MASCARAS DE VALORES  PARA FORMULARIOS********************************/
/************************************************************************************************************/
function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function soNumeros(v){
    return v.replace(/\D/g,"")
}

function dataM(v){
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/(\d{2})(\d)/,"$1/$2") //Coloca barra entre o segundo e o terceiro digito
	v=v.replace(/(\d{2})(\d)/,"$1/$2") //Coloca barra entre o quinto e o sexto digito
	return v
}
function money(v){
	v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
	v=v.replace(/(\d)(\d{2})$/,"$1,$2") //Coloca ponto antes dos 2 últimos digitos
	return v
}

function telefone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function romanos(v){
    v=v.toUpperCase()             //Maiúsculas
    v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M
    //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html
    while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
        v=v.replace(/.$/,"")
    return v
}

function site(v){
    //Esse sem comentarios para que você entenda sozinho ;-)
    v=v.replace(/^http:\/\/?/,"")
    dominio=v
    caminho=""
    if(v.indexOf("/")>-1)
        dominio=v.split("/")[0]
        caminho=v.replace(/[^\/]*/,"")
    dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
    caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
    caminho=caminho.replace(/([\?&])=/,"$1")
    if(caminho!="")dominio=dominio.replace(/\.+$/,"")
    v="http://"+dominio+caminho
    return v
}


/************************************************************************************************************/
/*********************************************VALIDAR CAMPO DATA E HORA**************************************/
/************************************************************************************************************/
//mascada data hora => 12/12/1979 12:10
function filtroDataHora(campo,event){
	if(navigator.appName.indexOf("Netscape")!= -1) tecla = event.which;
	else tecla = event.keyCode;

	if (tecla != 9 && tecla != 8 && tecla != 47){
		if(campo.value.length==2) campo.value+="/";
		if(campo.value.length==5) campo.value+="/";
		if(campo.value.length==10) campo.value+=" ";
		if(campo.value.length==13) campo.value+=":";
	}
}


/*valida se a data e valida*/
function doDate(pStr){
    var bissexto = 0;
    var data = pStr; 
    var tam = data.length;
    if (tam == 10){
        var dia = data.substr(0,2)
        var mes = data.substr(3,2)
        var ano = data.substr(6,4)
        if ((ano > 1900)||(ano < 2100)){
            switch (mes){
                case '01':
                case '03':
                case '05':
                case '07':
                case '08':
                case '10':
                case '12':
                    if  (dia <= 31){ return true; }
                    break
                
                case '04':        
                case '06':
                case '09':
                case '11':
                    if  (dia <= 30){ return true; }
                    break
                case '02':
                    /* Validando ano Bissexto / fevereiro / dia */ 
                    if ((ano % 4 == 0) || (ano % 100 == 0) || (ano % 400 == 0)){ bissexto = 1; } 
                    if ((bissexto == 1) && (dia <= 29)){ return true; } 
                    if ((bissexto != 1) && (dia <= 28)){ return true; }            
                    break                        
            }
        }
    }    
    return false;
}

/*valida se a hora e valida*/
function doHora(pStr) {
    var hora = pStr.split(":");
	if (hora.length > 1){
		if (hora[0] > 24 || hora[0] < 0 || hora[1] > 60 || hora[1] < 0 ){
			return false;
		} else {
			return true;
		}
	} else {
		return false;
	}
}

/*pega campo com data e hora e separa a data da hora*/
function validaDataHora(pStr){
	var dataHora = pStr.value.split(" ");
	if (dataHora.length > 1){
		if ((dataHora[0].length != 10) || (dataHora[1].length != 5)) {
			alert('Formato de data e hora diferente de: [dd/mm/yyyy hh:mm]!');
			pStr.focus();
			return false;
		} else if (!doDate(dataHora[0])){
			alert('Data ['+dataHora[0]+'] inválida!');
			pStr.focus();
			return false;
		} else if (!doHora(dataHora[1])){
			alert('Hora ['+dataHora[1]+'] inválida!');
			pStr.focus();
			return false;
		} else {
			return true;
		}
	} else {
		alert('Formato de data e hora diferente de: [dd/mm/yyyy hh:mm]!');
		return false;
	}
}

/*pega campo com data e hora e separa a data da hora*/
function validaSoData(pStr){
	var dataHora = pStr.value;
	if (dataHora == ""){
		return true;
	} else {
		if ((dataHora.length != 10)) {
			alert('Formato de data diferente de: [dd/mm/yyyy]!');
			pStr.focus();
			return false;
		} else if (!doDate(dataHora)){
			alert('Data ['+dataHora+'] inválida!');
			pStr.focus();
			return false;
		} else {
			return true;
		}
	}
}

function insRow_arq(){
	var nRows = document.getElementById('tb_arquivo').rows.length;
	var x=document.getElementById('tb_arquivo').insertRow(nRows);
	var x1=x.insertCell(0);
    var x2=x.insertCell(1);
	var x3=x.insertCell(2);
	var x4=x.insertCell(3);
	x1.innerHTML="<b>Nome</b>:<br><input class='input_text' type='text' maxlength='100' style='width:98%;' name='descricao[]' value=''>";
	x2.innerHTML="<b>Arquivo</b>:<br><input class='input_text' type='file' style='width:98%;' name='pathNomeArq[]' value=''>";
    x3.innerHTML="<b>Resumo</b>:<br><textarea class='input_text' maxlength='1000' style='width:98%;' name='resumo[]'></textarea>";
	x4.innerHTML="<b>Ativo</b>:<br><input class='input_text' type='checkbox' name='flagAtivo[]'><img src='imagens/icones/remove.gif' style='cursor:pointer;' onclick='deleteRow_arq(this);' />"; 
}
function deleteRow_arq(r){
	var i=r.parentNode.parentNode.rowIndex
	document.getElementById('tb_arquivo').deleteRow(i)
}

function mostraBanner(caminho,valor,link){
	var form = document.contBanner;

	window.open(link, "", "");

	form.idBanner.value = valor;
	form.acao.value = "contaClickBanner";
	form.crud.value = "Banner";
	form.action = caminho+"classes/action/actionAux.php";
	form.target = "johnJohn";
	form.submit();
}