/*
 +-------------------------------------------------------------------+
 |                  S C R I P T S - J S   (v2.0)                     |
 |                                                                   |
 | Criado: Set 10, 2009             Última Modificação: Out 28, 2009 |
 +-------------------------------------------------------------------+
 |              Criado por Adriano Chamelet Paladini                 |
 |              adrianopaladini@puc-campinas.edu.br                  |
 +-------------------------------------------------------------------+

======================================================================================================
 Este Script foi testado nos seguintes navegadores:

 - IE 5.5/6/7/8, Firefox 3, Opera 9/10, Safari 3, Chrome 1/2/3

======================================================================================================
*/


/* Variáveis Golbais */
var ModalPastaImg = '/websist/egresso/portalegresso/includes/';
var ModalImgFechar = ModalPastaImg+'close.gif';
var ModalImgAjax = ModalPastaImg+'ajax-loader.gif';
var ModalImgAjaxBkg = ModalPastaImg+'tooltip.png';

var TmpDiv;
/* Variáveis Golbais */


/* Função para abrir URL */
function AbrirModalURL(theURL,width,height,bClose) {
	browser = navigator.userAgent;
	
	var OldIE = false;
	if(browser.indexOf('MSIE')>0){
		if(browser.indexOf('MSIE 8')<1){
			OldIE = true;
		}
	}
	
	
	
	var NovoStyle = document.createStyleSheet();
	
	TmpDiv = false;
	
	if(document.getElementById('PC_Modal_D')) {
		var obj=document.getElementById('PC_Modal_C');
		obj.parentNode.removeChild(obj);
		obj=document.getElementById('PC_Modal_D');
		obj.parentNode.removeChild(obj);
		obj=document.getElementById('PC_Modal_S');
		obj.parentNode.removeChild(obj);
	}
	
	var sEd = '<div id="PC_Modal_S" style="display: none; top: 0px; left: 0px; background-color: #000000; z-index: 1000;"></div>';
	sEd = sEd + '<div id="PC_Modal_D" style="display: none; left: 50%; z-index: 1010; border: 4px solid #000; background-color: #fff; padding: 10px;"><div id="PC_Modal_CARREGANDO" style="z-index: 10; display: block; position: absolute; text-align: center; color: #ffffff; background-image: url('+ModalImgAjaxBkg+'); font-size: 11px; font-family: Verdana; border: 1px solid #c3c3c3; height: 65px; width: 140px; top: 50%; margin-top: -32px; left: 50%; margin-left: -70px;"><br><img src="'+ModalImgAjax+'"><br>Carregando...</div><iframe src="about:blank" frameborder="0" id="PC_iframe" onload="document.getElementById(\'PC_iframe\').style.display=\'block\';document.getElementById(\'PC_Modal_CARREGANDO\').style.display=\'none\';"></iframe></div>';
	sEd = sEd + '<div id="PC_Modal_C" style="display:none; z-index:1100; left: 50%; height: 36px; width: 36px; background-image: url('+ModalImgFechar+'); cursor: pointer;" onclick="FecharModal();"></div>';
	AdicionarHTMLBody(sEd);
	sEd = '';

	if(OldIE){
		NovoStyle.addRule('#PC_Modal_D','position: absolute; top: expression((-'+(height/2)+'+(document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 )+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+"px"); height: '+height+'px; width: '+width+'px; margin-left:-'+(width/2)+'px;');
		NovoStyle.addRule('#PC_Modal_S','position: absolute; height: expression((document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight )+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)+"px"); width: expression((document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth )+"px");');
		NovoStyle.addRule('#PC_Modal_C','position: absolute; margin-left: '+((width/2)+7)+'px; top: expression((-'+((height/2)+16)+'+(document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 )+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+"px");');
	}else{
		NovoStyle.addRule('#PC_Modal_D','position: fixed; top: 50%; margin-top:-'+(height/2)+'px; height: '+height+'px; width: '+width+'px; margin-left:-'+(width/2)+'px;');
		NovoStyle.addRule('#PC_Modal_S','position: fixed; width: 100%; height: 100%;');
		NovoStyle.addRule('#PC_Modal_C','position: fixed; top: 50%; margin-left: '+((width/2)+7)+'px; margin-top:-'+((height/2)+16)+'px; ');
	}
	
	document.getElementById('PC_iframe').src=theURL;
	document.getElementById('PC_iframe').style.display='none';
	document.getElementById('PC_iframe').style.width=width+'px';
	document.getElementById('PC_iframe').style.height=height+'px';
	
	n = 0.6;
	document.getElementById('PC_Modal_S').style.opacity = n;
	document.getElementById('PC_Modal_S').style.MozOpacity = n;
	document.getElementById('PC_Modal_S').style.KhtmlOpacity = n;
	document.getElementById('PC_Modal_S').style.filter = "alpha(opacity="+(n*100)+");";
	document.getElementById('PC_Modal_S').style.display='block';
	document.getElementById('PC_Modal_D').style.display='block';
	if (bClose!=false) {
		document.getElementById('PC_Modal_C').style.display='block';
	}
}
/* Função para abrir URL */

