function fncArraySearch(arrName,strSearch){ // case sensitive
	for(var a=0;a<arrName.length;a++){ if(arrName[a]==strSearch){ return a; } }
	return -1;
}
function fncFilterKey(objEvent,optFiltra){ // use: onKeyDown="return fncAcceptNumbers(event);"
	// filtra através do código da tecla apertada
	arrAccessKeys=new Array(8,9,13,46,16,33,34,35,36,37,38,39,40,116); // + tab + enter
	switch(optFiltra){
	case 2: // email
		arrNumbers=new Array(48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105);
		arrLetters=new Array(65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90);
		arrPontuacao=new Array(189,109,190,194); // chars: - (num -) . (num .)
		arrAllowed=arrAccessKeys.concat(arrNumbers).concat(arrLetters).concat(arrPontuacao);
		break;
	case 3: // moeda com virgula
		arrNumbers=new Array(48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105);
		arrPontuacao=new Array(188,110); // chars: , (num ,)
		arrAllowed=arrAccessKeys.concat(arrNumbers).concat(arrPontuacao);
		break;
	default: // numbers
		arrNumbers=new Array(48,49,50,51,52,53,54,55,56,57,96,97,98,99,100,101,102,103,104,105);
		arrAllowed=arrAccessKeys.concat(arrNumbers);
	}
	
	numEventKey=(objEvent.which)?objEvent.which:objEvent.keyCode;
	//alert(numEventKey);
	if(fncArraySearch(arrAllowed,numEventKey)==-1){ return false; }
}

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+="/"; }
	}
}

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);
		}
	}
}





function fncFlash(){
	theObjects = document.getElementsByTagName("object");
	for(i=0; i<theObjects.length; i++){ theObjects[i].outerHTML=theObjects[i].outerHTML; }
}






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=800,height=500,top=0,left=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1");
}







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 posição 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;
	}
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// 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;
}









