addEvent(window, "load",  init);


var isDisable = false;

function init()
{
	adjustLayoutByResolution();
	breadcrumbs();
	checkScroll();
}

function CheckBrowserForLogin()
{
	if(!( is.NS2 || is.NS3 || is.NS7 || is.NS8 || is.NS9 || is.NS10 || is.IE5 || is.IE6 || is.IE7 || is.IE8 || is.IE9 || is.CH14 || is.CH15 || is.CH16))
	{
		var divMask = '<div id="login_mask"><div id="login_alert"><img src='+PATH_LMS+'core/images/error_Alert.gif /></div><span style="font-size:13px;">Seu navegador não é compatível!</span><br />Para acessar seu ambiente de estudo, utilize os navegadores Internet Explorer versão 5.5 ou superior, Firefox versão 2.0 ou superior ou Chrome versão 14.x ou superior.</div>';
		var login = document.getElementById("login");
		login.innerHTML = divMask + login.innerHTML;
		document.getElementById("username").disabled = "true";
		document.getElementById("password").disabled = "true";
		isDisable = true;
	}
}

function checkScroll()
{
	var heightScroll = document.body.scrollHeight;
	//var heightBody = document.body.clientHeight
	var result = 0;
	var antes_cabecalho = document.getElementById("antes_cabecalho").style.height;
	
	if(is.NS)// firefox
	{
		//alert('F')
		//alert("---"+ document.body.clientHeight)
		//var heightBody = window.innerHeight;
		var heightBody = document.body.clientHeight;
		var diff = window.innerHeight - heightBody; 
		//alert(diff)
		var result  = heightBody - heightScroll;
		//alert(antes_cabecalho)
		//alert(heightBody)
		//alert(heightScroll)
		if(heightScroll < window.innerHeight && agSystem.getHeightResolution() <= 768)
			document.getElementById("bloco_site").style.height = (heightBody + diff) + "px";
		if(agSystem.getHeightResolution() > 768 && heightScroll < heightBody)
			document.getElementById("bloco_site").style.height = heightBody + "px";
	}
	else if(is.IE7)
	{
		document.getElementById("antes_cabecalho").style.height = "20px";
		var heightBody = document.body.clientHeight;
		var diff = document.documentElement.clientHeight - heightBody; 
		//alert(diff)
		var result  = heightBody - heightScroll;
		//alert(antes_cabecalho)
		//alert(heightBody)
		//alert(heightScroll)
		if(heightScroll < document.documentElement.clientHeight && agSystem.getHeightResolution() <= 768)
			document.getElementById("bloco_site").style.height = (heightBody + diff) + "px";
		if(agSystem.getHeightResolution() > 768 && heightScroll < heightBody)
			document.getElementById("bloco_site").style.height = heightBody + "px";
	}
	else//IE
	{
		//alert('I6')
		var heightBody = document.body.clientHeight;		
		var diff = document.documentElement.clientHeight - heightBody; 
		var bloco_site = document.getElementById("bloco_site");
		bloco_site.style.height = (heightBody+diff)  + "px";
		if(agSystem.getWidthResolution() > 1024)
			document.getElementById("bloco_site").style.height = "593px";	
	}
	
	
	//if(result > 0 && result < parseInt(document.getElementById("bloco_site").style.height))

		//alert(document.getElementById("bloco_site").style.height);
	/*if (heightScroll > heightBody)
	{
		result  = heightScroll - heightBody
		var test = parseInt(document.getElementById("bloco_site").style.height) + result
		if(test < 600)
		   document.getElementById("xxxx").height=result.
	}*/
}

function adjustLayoutByResolution()
{
	if(agSystem.getWidthResolution() > 800)
	{
		if(!document.getElementById("home"))
		{
			if(document.getElementById("elementAdjustLayout") != null)
				document.getElementById("elementAdjustLayout").style.display = "none";
		}
		document.getElementById("img_stope").style.marginTop = "60px";
	}
	else
	{
		document.getElementById("bloco_site").style.width = "777px";
		document.getElementById("element_absolut_white").style.width = "99%";
		
		if(document.getElementById("home"))
		{
			document.getElementById("banner_meio").style.marginLeft = "7px";
			document.getElementById("banner_meio").style.marginTop = "28px";
			if(is.NS)// firefox
			{
				document.getElementById("not_semBorda").style.marginLeft = "8px";
			}
			else//IE
			{
				document.getElementById("not_semBorda").style.marginLeft = "5px";
			}
		}
		else
		{
			document.getElementById("content_optional").style.display = "none";
		}
		document.getElementById("content_optional").style.width = "461px";
		document.getElementById("cadastro").style.display = "none";
		document.getElementById("cadastro_menu").style.display = "block";
		document.getElementById("content_meio").style.cssFloat = "right";
		document.getElementById("content_optional").style.cssFloat = "right";
		document.getElementById("content_meio").style.styleFloat = "right";
		document.getElementById("content_optional").style.styleFloat = "right";
		document.getElementById("content_meio").style.marginLeft = "0px";
		document.getElementById("content_optional").style.marginRight = "5px";
		document.getElementById("content_meio").style.marginLeft = "0px";
		document.getElementById("content_meio").style.border = "none";
		document.getElementById("content_optional").style.border = "0";
		document.getElementById("content_optional").style.borderTop = "1px solid #C2C1C1";
		//document.getElementById("img_stope").style.marginTop = "30px";
	
		if(is.NS)// firefox
		{
			document.getElementById("content_optional").style.marginTop = "10px";
			document.getElementById("enquete_fora").style.height = "0px";
			document.getElementById("enquete").style.width = "220px";
			document.getElementById("agenda").style.width = "220px";
			document.getElementById("enquete").style.paddingLeft = "10px";
			document.getElementById("enquete").style.borderLeft = "1px solid #C2C1C1";
		}
		if(is.CH)// chrome
		{
			document.getElementById("content_optional").style.marginTop = "10px";
			document.getElementById("enquete_fora").style.height = "0px";
			document.getElementById("enquete").style.width = "220px";
			document.getElementById("agenda").style.width = "220px";
			document.getElementById("enquete").style.paddingLeft = "10px";
			document.getElementById("enquete").style.borderLeft = "1px solid #C2C1C1";
		}	
		else//IE
		{
			document.getElementById("content_optional").style.marginTop = "10px";
			document.getElementById("enquete").style.height = "230px";
			document.getElementById("enquete_fora").style.height = "0px";
			document.getElementById("enquete").style.width = "215px";
			document.getElementById("agenda").style.width = "225px";
			document.getElementById("enquete").style.paddingLeft = "10px";
			document.getElementById("enquete").style.borderLeft = "1px solid #C2C1C1";
			document.getElementById("content_optional").style.paddingBottom = "7px";
		}
		
	}
	
	document.getElementById("bloco_site").style.display="block";
}
function openLittlePopup(path)
{
	window.open(path, '_blank', 'width=400,height=300,resizable=NO,scrollbars=YES');
}

