function crea_editor_codice(id_textarea) {
	alert('richiesta editor!');

	try {
		editAreaLoader.delete_instance(id_textarea);
	} catch (ex) {
		//
	}

	editAreaLoader.init({
		id : id_textarea
	});

	editAreaLoader.show(id_textarea);

}

function codepress_run() {
	CodePress.run();
}

function codepress_toggleEditor() {
	alert('toggle');
	CodePress.toggleEditor();
}

function post_ajax(form, div, url, ico_url) {
	var params = $(form).serialize(true);
	new Ajax.Request(url, {
		method : 'post',
		evalJS : true,
		parameters : params,
		onSuccess : function(transport) {
			document.getElementById(div).innerHTML = transport.responseText;
			transport.responseText.evalScripts();
		},
		onCreate : function() {
			if (ico_url != "") {
				document.getElementById(div).innerHTML = '<img src=\''
						+ ico_url + '\'></img>';
			}
		}
	});

	if ($(form) != null) {
		try {
			$(form).reset();
		} catch (ex) {
			//
		}
	}

}

// funzione usata per fare il postback automatico di una select
function select_postback(id_select, url, output_div) {
	var dropdownIndex = document.getElementById(id_select).selectedIndex;
	var dropdownValue = document.getElementById(id_select)[dropdownIndex].value;
	makeRequest(output_div, true, url + dropdownValue);
	// window.location =url+dropdownValue;
}

// ritorna il valore selezionato in una select
function get_selected_value(id_select, url, output_div) {
	var dropdownIndex = document.getElementById(id_select).selectedIndex;
	var dropdownValue = document.getElementById(id_select)[dropdownIndex].value;
	return dropdownValue;
}

// funzione usata per accedere ai cookies
function webbins_leggicookie(CookieNome) {
	if (CookieNome.length == 0)
		return null;
	var PosizioneIniziale = document.cookie.indexOf(CookieNome + "=");
	if (PosizioneIniziale == -1)
		return null;
	PosizioneIniziale += CookieNome.length + 1; // restituisce la posizione del
												// primo carattere del valore
												// della variabile-cookie
	var PosizioneFinale = document.cookie.indexOf(";", PosizioneIniziale);
	if (PosizioneFinale == -1)
		PosizioneFinale = document.cookie.length; // serve perch� se il cookie
													// � l'ultimo non avr� ";"
	return unescape(document.cookie.substring(PosizioneIniziale,
			PosizioneFinale));
}

// funzione usata per l'update dei file
var chiamata_barra = 0;
function webbins_sleep(id_div, upload_id) {
	var sleep_time;
	sleep_time = 5000;
	if (chiamata_barra == 0) {
		// document.getElementById(id_div).innerHTML = '<p><div
		// class="preload_box"><div class="preload_bar" style="width:
		// 1%;">1</div></div></p>';
		sleep_time = 10;
	}
	// document.write('<div id="cache" style="width: 100%; height: 100%;
	// background-color: #006699; margin: 0px; padding: 0px; position:
	// absolute;"><img
	// src="http://'+document.location.hostname+'/files/getbyname/wait.gif"
	// style="margin: 10px; padding: 0px;" border="0"></div>');
	// non faccio niente
	url = 'http://' + document.location.hostname + '/files/upload_progress/'
			+ upload_id;
	// alert(upload_id);
	makeRequest(id_div, false, url);
	setTimeout(function() {
		webbins_sleep(id_div, upload_id, false);
	}, sleep_time);
	chiamata_barra = chiamata_barra + 1;
}

// funzione usata per l'update dei file
function render_progressbar(upload_id) {
	try {
		id_div = 'upload_progress_' + upload_id;
		webbins_sleep(id_div, upload_id);
	} catch (ex) {
		//
	}
}

// funzione usata per generare un'effetto trasparenza durante i submit
function cacheOff() {
	ver = navigator.appVersion.substring(0, 1);
	if (ver >= 4) {
		cache.visibility = NASCOSTO;
	}
}

