function loadArea(area){
	xajax_loadArea(area);
//	alert("a= "+area)	
}

function initFormFoto(){
	$('#albumFotoFile').MultiFile({
		max: 5,
		accept:'gif|jpg|jpeg',
		STRING: {
			remove: 'remover'
		}
	});
	
	$("#addFotoForm").validate({
		errorElement: "div",
			success: function(label) {
			label.text("ok!").addClass("success").remove();					
		},
		
		rules: {
			albumFotoFile :{
				accept:'jpg|jpeg|gif'
			}
		},
		messages: {
			albumFotoFile: "Selecione um arquivo do tipo JPG ou GIF de até 1mb"
		}
	});
}


function Confirm(texto,indice, area){
	if (window.confirm (texto)) {
		switch (indice){
			case "alert":
				//window.alert(" Continuando.. ")
				break;
			case "location":
				window.location = area;
				break
			case "back":
				window.back(-1);
				break;
		}
	}else {
		//window.alert(" Cancelando... ")
	}
}

function escSt(item){
	var st = document.getElementById(item).style.display;
	if(st == "none"){
		document.getElementById(item).style.display = "block";
	}else{
		document.getElementById(item).style.display = "none";
	}
}


function colorLine(id,cor){
	document.getElementById(id).style.backgroundColor = ""+cor+"";
}
function uncolorLine(id,cor){
	document.getElementById(id).style.backgroundColor = ""+cor+"";
}

function getURL(url){
	window.location.href = url;	
}


all_tabs=[];
function tabs(aba,tabela,colorh){
	if(all_tabs.length > 0){
		for(i=0;i<all_tabs.length;i++){
			var abaHide 	= document.getElementById(all_tabs[i][0]);
			var tabelaHide 	= document.getElementById(all_tabs[i][1]);
			if((abaHide != null) && (tabelaHide != null)){
				abaHide.style.backgroundColor 	= "";
				tabelaHide.style.display 		= "none";
			}			
		}
		all_tabs = [];
	}
	var aba_ 		= document.getElementById(aba);
	var tabela_ 	= document.getElementById(tabela)
	
	aba_.style.backgroundColor = ""+colorh+"";
	tabela_.style.display = "";
	
	all_tabs[all_tabs.length] = [aba,tabela];
	createCookie("plug_abas",aba+","+tabela,'');
}

function tab_ini(colorh,abaIni,tabelaIni){
	cookie = getCookie('plug_abas');
	
	var tabelaIni_ 	= document.getElementById(tabelaIni);
	var abaIni_	 	= document.getElementById(abaIni);
	
	if(cookie){
		infos = cookie.split(",");

		var abaID 		= infos[0];
		var tabelaID 	= infos[1];
		
		var tabela 	= document.getElementById(""+tabelaID+"");
		var aba 	= document.getElementById(""+abaID+"");

		if((tabela != null) && (aba != null)){
			tabela.style.display 		= "block";
			aba.style.backgroundColor	= ""+colorh+"";
			all_tabs[all_tabs.length] 	= [abaID,tabelaID];
		}else{
			all_tabs[all_tabs.length] = [abaIni,tabelaIni];
			tabelaIni_.style.display = "";
			abaIni_.style.backgroundColor=""+colorh+"";	
		}
	}else{
		all_tabs[all_tabs.length] = [abaIni,tabelaIni];
		tabelaIni_.style.display = "";
		abaIni_.style.backgroundColor=""+colorh+"";	
	}
	/*
	if(all_tabs.length == 0){ 
		tab_cont = document.getElementById(id);
		tab_cont2 = document.getElementById(id2);
		if(tab_cont != null){
			all_tabs[all_tabs.length] = [id,tab];
			tab_cont.style.display = "";
			tab_show = document.getElementById(tab);
			tab_show.style.backgroundColor=""+colorh+"";
		}else{
			all_tabs[all_tabs.length] = [id2,tab2];
			tab_cont2.style.display = "";
			tab_show2 = document.getElementById(tab2);
			tab_show2.style.backgroundColor=""+colorh+"";			
		}
	}
	*/
}

function createCookie(name,value,days){
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function getCookie(c_name){
	if (document.cookie.length>0){
  		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
    	} 
  	}
	return "";
}




