var text_count=0;
var text_area_count=0;
var checkbox_count=0;
var radio_count=0;
var jumpmenu_count=0;
var objecto_caixa_count=1;
var formulario=0;
var layout;
var element_posicao;
var current_element;
var previous_element;
var datePickerController_hack=0;
var hora;
var minuto;
var tempo_flag=0;
var crossobj;
var id_formulario_global=0;
var pagina_actual_init_entradas=0;


/*ligar = ligacao();
ligar.open("POST","/mod/formularios/processos/form_inserir.php",true);
//ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//ligar.setRequestHeader("Content-length", info.lenght);
//ligar.setRequestHeader("Connection", "close");
var valor = ligar.responseText;	
alert(valor);*/


/*window.onscroll = scroll_contentor("contentor_objectos");
function scroll_contentor(valor){
	contentor_objectos=document.getElementById(valor);
	contentor_objectos.style.top = document.body.scrollTop;
}*/

/*Droppables.add("secondlist",{accept:'green', hoverclass:'orange', onDrop:function(element){new Ajax.Updater('secondlist', 'objecto.php', {method:'post',asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('indicator')}, onLoading:function(request){Element.show('indicator')}, parameters:'0=' + encodeURIComponent(element.id),insertion:Insertion.Bottom})}});*/
	

function init(){
	
	Droppables.add("contentor_layout",{accept:'green', onDrop:function(element){objecto(element.id,0,null)}});
Droppables.add("contentor_lixo",{accept:'objecto_caixa', onDrop:function(element){lixo(element)}});
Droppables.add("contentor_layout",{onHover:function(element){ordenar()}},{onDrop:function(element){ordenar()}});

Sortable.create("objectos_dir",
	{dropOnEmpty:true,handle:'handle',/*containment:["firstlist","secondlist"],*/constraint:false});
Sortable.create("objectos_esq",
	{dropOnEmpty:true,handle:'handle',/*containment:["firstlist","secondlist"],*/constraint:false});

	layout=document.getElementById("layout");

	ligar = ligacao();
	ligar.open("GET","/mod/formularios/processos/form_inserir.php",false);
	ligar.send(null);
	var dados=ligar.responseXML;
	
	objecto_caixa_count=1;	
	
	formulario=dados.getElementsByTagName("id")[0].firstChild.nodeValue;
	nome=dados.getElementsByTagName("nome")[0].firstChild.nodeValue;
	descricao=dados.getElementsByTagName("descricao")[0].firstChild.nodeValue;
	var layout_titulo_nome=document.getElementById("layout_titulo_nome");
	var layout_titulo_descricao=document.getElementById("layout_titulo_descricao");
	layout_titulo_nome.innerHTML=nome;
	layout_titulo_descricao.innerHTML=descricao;
	
	var cabecalho_input_publicar=document.getElementById('cabecalho_input_publicar');
	cabecalho_input_publicar.innerHTML="<input name='guardar' type='button' value='Guardar' onClick='javascript:listar_admin_guardar();' /><input name='publicar' type='button' value='Publicar' onClick='javascript:init_publicar("+formulario+");' />"
	
}
function init_formulario_editar(valor){
	formulario=valor;
	objecto_caixa_count=1;	
	info="0="+valor;
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/editar_query.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	var dados=ligar.responseXML;	
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/construcao.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(null);
	var valor = ligar.responseText;
	document.getElementById('centro').innerHTML=valor;
	layout=document.getElementById("layout");
	
	Droppables.add("contentor_layout",{accept:'green', onDrop:function(element){objecto(element.id,0,null)}});
Droppables.add("contentor_lixo",{accept:'objecto_caixa', onDrop:function(element){lixo(element)}});
Droppables.add("contentor_layout",{onHover:function(element){ordenar()}},{onDrop:function(element){ordenar()}});

Sortable.create("objectos_dir",
	{dropOnEmpty:true,handle:'handle',/*containment:["firstlist","secondlist"],*/constraint:false});
Sortable.create("objectos_esq",
	{dropOnEmpty:true,handle:'handle',/*containment:["firstlist","secondlist"],*/constraint:false});	

	var titulo=dados.getElementsByTagName("titulo")[0];
	var nome=titulo.firstChild.firstChild.nodeValue;	
	var descricao=titulo.lastChild.firstChild.nodeValue;
	var layout_titulo_nome=document.getElementById("layout_titulo_nome");
	var layout_titulo_descricao=document.getElementById("layout_titulo_descricao");
	layout_titulo_nome.innerHTML=nome;
	layout_titulo_descricao.innerHTML=descricao;
	
	if(dados.getElementsByTagName("objectos")[0].hasChildNodes()){
		var objectos=dados.getElementsByTagName("objectos")[0];
		var objectos_childNodes=objectos.childNodes;
		for(var i=0;i<objectos_childNodes.length;i++){
			tipo=objectos_childNodes[i].childNodes[1].firstChild.nodeValue;
			objecto(tipo,1,objectos_childNodes[i]);
		}
		objecto_caixa_count=objectos.lastChild.childNodes[6].firstChild.nodeValue;
		objecto_caixa_count++;
	}

	var cabecalho_input_publicar=document.getElementById('cabecalho_input_publicar');
		cabecalho_input_publicar.innerHTML="<input name='guardar' type='button' value='Guardar' onClick='javascript:listar_admin_guardar();' /><input name='publicar' type='button' value='Publicar' onClick='javascript:init_publicar("+formulario+");' />"	
}
function init_publicar(form){
	formulario=form;
	clearInterval(intervalo);
	carregar('visible');
	ligar = ligacao();
	ligar.open("GET","/mod/pesquisa/utente.php",false);
	ligar.setRequestHeader("Connection", "close");		
	ligar.send(null);
	var valor = ligar.responseText;
	document.getElementById("centro").innerHTML = valor;	
	//aviso_utente_grupos_actualizar(1);
	aviso_utente_grupos(1);
	carregar('hidden');
	//REMOVER PESQUISA POR UTENTE
	var tabnav = document.getElementById("tabnav");
	tabnav.parentNode.removeChild(tabnav);
	barra_utente_geral=document.getElementById('barra_utente_geral');
	barra_utente_geral.parentNode.removeChild(barra_utente_geral);
	//FIM REMOVER PESQUISA POR UTENTE
	//ALTERAR ENVIAR
	/*var enviar=document.getElementById('enviar');
	enviar.parentNode.removeChild(enviar);*/
	
	document.form2.setAttribute('action','javascript:end_publicar();');
	// FIM ALTERAR ENVIAR
	//INICIO ACTUALIZAR
	var info="0="+formulario;	
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/net/listar_admin_grupos_xml.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.length);	
	ligar.setRequestHeader("Connection", "close");	
	ligar.send(info);
	var dados	= ligar.responseXML;
	var dados=dados.getElementsByTagName('dados')[0];
	var grupos_selecionados=document.getElementById('grupos_selecionados');
	if(dados.hasChildNodes()){
		var array_posicoes=new Array("a","b","c","d","e");
		for(var c=0;c<dados.childNodes.length-1;c++){
			
			var div=document.createElement('div');
			div.setAttribute('id',c);
								
			var grupo_selecionados_class=document.createElement('div');
			grupo_selecionados_class.setAttribute('class','grupo_selecionados');

			var descricao_selecionados=document.createElement('div');
			descricao_selecionados.setAttribute('class','descricao_selecionados');
			
			descricao_selecionados.innerHTML=dados.childNodes[c].childNodes[1].firstChild.nodeValue;
			
			grupo_selecionados_class.appendChild(descricao_selecionados);
			
			var opcao_remover=document.createElement('div');
			opcao_remover.setAttribute('class','opcao_remover');
			
			var img_opcao_remover=document.createElement('img');
			img_opcao_remover.setAttribute('src','/imgs/icons/remove.png');
			img_opcao_remover.setAttribute('onclick','javascript:aviso_grupos_remover('+c+');');
			
			opcao_remover.appendChild(img_opcao_remover);
			grupo_selecionados_class.appendChild(opcao_remover);
			
			div.appendChild(grupo_selecionados_class);

			var array_grupos=dados.childNodes[c].firstChild.firstChild.nodeValue.split(',');
			for(var y=0;y<array_grupos.length;y++){
				div.setAttribute(array_posicoes[y],array_grupos[y]);
			}
			grupos_selecionados.appendChild(div);
		}
	}
	//FIM ACTUALIZAR
}
function end_publicar(){
	var grupos_selecionados=document.getElementById("grupos_selecionados");
	if(grupos_selecionados.hasChildNodes()){
		var publicar_formulario=new Array();
		var publicar_formulario_string=new Array();
		var grupos_selecionados_elements=grupos_selecionados.childNodes;
		for(i=0;i<grupos_selecionados_elements.length;i++){
			publicar_formulario[i]=new Array();
			var grupo=grupos_selecionados_elements[i].getAttribute("a")
			publicar_formulario[i][0]=grupo;
			if(grupos_selecionados_elements[i].getAttribute("b")){
				var escola=grupos_selecionados_elements[i].getAttribute("b");
				publicar_formulario[i][1]=escola;
				if(grupos_selecionados_elements[i].getAttribute("c")){
					var ciclo=grupos_selecionados_elements[i].getAttribute("c")
					publicar_formulario[i][2]=ciclo;
					if(grupos_selecionados_elements[i].getAttribute("d")){
						var ano=grupos_selecionados_elements[i].getAttribute("d")
						publicar_formulario[i][3]=ano;
						if(grupos_selecionados_elements[i].getAttribute("e")){
							var turma=grupos_selecionados_elements[i].getAttribute("e");
							publicar_formulario[i][4]=turma;
						}
					}
				}
			}
			publicar_formulario_string[i]=grupos_selecionados_elements[i].firstChild.firstChild.innerHTML;
		}
	}
	publicar_formulario=publicar_formulario.join("~");
	publicar_formulario_string=publicar_formulario_string.join("~");
	//alert(publicar_formulario);
	publicar_formulario=formulario+':'+publicar_formulario;
	//alert(publicar_formulario);
	var info="0="+publicar_formulario+"&1="+publicar_formulario_string;
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/publicar.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	listar_admin();
}