function crea_trasparenza() {

	ver = navigator.appVersion.substring(0, 1);
	if (ver >= 4) {
		document
				.write('<div id="cache" style="color: white; font-size: 80px; clear: none; width: 100%; height: 100%; background-color: #006699; margin: 0px; padding: 0px; position: absolute; z-index: 1000; top: 0px; left: 0px; visibility: hidden; -moz-opacity: 0.8; filter: alpha(opacity=80); opacity: 0.8"><div class=\"wait\"><img src="http://'
						+ document.location.hostname
						+ '/files/getbyname/wait.gif" style="margin: 10px; padding: 0px;" border="0"></div></div>');
		var navi = (navigator.appName == "Firefox_No" && parseInt(navigator.appVersion) >= 4);
		var NASCOSTO = (navi) ? 'hide' : 'hidden';
		var VISIBILE = (navi) ? 'show' : 'visible';
		if (document.getElementById) {
			var cache = (navi) ? document.cache : document
					.getElementById('cache').style;
		} else if (document.all) {
			var cache = (navi) ? document.cache : document.all['cache'].style;
		} else if (document.layers) {
			var cache = (navi) ? document.cache
					: document.layers['cache'].style;
		}

		// cache.left = Math.round(100);
		cache.visibility = VISIBILE;
	}
}

// funzione usata per il submit dei form contenenti tinymce

function submit_WYSIWYG(content_form, elemento_locale) {

	id_elemento = content_form[elemento_locale].id;
	try {
		valore = tinyMCE.get(id_elemento).getContent();
		return true;
	} catch (err) {
		alert("Non puoi ancora salvare la pagina, devi aspettare che si carichi il contenuto");
		return false;
	}
}

// funzione usata per il submit dei form contenenti tinymce

function submit_WYSIWYG_array(content_form, array_elementi) {
	var val = true;
	for (z = 0; z < array_elementi.length; z++) {
		id_elemento = content_form[array_elementi[z]].id;

		try {
			valore = tinyMCE.get(id_elemento).getContent();
			val = true;
		} catch (err) {
			alert("Non puoi ancora salvare la pagina, devi aspettare che si carichi il contenuto");
			return false;
		}
	}
	return val

}

// seleziona tutti i checkbox di un form
function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for (z = 0; z < theForm.length; z++) {
		if (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
			theForm[z].checked = theElement.checked;
		}
	}
}

// seleziona alcuni checkbox di un form

function checkUncheckSome(controller, theElements) {

	// Programmed by Shawn Olson
	// Copyright (c) 2006
	// Permission to use this function provided that it always includes this
	// credit text
	// http://www.shawnolson.net
	// Find more JavaScripts at http://www.shawnolson.net/topics/Javascript/

	// theElements is an array of objects designated as a comma separated list
	// of their IDs
	// If an element in theElements is not a checkbox, then it is assumed
	// that the function is recursive for that object and will check/uncheck
	// all checkboxes contained in that element

	var formElements = theElements.split(',');
	var theController = document.getElementById(controller);
	for ( var z = 0; z < formElements.length; z++) {
		theItem = document.getElementById(formElements[z]);
		if (theItem) {
			if (theItem.type) {
				if (theItem.type == 'checkbox'
						&& theItem.id != theController.id) {
					theItem.checked = theController.checked;
				}
			} else {

				var nextArray = '';
				for ( var x = 0; x < theItem.childNodes.length; x++) {
					if (theItem.childNodes[x]) {
						if (theItem.childNodes[x].id) {
							nextArray += theItem.childNodes[x].id + ',';
						}
					}
				}
				checkUncheckSome(controller, nextArray);

			}

		}
	}
}

function get_bandiera(lingua) {
	switch (lingua) {
	case "IT":
		return '<img src="http://www.webbins.it/files/getbyname/IT.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "DE":
		return '<img src="http://www.webbins.it/files/getbyname/DE.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "EN":
		return '<img src="http://www.webbins.it/files/getbyname/EN.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "FR":
		return '<img src="http://www.webbins.it/files/getbyname/FR.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "NL":
		return '<img src="http://www.webbins.it/files/getbyname/NL.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "RU":
		return '<img src="http://www.webbins.it/files/getbyname/RU.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "PL":
		return '<img src="http://www.webbins.it/files/getbyname/PL.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "ES":
		return '<img src="http://www.webbins.it/files/getbyname/ES.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "CZ":
		return '<img src="http://www.webbins.it/files/getbyname/CZ.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "AR":
		return '<img src="http://www.webbins.it/files/getbyname/AR.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "CN":
		return '<img src="http://www.webbins.it/files/getbyname/CN.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "RU":
		return '<img src="http://www.webbins.it/files/getbyname/RU.gif" border="0" alt="immagine_bandiera" />';
		break;
	case "TR":
		return '<img src="http://www.webbins.it/files/getbyname/TR.gif" border="0" alt="immagine_bandiera" />';
		break;

	}
}

