/*
	author: Cristiano Aicardi
	copyright: Net Source (http://www.netsource.it/)
	version: 1.0
	ref: jQuery
	ajaxCall: vd. directory
*/

/* Visualizzazione finestre modali ---------------------------------------------------------- */

	function playFLVVideo() {

		var videoFile = document.getElementById('vFile').value;
		var videoWidth = document.getElementById('vWidth').value;
		var videoHeight = document.getElementById('vHeight').value;

		var s1 = new SWFObject("libraries/flvplayer/mediaplayer.swf","mediaplayer",videoWidth,videoHeight,"8");
		s1.addParam("allowfullscreen","true");
		s1.addVariable("width",videoWidth);
		s1.addVariable("height",videoHeight);
		s1.addVariable("file","../../content/download/"+videoFile);
		s1.write("videoContainer");
	}

	function getScrollHeight() {
   		var h = window.pageYOffset ||
           		document.body.scrollTop ||
           		document.documentElement.scrollTop;
           
   		return h ? h : 0;
	}

function openActionChannel() {

	document.getElementById('actionResult').value = "";
	$("#actionChannel").empty();
	$("#actionChannel").show();
	$.get("ajaxcall/actionChannel.inc.php?action="+$("#userAction").val()+"&actionFirstID="+$("#actionFirstID").val()+"&actionSecondID="+$("#actionSecondID").val()+"&popupWidth="+$("#popupWidth").val(), function(data) {
		$("#actionChannel").html(data);

		/* Se necessario istanzia le textarea WYSIWYG */
		if (document.getElementById('userAction').value=="newArticle" || document.getElementById('userAction').value=="updateArticle") {
			tinyMCE.execCommand('mceAddControl',false,'testo_it');
			tinyMCE.execCommand('mceAddControl',false,'testo_en');
		}

		document.getElementById('actionResult').value = "OK";

		/* Se richiesto dall'utente lancia la riproduzione del file FLV */
		if (document.getElementById('userAction').value=="playFLVContent") {
			playFLVVideo();
		}
		/* ------------------------------------------------------------ */
		centerActionChannel();
		viewActionChannelShadow();

	});

}

function centerActionChannel() {

	/* Posizione orizzontale a centro pagina */

	var popWidth = document.getElementById('popupWidth').value;
	var hML = (popWidth/2);
	document.getElementById('actionChannel').style.width = popWidth+"px";
	document.getElementById('actionChannel').style.marginLeft = "-"+hML+"px";

	/* Posizione verticale a centro pagina */

	var popHeight = document.getElementById('actionChannel').offsetHeight;
	var vML = (popHeight/2);
	document.getElementById('actionChannel').style.marginTop = "-"+vML+"px";

	/* Scostamento in caso di scroll di pagina */

	var scrollH = getScrollHeight();

	if (parseInt(scrollH)!=0) {

		var newPos = scrollH - vML;
		document.getElementById('actionChannel').style.marginTop = newPos+"px";

	}

	/* Se la finestra popup inizia prima dell'inizio della pagina viene spostata a 10px dal bordo superiore della pagina */

	var topPos = document.getElementById('actionChannel').offsetTop;

	if (topPos<0) {

		newPos = 10+vML;
		document.getElementById('actionChannel').style.top = newPos+"px";

	}
}

function viewActionChannelShadow() {

	$("#actionChannelShadow").show();

	/* Dimensioni DIV */

	var shWidth = document.getElementById('actionChannel').offsetWidth;
	var shHeight = document.getElementById('actionChannel').offsetHeight;

	document.getElementById('actionChannelShadow').style.width = shWidth+"px";
	document.getElementById('actionChannelShadow').style.height = shHeight+"px";

	/* Posizione */
	var hML = (shWidth/2)-5;
	document.getElementById('actionChannelShadow').style.marginLeft = "-"+hML+"px";

	var vML = (shHeight/2)-5;
	document.getElementById('actionChannelShadow').style.marginTop = "-"+vML+"px";

	/* Scostamento in caso di scroll di pagina */

	var scrollH = getScrollHeight();

	if (parseInt(scrollH)!=0) {

		var newPos = scrollH - vML;
		document.getElementById('actionChannelShadow').style.marginTop = newPos+"px";

	}

	/* Se la finestra popup inizia prima dell'inizio della pagina viene spostata a 10px dal bordo superiore della pagina */

	var topPos = document.getElementById('actionChannelShadow').offsetTop;

	if (topPos<0) {

		newPos = 15+vML;
		document.getElementById('actionChannelShadow').style.top = newPos+"px";

	}
}