function init_entradas(id_formulario,pagina){
	id_formulario_global=id_formulario;
	pagina_actual_init_entradas=pagina;
	var registos=document.getElementById("registos");
	registos.innerHTML="";
	
	var conteudo=document.createElement('div');
	conteudo.setAttribute('id','conteudo');
	
	var conteudo_cabecalho=document.createElement('div');
	conteudo_cabecalho.setAttribute('id','conteudo_cabecalho');
	conteudo_cabecalho.setAttribute('class','conteudo_cabecalho');
	
	var conteudo_cabecalho_control_util=document.createElement('div');
	conteudo_cabecalho_control_util.setAttribute('id','conteudo_cabecalho_control_util');
	conteudo_cabecalho_control_util.setAttribute('class','conteudo_cabecalho_control_util');
	conteudo_cabecalho_control_util.innerHTML="# ";
	
	var conteudo_cabecalho_dados=document.createElement('div');
	conteudo_cabecalho_dados.setAttribute('id','conteudo_cabecalho_dados');
	conteudo_cabecalho_dados.setAttribute('class','conteudo_cabecalho_dados');
	conteudo_cabecalho_dados.innerHTML="Entradas";

	
	conteudo_cabecalho.appendChild(conteudo_cabecalho_control_util);
	conteudo_cabecalho.appendChild(conteudo_cabecalho_dados);

	var conteudo_registos=document.createElement('form');
	conteudo_registos.setAttribute('id','conteudo_registos');
	conteudo_registos.setAttribute('name','conteudo_registos');
	conteudo.appendChild(conteudo_cabecalho);
	conteudo.appendChild(conteudo_registos);
	
	registos.appendChild(conteudo);
		
	var navegar_listar_admin=document.createElement("div");
	navegar_listar_admin.setAttribute("id","navegar_listar_admin")	
	
	registos.appendChild(navegar_listar_admin);	
	
	registos.appendChild(conteudo);
	
	var navegar_listar_admin_paginacao=document.createElement("div");
	navegar_listar_admin_paginacao.setAttribute("id","navegar_listar_admin_paginacao");
	
	navegar_listar_admin.appendChild(navegar_listar_admin_paginacao);	
	
	removerChildNodes(document.getElementById("cabecalho").firstChild);
	
	document.getElementById("cabecalho").firstChild.innerHTML="<input name='Voltar' type='button' value='Voltar' onClick='javascript:listar_admin();' />";
	
	if(pagina!=null){
		var primeiro_ultimo=((pagina*10)-10);
		primeiro=primeiro_ultimo;
	}
	else{
		primeiro=0;
	}
	var info="0="+id_formulario_global+"&1="+primeiro;
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/entradas_query.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	var dados=ligar.responseXML;
	
	dados=dados.getElementsByTagName('dados')[0];
	var nreg=dados.lastChild.firstChild.nodeValue;
	var conta = nreg / 10;
	var conta_inteira = Math.ceil(conta); 
	//var primeiro;
	var um;
	if(pagina==null){
		//INICIO NAVEGAR REGISTOS
		conta_ultimo_listar_admin=conta_inteira;
		conta_primeiro=1;
		
		if(conta_ultimo_listar_admin>3){
			conta_ultimo_listar_admin=3;
		}
		for(um=1;um<=conta_ultimo_listar_admin;um++){
			var nodo_texto_registo=document.createTextNode(um);
			var div_texto_registo=document.createElement("div");
			if(um!=1){
				div_texto_registo.setAttribute("class","div_texto_registo");
				div_texto_registo.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + um + "');");
			}
			if(um==1){
				div_texto_registo.setAttribute("class","div_texto_registo div_texto_registo_selecionado");
				div_texto_registo.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + um + "');");
				pagina=um;
			}
			div_texto_registo.appendChild(nodo_texto_registo);
			navegar_listar_admin_paginacao.appendChild(div_texto_registo);
		}
		if(conta_inteira>3){
			var nodo_texto_registo_ultimo=document.createTextNode(conta_inteira);
			var div_texto_registo_ultimo=document.createElement("div");
			div_texto_registo_ultimo.setAttribute("class","div_texto_registo");
			div_texto_registo_ultimo.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + conta_inteira + "');");
			div_texto_registo_ultimo.appendChild(nodo_texto_registo_ultimo);
			var nodo_texto_registo_ultimo_reticencias=document.createTextNode("...");
			navegar_listar_admin_paginacao.appendChild(nodo_texto_registo_ultimo_reticencias);
			navegar_listar_admin_paginacao.appendChild(div_texto_registo_ultimo);
		}
	}
	else{
		pagina=parseInt(pagina);
		//INICIO MOVIMENTO DO CRUSOR NA NAVEGACAO
		if(pagina==1){
			if(conta_inteira==2){
				um=1;
				conta_ultimo_listar_admin=2;
			}
			else{
				um=1;
				conta_ultimo_listar_admin=pagina+2;
			}
		}
		else{
			if(conta_inteira==2){
				conta_ultimo_listar_admin=2;
				um=1;
			}
			else if(pagina==conta_inteira){
				conta_ultimo_listar_admin=pagina;
				um=conta_ultimo_listar_admin-2;
			}
			else{
				um=pagina-1;
				conta_ultimo_listar_admin=pagina+1;
			}
		}
		//FIM MOVIMENTO DO CRUSOR NA NAVEGACAO
		if(um>1){
			var nodo_texto_registo_primeiro=document.createTextNode("1");
			var nodo_texto_registo_primeiro_reticencias=document.createTextNode("...");
			var div_texto_registo_primeiro=document.createElement("div");
			div_texto_registo_primeiro.setAttribute("class","div_texto_registo");
			div_texto_registo_primeiro.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + 1 + "');");
			div_texto_registo_primeiro.appendChild(nodo_texto_registo_primeiro);
			navegar_listar_admin_paginacao.appendChild(div_texto_registo_primeiro);
			navegar_listar_admin_paginacao.appendChild(nodo_texto_registo_primeiro_reticencias);
		}
		for(primeiro=um;primeiro<=conta_ultimo_listar_admin;primeiro++){
			var nodo_texto_registo=document.createTextNode(primeiro);
			var div_texto_registo=document.createElement("div");
			if(primeiro!=pagina){
				div_texto_registo.setAttribute("class","div_texto_registo");
				div_texto_registo.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + primeiro + "');");
			}
			if(primeiro==pagina){
				div_texto_registo.setAttribute("class","div_texto_registo div_texto_registo_selecionado");
				div_texto_registo.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + primeiro + "');");
			}
			div_texto_registo.appendChild(nodo_texto_registo);
			navegar_listar_admin_paginacao.appendChild(div_texto_registo);
		}
		//FIM NAVEGAR REGISTOS
		if((conta_ultimo_listar_admin)<conta_inteira){			
			var nodo_texto_registo_primeiro=document.createTextNode(conta_inteira);
			var div_texto_registo_primeiro=document.createElement("div");
			div_texto_registo_primeiro.setAttribute("class","div_texto_registo");
			div_texto_registo_primeiro.setAttribute("onclick","javascript:init_entradas('"+id_formulario_global+"','" + conta_inteira + "');");
			div_texto_registo_primeiro.appendChild(nodo_texto_registo_primeiro);
			var nodo_texto_registo_primeiro_reticencias=document.createTextNode("...");
			navegar_listar_admin_paginacao.appendChild(nodo_texto_registo_primeiro_reticencias);
			navegar_listar_admin_paginacao.appendChild(div_texto_registo_primeiro);
		}		
	}	
	var dados_childNodes=dados.firstChild.childNodes;
	var entradas;
	var resultado=pagina*10;
	resultado=resultado-10;	
	for(var i=0;i<dados_childNodes.length;i++){
		var id=dados_childNodes[i].firstChild.firstChild.nodeValue;	
		var conteudo_registos_linha_util=document.createElement('div');
		conteudo_registos_linha_util.setAttribute('id','conteudo_registos_linha_util');	
		conteudo_registos_linha_util.setAttribute('class','conteudo_registos_linha_util');
		conteudo_registos_linha_util.setAttribute("onclick","javascript:init_entradas_registo('"+id_formulario_global+"','" + id + "');");
		conteudo_registos_linha_util.setAttribute('value',id);	
		conteudo_registos.appendChild(conteudo_registos_linha_util);

		var conteudo_registos_linha_util_dados=document.createElement('div');
		conteudo_registos_linha_util_dados.setAttribute('id','conteudo_registos_linha_util_dados');
		conteudo_registos_linha_util_dados.setAttribute('class','conteudo_registos_linha_util_dados');

		var conteudo_registos_linha_util_dados_numeracao=document.createElement('div');
		conteudo_registos_linha_util_dados_numeracao.setAttribute('class','conteudo_registos_linha_util_dados_numeracao');
		resultado++;
		conteudo_registos_linha_util_dados_numeracao.innerHTML=resultado;

		var conteudo_registos_linha_dados_texto=document.createElement('div');
		conteudo_registos_linha_dados_texto.setAttribute('class','conteudo_registos_linha_dados_texto');
		
		var conteudo_registos_linha_dados_nome=document.createElement('div');
		conteudo_registos_linha_dados_nome.setAttribute('class','conteudo_registos_linha_dados_nome');
		
		if(dados_childNodes[i].childNodes[1].hasChildNodes()){		
			conteudo_registos_linha_dados_texto.innerHTML=dados_childNodes[i].childNodes[1].firstChild.nodeValue;
			//conteudo_registos_linha_dados_texto.setAttribute('onclick','preencheform('+id+')');			
		}
		if(dados_childNodes[i].lastChild.hasChildNodes()){		
			conteudo_registos_linha_dados_nome.innerHTML=dados_childNodes[i].lastChild.firstChild.nodeValue;
			//conteudo_registos_linha_dados_texto.setAttribute('onclick','preencheform('+id+')');			
		}
		
		conteudo_registos_linha_util_dados.appendChild(conteudo_registos_linha_util_dados_numeracao);
		conteudo_registos_linha_util_dados.appendChild(conteudo_registos_linha_dados_texto);
		conteudo_registos_linha_util_dados.appendChild(conteudo_registos_linha_dados_nome);
		conteudo_registos_linha_util.appendChild(conteudo_registos_linha_util_dados);	
	}	
}
function init_entradas_registo(id_formulario_global,id){
	info="0="+id_formulario_global+"&1="+id;
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/net/preencher_form_util.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	
	var xmldoc=ligar.responseXML;
	//alert(xmldoc.getElementsByTagName("dados")[0].getElementsByTagName("corpo")[0].getElementsByTagName("linha")[0].getElementsByTagName("tipo")[0].firstChild.nodeValue);
	var dados=xmldoc.getElementsByTagName("dados")[0];
	var cab = dados.getElementsByTagName("cab")[0];
	var id=cab.getElementsByTagName("id")[0].firstChild.nodeValue;
	var nome=cab.getElementsByTagName("nome")[0].firstChild.nodeValue;
	var descricao=cab.getElementsByTagName("descricao")[0].firstChild.nodeValue;
	
	var registos=document.getElementById("registos");
	registos.innerHTML="";
	
	var registos_cab=document.createElement('div');
	registos_cab.setAttribute('id','registos_cab');
	registos_cab.setAttribute('class','registos_cab');
	registos.appendChild(registos_cab);
	var registos_cab_titulo=document.createElement('div');
	registos_cab_titulo.setAttribute('id','registos_cab_titulo');
	registos_cab_titulo.setAttribute('class','registos_cab_titulo');
	registos_cab_titulo.innerHTML=nome;
	registos_cab.appendChild(registos_cab_titulo);
	var registos_cab_descricao=document.createElement('div');
	registos_cab_descricao.setAttribute('id','registos_cab_descricao');
	registos_cab_descricao.setAttribute('class','registos_cab_descricao');
	registos_cab_descricao.innerHTML=descricao;
	registos_cab.appendChild(registos_cab_descricao);
	
	var registos_corpo=document.createElement('div');
	registos_corpo.setAttribute('id','registos_corpo');
	registos_corpo.setAttribute('class','registos_corpo');
	registos.appendChild(registos_corpo);
	
	removerChildNodes(document.getElementById("cabecalho").firstChild);
	
	document.getElementById("cabecalho").firstChild.innerHTML="<input name='Voltar' type='button' value='Voltar' onClick='javascript:init_entradas(id_formulario_global,pagina_actual_init_entradas);' /><input name='Imprimir Registo' type='button' value='Imprimir Registo' onClick='javascript:printer();' />";	
	
	var corpo = dados.getElementsByTagName("corpo")[0];
	
	var titulo;
	var tamanho;
	var tipo;
	var posicao;
	var objecto;
	var obrigatorio;
	if(corpo.hasChildNodes()){ //se houver filhos "linha"
		for(var x=0;x<corpo.childNodes.length;x++){
			objecto=corpo.childNodes[x].getElementsByTagName("id_objecto")[0].firstChild.nodeValue;	
			posicao=corpo.childNodes[x].getElementsByTagName("posicao")[0].firstChild.nodeValue;
			tipo=corpo.childNodes[x].getElementsByTagName("tipo")[0].firstChild.nodeValue;
			tamanho=corpo.childNodes[x].getElementsByTagName("tamanho")[0].firstChild.nodeValue;
			if(corpo.childNodes[x].getElementsByTagName("titulo")[0].hasChildNodes()){
				titulo=corpo.childNodes[x].getElementsByTagName("titulo")[0].firstChild.nodeValue;
			}
			else{
				titulo="";	
			}
			obrigatorio=corpo.childNodes[x].getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
			
			
			var registos_corpo_obj=document.createElement('div');
			registos_corpo_obj.setAttribute('class','registos_corpo_obj');
			registos_corpo_obj.setAttribute('id',objecto);
			registos_corpo_obj.setAttribute('posicao',posicao);
			registos_corpo.appendChild(registos_corpo_obj);
			
			obj_caixa_geral=document.createElement("div");
			obj_caixa_geral.setAttribute('class',"obj_caixa_geral");
			registos_corpo_obj.appendChild(obj_caixa_geral);
			obj_caixa_informacao=document.createElement("div");

			registos_corpo_obj.appendChild(obj_caixa_informacao);
			if(corpo.childNodes[x].getElementsByTagName("info")[0].hasChildNodes()){
				obj_caixa_informacao.innerHTML=corpo.childNodes[x].getElementsByTagName("info")[0].firstChild.nodeValue;
				obj_caixa_informacao.setAttribute('class',"obj_caixa_informacao obj_caixa_informacao_none");
				obj_caixa_geral.setAttribute('onmouseover',"onmouseover_object(this)");
				obj_caixa_geral.setAttribute('onmouseout',"onmouseout_object(this)");
			}
			
			obj_titulo=document.createElement("div");
			obj_titulo.setAttribute('class',"obj_titulo");
			obj_caixa_geral.appendChild(obj_titulo);
			obj_titulo.innerHTML=titulo;
			
			if(tipo!="radio" || tipo!="jumpmenu" || tipo!="nome"){
				if(obrigatorio==1){
					asterisco=document.createElement("div");
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *";
					obj_titulo.appendChild(asterisco);
					registos_corpo_obj.setAttribute('obrigatorio',1);
				}
				else{
					registos_corpo_obj.setAttribute('obrigatorio',0);
				}
			}
			if(tipo=='text'){
				var objecto_text_caixa=document.createElement("div");
				objecto_text_caixa.setAttribute('class','objecto_text_caixa');
				text_count=text_count+1;
				var input=document.createElement("input");
				input.setAttribute('name',text_count);
				input.setAttribute('id',"text_"+text_count);
				if(tamanho==1){
					input.setAttribute('class','textfield_small');
				}
				else if(tamanho==2){
					input.setAttribute('class','textfield_medium');
				}
				else if(tamanho==3){
					input.setAttribute('class','textfield_large');
				}
				input.setAttribute('type','text');
				input.setAttribute('disabled','disabled');
				if(corpo.childNodes[x].getElementsByTagName("default_text")[0].hasChildNodes()){
					input.value=corpo.childNodes[x].getElementsByTagName("default_text")[0].firstChild.nodeValue;
				}
				objecto_text_caixa.appendChild(input);
				obj_caixa_geral.appendChild(objecto_text_caixa);
				registos_corpo_obj.setAttribute('type','text');
			}
			else if(tipo=='text_area'){
				var objecto_text_area_caixa=document.createElement("div");
				objecto_text_area_caixa.setAttribute('class','objecto_text_area_caixa');
				text_area_count=text_area_count+1;
				var input=document.createElement("textarea");
				input.setAttribute('name',text_area_count);
				input.setAttribute('id',"text_area_"+text_area_count);
				if(tamanho==1){
					input.setAttribute('class','textarea_small');
				}
				else if(tamanho==2){
					input.setAttribute('class','textarea_medium');
				}
				else if(tamanho==3){
					input.setAttribute('class','textarea_large');
				}
				input.setAttribute('type','text_area');
				input.setAttribute('disabled','disabled');
				if(corpo.childNodes[x].getElementsByTagName("default_text")[0].hasChildNodes()){
					input.value=corpo.childNodes[x].getElementsByTagName("default_text")[0].firstChild.nodeValue;
				}
				objecto_text_area_caixa.appendChild(input);
				obj_caixa_geral.appendChild(objecto_text_area_caixa);
				registos_corpo_obj.setAttribute('type','text_area');
			}
			else if(tipo=='checkbox'){
				var objecto_checkbox_caixa=document.createElement("div");
				objecto_checkbox_caixa.setAttribute('class','objecto_checkbox_caixa_ver');
				total=corpo.childNodes[x].getElementsByTagName("filhos")[0].childNodes.length;
				var form=document.createElement('form');
				form.setAttribute('name','checkbox');
				obj_caixa_geral.appendChild(objecto_checkbox_caixa);
				for(var c=0;c<total;c++){ //total= num de "detalhes"
					var selecionado=corpo.childNodes[x].lastChild.childNodes[c].lastChild.firstChild.nodeValue;
					var objecto_checkbox_caixa_input=document.createElement("div");
					objecto_checkbox_caixa_input.setAttribute('class','objecto_checkbox_caixa_input');
					checkbox_count=checkbox_count+1;
					var input=document.createElement("input");
					input.setAttribute('name',checkbox_count);
					input.setAttribute('id',"checkbox_"+checkbox_count);
					input.setAttribute('type','checkbox');
					input.setAttribute('value',c);
					input.setAttribute('disabled','disabled');
					input.setAttribute('class','objecto_checkbox_caixa_input_value');
					objecto_checkbox_caixa_input.appendChild(input); //cria uma div e desenha a checkbox
					var objecto_checkbox_caixa_input_label=document.createElement("div");
					objecto_checkbox_caixa_input_label.setAttribute('class','objecto_checkbox_caixa_input_label');
					if(corpo.childNodes[x].lastChild.childNodes[c].childNodes[1].hasChildNodes()){
						objecto_checkbox_caixa_input_label.innerHTML=corpo.childNodes[x].lastChild.childNodes[c].childNodes[1].firstChild.nodeValue;
					}
					objecto_checkbox_caixa_input.appendChild(objecto_checkbox_caixa_input_label);
					form.appendChild(objecto_checkbox_caixa_input);
					objecto_checkbox_caixa.appendChild(form);
					if(c==selecionado){					
						input.setAttribute('checked','checked');
					}
				}
				registos_corpo_obj.setAttribute('type','checkbox');
			}
			else if(tipo=='radio'){
				var objecto_radio_caixa=document.createElement("div");
				objecto_radio_caixa.setAttribute('class','objecto_radio_caixa_ver');
				total=corpo.childNodes[x].getElementsByTagName("filhos")[0].childNodes.length;
				var form=document.createElement('form');
				form.setAttribute('name','radio');
				obj_caixa_geral.appendChild(objecto_radio_caixa);
				var selecionado=corpo.childNodes[x].getElementsByTagName("selecionado")[0].firstChild.nodeValue;
				for(var c=0;c<total;c++){
					var posicao=corpo.childNodes[x].lastChild.childNodes[c].firstChild.firstChild.nodeValue;
					var objecto_radio_caixa_input=document.createElement("div");
					objecto_radio_caixa_input.setAttribute('class','objecto_radio_caixa_input');
					radio_count=radio_count+1;
					var input=document.createElement("input");
					input.setAttribute('name','radio'+objecto);
					input.setAttribute('id',"radio_"+radio_count);
					input.setAttribute('value',c);
					input.setAttribute('type','radio');
					input.setAttribute('disabled','disabled');
					input.setAttribute('class','objecto_radio_caixa_input_value');
					objecto_radio_caixa_input.appendChild(input);
					var objecto_radio_caixa_input_label=document.createElement("div");
					objecto_radio_caixa_input_label.setAttribute('class','objecto_radio_caixa_input_label');
					if(corpo.childNodes[x].lastChild.childNodes[c].lastChild.hasChildNodes()){
						objecto_radio_caixa_input_label.innerHTML=corpo.childNodes[x].lastChild.childNodes[c].lastChild.firstChild.nodeValue;
					}
					objecto_radio_caixa_input.appendChild(objecto_radio_caixa_input_label);
					form.appendChild(objecto_radio_caixa_input);
					objecto_radio_caixa.appendChild(form);
					if(c==selecionado){
						input.setAttribute('checked','checked');
					}
				}
				registos_corpo_obj.setAttribute('type','radio');
			}
			else if(tipo=="quebra"){
				var objecto_quebra_caixa=document.createElement("div");
				objecto_quebra_caixa.setAttribute('class','objecto_quebra_caixa');
				var objecto_quebra_caixa_descricao=document.createElement("div");
				objecto_quebra_caixa_descricao.setAttribute('id','objecto_quebra_caixa_descricao');
				if(corpo.childNodes[x].getElementsByTagName("descr_quebra")[0].hasChildNodes()){
					objecto_quebra_caixa_descricao.innerHTML=corpo.childNodes[x].getElementsByTagName("descr_quebra")[0].firstChild.nodeValue;
				}
				objecto_quebra_caixa.appendChild(objecto_quebra_caixa_descricao);
				obj_caixa_geral.appendChild(objecto_quebra_caixa);
				registos_corpo_obj.setAttribute('type','quebra');
			}
			else if(tipo=="jumpmenu"){
				var objecto_jumpmenu_caixa=document.createElement("div");
				objecto_jumpmenu_caixa.setAttribute('class','objecto_jumpmenu_caixa');
				var input=document.createElement("select");
				input.setAttribute('name',jumpmenu_count);
				input.setAttribute('id',"jumpmenu_"+jumpmenu_count);
				input.setAttribute('disabled','disabled');	
				if(tamanho==1){
					input.setAttribute('class','jumpmenu_small');
				}
				else if(tamanho==2){
					input.setAttribute('class','jumpmenu_medium');
				}
				else if(tamanho==3){
					input.setAttribute('class','jumpmenu_large');
				}
				total=corpo.childNodes[x].getElementsByTagName("filhos")[0].childNodes.length;
				objecto_jumpmenu_caixa.appendChild(input);
				obj_caixa_geral.appendChild(objecto_jumpmenu_caixa);
				registos_corpo_obj.setAttribute('type','jumpmenu');
				
				for(var c=0;c<total;c++){
					if(corpo.childNodes[x].lastChild.childNodes[c].lastChild.hasChildNodes()){
						var option=document.createElement("option");
						option.setAttribute('value',c);
						option.innerHTML=corpo.childNodes[x].lastChild.childNodes[c].lastChild.firstChild.nodeValue;
						input.appendChild(option);
					}
				}
				if(corpo.childNodes[x].getElementsByTagName("selecionado")[0].hasChildNodes()){
					var selecionado=corpo.childNodes[x].getElementsByTagName("selecionado")[0].firstChild.nodeValue;
					var option=document.createElement("option");
					option.setAttribute('value',c);
					input.options[selecionado].selected=true;
				}	
			}
		
			else if(tipo=='nome'){
				//var tiponome=corpo.childNodes[x].getElementsByTagName("tiponome")[0].firstChild.nodeValue;
				var objecto_nome_caixa=document.createElement("div");
				objecto_nome_caixa.setAttribute('class','objecto_nome_caixa');
				//objecto_nome_caixa.setAttribute('tipo',tiponome);
				var nome;
				if(corpo.childNodes[x].getElementsByTagName("nome")[0].hasChildNodes()){
					nome=corpo.childNodes[x].getElementsByTagName("nome")[0].firstChild.nodeValue;	
				}
				else{
					nome="";	
				}
				var input_nome=document.createElement("input")
				input_nome.setAttribute('name','input_nome');
				input_nome.setAttribute('id','input_nome');
				input_nome.setAttribute('disabled','disabled');
				input_nome.setAttribute('type','text');
				input_nome.setAttribute('class','textfield_large');
				nome=html_entity_decode(nome);
				input_nome.value=nome;
				objecto_nome_caixa.appendChild(input_nome);
				
				var objecto_nome_text=document.createElement("div");
				objecto_nome_text.setAttribute('class','objecto_nome_text');
				objecto_nome_text.innerHTML="Nome Completo";
				
				objecto_nome_caixa.appendChild(objecto_nome_text);
				
				obj_caixa_geral.appendChild(objecto_nome_caixa);
				registos_corpo_obj.setAttribute('type','nome');
			}
			else if(tipo=='data'){
		
				var objecto_data_caixa=document.createElement("div");
				objecto_data_caixa.setAttribute('class','objecto_data_caixa');
				
				var objecto_data_ano_hiffen=document.createElement("div");
				objecto_data_ano_hiffen.setAttribute('class','objecto_data_ano_hiffen');
				objecto_data_ano_hiffen.innerHTML='/';
				
				var objecto_data_mes_hiffen=document.createElement("div");
				objecto_data_mes_hiffen.setAttribute('class','objecto_data_mes_hiffen');
				objecto_data_mes_hiffen.innerHTML='/';
				
				var objecto_data_dia=document.createElement("div");
				objecto_data_dia.setAttribute('class','objecto_data_dia');
				var input_data_dia=document.createElement("input")
				input_data_dia.setAttribute('name','input_data_dia');
				input_data_dia.setAttribute('class','input_data_dia');
				input_data_dia.setAttribute('id','input_data_dia');
				input_data_dia.setAttribute('disabled','disabled');
				input_data_dia.setAttribute('type','text');
				var objecto_data_dia_text=document.createElement("div");
				objecto_data_dia_text.setAttribute('class','objecto_data_dia_text');
				objecto_data_dia_text.innerHTML="Dia";
				objecto_data_dia.appendChild(input_data_dia);
				objecto_data_dia.appendChild(objecto_data_dia_text);
				objecto_data_caixa.appendChild(objecto_data_dia);
						
				var objecto_data_mes=document.createElement("div");
				objecto_data_mes.setAttribute('class','objecto_data_mes');
				var input_data_mes=document.createElement("input")
				input_data_mes.setAttribute('name','input_data_mes');
				input_data_mes.setAttribute('id','input_data_mes');
				input_data_mes.setAttribute('class','input_data_mes');
				input_data_mes.setAttribute('disabled','disabled');
				input_data_mes.setAttribute('type','text');
				var objecto_data_mes_text=document.createElement("div");
				objecto_data_mes_text.setAttribute('class','objecto_data_mes_text');
				objecto_data_mes_text.innerHTML="M&ecirc;s";
				objecto_data_mes.appendChild(input_data_mes);
				objecto_data_mes.appendChild(objecto_data_mes_hiffen);
				objecto_data_mes.appendChild(objecto_data_mes_text);
				objecto_data_caixa.appendChild(objecto_data_mes);
				
				
				var objecto_data_ano=document.createElement("div");
				objecto_data_ano.setAttribute('class','objecto_data_ano');
				var input_data_ano=document.createElement("input")
				input_data_ano.setAttribute('name','input_data_ano');
				input_data_ano.setAttribute('id','input_data_ano');
				input_data_ano.setAttribute('class','input_data_ano');
				input_data_ano.setAttribute('disabled','disabled');
				input_data_ano.setAttribute('type','text');
				var objecto_data_ano_text=document.createElement("div");
				objecto_data_ano_text.setAttribute('class','objecto_data_ano_text');
				objecto_data_ano_text.innerHTML="Ano";
				objecto_data_ano.appendChild(input_data_ano);
				objecto_data_ano.appendChild(objecto_data_ano_hiffen);
				objecto_data_ano.appendChild(objecto_data_ano_text);
				objecto_data_caixa.appendChild(objecto_data_ano);
				
				if(corpo.childNodes[x].getElementsByTagName("data")[0].hasChildNodes()){
					var data=corpo.childNodes[x].getElementsByTagName("data")[0].firstChild.nodeValue;
					var data_array=data.split('-');
					input_data_dia.value=data_array[0];
					input_data_mes.value=data_array[1];
					input_data_ano.value=data_array[2];
				}
				
				var input_data_hidden=document.createElement("div");
				input_data_hidden.setAttribute('class','editar_data_hidden');
				input_data_hidden.setAttribute('id','editar_data_valor_hidden');
				
				input_datepicker=document.createElement('input');
				input_datepicker.setAttribute('type','text');
				input_datepicker.setAttribute('value','');
				input_datepicker.setAttribute('style','display:none');
				input_data_hidden.appendChild(input_datepicker);
				objecto_data_caixa.appendChild(input_data_hidden);
				obj_caixa_geral.appendChild(objecto_data_caixa);
				registos_corpo_obj.setAttribute('type','data');		
			}
			else if(tipo=='tempo'){
			
				var objecto_tempo_caixa=document.createElement("div");
				objecto_tempo_caixa.setAttribute('class','objecto_tempo_caixa');
				
				var objecto_tempo_segundo_hiffen=document.createElement("div");
				objecto_tempo_segundo_hiffen.setAttribute('class','objecto_tempo_segundo_hiffen');
				objecto_tempo_segundo_hiffen.innerHTML=':';
				
				var objecto_tempo_minuto_hiffen=document.createElement("div");
				objecto_tempo_minuto_hiffen.setAttribute('class','objecto_tempo_minuto_hiffen');
				objecto_tempo_minuto_hiffen.innerHTML=':';
				
				var objecto_tempo_hora=document.createElement("div");
				objecto_tempo_hora.setAttribute('class','objecto_tempo_hora');
				var input_tempo_hora=document.createElement("input");
				input_tempo_hora.setAttribute('class','input_tempo_hora');
				input_tempo_hora.setAttribute('id','input_tempo_hora'+objecto);
				//input_tempo_hora.setAttribute('disabled','disabled');
				input_tempo_hora.setAttribute('maxlength','2');
				input_tempo_hora.setAttribute('onkeyup',"javascript:validar(this,"+objecto+")");
				input_tempo_hora.setAttribute('type','text');
				input_tempo_hora.setAttribute('disabled','disabled');
				var objecto_tempo_hora_text=document.createElement("div");
				objecto_tempo_hora_text.setAttribute('class','objecto_tempo_hora_text');
				objecto_tempo_hora_text.innerHTML="HH";
				objecto_tempo_hora.appendChild(input_tempo_hora);
				objecto_tempo_hora.appendChild(objecto_tempo_hora_text);
				objecto_tempo_caixa.appendChild(objecto_tempo_hora);
						
				var objecto_tempo_minuto=document.createElement("div");
				objecto_tempo_minuto.setAttribute('class','objecto_tempo_minuto');
				var input_tempo_minuto=document.createElement("input")
				input_tempo_minuto.setAttribute('name','input_tempo_minuto');
				input_tempo_minuto.setAttribute('id','input_tempo_minuto'+objecto);
				input_tempo_minuto.setAttribute('class','input_tempo_minuto');
				//input_tempo_minuto.setAttribute('disabled','disabled');
				input_tempo_minuto.setAttribute('onkeyup',"javascript:validar(this,"+objecto+")");
				input_tempo_minuto.setAttribute('maxlength','2');
				input_tempo_minuto.setAttribute('type','text');
				input_tempo_minuto.setAttribute('disabled','disabled');
				var objecto_tempo_minuto_text=document.createElement("div");
				objecto_tempo_minuto_text.setAttribute('class','objecto_tempo_minuto_text');
				objecto_tempo_minuto_text.innerHTML="MM";
				objecto_tempo_minuto.appendChild(input_tempo_minuto);
				objecto_tempo_minuto.appendChild(objecto_tempo_minuto_hiffen);
				objecto_tempo_minuto.appendChild(objecto_tempo_minuto_text);
				objecto_tempo_caixa.appendChild(objecto_tempo_minuto);
			
	///////////////////falta colocar as combobox com as horas para o utilizador editar este campo/////////////////
				if(corpo.childNodes[x].getElementsByTagName("default")[0].hasChildNodes()){
					var tempo=corpo.childNodes[x].getElementsByTagName("default")[0].firstChild.nodeValue;
					var tempo_array=tempo.split(':');
					input_tempo_minuto.value=tempo_array[1];
					input_tempo_hora.value=tempo_array[0];
				}
				
				var objecto_tempo_status=document.createElement("div");
				objecto_tempo_status.setAttribute('id','objecto_tempo_status'+objecto);
				objecto_tempo_caixa.appendChild(objecto_tempo_status);
				obj_caixa_geral.appendChild(objecto_tempo_caixa);
				registos_corpo_obj.setAttribute('type','tempo');
				
				
			}
			else if(tipo=='morada'){
				
				
			}	
			registos_corpo.appendChild(registos_corpo_obj);
			/*tipo=registos_corpo_obj.getAttribute('type');
			
			posicao=registos_corpo_obj.getAttribute('posicao');
			var info="0="+formulario+"&1="+tipo+"&2="+posicao;	*/	
		}
	}
}

























