////////////////////////////////
// JavaScript Document
// Codigo javascript BooByte 1.0
//AUTOR Samyr de Alencar Pereira
// 2009
//////////////////////////////
	
function criarimg(foto){
	document.getElementById("gif_animado").style.display= "none";
	var fto = new Image();
	fto.src = foto;
	var w = fto.width;
	var h = fto.height;
	
      var wi = w+"px";
	  var he = h+"px";
	  // onde o elemento será adicionado
      var pai = document.getElementById("cx_editor");
      // definimos qual elemento queremos criar
      var elem = document.createElement("div");
	 
	 var tam = pai.getElementsByTagName("div").length;
	  var nova = "animado"+tam;
	  	
	   elem.setAttribute("name", nova);
	   elem.setAttribute('id', nova);
	   	 
	    pai.appendChild(elem);
		 num_index = 164 + tam;
	 document.getElementById(nova).style.zIndex =num_index;
	  document.getElementById(nova).style.position ="relative";
	  document.getElementById(nova).style.width = wi; 
	  document.getElementById(nova).style.height = he; 
	  document.getElementById(nova).style.backgroundImage="url("+foto+")";
	  document.getElementById(nova).style.margin = "0px 0 0 10px"; 
	  //document.getElementById(nova).style.border ="1px solid #000000";
		
	 ADD_DHTML(CURSOR_MOVE, nova);
	 
	 dd.elements[nova].text = foto;
	 dd.elements[nova].src = foto;
				document.getElementById("gif_animado").style.display= "none";
}

function deletar(){
       //se não existir elementos h1 ele não faz nada.
       if (pai.childNodes.length != 0){
       //de onde o elemento será deletado
       pai = document.getElementById("cx_imagem");
       //como o elemento h1 é filho do elemento corpo usamos o childNodes[x]
       //para deletarmos.
       elem = pai.childNodes[pai.childNodes.length-1];
       //remove o elemento
       elem.removeNode(true);
       }
}


function abrir(url) {
  window.open(url,'','scrollbars=no,status=no,location=no,toolbar=no,menubar=no,width=400,height=500');
}



function cima(indice_atual){

// pega nome camada atual
var camada_atual = document.getElementById( indice_atual ).innerHTML;

// pega indice camada atual
var ind_pra_cima = document.getElementById(camada_atual).style.zIndex;

// pega numero ultimo caracter nome camada
var num = indice_atual.substr(14,15);

// cria nome da camada de troca 
num = parseInt(num);
num = num - 1;
var indice_troca = indice_atual.substr(0,14)+num;

// pega nome camada troca
var camada_troca = document.getElementById( indice_troca ).innerHTML;

//pega indice camada de troca
var ind_pra_baixo = document.getElementById(camada_troca).style.zIndex;

// troca indices
document.getElementById(camada_atual).style.zIndex= ind_pra_baixo;
document.getElementById(camada_troca).style.zIndex= ind_pra_cima;
dd.elements[camada_atual].setZ(ind_pra_baixo);
dd.elements[camada_troca].setZ(ind_pra_cima);

// troca nome na coluna de indice
document.getElementById( indice_atual ).innerHTML= camada_troca;
document.getElementById( indice_troca ).innerHTML= camada_atual;

}
function baixo(indice_atual){

// pega nome camada atual
var camada_atual = document.getElementById( indice_atual ).innerHTML;

// pega indice camada atual
var ind_pra_cima = document.getElementById(camada_atual).style.zIndex;

// pega numero ultimo caracter nome camada
var num = indice_atual.substr(14,15);

// cria nome da camada de troca 
num = parseInt(num);
num = num + 1;
var indice_troca = indice_atual.substr(0,14)+num;

// pega nome camada troca
var camada_troca = document.getElementById( indice_troca ).innerHTML;

//pega indice camada de troca
var ind_pra_baixo = document.getElementById(camada_troca).style.zIndex;

// troca indices
document.getElementById(camada_atual).style.zIndex= ind_pra_baixo;
document.getElementById(camada_troca).style.zIndex= ind_pra_cima;
dd.elements[camada_atual].setZ(ind_pra_baixo);
dd.elements[camada_troca].setZ(ind_pra_cima);

// troca nome na coluna de indice
document.getElementById( indice_atual ).innerHTML= camada_troca;
document.getElementById( indice_troca ).innerHTML= camada_atual;

}

