
// BROWSER DETECT
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();











// FUNCOES UTEIS

// busca em array (case sensitive)
function fncArraySearch(arrName,strSearch){
	for(var a=0;a<arrName.length;a++){ if(arrName[a]==strSearch){ return a; } }
	return -1;
}

// retorna um objeto pelo ID
function getObj(objID){
	if(document.getElementById){ return document.getElementById(objID); }
	else if(document.all){ return document.all[objID]; }
	else if(document.layers){ return document.layers[objID]; }
	return false;
}

// retorna a posio absoluta de um objeto, em pixels (left,top)
function getPos(objID) {
	if(typeof(objID.offsetParent)!="undefined"){
		for(var posX=0, posY=0; objID; objID=objID.offsetParent ){
			posX += Number(objID.offsetLeft);
			posY += Number(objID.offsetTop);
		}
		return [parseInt(posX),parseInt(posY)];
	}else{
		return [parseInt(objID.x),parseInt(objID.y)];
	}
}

// verifica se obj1  filho de obj2
function isChild(obj1,obj2){
	while(obj1){
		if(obj1==obj2){ return true; }
		obj1=obj1.parentNode;
	}
	return false;
}

// adiciona um eventHandler a um objeto
function addEventHandler(object,eventName,functionName){
	if(object.attachEvent){
		object.attachEvent("on" + eventName, functionName);
	}else if(object.addEventListener){
		object.addEventListener(eventName, functionName, true);
	}else{
		object["on" + eventName] = functionName;
	}
}

// remove um eventHandler de um objeto
function removeEventHandler(object,eventName,functionName){
	if(object.detachEvent){
		object.detachEvent("on" + eventName, functionName);
	}else if(object.removeEventListener){
		object.removeEventListener(eventName, functionName, true);
	}else{
		object["on" + eventName] = null;
	}
}

//
// getObjSize()
// Returns array with object width and height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getObjSize(objTarget){
	arrayObjSize = new Array(0,0);
	if(objTarget){ arrayObjSize = new Array(objTarget.offsetWidth,objTarget.offsetHeight); }
	return arrayObjSize;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	var xScroll, yScroll;
	if(window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}else if(document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}else if (document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // repete
		xScroll = document.documentElement.scrollWidth;
		yScroll = document.documentElement.scrollHeight;
	}else{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if(self.innerHeight){	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body){ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){ pageHeight = windowHeight; }else{ pageHeight = yScroll; }
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){ pageWidth = windowWidth; }else{ pageWidth = xScroll; }
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){
	var xScroll, yScroll;
	if(self.pageYOffset){
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}else if(document.documentElement && document.documentElement.scrollTop){ // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	}else if (document.body){ // all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

//
// getMousePosition()
// Returns array with x,y mouse position values.
// Core code from - quirksmode.org
//
function getMousePosition(e){
	var posx=0, posy=0;
	if(!e){ var e = window.event; }
	if(e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	}else if(e.clientX || e.clientY){
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	arrayMousePosition = new Array(posx,posy);
	return arrayMousePosition;
}

// mostra/esconde os campos tipo SELECT (apenas no IE)
function fncSHSelects(strShowHide){
	if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7)){
		switch(strShowHide){
		case "hidden": strShowHide="hidden"; break;
		case false: strShowHide="hidden"; break;
		case 0: strShowHide="hidden"; break;
		default: strShowHide="visible";
		}
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) { selects[i].style.visibility = strShowHide; }
	}
}

//
//  Returns the caret (cursor) position of the specified text field.
//  Return value range is 0-oField.length.
//
function fncGetTextCaretPos(objInput){
	var numPosIni=0, numPosEnd=0;
	// IE Support
	if(document.selection){ 
		objInput.focus(); // Set focus on the element
		var objSel = document.selection.createRange(); // To get cursor position, get empty selection range
		numLenSelect = objSel.text.length;
		objSel.moveStart("character", -objInput.value.length); // Move selection start to 0 position
		numPosEnd = objSel.text.length; // The caret position is selection length
		numPosIni = numPosEnd - numLenSelect;
	}
	// Firefox support
	else if(objInput.selectionStart || objInput.selectionStart=="0"){
		numPosIni = objInput.selectionStart;
		numPosEnd = objInput.selectionEnd;
	}
	return [numPosIni,numPosEnd];
}