function BrowserCheck() {
var b = navigator.userAgent;
if (b.indexOf('Firefox')>0) this.b = "NS";
else if (b.indexOf('MSIE')>0) this.b = "IE";
else if (b == "Chrome") this.b = "CH";
else this.b = b;
this.v = parseInt(navigator.appVersion);
this.NS = (this.b == "NS" && this.v>=4);
this.NS4 = (this.b == "NS" && this.v == 4);
this.NS5 = (this.b == "NS" && this.v == 5);
this.IE = (this.b == "IE" && this.v>=4);
this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
this.IE6 = (navigator.userAgent.indexOf('MSIE 6')>0);
this.IE7 = (navigator.userAgent.indexOf('MSIE 7')>0);
this.IE8 = (navigator.userAgent.indexOf('MSIE 8')>0);
this.IE9 = (navigator.userAgent.indexOf('MSIE 9')>0);
this.NS2 = (navigator.userAgent.indexOf('Firefox/2')>0);
this.NS3 = (navigator.userAgent.indexOf('Firefox/3')>0);
this.NS7 = (navigator.userAgent.indexOf('Firefox/7')>0);
this.NS8 = (navigator.userAgent.indexOf('Firefox/8')>0);
this.NS9 = (navigator.userAgent.indexOf('Firefox/9')>0);
this.NS10 = (navigator.userAgent.indexOf('Firefox/10')>0);
this.CH14 =(navigator.userAgent.indexOf('Chrome/14')>0);
this.CH15 =(navigator.userAgent.indexOf('Chrome/15')>0);
this.CH16 =(navigator.userAgent.indexOf('Chrome/16')>0);
if (this.IE5 || this.NS5) this.VER5 = true;
if (this.IE4 || this.NS4) this.VER4 = true;
this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
this.min = (this.NS||this.IE);
}
var is = new BrowserCheck();

/*
function insertElement()
{
var div = document.createElement("div");
div.setAttribute('id',"elementAdjustLayout");
div.setAttribute('className',"elementAdjustLayout");

if(document.getElementById("elementAdjustLayout"))
document.getElementById("bloco_site").removeChild(document.getElementById("elementAdjustLayout"))

document.getElementById("bloco_site").appendChild(div)
}

function inserElementBR()
{
	var div = document.createElement("br");
	div.setAttribute('id',"brClear");
	div.setAttribute('className',"brClear");
	
	if(document.getElementById("brClear"))
		document.getElementById("bloco_site").removeChild(document.getElementById("brClear"))
		
	document.getElementById("bloco_site").appendChild(div)

	//var sHTML ="<br style='clear: both;' />";
	//document.getElementById("bloco_site").innerHTML+=sHTML;
	alert(document.getElementById("bloco_site").innerHTML.substring(4000))
	
}
*/

function back()
{
  if(history.length > 0)
     history.back();
  else
    location.replace("../");  
}

function addEvent(obj, eventType, functionName)
{
	if(obj.addEventListener){
		obj.addEventListener(eventType, functionName, true);
		return true;
	}
	else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+eventType, functionName);
		return r;
	}

	return false;
}

function breadcrumbs()
{
	if(document.getElementById("title_page"))
	{
		try
		{
			var bc = top.fAGLogger.agBreadCrumbs;
			var title = document.getElementById("title_page").innerText;
			var href = document.location.href;
	
			bc.setFormatBreadCrumbs(" <a href='[HREF]'>[TITLE]</a> ");
			bc.setSeparatorBreadCrumbs(" >> ");
			
			if(typeof (title) == 'undefined')
				title = document.getElementById("title_page").textContent;
	
			bc.addLocationAccess(href,title);
			
		 	document.getElementById("caminho_pao").innerHTML = bc.getBreadCrumbs();
		}
		catch(e){}
	}
}

function openPictureWindow(imageName,imageWidth,imageHeight,alt,posLeft,posTop)
{
	newWindow = window.open("","newWindow","width=100,height=100,scrollbars=no,left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onload="self.focus()">'); 
	newWindow.document.write('<img src=\"'+imageName+'\" alt=\"'+alt+'\" onload=\"window.resizeTo((this.width),(this.height+49))\">'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}

function $Id(id)
{
	return document.getElementById(id);
}