/* Função para exibir DIV */
function AbrirModalDIV(theDIV,width,height,bClose,newWin) {
	browser = navigator.userAgent;
	
	var OldIE = false;
	if(browser.indexOf('MSIE')>0){
		if(browser.indexOf('MSIE 8')<1){
			OldIE = true;
		}
	}
	
	
	var NovoStyle = document.createStyleSheet();

	TmpDiv = theDIV;
	
    document.getElementById(theDIV).style.display = 'block';
    if (!width) {
        width = ModalObterLargura(theDIV);
    } else {
        document.getElementById(theDIV).style.width = width;
    }
    if (!height) {
        height = ModalObterAltura(theDIV);
    } else {
        document.getElementById(theDIV).style.height = height;
    }
	
	
	if(document.getElementById('PC_Modal_D')) {
		var obj=document.getElementById('PC_Modal_C');
		obj.parentNode.removeChild(obj);
		obj=document.getElementById('PC_Modal_D');
		obj.parentNode.removeChild(obj);
		obj=document.getElementById('PC_Modal_S');
		obj.parentNode.removeChild(obj);
	}
	
	var sEd = '<div id="PC_Modal_S" style="display: none; top: 0px; left: 0px; background-color: #000000; z-index: 1000;"></div>';
	if(newWin!=false) {
		sEd = sEd + '<div id="PC_Modal_D" style="display: none; left: 50%; z-index: 1010; border: 4px solid #000; background-color: #fff; padding: 10px;">';
		sEd = sEd + document.getElementById(theDIV).innerHTML;
		sEd = sEd + '</div>';
		theDIV = 'PC_Modal_D';
	}
	sEd = sEd + '<div id="PC_Modal_C" style="display:none; z-index:1100; left: 50%; height: 36px; width: 36px; background-image: url('+ModalImgFechar+'); cursor: pointer;" onclick="FecharModal();"></div>';
	AdicionarHTMLBody(sEd);
	sEd = '';

	if(OldIE){
		NovoStyle.addRule('#' + theDIV, 'position: absolute; background-color: #fff; padding: 10px; border: 4px solid #000; z-index: 1010; left: 50%; top: expression((-' + (height / 2) + '+(document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 )+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+"px"); height: ' + height + 'px; width: ' + width + 'px; margin-left:-' + (width / 2) + 'px !important;');
		NovoStyle.addRule('#PC_Modal_S','position: absolute; height: expression((document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight )+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop)+"px"); width: expression((document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth )+"px");');
		NovoStyle.addRule('#PC_Modal_C','position: absolute; margin-left: '+((width/2)+7)+'px; top: expression((-'+((height/2)+16)+'+(document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 )+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+"px");');
	}else{
		NovoStyle.addRule('#' + theDIV, 'position: fixed; background-color: #fff; padding: 10px; border: 4px solid #000; z-index: 1010; top: 50%; left: 50%; margin-top:-' + (height / 2) + 'px; height: ' + height + 'px; width: ' + width + 'px; margin-left:-' + (width / 2) + 'px;');
		NovoStyle.addRule('#PC_Modal_S','position: fixed; width: 100%; height: 100%;');
		NovoStyle.addRule('#PC_Modal_C','position: fixed; top: 50%; margin-left: '+((width/2)+7)+'px; margin-top:-'+((height/2)+16)+'px; ');
	}
	
	
	n = 0.6;
	document.getElementById('PC_Modal_S').style.opacity = n;
	document.getElementById('PC_Modal_S').style.MozOpacity = n;
	document.getElementById('PC_Modal_S').style.KhtmlOpacity = n;
	document.getElementById('PC_Modal_S').style.filter = "alpha(opacity="+(n*100)+");";
	document.getElementById('PC_Modal_S').style.display='block';
	document.getElementById(theDIV).style.display='block';
	if (bClose!=false) {
		document.getElementById('PC_Modal_C').style.display='block';
	}
}
/* Função para exibir DIV */