function moveActionChannelShadow() {

	/* Dimensioni DIV : cambia solo la dimensione verticale */

	var shHeight = document.getElementById('actionChannel').offsetHeight;

	document.getElementById('actionChannelShadow').style.height = shHeight+"px";

}

function closeActionChannel() {

	/* Se necessario scarica le textarea WYSIWYG */
	if (document.getElementById('userAction').value=="newArticle" || document.getElementById('userAction').value=="updateArticle") {

		tinyMCE.execCommand('mceRemoveControl',false,'testo_it');
		tinyMCE.execCommand('mceRemoveControl',false,'testo_en');
	}

	$("#actionChannel").html("");
	$("#actionChannel").empty();
	$("#actionChannel").hide();
	$("#actionChannelShadow").hide();
}


function openViewChannel() {

	document.getElementById('actionResult').value = "";
	$("#viewChannel").empty();
	$("#viewChannel").show();
	$.get("ajaxcall/viewChannel.inc.php?action="+$("#view_userAction").val()+"&actionFirstID="+$("#view_actionFirstID").val()+"&actionSecondID="+$("#view_actionSecondID").val()+"&popupWidth="+$("#view_popupWidth").val(), function(data) {
		$("#viewChannel").html(data);
		document.getElementById('actionResult').value = "OK";
		centerViewChannel();
		viewViewChannelShadow();
	});

}

function centerViewChannel() {

	/* Posizione orizzontale a centro pagina */

	var popWidth = document.getElementById('view_popupWidth').value;
	var hML = (popWidth/2);
	document.getElementById('viewChannel').style.width = popWidth+"px";
	document.getElementById('viewChannel').style.marginLeft = "-"+hML+"px";

	/* Posizione verticale a centro pagina */

	var popHeight = document.getElementById('viewChannel').offsetHeight;
	var vML = (popHeight/2);
	document.getElementById('viewChannel').style.marginTop = "-"+vML+"px";

	/* Scostamento in caso di scroll di pagina */

	var scrollH = getScrollHeight();

	if (parseInt(scrollH)!=0) {

		var newPos = scrollH - vML;
		document.getElementById('viewChannel').style.marginTop = newPos+"px";

	}

	/* Se la finestra popup inizia prima dell'inizio della pagina viene spostata a 10px dal bordo superiore della pagina */

	var topPos = document.getElementById('viewChannel').offsetTop;

	if (topPos<0) {

		newPos = 10+vML;
		document.getElementById('viewChannel').style.top = newPos+"px";

	}
}

function viewViewChannelShadow() {

	$("#viewChannelShadow").show();

	/* Dimensioni DIV */

	var shWidth = document.getElementById('viewChannel').offsetWidth;
	var shHeight = document.getElementById('viewChannel').offsetHeight;

	document.getElementById('viewChannelShadow').style.width = shWidth+"px";
	document.getElementById('viewChannelShadow').style.height = shHeight+"px";

	/* Posizione */
	var hML = (shWidth/2)-5;
	document.getElementById('viewChannelShadow').style.marginLeft = "-"+hML+"px";

	var vML = (shHeight/2)-5;
	document.getElementById('viewChannelShadow').style.marginTop = "-"+vML+"px";

	/* Scostamento in caso di scroll di pagina */

	var scrollH = getScrollHeight();

	if (parseInt(scrollH)!=0) {

		var newPos = scrollH - vML;
		document.getElementById('viewChannelShadow').style.marginTop = newPos+"px";

	}

	/* Se la finestra popup inizia prima dell'inizio della pagina viene spostata a 10px dal bordo superiore della pagina */

	var topPos = document.getElementById('viewChannelShadow').offsetTop;

	if (topPos<0) {

		newPos = 15+vML;
		document.getElementById('viewChannelShadow').style.top = newPos+"px";

	}
}