// utilizzata per il cambio della lingua
function cambialingua_old(form_id, lingua, campi) {
	lingua_corrente = form_id.current_multilingua.value;

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

		// salvo il contenuto attuale nel campo hidden

		nome_campo = "multilingua_" + lingua_corrente + "_" + campi[i];
		form_id[nome_campo].value = form_id[campi[i]].value;

		tipo_campo = form_id[campi[i]].tagName;

		form_id[campi[i]].className = "input";

		if (tipo_campo == "INPUT") {
			form_id[campi[i]].className = "input_text_" + lingua;
		} else if (tipo_campo == "TEXTAREA") {
			form_id[campi[i]].className = "input_textarea_" + lingua;

		}

		// sostituisco il valore del campo con la variabile hiddend della lingua
		// scelta

		nome_campo_lingua = "multilingua_" + lingua + "_" + campi[i];
		form_id[campi[i]].value = form_id[nome_campo_lingua].value;
	}

	// salvo la nuova lingua scelta

	form_id.current_multilingua.value = lingua;

	/*
	 * non stampo nulla, viene cambiata la classe testo_lingua_attuale = 'La
	 * lingua attualmente impostata e\': '+lingua +' '+ get_bandiera(lingua);
	 * 
	 * document.getElementById('lingua_attuale').innerHTML=testo_lingua_attuale;
	 */

	document.getElementById(form_id.id + '_' + 'scegli_lingua_'
			+ lingua_corrente).className = "";
	document.getElementById(form_id.id + '_' + 'scegli_lingua_' + lingua).className = "link_attivo";

}

function cambialingua(form_id, lingua, arr_elementi, arr_tiny) {
	// leggo la lingua corrente
	var lingua_corrente = form_id.current_multilingua.value;

	if (arr_elementi != null) // controllo gli elementi multilingua
	{
		for ( var i = 0; i < arr_elementi.length; i++) {
			var elemento_locale = arr_elementi[i];
			var valore = form_id[elemento_locale].value;
			var nome_campo = "multilingua_" + lingua_corrente + "_"
					+ elemento_locale;

			var tipo_campo = form_id[arr_elementi[i]].tagName;
			var cur_class="";
			
			
			//alert(form_id[arr_elementi[i]].className);
			if (tipo_campo == "INPUT") 
			{
				if(form_id[arr_elementi[i]].className!="")
				{
					var array_classes=form_id[arr_elementi[i]].className.split(" ");
					
					for(k = 0; k < array_classes.length;k++)
					{
						//se non è la classe di tipo "input_text_" la concateno a cur_class
						if(array_classes[k].indexOf("input_text_")==-1)
						{
							cur_class+=" "+array_classes[k]; 
						}
					}
				}
				
				form_id[arr_elementi[i]].className = "input_text_" + lingua+cur_class;
			}
			else if (tipo_campo == "TEXTAREA") {
				// form_id[arr_elementi[i]].className = "input_textarea_" +
				// lingua;
			}

			form_id[nome_campo].value = valore;
			var nome_campo_lingua = "multilingua_" + lingua + "_"
					+ elemento_locale;
			form_id[elemento_locale].value = form_id[nome_campo_lingua].value; // ->
																				// insert
																				// the
																				// reply
		}
	}

	if (arr_tiny != null) // controllo gli elementi multilingua di tipo
							// tinyMCE
	{
		for ( var k = 0; k < arr_tiny.length; k++) {
			var elemento_locale_tiny = arr_tiny[k];
			// var id_elemento_tiny =form_id[elemento_locale_tiny].id;
			var id_elemento_tiny = "fckfield_" + elemento_locale_tiny;
			if (id_elemento_tiny == null) {
				return;
			}
			var valore_tiny = tinyMCE.get(id_elemento_tiny).getContent();
			var nome_campo_tiny = "multilingua_" + lingua_corrente + "_"
					+ elemento_locale_tiny;
			form_id[nome_campo_tiny].value = valore_tiny;
			var nome_campo_lingua_tiny = "multilingua_" + lingua + "_"
					+ elemento_locale_tiny;
			// imposto il valore nella nuova lingua
			tinyMCE.get(id_elemento_tiny).setContent(
					form_id[nome_campo_lingua_tiny].value); // -> insert the
															// reply
		}
	}

	document.getElementById(form_id.id + '_' + 'scegli_lingua_'
			+ lingua_corrente).className = "";
	document.getElementById(form_id.id + '_' + 'scegli_lingua_' + lingua).className = "link_attivo";
	form_id.current_multilingua.value = lingua;
}

