// JavaScript Document

var raiz = "../";
var path = raiz+"modules/mod_front_end/";

window.onload = function(){
	this.onloadPage();
	try{$('.canto1').corner('rounded 12px');}catch(Exception){}
	try{$('.cantoD').corner('rounded 12px');}catch(Exception){}
	try{$('.parceiros').corner('rounded 12px');}catch(Exception){}
	try{$('#component-contact').corner('rounded 12px');}catch(Exception){}
}
function onloadPage(){
	tag = document.getElementById('innerPublicidade');
	var loader = "<p style=\"margin:60px 0 0 160px;\"><img src=\"/site/images/mod_front_end/loader.gif\" border=\"0\" width=\"70\" height=\"20px\"></p>";
	if(tag!=null){
		tag.innerHTML += loader;
		this.loadPage('innerPublicidade','modules/mod_front_end/frontpage/index.php');
	}
	tag = document.getElementById('opiniao');
	loader = "<p style=\"margin:50px 0 0 60px;\"><img src=\"/site/images/mod_front_end/loader.gif\" border=\"0\" width=\"70\" height=\"20px\"></p>";
	if(tag!=null){
		tag.innerHTML += loader;
		this.loadPage('opiniao','modules/mod_front_end/opiniao/index.php');
	}
	tag = document.getElementById('form_cadastrese');
	if(tag!=null){
		tag.innerHTML += loader;
		this.loadPage('form_cadastrese','modules/mod_front_end/news/form.php');
	}
}
function goodBrowser(){
	var versao = navigator.appVersion;
	var pos = versao.indexOf("MSIE");

	if(pos>=0){		
		var tmp = versao.substring(pos);
		tmp = tmp.replace("MSIE","");
		tmp = tmp.substring(0,tmp.indexOf(";"));
		tmp = parseInt(this.trim(tmp));
		if(tmp<7)
			return false;
	}
	return true;
}
function trim(str){
	return str.replace(/^\s+|\s+$/g,"");
}
function block(tag){
	var ul = tag.getElementsByTagName('ul')[0];
	if(ul!=null){
		var tmp = ul.style.display;
		if(tmp == 'block')
			ul.style.display = "none";
		else
			ul.style.display = "block";
	}else
		tag.innerHTML += "<ul id=\"subitem\"><li class=\"innerCor\"><span id=\"label\">Não há item cadastrado<span></li></ul>";
}
function addTagId(id,str){
	var tag = document.getElementsByTagName("body")[0];
	if(tag!=null){
		var div = document.createElement("div");
		div.setAttribute('id',id);
	
		var corpo = "";
		if(str!=null)
			corpo = str;
			
		removeTagId(id);
		div.innerHTML = corpo;
		tag.appendChild(div);
		
		return div;
	}
	return null;
}
function removeTagId(id){
	var div = document.getElementById(id);
	if (div != null)
		div.parentNode.removeChild(div);
	return true;
}
function addDivId (id,localTag,str,classe){
	var div = document.createElement("div");
	div.setAttribute('id',id);
	if(classe != null)
		div.setAttribute("class", classe);

	var corpo = "";
	if(str!=null)
		corpo = str;
		
	removeTagId(id);
	div.innerHTML = corpo;
	
	if(localTag!=null){
		tag = document.getElementById(localTag);
		tag.appendChild(div);
	}
	return div;
}