function escSub(item,sub){
	var t = document.getElementById(item);
	var img = document.getElementById('img'+item);

	var divErro = document.getElementById('divErro');
	var sombraErro = document.getElementById('sombraErro');
	var iframeErro = document.getElementById('iframeErro');


	if(t != null){
		
		if (divErro) {
			divErro.style.display = "none";
		}
		
		if (sombraErro) {
			sombraErro.style.display = 'none';
		}
		
		if (iframeErro) {
			iframeErro.style.display = 'none';
		}
		
		
		var st = document.getElementById(item).style.display;
		if(st == "none"){
			document.getElementById(item).style.display = "block";
			if(sub == 1){
				if(img != null){
					document.getElementById('img'+item).innerHTML = "<img src='../../images/icon_522.gif' align='absmiddle' border='0'><img src='../../images/menos.gif' border=0 align='absmiddle' />";
				}
			}else{
				if(img != null){
					document.getElementById('img'+item).innerHTML = "<img src='../../images/menos.gif' border=0 align='absmiddle' />";			
				}
			}
		}
		else{
			document.getElementById(item).style.display = "none";
			if(sub == 1){
				if(img != null){
					document.getElementById('img'+item).innerHTML = "<img src='../../images/icon_522.gif' align='absmiddle' border='0'><img src='../../images/mais.gif' border=0 align='absmiddle' />";
				}
			}else{
				if(img != null){
					document.getElementById('img'+item).innerHTML = "<img src='../../images/mais.gif' border=0 align='absmiddle' />";
				}
			}
		}
	}
}

function findPos(obj,show) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	div = document.getElementById(show);
	div.style.top = curtop+10;
	div.style.left = curleft;
	div.style.display = '';
	//return [curleft,curtop];
}


var tempoOn = false;

function calculaWidHei(elemento) {
	if (elemento.offsetParent) {
		wid = elemento.offsetWidth;
		hei = elemento.offsetHeight;
		pos_l = elemento.offsetLeft;
		pos_t = elemento.offsetTop;
		while (elemento = elemento.offsetParent) {
			pos_l += elemento.offsetLeft;
			pos_t += elemento.offsetTop;
		}
	}	
}

