jQuery(document).ready(function() {
	var xmlDocument;
 	jQuery.ajax({
		type: "POST",
		url: "/html/portlet/journal/recupero_dati_preview.jsp",
		dataType: "xml",
		cache: "false",
		data: xmlDocument,
		success: function(xmlDocument){	
      var markers = xmlDocument.getElementsByTagName('marker');
			var boolean_preview = markers[0].getAttribute("boolean_preview");
			var contenuto = markers[0].getAttribute("contenuto");
			var istanza = markers[0].getAttribute("istanza");
			if(boolean_preview=="SI"){
			if (Liferay._editControlsState == 'visible'){
		 		jQuery('.toggle-controls').click();
		 	}
			//TOGLIE IL TASTO WELCOME
			
			 var collection_h2 = document.getElementsByTagName("h2");
			 
			 for(j=0;j<collection_h2.length;j++){
		        	var out = collection_h2[j].getAttribute("class");
		        	
		        	if(out=="user-greeting"){
		        		
			        	collection_h2[j].id="id_administrator";
			          jQuery("h2#id_administrator").hide();
		          }
		    }
			//AGGANCIA IL CONTENUTO
				var id_portlet= document.getElementById("p_p_id_" + istanza + "_");
				if(id_portlet!=null){
				/*		var collection = id_portlet.getElementsByTagName("div");
						for(i=0;i<collection.length;i++){
		        	var output = collection[i].getAttribute("class");
		        	if(output=="portlet-borderless-container"){
			        	collection[i].id="id_preview";
							  jQuery('div#id_preview').html(contenuto);
							}
		   			}*/
		   			jQuery("#p_p_id_" + istanza + "_ > .portlet-borderless-container").html(contenuto);
		   			jQuery("#p_p_id_" + istanza + "_").removeClass();
		   	}else if(istanza!=''){
		   		jQuery('div#' + istanza).html(contenuto);
		   	}					
		   	
		    /*var lockerHtml='<div id="locker" style="position: absolute; height:'+jQuery('#wrapper').height()+'; width:'+jQuery('#wrapper').height()+'; top: 0px; left: 0px;"/></div>'
		   	jQuery('#wrapper').append(lockerHtml);
  */}

	  }
  });
  });