﻿/*---------------------------------
ÚLTIMA ALTERAÇÃO
Data: 24/09/2008 
Quem: Fernando Hamasaki de Amorim
---------------------------------*/


/*------------------------------
	Object
------------------------------*/
function $(objName) {
	return document.getElementById(objName);
}

function doClick(objId)
{
    var obj = $(objId);
    
    if (obj){
        obj.click();
    }else{
        alert("doClick: Objeto com ID " + objId + " não encontrado.     ");
    }
}


/*------------------------------
	Layout
------------------------------*/
function setVisibility(obj, cond)
{
	var o = $(obj);
	
	if (o){
		o.style.visibility = (cond) ? "visible" : "hidden";	
	}
}

function setDisplay(obj, cond, inline)
{
	var o = $(obj);
	
	if (o){
		o.style.display = (cond) ? ((inline) ? "inline" : "block") : "none";
	}
}

function setDisplayRow(obj, cond)
{
	var o = $(obj);
	
	if (o){
	    var isIE = (navigator.appName == "Microsoft Internet Explorer" || navigator.userAgent.indexOf("MSIE") != -1);
		o.style.display = (cond) ? ((isIE) ? "inline" : "table-row") : "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 + 29);
		}
		
		if (isFF){
			window.resizeTo(img.width + 6, img.height + 47);
		}
		
		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 = $(image);
	
	if (img){
		img.src = file;
		//alert(file);
	}
}


/*------------------------------
	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;
}

/*------------------------------
	Botão Alterar
------------------------------*/
function desabilitaBotaoAlterar(acao, obj, image)
{
    if(acao){
        obj.src = image; //disable
        obj.disabled = true; 
        
        document.body.style.cursor = "wait";
        obj.style.cursor = "wait";
        __doPostBack(obj.name, "");
          
        return false;
    }else{
        obj.src = image;
        obj.disabled = false;
        
        document.body.style.cursor = "default";
        obj.style.cursor = "hand";
    }
}