function selecionar(indice_atual){

// pega todos os indices e coloca cor padrão
pai_camadas = document.getElementById("col_camadas");
var conta_elem = pai_camadas.getElementsByTagName("div").length;
for(u=0;u<conta_elem;u++){
	elem = pai_camadas.getElementsByTagName("div")[u];

	elem.style.backgroundColor="#FFFFFF";
	elem.style.color="#000000";
}

//seleciona o indice atual
document.getElementById(indice_atual).style.backgroundColor="#0000FF";
document.getElementById(indice_atual).style.color = "#FFFFFF";

// pega nome camada atual e seta
var camada_atual = document.getElementById( indice_atual ).innerHTML;

document.cform2.seltext.value = camada_atual;

}

// AJUDA BOOBYTE

function ajuda(ajuda){

document.getElementById(ajuda).style.display = 'inline';

}
function ajuda_out(ajuda){

document.getElementById(ajuda).style.display = 'none';

}

/////////
function escreve(valor){
	
	var font = document.getElementById("selfont").value;
	var size = document.getElementById("selfontsize").value;
	var cortexto = document.getElementById("ctext").value;
	
	var tastr = valor.length;
	//var siz = 2*(parseInt(size/3));
	var wid = tastr * parseInt(2*(size/3));
	
	document.getElementById("tex").style.width = wid+"px";
	document.getElementById("tex").style.height ="30px";
	document.getElementById("tex").style.fontFamily = font;
	document.getElementById("tex").style.fontSize = size+"px";
	document.getElementById("tex").style.color = "#"+cortexto;
	//document.getElementById(nova).style.display ='inline';
	
	//var pesquisa = /\n/g;
	//valor = valor.replace(pesquisa, "&lt;br&gt;");
	// quebra de linha funciona para impressao na imagem
	document.getElementById("tex").innerHTML = valor;
	dd.elements["tex"].text = valor+"*"+font+"*"+size+"*"+cortexto;
	
}

function criatexto2(){
	
//document.getElementById("tex").style.display = "inline";

	   ////// pega numero do ultimo elemento
var num = document.getElementById( "hdfoto").value;
num++;
// seta o numero do novo  elemento ativo
document.getElementById( "hdfoto").value = num;
// seta a foto no controle IMG
	
		// pega indice ultimo elemento
		
		var ult_indice = (164 + num)+1;
		
		document.getElementById("tex").style.zIndex = ult_indice;
		dd.elements["tex"].setZ(ult_indice);
		// torna visivel
		dd.elements["tex"].show();
		//document.getElementById("tex").style.display ='inline';
	
	var indi_camada = "novo_indice_camada_"+num;
document.getElementById( indi_camada).style.display = "inline";
document.getElementById( indi_camada).innerHTML= "tex";
document.getElementById( indi_camada).style.display = "inline";
document.getElementById( indi_camada).style.display= "inline";
//document.getElementById( indi_camada).style.backgroundImage = "url(images/tools/foto.jpg)";

	var display = "novo_linha_seta_camada_"+num;
	document.getElementById(display).style.display= "inline";
	var display = "linha_sel_camada_"+num;
	document.getElementById(display).style.display= "inline";
	
}



///////////// w