function captcha_update(id_elemento, to) {
	document.getElementById(id_elemento).src = to + "/" + Math.random();
}

function mydipendenti_formatta_ore(minuti) {
	if (minuti == 0) {
		return "0:0";
	} else {
		ore = parseInt(minuti / 60);
		minuti_rimanenti = minuti - ore * 60;

		ore = Math.abs(ore);
		minuti_rimanenti = Math.abs(minuti_rimanenti);
		return ore + ":" + minuti_rimanenti;
	}

}

function mydipendenti_timbrature_add_cdc_fast(obj) {

	var campi_input = document.getElementsByTagName("input");

	var totale = 0;

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

		var elemento_corrente = campi_input[i];
		if (elemento_corrente.name.indexOf("cdc_fast_") != -1
				&& elemento_corrente.name.indexOf("cdc_fast_note") == -1) {

			if (elemento_corrente.value.length > 0) {

				if (elemento_corrente.value.indexOf(":") != -1) {
					var input = elemento_corrente.value.split(":");
					totale+=(parseInt(input[0])*60+parseInt(input[1]));
				} else {
					alert("Attenzione! formato obbligatorio H:MM");
					elemento_corrente.value=0;
				}
			}

		}

	}
	
	var ore =0;
	var minuti =0;
	
	if(totale>0){
		ore = Math.floor(totale/60);
		minuti = totale-ore*60;
	}
	
	document.getElementById('ore_totali_effettuate').innerHTML=ore+":"+minuti;

	document.getElementById('form_timbratura').onsubmit=function(){
		
		return confirm("Confermi la timbratura per un totale di "+ore+":"+minuti+" ?");
		
	}

}

function mydipendenti_timbrature_select_commessa(obj){
	
	var id = obj.id;
	var info = obj.info;
	var id_elemento_generato = "token_" + Math.random() + Math.random();
	id_elemento_generato = id_elemento_generato.replace(",", "_");
	id_elemento_generato = id_elemento_generato.replace(".", "_");

	var input_id_commessa = document.createElement("input");
	input_id_commessa.setAttribute("name", "id_filtro_commessa");
	input_id_commessa.setAttribute("type", "hidden");
	input_id_commessa.setAttribute("value", obj.id);

	var desc_commessa = document.createElement("div");
	desc_commessa.setAttribute("class", "commessa");
	desc_commessa.appendChild(document.createTextNode(info));

	var button_elimina = document.createElement("input");
	button_elimina.setAttribute("onclick",
			"document.getElementById('div_contenitore_" + id_elemento_generato
					+ "').innerHTML='';");
	button_elimina.setAttribute("type", "button");
	button_elimina.setAttribute("value", "Elimina");

	var nuovo_div = document.createElement("div");
	nuovo_div.setAttribute("id", "div_contenitore_" + id_elemento_generato);

	nuovo_div.appendChild(input_id_commessa);
	nuovo_div.appendChild(desc_commessa);
	nuovo_div.appendChild(button_elimina);

	
	document.getElementById('seleziona_timbratura_commesse').insertBefore(nuovo_div,document.getElementById('seleziona_timbratura_commesse').firstChild);
			
}

function mydipendenti_timbrature_select_cliente(obj){
	var id = obj.id;
	var info = obj.info;
	var id_elemento_generato = "token_" + Math.random() + Math.random();
	id_elemento_generato = id_elemento_generato.replace(",", "_");
	id_elemento_generato = id_elemento_generato.replace(".", "_");

	var input_id_commessa = document.createElement("input");
	input_id_commessa.setAttribute("name", "id_filtro_cliente");
	input_id_commessa.setAttribute("type", "hidden");
	input_id_commessa.setAttribute("value", obj.id);

	var desc_commessa = document.createElement("div");
	desc_commessa.setAttribute("class", "commessa");
	desc_commessa.appendChild(document.createTextNode(info));

	var button_elimina = document.createElement("input");
	button_elimina.setAttribute("onclick",
			"document.getElementById('div_contenitore_" + id_elemento_generato
					+ "').innerHTML='';");
	button_elimina.setAttribute("type", "button");
	button_elimina.setAttribute("value", "Elimina");

	var nuovo_div = document.createElement("div");
	nuovo_div.setAttribute("id", "div_contenitore_" + id_elemento_generato);

	nuovo_div.appendChild(input_id_commessa);
	nuovo_div.appendChild(desc_commessa);
	nuovo_div.appendChild(button_elimina);

	
	document.getElementById('seleziona_timbratura_clienti').insertBefore(nuovo_div,document.getElementById('seleziona_timbratura_clienti').firstChild);
}