//
//  Sets the caret (cursor) position of the specified text field.
//  Valid positions are 0-oField.length.
//
function fncSetTextCaretPos(objInput,numPosIni,numPosEnd){
	if(!isNaN(numPosIni)&&!isNaN(numPosEnd)){
		if(objInput.createTextRange){
			var objSel = objInput.createTextRange();
			objSel.collapse(true);
			objSel.moveStart("character", numPosIni);
			objSel.moveEnd("character", numPosEnd-numPosIni);
			objSel.select();
		}
		else if(objInput.setSelectionRange){
			objInput.focus();
			objInput.setSelectionRange(numPosIni,numPosEnd);
		}
	}
}

// insere uma string na posicao do cursor
function fncInsertAtCursor(myField,myValue){
	//IE support
	if(document.selection){
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if(myField.selectionStart || myField.selectionStart == '0'){
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0,startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

// funcao para PADDING 
var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;

function pad(str,len,pad,dir){
	if(typeof(len)=="undefined"){ var len=0; }
	if(typeof(pad)=="undefined"){ var pad=" "; }
	if(typeof(dir)=="undefined"){ var dir=STR_PAD_RIGHT; }
	
	if(len+1 >= str.length){
		switch(dir){
		case STR_PAD_LEFT:
			str=Array(len+1 - str.length).join(pad) + str;
			break;
			
		case STR_PAD_BOTH:
			var right = Math.ceil((padlen = len - str.length) / 2);
			var left = padlen - right;
			str=Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;
		
		default:
			str=str + Array(len + 1 - str.length).join(pad);
			break;
		}
	}
	
	return str;
}

// arredondamento com casas decimais
if(!Number.toFixed){
	Number.prototype.toFixed=function(x){
		var temp=this;
		temp=Math.round(temp*Math.pow(10,x))/Math.pow(10,x);
		return temp;
	};
}
Number.prototype.toFixedUp=function(x){
	var temp=this;
	temp=Math.ceil(temp*Math.pow(10,x))/Math.pow(10,x);
	return temp;
};
Number.prototype.toFixedDown=function(x){
	var temp=this;
	temp=Math.floor(temp*Math.pow(10,x))/Math.pow(10,x);
	return temp;
};

// formata numero
function number_format(number, decimals, dec_point, thousands_sep){
	// Formats a number with grouped thousands
	//
	// version: 906.1806
	// discuss at: http://phpjs.org/functions/number_format
	// +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
	// +     bugfix by: Michael White (http://getsprink.com)
	// +     bugfix by: Benjamin Lupton
	// +     bugfix by: Allan Jensen (http://www.winternet.no)
	// +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
	// +     bugfix by: Howard Yeend
	// +    revised by: Luke Smith (http://lucassmith.name)
	// +     bugfix by: Diogo Resende
	// +     bugfix by: Rival
	// +     input by: Kheang Hok Chin (http://www.distantia.ca/)
	// +     improved by: davook
	// +     improved by: Brett Zamir (http://brett-zamir.me)
	// +     input by: Jay Klehr
	// +     improved by: Brett Zamir (http://brett-zamir.me)
	// +     input by: Amir Habibi (http://www.residence-mixte.com/)
	// +     bugfix by: Brett Zamir (http://brett-zamir.me)
	// *     example 1: number_format(1234.56);
	// *     returns 1: '1,235'
	// *     example 2: number_format(1234.56, 2, ',', ' ');
	// *     returns 2: '1 234,56'
	// *     example 3: number_format(1234.5678, 2, '.', '');
	// *     returns 3: '1234.57'
	// *     example 4: number_format(67, 2, ',', '.');
	// *     returns 4: '67,00'
	// *     example 5: number_format(1000);
	// *     returns 5: '1,000'
	// *     example 6: number_format(67.311, 2);
	// *     returns 6: '67.31'
	// *     example 7: number_format(1000.55, 1);
	// *     returns 7: '1,000.6'
	// *     example 8: number_format(67000, 5, ',', '.');
	// *     returns 8: '67.000,00000'
	// *     example 9: number_format(0.9, 0);
	// *     returns 9: '1'
	// *     example 10: number_format('1.20', 2);
	// *     returns 10: '1.20'
	// *     example 11: number_format('1.20', 4);
	// *     returns 11: '1.2000'
	// *     example 12: number_format('1.2000', 3);
	// *     returns 12: '1.200'
	var n = number, prec = decimals;
	
	var toFixedFix = function (n,prec) {
		var k = Math.pow(10,prec);
		return (Math.round(n*k)/k).toString();
	};
	
	n = !isFinite(+n) ? 0 : +n;
	prec = !isFinite(+prec) ? 0 : Math.abs(prec);
	var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
	var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
	
	var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
	
	var abs = toFixedFix(Math.abs(n), prec);
	var _, i;
	
	if (abs >= 1000) {
		_ = abs.split(/\D/);
		i = _[0].length % 3 || 3;
	
		_[0] = s.slice(0,i + (n < 0)) +
			  _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
		s = _.join(dec);
	} else {
		s = s.replace('.', dec);
	}
	
	var decPos = s.indexOf(dec);
	if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
		s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
	}
	else if (prec >= 1 && decPos === -1) {
		s += dec+new Array(prec).join(0)+'0';
	}
	return s;
}








// ##################################################
// ##################################################
// ##################################################











// HINTBOX

// cria e mostra um quadro (div) de ajuda/mensagem
function fncShowHintBox(numSize,strTexto){
	objBody = document.body;
	if(getObj("d_hint_box")){
		hintBox = getObj("d_hint_box");
	}else{
		hintBox = document.createElement("div");
		hintBox.setAttribute("id","d_hint_box");
	}
	if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7)){
		// utiliza IFRAME para enganar o z-index das SELECTs, apenas IE<7
		if(getObj("d_hint_box_if")){
			hintBoxIf = getObj("d_hint_box_if");
		}else{
			hintBoxIf = document.createElement("iframe");
			hintBoxIf.setAttribute("id","d_hint_box_if");
			hintBoxIf.setAttribute("src","javascript:'<html></html>';");
			hintBoxIf.setAttribute("frameborder","0");
			hintBoxIf.setAttribute("scrolling","no");
		}
		objBody.appendChild(hintBoxIf);
	}
	objBody.appendChild(hintBox);
	hintBox.innerHTML = strTexto;
	
	if(isNaN(numSize)){ numSize=170; }
	if(numSize==0){ numSize=170; }
	if(numSize>2000){ numSize=2000; }
	if(numSize<100){ numSize=100; }
	hintBox.style.width = numSize+"px";
	hintBox.style.position = "absolute";
	hintBox.style.top = hintBox.style.left = "-5000px";
	hintBox.style.display = "block";
	hintBox.style.zIndex = "10000";
	
	if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7)){
		arrHintBoxSize=getObjSize(hintBox);
		hintBoxIf.style.width = arrHintBoxSize[0]+"px";
		hintBoxIf.style.height = arrHintBoxSize[1]+"px";
		hintBoxIf.style.position = "absolute";
		hintBoxIf.style.top = hintBoxIf.style.left = "-5000px";
		hintBoxIf.style.display = "block";
		hintBoxIf.style.zIndex = "10000";
	}
	
	//fncSHSelects(0);
	addEventHandler(document,"mousemove",fncMoveHintBox);
}