function cima2(indice_atual){

// pega nome camada atual
var camada_atual = document.getElementById( indice_atual ).innerHTML;

// pega indice camada atual
var ind_pra_cima = document.getElementById(camada_atual).style.zIndex;

// pega numero ultimo caracter nome camada
var num = indice_atual.substr(19,20);

// cria nome da camada de troca 
num = parseInt(num);
var num2 = num - 1;
var indice_troca = indice_atual.substr(0,19)+num2;

// pega nome camada troca
var camada_troca = document.getElementById( indice_troca ).innerHTML;

//pega indice camada de troca
var ind_pra_baixo = document.getElementById(camada_troca).style.zIndex;

// troca indices
document.getElementById(camada_atual).style.zIndex = ind_pra_baixo;
document.getElementById(camada_troca).style.zIndex = ind_pra_cima;
dd.elements[camada_atual].setZ(ind_pra_baixo);
dd.elements[camada_troca].setZ(ind_pra_cima);

// troca nome na coluna de indice
document.getElementById( indice_atual ).innerHTML= camada_troca;
document.getElementById( indice_troca ).innerHTML= camada_atual;

// troca imagens

// troca imagens
var foto_ico = document.frmfoto.hdimagem.value;
var foto_ico2 = "images/imi/ico/foto.gif"; //document.frmfoto.hdimagem2.value;

var elemento = document.getElementById(indice_troca);
elemento.style.backgroundImage = eval("\"url("+foto_ico+")\"");

var elemento2 = document.getElementById(indice_atual);
elemento2.style.backgroundImage = eval("\"url("+foto_ico2+")\"");



//var ele_sel = "linha_sel_camada_"+num;
//var ele_sel2 = "linha_sel_camada_"+num2;
//var foto_ico = document.getElementById( ele_sel2 ).innerHTML;//document.frmfoto.hdimagem.value;
//var foto_ico2 = document.getElementById( ele_sel ).innerHTML;//"images/imi/ico/foto.gif"; //document.frmfoto.hdimagem2.value;

//var elemento = document.getElementById(indice_troca);
//elemento.style.backgroundImage = eval("\"url("+foto_ico+")\"");

//var elemento2 = document.getElementById(indice_atual);
//elemento2.style.backgroundImage = eval("\"url("+foto_ico2+")\"");



}
function baixo2(indice_atual){

// pega nome camada atual
var camada_atual = document.getElementById( indice_atual ).innerHTML;

// pega indice camada atual
var ind_pra_cima = document.getElementById(camada_atual).style.zIndex;

// pega numero ultimo caracter nome camada
var num = indice_atual.substr(19,20);

// cria nome da camada de troca 
num = parseInt(num);
num = num + 1;
var indice_troca = indice_atual.substr(0,19)+num;

// pega nome camada troca
var camada_troca = document.getElementById( indice_troca ).innerHTML;

//pega indice camada de troca
var ind_pra_baixo = document.getElementById(camada_troca).style.zIndex;

// troca indices
document.getElementById(camada_atual).style.zIndex= ind_pra_baixo;
document.getElementById(camada_troca).style.zIndex= ind_pra_cima;
dd.elements[camada_atual].setZ(ind_pra_baixo);
dd.elements[camada_troca].setZ(ind_pra_cima);

// troca nome na coluna de indice
document.getElementById( indice_atual ).innerHTML= camada_troca;
document.getElementById( indice_troca ).innerHTML= camada_atual;

// troca imagens
var foto_ico = document.frmfoto.hdimagem.value;
var foto_ico2 = "images/imi/ico/foto.gif"; //document.frmfoto.hdimagem2.value;

var elemento = document.getElementById(indice_troca);
elemento.style.backgroundImage = eval("\"url("+foto_ico+")\"");

var elemento2 = document.getElementById(indice_atual);
elemento2.style.backgroundImage = eval("\"url("+foto_ico2+")\"");

}

///// efeitos

function efeitos(url) 
{ 

req = null; 
// Procura por um objeto nativo (Mozilla/Safari) 
if (window.XMLHttpRequest) { 
req = new XMLHttpRequest(); 
req.onreadystatechange = processReqChange; 
req.open("GET",url,true); 
req.send(null); 
// Procura por uma versão ActiveX (IE) 
} else if (window.ActiveXObject) { 
req = new ActiveXObject("Microsoft.XMLHTTP"); 
if (req) { 

req.onreadystatechange = processReqChange; 
req.open("GET",url,true); 

req.send(); 
} 
} 
} 

function processReqChange() 
{ 

// apenas quando o estado for "completado" 
if (req.readyState == 4) { 

// apenas se o servidor retornar "OK" 

if (req.status ==200) { 

// procura pela div id="pagina" e insere o conteudo 
// retornado nela, como texto HTML 

document.getElementById('foto_user').src = req.responseText;

} else { 
alert("Houve um problema ao obter os dados:n" + req.statusText); 
} 
} 
} 

