/*
window.addEvent('domready', function(){
	var accordion = new Accordion('h3.atStart', 'div.atStart', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ff3300');
		},
		
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#222');
		}
	}, $('accordion'));
	
	var accordion1 = new Accordion('h3.atStart1', 'div.atStart1', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ff3300');
		},
		
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#222');
		}
	}, $('accordion1'));
	
	var accordion2 = new Accordion('h3.atStart2', 'div.atStart2', {
		opacity: false,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ff3300');
		},
		
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#222');
		}
	}, $('accordion2'));
	

	
	
	
	document.addEvent('mousedown', function(event) {
	event = new Event(event); 
	posX = event.page.x; 
    posY = event.page.y;
	});
	
	 
	
	
}); 
*/
var posX;
var posY;

function destroy(layer){
	$(layer).remove();
	}


function ativa(layer, param, janela){
	//alert($("#list1b").style('display'));
	//addElement(layer);
	
	addElement(layer);
	
	$(layer).style.position = "absolute";
	
	if(janela) {
	
		if (navigator.appName == "Microsoft Internet Explorer"){
			resolucao = new Array(document.body.offsetWidth, document.body.offsetHeight);
		}
		else{
			resolucao = new Array(window.innerWidth, window.innerHeight);
		}
		
		posX = (resolucao[0]/2) - (janela/2);
		posY = (resolucao[1]/2) - (janela/2);
		
		if((posX + janela) > (resolucao)){
		alert('entrou');
			posX = posX - janela;
		}
		
		$(layer).style.top = posY+"px";
		$(layer).style.left = posX+"px";	
		
	}
	
	//req = new Ajax('template/'+layer+'.php', {
	req = new Ajax(layer+'.php?' + param, {
			method: 'get',
			update: $(layer)
			//onComplete: Acc
	}).request();
	
	
}

function atualiza(destino, layer, param){	

	//pega o texto do div.
	var text = document.getElementById('recado').value;
	
	req = new Ajax(destino+'.php?' + param +'&txt='+text, {
			method: 'get',
			update: $(layer)
			//onComplete: Acc
		}).request();	
}

function atualizaAddFriend(destino, layer, param){	

	//pega o texto do div.
	//var text = document.getElementById('recado').value;
	
	req = new Ajax(destino+'.php?' + param,  {
			method: 'get',
			update: $(layer)
			//onComplete: Acc
		}).request();	
}

function atualizaAddCommunity(destino, layer, param){	

	//pega o texto do div.
	//var text = document.getElementById('recado').value;
	
	req = new Ajax(destino+'.php?' + param,  {
			method: 'get',
			update: $(layer)
			//onComplete: Acc
		}).request();	
}

function deletecontent()
{
	this.innerHTML = '';	
}

function addElement(layer) {	
  var newdiv = document.createElement('div');
  var divIdName = layer;
  var divStyle ="position:absolute; top:0px; left:0px";
  newdiv.setAttribute('id',divIdName);  
  newdiv.setAttribute('style',divStyle); 
  document.body.appendChild(newdiv);
}

function deleteComentario(param){
	
	if (confirm (" Deseja realmente excluir o comentário ? "))
	{
		location= 'topico.php?' + param;
		submit();
	}

}

function deleteComunidade(param){

	if (confirm (" Deseja realmente excluir a Comunidade ? "))
	{
		location= 'indexCommunity.php?' + param;
		submit();
	}

}

function sairComunidade(param){

	if (confirm (" Deseja realmente sair da Comunidade ? "))
	{
		location= 'indexCommunity.php?' + param;
		submit();
	}

}

function validaComunidade(){

	var nome = document.getElementById('nome_comunidade').value;
	alert(nome);
	
			
}

function seleciona_todas(totalCheck){
//	alert(totalCheck);
	for(i=0; i<totalCheck; i++){
		
		var cp = "chk_" + i;
			document.getElementById(cp).checked=true;


	}
	
	
}

function deletaConteudo(){
	
	var totChecked = 0;

	var form = document.getElementById( 'excluir' );
	var arrayInput = form.getElementsByTagName( 'input' );
		
	for( var i=0; i<arrayInput.length; i++ ){
		if( arrayInput[i].type == 'checkbox' ){
			if( arrayInput[i].checked ){
				totChecked++;
			}
		}
	}

	if( totChecked == 0 ){
		
		alert('Selecione um conteúdo para ser excluído !');
		return false;
		
	}
	
	
	if (confirm (" Deseja realmente excluir " + totChecked + " conteudo(s) selecionado(s) ? "))
	{
		document.getElementById('excluir').submit();
	}

}
