﻿var ajaxObjects = new Array();
var ajaxObjectsDelayProtect = new Array();

function trim(str) {
    return str.replace(/^\s*|\s*$/g, "");
}

var is = new function() {
    this.VER = navigator.appVersion
    this.AGENT = navigator.userAgent
    this.DOM = document.getElementById ? 1 : 0
    this.IE = (document.all && !this.DOM) ? 1 : 0;
    this.MAC = this.AGENT.indexOf("Mac") > -1
    this.NS6 = document.getElementById && !document.all ? 1 : 0
    this.NS4 = (document.layers && !this.DOM) ? 1 : 0;
    this.OPERA = this.AGENT.indexOf('Opera') > -1
    return this
}

function getElement(id) {
    if (is.DOM) return document.getElementById(id)
    else
        if (is.IE) return eval("document.all." + id)
    else
        if (is.NS) return eval("document." + id)
}

function toggle_visibility(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'block')
	  e.style.display = 'none';
   else
	  e.style.display = 'block';
}

function show(id) {
    obj = getElement(id);
    obj.style.display = "block";
}

function hide(id) {
    obj = getElement(id);
    obj.style.display = "none";
}


function openWindowCenterHalfTop(url,nome,xx,yy) {
	iwidth = xx;
	iheight = yy; 
	itop = (screen.height/2) - (iheight/2);
	itop = (itop-((screen.height-iheight)/2)/2);
	ileft = (screen.width/2)- (iwidth/2);
	nome = nome + Math.floor(Math.random()*222);
	propriedades = "width=" + iwidth + ",height=" + iheight + ",top=" + itop + ",left=" + ileft + ",scrollbars=yes,toolbar=no,menubar=no,resizable=1,dependent=1,status=1";
	popupWin2 = window.open(url,nome,propriedades);
	try { popupWin2.focus();	}
	catch(e){ alert('Bloqueador de popups encontrado!\nDesactive o mesmo para proceder a operação') }
}

function Imprimir() {
    var a = window.open('', '', 'scrollbars=yes,width=720,height=500');
    a.document.open("text/html");
    a.document.write('<html>\n<head>\n<link rel="stylesheet" href="/css/main.css" media="all" type="text/css" />\n<style>\n.noprint{display:none}\n<\/style>\n</head>\n<body style="background-image:none;background-color:#FFFFFF;">\n');
    a.document.write('<table align="center" width="700" border="0" cellpadding="10" cellspacing="0">\n<tr>\n<td align="left">\n<img align="absmiddle" src="/images/banner_impressao.jpg" border="0" alt="" /><br/><br/>');
    a.document.write('<tr>\n<td>\n');
    a.document.write(document.getElementById('print').innerHTML);
    a.document.write('\n<\/td>\n<\/tr>\n');
    a.document.write('<\/table>\n');
    a.document.write('<\/body>\n<\/html>');
    a.document.close();
    a.print();
}

function set_style(idx, stl) {
    var obj = document.getElementById(idx)
    //alert(obj.className);
    obj.className = stl;
}


function CheckIsIE() {
    if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') { return true; }
    else { return false; }
}

function changeFontSize(element,step)
{
	step = parseInt(step,10);
	var el = document.getElementById(element);
	var curFont = parseInt(el.style.fontSize,10);
	el.style.fontSize = (curFont+step) + 'px';
}

function mostrar_sn() {
    document.getElementById('social_networks').style.display = 'block';
    pos = findPos(document.getElementById("link_social_networks1"));
    pos_x = pos[0];
    document.getElementById("social_networks").style.left = pos_x - 79 + 'px';
    pos_y = pos[1];
    document.getElementById("social_networks").style.top = pos_y - 191 + 'px';
}

function mostrar_sn2(obj)
{
    document.getElementById('social_networks').style.display = 'block';
    pos = findPos(obj);
    pos_x = pos[0];
    document.getElementById('social_networks').style.left =  pos_x+'px';
    pos_y = pos[1];
    document.getElementById('social_networks').style.top = pos_y-30+'px'
}


function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft, curtop];
}

function esconder_sn() {
    getElement('social_networks').style.display = 'none';
}

/* ****/



/*----------------Ajax getContent -------------------*/
function getContent(url,divobj,fnc_completo,params){
	try {
	pageTracker._trackPageview(url);
	} catch(err) {}
	var ajaxIndex = ajaxObjects.length;
	ajaxObjectsDelayProtect[url] = ajaxIndex;
	ajaxObjects[ajaxIndex] = new sack();
	ajaxObjects[ajaxIndex].requestFile = url;
	ajaxObjects[ajaxIndex].encodeURIString = false;
	ajaxObjects[ajaxIndex].onCompletion = function() {showContent(divobj,ajaxIndex,url,fnc_completo);};
	ajaxObjects[ajaxIndex].runAJAX(params);
	showWaitMessage(divobj);
} 

function showWaitMessage(divobj){
	divobj.innerHTML = '<img src="/images/ajax-loader.gif" alt="A carregar dados..." />';
}

function showContent(divobj,index,url,fnc_completo){
	if (ajaxObjectsDelayProtect[url] == index){divobj.innerHTML = ajaxObjects[index].response;	}
	if (fnc_completo)eval(fnc_completo);
}