// move o quadro de ajuda/mensagem conforme o mouse
function fncMoveHintBox(e){
	hintBox = getObj("d_hint_box");
	
	arrOSize=getObjSize(hintBox); // object size
	arrPSize=getPageSize(); // page size
	arrPScroll=getPageScroll(); // scroll size
	arrMPos=getMousePosition(e); // posicao do mouse
	
	pSizeW=arrPSize[2]+arrPScroll[0];
	pSizeY=arrPSize[3]+arrPScroll[1];
	sSizeY=arrPScroll[1];
	
	posX=Number(arrMPos[0])+20;
	posY=Number(arrMPos[1])-(arrOSize[1]/10)-5;
	
	if((posX+arrOSize[0]+10)>pSizeW){ posX-=arrOSize[0]+35; } // move o box para o lado esquerdo caso nao haja espaco do lado direito
	if((posY+arrOSize[1]+5)>pSizeY){ posY=pSizeY-arrOSize[1]-5; } // nao deixa o box sumir para baixo da tela (evita rolagem)
	if(posY<arrPScroll[1]+5){ posY=sSizeY+5; } // nao deixa o box sumir para cima da tela (evita rolagem)
	if(posX<5){ posX=5; }
	if(posY<5){ posY=5; }
	
	hintBox.style.left = posX+"px";
	hintBox.style.top = posY+"px";
	
	if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7)){
		hintBoxIf = getObj("d_hint_box_if");
		hintBoxIf.style.left = posX+"px";
		hintBoxIf.style.top = posY+"px";
	}
}