function get_lastchild(n){
	var x=n.lastChild;
	if(x.nodeType == 1){
		while (x.nodeType!=1){
			x=x.previousSibling;
		}
	}
	return x;
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showAlert(page,url){
	var div = document.getElementById('messageBoard');
	var container = document.getElementById('Boards');
	var frame = document.getElementById('frameBoards');	
	var cont = document.getElementById('showContent');
	
	getPageSize();

	var scrol = ScrollCoordinates()
	if(scrol > 0){
		window.scrollTo(0,0);
		container.style.height = arrayPageSize[1];
		frame.style.height = arrayPageSize[1];
	}else{
		container.style.height = arrayPageSize[1]-5;
		frame.style.height = arrayPageSize[1]-5;
	}

	container.style.display = "";
	frame.style.display = "";

	div.style.display = "";
	post = "url="+url;
	ajaxHTMLCal("showContent",page,post);
	
}


function ScrollCoordinates() {
  return (document.all)?document.body.scrollTop:window.pageYOffset;
} 

function hideBoard(){
	var div = document.getElementById('messageBoard');
	var container = document.getElementById('Boards');
	var frame = document.getElementById('frameBoards');
	var flashBoard = document.getElementById('flashBoard');
	
	
	var cont = document.getElementById('showContent');
	cont.innerHTML = "";
	container.style.display = "none";
	div.style.display = "none";
	frame.style.display = "none";
	
	flashBoard.style.display = "none";
	
	
	var cal = document.getElementById('yearDropDown');
	if(cal){
		closeCalendar();
	}
}

function geraBg(){
	var flashBoard = document.getElementById('flashBoard');
	var flashs = document.getElementById('flashs');
	var content = document.getElementById('fill');

	if(content != null){
		calculaWidHei(content);
		
		var bg = flash("../common/swf/common/bg_flash.swf",wid,hei+20,'menu=false,wmode=transparent,scale=exactfit');
		flashs.innerHTML = bg;
		flashBoard.style.display = "";
		flashs.style.width = wid+"px";
		flashs.style.height = hei+"px";
	}
}

function flash(arquivo,largura,altura,param) {
	// Parametros padrões - <param />
	var codigo_param = '<param name="movie" value="' + arquivo + '" />\n';
	codigo_param += '<param name="quality" value="high" />\n';
	
	// Parametros padrões - <embed />
	var codigo_embed = 'width="' + largura + '" height="' + altura + '"';
	
	// Arrays
	var parametros = new Array; // Ex: wmode=transparent
	var parametro = new Array; // Ex: wmode
	
	// Código HTML
	var codigo = "";
	
	// Transformando parametros enviados em array
	parametros = param.split(","); // Transforma wmode=transparent,scale=noscale em array separado por vírgula
	
	// Criando o html dos parametros
	for (var i=0; i < parametros.length; i++) { // Criar enquanto existir array
		ponto = parametros[i].indexOf('=');
		parametro[0] = parametros[i].substr(0,ponto);
		parametro[1] = parametros[i].substr(ponto+1);

		//parametro = parametros[i].split("="); // Separando wmode de transparent

		codigo_param += '<param name="' + parametro[0] + '" value="' + parametro[1] + '" />\n'; // Criando tags <param />
		codigo_embed += ' ' + parametro[0] + '="' + parametro[1] + '"'; // Criando final da tag <embed />
	}
	
	codigo += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">';
	codigo += '\n';
	codigo += codigo_param;
	codigo += '<embed src="' + arquivo + '" quality="high" pluginspage="https://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" ' + codigo_embed + '></embed>';
	codigo += '\n';
	codigo += '</object>';
	return codigo;
}


function ajaxConect(){
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
	return xmlhttp;
};

function sent(f){
	var frm = document.getElementById(f);
	var post = "";
	
	for (i = 0; i < frm.elements.length; i++) {
		var elemento = frm.elements[i];	
		if(!elemento.getAttribute('disabled')){
			switch(elemento.type) {
				case "text":
					post+=elemento.name+"="+elemento.value+"&";
				break;
				case "hidden":
					post+=elemento.name+"="+elemento.value+"&";
				break;
				case "select-one":
					post+=elemento.name+"="+elemento.value+"&";
				break;
				case "textarea":
					post+=elemento.name+"="+elemento.value+"&";
				break;
				case "radio":
					marcados =-1;
							//alert(elemento.name)
					for (x=0; x<frm.elements[elemento.name].length; x++) {
						if (frm.elements[elemento.name][x].checked) {
							val = frm.elements[elemento.name][x].value;
							post+=elemento.name+"="+val+"&";
						}
					}
				break;
				case "checkbox":
					marcados =-1;
					//alert(elemento.name)
					if (frm.elements[elemento.name].checked) {
						val = frm.elements[elemento.name].value;
						post+=elemento.name+"="+val+"&";
					}
				break;
			}
		}
	}
	//post = post+"form=";
	ajaxHTMLCal('alerta','site/posts.php',post);
	frm.reset();
}

fila=[];
ifila=0;

function ajaxHTMLCal(div,url,parametros){
	fila[fila.length]=[div,url,parametros];
	if((ifila+1)==fila.length)ajaxRunCal();
}

function ajaxRunCal(){
	//Abre a conexão
	var xmlhttp3 = ajaxConect();
	xmlhttp3.open("POST",fila[ifila][1],true);
	post = fila[ifila][2];
	xmlhttp3.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8"); 
	//Função para tratamento do retorno
	xmlhttp3.onreadystatechange=function() {
	var r = document.getElementById(fila[ifila][0]);
	r.innerHTML = "<font color='#FFFFFF'>Aguarde...</font>";
	if (xmlhttp3.readyState==4){
		retorno=unescape(xmlhttp3.responseText.replace(/\+/g," "))
		//alert(retorno);
		if(r != null){
			r.innerHTML=retorno;
			extraiScript(xmlhttp3.responseText);
			geraBg();
		}
		ifila++
		if(ifila<fila.length)setTimeout("ajaxRunCal()",20);
		}
	}
	//Executa
	xmlhttp3.send(post);
}

function extraiScript(texto){
    var ini = 0;
    while (ini!=-1){
        ini = texto.indexOf('<script', ini);
        if (ini >=0){
            ini = texto.indexOf('>', ini) + 1;
            var fim = texto.indexOf('</script>', ini);
            codigo = texto.substring(ini,fim);
            eval(codigo);
			novo = document.createElement("script");
            novo.text = codigo;
			//alert(codigo);
            var script = document.getElementById("scripts");
			script.innerHTML = "";
			script.appendChild(novo);
			//alert(script.innerHTML);
        }
    }
}

function setSwf(obj,destino,w,h){
	var so = new SWFObject(obj, "banner", w, h, "7", "#FFFFFF");
	so.addParam("allowScriptAccess", "always");
	so.addParam("wmode", "transparent");
	so.write(destino);
}

function loadFoto(fotoID){
	var img = document.getElementById('fotos');
	img.innerHTML = "<img src=\""+fotoID+"\" border=\"0\"  align=\"left\" />"; 
	//img.src = "common/image/site/fotos/"+fotoID+".jpg";
}

function teste(){
	alert("aaaaaa");
}

function cadastraTag(){
	var div = document.getElementById('cadastraTag');
	var iframe = document.getElementById('iframe');
	var loader = document.getElementById('loader');
	
	getPageSize();
	
	loader.style.height = arrayPageSize[1];
	iframe.style.height = arrayPageSize[1];
	
    if(div.style.display === ''){
    	div.style.display		= 'none';
		iframe.style.display 	= 'none';
		loader.style.display 	= 'none'
    }else{
    	div.style.display		= '';
		iframe.style.display 	= '';
		loader.style.display 	= ''
    }
	
	return true;
	
}