function mydipendenti_timbrature_add_commessa(obj) {

	var id = obj.id;
	var info = obj.info;
	var id_elemento_generato = "token_" + Math.random() + Math.random();
	id_elemento_generato = id_elemento_generato.replace(",", "_");
	id_elemento_generato = id_elemento_generato.replace(".", "_");

	var input_minuti = document.createElement("input");
	input_minuti
			.setAttribute("name", "commessa_minuti_" + id_elemento_generato);
	input_minuti.setAttribute("class",
			"required my_validate-mydipendenti_timbrature");
	input_minuti.setAttribute("type", "text");
	input_minuti.setAttribute("size", "4");

	var input_note = document.createElement("input");
	input_note.setAttribute("name", "commessa_note_" + id_elemento_generato);
	input_note.setAttribute("type", "text");

	var input_id_commessa = document.createElement("input");
	input_id_commessa.setAttribute("name", "commessa_id_"
			+ id_elemento_generato);
	input_id_commessa.setAttribute("type", "hidden");
	input_id_commessa.setAttribute("value", obj.id);

	var desc_commessa = document.createElement("div");
	desc_commessa.setAttribute("class", "commessa");
	desc_commessa.appendChild(document.createTextNode(info));

	var button_elimina = document.createElement("input");
	button_elimina.setAttribute("onclick",
			"document.getElementById('div_contenitore_" + id_elemento_generato
					+ "').innerHTML='';");
	button_elimina.setAttribute("type", "button");
	button_elimina.setAttribute("value", "Elimina");

	var nuovo_div = document.createElement("div");
	nuovo_div.setAttribute("id", "div_contenitore_" + id_elemento_generato);

	nuovo_div.appendChild(input_minuti);
	nuovo_div.appendChild(document.createTextNode("HH:MM"));
	nuovo_div.appendChild(input_note);
	nuovo_div.appendChild(document.createTextNode("Note"));
	nuovo_div.appendChild(input_id_commessa);
	nuovo_div.appendChild(desc_commessa);
	nuovo_div.appendChild(button_elimina);

	document.getElementById('chiudi_timbratura_commesse').insertBefore(
			nuovo_div,
			document.getElementById('chiudi_timbratura_commesse').firstChild);
	// document.getElementById('chiudi_timbratura_commesse').appendChild(nuovastringa);

}

function mydipendenti_timbrature_add_cliente(obj) {

	var id = obj.id;
	var info = obj.info;
	var id_elemento_generato = "token_" + Math.random() + Math.random();
	id_elemento_generato = id_elemento_generato.replace(",", "_");
	id_elemento_generato = id_elemento_generato.replace(".", "_");

	var select_cdc = document.getElementById('mydipendenti_timbrature_cdc')
			.cloneNode(true);
	select_cdc.setAttribute("id", "cliente_cdc_" + id_elemento_generato);
	select_cdc.setAttribute("name", "cliente_cdc_" + id_elemento_generato);

	var input_minuti = document.createElement("input");
	input_minuti.setAttribute("name", "cliente_minuti_" + id_elemento_generato);
	input_minuti.setAttribute("class",
			"required my_validate-mydipendenti_timbrature");
	input_minuti.setAttribute("type", "text");
	input_minuti.setAttribute("size", "4");

	var input_note = document.createElement("input");
	input_note.setAttribute("name", "cliente_note_" + id_elemento_generato);
	input_note.setAttribute("type", "text");

	var input_id_cliente = document.createElement("input");
	input_id_cliente.setAttribute("name", "cliente_id_" + id_elemento_generato);
	input_id_cliente.setAttribute("type", "hidden");
	input_id_cliente.setAttribute("value", obj.id);

	var desc_cliente = document.createElement("div");
	desc_cliente.setAttribute("class", "cliente");
	desc_cliente.appendChild(document.createTextNode(info));

	var button_elimina = document.createElement("input");
	button_elimina.setAttribute("onclick",
			"document.getElementById('div_contenitore_" + id_elemento_generato
					+ "').innerHTML='';");
	button_elimina.setAttribute("type", "button");
	button_elimina.setAttribute("value", "Elimina");

	var nuovo_div = document.createElement("div");
	nuovo_div.setAttribute("id", "div_contenitore_" + id_elemento_generato);

	nuovo_div.appendChild(select_cdc);
	nuovo_div.appendChild(input_minuti);
	nuovo_div.appendChild(document.createTextNode("HH:MM"));
	nuovo_div.appendChild(input_note);
	nuovo_div.appendChild(document.createTextNode("Note"));
	nuovo_div.appendChild(input_id_cliente);
	nuovo_div.appendChild(desc_cliente);
	nuovo_div.appendChild(button_elimina);

	document.getElementById('chiudi_timbratura_clienti').insertBefore(
			nuovo_div,
			document.getElementById('chiudi_timbratura_clienti').firstChild);

}