// esconde o quadro de ajuda/mensagem
function fncHideHintBox(){
	hintBox = getObj("d_hint_box");
	if(hintBox){
		hintBox.innerHTML = "";
		hintBox.style.display = "none";
		hintBox = null;
	}
	if((BrowserDetect.browser=="Explorer")&&(BrowserDetect.version<7)){
		hintBoxIf = getObj("d_hint_box_if");
		if(hintBoxIf){
			hintBoxIf.style.display = "none";
			hintBoxIf = null;
		}
	}
	
	//fncSHSelects(1);
	removeEventHandler(document,"mousemove",fncMoveHintBox);
}










// ##################################################
// ##################################################
// ##################################################










// VALIDACOES, FILTROS E FORMATACOES DE ENTRADAS DE DADOS

// filtra conteudo de campos de livre digitacao
function fncFilterInit(objTarget,optFiltra){ // use: onFocus="fncFilterKey(this,1);"
	fncFilterChar(objTarget,optFiltra,true);
	addEventHandler(objTarget,"keyup",function(){ fncFilterChar(objTarget,optFiltra,true); });
	addEventHandler(objTarget,"blur",function(){ fncFilterChar(objTarget,optFiltra,false); });
}
function fncFilterChar(objTarget,optFiltra,moveCaret){
	if(objTarget){
		if(moveCaret){ // mantem o cursor na mesma posicao
			var arrCaretPos = fncGetTextCaretPos(objTarget);
			var numLength = objTarget.value.length;
		}
		
		switch(optFiltra){
		case 2: // email
			rExp = /[^0-9a-z@\._-]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /@{2,}/g; objTarget.value = objTarget.value.replace(rExp,"@"); // substitui 2 ou mais @ por apenas 1
			rExp = /\.{2,}/g; objTarget.value = objTarget.value.replace(rExp,"."); // substitui 2 ou mais . por apenas 1
			rExp = /-{2,}/g; objTarget.value = objTarget.value.replace(rExp,"-"); // substitui 2 ou mais - por apenas 1
			break;
		case 3: // data (numeros e barras)
			rExp = /[^0-9\/]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /\/{2,}/g; objTarget.value = objTarget.value.replace(rExp,"/"); // substitui 2 ou mais / por apenas 1
			break;
		case 4: // moeda (numeros e virgula)
			rExp = /[^0-9,]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /,{2,}/g; objTarget.value = objTarget.value.replace(rExp,","); // substitui 2 ou mais , por apenas 1
			break;
		case 5: // CEP (numeros e traco)
			rExp = /[^0-9-]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /-{2,}/g; objTarget.value = objTarget.value.replace(rExp,"-"); // substitui 2 ou mais - por apenas 1
			break;
		case 6: // CPF (numeros, ponto e traco)
			rExp = /[^0-9\.-]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /\.{2,}/g; objTarget.value = objTarget.value.replace(rExp,"."); // substitui 2 ou mais . por apenas 1
			rExp = /-{2,}/g; objTarget.value = objTarget.value.replace(rExp,"-"); // substitui 2 ou mais - por apenas 1
			break;
		case 7: // CNPJ (numeros, pontos, barra e traco)
			rExp = /[^0-9\.\/-]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /\.{2,}/g; objTarget.value = objTarget.value.replace(rExp,"."); // substitui 2 ou mais . por apenas 1
			rExp = /-{2,}/g; objTarget.value = objTarget.value.replace(rExp,"-"); // substitui 2 ou mais - por apenas 1
			rExp = /\/{2,}/g; objTarget.value = objTarget.value.replace(rExp,"/"); // substitui 2 ou mais / por apenas 1
			break;
		case 8: // moeda americana (numeros e ponto)
			rExp = /[^0-9\.]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /\.{2,}/g; objTarget.value = objTarget.value.replace(rExp,"."); // substitui 2 ou mais . por apenas 1
			break;
		case 9: // moeda completa (numeros, ponto e virgula)
			rExp = /[^0-9\.,]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /\.{2,}/g; objTarget.value = objTarget.value.replace(rExp,"."); // substitui 2 ou mais . por apenas 1
			rExp = /,{2,}/g; objTarget.value = objTarget.value.replace(rExp,","); // substitui 2 ou mais , por apenas 1
			break;
		case 10: // telefone (numeros, traco e espaco)
			rExp = /[^0-9 -]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /\-{2,}/g; objTarget.value = objTarget.value.replace(rExp,"-"); // substitui 2 ou mais - por apenas 1
			rExp = / {2,}/g; objTarget.value = objTarget.value.replace(rExp," "); // substitui 2 ou mais espacos por apenas 1
			break;
		case 11: // cor hexadecimal (numeros e #)
			rExp = /[^0-9A-Fa-f#]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
			rExp = /#{2,}/g; objTarget.value = objTarget.value.replace(rExp,"#"); // substitui 2 ou mais # por apenas 1
			break;
		default: // numeros
			rExp = /[^0-9]/g;
			objTarget.value = objTarget.value.replace(rExp,"");
		}
		
		if(moveCaret){ // mantem o cursor na mesma posicao
			var numOffset = numLength-objTarget.value.length;
			fncSetTextCaretPos(objTarget,arrCaretPos[0]-numOffset,arrCaretPos[1]-numOffset);
		}
	}
}



// remove espacos do comeco e fim da string
function fncTrim(strText){
	return strText.replace(/^\s\s*/,'').replace(/\s\s*$/,'');
}

// formata data dd/mm/aaaa em campo input
function fncFormatDate(objTarget,objEvent){ // use: onKeyDown="fncFormatDate(this,event);"
	arrAccessKeys = new Array(8,46,16,33,34,35,36,37,38,39,40,116); // - tab - enter
	numEventKey=(objEvent.which)?objEvent.which:objEvent.keyCode;
	if(fncArraySearch(arrAccessKeys,numEventKey)==-1){
		if( (objTarget.value.length==2)||(objTarget.value.length==5) ){ objTarget.value+="/"; }
	}
}

// formata moeda 99,99 em campo input
function fncFormatMoney(objTarget,objEvent){ // use: onKeyUp="fncFormatMoney(this,event);"
	arrAccessKeys = new Array(13,16,33,34,35,36,37,38,39,40,116); // - enter
	numEventKey=(objEvent.which)?objEvent.which:objEvent.keyCode;
	if(fncArraySearch(arrAccessKeys,numEventKey)==-1){
		objTarget.value=objTarget.value.replace(",","");
		if(objTarget.value.length>2){
			objTarget.value=objTarget.value.substring(0,objTarget.value.length-2)+","+objTarget.value.substring(objTarget.value.length-2,objTarget.value.length);
		}
	}
}

// funcao maxlength para textarea
function fncMaxlength(objText,numCaract,strCount,strTotal){ // use: onKeyUp="fncContaCaracteres(this,100,'dispCount','dispTotal');"
	if(objText && !isNaN(numCaract)){
		if(objText.value.length>numCaract){ objText.value=objText.value.substr(0,numCaract); }
		
		objTotal=document.getElementById(strTotal);
		if(objTotal){ objTotal.innerHTML=numCaract; }
		
		objCount=document.getElementById(strCount);
		if(objCount){ objCount.innerHTML=objText.value.length; }
	}
}



// swap image
function fncSwapImg(objTarget,strSrc){
	if(objTarget){
		objTarget.lowsrc=objTarget.src;
		objTarget.src=strSrc;
	}
}
// restore image
function fncRestoreImg(objTarget){
	if(objTarget){
		objTarget.src=objTarget.lowsrc;
	}
}










// ##################################################
// ##################################################
// ##################################################










// RETIRA CONFIRMACAO DO FLASH

/*window.onload = function(){
	theObjects = document.getElementsByTagName("object");
	for(i=0; i<theObjects.length; i++){ theObjects[i].outerHTML=theObjects[i].outerHTML; }
}*/










// ##################################################
// ##################################################
// ##################################################










// FUNCOES ADMIN

function fncUploadWindow(strLabel,strCampo,numTipo,numLargura,numAltura,numTamanho,strAntigo){
	window.open("upload_window.php?label="+strLabel+"&campo="+strCampo+"&tipo="+numTipo+"&largura="+numLargura+"&altura="+numAltura+"&tamanho="+numTamanho+"&antigo="+strAntigo,"upload_window","width=450,height=200,top=50,left=50,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0");
}

function fncImagesWindow(strOpt){
	window.open("imagens.php?opt="+strOpt,"images_window","width=920,height=610,top=0,left=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1");
}

function fncFilesWindow(strOpt){
	window.open("arquivos.php?opt="+strOpt,"files_window","width=920,height=610,top=0,left=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1");
}

