function closeViewChannel() {
	$("#viewChannel").html("");
	$("#viewChannel").empty();
	$("#viewChannel").hide();
	$("#viewChannelShadow").hide();
}

/* ------------------------------------------------------------------------------------------ */

/* Funzioni all'aggiornamento di pagina ----------------------------------------------------- */

$(document).ready(function(){
	$("#pageLoader").hide();
});

$(window).load(function() {
	$("#pageLoader").hide();
});

/* ------------------------------------------------------------------------------------------ */

/* Funzioni di invio FORM ------------------------------------------------------------------- */

	/* FORM LOGIN */

	function sendLoginForm() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/loginUser.action.php",{ 
       			email: $("#email").val(), 
      			password: $("#password").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		}); 

	}

	/* FORM NUOVO UTENTE */

	function confirmRegForm() {

		document.getElementById('procedureResult').value = "";

		if (document.getElementById('check_privacy').checked) { var isCheckPrivacy = "x"; } else { var isCheckPrivacy = ""; }
		if (document.getElementById('check_newsletter').checked) { var isCheckNewsletter = "x"; } else { var isCheckNewsletter = ""; }

		$.post("actions/regUser.action.php",{ 
       			nome: $("#nome").val(),
       			cognome: $("#cognome").val(),
       			indirizzo: $("#indirizzo").val(),
       			citta: $("#citta").val(),
       			cap: $("#cap").val(),
       			provincia: $("#provincia").val(),
       			telefono: $("#telefono").val(),
       			fax: $("#fax").val(),
       			email: $("#email").val(),
       			conf_email: $("#conf_email").val(),
       			password: $("#password").val(),
       			conf_password: $("#conf_password").val(),
       			check_privacy: isCheckPrivacy,
       			check_newsletter: isCheckNewsletter
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		}); 

	}

	/* FORM MODIFICA ACCOUNT */

	function updateUserAccount() {

		document.getElementById('procedureResult').value = "";

		if (document.getElementById('check_newsletter').checked) { var isCheckNewsletter = "x"; } else { var isCheckNewsletter = ""; }

		$.post("actions/updateUser.action.php",{ 
       			nome: $("#nome").val(),
       			cognome: $("#cognome").val(),
       			indirizzo: $("#indirizzo").val(),
       			citta: $("#citta").val(),
       			cap: $("#cap").val(),
       			provincia: $("#provincia").val(),
       			telefono: $("#telefono").val(),
       			fax: $("#fax").val(),
       			email: $("#email").val(),
       			conf_email: $("#conf_email").val(),
       			check_newsletter: isCheckNewsletter
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		}); 

	}

	/* FORM CAMBIO PASSWORD */

	function changePassword() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/changePassword.action.php",{ 
       			old_password: $("#old_password").val(),
       			password: $("#password").val(),
       			conf_password: $("#conf_password").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				
				/* document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()"; */
			}
			moveActionChannelShadow();
 		}); 

	}

	/* FORM RECUPERO PASSWORD */

	function getPassword() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/getPassword.action.php",{ 
       			email: $("#email").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				
				/* document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()"; */
			}
			moveActionChannelShadow();
 		}); 

	}

	/* FORM NUOVO ARTICOLO */

	function sendNewArticle() {

		document.getElementById('procedureResult').value = "";

		if (document.getElementById('flag_pubblica').checked) { var isCheckPubblica = "x"; } else { var isCheckPubblica = ""; }
		if (document.getElementById('flag_commenti').checked) { var isCheckCommenti = "x"; } else { var isCheckCommenti = ""; }

		tinyMCE.triggerSave(); /* inserisce il contenuto dell'editor nel campo */

		$.post("actions/newArticle.action.php",{ 
       			id_cat: $("#id_cat").val(),
       			id_subcat: $("#id_subcat").val(),
       			titolo_it: $("#titolo_it").val(),
       			titolo_en: $("#titolo_en").val(),
       			testo_it: $("#testo_it").val(),
       			testo_en: $("#testo_en").val(),
       			flag_pubblica: isCheckPubblica,
       			flag_commenti: isCheckCommenti
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM MODIFICA ARTICOLO */

	function updateArticle() {

		document.getElementById('procedureResult').value = "";

		if (document.getElementById('flag_pubblica').checked) { var isCheckPubblica = "x"; } else { var isCheckPubblica = ""; }
		if (document.getElementById('flag_commenti').checked) { var isCheckCommenti = "x"; } else { var isCheckCommenti = ""; }

		tinyMCE.triggerSave(); /* inserisce il contenuto dell'editor nel campo */

		$.post("actions/updateArticle.action.php",{ 
       			id_article: $("#id_article").val(),
       			id_cat: $("#id_cat").val(),
       			id_subcat: $("#id_subcat").val(),
       			titolo_it: $("#titolo_it").val(),
       			titolo_en: $("#titolo_en").val(),
       			testo_it: $("#testo_it").val(),
       			testo_en: $("#testo_en").val(),
       			flag_pubblica: isCheckPubblica,
       			flag_commenti: isCheckCommenti
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM ELIMINAZIONE ARTICOLO */

	function deleteArticle() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/deleteArticle.action.php",{ 
       			id_article: $("#id_article").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM AGGIUNTA FILE */

	function addFile() {

		document.getElementById('procedureResult').value = "";

		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'actions/addFile.action.php',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{

							$.post("actions/updateFile.action.php",{ 
       								id_article: $("#id_article").val(),
								id_file: data.ID_file
     							}, function(res) { 
								if (res=="NO") { alert("Attenzione: inserimento nel DB non riuscito."); } 
 							});

							var str=data.htmlContent;
							str = str.replace(/&lt;/gi,"<");
							str = str.replace(/&gt;/gi,">");

							$("#actionWindowContainer").html(str);

							if (str.indexOf("<input type='hidden' name='procedureResult' id='procedureResult' value='OK' />")!=-1) {
								document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
							}
							moveActionChannelShadow();

						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}

	/* FORM AGGIUNTA IMMAGINE */

	function addImage() {

		document.getElementById('procedureResult').value = "";

		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'actions/addImage.action.php',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							alert(data.error);
						}else
						{

							$.post("actions/updateImage.action.php",{ 
       								id_article: $("#id_article").val(),
       								txt_descrizione_it: $("#descrizione_it").val(),
       								txt_descrizione_en: $("#descrizione_en").val(),
								id_image: data.ID_image
     							}, function(res) { 
								if (res=="NO") { alert("Attenzione: inserimento nel DB non riuscito."); } 
 							});

							var str=data.htmlContent;
							str = str.replace(/&lt;/gi,"<");
							str = str.replace(/&gt;/gi,">");

							$("#actionWindowContainer").html(str);

							if (str.indexOf("<input type='hidden' name='procedureResult' id='procedureResult' value='OK' />")!=-1) {
								document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
							}
							moveActionChannelShadow();

						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		)
		
		return false;

	}

	/* FORM NUOVA CATEGORIA */

	function newCategory() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/newCategory.action.php",{ 
       			nome_it: $("#nome_it").val(),
       			nome_en: $("#nome_en").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM MODIFICA CATEGORIA */

	function updateCategory() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/updateCategory.action.php",{ 
       			id_cat: $("#id_cat").val(),
       			nome_it: $("#nome_it").val(),
       			nome_en: $("#nome_en").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM ELIMINAZIONE CATEGORIA */

	function deleteCategory() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/deleteCategory.action.php",{ 
       			id_cat: $("#id_cat").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM ELIMINAZIONE IMMAGINE */

	function deleteImage() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/deleteImage.action.php",{ 
       			id_img: $("#id_img").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM ELIMINAZIONE ALLEGATO */

	function deleteFile() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/deleteFile.action.php",{ 
       			id_file: $("#id_file").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM INSERIMENTO COMMENTO */

	function addComment() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/addComment.action.php",{ 
       			id_article: $("#id_article").val(),
       			testo: $("#testo").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM MODIFICA COMMENTO */

	function updateComment() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/updateComment.action.php",{ 
       			id_comment: $("#id_comment").val(),
       			testo: $("#testo").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM ELIMINAZIONE COMMENTO */

	function deleteComment() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/deleteComment.action.php",{ 
       			id_comment: $("#id_comment").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM NUOVA SOTTOCATEGORIA */

	function newSubcategory() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/newSubcategory.action.php",{ 
       			id_cat: $("#id_cat").val(),
       			nome_it: $("#nome_it").val(),
       			nome_en: $("#nome_en").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM MODIFICA SOTTOCATEGORIA */

	function updateSubcategory() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/updateSubcategory.action.php",{ 
       			id_subcat: $("#id_subcat").val(),
       			id_cat: $("#id_cat").val(),
       			nome_it: $("#nome_it").val(),
       			nome_en: $("#nome_en").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* FORM ELIMINAZIONE SOTTOCATEGORIA */

	function deleteSubcategory() {

		document.getElementById('procedureResult').value = "";

		$.post("actions/deleteSubcategory.action.php",{ 
       			id_subcat: $("#id_subcat").val()
     		}, function(data) { 
			$("#actionWindowContainer").html(data); 

			var str=data;
			if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
				document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
			}
			moveActionChannelShadow();
 		});

	}

	/* ORDINAMENTO CATEGORIE */

	function orderCategories() {

		document.getElementById('sendButton').disabled = true;

		document.getElementById('procedureResult').value = "";
		document.getElementById('dString').value = "";

		var formContent = document.getElementById('formContainer');
		var dataString = "";
		if (formContent) {

			var ck = formContent.getElementsByTagName("SELECT");

			for(var i = 0; i < ck.length; i++) {

				ckPartialName = ck[i].name.replace("pm[","");
				ckID = ckPartialName.replace("]","");

				dataString = dataString+"@"+ckID+"="+ck[i].value;
				
			}

			document.getElementById('dString').value = dataString;

			$.post("actions/orderCategories.action.php",{ 
       				posList: $("#dString").val()
     			}, function(data) { 
				$("#actionWindowContainer").html(data); 

				var str=data;
				if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
					document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
				}
				moveActionChannelShadow();
 			});
		}
	}

	/* ORDINAMENTO SOTTOCATEGORIE */

	function orderSubcategories() {

		document.getElementById('sendButton').disabled = true;

		document.getElementById('procedureResult').value = "";
		document.getElementById('dString').value = "";

		var formContent = document.getElementById('formContainer');
		var dataString = "";
		if (formContent) {

			var ck = formContent.getElementsByTagName("SELECT");

			for(var i = 0; i < ck.length; i++) {

				ckPartialName = ck[i].name.replace("pm[","");
				ckID = ckPartialName.replace("]","");

				dataString = dataString+"@"+ckID+"="+ck[i].value;
				
			}

			document.getElementById('dString').value = dataString;

			$.post("actions/orderSubcategories.action.php",{ 
       				posList: $("#dString").val()
     			}, function(data) { 
				$("#actionWindowContainer").html(data); 

				var str=data;
				if (str.indexOf("<input type=\"hidden\" name=\"procedureResult\" id=\"procedureResult\" value=\"OK\" />")!=-1) {
					document.getElementById('actionPopupCloseLink').href = "javascript:self.location.reload()";
				}
				moveActionChannelShadow();
 			});
		}
	}

/* ------------------------------------------------------------------------------------------ */

