﻿// JScript File
// Function Load Events
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// Abre uma janela centrada
function NewWindow(url, name, width, height, features) {
	var left = 0;
	var top = 0;

	if ( screen.width > width ) {
		left = parseInt( ( screen.width - width ) / 2 );
	} else {
		left = 0;
	}

	if ( screen.height > height ) {
		top = parseInt( ( screen.height - height ) / 2 );
	} else {
		top = 0;
	}

    //alert("url:" + url + "; name:" + name + "; width:" + width + "; height:" + height + "; left:" + left + "; top:" + top + "; features:" + features);

    if(features != null && features.length != 0) {
	    window.open(url, name, 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',' + features);
	} else {
	    window.open(url, name, 'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=auto,left=' + left + ',top=' + top);
	}
}
// Abre uma janela para o chat
function OpenChatWindow(url) {
    var iLeft;
    var iTop;
    var iWidth = 600;
    var iHeight = 500;

    if ( screen.width > iWidth ) {
        iLeft = parseInt( ( screen.width - iWidth ) / 2 );
    } else {
        iLeft = 0
    }

    if ( screen.height > iHeight ) {
        iTop = parseInt( ( screen.height - iHeight ) / 2 );
    } else {
        iTop = 0
    }

    window.open( url, 'Chat', 'width=' + iWidth + ',height=' + iHeight + ', left=' + iLeft + ', top=' + iTop + ", status=1");
}

// Popup Window
function doPopupWindow() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		var sectionId = links[i].getAttribute("href");
		if (links[i].className.match("popup")) {
			links[i].destination = sectionId;
			links[i].onclick = function() {
				NewWindow(this.destination, '', 580, 580, null);
				return false;
			}
		}
	}
}

// Focus Login
function doFocusLogin() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("input");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("firstinput")) {
			links[i].focus();
		}
	}
}

// Window Print
function doPrint() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i < links.length; i++) {
		if (links[i].className.match("print")) {
			links[i].onclick = function() {
				window.print();
				return false;
			}
		}
	}
}

// Show Section FAQs
function showSection(id) {
	var divs = document.getElementsByTagName("dl");
	for (var i=0; i<divs.length; i++ ) {
		if (divs[i].getAttribute("id") == id) {
			divs[i].className = "";
		} if (divs[i].getAttribute("id") != id) {
			divs[i].className = "hide";
		}
	}
}
function prepareInternalnav() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("faqs")) return false;
	var nav = document.getElementById("faqs");
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++ ) {
		var sectionId = links[i].getAttribute("href").split("#")[1];
		if (!document.getElementById(sectionId)) continue;
		document.getElementById(sectionId).className += " hide";
		links[i].destination = sectionId;
		links[i].onclick = function() {
			showSection(this.destination);
			return false;
		}
	}
}

/* ---------------------------- */
// Add Load Event
addLoadEvent(doFocusLogin);
addLoadEvent(doPopupWindow);
addLoadEvent(doPrint);
