/**
 * Retorna as janelas padrões do sistema de lightbox
 * 
 * @author Rafael R. Noronha <rafael.noronha@addcomm.com.br>
 * @since 06/09/2007
 * @return array
 */
function getCoreWnd() {
	wnd = new Array();
	wnd[0] = 'lb-lock';
	wnd[1] = 'lb-sm';
	return wnd;
}

/**
 * Esconde todas as janelas
 * 
 * @author Rafael R. Noronha <rafael.noronha@addcomm.com.br>
 * @since 20/08/2007
 * @return void
 */
function clearWindow(){
	wnd = getCoreWnd();
	// -------------------------
	// Limpa as janelas basicas
	// -------------------------
	for(i=0;i<wnd.length;i++)
		$(wnd[i]).style.display = "none";
	// ------------------
	// Show/Hide selects
	// ------------------
	flip();
}
/**
 * Muda o estado das selects de uma pagina
 * 
 * @author Rafael R. Noronha <rafael.noronha@addcomm.com.br>
 * @since 20/08/2007
 * @return void
 */
function flip(){
	selects = document.getElementsByTagName("select");
	for (i=0; i!=selects.length;i++)
		selects[i].style.visibility = (selects[i].style.visibility == "hidden") ? "visible" : "hidden";
}

/**
 * Cria e mostra janela de aviso
 * 
 * @param {Object} obj
 * @param {Object} overlayClick
 * @since 20/08/2007
 * @author Rafael R. Noronha <rafael.noronha@addcomm.com.br>
 * @return void
 */
function callWindow(obj, overlayClick){
	// --------------------------
	// Pega resolucao do browser
	// --------------------------
	arrayPageSize = getPageSize();
	// ------------
	// Cria janela
	// ------------
	http.open("GET", obj + '.html', true);
    http.onreadystatechange = function() {
            if (http.readyState == 4) {
				$('lb-sm').innerHTML = http.responseText;
				// ------------------
				// Show/Hide selects
				// ------------------
				flip();	
				$(obj).style.zIndex = 1000;
				$(obj).style.display = "block";
				$('lb-sm').style.display = "block";
				lock = $('lb-lock');
				lock.style.height 	= arrayPageSize[1] + 'px';
				lock.style.width 	= arrayPageSize[0] + 'px';
				lock.style.display 	= "block";
				lock.onclick = (overlayClick) ? clearWindow : '';
			}
    };
    http.send(null);
}

/**
 * Funcao que retorna o objeto do id
 * 
 * @since 21/08/2007
 * @author Rafael R. Noronha <rafael.noronha@addcomm.com.br>
 * @return obj
 */
function $() {
	var elements = new Array();
	for (var i=0;i<arguments.length;i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

/**
 * Cria objeto HTTPRequest
 * 
 * @return object
 */
function getHTTPObject() {
        var xmlhttp;
        /*@cc_on
        @if (@_jscript_version >= 5)
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (e) {
            xmlhttp = false;
          }
        }
        @else
        xmlhttp = false;
        @end @*/
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                try {
                        xmlhttp = new XMLHttpRequest();
                } catch (e) {
                      xmlhttp = false;
                }
        }
        return xmlhttp;
}
var http = getHTTPObject();


/**
 * Pega informacoes de resolucao do browser
 * 
 * @return array
 */
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 { // 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.availWidth;
		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;
}