/* Função para fechar o Modal */
function FecharModal() {
	if (document.getElementById('PC_Modal_C')) {
		document.getElementById('PC_Modal_C').style.display='none';
		document.getElementById('PC_Modal_S').style.display='none';
		if (document.getElementById('PC_Modal_D')) {
			document.getElementById('PC_Modal_D').style.display='none';
		}
		if(TmpDiv) {
			document.getElementById(TmpDiv).style.display='none';
		}
	}
}
/* Função para fechar o Modal */


/* Função para ocultar/exibir o botão fechar */
function ModalBotaoFechar(bVal) {
	if(bVal) {
		document.getElementById('PC_Modal_C').style.display='block';
	}else{
		document.getElementById('PC_Modal_C').style.display='none';
	}
}
/* Função para ocultar/exibir o botão fechar */


/* AUXILIAR - Função para obter a Altura de uma div */
function ModalObterAltura(obj) {
    if (typeof (obj) == 'string') { obj = document.getElementById(obj); }
    if (obj.offsetHeight) {
        r = obj.offsetHeight;
    } else if (obj.clientHeight) {
        r = obj.clientHeight;
    } else {
        r = obj.style.height;
    }
    return r;
}
/* AUXILIAR - Função para obter a Altura de uma div */


/* AUXILIAR - Função para obter a Largura de uma div */
function ModalObterLargura(obj) {
    if (typeof (obj) == 'string') { obj = document.getElementById(obj); }
    if (obj.offsetWidth) {
        r = obj.offsetWidth;
    } else if (obj.clientWidth) {
        r = obj.clientWidth;
    } else {
        r = obj.style.width;
    }
    return r;
}
/* AUXILIAR - Função para obter a Largura de uma div */


/* AUXILIAR - Adiciona o código HTML ao corpo da página */
function AdicionarHTMLBody(html) {
	if (document.all) {
		document.body.insertAdjacentHTML('afterBegin', html);
	}else if (document.createRange) {
		var range = document.createRange();
		range.setStartAfter(document.body.lastChild);
		var docFrag = range.createContextualFragment(html);
		document.body.appendChild(docFrag);
	}else if (document.layers) {
		var l = new Layer(window.innerWidth);
		l.document.open();
		l.document.write(html);
		l.document.close();
		l.top = document.height;
		document.height += l.document.height;
		l.visibility = 'show';
	}
}
/* Adiciona o código HTML ao corpo da página */




/* AUXILIAR - Criar a função createStyleSheet para browser que não a tem */
if(typeof document.createStyleSheet === 'undefined') {
	document.createStyleSheet = (function() {
		function createStyleSheet(href) {
			if(typeof href !== 'undefined') {
				var element = document.createElement('link');
				element.type = 'text/css';
				element.rel = 'stylesheet';
				element.href = href;
			}else {
				var element = document.createElement('style');
				element.type = 'text/css';
			}
			document.getElementsByTagName('head')[0].appendChild(element);
			var sheet = document.styleSheets[document.styleSheets.length - 1];
			if(typeof sheet.addRule === 'undefined')
				sheet.addRule = addRule;
			if(typeof sheet.removeRule === 'undefined')
				sheet.removeRule = sheet.deleteRule;
			return sheet;
		}
		function addRule(selectorText, cssText, index) {
			if(typeof index === 'undefined')
				index = this.cssRules.length;
			this.insertRule(selectorText + ' {' + cssText + '}', index);
		}
		return createStyleSheet;
	})();
}
/* AUXILIAR - Criar a função createStyleSheet para browser que não a tem */