// aggiunge una parola key al textfield specificato separandola con |
function addTagKey(textfield, key_val, id) {
	var txt = document.getElementById(textfield);
	if (txt != null) {
		if (txt.value != null) {
			txt.value = txt.value + '|' + key_val;
		} else {
			txt.value = '|' + key_val;
		}

	}

	code_val = addslashes(key_val);

	var key_div = document.getElementById(id);
	key_div.innerHTML = "<div class=\"tag_key_sel\"><a href=\"#\" class=\"link_tag_sel\" onclick=\"removeTagKey('"
			+ textfield
			+ "','"
			+ code_val
			+ "','"
			+ id
			+ "');return false;\">"
			+ key_val + "</a></div>";

	// alert('KEY ' + key + ' aggiunta');
	// alert(txt.value);
}

// rimuove una parola key dal textfield specificato(le parole devono essere
// separate da |)
function removeTagKey(textfield, key_val, id) {
	var txt = document.getElementById(textfield);
	if (txt != null) {
		var strtxt = '';
		if (txt.value != null) {
			var rplVal = '|' + key_val;
			strtxt = txt.value;
			strtxt = strtxt.replace(rplVal, '');
		} else {
			txt.value = '';
		}
	}

	txt.value = strtxt;

	code_val = addslashes(key_val);

	var key_div = document.getElementById(id);
	key_div.innerHTML = "<div class=\"tag_key_no_sel\"><a href=\"#\" class=\"link_tag_no_sel\" onclick=\"addTagKey('"
			+ textfield
			+ "','"
			+ code_val
			+ "','"
			+ id
			+ "');return false;\">"
			+ key_val + "</a></div>";
	// alert('KEY ' + key + ' rimossa');
	// alert(txt.value);
}

function addslashes(str) {
	return (str + '').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}

function stripslashes(str) {
	return (str + '').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
}

// modifica il valore di un input box
function ChangeInputValue(id, val) {
	var input = document.getElementById(id);
	if (input != null) {
		input.value = val;
	}
}

// Seleziona o deseleziona tutti i valori checkbox in una tabella ()

function CheckUncheckAllInTable(idtable, idcheck, col, val) {
	var table = document.getElementById(idtable);

	var check = document.getElementById(idcheck);

	if (val == null) {
		val = true;
	}

	if (check != null) {
		if (!check.checked) {
			val = false;
		}
	}
	if (table != null) {
		// alert(table.rows.length);

		for ( var i = 0; i < table.rows.length; i++) {
			var cell = table.rows[i].cells[col];
			var checkboxes = cell.getElementsByTagName("input");
			if (checkboxes[0] != null) {
				checkboxes[0].checked = val;
			}
		}
	}
}

function mostraElemento(id, mostra) {
	var std_display = "block";
	if (mostra == false) {
		std_display = "none";
	}
	if (document.getElementById(id) != null) {
		document.getElementById(id).style.display = std_display;
	}
}

function showHideDiv(id) {
	var ele = document.getElementById(id);
	try {
		if (ele.style.display == "block") {
			ele.style.display = "none";
		} else {
			ele.style.display = "block";
		}
	} catch (err) {

	}

}