function mostrar_adicionar_objectos(){
	var contentor_editar=document.getElementById('editar');
	contentor_editar.setAttribute('class','editar_display');
	var objectos=document.getElementById('objectos');
	objectos.removeAttribute('class','objectos_display');
}
function mostrar_editar_objectos(){
	var contentor_editar=document.getElementById('editar');
	contentor_editar.removeAttribute('class','editar_display');
	var objectos=document.getElementById('objectos');
	objectos.setAttribute('class','objectos_display');
}
function layout_organizar(){
	Sortable.create("layout",
 		{dropOnEmpty:false,handle:'handle',constraint:false});
}
function objecto(x,y,dados){
	var objecto_caixa=document.createElement("li");
	if(y==0){
		objecto_caixa.setAttribute('interno',objecto_caixa_count);
		objecto_caixa.setAttribute('posicao',objecto_caixa_count);
		objecto_caixa_count=objecto_caixa_count+1;
	}
	else{
		objecto_caixa.setAttribute('interno',dados.childNodes[6].firstChild.nodeValue);
		objecto_caixa.setAttribute('posicao',dados.childNodes[6].firstChild.nodeValue);	
		x=dados.childNodes[1].firstChild.nodeValue;
	}
	objecto_caixa.setAttribute('class','objecto_caixa');
	objecto_caixa_titulo=document.createElement("div");
	objecto_caixa_titulo.setAttribute('class',"objecto_caixa_titulo");
	var objecto_caixa_geral=document.createElement("div");
	objecto_caixa_geral.setAttribute('class','objecto_caixa_geral');
	var objecto_caixa_informacao=document.createElement("div");
	if(y==0){
		objecto_caixa_informacao.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
	}
	else{
		if(dados.childNodes[5].hasChildNodes()){
			objecto_caixa_informacao.innerHTML=dados.childNodes[5].firstChild.nodeValue;
			objecto_caixa_informacao.setAttribute('class','objecto_caixa_informacao');
		}
		else{
			objecto_caixa_informacao.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
		}
	}
	objecto_caixa_geral.appendChild(objecto_caixa_titulo);
	objecto_caixa.appendChild(objecto_caixa_geral);
	objecto_caixa.appendChild(objecto_caixa_informacao);
	if(y==0){
		objecto_caixa_titulo.innerHTML="Indefinido";
	}
	else{
		if(dados.childNodes[2].hasChildNodes()){
			objecto_caixa_titulo.innerHTML=dados.childNodes[2].firstChild.nodeValue;
		}
	}
	//objecto_caixa_count_corrente=objecto_caixa_count;
	if(x=='text'){
		var objecto_text_caixa=document.createElement("div");
		objecto_text_caixa.setAttribute('class','objecto_text_caixa');
		text_count=text_count+1;
		var input=document.createElement("input");
		input.setAttribute('name',text_count);
		input.setAttribute('id',"text_"+text_count);
		input.setAttribute('type','text');
		if(y==0){
			input.setAttribute('class','textfield_medium');
		}
		else{
			var tamanho=dados.childNodes[3].firstChild.nodeValue
			if(tamanho==1){
				input.setAttribute('class','textfield_small');
			}
			else if(tamanho==2){
				input.setAttribute('class','textfield_medium');
			}
			else if(tamanho==3){
				input.setAttribute('class','textfield_large');
			}
			
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
			
			if(dados.lastChild.firstChild.firstChild.hasChildNodes()){
				input.setAttribute('value',dados.lastChild.firstChild.firstChild.firstChild.nodeValue);
			}
		}
		input.setAttribute('readonly','true');
		objecto_text_caixa.appendChild(input);
		objecto_caixa_geral.appendChild(objecto_text_caixa);
		objecto_caixa.setAttribute('type','text');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
	}
	else if(x=='text_area'){
		var objecto_text_area_caixa=document.createElement("div");
		objecto_text_area_caixa.setAttribute('class','objecto_text_area_caixa');
		text_area_count=text_area_count+1;
		var input=document.createElement("textarea")
		input.setAttribute('name',text_area_count);
		input.setAttribute('id',"text_area_"+text_area_count);
		if(y==0){
			input.setAttribute('class','textarea_medium');
		}
		else{
			var tamanho=dados.childNodes[3].firstChild.nodeValue
			if(tamanho==1){
				input.setAttribute('class','textarea_small');
			}
			else if(tamanho==2){
				input.setAttribute('class','textarea_medium');
			}
			else if(tamanho==3){
				input.setAttribute('class','textarea_large');
			}
			
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
			
			if(dados.lastChild.firstChild.firstChild.hasChildNodes()){
				input.innerHTML=dados.lastChild.firstChild.firstChild.firstChild.nodeValue;
			}			
		}
		input.setAttribute('readonly','true');
		input.setAttribute('type','text_area');
		objecto_text_area_caixa.appendChild(input);
		objecto_caixa_geral.appendChild(objecto_text_area_caixa);
		objecto_caixa.setAttribute('type','text_area');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
	}
	else if(x=='checkbox'){
		var objecto_checkbox_caixa=document.createElement("div");
		objecto_checkbox_caixa.setAttribute('class','objecto_checkbox_caixa');
		if(y==0){
			for(var c=1;c<4;c++){
				var objecto_checkbox_caixa_input=document.createElement("div");
				objecto_checkbox_caixa_input.setAttribute('class','objecto_checkbox_caixa_input');
				var input=document.createElement("input");
				input.setAttribute('name','checkbox');
				input.setAttribute('id','checkbox');
				input.setAttribute('type','checkbox');
				input.setAttribute('disabled','disabled');
				input.setAttribute('class','objecto_checkbox_caixa_input_value');
				objecto_checkbox_caixa_input.appendChild(input);
				objecto_checkbox_caixa_input.setAttribute('value',c);
				var objecto_checkbox_caixa_input_label=document.createElement("div");
				objecto_checkbox_caixa_input_label.setAttribute('class','objecto_checkbox_caixa_input_label');
				objecto_checkbox_caixa_input_label.innerHTML="Indefinido";
				objecto_checkbox_caixa_input.appendChild(objecto_checkbox_caixa_input_label);
				objecto_checkbox_caixa.appendChild(objecto_checkbox_caixa_input);
			}
		}
		else{
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}

			if(dados.lastChild.hasChildNodes()){
				var detalhes_childNodes=dados.lastChild.childNodes;
				for(var c=0;c<detalhes_childNodes.length;c++){
					//detalhes_childNodes[c].firstChild.firstChild.nodeValue;
					
					var objecto_checkbox_caixa_input=document.createElement("div");
					objecto_checkbox_caixa_input.setAttribute('class','objecto_checkbox_caixa_input');
					var input=document.createElement("input");
					input.setAttribute('name','checkbox');
					input.setAttribute('id','checkbox');
					input.setAttribute('type','checkbox');
					input.setAttribute('disabled','disabled');
					input.setAttribute('class','objecto_checkbox_caixa_input_value');
					if(detalhes_childNodes[c].lastChild.firstChild.nodeValue==1){
						input.setAttribute('checked','checked');
					}
					objecto_checkbox_caixa_input.appendChild(input);
					objecto_checkbox_caixa_input.setAttribute('value',detalhes_childNodes[c].firstChild.firstChild.nodeValue);
					var objecto_checkbox_caixa_input_label=document.createElement("div");
					objecto_checkbox_caixa_input_label.setAttribute('class','objecto_checkbox_caixa_input_label');
					if(detalhes_childNodes[c].childNodes[1].hasChildNodes()){
						objecto_checkbox_caixa_input_label.innerHTML=detalhes_childNodes[c].childNodes[1].firstChild.nodeValue;
					}
					objecto_checkbox_caixa_input.appendChild(objecto_checkbox_caixa_input_label);
					objecto_checkbox_caixa.appendChild(objecto_checkbox_caixa_input);	
				}
			}	
		}

		objecto_caixa_geral.appendChild(objecto_checkbox_caixa);
		objecto_caixa.setAttribute('type','checkbox');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
	}
	else if(x=='radio'){
		var objecto_radio_caixa=document.createElement("div");
		objecto_radio_caixa.setAttribute('class','objecto_radio_caixa');
		if(y==0){
			for(var c=1;c<4;c++){
				var objecto_radio_caixa_input=document.createElement("div");
				objecto_radio_caixa_input.setAttribute('class','objecto_radio_caixa_input');
				var input=document.createElement("input");
				//input.setAttribute('name','radio');
				input.setAttribute('id','radio');
				input.setAttribute('type','radio');
				input.setAttribute('disabled','disabled');
				input.setAttribute('class','objecto_radio_caixa_input_value');
				objecto_radio_caixa_input.appendChild(input);
				var objecto_radio_caixa_input_label=document.createElement("div");
				objecto_radio_caixa_input_label.setAttribute('class','objecto_radio_caixa_input_label');
				objecto_radio_caixa_input_label.innerHTML="Indefinido";
				objecto_radio_caixa_input.appendChild(objecto_radio_caixa_input_label);
				objecto_radio_caixa.appendChild(objecto_radio_caixa_input);
			}
		}
		else{
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
			
			if(dados.lastChild.hasChildNodes()){
				var detalhes_childNodes=dados.lastChild.childNodes;
				for(var c=0;c<detalhes_childNodes.length;c++){
					var objecto_radio_caixa_input=document.createElement("div");
					objecto_radio_caixa_input.setAttribute('class','objecto_radio_caixa_input');
					var input=document.createElement("input");
					//input.setAttribute('name','radio');
					input.setAttribute('id','radio');
					input.setAttribute('type','radio');
					input.setAttribute('disabled','disabled');
					input.setAttribute('class','objecto_radio_caixa_input_value');
					objecto_radio_caixa_input.appendChild(input);
					var objecto_radio_caixa_input_label=document.createElement("div");
					objecto_radio_caixa_input_label.setAttribute('class','objecto_radio_caixa_input_label');
					if(detalhes_childNodes[c].childNodes[1].hasChildNodes()){
						objecto_radio_caixa_input_label.innerHTML=detalhes_childNodes[c].childNodes[1].firstChild.nodeValue;
					}
					objecto_radio_caixa_input.appendChild(objecto_radio_caixa_input_label);
					objecto_radio_caixa.appendChild(objecto_radio_caixa_input);
					if(detalhes_childNodes[c].lastChild.firstChild.nodeValue==1){
						input.setAttribute('checked','checked');
					}
				}
			}
		}
			
		objecto_caixa_geral.appendChild(objecto_radio_caixa);
		objecto_caixa.setAttribute('type','radio');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
	}
	else if(x=='quebra'){
		var objecto_quebra_caixa=document.createElement("div");
		objecto_quebra_caixa.setAttribute('class','objecto_quebra_caixa');
		var objecto_quebra_caixa_descricao=document.createElement("div");
		objecto_quebra_caixa_descricao.setAttribute('id','objecto_quebra_caixa_descricao');
		objecto_quebra_caixa.appendChild(objecto_quebra_caixa_descricao);
		objecto_caixa_geral.appendChild(objecto_quebra_caixa);
		objecto_caixa.setAttribute('type','quebra');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
		if(y==0){
			objecto_quebra_caixa_descricao.innerHTML='Descrição da quebra aparece aqui.';		
		}
		else{
			if(dados.lastChild.firstChild.firstChild.hasChildNodes()){
				objecto_quebra_caixa_descricao.innerHTML=dados.lastChild.firstChild.firstChild.firstChild.nodeValue;
			}
		}
	}
	else if(x=='jumpmenu'){
		var objecto_jumpmenu_caixa=document.createElement("div");
		objecto_jumpmenu_caixa.setAttribute('class','objecto_jumpmenu_caixa');
		var input=document.createElement("select");
		input.setAttribute('name',jumpmenu_count);
		input.setAttribute('disabled','disabled');		
		if(y==0){
			var option=document.createElement("option");
			input.setAttribute('class','jumpmenu_medium');
			option.setAttribute('value',0);
			option.innerHTML="Indefinido";
			input.appendChild(option);
		}
		else{
			var tamanho=dados.childNodes[3].firstChild.nodeValue
			if(tamanho==1){
				input.setAttribute('class','jumpmenu_small');
			}
			else if(tamanho==2){
				input.setAttribute('class','jumpmenu_medium');
			}
			else if(tamanho==3){
				input.setAttribute('class','jumpmenu_large');
			}
			
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
			if(dados.lastChild.hasChildNodes()){
				var detalhes_childNodes=dados.lastChild.childNodes;
				var value;
				for(var c=0;c<detalhes_childNodes.length;c++){
					value=detalhes_childNodes[c].firstChild.firstChild.nodeValue;
					var option=document.createElement("option");
					option.setAttribute('value',value);
					if(detalhes_childNodes[c].childNodes[1].hasChildNodes()){
						option.innerHTML=detalhes_childNodes[c].childNodes[1].firstChild.nodeValue;
					}
					input.appendChild(option);
					if(detalhes_childNodes[c].lastChild.firstChild.nodeValue==1){
						input.options[c].selected=true;
					}
				}
			}
		}
		objecto_jumpmenu_caixa.appendChild(input);	
		objecto_caixa_geral.appendChild(objecto_jumpmenu_caixa);
		objecto_caixa.setAttribute('type','jumpmenu');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');		
	}
	else if(x=='nome'){		
		var objecto_nome_caixa=document.createElement("div");
		objecto_nome_caixa.setAttribute('class','objecto_nome_caixa');
		
		var objecto_nome=document.createElement("div");
		objecto_nome.setAttribute('class','objecto_nome');
		var input_nome=document.createElement("input")
		input_nome.setAttribute('name','input_nome');
		input_nome.setAttribute('id','input_nome');
		input_nome.setAttribute('disabled','disabled');
		input_nome.setAttribute('type','text');
		input_nome.setAttribute('class','textfield_large');
		var objecto_nome_text=document.createElement("div");
		objecto_nome_text.setAttribute('class','objecto_nome_text');
		objecto_nome_text.innerHTML="Nome Completo";

		if(y==0){
			objecto_caixa_titulo.innerHTML="Nome";
		}
		else{
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
		}
		objecto_nome.appendChild(input_nome);
		objecto_nome.appendChild(objecto_nome_text);
		objecto_nome_caixa.appendChild(objecto_nome);
		
		objecto_caixa_geral.appendChild(objecto_nome_caixa);
		objecto_caixa.setAttribute('type','nome');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
		
	}
	else if(x=='data'){		
		var objecto_data_caixa=document.createElement("div");
		objecto_data_caixa.setAttribute('class','objecto_data_caixa');
		
		var objecto_data_ano_hiffen=document.createElement("div");
		objecto_data_ano_hiffen.setAttribute('class','objecto_data_ano_hiffen');
		objecto_data_ano_hiffen.innerHTML='/';
		
		var objecto_data_mes_hiffen=document.createElement("div");
		objecto_data_mes_hiffen.setAttribute('class','objecto_data_mes_hiffen');
		objecto_data_mes_hiffen.innerHTML='/';
		
		var objecto_data_dia=document.createElement("div");
		objecto_data_dia.setAttribute('class','objecto_data_dia');
		var input_data_dia=document.createElement("input")
		input_data_dia.setAttribute('name','input_data_dia');
		input_data_dia.setAttribute('class','input_data_dia');
		input_data_dia.setAttribute('id','input_data_dia');
		input_data_dia.setAttribute('disabled','disabled');
		input_data_dia.setAttribute('type','text');
		var objecto_data_dia_text=document.createElement("div");
		objecto_data_dia_text.setAttribute('class','objecto_data_dia_text');
		objecto_data_dia_text.innerHTML="Dia";
		objecto_data_dia.appendChild(input_data_dia);
		objecto_data_dia.appendChild(objecto_data_dia_text);
		objecto_data_caixa.appendChild(objecto_data_dia);
				
		var objecto_data_mes=document.createElement("div");
		objecto_data_mes.setAttribute('class','objecto_data_mes');
		var input_data_mes=document.createElement("input")
		input_data_mes.setAttribute('name','input_data_mes');
		input_data_mes.setAttribute('id','input_data_mes');
		input_data_mes.setAttribute('class','input_data_mes');
		input_data_mes.setAttribute('disabled','disabled');
		input_data_mes.setAttribute('type','text');
		var objecto_data_mes_text=document.createElement("div");
		objecto_data_mes_text.setAttribute('class','objecto_data_mes_text');
		objecto_data_mes_text.innerHTML="Mês";
		objecto_data_mes.appendChild(input_data_mes);
		objecto_data_mes.appendChild(objecto_data_mes_hiffen);
		objecto_data_mes.appendChild(objecto_data_mes_text);
		objecto_data_caixa.appendChild(objecto_data_mes);
		
		
		var objecto_data_ano=document.createElement("div");
		objecto_data_ano.setAttribute('class','objecto_data_ano');
		var input_data_ano=document.createElement("input")
		input_data_ano.setAttribute('name','input_data_ano');
		input_data_ano.setAttribute('id','input_data_ano');
		input_data_ano.setAttribute('class','input_data_ano');
		input_data_ano.setAttribute('disabled','disabled');
		input_data_ano.setAttribute('type','text');
		var objecto_data_ano_text=document.createElement("div");
		objecto_data_ano_text.setAttribute('class','objecto_data_ano_text');
		objecto_data_ano_text.innerHTML="Ano";
		objecto_data_ano.appendChild(input_data_ano);
		objecto_data_ano.appendChild(objecto_data_ano_hiffen);
		objecto_data_ano.appendChild(objecto_data_ano_text);
		objecto_data_caixa.appendChild(objecto_data_ano);
		
		/*var objecto_data_icon=document.createElement("div");
		objecto_data_icon.setAttribute('class','objecto_data_icon');
		var objecto_data_icon_img=document.createElement("img");
		objecto_data_icon_img.setAttribute('src','/mod/formularios/icons/data.png');
		objecto_data_icon_img.setAttribute('class','objecto_data_icon_img');
		objecto_data_icon.appendChild(objecto_data_icon_img);
		objecto_data_caixa.appendChild(objecto_data_icon);*/
		if(y==0){
			objecto_caixa_titulo.innerHTML="Data";
		}
		else{
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
			if(dados.lastChild.firstChild.firstChild.hasChildNodes()){
				var data=dados.lastChild.firstChild.firstChild.firstChild.nodeValue;
				var data_array=data.split('-');
				input_data_dia.value=data_array[0];
				input_data_mes.value=data_array[1];
				input_data_ano.value=data_array[2];
			}
		}	
		objecto_caixa_geral.appendChild(objecto_data_caixa);
		objecto_caixa.setAttribute('type','data');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
	}
	else if(x=='tempo'){		
		var objecto_tempo_caixa=document.createElement("div");
		objecto_tempo_caixa.setAttribute('class','objecto_tempo_caixa');
		
		var objecto_tempo_segundo_hiffen=document.createElement("div");
		objecto_tempo_segundo_hiffen.setAttribute('class','objecto_tempo_segundo_hiffen');
		objecto_tempo_segundo_hiffen.innerHTML=':';
		
		var objecto_tempo_minuto_hiffen=document.createElement("div");
		objecto_tempo_minuto_hiffen.setAttribute('class','objecto_tempo_minuto_hiffen');
		objecto_tempo_minuto_hiffen.innerHTML=':';
		
		var objecto_tempo_hora=document.createElement("div");
		objecto_tempo_hora.setAttribute('class','objecto_tempo_hora');
		var input_tempo_hora=document.createElement("input")
		input_tempo_hora.setAttribute('class','input_tempo_hora');
		input_tempo_hora.setAttribute('id','input_tempo_hora');
		input_tempo_hora.setAttribute('disabled','disabled');
		input_tempo_hora.setAttribute('type','text');
		var objecto_tempo_hora_text=document.createElement("div");
		objecto_tempo_hora_text.setAttribute('class','objecto_tempo_hora_text');
		objecto_tempo_hora_text.innerHTML="HH";
		objecto_tempo_hora.appendChild(input_tempo_hora);
		objecto_tempo_hora.appendChild(objecto_tempo_hora_text);
		objecto_tempo_caixa.appendChild(objecto_tempo_hora);
				
		var objecto_tempo_minuto=document.createElement("div");
		objecto_tempo_minuto.setAttribute('class','objecto_tempo_minuto');
		var input_tempo_minuto=document.createElement("input")
		input_tempo_minuto.setAttribute('name','input_tempo_minuto');
		input_tempo_minuto.setAttribute('id','input_tempo_minuto');
		input_tempo_minuto.setAttribute('class','input_tempo_minuto');
		input_tempo_minuto.setAttribute('disabled','disabled');
		input_tempo_minuto.setAttribute('type','text');
		var objecto_tempo_minuto_text=document.createElement("div");
		objecto_tempo_minuto_text.setAttribute('class','objecto_tempo_minuto_text');
		objecto_tempo_minuto_text.innerHTML="MM";
		objecto_tempo_minuto.appendChild(input_tempo_minuto);
		objecto_tempo_minuto.appendChild(objecto_tempo_minuto_hiffen);
		objecto_tempo_minuto.appendChild(objecto_tempo_minuto_text);
		objecto_tempo_caixa.appendChild(objecto_tempo_minuto);
		
		
		/*var objecto_tempo_segundo=document.createElement("div");
		objecto_tempo_segundo.setAttribute('class','objecto_tempo_segundo');
		var input_tempo_segundo=document.createElement("input")
		input_tempo_segundo.setAttribute('name','input_tempo_segundo');
		input_tempo_segundo.setAttribute('id','input_tempo_segundo');
		input_tempo_segundo.setAttribute('class','input_tempo_segundo');
		input_tempo_segundo.setAttribute('disabled','disabled');
		input_tempo_segundo.setAttribute('type','text');
		var objecto_tempo_segundo_text=document.createElement("div");
		objecto_tempo_segundo_text.setAttribute('class','objecto_tempo_segundo_text');
		objecto_tempo_segundo_text.innerHTML="SS";
		objecto_tempo_segundo.appendChild(input_tempo_segundo);
		objecto_tempo_segundo.appendChild(objecto_tempo_segundo_hiffen);
		objecto_tempo_segundo.appendChild(objecto_tempo_segundo_text);
		objecto_tempo_caixa.appendChild(objecto_tempo_segundo);*/
		
		if(y==0){
			objecto_caixa_titulo.innerHTML="Tempo";
		}
		else{
			if(dados.childNodes[4].hasChildNodes()){
				if(dados.childNodes[4].firstChild.nodeValue==1){
					asterisco=document.createElement('span');
					asterisco.setAttribute('class','asterisco');
					asterisco.innerHTML=" *"
					objecto_caixa_titulo.appendChild(asterisco);
				}
			}
			if(dados.lastChild.firstChild.firstChild.hasChildNodes()){
				var tempo=dados.lastChild.firstChild.firstChild.firstChild.nodeValue;
				var tempo_array=tempo.split(':');
				input_tempo_minuto.value=tempo_array[1];
				input_tempo_hora.value=tempo_array[0];
			}
		}				
	
		objecto_caixa_geral.appendChild(objecto_tempo_caixa);
		objecto_caixa.setAttribute('type','tempo');
		objecto_caixa.setAttribute('ondblclick','init_editar(this)');
	}
	else if(x=='morada'){
		/*objecto_caixa_titulo.innerHTML="Morada";
		
		var objecto_morada_caixa=document.createElement("div");
		objecto_morada_caixa.setAttribute('class','objecto_morada_caixa');
		
		var objecto_morada_rua=document.createElement("div");
		objecto_morada_rua.setAttribute('class','objecto_morada_rua');
		var objecto_morada_rua_input=document.createElement("div");
		objecto_morada_rua_input.setAttribute('class','objecto_morada_rua_input');
		var objecto_morada_rua_texto=document.createElement("div");
		objecto_morada_rua_texto.setAttribute('class','objecto_morada_rua_texto');
		objecto_morada_rua_texto.innerHTML="Endereço";
		objecto_morada_rua.appendChild(objecto_morada_rua_input);
		objecto_morada_rua.appendChild(objecto_morada_rua_texto);
		objecto_morada.appendChild(objecto_morada_rua);
		
		var objecto_morada_cidade=document.createElement("div");
		objecto_morada_cidade.setAttribute('class','objecto_morada_cidade');
		var objecto_morada_cidade_input=document.createElement("select");
		objecto_morada_cidade_input.setAttribute('class','objecto_morada_cidade_input');
		objecto_morada_cidade_input.setAttribute('name','objecto_morada_cidade_input');
		objecto_morada_cidade_input.setAttribute('id','objecto_morada_cidade_input');
		
		
		
		objecto_morada_cidade_input_option=document.createElement("option");
		
		
		
		
		
		var objecto_morada_rua_texto=document.createElement("div");
		objecto_morada_rua_texto.setAttribute('class','objecto_morada_rua_texto');
		objecto_morada_rua_texto.innerHTML="Endereço";
		objecto_morada_rua.appendChild(objecto_morada_rua_input);
		objecto_morada_rua.appendChild(objecto_morada_rua_texto);
		objecto_morada.appendChild(objecto_morada_rua);
		
		
		
		
		var objecto_tempo_minuto_hiffen=document.createElement("div");
		objecto_tempo_minuto_hiffen.setAttribute('class','objecto_tempo_minuto_hiffen');
		objecto_tempo_minuto_hiffen.innerHTML=':';*/
		
		
	}
	layout.appendChild(objecto_caixa);
	var id_objecto;	
	if(y==0){
		tipo=objecto_caixa.getAttribute('type');
		posicao=objecto_caixa.getAttribute('posicao');
		var info="0="+formulario+"&1="+tipo+"&2="+posicao;
		id_objecto=objecto_inserir(info);
		if(x=='radio'){
			for(var a=0;a<objecto_radio_caixa.childNodes.length;a++){
				objecto_radio_caixa.childNodes[a].firstChild.setAttribute('name','radio'+id_objecto);
				if(a==0){
					objecto_radio_caixa.childNodes[a].firstChild.setAttribute('checked','checked');				
				}
			}
		}
	}
	else{
		id_objecto=dados.childNodes[0].firstChild.nodeValue;
		if(x=='radio'){
			for(var a=0;a<objecto_radio_caixa.childNodes.length;a++){
				objecto_radio_caixa.childNodes[a].firstChild.setAttribute('name','radio'+id_objecto);
			}
		}
	}
	objecto_caixa.setAttribute('id',id_objecto);

	layout_organizar();
}
function objecto_inserir(info){
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/objecto_inserir.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	var dados=ligar.responseXML;
	var id=dados.getElementsByTagName("id")[0].firstChild.nodeValue;
	return id;
}
function init_editar(objecto){
	x=objecto.getAttribute('type');
	info="0="+objecto.getAttribute('posicao');
	var url;
	mostrar_editar_objectos();
	if(x=="titulo"){
		if(previous_element!=null){
			if(previous_element.getAttribute('type')!="titulo"){
				previous_element.firstChild.setAttribute('class','objecto_caixa_geral');
				previous_element=current_element;
			}
		}
		current_element=objecto;
		previous_element=current_element;
		current_element.setAttribute('class','layout_titulo layout_titulo_active');
		url="/mod/formularios/editar/init/titulo.php";
	}
	else{
		if(previous_element!=null){
			if(previous_element.getAttribute('type')!="titulo"){
				previous_element.firstChild.setAttribute('class','objecto_caixa_geral');
				previous_element=current_element;
			}
			else{
				previous_element.setAttribute('class','layout_titulo');
			}
		}
		current_element=objecto;
		previous_element=current_element;
		current_element.firstChild.setAttribute('class','objecto_caixa_geral objecto_caixa_geral_active');

		if(x=="text"){
			url="/mod/formularios/editar/init/text_field.php";
		}
		else if(x=="text_area"){
			url="/mod/formularios/editar/init/text_area.php";		
		}
		else if(x=="checkbox"){
			url="/mod/formularios/editar/init/checkbox.php";
		}
		else if(x=="jumpmenu"){
			url="/mod/formularios/editar/init/jumpmenu.php";
		}
		else if(x=="radio"){
			url="/mod/formularios/editar/init/radio.php";
		}
		else if(x=="nome"){
			url="/mod/formularios/editar/init/nome.php";
		}
		else if(x=="data"){
			url="/mod/formularios/editar/init/data.php";
		}
		else if(x=="tempo"){
			url="/mod/formularios/editar/init/tempo.php";
		}
		else if(x=="quebra"){
			url="/mod/formularios/editar/init/quebra.php";
		}
	}
	ligar = ligacao();
	ligar.open("POST",url,false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	var valor = ligar.responseText;
	var	editar_conteudo=document.getElementById('editar_conteudo');
	editar_conteudo.innerHTML=valor;
	load_editar(x);
}
function load_editar(x){
	var info;
	if(x=="titulo"){
		info="0="+formulario;
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/titulo.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados=ligar.responseXML;
		//alert(dados);
		if(dados.getElementsByTagName("nome")[0].hasChildNodes()){
			var nome=dados.getElementsByTagName("nome")[0].firstChild.nodeValue;
			var layout_titulo_nome=document.getElementById("layout_titulo_nome");
			layout_titulo_nome.innerHTML=nome;
			var editar_nome=document.getElementById("editar_titulo_nome");
			editar_titulo_nome.value=nome;
		}
		if(dados.getElementsByTagName("descricao")[0].hasChildNodes()){
			var descricao=dados.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			var layout_titulo_descricao=document.getElementById("layout_titulo_descricao");
			layout_titulo_descricao.innerHTML=descricao;
			var editar_descricao=document.getElementById("editar_titulo_descricao");
			editar_titulo_descricao.value=descricao;
		}
	}
	else if(x=="text"){
		info="0="+formulario+"&1="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/text_field.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_textfield_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		
		var tamanho=dados.getElementsByTagName("tamanho")[0].firstChild.nodeValue;
		document.getElementById('editar_textfield_tamanho').options[tamanho-1].selected = true;
		if(tamanho==1){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','textfield_small');
		}
		else if(tamanho==2){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','textfield_medium');
		}
		else if(tamanho==3){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','textfield_large');
		}
		
		var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_textfield_opcoes=document.getElementById('editar_textfield_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_textfield_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_textfield_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}
		if(dados.getElementsByTagName("descricao")[0].hasChildNodes()){
			document.getElementById('editar_textfield_valor').value=current_element.firstChild.lastChild.firstChild.value=dados.getElementsByTagName("descricao")[0].firstChild.nodeValue;
		}
		
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_textfield_instrucoes_linha').innerHTML=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
	}
	else if(x=="text_area"){
		info="0="+formulario+"&1="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/text_area.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_textarea_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		var tamanho=dados.getElementsByTagName("tamanho")[0].firstChild.nodeValue;
		document.getElementById('editar_textarea_tamanho').options[tamanho-1].selected = true;
		if(tamanho==1){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','textarea_small');
		}
		else if(tamanho==2){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','textarea_medium');
		}
		else if(tamanho==3){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','textarea_large');
		}
		
		var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_textarea_opcoes=document.getElementById('editar_textarea_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_textarea_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_textarea_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}
		
		
		if(dados.getElementsByTagName("descricao")[0].hasChildNodes()){
			var descricao=dados.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			document.getElementById('editar_textarea_valor').value=descricao;
			current_element.firstChild.lastChild.firstChild.value=descricao;
		}
		
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_textarea_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
	}
	else if(x=="jumpmenu"){
		info="0="+formulario+"&1="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/jumpmenu.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_jumpmenu_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		
		var tamanho=dados.getElementsByTagName("tamanho")[0].firstChild.nodeValue;
		document.getElementById('editar_jumpmenu_tamanho').options[tamanho-1].selected = true;
		if(tamanho==1){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','jumpmenu_small');
		}
		else if(tamanho==2){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','jumpmenu_medium');
		}
		else if(tamanho==3){
			current_element.firstChild.lastChild.firstChild.setAttribute('class','jumpmenu_large');
		}
		
		/*var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_jumpmenu_opcoes=document.getElementById('editar_jumpmenu_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_jumpmenu_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_jumpmenu_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}*/
	
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_jumpmenu_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
		if(dados.getElementsByTagName("selecionado")[0].hasChildNodes()){
			selecionado=dados.getElementsByTagName("selecionado")[0].firstChild.nodeValue;
		}
		
		//var detalhes=dados.getElementsByTagName("detalhes")[0].childNodes.length;
		var editar_escolhas=document.getElementById('editar_escolhas');
		removerChildNodes(current_element.firstChild.lastChild.firstChild);
		for(var y=0;y<dados.getElementsByTagName("detalhes")[0].childNodes.length;y++){
			valor=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[0].firstChild.nodeValue;
			var option=document.createElement("option");
			option.setAttribute('value',valor);
			if(dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].hasChildNodes()){
				descricao=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].firstChild.nodeValue;
				option.innerHTML=descricao;		
			}
			else{
				descricao="";	
			}
			current_element.firstChild.lastChild.firstChild.appendChild(option);
			
			var editar_escolhas_linha=document.createElement('div');
			editar_escolhas_linha.setAttribute('class','editar_escolhas_linha');
			editar_escolhas_linha.setAttribute('value',y);
			
			
			var editar_escolhas_linha_radio=document.createElement('div');
			editar_escolhas_linha_radio.setAttribute('class','editar_escolhas_linha_radio');

			var input_radio=document.createElement('input');
			input_radio.setAttribute('name','radio');
			input_radio.setAttribute('type','radio');
			input_radio.setAttribute('onclick','escolhas_selecionado(this,"jumpmenu")');
			editar_escolhas_linha_radio.appendChild(input_radio);
			if(selecionado==y){
				input_radio.setAttribute('checked','checked');
				current_element.firstChild.lastChild.firstChild.options[selecionado].selected = true;
			}
			
			var editar_escolhas_linha_text=document.createElement('div');
			editar_escolhas_linha_text.setAttribute('class','editar_escolhas_linha_text');
			var input_text=document.createElement('input');
			input_text.setAttribute('name','text1');
			input_text.setAttribute('type','text');
			input_text.setAttribute('value',descricao);
			input_text.setAttribute('class','editar_escolhas_linha_text_input');
			input_text.setAttribute('onkeyup','escolhas_selecionado(this,"jumpmenu")');
			editar_escolhas_linha_text.appendChild(input_text);
			
			var editar_escolhas_linha_plus_minus=document.createElement('div');
			editar_escolhas_linha_plus_minus.setAttribute('class','editar_escolhas_linha_plus_minus');
			var img_plus=document.createElement('img');
			img_plus.setAttribute('src','/mod/formularios/icons/plus.png');
			img_plus.setAttribute('type','plus');
			img_plus.setAttribute('onclick','escolhas_selecionado(this,"jumpmenu")');
			var img_minus=document.createElement('img');
			img_minus.setAttribute('src','/mod/formularios/icons/minus.png')
			img_minus.setAttribute('type','minus');
			img_minus.setAttribute('onclick','escolhas_selecionado(this,"jumpmenu")');
			editar_escolhas_linha_plus_minus.appendChild(img_plus);
			editar_escolhas_linha_plus_minus.appendChild(img_minus);
			
			editar_escolhas_linha.appendChild(editar_escolhas_linha_radio);
			editar_escolhas_linha.appendChild(editar_escolhas_linha_text);
			editar_escolhas_linha.appendChild(editar_escolhas_linha_plus_minus);
			
			editar_escolhas.appendChild(editar_escolhas_linha);
		}	
	}
	else if(x=="checkbox"){
		info="0="+formulario+"&1="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/checkbox.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;

		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_checkbox_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		
		var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_checkbox_opcoes=document.getElementById('editar_checkbox_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_checkbox_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_checkbox_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}
	
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_checkbox_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
		
		//var detalhes=dados.getElementsByTagName("detalhes")[0].childNodes.length;
		var editar_escolhas=document.getElementById('editar_escolhas');
		removerChildNodes(current_element.firstChild.lastChild);
		for(var y=0;y<dados.getElementsByTagName("detalhes")[0].childNodes.length;y++){
			valor=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[0].firstChild.nodeValue;
			var objecto_checkbox_caixa_input_label=document.createElement("div");
			objecto_checkbox_caixa_input_label.setAttribute('class','objecto_checkbox_caixa_input_label');
			if(dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].hasChildNodes()){
				descricao=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].firstChild.nodeValue;
				objecto_checkbox_caixa_input_label.innerHTML=descricao;
			}
			else{
				descricao="";	
			}
			selecionado=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[2].firstChild.nodeValue;

			var objecto_checkbox_caixa_input=document.createElement("div");
			objecto_checkbox_caixa_input.setAttribute('class','objecto_checkbox_caixa_input');
			var input=document.createElement("input");
			input.setAttribute('name','checkbox');
			input.setAttribute('id',valor);
			input.setAttribute('type','checkbox');
			input.setAttribute('disabled','disabled');
			input.setAttribute('class','objecto_checkbox_caixa_input_value');
			objecto_checkbox_caixa_input.appendChild(input);
			objecto_checkbox_caixa_input.setAttribute('value',valor);

			objecto_checkbox_caixa_input.appendChild(objecto_checkbox_caixa_input_label);
			current_element.firstChild.lastChild.appendChild(objecto_checkbox_caixa_input);
			
			var editar_escolhas_linha=document.createElement('div');
			editar_escolhas_linha.setAttribute('class','editar_escolhas_linha');
			editar_escolhas_linha.setAttribute('value',y);
			
			
			var editar_escolhas_linha_radio=document.createElement('div');
			editar_escolhas_linha_radio.setAttribute('class','editar_escolhas_linha_radio');

			var input_radio=document.createElement('input');
			input_radio.setAttribute('name','checkbox');
			input_radio.setAttribute('type','checkbox');
			input_radio.setAttribute('onclick','escolhas_selecionado(this,"checkbox")');
			editar_escolhas_linha_radio.appendChild(input_radio);
			if(selecionado==1){
				input_radio.setAttribute('checked','checked');
				input.setAttribute('checked','checked');
			}
			
			var editar_escolhas_linha_text=document.createElement('div');
			editar_escolhas_linha_text.setAttribute('class','editar_escolhas_linha_text');
			var input_text=document.createElement('input');
			input_text.setAttribute('name','text1');
			input_text.setAttribute('type','text');
			input_text.setAttribute('value',descricao);
			input_text.setAttribute('class','editar_escolhas_linha_text_input');
			input_text.setAttribute('onkeyup','escolhas_selecionado(this,"checkbox")');
			editar_escolhas_linha_text.appendChild(input_text);
			
			var editar_escolhas_linha_plus_minus=document.createElement('div');
			editar_escolhas_linha_plus_minus.setAttribute('class','editar_escolhas_linha_plus_minus');
			var img_plus=document.createElement('img');
			img_plus.setAttribute('src','/mod/formularios/icons/plus.png');
			img_plus.setAttribute('type','plus');
			img_plus.setAttribute('onclick','escolhas_selecionado(this,"checkbox")');
			var img_minus=document.createElement('img');
			img_minus.setAttribute('src','/mod/formularios/icons/minus.png')
			img_minus.setAttribute('type','minus');
			img_minus.setAttribute('onclick','escolhas_selecionado(this,"checkbox")');
			editar_escolhas_linha_plus_minus.appendChild(img_plus);
			editar_escolhas_linha_plus_minus.appendChild(img_minus);
			
			editar_escolhas_linha.appendChild(editar_escolhas_linha_radio);
			editar_escolhas_linha.appendChild(editar_escolhas_linha_text);
			editar_escolhas_linha.appendChild(editar_escolhas_linha_plus_minus);
			
			editar_escolhas.appendChild(editar_escolhas_linha);
		}	
	}
	else if(x=="radio"){
		info="0="+formulario+"&1="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/radio.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;

		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_radio_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		
		/*var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_radio_opcoes=document.getElementById('editar_radio_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_radio_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_radio_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}*/
	
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_radio_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
		if(dados.getElementsByTagName("selecionado")[0].hasChildNodes()){
			selecionado=dados.getElementsByTagName("selecionado")[0].firstChild.nodeValue;
		}
		
		//var detalhes=dados.getElementsByTagName("detalhes")[0].childNodes.length;
		var editar_escolhas=document.getElementById('editar_escolhas');
		removerChildNodes(current_element.firstChild.lastChild);
		var descricao;
		for(var y=0;y<dados.getElementsByTagName("detalhes")[0].childNodes.length;y++){
			valor=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[0].firstChild.nodeValue;
			var objecto_radio_caixa_input_label=document.createElement("div");
			objecto_radio_caixa_input_label.setAttribute('class','objecto_radio_caixa_input_label');
			if(dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].hasChildNodes()){
				descricao=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].firstChild.nodeValue;
				objecto_radio_caixa_input_label.innerHTML=descricao;				
			}
			else{
				descricao="";	
			}
			
			var objecto_radio_caixa_input=document.createElement("div");
			objecto_radio_caixa_input.setAttribute('class','objecto_radio_caixa_input');
			var input=document.createElement("input");
			input.setAttribute('name','radio'+current_element.getAttribute('id'));
			input.setAttribute('type','radio');
			input.setAttribute('disabled','disabled');
			input.setAttribute('class','objecto_radio_caixa_input_value');
			objecto_radio_caixa_input.appendChild(input);
			objecto_radio_caixa_input.setAttribute('value',valor);
			objecto_radio_caixa_input.appendChild(objecto_radio_caixa_input_label);
			current_element.firstChild.lastChild.appendChild(objecto_radio_caixa_input);
			
			var editar_escolhas_linha=document.createElement('div');
			editar_escolhas_linha.setAttribute('class','editar_escolhas_linha');
			editar_escolhas_linha.setAttribute('value',y);
			
			
			var editar_escolhas_linha_radio=document.createElement('div');
			editar_escolhas_linha_radio.setAttribute('class','editar_escolhas_linha_radio');
	
			var input_radio=document.createElement('input');
			input_radio.setAttribute('name','radio');
			input_radio.setAttribute('type','radio');
			input_radio.setAttribute('onclick','escolhas_selecionado(this,"radio")');
			editar_escolhas_linha_radio.appendChild(input_radio);

			var editar_escolhas_linha_text=document.createElement('div');
			editar_escolhas_linha_text.setAttribute('class','editar_escolhas_linha_text');
			var input_text=document.createElement('input');
			input_text.setAttribute('name','text1');
			input_text.setAttribute('type','text');
			input_text.setAttribute('value',descricao);
			input_text.setAttribute('class','editar_escolhas_linha_text_input');
			input_text.setAttribute('onkeyup','escolhas_selecionado(this,"radio")');
			editar_escolhas_linha_text.appendChild(input_text);
			
			var editar_escolhas_linha_plus_minus=document.createElement('div');
			editar_escolhas_linha_plus_minus.setAttribute('class','editar_escolhas_linha_plus_minus');
			var img_plus=document.createElement('img');
			img_plus.setAttribute('src','/mod/formularios/icons/plus.png');
			img_plus.setAttribute('type','plus');
			img_plus.setAttribute('onclick','escolhas_selecionado(this,"radio")');
			var img_minus=document.createElement('img');
			img_minus.setAttribute('src','/mod/formularios/icons/minus.png')
			img_minus.setAttribute('type','minus');
			img_minus.setAttribute('onclick','escolhas_selecionado(this,"radio")');
			editar_escolhas_linha_plus_minus.appendChild(img_plus);
			editar_escolhas_linha_plus_minus.appendChild(img_minus);
			
			editar_escolhas_linha.appendChild(editar_escolhas_linha_radio);
			editar_escolhas_linha.appendChild(editar_escolhas_linha_text);
			editar_escolhas_linha.appendChild(editar_escolhas_linha_plus_minus);
			
			editar_escolhas.appendChild(editar_escolhas_linha);
						
			if(selecionado==y){
				input_radio.click();
			}
		}
	}
	else if(x=="quebra"){
		info="0="+formulario+"&1="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/quebra.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_quebra_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		
		if(dados.getElementsByTagName("descricao")[0].hasChildNodes()){
			document.getElementById('editar_quebra_descricao').innerHTML=current_element.firstChild.lastChild.firstChild.value=dados.getElementsByTagName("descricao")[0].firstChild.nodeValue;
		}
		
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_quebra_instrucoes_linha').innerHTML=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
	}
	else if(x=="nome"){
		info="0="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/nome.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_nome_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		/*var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_nome_opcoes=document.getElementById('editar_nome_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_nome_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_nome_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}*/
	
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_nome_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
		//valor=dados.getElementsByTagName("detalhes")[0].childNodes[y].childNodes[1].firstChild.nodeValue;
		/*if(dados.getElementsByTagName("selecionado")[0].hasChildNodes()){
			var selecionado=dados.getElementsByTagName("selecionado")[0].firstChild.nodeValue;
			if(selecionado==1){
				document.getElementById('editar_nome_predefinido').setAttribute('checked','checked');
			}
			else if(selecionado==0){
				document.getElementById('editar_nome_predefinido').removeAttribute('checked');
			}
		}*/
		if(dados.getElementsByTagName("descricao")[0].hasChildNodes()){
			var editar_escolhas_predefenidas_linha=document.getElementById('editar_escolhas_predefenidas_linha');
			var editar_escolhas_predefenidas_nome=document.createElement('div');
			editar_escolhas_predefenidas_nome.setAttribute('class','editar_escolhas_predefenidas_nome');
			editar_escolhas_predefenidas_linha.appendChild(editar_escolhas_predefenidas_nome);
			
			if(dados.getElementsByTagName("descricao")[0].firstChild.nodeValue==0){
				editar_escolhas_predefenidas_nome.setAttribute('onClick','javascript:carregar_escolhas(null,1,1,0)');
				editar_escolhas_predefenidas_nome.innerHTML="A opção selecionada para este objecto é a 1ª (valor por defeito).  <b>(Alterar)</b>";
			}
			else if(dados.getElementsByTagName("descricao")[0].firstChild.nodeValue==1){
				editar_escolhas_predefenidas_nome.setAttribute('onClick','javascript:carregar_escolhas(null,1,1,1)');
				editar_escolhas_predefenidas_nome.innerHTML="A opção selecionada para este objecto é a 2ª.  <b>(Alterar)</b>";

			}
		}
	}
	else if(x=="data"){
		info="0="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/data.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_data_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_data_opcoes=document.getElementById('editar_data_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_data_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_data_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}
	
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_data_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
		input_datepicker=document.createElement('input');
		input_datepicker.setAttribute('type','text');
		input_datepicker.setAttribute('class','w8em highlight-days-67 format-d-m-y divider-dash highlight-days-12 split-date');
		input_datepicker.setAttribute('id','editar_data_valor_linha_datepicker_input'+datePickerController_hack);
		input_datepicker.setAttribute('name','editar_data_valor_linha_datepicker_input'+datePickerController_hack);
		input_datepicker.setAttribute('value','');
		input_datepicker.setAttribute('style','display:none');
		input_datepicker.setAttribute('onchange',"javascript:change_editar(this,'data')");
		document.getElementById('editar_data_valor_linha_datepicker').appendChild(input_datepicker);
		
		datePickerController.create(document.getElementById('editar_data_valor_linha_datepicker_input'+datePickerController_hack));

		datePickerController_hack=datePickerController_hack+1;
	}
	else if(x=="tempo"){
		info="0="+current_element.getAttribute("id");
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/editar/load/tempo.php",false);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", info.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(info);
		var dados = ligar.responseXML;
		if(dados.getElementsByTagName("titulo")[0].hasChildNodes()){
			document.getElementById('editar_tempo_nome').innerHTML=current_element.firstChild.firstChild.innerHTML=dados.getElementsByTagName("titulo")[0].firstChild.nodeValue;
		}
		var obrigatorio=dados.getElementsByTagName("obrigatorio")[0].firstChild.nodeValue;
		var editar_tempo_opcoes=document.getElementById('editar_tempo_opcoes');	
		if(obrigatorio==1){
			if(current_element.firstChild.firstChild.childNodes.length==1){
				editar_tempo_opcoes.setAttribute('checked','checked');
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(obrigatorio==0){
			if(current_element.firstChild.firstChild.childNodes.length==2){
				editar_tempo_opcoes.removeAttribute('checked');
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
			}
		}
	
		if(dados.getElementsByTagName("instrucoes")[0].hasChildNodes()){
			document.getElementById('editar_tempo_instrucoes_linha').value=current_element.lastChild.innerHTML=dados.getElementsByTagName("instrucoes")[0].firstChild.nodeValue;
			if(current_element.lastChild.innerHTM==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
		}
		if(dados.getElementsByTagName("detalhes")[0].childNodes[0].childNodes[1].hasChildNodes() && dados.getElementsByTagName("detalhes")[0].childNodes[1].childNodes[1].hasChildNodes()){
			current_element.firstChild.childNodes[1].childNodes[0].firstChild.value=dados.getElementsByTagName("detalhes")[0].childNodes[0].childNodes[1].firstChild.nodeValue;
			current_element.firstChild.childNodes[1].childNodes[1].firstChild.value=dados.getElementsByTagName("detalhes")[0].childNodes[1].childNodes[1].firstChild.nodeValue;			
		}
		if(current_element.firstChild.childNodes[1].childNodes[0].firstChild.value=="" && current_element.firstChild.childNodes[1].childNodes[1].firstChild.value==""){
			document.getElementById('editar_tempo_valor_linha_timepicker_mm').disabled=true;
			tempo_flag=0;
		}
		else{
			if(dados.getElementsByTagName("detalhes")[0].childNodes[0].childNodes[1].hasChildNodes() && dados.getElementsByTagName("detalhes")[0].childNodes[1].childNodes[1].hasChildNodes()){
				var index_hh=0;
				var index_mm=0;
				document.getElementById('editar_tempo_valor_linha_timepicker_hh').options[0]=null;
				document.getElementById('editar_tempo_valor_linha_timepicker_mm').options[0]=null;
				while(document.getElementById('editar_tempo_valor_linha_timepicker_hh').options[index_hh].value!=dados.getElementsByTagName("detalhes")[0].childNodes[0].childNodes[1].firstChild.nodeValue){
					index_hh++;
				}
				document.getElementById('editar_tempo_valor_linha_timepicker_hh').options[index_hh].selected = true;			
				while(document.getElementById('editar_tempo_valor_linha_timepicker_mm').options[index_mm].value!=dados.getElementsByTagName("detalhes")[0].childNodes[1].childNodes[1].firstChild.nodeValue){
					index_mm++;
				}
				document.getElementById('editar_tempo_valor_linha_timepicker_mm').options[index_mm].selected = true;
				tempo_flag=1;
			}
		}
	}
}
function change_editar(objecto,x){
	if(x=="titulo"){
		if(objecto.getAttribute('id')=="editar_titulo_nome"){
			var layout_titulo_nome=document.getElementById("layout_titulo_nome");
			layout_titulo_nome.innerText=objecto.value;
			if(objecto.value==""){
				valor='Sem Título';
			}
			valor=objecto.value;
		}
		else if(objecto.getAttribute('id')=="editar_titulo_descricao"){
			var layout_titulo_descricao=document.getElementById("layout_titulo_descricao");
			layout_titulo_descricao.innerText=objecto.value;
			valor=objecto.value;
		}
		info="0="+formulario+"&1="+objecto.getAttribute('id')+"&2="+valor;
		url="/mod/formularios/editar/change/titulo.php";
	}
	else if(x=="textfield"){
		if(objecto.getAttribute('id')=="editar_textfield_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_textfield_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(objecto.getAttribute('id')=="editar_textfield_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}
		else if(objecto.getAttribute('id')=="editar_textfield_tamanho"){
			var selecionado = objecto.selectedIndex
			if(objecto.options[selecionado].value==1){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','textfield_small');
				valor=1;
			}
			else if(objecto.options[selecionado].value==2){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','textfield_medium');
				valor=2;			
			}
			else if(objecto.options[selecionado].value==3){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','textfield_large');
				valor=3;
			}
		}
		else if(objecto.getAttribute('id')=="editar_textfield_valor"){
			current_element.firstChild.lastChild.firstChild.value=objecto.value;
			valor=objecto.value;
		}
		else if(objecto.getAttribute('id')=="editar_textfield_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value;
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+"&1="+current_element.getAttribute('id')+"&2="+objecto.getAttribute('id')+"&3="+valor;
		url="/mod/formularios/editar/change/text_field.php";
	}
	else if(x=="textarea"){
		if(objecto.getAttribute('id')=="editar_textarea_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_textarea_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(objecto.getAttribute('id')=="editar_textarea_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}
		else if(objecto.getAttribute('id')=="editar_textarea_tamanho"){
			var selecionado = objecto.selectedIndex
			if(objecto.options[selecionado].value==1){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','textarea_small');
				valor=1;			
			}
			else if(objecto.options[selecionado].value==2){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','textarea_medium');
				valor=2;						
			}
			else if(objecto.options[selecionado].value==3){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','textarea_large');
				valor=3;			
			}
		}
		else if(objecto.getAttribute('id')=="editar_textarea_valor"){
			current_element.firstChild.lastChild.firstChild.value=objecto.value;
			valor=objecto.value;
		}
		else if(objecto.getAttribute('id')=="editar_textarea_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+"&1="+current_element.getAttribute('id')+"&2="+objecto.getAttribute('id')+"&3="+valor;
		url="/mod/formularios/editar/change/text_area.php";
	}
	else if(x=="jumpmenu"){
		if(objecto.getAttribute('id')=="editar_jumpmenu_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
		}
		/*else if(objecto.getAttribute('id')=="editar_jumpmenu_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}*/
		else if(objecto.getAttribute('id')=="editar_jumpmenu_tamanho"){
			var selecionado = objecto.selectedIndex
			if(objecto.options[selecionado].value==1){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','jumpmenu_small');
				valor=1;			
			}
			else if(objecto.options[selecionado].value==2){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','jumpmenu_medium');
				valor=2;						
			}
			else if(objecto.options[selecionado].value==3){
				current_element.firstChild.lastChild.firstChild.setAttribute('class','jumpmenu_large');
				valor=3;			
			}
		}
		else if(objecto.getAttribute('id')=="editar_jumpmenu_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+objecto.getAttribute('id')+'&4='+valor;
		url="/mod/formularios/editar/change/jumpmenu.php";	
	}
	else if(x=="checkbox"){
		if(objecto.getAttribute('id')=="editar_checkbox_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_checkbox_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(objecto.getAttribute('id')=="editar_checkbox_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}
		else if(objecto.getAttribute('id')=="editar_checkbox_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+objecto.getAttribute('id')+'&4='+valor;
		url="/mod/formularios/editar/change/checkbox.php";	
	}
	else if(x=="radio"){
		if(objecto.getAttribute('id')=="editar_radio_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_radio_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		/*else if(objecto.getAttribute('id')=="editar_radio_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}*/
		else if(objecto.getAttribute('id')=="editar_radio_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+objecto.getAttribute('id')+'&4='+valor;
		url="/mod/formularios/editar/change/radio.php";	
	}
	else if(x=="quebra"){
		if(objecto.getAttribute('id')=="editar_quebra_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
		}
		else if(objecto.getAttribute('id')=="editar_quebra_descricao"){
			current_element.firstChild.lastChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
		}
		else if(objecto.getAttribute('id')=="editar_quebra_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value;
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+"&1="+current_element.getAttribute('id')+"&2="+objecto.getAttribute('id')+"&3="+valor;
		url="/mod/formularios/editar/change/quebra.php";
	}
	else if(x=="nome"){
		if(objecto.getAttribute('id')=="editar_nome_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_nome_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		/*else if(objecto.getAttribute('id')=="editar_nome_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}*/
		/*else if(objecto.getAttribute('id')=="editar_nome_predefinido"){
			if(objecto.checked){
				valor=1;
			}
			else{
				valor=0;
			}
		}*/
		else if(objecto.getAttribute('id')=="editar_nome_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+objecto.getAttribute('id')+'&3='+valor;
		url="/mod/formularios/editar/change/nome.php";
	}
	else if(x=="data"){
		var attribute;
		var editar_data_valor_linha_datepicker_input="editar_data_valor_linha_datepicker_input"+(datePickerController_hack-1);
		if(objecto.getAttribute('id')=="editar_data_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_data_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
			attribute=objecto.getAttribute('id');
		}
		else if(objecto.getAttribute('id')=="editar_data_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
			attribute=objecto.getAttribute('id');
		}
		else if(objecto.getAttribute('id')=="editar_data_valor_linha_activo"){
			current_element.firstChild.childNodes[1].childNodes[2].firstChild.value="";
			current_element.firstChild.childNodes[1].childNodes[1].firstChild.value="";
			current_element.firstChild.childNodes[1].childNodes[0].firstChild.value="";
			valor=null;
			attribute=objecto.getAttribute('id');
		}
		else if(objecto.getAttribute('id')==editar_data_valor_linha_datepicker_input){
			var texto=objecto.value;
			var index=texto.split("-");
			current_element.firstChild.childNodes[1].childNodes[2].firstChild.value=index[2];
			current_element.firstChild.childNodes[1].childNodes[1].firstChild.value=index[1];
			current_element.firstChild.childNodes[1].childNodes[0].firstChild.value=index[0];
			valor=texto;
			attribute="editar_data_valor_linha_datepicker_input";
		}
		else if(objecto.getAttribute('id')=="editar_data_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
			attribute=objecto.getAttribute('id');
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+attribute+'&3='+valor;
		url="/mod/formularios/editar/change/data.php";
	}
	else if(x=="tempo"){
		if(objecto.getAttribute('id')=="editar_tempo_nome"){
			current_element.firstChild.firstChild.innerHTML=objecto.value;
			valor=objecto.value;
			if(document.getElementById('editar_tempo_opcoes').checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
			}
		}
		else if(objecto.getAttribute('id')=="editar_tempo_opcoes"){
			if(objecto.checked){
				asterisco=document.createElement('span');
				asterisco.setAttribute('class','asterisco');
				asterisco.innerHTML=" *"
				current_element.firstChild.firstChild.appendChild(asterisco);
				valor=1;
			}
			else{
				current_element.firstChild.firstChild.removeChild(current_element.firstChild.firstChild.lastChild);
				valor=0;
			}
		}
		else if(objecto.getAttribute('id')=="editar_tempo_valor_linha_activo"){
			/*info="0="+current_element.getAttribute('posicao');
			ligar = ligacao();
			ligar.open("POST","/mod/formularios/editar/init/tempo.php",false);
			ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ligar.setRequestHeader("Content-length", info.lenght);
			ligar.setRequestHeader("Connection", "close");
			ligar.send(info);
			var valor = ligar.responseText;
			var	editar_conteudo=document.getElementById('editar_conteudo');
			editar_conteudo.innerHTML=valor;
			load_editar(x)*/
			
			
			current_element.firstChild.childNodes[1].childNodes[1].firstChild.value="";
			current_element.firstChild.childNodes[1].childNodes[0].firstChild.value="";
			document.getElementById("editar_tempo_valor_linha_timepicker_mm").disabled=true;
			tempo_flag=0;
			valor=null;			
		}
		else if(objecto.getAttribute('id')=="editar_tempo_valor_linha_timepicker_hh" || objecto.getAttribute('id')=="editar_tempo_valor_linha_timepicker_mm"){
			if(objecto.getAttribute('id')=="editar_tempo_valor_linha_timepicker_hh"){
				hora=objecto.options[objecto.selectedIndex].value;
				current_element.firstChild.childNodes[1].childNodes[0].firstChild.value=hora;
				if(tempo_flag==0){
					document.getElementById('editar_tempo_valor_linha_timepicker_hh').options[0]=null;
					document.getElementById('editar_tempo_valor_linha_timepicker_mm').options[0]=null;
					tempo_flag=1;
				}
				var index=document.getElementById('editar_tempo_valor_linha_timepicker_mm').selectedIndex;
				document.getElementById('editar_tempo_valor_linha_timepicker_mm').options[index].selected = true;
				minuto=document.getElementById('editar_tempo_valor_linha_timepicker_mm').options[document.getElementById('editar_tempo_valor_linha_timepicker_mm').selectedIndex].value;
				current_element.firstChild.childNodes[1].childNodes[1].firstChild.value	=minuto;
				document.getElementById('editar_tempo_valor_linha_timepicker_mm').disabled=false;
			}
			else if(objecto.getAttribute('id')=="editar_tempo_valor_linha_timepicker_mm"){
				minuto=objecto.options[objecto.selectedIndex].value;
				current_element.firstChild.childNodes[1].childNodes[1].firstChild.value=minuto;
			}
			valor=hora+":"+minuto;
		}
		else if(objecto.getAttribute('id')=="editar_tempo_instrucoes_linha"){
			current_element.lastChild.innerHTML=objecto.value
			if(objecto.value==""){
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao objecto_caixa_informacao_none');
			}
			else{
				current_element.lastChild.removeAttribute('class');
				current_element.lastChild.setAttribute('class','objecto_caixa_informacao');
			}
			valor=objecto.value;
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+objecto.getAttribute('id')+'&3='+valor;
		url="/mod/formularios/editar/change/tempo.php";
	}
	ligar = ligacao();
	ligar.open("POST",url,false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	if(x=="tempo" && objecto.getAttribute('id')=="editar_tempo_valor_linha_activo"){
		alert("linha");
		init_editar(current_element);
	}
}
function lixo(element){
	info="0="+formulario+'&1='+element.getAttribute('id');
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/objecto_remover.php",true);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	var parent_element=element.parentNode;
	parent_element.removeChild(element);
	current_element=null;
	ordenar();
}
function ordenar(){
	var id;
	var info="0="+formulario;
	
	/*var element_parent=element.parentNode;
	var children = element_parent.childNodes;*/
	var children = document.getElementById('layout').childNodes;
		
	for (var i = 0; i < children.length; i++){
		children[i].setAttribute("posicao",i+1);
	}
	
	for (i = 0; i < children.length; i++){
		id=children[i].getAttribute("id");
		info=info+"&"+(i+1)+"="+id;	
	}
	if(current_element!=null){
		document.getElementById('editar_conteudo').childNodes[1].innerHTML=current_element.getAttribute('posicao');
	}
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/objecto_ordenar.php",true);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
}
	
	
	
	
	
	/*var element_parent=element.parentNode;
	var children = element_parent.childNodes;
	
	for (var i = 0; i < children.length; i++){
		posicao=children[i].getAttribute("posicao");
		info=info+"&"+(i+1)+"="+posicao;	
	}
	for (i = 0; i < children.length; i++){
		children[i].setAttribute("posicao",i+1);
	}
	var erro=document.getElementById("erro");
	erro.innerHTML=info;
	
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/objecto_ordenar.php",true);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);*/
	
/*function ordenar_done(element){
	alert("linha");
	var element_parent=element.parentNode;
	var children = element_parent.childNodes;
	
	for (i = 0; i < children.length; i++){
		children[i].setAttribute("posicao",i+1);
	}
	var element_posicao_after=element.getAttribute('posicao');
	
	var erro=document.getElementById('erro');
	erro.innerHTML=element_posicao_init+"="+element_posicao_after;
}*/

function escolhas_init(y,nome){
		var contentor_construcao=document.getElementById('contentor_construcao');
		
		var escolhas=document.createElement('div');
		escolhas.setAttribute('id','escolhas');
	
		escolhas_contentor=document.createElement('div');
		escolhas_contentor.setAttribute('class','escolhas_contentor');
		escolhas_contentor.setAttribute('id','escolhas_contentor');
		//escolhas_contentor.setAttribute('style','position:absolute; width:700px; vertical-align: top;');

		contentor_construcao.appendChild(escolhas);
		escolhas.appendChild(escolhas_contentor);
		
		var escolhas_contentor_moldura=document.createElement('div');
		escolhas_contentor_moldura.setAttribute('id','escolhas_contentor_moldura');
		var escolhas_contentor_gestao=document.createElement("div");
		escolhas_contentor_gestao.setAttribute('id','escolhas_contentor_gestao');
		escolhas_contentor_gestao.style.display="none";
	
		escolhas_contentor.appendChild(escolhas_contentor_gestao);
		escolhas_contentor.appendChild(escolhas_contentor_moldura);
		
		var escolhas_contentor_moldura_control=document.createElement("div");
		escolhas_contentor_moldura_control.setAttribute('class','escolhas_contentor_moldura_control');
	
	if(y==0){	
		var escolhas_contentor_moldura_descricao=document.createElement('div');
		escolhas_contentor_moldura_descricao.setAttribute('class','escolhas_contentor_moldura_descricao');
		escolhas_contentor_moldura_descricao.innerHTML="Adicionar a Partir de Escolhas Predefinidas"
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_descricao);
		var escolhas_contentor_moldura_instruccoes=document.createElement('div');
		escolhas_contentor_moldura_instruccoes.setAttribute('class','escolhas_contentor_moldura_instruccoes');
		escolhas_contentor_moldura_instruccoes.innerHTML="(1: Selecione uma das categorias) (2: Altere como desejar) (3: Adicione ao seu objecto)";
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_instruccoes);
	
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/processos/escolhas_query.php",false);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(null);
		var dados=ligar.responseXML;
		dados=dados.getElementsByTagName('dados')[0];
		var childs=dados.childNodes;
		
		var escolhas_contentor_moldura_lista=document.createElement('div');	
		escolhas_contentor_moldura_lista.setAttribute('class','escolhas_contentor_moldura_lista');
	
		for(var a=0;a<childs.length;a++){
			var id=childs[a].getElementsByTagName("id")[0].firstChild.nodeValue;
			var descricao=childs[a].getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
			var escolhas_contentor_moldura_lista_categoria=document.createElement('div');	
			escolhas_contentor_moldura_lista_categoria.setAttribute('class','escolhas_contentor_moldura_lista_categoria');
			escolhas_contentor_moldura_lista_categoria.setAttribute('id',id);
			escolhas_contentor_moldura_lista_categoria.setAttribute('onclick','escolhas_seleccao(this)');
	
			
			var escolhas_contentor_moldura_lista_categoria_descricao=document.createElement('div');	
			escolhas_contentor_moldura_lista_categoria_descricao.setAttribute('class','escolhas_contentor_moldura_lista_categoria_descricao');
			escolhas_contentor_moldura_lista_categoria_descricao.innerHTML=descricao;
	
			escolhas_contentor_moldura_lista_categoria.appendChild(escolhas_contentor_moldura_lista_categoria_descricao);
			
			escolhas_contentor_moldura_lista.appendChild(escolhas_contentor_moldura_lista_categoria);
		}
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_lista);
		
		var escolhas_contentor_moldura_caracter=document.createElement("div");
		escolhas_contentor_moldura_caracter.setAttribute('class','escolhas_contentor_moldura_caracter');
		escolhas_contentor_moldura_caracter.innerText='{';
		
		var escolhas_contentor_moldura_area=document.createElement("div");
		escolhas_contentor_moldura_area.setAttribute('class','escolhas_contentor_moldura_area');
		escolhas_contentor_moldura_area.setAttribute('id','escolhas_contentor_moldura_area');
		
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_caracter);
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_area);
		
		//var escolhas_contentor_moldura_control=document.createElement("div");
		//escolhas_contentor_moldura_control.setAttribute('class','escolhas_contentor_moldura_control');
		
		var escolhas_contentor_moldura_control_gerir=document.createElement("div");
		escolhas_contentor_moldura_control_gerir.setAttribute('class','escolhas_contentor_moldura_control_gerir');
	
		var input_gerir=document.createElement("input");
		input_gerir.setAttribute('type','submit');
		input_gerir.setAttribute('name','gerir');
		input_gerir.setAttribute('id','input_gerir');
		input_gerir.setAttribute('value','Gerir Categorias');
		input_gerir.setAttribute('onClick','DropOut(escolhas_contentor_moldura,"escolhas_gestao")');
		
		/*var escolhas_contentor_moldura_control_cancelar=document.createElement("div");
		escolhas_contentor_moldura_control_cancelar.setAttribute('class','escolhas_contentor_moldura_control_cancelar');
		
		var input_cancelar=document.createElement("input");
		input_cancelar.setAttribute('type','submit');
		input_cancelar.setAttribute('name','gerir');
		input_cancelar.setAttribute('id','input_cancelar');
		input_cancelar.setAttribute('value','Cancelar');
		input_cancelar.setAttribute('onClick','carregar_escolhas(escolhas_contentor_moldura,2)');*/
		
		escolhas_contentor_moldura_control_gerir.appendChild(input_gerir);
		//escolhas_contentor_moldura_control_cancelar.appendChild(input_cancelar);
		escolhas_contentor_moldura_control.appendChild(escolhas_contentor_moldura_control_gerir);
		//escolhas_contentor_moldura_control.appendChild(escolhas_contentor_moldura_control_cancelar);
		
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_control);
		
		/*<input type="submit" name="button" id="button" value="Submit" />*/
		
		//alert("passou");	
		
		//var nome=dados.getElementsByTagName("id")[0].firstChild.nodeValue;
		//var descricao=dados.getElementsByTagName("descricao")[0].firstChild.nodeValue;
		
		var escolhas_contentor_moldura_control_cancelar=document.createElement("div");
		escolhas_contentor_moldura_control_cancelar.setAttribute('class','escolhas_contentor_moldura_control_cancelar');
		
		var input_cancelar=document.createElement("input");
		input_cancelar.setAttribute('type','submit');
		input_cancelar.setAttribute('name','gerir');
		input_cancelar.setAttribute('id','input_cancelar');
		input_cancelar.setAttribute('value','Cancelar');
		input_cancelar.setAttribute('onClick','carregar_escolhas(escolhas_contentor_moldura,2)');
		
		var escolhas_contentor_moldura_control_adicionar=document.createElement("div");
		escolhas_contentor_moldura_control_adicionar.setAttribute('class','escolhas_contentor_moldura_control_adicionar');
		
		var input_adicionar=document.createElement("input");
		input_adicionar.setAttribute('type','submit');
		input_adicionar.setAttribute('name','gerir');
		input_adicionar.setAttribute('id','input_adicionar');
		input_adicionar.setAttribute('value','Adicionar Ao Objecto');
		input_adicionar.disabled=true;
		input_adicionar.setAttribute('onClick','carregar_escolhas(escolhas_contentor_moldura,3)');
		escolhas_contentor_moldura_control_adicionar.appendChild(input_adicionar);
		escolhas_contentor_moldura_control.appendChild(escolhas_contentor_moldura_control_adicionar);
		
		escolhas_contentor_moldura_control_cancelar.appendChild(input_cancelar);
		escolhas_contentor_moldura_control.appendChild(escolhas_contentor_moldura_control_cancelar);		
	}
	else if(y==1){
		var escolhas_contentor_moldura_descricao=document.createElement('div');
		escolhas_contentor_moldura_descricao.setAttribute('class','escolhas_contentor_moldura_descricao');
		escolhas_contentor_moldura_descricao.innerHTML="Adicionar Nome(s) Predefinido(s)"
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_descricao);
		var escolhas_contentor_moldura_instruccoes=document.createElement('div');
		escolhas_contentor_moldura_instruccoes.setAttribute('class','escolhas_contentor_moldura_instruccoes');
		escolhas_contentor_moldura_instruccoes.innerHTML="(1: Escolha uma das opções predefinidas) (2: Adicione ao seu objecto)";
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_instruccoes);
		
		var escolhas_contentor_moldura_lista=document.createElement('div');	
		escolhas_contentor_moldura_lista.setAttribute('class','escolhas_contentor_moldura_lista_nome');
		
		var escolhas_contentor_moldura_lista_defeito=document.createElement('div');	
		escolhas_contentor_moldura_lista_defeito.setAttribute('class','escolhas_contentor_moldura_lista_defeito');
		
		var input_defeito=document.createElement("input");
		input_defeito.setAttribute('name','radio');
		input_defeito.setAttribute('type','radio');
		input_defeito.setAttribute('class','escolhas_contentor_moldura_lista_defeito_radio');
		input_defeito.setAttribute('onClick','javascript:carregar_escolhas_nome(0)');

	
		var escolhas_contentor_moldura_lista_defeito_texto=document.createElement('div');	
		escolhas_contentor_moldura_lista_defeito_texto.setAttribute('class','escolhas_contentor_moldura_lista_defeito_texto')
		escolhas_contentor_moldura_lista_defeito_texto.innerHTML="1º (valor por defeito) - Esta opção quando selecionada irá defenir o campo nome com o nome do utilizador que preenche o formulário";
		
		escolhas_contentor_moldura_lista_defeito.appendChild(input_defeito);
		escolhas_contentor_moldura_lista_defeito.appendChild(escolhas_contentor_moldura_lista_defeito_texto);
		
		var escolhas_contentor_moldura_lista_filhos=document.createElement('div');	
		escolhas_contentor_moldura_lista_filhos.setAttribute('class','escolhas_contentor_moldura_lista_filhos')
		
		var input_filhos=document.createElement("input");
		input_filhos.setAttribute('name','radio');
		input_filhos.setAttribute('type','radio');
		input_filhos.setAttribute('class','escolhas_contentor_moldura_lista_filhos_radio');
		input_filhos.setAttribute('onClick','javascript:carregar_escolhas_nome(1)');
		
		var escolhas_contentor_moldura_lista_filhos_texto=document.createElement('div');	
		escolhas_contentor_moldura_lista_filhos_texto.setAttribute('class','escolhas_contentor_moldura_lista_filhos_texto')
		escolhas_contentor_moldura_lista_filhos_texto.innerHTML="2º - Esta opção quando selecionada irá permitir ao utilizador defenir o campo nome com um dos encarregandos do qual o utilizador que preenche o formulário é titular <br></br> *Esta opção só é possivel quando o formulário é preenchido apenas e só por Encarregados de Educação.)";

		escolhas_contentor_moldura_lista_filhos.appendChild(input_filhos);
		escolhas_contentor_moldura_lista_filhos.appendChild(escolhas_contentor_moldura_lista_filhos_texto);
		
		escolhas_contentor_moldura_lista.appendChild(escolhas_contentor_moldura_lista_defeito);
		escolhas_contentor_moldura_lista.appendChild(escolhas_contentor_moldura_lista_filhos);
		
		escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_lista);
		
		var escolhas_contentor_moldura_control_cancelar=document.createElement("div");
		escolhas_contentor_moldura_control_cancelar.setAttribute('class','escolhas_contentor_moldura_control_cancelar');
		
		var input_cancelar=document.createElement("input");
		input_cancelar.setAttribute('type','submit');
		input_cancelar.setAttribute('name','gerir');
		input_cancelar.setAttribute('id','input_cancelar');
		input_cancelar.setAttribute('value','Guardar Alterações');
		input_cancelar.setAttribute('onClick','carregar_escolhas(escolhas_contentor_moldura,2)');
		
		escolhas_contentor_moldura_control_cancelar.appendChild(input_cancelar);
		escolhas_contentor_moldura_control.appendChild(escolhas_contentor_moldura_control_cancelar);		
		
		if(nome==0){
			input_defeito.setAttribute('checked','checked');
		}
		else if(nome==1){
			input_filhos.setAttribute('checked','checked');
		}

	}	
	escolhas_contentor_moldura.appendChild(escolhas_contentor_moldura_control);	
	//crossobj=document.all? document.all.staticcontent : document.getElementById("escolhas_contentor");
}
function carregar_escolhas_nome(x){
	var editar_escolhas_predefenidas_linha=document.getElementById('editar_escolhas_predefenidas_linha');
	removerChildNodes(editar_escolhas_predefenidas_linha);
	var editar_escolhas_predefenidas_nome=document.createElement('div');
	editar_escolhas_predefenidas_nome.setAttribute('class','editar_escolhas_predefenidas_nome');
	editar_escolhas_predefenidas_linha.appendChild(editar_escolhas_predefenidas_nome);
	if(x==0){
		editar_escolhas_predefenidas_nome.setAttribute('onClick','javascript:carregar_escolhas(null,1,1,0)');
		editar_escolhas_predefenidas_nome.innerHTML="A opção selecionada para este objecto é a 1ª (valor por defeito).  <b>(Alterar)</b>";
	}
	else if(x==1){		
		editar_escolhas_predefenidas_nome.setAttribute('onClick','javascript:carregar_escolhas(null,1,1,1)');
		editar_escolhas_predefenidas_nome.innerHTML="A opção selecionada para este objecto é a 2ª.  <b>(Alterar)</b>";
	}
	info="0="+current_element.getAttribute("id")+"&1="+x;
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/escolhas_nome.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
}
function escolhas_seleccao(objecto){
	input_adicionar=document.getElementById('input_adicionar');
	input_adicionar.disabled=false;
	
	info="0="+objecto.getAttribute("id");
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/escolhas_seleccao.php",false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	var dados = ligar.responseXML;
	dados=dados.getElementsByTagName('dados')[0];
	var childs=dados.childNodes;
	
	escolhas_contentor_moldura_area=document.getElementById('escolhas_contentor_moldura_area');
	removerChildNodes(escolhas_contentor_moldura_area);
	
	
	var escolhas_contentor_gestao_atributo=document.createElement('div');
	escolhas_contentor_gestao_atributo.setAttribute('id','escolhas_contentor_moldura_atributo');
		
	for(var a=0;a<childs.length;a++){
		var id=childs[a].getElementsByTagName("id")[0].firstChild.nodeValue;
		var descricao=childs[a].getElementsByTagName("descricao")[0].firstChild.nodeValue;
		descricao=html_entity_decode(descricao);
		//alert(descricao);
		
		var escolhas_contentor_gestao_atributo_linha=document.createElement('div');
		escolhas_contentor_gestao_atributo_linha.setAttribute('class','escolhas_contentor_gestao_atributo_linha');	
		//escolhas_contentor_gestao_atributo_linha.setAttribute('id',x);
		
			var escolhas_contentor_gestao_atributo_linha_texto=document.createElement('div');
			escolhas_contentor_gestao_atributo_linha_texto.setAttribute('class','escolhas_contentor_gestao_atributo_linha_texto');	
				var input=document.createElement("input");
				input.setAttribute('name','texto');
				input.setAttribute('id','texto');
				input.setAttribute('type','text');
				input.setAttribute('value',descricao);
			escolhas_contentor_gestao_atributo_linha_texto.appendChild(input);
		
			var escolhas_contentor_gestao_atributo_linha_plus_minus=document.createElement('div');
			escolhas_contentor_gestao_atributo_linha_plus_minus.setAttribute('class','escolhas_contentor_gestao_atributo_linha_plus_minus');
			
				img_plus=document.createElement("img");
				img_plus.setAttribute('src',"/mod/formularios/icons/plus.png");
				img_plus.setAttribute('onclick','escolhas_gestao_atributo(this,1)');

		
				img_minus=document.createElement("img");
				img_minus.setAttribute('src',"/mod/formularios/icons/minus.png");
				img_minus.setAttribute('onclick','escolhas_gestao_atributo(this,0)');

				
			escolhas_contentor_gestao_atributo_linha_plus_minus.appendChild(img_plus);
			escolhas_contentor_gestao_atributo_linha_plus_minus.appendChild(img_minus);
		
		escolhas_contentor_gestao_atributo_linha.appendChild(escolhas_contentor_gestao_atributo_linha_texto);
		escolhas_contentor_gestao_atributo_linha.appendChild(escolhas_contentor_gestao_atributo_linha_plus_minus);
		
		escolhas_contentor_gestao_atributo.appendChild(escolhas_contentor_gestao_atributo_linha);
	}
	escolhas_contentor_moldura_area.appendChild(escolhas_contentor_gestao_atributo);
}
function DropOut(element,valor){
   new Effect.DropOut(element, {duration:1});

   if(valor=="escolhas_gestao"){
		setTimeout("escolhas_gestao()",1000);
   }
   else if(valor=="adicionar"){
		setTimeout("escolhas_adicionar()",1000);
	}
   else if(valor=="cancelar"){
		setTimeout("escolhas_esconder()",1000);
	}
}
function escolhas_gestao(){
 	Effect.Appear("escolhas_contentor_gestao",{duration:1});
	var escolhas_contentor_gestao_descricao=document.createElement('div');
	escolhas_contentor_gestao_descricao.setAttribute('class','escolhas_contentor_gestao_descricao');
	escolhas_contentor_gestao_descricao.innerHTML="Criar Nova Categoria"
	escolhas_contentor_gestao.appendChild(escolhas_contentor_gestao_descricao);
	var escolhas_contentor_gestao_instruccoes=document.createElement('div');
	escolhas_contentor_gestao_instruccoes.setAttribute('class','escolhas_contentor_gestao_instruccoes');
	escolhas_contentor_gestao_instruccoes.innerHTML="(1: Selecione uma das categorias) (2: Altere como desejar) (3: Adicione ao seu menu suspenso)";
	escolhas_contentor_gestao.appendChild(escolhas_contentor_gestao_instruccoes);
	
	var escolhas_contentor_gestao_atributo=document.createElement('div');
	escolhas_contentor_gestao_atributo.setAttribute('id','escolhas_contentor_gestao_atributo');
	for(var x=1;x<8;x++){
		var escolhas_contentor_gestao_atributo_linha=document.createElement('div');
		escolhas_contentor_gestao_atributo_linha.setAttribute('class','escolhas_contentor_gestao_atributo_linha');	
		//escolhas_contentor_gestao_atributo_linha.setAttribute('id',x);
		
			var escolhas_contentor_gestao_atributo_linha_texto=document.createElement('div');
			escolhas_contentor_gestao_atributo_linha_texto.setAttribute('class','escolhas_contentor_gestao_atributo_linha_texto');	
				var input=document.createElement("input");
				input.setAttribute('name','texto');
				input.setAttribute('id','texto');
				input.setAttribute('type','text');
			escolhas_contentor_gestao_atributo_linha_texto.appendChild(input);
		
			var escolhas_contentor_gestao_atributo_linha_plus_minus=document.createElement('div');
			escolhas_contentor_gestao_atributo_linha_plus_minus.setAttribute('class','escolhas_contentor_gestao_atributo_linha_plus_minus');
			
				img_plus=document.createElement("img");
				img_plus.setAttribute('src',"/mod/formularios/icons/plus.png");
				img_plus.setAttribute('onclick','escolhas_gestao_atributo(this,1)');

		
				img_minus=document.createElement("img");
				img_minus.setAttribute('src',"/mod/formularios/icons/minus.png");
				img_minus.setAttribute('onclick','escolhas_gestao_atributo(this,0)');

				
			escolhas_contentor_gestao_atributo_linha_plus_minus.appendChild(img_plus);
			escolhas_contentor_gestao_atributo_linha_plus_minus.appendChild(img_minus);
		
		escolhas_contentor_gestao_atributo_linha.appendChild(escolhas_contentor_gestao_atributo_linha_texto);
		escolhas_contentor_gestao_atributo_linha.appendChild(escolhas_contentor_gestao_atributo_linha_plus_minus);
		
		escolhas_contentor_gestao_atributo.appendChild(escolhas_contentor_gestao_atributo_linha);
	}
	escolhas_contentor_gestao.appendChild(escolhas_contentor_gestao_atributo);
}
function escolhas_adicionar(){
	editar_escolhas=document.getElementById('editar_escolhas');
	removerChildNodes(editar_escolhas);
	if(current_element.getAttribute('type')=='jumpmenu'){
		removerChildNodes(current_element.firstChild.lastChild.firstChild);
	}
	else if(current_element.getAttribute('type')=='checkbox' || current_element.getAttribute('type')=='radio'){
		removerChildNodes(current_element.firstChild.lastChild);
	}


	escolhas_contentor_moldura_atributo=document.getElementById('escolhas_contentor_moldura_atributo');
	
	var escolhas_contentor_moldura_atributo=document.getElementById('escolhas_contentor_moldura_atributo');
			
	var escolhas_contentor_gestao_atributo=document.createElement('div');
	escolhas_contentor_gestao_atributo.setAttribute('id','editar_escolhas_contentor_moldura_atributo');
	
	var info=new Array();
			
	for(var x=0;x<escolhas_contentor_moldura_atributo.childNodes.length;x++){
		
		var editar_escolhas_linha=document.createElement('div');
		editar_escolhas_linha.setAttribute('class','editar_escolhas_linha');	
		editar_escolhas_linha.setAttribute('value',x);	
								
		var editar_escolhas_linha_radio=document.createElement('div');
		editar_escolhas_linha_radio.setAttribute('class','editar_escolhas_linha_radio');
		var input_radio=document.createElement("input");
		
		if(current_element.getAttribute('type')=='jumpmenu' || current_element.getAttribute('type')=='radio'){
			input_radio.setAttribute('name','radio');
			input_radio.setAttribute('type','radio');
			if(x==0){
				input_radio.setAttribute('checked','checked');
				//input_radio.click();
				//current_element.firstChild.lastChild.firstChild.childNodes[0].firstChild.nodeValue=	escolhas_contentor_moldura_atributo.childNodes[x].firstChild.firstChild.value;
			}
		}
		else if(current_element.getAttribute('type')=='checkbox'){
			input_radio.setAttribute('name','checkbox');
			input_radio.setAttribute('type','checkbox');
		}
		input_radio.setAttribute('onclick','escolhas_selecionado(this,"'+current_element.getAttribute('type')+'")');
		editar_escolhas_linha_radio.appendChild(input_radio);
		
		var editar_escolhas_linha_text=document.createElement('div');
		editar_escolhas_linha_text.setAttribute('class','editar_escolhas_linha_text');	
		var input=document.createElement("input");
		input.setAttribute('name','texto');
		input.setAttribute('id','texto');
		input.setAttribute('type','text');
		input.setAttribute('class','editar_escolhas_linha_text_input');
		var value=escolhas_contentor_moldura_atributo.childNodes[x].firstChild.firstChild.value;
		input.setAttribute('value',value);
		editar_escolhas_linha_text.appendChild(input);
		
		input.setAttribute('onkeyup','escolhas_selecionado(this,"'+current_element.getAttribute('type')+'")');
		
		var editar_escolhas_linha_plus_minus=document.createElement('div');
		editar_escolhas_linha_plus_minus.setAttribute('class','editar_escolhas_linha_plus_minus');
			
		img_plus=document.createElement("img");
		img_plus.setAttribute('src',"/mod/formularios/icons/plus.png");
		img_plus.setAttribute('type','plus');
		img_plus.setAttribute('onclick','escolhas_selecionado(this,"'+current_element.getAttribute('type')+'")');


		img_minus=document.createElement("img");
		img_minus.setAttribute('src',"/mod/formularios/icons/minus.png");
		img_minus.setAttribute('type','minus');
		img_minus.setAttribute('onclick','escolhas_selecionado(this,"'+current_element.getAttribute('type')+'")');

				
		editar_escolhas_linha_plus_minus.appendChild(img_plus);
		editar_escolhas_linha_plus_minus.appendChild(img_minus);
		
		editar_escolhas_linha.appendChild(editar_escolhas_linha_radio);
		editar_escolhas_linha.appendChild(editar_escolhas_linha_text);
		editar_escolhas_linha.appendChild(editar_escolhas_linha_plus_minus);
		editar_escolhas.appendChild(editar_escolhas_linha);
		
		if(current_element.getAttribute('type')=='jumpmenu'){
			var option=document.createElement("option");
			option.innerHTML=escolhas_contentor_moldura_atributo.childNodes[x].firstChild.firstChild.value;
			option.setAttribute('value',x);
			current_element.firstChild.lastChild.firstChild.appendChild(option);
		}
		else if(current_element.getAttribute('type')=='checkbox'){
			var objecto_checkbox_caixa_input=document.createElement("div");
			objecto_checkbox_caixa_input.setAttribute('class','objecto_checkbox_caixa_input');
			var input=document.createElement("input");
			input.setAttribute('name',"checkbox");
			input.setAttribute('type','checkbox');
			input.setAttribute('disabled','disabled');
			input.setAttribute('class','objecto_checkbox_caixa_input_value');
			objecto_checkbox_caixa_input.appendChild(input);
			var objecto_checkbox_caixa_input_label=document.createElement("div");
			objecto_checkbox_caixa_input_label.setAttribute('class','objecto_checkbox_caixa_input_label');
			objecto_checkbox_caixa_input_label.innerHTML=escolhas_contentor_moldura_atributo.childNodes[x].firstChild.firstChild.value;
			objecto_checkbox_caixa_input.appendChild(objecto_checkbox_caixa_input_label);
			objecto_checkbox_caixa_input.setAttribute('value',x);
			current_element.firstChild.lastChild.appendChild(objecto_checkbox_caixa_input);
		}
		else if(current_element.getAttribute('type')=='radio'){
			var objecto_radio_caixa_input=document.createElement("div");
			objecto_radio_caixa_input.setAttribute('class','objecto_radio_caixa_input');
			var input=document.createElement("input");
			input.setAttribute('name','radio'+current_element.getAttribute('id'));
			input.setAttribute('type','radio');
			input.setAttribute('disabled','disabled');
			input.setAttribute('class','objecto_radio_caixa_input_value');
			objecto_radio_caixa_input.appendChild(input);
			var objecto_radio_caixa_input_label=document.createElement("div");
			objecto_radio_caixa_input_label.setAttribute('class','objecto_radio_caixa_input_label');
			objecto_radio_caixa_input_label.innerHTML=escolhas_contentor_moldura_atributo.childNodes[x].firstChild.firstChild.value;
			objecto_radio_caixa_input.appendChild(objecto_radio_caixa_input_label);
			objecto_radio_caixa_input.setAttribute('value',x);
			current_element.firstChild.lastChild.appendChild(objecto_radio_caixa_input);
			current_element.firstChild.childNodes[1].firstChild.firstChild.checked=true;
		}

		
		info[x]=value;
	}
	var know=current_element.getAttribute('id');
	javascript_array_to_string(info);
	know="0="+formulario+"-"+know+'-'+info;
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/escolhas_adicionar.php",true);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", know.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(know);
}
function escolhas_gestao_atributo(element,value){
	if(value==1){
		element=element.parentNode;
		element=element.parentNode;
		element_pai=element.parentNode;
		
		var escolhas_contentor_gestao_atributo_linha=document.createElement('div');
		escolhas_contentor_gestao_atributo_linha.setAttribute('class','escolhas_contentor_gestao_atributo_linha');	
		
			var escolhas_contentor_gestao_atributo_linha_texto=document.createElement('div');
			escolhas_contentor_gestao_atributo_linha_texto.setAttribute('class','escolhas_contentor_gestao_atributo_linha_texto');	
				var input=document.createElement("input");
				input.setAttribute('name','texto');
				input.setAttribute('id','texto');
				input.setAttribute('type','text');
			escolhas_contentor_gestao_atributo_linha_texto.appendChild(input);
		
			var escolhas_contentor_gestao_atributo_linha_plus_minus=document.createElement('div');
			escolhas_contentor_gestao_atributo_linha_plus_minus.setAttribute('class','escolhas_contentor_gestao_atributo_linha_plus_minus');
			
				img_plus=document.createElement("img");
				img_plus.setAttribute('src',"/mod/formularios/icons/plus.png");
				img_plus.setAttribute('onclick','escolhas_gestao_atributo(this,1)');

		
				img_minus=document.createElement("img");
				img_minus.setAttribute('src',"/mod/formularios/icons/minus.png");
				img_minus.setAttribute('onclick','escolhas_gestao_atributo(this,0)');

				
			escolhas_contentor_gestao_atributo_linha_plus_minus.appendChild(img_plus);
			escolhas_contentor_gestao_atributo_linha_plus_minus.appendChild(img_minus);
		
		escolhas_contentor_gestao_atributo_linha.appendChild(escolhas_contentor_gestao_atributo_linha_texto);
		escolhas_contentor_gestao_atributo_linha.appendChild(escolhas_contentor_gestao_atributo_linha_plus_minus);
		
		element_pai.insertBefore(escolhas_contentor_gestao_atributo_linha, element);
	}
	else if(value==2){
		element=element.parentNode;
		element=element.parentNode;
		element_pai=element.parentNode;
		
		editar_escolhas_linha=document.getElementById('editar_escolhas_linha');
		escolhas_contentor_moldura_atributo=document.getElementById('escolhas_contentor_moldura_atributo');
				
		editar_escolhas_linha=document.getElementById('editar_escolhas_linha');
		
		var escolhas_contentor_gestao_atributo=document.createElement('div');
		escolhas_contentor_gestao_atributo.setAttribute('id','editar_escolhas_contentor_moldura_atributo');
					
			var editar_jumpmenu_escolhas_linha=document.createElement('div');
			editar_jumpmenu_escolhas_linha.setAttribute('class','editar_jumpmenu_escolhas_linha');
									
				var editar_jumpmenu_escolhas_linha_radio=document.createElement('div');
				editar_jumpmenu_escolhas_linha_radio.setAttribute('class','editar_jumpmenu_escolhas_linha_radio');
					var input_radio=document.createElement("input");
					input_radio.setAttribute('name','jumpmenu');
					input_radio.setAttribute('type','radio');
					input_radio.setAttribute('onClick','escolhas_selecionado(this,0)');
				editar_jumpmenu_escolhas_linha_radio.appendChild(input_radio);
			
				var editar_jumpmenu_escolhas_linha_text=document.createElement('div');
				editar_jumpmenu_escolhas_linha_text.setAttribute('class','editar_jumpmenu_escolhas_linha_text');	
					var input=document.createElement("input");
					input.setAttribute('name','texto');
					input.setAttribute('id','texto');
					input.setAttribute('type','text');
				editar_jumpmenu_escolhas_linha_text.appendChild(input);
				
				input.setAttribute('onkeyup','escolhas_selecionado(this,1)');
				input.setAttribute('onblur','escolhas_selecionado(this,1)');
			
				var editar_jumpmenu_escolhas_linha_plus_minus=document.createElement('div');
				editar_jumpmenu_escolhas_linha_plus_minus.setAttribute('class','editar_jumpmenu_escolhas_linha_plus_minus');
				
					img_plus=document.createElement("img");
					img_plus.setAttribute('src',"/mod/formularios/icons/plus.png");
					img_plus.setAttribute('onclick','escolhas_gestao_atributo(this,2)');
		
			
					img_minus=document.createElement("img");
					img_minus.setAttribute('src',"/mod/formularios/icons/minus.png");
					img_minus.setAttribute('onclick','escolhas_gestao_atributo(this,3)');
		
					
				editar_jumpmenu_escolhas_linha_plus_minus.appendChild(img_plus);
				editar_jumpmenu_escolhas_linha_plus_minus.appendChild(img_minus);
			
			editar_jumpmenu_escolhas_linha.appendChild(editar_jumpmenu_escolhas_linha_radio);
			editar_jumpmenu_escolhas_linha.appendChild(editar_jumpmenu_escolhas_linha_text);
			editar_jumpmenu_escolhas_linha.appendChild(editar_jumpmenu_escolhas_linha_plus_minus);
			
			element_pai.insertBefore(editar_jumpmenu_escolhas_linha, element.nextSibling);
			
		var posicao=element.getAttribute('value');
			
		var pai_childnodes=element_pai.childNodes;
			
		for(var i=0;i<pai_childnodes.length;i++){
			pai_childnodes[i].removeAttribute('value');
			pai_childnodes[i].setAttribute('value',i);
		}
		var know=current_element.getAttribute('id');
		know="0="+formulario+'-'+know+'-'+2+'-'+posicao;
		alert(know);
		ligar = ligacao();
		ligar.open("POST","/mod/formularios/processos/escolhas_gestao_atributo.php",true);
		ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ligar.setRequestHeader("Content-length", know.lenght);
		ligar.setRequestHeader("Connection", "close");
		ligar.send(know);
	}
	else if(value==0){
		element=element.parentNode;
		element=element.parentNode;
		element_pai=element.parentNode;
		element_childnodes=element_pai.childNodes;
		if(element_childnodes.length>1){
			element_pai.removeChild(element);	
		}
	}
	else if(value==3){
		element=element.parentNode;
		element=element.parentNode;
		element_pai=element.parentNode;
		element_childnodes=element_pai.childNodes;
		if(element_childnodes.length>1){
			if(element.childNodes[0].firstChild.checked){
				element_pai.removeChild(element);	
				element_childnodes[0].childNodes[0].firstChild.click();
			}
			else{
				element_pai.removeChild(element);	
			}
		}
		var pai_childnodes=element_pai.childNodes;
			
		for(var i=0;i<pai_childnodes.length;i++){
			pai_childnodes[i].removeAttribute('value');
			pai_childnodes[i].setAttribute('value',i);
		}
	}
}
function escolhas_selecionado(element,x){
	var valor;
	var fim;
	if(x=='jumpmenu'){
		if(element.getAttribute('type')=='radio'){
			current_element.firstChild.lastChild.firstChild.options[element.parentNode.parentNode.getAttribute('value')].selected = true;
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='text'){
			current_element.firstChild.lastChild.firstChild.options[element.parentNode.parentNode.getAttribute('value')].innerHTML=element.value;
			valor=element.value;
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='plus'){
			plus(element,x);
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='minus'){
			minus(element,x);
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+'editar'+'&3='+element.getAttribute('type')+'&4='+valor+'&5='+posicao;
		var url="/mod/formularios/editar/change/jumpmenu.php";
	}
	else if(x=='checkbox'){
		checked=null;
		if(element.getAttribute('type')=='checkbox'){
			if(element.checked){
				current_element.firstChild.childNodes[1].childNodes[element.parentNode.parentNode.getAttribute('value')].firstChild.setAttribute('checked','checked');
				posicao=element.parentNode.parentNode.getAttribute('value');
				checked=1;
			}
			else{
				current_element.firstChild.childNodes[1].childNodes[element.parentNode.parentNode.getAttribute('value')].firstChild.removeAttribute('checked');
				posicao=element.parentNode.parentNode.getAttribute('value');
				checked=0;
			}
		}
		else if(element.getAttribute('type')=='text'){
			current_element.firstChild.childNodes[1].childNodes[element.parentNode.parentNode.getAttribute('value')].lastChild.innerHTML=element.value;
			valor=element.value;
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='plus'){
			plus(element,x);
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='minus'){
			minus(element,x);
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+'editar'+'&3='+element.getAttribute('type')+'&4='+valor+'&5='+posicao+'&6='+checked;
		var url="/mod/formularios/editar/change/checkbox.php";
	}
	else if(x=='radio'){
		if(element.getAttribute('type')=='radio'){
			if(element.checked){
				current_element.firstChild.lastChild.childNodes[element.parentNode.parentNode.getAttribute('value')].firstChild.checked=true;
			}
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='text'){
			current_element.firstChild.childNodes[1].childNodes[element.parentNode.parentNode.getAttribute('value')].lastChild.innerHTML=element.value;
			valor=element.value;
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		else if(element.getAttribute('type')=='plus'){
			plus(element,x);
			posicao=element.parentNode.parentNode.getAttribute('value');
			//valor='Indefinido';
		}
		else if(element.getAttribute('type')=='minus'){
			minus(element,x);
			posicao=element.parentNode.parentNode.getAttribute('value');
		}
		info="0="+formulario+'&1='+current_element.getAttribute('id')+'&2='+'editar'+'&3='+element.getAttribute('type')+'&4='+valor+'&5='+posicao;
		var url="/mod/formularios/editar/change/radio.php";
	}
	ligar = ligacao();
	ligar.open("POST",url,false);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
	/*if(element.getAttribute('type')=='plus'){
		var valor = ligar.responseText;
		document.getElementById('centro').innerHTML=valor;
	}*/
}
function plus(element,x){
	element=element.parentNode.parentNode;
	pai=element.parentNode;
	
	var editar_escolhas_linha=document.createElement('div');
	editar_escolhas_linha.setAttribute('class','editar_escolhas_linha');
	
	var editar_escolhas_linha_radio=document.createElement('div');
	editar_escolhas_linha_radio.setAttribute('class','editar_escolhas_linha_radio');
	
	var input_radio=document.createElement('input');	
	if(x=='jumpmenu'){
		input_radio.setAttribute('name','radio');
		input_radio.setAttribute('type','radio');
	}
	else if(x=='checkbox'){
		input_radio.setAttribute('name','checkbox');
		input_radio.setAttribute('type','checkbox');
	}
	else if(x=='radio'){
		input_radio.setAttribute('name','radio');
		input_radio.setAttribute('type','radio');
	}	
	input_radio.setAttribute('onclick','escolhas_selecionado(this,"'+x+'")');
	editar_escolhas_linha_radio.appendChild(input_radio);

	
	var editar_escolhas_linha_text=document.createElement('div');
	editar_escolhas_linha_text.setAttribute('class','editar_escolhas_linha_text');
	var input_text=document.createElement('input');
	input_text.setAttribute('name','text');
	input_text.setAttribute('type','text');
	input_text.setAttribute('class','editar_escolhas_linha_text_input');
	input_text.setAttribute('value','Indefinido');
	input_text.setAttribute('onkeyup','escolhas_selecionado(this,"'+x+'")');
	editar_escolhas_linha_text.appendChild(input_text);
	
	var editar_escolhas_linha_plus_minus=document.createElement('div');
	editar_escolhas_linha_plus_minus.setAttribute('class','editar_escolhas_linha_plus_minus');
	var img_plus=document.createElement('img');
	img_plus.setAttribute('src','/mod/formularios/icons/plus.png');
	img_plus.setAttribute('type','plus');
	img_plus.setAttribute('onclick','escolhas_selecionado(this,"'+x+'")');
	var img_minus=document.createElement('img');
	img_minus.setAttribute('src','/mod/formularios/icons/minus.png')
	img_minus.setAttribute('type','minus');
	img_minus.setAttribute('onclick','escolhas_selecionado(this,"'+x+'")');
	editar_escolhas_linha_plus_minus.appendChild(img_plus);
	editar_escolhas_linha_plus_minus.appendChild(img_minus);
	
	editar_escolhas_linha.appendChild(editar_escolhas_linha_radio);
	editar_escolhas_linha.appendChild(editar_escolhas_linha_text);
	editar_escolhas_linha.appendChild(editar_escolhas_linha_plus_minus);
	
	pai.insertBefore(editar_escolhas_linha, element.nextSibling);
	
	if(x=='jumpmenu'){
		var option=document.createElement("option");
		option.innerHTML='Indefinido';
		current_element.firstChild.lastChild.firstChild.appendChild(option);
		
		current_element.firstChild.lastChild.firstChild.insertBefore(option, current_element.firstChild.lastChild.firstChild.options[element.getAttribute('value')].nextSibling);	

		for(var i=0;i<pai.childNodes.length;i++){
			pai.childNodes[i].removeAttribute('value');
			pai.childNodes[i].setAttribute('value',i);
			current_element.firstChild.lastChild.firstChild.options[i].value=i;
		}
	}
	else if(x=='checkbox'){
		var objecto_checkbox_caixa_input=document.createElement("div");
		objecto_checkbox_caixa_input.setAttribute('class','objecto_checkbox_caixa_input');
		var input=document.createElement("input");
		input.setAttribute('name',"checkbox");
		input.setAttribute('id','checkbox');
		input.setAttribute('type','checkbox');
		input.setAttribute('disabled','disabled');
		input.setAttribute('class','objecto_checkbox_caixa_input_value');
		objecto_checkbox_caixa_input.appendChild(input);
		var objecto_checkbox_caixa_input_label=document.createElement("div");
		objecto_checkbox_caixa_input_label.setAttribute('class','objecto_checkbox_caixa_input_label');
		objecto_checkbox_caixa_input_label.innerHTML="Indefinido";
		objecto_checkbox_caixa_input.appendChild(objecto_checkbox_caixa_input_label);
		current_element.firstChild.lastChild.insertBefore(objecto_checkbox_caixa_input,current_element.firstChild.childNodes[1].childNodes[element.getAttribute('value')].nextSibling);
			
		for(var i=0;i<pai.childNodes.length;i++){
			pai.childNodes[i].removeAttribute('value');
			pai.childNodes[i].setAttribute('value',i);
			current_element.firstChild.childNodes[1].childNodes[i].setAttribute('value',i);
		}
	}
	else if(x=='radio'){
		var objecto_radio_caixa_input=document.createElement("div");
		objecto_radio_caixa_input.setAttribute('class','objecto_radio_caixa_input');
		var input=document.createElement("input");
		input.setAttribute('name','radio'+current_element.getAttribute('id'));
		input.setAttribute('type','radio');
		input.setAttribute('disabled','disabled');
		input.setAttribute('class','objecto_radio_caixa_input_value');
		objecto_radio_caixa_input.appendChild(input);
		var objecto_radio_caixa_input_label=document.createElement("div");
		objecto_radio_caixa_input_label.setAttribute('class','objecto_radio_caixa_input_label');
		objecto_radio_caixa_input_label.innerHTML="Indefinido";
		objecto_radio_caixa_input.appendChild(objecto_radio_caixa_input_label);
		current_element.firstChild.lastChild.insertBefore(objecto_radio_caixa_input,current_element.firstChild.childNodes[1].childNodes[element.getAttribute('value')].nextSibling);
			
		for(var i=0;i<pai.childNodes.length;i++){
			pai.childNodes[i].removeAttribute('value');
			pai.childNodes[i].setAttribute('value',i);
			current_element.firstChild.childNodes[1].childNodes[i].setAttribute('value',i);
		}		
	}
	info="0="+formulario+'-'+current_element.getAttribute('id')+'-'+2+'-'+element.nextSibling.getAttribute('value');
	ligar = ligacao();
	ligar.open("POST","/mod/formularios/processos/escolhas_gestao_atributo.php",true);
	ligar.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	ligar.setRequestHeader("Content-length", info.lenght);
	ligar.setRequestHeader("Connection", "close");
	ligar.send(info);
}
function minus(element,x){
	element=element.parentNode.parentNode;
	pai=element.parentNode;
	if(pai.childNodes.length>1){
		if(x=='jumpmenu'){
			if(element.childNodes[0].firstChild.checked){
				current_element.firstChild.lastChild.firstChild.removeChild(current_element.firstChild.lastChild.firstChild.options[element.getAttribute('value')]);
				pai.removeChild(element);
				for(var i=0;i<pai.childNodes.length;i++){
					pai.childNodes[i].removeAttribute('value');
					pai.childNodes[i].setAttribute('value',i);
					current_element.firstChild.lastChild.firstChild.options[i].value=i;
				}
				pai.firstChild.firstChild.firstChild.click();
			}
			else{
				current_element.firstChild.lastChild.firstChild.removeChild(current_element.firstChild.lastChild.firstChild.options[element.getAttribute('value')]);
				pai.removeChild(element);
				for(var i=0;i<pai.childNodes.length;i++){
					pai.childNodes[i].removeAttribute('value');
					pai.childNodes[i].setAttribute('value',i);
					current_element.firstChild.lastChild.firstChild.options[i].value=i;
				}
			}
		}
		else if(x=='checkbox'){
			current_element.firstChild.childNodes[1].removeChild(current_element.firstChild.childNodes[1].childNodes[element.getAttribute('value')]);
			pai.removeChild(element);
			for(var i=0;i<pai.childNodes.length;i++){
				pai.childNodes[i].removeAttribute('value');
				pai.childNodes[i].setAttribute('value',i);
				current_element.firstChild.childNodes[1].childNodes[i].setAttribute('value',i);
			}
		}
		else if(x=='radio'){
			if(element.childNodes[0].firstChild.checked){
				current_element.firstChild.childNodes[1].removeChild(current_element.firstChild.childNodes[1].childNodes[element.getAttribute('value')]);
				pai.removeChild(element);
			   	pai.firstChild.firstChild.firstChild.checked=true;
				current_element.firstChild.childNodes[1].firstChild.firstChild.checked=true;
			}
			else{
				current_element.firstChild.childNodes[1].removeChild(current_element.firstChild.childNodes[1].childNodes[element.getAttribute('value')]);
				pai.removeChild(element);	
			}
			for(var i=0;i<pai.childNodes.length;i++){
				pai.childNodes[i].removeAttribute('value');
				pai.childNodes[i].setAttribute('value',i);
				current_element.firstChild.childNodes[1].childNodes[i].setAttribute('value',i);
			}
		}
	}		
}
/////////////////FUNCÔES ESPECIAIS DE APOIO//////////////////
function html_entity_decode(str) {
  var ta = document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  toReturn = ta.value;
  ta = null;
  return toReturn
}
function removerChildNodes(parent){
	while(parent.hasChildNodes()){
		parent.removeChild(parent.childNodes[0])
	}
}
function javascript_array_to_string(vector) {
	var php = "";
	cola="";
	for(value in vector) { 
		php += cola+vector[value];
		cola="~";
	} 
	return php;
}
/////////////////FUNCÔES ESPECIAIS DE APOIO//////////////////
function carregar_escolhas(element,x,y,nome){
	if(x==1){
		//escolhas.setAttribute('style','display:inline');
		escolhas_init(y,nome);
	}
	else if(x==2){
		new Effect.DropOut(element, {duration:1});
		setTimeout("remover_escolhas()",1000);
	}
	else if(x==3){
		new Effect.DropOut(element, {duration:1});
		setTimeout("escolhas_adicionar()",1000);
		setTimeout("remover_escolhas()",1000);	
	}
}
function remover_escolhas(element){
	var contentor_construcao=document.getElementById('contentor_construcao');
	var escolhas=document.getElementById('escolhas');
	contentor_construcao.removeChild(escolhas);
}
function printer()
{
	var a = window.open('','','width=595px,height=842px');
	a.document.open("text/css");
	a.document.write(a.document.innerHTML="<link href=\"/mod/formularios/formularios.css\" rel=\"stylesheet\" type=\"text/css\">");
	a.document.write(document.getElementById('registos').innerHTML);
	a.document.close();
	a.print();
}
////////////////////////////////////////////////////////////

/*/////////////////////////////////////////////////////////////////////

//define universal reference to "staticcontent"

//define reference to the body object in IE
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

function positionit(){
	//define universal dsoc left point
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset
	//define universal dsoc top point
	var dsoctop=document.all? iebody.scrollTop : pageYOffset
	if (dsoctop == undefined)
		dsoctop=0
	{
	//if the user is using IE 4+ or Firefox/ NS6+
	if (document.all||document.getElementById){
		crossobj.style.left=parseInt(dsocleft)+5+"px"
		if(dsoctop>300){
			crossobj.style.top=dsoctop-200+"px"
		}
	}
}
setInterval("positionit()",100);*/