function addLoadding(){
	var div = this.addTagId('blackout');
	if(!this.goodBrowser())
		div.style.position= 'absolute';
	else
		div.style.position	= 'fixed';
	div.style.top			= '0px';
	div.style.left			= '0px';
	div.style.width			= '100%';
	div.style.height		= '100%';
	div.style.color			= '#FFFFFF';
	div.style.zIndex		= '1000';
	div.style.background	= '#000000';
	div.style.opacity		= '.65';
	div.style.filter		= ' alpha(opacity=65)';
	var inner = this.addDivId ('loadding','blackout','');
	if(!this.goodBrowser())
		inner.style.position= 'absolute';
	else{
		//inner.innerHTML += '<img src=\'/site/images/mod_front_end/loader.gif\' />';
		inner.style.position= 'fixed';
	}
	inner.style.top			= '46%';
	inner.style.left		= '46%';
	inner.style.width		= '100px';
	inner.style.height		= '20px';
	inner.style.color		= '#FFFFFF';
	inner.style.fontWeight	= '900';
	inner.style.zIndex		= '1100';
}
function addBlackout(){
	var div = this.addTagId('blackout');
	if(!this.goodBrowser())
		div.style.position= 'absolute';
	else
		div.style.position	= 'fixed';
	div.style.top			= '0px';
	div.style.left			= '0px';
	div.style.width			= '100%';
	div.style.height		= '100%';
	div.style.color			= '#FFFFFF';
	div.style.zIndex		= '1000';
	div.style.background	= '#000000';
	div.style.opacity		= '.65';
	div.style.filter		= ' alpha(opacity=65)';
	var inner = this.addDivId ('loadding','blackout','');
	if(!this.goodBrowser())
		inner.style.position= 'absolute';
	else
		inner.style.position= 'fixed';
	inner.style.top			= '10%';
	inner.style.left		= '10%';
	inner.style.width		= '800px';
	inner.style.height		= '60px';
	inner.style.color		= '#FFFFFF';
	inner.style.fontWeight	= '900';
	inner.style.zIndex		= '1010';
}
function loadPage(id,url,parans){
	var par = "";
	if(parans != null && parans != "")
		par = "?"+parans;
	MyAjax.simpleLoad(url+par,id, "GET", "", true);
	//new Ajax.Updater(id,url+par,{evalScripts:true});
}
function removeIFrame(op){
	this.removeTagId('blackout');
	this.removeTagId('div_'+op);
}
function viewIFrame(op){
	this.addBlackout();
	var tag = document.getElementsByTagName("body")[0];
	if(tag!=null){
		var x 		= screen.width; // largura
		var y 		= screen.height; // altura
		var width	= 1000;
		var height	= 545;
		var left 	= (x<=width)?0:(x-width)/2;
		var top		= (y<=height)?0:((y-height)/2)-100;
		var div 	= document.createElement("div");
		div.setAttribute('id','div_'+op);
		div.style.position		= 'absolute';
		div.style.top			= top+'px';
		div.style.left			= left+'px';
		div.style.width			= width+'px';
		div.style.height		= height+'px';
		div.style.zIndex		= '1100';
		
		var corpo = '<iframe id="upload_iFrame" name="upload_iFrame" src="modules/mod_front_end/'+op+'" frameborder="0" scrolling="no" width="'+width+'" height="'+height+'" ALLOWTRANSPARENCY="true" ></iframe>';
			
		removeTagId('div_'+op);
		div.innerHTML = corpo;
		tag.appendChild(div);
		
		return div;
	}
	return null;
}
function addAssNewsletter(dt){
	if(dt!=null)
		dt.disabled=true;
	this.addLoadding();
	var mail 	= document.getElementById('email');
	var nome 	= document.getElementById('nome');
	var access 	= document.getElementById('access');
	var value 	= "nome="+nome.value+"&email="+mail.value+"&access="+access.value;
	this.loadPage('innerContents','modules/mod_news_letter/action/add_ass_newsletter.php',value);
}
function downloadIni(op){
	id 		= 'domus_colunaCentral';
	classId	= 'domus_coluna';
	idLocal = 'domus_corpo';
	
	this.removeTagId(id);
	this.addDivId (id,idLocal,'',classId);
	
	var tmp = document.getElementById(id);
	tmp.style.height = "300px";

	this.loadPage(id,'modules/mod_news_letter/module/mod_news_letter.php','access='+op);

}
function closeAll(id){
	var lista = document.getElementById(id).getElementsByTagName("ul");
	for(i = 0;i<lista.length;i++)
		lista[i].style.display = "none";
}
function abrirHome(){
	//this.addLoadding();
	
	id 		= 'domus_colunaCentral';
	classId	= 'domus_coluna';
	idLocal = 'domus_corpo';
	
	this.removeTagId(id);
	this.addDivId (id,idLocal,'',classId);
		
	var tmpidLocal = document.getElementById(idLocal);
	tmpidLocal.style.height = "710px";

	/**/
	this.loadPage(id,'templates/domusitlica2009/openHome.php');
	this.dormirHome();
	//this.onloadPage();

	this.loadPage('innerPublicidade','modules/mod_front_end/frontpage/index.php');
	this.loadPage('opiniao','modules/mod_front_end/opiniao/index.php');
	this.loadPage('form_cadastrese','modules/mod_front_end/news/form.php');

	/**/
	//new Ajax.Updater(id,'templates/domusitlica2009/openHome.php',{evalScripts:true});

}
function abrirNoticias(){	
	id 		= 'domus_colunaCentral';
	classId	= 'domus_coluna';
	idLocal = 'domus_corpo';
	
	//this.removeTagId("domus_colunaEsquerda");
	this.removeTagId(id);
	this.addDivId (id,idLocal,'',classId);
	
	var tmpidLocal = document.getElementById(idLocal);
	tmpidLocal.style.height = "710px";
	
	var site = window.location;	
	//new Ajax.Updater(id,'/site/templates/domusitlica2009/news.php?site='+site,{evalScripts:true});
	this.loadPage(id,'templates/domusitlica2009/news.php?site='+site);
}
function openNews(num){
	id 		= 'domus_colunaCentral';
	
	var site = window.location;
	//new Ajax.Updater(id,'/site/templates/domusitlica2009/news.php?id='+num+'&site='+site,{ evalScripts:true});
	this.loadPage(id,'templates/domusitlica2009/news.php?id='+num+'&site='+site);
}
function dormirHome(){
	sleep(2000);
}
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

/*MENU DROP DOWN*/
// Copyright 2006-2007 javascript-array.com

var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}

function onchangeInputId(tag, txtDefault){
	if(tag){
		if(txtDefault){
			if(tag.value == '')
				tag.value = txtDefault;
			else if(tag.value == txtDefault)
				tag.value = '';
			
		}
	}
}
