//Desenvolvido por TimeDev - www.timedev.com

/*------------------------------
	TimeDev.Util
	Version 3.0.0.0
	Released in 04/03/2007
------------------------------*/

/*------------------------------
	Object
------------------------------*/
function $tdv(objName)
{
	return document.getElementById(objName);
}


/*------------------------------
	Browser
------------------------------*/
var isIE = false; //Internet Explorer
var isNS = false; //Netscape
var isFF = false; //Firefox


function getBrowser()
{
	isIE = (navigator.appName == "Microsoft Internet Explorer") ? true : false;
	
	if (navigator.appName == "Netscape"){
		isNS = (navigator.userAgent.indexOf("Netscape") != -1) ? true : false;
		isFF = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;		
	}
	
	//alert("Internet Explorer = " + isIE + "\nNetscape = " + isNS + "\nFirefox = " + isFF);
}


/*------------------------------
	Layout
------------------------------*/
//Obsolete
function setLayer(obj, cond)
{
	setVisibility(obj, cond);
}


function setVisibility(obj, cond)
{
	var o = $tdv(obj);
	
	if (o){
		o.style.visibility = (cond) ? "visible" : "hidden";	
	}
}


function setDisplay(obj, cond)
{
	var o = $tdv(obj);
	
	if (o){
		o.style.display = (cond) ? "block" : "none";
	}
}



/*------------------------------
	Popup
------------------------------*/
function setPopup(page, name, width, height)
{
	var	left = (screen.width / 2) - (width / 2) - 2.5;
	var top = (screen.height / 2) - (height / 2);
	var popup = window.open(page, name, "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", toolbar=0, menubar=0, scrollbars=0, location=0, directories=0, status=0, resisable=0");
	popup.focus();
}


function setPopupScroll(page, name, width, height)
{
	var	left = (screen.width / 2) - (width / 2) - 2.5;
	var top = (screen.height / 2) - (height / 2);
	var popup = window.open(page, name, "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", toolbar=0, menubar=0, scrollbars=1, location=0, directories=0, status=0, resisable=0");
	popup.focus();
}


function setPopupPrecise(page, name, width, height, left, top)
{
	var popup = window.open(page, name, "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", toolbar=0, menubar=0, scrollbars=0, location=0, directories=0, status=0, resisable=0");
	popup.focus();
}


function setPopupFull(page)
{
	var popup = window.open(page, "Full", "windowmode=fullwindow, fullscreen=yes");
	popup.focus();
}


function setPopupBars(page, name)
{
	var width = 796;
	var height = 476;
	var	left = (screen.width / 2) - (width / 2) - 2.5;
	var top = (screen.height / 2) - (height / 2);
	var popup = window.open(page, name, "width=" + width + ", height=" + height + ", left=" + left + ", top=" + top + ", location=no, scrollbars=yes, menubar=yes, toolbar=no, directories=no, status=yes, resizable=yes");
	popup.focus();
}


function setSizeFromImage(image)
{
	var img = document.getElementById(image);
	
	if (img){ //if exists
		getBrowser();

		if (isIE){
			window.resizeTo(img.width + 10, img.height + 72);
		}
		
		if (isFF){
			window.resizeTo(img.width + 6, img.height + 51);
		}
		
		if (isNS){
			window.innerWidth = img.width;
			window.innerHeight = img.height;
		}
		
		//Move the windows
		var	left = (screen.width / 2) - (img.width / 2) - 2.5;
		var top = (screen.height / 2) - (img.height / 2);
		window.moveTo(left, top);
	} //if exists
}



/*------------------------------
	Image
------------------------------*/
function setPreLoadImages()
{
  var d = document; 
	
	if (d.images){
		if (!d.param){
			d.param = new Array();
		}
		
		var j = d.param.length;
		var a = setPreLoadImages.arguments; 
		
		for(var i = 0; i < a.length; i++){
	    if (a[i].indexOf("#") != 0){
				d.param[j] = new Image;
				d.param[j++].src = a[i];
			}
		}
	}
}


function setImage(image, file)
{
	var img = $tdv(image);
	
	if (img){
		img.src = file;
		//alert(file);
	}
}



/*------------------------------
	Flash
------------------------------*/
/*
function setFlash(flash, frame)
{
	var f = eval(dca + flash);

	if (f){
		if (f.PercentLoaded() == 100){
			frame = parseInt(frame);

			if (!isNaN(frame)){
				f.GoToFrame((frame - 1));
				f.Play();
        return true;
			}
		}else{
			setTimeout('setFlash("' + flash + '", ' + frame + ');', 1000);
		}
	}
}
*/



/*------------------------------
	Text
------------------------------*/
function trim(text)
{
	text = text.toString();
	
	var textSize = text.length;

	// Retira espaços do começo da string
	var begin = text.indexOf(" ");
	while (begin == 0){
		text = text.substr(begin + 1);
		begin = text.indexOf(" ");
		textSize = textSize - 1;
	}
	
	// Retira espaços do fim da string
	var end = text.lastIndexOf(" ");
	while (end == textSize - 1){
		text = text.substring(0, textSize - 1);
		end = text.lastIndexOf(" ");
		textSize = textSize - 1;
	}
	
	return text;
}



/*------------------------------
	Forms
------------------------------*/
//Usage: onKeyPress="getEnter(event); return getReturn();"
//setCustomEnter: custom function
var returnEnter = true;


function getReturn()
{
	return returnEnter;
}


function getEnter(evt)
{

	if (evt){
		if (evt.keyCode == 13){
			returnEnter = false;
			setCustomEnter();
		}else{
			returnEnter = true;
		}
	}
}


function setAction(action)
{
	var f = document.forms[0];
	
	if (f){
		f.action = action;
	}
}

