	function conferma(IDKey_value, IDKey_label, str_parametri, str_messaggio, str_url){
		if (confirm(str_messaggio + " confermi?")){
			location.href = str_url + "?" + IDKey_label + "=" + IDKey_value + str_parametri;
		}
	}
	function confermaEVai(msg,url){
		if (confirm(msg) == true){document.location.href=url;}
	}

	function conferma_si_no(idkey_label, idkey_value, str_parametri_si, str_parametri_no, str_messaggio, str_url){
		var idkey_label;
		var idkey_value;
		var idpadre_label;
		var idpadre_value;
		var str_messaggio;
		var str_url;
		var str_parametri_si;
		var str_parametri_no;
		var URLelimina;
		var conferma;
		URLelimina = str_url + "?" + idkey_label + "=" + idkey_value + str_parametri_si ;

		conferma = confirm(str_messaggio + " confermi?");
		if (conferma == true){
			document.location.href = URLelimina;
		}else{
			document.location.href = str_url + str_parametri_no;
		}
	}
	function confermaEVai(msg,url){
		if (confirm(msg) == true){document.location.href=url;}
	}

	function confermaEVai_window_open(msg,url,parametri,self_location){
		if (confirm(msg) == true){
			window.open(url,'',parametri);
			if (self_location != ''){
				self.location.href = self_location;
			}
		}
	}

	function controllaqta(oggetto,qta){
		msg = '';
		if (isNumeric(oggetto.value) == true)
			{
				if (oggetto.value<=0) {msg='\tAttenzione!\nE\' stato inserito un valore non valido!';}
			} else { msg='\tAttenzione!\nE\' stato inserito un valore non valido!';}
		if (msg != '') {
			alert(msg);
			oggetto.value = qta;
		}
	}

	function anteprima_immagine(id){
		addr 	=	"/0_inizio/anteprima_immagine.asp?" + id
		alt		=	150
		lar 	=	150
		rszb 	=	(document.layers)?1:0;
		props	=	'height=' + alt + ',width=' + lar + ',top=' + parseInt((screen.availHeight-alt)/2) + ',left=' + parseInt((screen.availWidth-lar)/2) + ',scrollbars=0,resizable=' + rszb + ',toolbar=0,menubar=0,location=0,status=0';

		window.open(addr,'anteprima','_blank',props);
	}

	function pannelloFile(Count1,Count2,popup){
		//alert('Count1='+Count1+'\nCount2='+Count1);
		document.cb_edit.HCount1.value 		= Count1;
		document.cb_edit.HCount2.value		= Count2;
		document.cb_edit.tipo_popup.value 	= popup;
		document.cb_edit.submit();
	}
	
	function aggiornaOpener(host, parametri){
		opener.location.href = 'http://'+host+opener.location.pathname+'?'+parametri;
	}
	function refreshOpener(){
		if(window.opener && window.opener.location)
		{
			opener.location.reload();
		}
	}
	
	function misura(){
		larghezza 	= document.myImg.width; 
		altezza		= document.myImg.height; 
		peso		= document.myImg.fileSize;
		
//		alert(larghezza + " x " + altezza + " : " + peso)
// controllo
		if (peso > 10000) { 
//			alert("troppo grosso");
			return false;
		} else {
			return true;
		}
	}

	function checkImg(id, com){
		var img = eval('document.images["' + id + '"]');
		var larghezza = img.width;
		var altezza = img.height;
		
		var nuovalarghezza = (larghezza * com) / altezza;
//		alert('id=' + id + '\nlarghezza=' + larghezza + '\naltezza=' + altezza);
		if (larghezza <= altezza){
			img.style.pixelHeight = com;
			img.style.pixelWidth = nuovalarghezza;
		}else{
			img.style.pixelWidth = com;
			img.vspace = (com - altezza) / 2
		}
	}
	
	function ridimensionaimmagine(id, larghmax, altmax){
		alert('larghmax='+larghmax+'\naltmax='+altmax);
		var img = id;
		var larghezza = img.width;
		var altezza = img.height;
		//alert('altezza='+altezza+'\nlarghezza='+larghezza);
		//img.style.pixelHeight = 100;
		var nuovalarghezza = (larghezza * larghmax) / altezza;
//		alert('id=' + id + '\nlarghezza=' + larghezza + '\naltezza=' + altezza);
		if (larghezza <= altezza){
			img.style.pixelHeight = larghmax;
			img.style.pixelWidth = nuovalarghezza;
		}else{
			img.style.pixelWidth = larghmax;
			img.vspace = (larghmax - altezza) / 2
		}
	}
	
	
	function initialize(campo, action, cb_prefix) {
		iFrameDoc = eval(str_iFrameDoc);
		iFrameDoc.open();
		iFrameDoc.write("<html><link rel='stylesheet' type='text/css' href='/css/web.css' media='screen' /><body MONOSPACE style='padding: 20px;'>" + unescape(eval('document.cb_edit.' + campo + '.value')) + "</body></html>");
		iFrameDoc.close();
		if (action == 'edit'){
			iFrameDoc.designMode = "On";
		}
	}
	// Porta il focus al riquadro di testo
	function setFocus() {
	if (document.all)
		document.frames("Composition").focus();
	else
		document.getElementById('Composition').contentWindow.focus()
	return;
	}
	function setBlur() {
	if (document.all)
		document.frames("Composition").blur();
	else
		document.getElementById('Composition').contentWindow.blur()
	return;
	}
	// Controlla se la toolbar č abilitata nella modalitā testo
	function validateMode() {
		if (! bHtmlMode)
			return true;
//		alert("Deselezionare \"Visualizza HTML\" per utilizzare le barre degli strumenti");
		setFocus();
		return false;
	}
	// Formatta il testo
	function formatC(what,opt) {
//		if (!validateMode())
//			return;
//alert(what);
		iFrameDoc = eval(str_iFrameDoc);
		if (what == 'h1'){

			var htmlSelez = iFrameDoc.selection.createRange().htmlText;
			htmlSelezModif = "<" + what + ">" + htmlSelez.valueOf() + "</" + what + ">";

			iFrameDoc.selection.createRange().pasteHTML(htmlSelezModif)

			setFocus();
		}else{
			iFrameDoc.execCommand(what,false,opt);
			setFocus();
		}
	}
	
	//Imposta l'hidden con il contenuto del frame dell'editor
	function setHidden(campo) {
		iFrameDoc = eval(str_iFrameDoc);
		riquadro = iFrameDoc.body;
		com1 = eval('document.cb_edit.' + campo);
//		alert(escape(riquadro.innerHTML));
		com1.value = riquadro.innerHTML;
	}

	function butover(el) {
	  el.className = "raised";
	}
	
	function butout(el) {
	  el.className = "button";
	}
	
	function butdown(el) {
	  el.className = "pressed";
	}
	
	function butup(el) {
	  el.className = "raised";
	}
	function inizia(campo){
		document.forms[document.forms.lenght-1].onsubmit = setHidden(campo);
	}
	function InfoAttivaIscrizione(id, messaggio){
		if (id == 'ATTIVO'){
//		alert(id);
			alert('Prima di attivare l\'iscrizione on-line sul sito web della scuola,\noccorre aver inserito: ' + messaggio + '.');
		}
	}

function LTrim(str){
	if (str==null){return null;}
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	if (str==null){return null;}
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
function LTrimAll(str) {
	if (str==null){return str;}
	for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
	return str.substring(i,str.length);
	}
function RTrimAll(str) {
	if (str==null){return str;}
	for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
	return str.substring(0,i+1);
	}
function TrimAll(str) {
	return LTrimAll(RTrimAll(str));
	}
function isNull(val){return(val==null);}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val){return(parseFloat(val,10)==(val*1));}

//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj){return(typeof(obj.length)=="undefined")?false:true;}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj){if(isBlank(obj.value)){obj.value="";}}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase(){
	for(var i=0;i<arguments.length;i++) {
		arguments[i].value = arguments[i].value.toUpperCase();
		}
	}

//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if 
//   blank and focuses
//-------------------------------------------------------------------
function disallowBlank(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (isBlank(getInputValue(obj))){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
			}
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// disallowModify(input_object[,message[,true]])
//   Checks a form field for a value different than defaultValue. 
//   Optionally alerts and focuses
//-------------------------------------------------------------------
function disallowModify(obj){
	var msg=(arguments.length>1)?arguments[1]:"";
	var dofocus=(arguments.length>2)?arguments[2]:false;
	if (getInputValue(obj)!=getInputDefaultValue(obj)){
		if(!isBlank(msg)){alert(msg);}
		if(dofocus){
			if (isArray(obj) && (typeof(obj.type)=="undefined")) {obj=obj[0];}
			if(obj.type=="text"||obj.type=="textarea"||obj.type=="password") { obj.select(); }
			obj.focus();
			}
		setInputValue(obj,getInputDefaultValue(obj));
		return true;
		}
	return false;
	}

//-------------------------------------------------------------------
// commifyArray(array)
//   Take an array of values and turn it into a comma-separated string
//-------------------------------------------------------------------
function commifyArray(obj){
	var s="";
	if(obj==null||obj.length<=0){return s;}
	for(var i=0;i<obj.length;i++){
		s=s+((s=="")?"":",")+obj[i].toString();
		}
	return s;
	}

//-------------------------------------------------------------------
// getSingleInputValue(input_object,use_default)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputValue(obj,use_default) {
	switch(obj.type){
		case 'radio': case 'checkbox': return(((use_default)?obj.defaultChecked:obj.checked)?obj.value:null);
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].value;}}
				return o[0].value;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].value:null;
		case 'select-multiple': 
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].value;
					}
				}
			return (values.length==0)?null:commifyArray(values);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}

//-------------------------------------------------------------------
// getSingleInputText(input_object,use_default)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputText(obj,use_default) {
	switch(obj.type){
		case 'radio': case 'checkbox': 	return "";
		case 'text': case 'hidden': case 'textarea': return(use_default)?obj.defaultValue:obj.value;
		case 'password': return((use_default)?null:obj.value);
		case 'select-one':
			if (obj.options==null) { return null; }
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].text;}}
				return o[0].text;
				}
			if (obj.selectedIndex<0){return null;}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].text:null;
		case 'select-multiple': 
			if (obj.options==null) { return null; }
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].text;
					}
				}
			return (values.length==0)?null:commifyArray(values);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}

//-------------------------------------------------------------------
// setSingleInputValue(input_object,value)
//   Utility function used by others
//-------------------------------------------------------------------
function setSingleInputValue(obj,value) {
	switch(obj.type){
		case 'radio': case 'checkbox': if(obj.value==value){obj.checked=true;return true;}else{obj.checked=false;return false;}
		case 'text': case 'hidden': case 'textarea': case 'password': obj.value=value;return true;
		case 'select-one': case 'select-multiple': 
			var o=obj.options;
			for(var i=0;i<o.length;i++){
				if(o[i].value==value){o[i].selected=true;}
				else{o[i].selected=false;}
				}
			return true;
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return false;
	}

//-------------------------------------------------------------------
// getInputValue(input_object)
//   Get the value of any form input field
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputValue(obj) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputValue(obj[i],use_default);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values);
		}
	return getSingleInputValue(obj,use_default);
	}

//-------------------------------------------------------------------
// getInputText(input_object)
//   Get the displayed text of any form input field
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,reset,submit)
//-------------------------------------------------------------------
function getInputText(obj) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputText(obj[i],use_default);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values);
		}
	return getSingleInputText(obj,use_default);
	}

//-------------------------------------------------------------------
// getInputDefaultValue(input_object)
//   Get the default value of any form input field when it was created
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputDefaultValue(obj){return getInputValue(obj,true);}

//-------------------------------------------------------------------
// isChanged(input_object)
//   Returns true if input object's value has changed since it was
//   created.
//-------------------------------------------------------------------
function isChanged(obj){return(getInputValue(obj)!=getInputDefaultValue(obj));}

//-------------------------------------------------------------------
// setInputValue(obj,value)
//   Set the value of any form field. In cases where no matching value
//   is available (select, radio, etc) then no option will be selected
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function setInputValue(obj,value) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if(isArray(obj)&&(typeof(obj.type)=="undefined")){
		for(var i=0;i<obj.length;i++){setSingleInputValue(obj[i],value);}
		}
	else{setSingleInputValue(obj,value);}
	}
	
//-------------------------------------------------------------------
// isFormModified(form_object,hidden_fields,ignore_fields)
//   Check to see if anything in a form has been changed. By default
//   it will check all visible form elements and ignore all hidden 
//   fields. 
//   You can pass a comma-separated list of field names to check in
//   addition to visible fields (for hiddens, etc).
//   You can also pass a comma-separated list of field names to be
//   ignored in the check.
//-------------------------------------------------------------------
function isFormModified(theform,hidden_fields,ignore_fields){
	if(hidden_fields==null){hidden_fields="";}
	if(ignore_fields==null){ignore_fields="";}
	var hiddenFields=new Object();
	var ignoreFields=new Object();
	var i,field;
	var hidden_fields_array=hidden_fields.split(',');
	for (i=0;i<hidden_fields_array.length;i++) {
		hiddenFields[Trim(hidden_fields_array[i])]=true;
		}
	var ignore_fields_array=ignore_fields.split(',');
	for (i=0;i<ignore_fields_array.length;i++) {
		ignoreFields[Trim(ignore_fields_array[i])]=true;
		}
	for (i=0;i<theform.elements.length;i++) {
		var changed=false;
		var name=theform.elements[i].name;
		if(!isBlank(name)){
			var type=theform[name].type;
			if(!ignoreFields[name]){
				if(type=="hidden"&&hiddenFields[name]){changed=isChanged(theform[name]);}
				else if(type=="hidden"){changed=false;}
				else {changed=isChanged(theform[name]);}
				}
			}
		if(changed){return true;}
		}
		return false;
	}
	
	function AbilitaDisabilita() {

		if (document.cb_edit.generapassword.checked == true) {
			document.cb_edit.nomeutente.disabled 	= true;
			document.cb_edit.password.disabled	 	= true;
			document.cb_edit.nomeutente.className	= 'w100';
			document.cb_edit.password.className		= 'w100';
		} else {
			document.cb_edit.nomeutente.disabled 	= false;
			document.cb_edit.password.disabled 		= false;
			document.cb_edit.nomeutente.className	= 'w100';
			document.cb_edit.password.className		= 'w100';

		}
	}
	
	function AbilitaDisabilita2() {

		if (document.cb_edit.movimenta.checked == true) {
			document.cb_edit.idcommessa2.disabled 	= true;
			document.cb_edit.idcommessa2.className	= 'text100 fdisabled';
		} else {
			document.cb_edit.idcommessa2.disabled 	= false;
			document.cb_edit.idcommessa2.className	= 'text100';
		}
	}
	
	function AbilitaDisabilita3() {

		if (document.cb_edit.tutteaziende.checked == true) {
			document.cb_edit.idazienda1.disabled 	= true;
			document.cb_edit.idazienda1.className	= 'text100 fdisabled';
		} else {
			document.cb_edit.idazienda1.disabled 	= false;
			document.cb_edit.idazienda1.className	= 'text100';
		}
	}
	
	function AbilitaDisabilita4() {

		if (document.cb_edit.tuttecommesse.checked == true) {
			document.cb_edit.idcommessa1.disabled 	= true;
			document.cb_edit.idcommessa1.className	= 'text100 fdisabled';
		} else {
			document.cb_edit.idcommessa1.disabled 	= false;
			document.cb_edit.idcommessa1.className	= 'text100';
		}
	}
	
	function AbilitaDisabilita5() {

		if (document.cb_edit.tuttilavoratori.checked == true) {
			document.cb_edit.idanagrafica1.disabled 	= true;
			document.cb_edit.idanagrafica1.className	= 'text100 fdisabled';
		} else {
			document.cb_edit.idanagrafica1.disabled 	= false;
			document.cb_edit.idanagrafica1.className	= 'text100';
		}
	}
	
function IsStringValid(szPassedString, szCompareString)
{
	var szTmpString = new String;
	var nLength = 0;
	var nIndex;
	
	szTmpString = szPassedString;
	nLength 	= szTmpString.length;

	for (nIndex = 0; nIndex < nLength; nIndex++)
		{
		if (szCompareString.indexOf(szTmpString.charAt(nIndex), 0) < 0)
			{
			return false;
			}
		} return true;
}

//*************************************************************************

  // Funzioni di rollover dei tasti
  // Funzioni di rollover dei tasti
  // Funzioni di rollover dei tasti
  function selOn(ctrl){
	ctrl.style.borderColor 		= '#000000';
	ctrl.style.backgroundColor 	= '#B5BED6';
	ctrl.style.cursor 			= 'pointer';	
  }
  
  function selOff(ctrl){
	ctrl.style.borderColor 		= '#D6D3CE';  
	ctrl.style.backgroundColor 	= '#D6D3CE';
  }
  
  function selDown(ctrl){
	ctrl.style.backgroundColor 	= '#8492B5';
  }
  
  function selUp(ctrl){
    ctrl.style.backgroundColor 	= '#B5BED6';
  }
  // Funzioni comandi WYSIWYG
  function doBold(idCbEditor){
	var id = eval(idCbEditor + '.document');
	id.execCommand('bold', false, null);
  }
  function doItalic(idCbEditor){
	var id = eval(idCbEditor + '.document');
	id.execCommand('italic', false, null);
  }
  function doUnderline(idCbEditor){
	var id = eval(idCbEditor + '.document');
	id.execCommand('underline', false, null);
  }
  function doLeft(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('justifyleft', false, null);
  }
  function doCenter(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('justifycenter', false, null);
  }

  function doRight(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('justifyright', false, null);
  }

  function doOrdList(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('insertorderedlist', false, null);
  }

  function doBulList(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('insertunorderedlist', false, null);
  }
  
  function doForeCol(idCbEditor){
	var id = eval(idCbEditor + '.document');
    var fCol = prompt('Enter foreground color', '');
    if(fCol != null){
      id.execCommand('forecolor', false, fCol);
	}
  }

  function doBackCol(idCbEditor){
	var id = eval(idCbEditor + '.document');
    var bCol = prompt('Enter background color', '');
    if(bCol != null){
		id.execCommand('backcolor', false, bCol);
	}
  }

  function doLink(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('createlink');
  }
  
  function doImage(idCbEditor){
	var id = eval(idCbEditor + '.document');
    var imgSrc = prompt('Enter image location', '');
    if(imgSrc != null){
		id.execCommand('insertimage', false, imgSrc);
	}
  }
  
  function doRule(idCbEditor){
	var id = eval(idCbEditor + '.document');
    id.execCommand('inserthorizontalrule', false, null);
  }
  
  function doFont(fName,idCbEditor){
	var id = eval(idCbEditor + '.document');
    if(fName != ''){
      id.execCommand('fontname', false, fName);
	}
  }
  
  function doSize(fSize,idCbEditor){
	var id = eval(idCbEditor + '.document');
    if(fSize != ''){
      id.execCommand('fontsize', false, fSize);
	}
  }
  
  function doHead(hType,idCbEditor){
  	alert(hType);
	var id = eval(idCbEditor + '.document');
    if(hType != ''){
      id.execCommand('FormatBlock', true, hType);  
//      doFont(selFont.options[selFont.selectedIndex].value,idCbEditor);
    }
  }
  
function UpdateCounter(Counter,Testo){
	Testo		= Trim(Testo);
	var lung 	= Testo.length;
	if (lung>0) {
		arr = Testo.split(" ");
		Counter.value = arr.length;
	}
}


	function iif(uno,due,tre){
		if (uno){
			return due;
		}else{
			return tre;
		}
	}

	function calcola_quantita_da_fattori(quantita, fattorea, fattoreb, fattorec, fattorescala) {

		var fattorea = iif(fattorea.value == null || fattorea.value == '',0,fattorea.value);
		var fattoreb = iif(fattoreb.value == null || fattoreb.value == '',0,fattoreb.value);
		var fattorec = iif(fattorec.value == null || fattorec.value == '',0,fattorec.value);

		fattorea = new String(fattorea);
		fattoreb = new String(fattoreb);
		fattorec = new String(fattorec);

		fattorea = fattorea.replace(',','.');
		fattoreb = fattoreb.replace(',','.');
		fattorec = fattorec.replace(',','.');

		fattorea = fattorea / fattorescala.value;
		fattoreb = fattoreb / fattorescala.value;
		fattorec = fattorec / fattorescala.value;
		
//		alert('fattorea = '+fattorea+'\nfattoreb = '+fattoreb+'\nfattorec = '+fattorec+'\n');

		if(fattorea != 0 && fattoreb != 0 && fattorec != 0){
			quantita.value = (Math.round((fattorea * fattoreb * fattorec)*100)/100)
		}else{
			if(fattorea != 0 && fattoreb != 0){
				quantita.value = (Math.round((fattorea * fattoreb)*100)/100)
			}else{
				if(fattorea != 0 ){
					quantita.value = (Math.round((fattorea)*100)/100)
				}
			}
		}
	}

	function alterna_vista_indirizzo_fatturazione() {

		if(	document.getElementById("idindirizzo1_table").style.display 				   == ''){

			document.getElementById("idindirizzo1_table").style.display						= 'none';
			document.getElementById("x_x_xidindirizzo1_ragionesociale_table").style.display	= '';
			document.getElementById("x_x_xidindirizzo1_indirizzo_table").style.display		= '';
			document.getElementById("x_x_xidindirizzo1_numero_table").style.display			= '';
			document.getElementById("x_x_xidindirizzo1_cap_table").style.display			= '';
			document.getElementById("x_x_xidindirizzo1_citta_table").style.display			= '';
			document.getElementById("x_x_xidindirizzo1_localita_table").style.display		= '';
			document.getElementById("x_x_xidindirizzo1_provincia_table").style.display		= '';
			document.getElementById("x_x_xidindirizzo1_nazione_table").style.display		= '';

		}else{
		
			document.getElementById("idindirizzo1_table").style.display						= '';
			document.getElementById("x_x_xidindirizzo1_ragionesociale_table").style.display	= 'none';
			document.getElementById("x_x_xidindirizzo1_indirizzo_table").style.display		= 'none';
			document.getElementById("x_x_xidindirizzo1_numero_table").style.display			= 'none';
			document.getElementById("x_x_xidindirizzo1_cap_table").style.display			= 'none';
			document.getElementById("x_x_xidindirizzo1_citta_table").style.display			= 'none';
			document.getElementById("x_x_xidindirizzo1_localita_table").style.display		= 'none';
			document.getElementById("x_x_xidindirizzo1_provincia_table").style.display		= 'none';
			document.getElementById("x_x_xidindirizzo1_nazione_table").style.display		= 'none';

		}
	}

	function alterna_vista_indirizzo_destinazione() {

		if(	document.getElementById("idindirizzo2_table").style.display 				   == ''){

			document.getElementById("idindirizzo2_table").style.display						= 'none';
			document.getElementById("x_x_xidindirizzo2_ragionesociale_table").style.display	= '';
			document.getElementById("x_x_xidindirizzo2_indirizzo_table").style.display		= '';
			document.getElementById("x_x_xidindirizzo2_numero_table").style.display			= '';
			document.getElementById("x_x_xidindirizzo2_cap_table").style.display			= '';
			document.getElementById("x_x_xidindirizzo2_citta_table").style.display			= '';
			document.getElementById("x_x_xidindirizzo2_localita_table").style.display		= '';
			document.getElementById("x_x_xidindirizzo2_provincia_table").style.display		= '';
			document.getElementById("x_x_xidindirizzo2_nazione_table").style.display		= '';

		}else{
		
			document.getElementById("idindirizzo2_table").style.display						= '';
			document.getElementById("x_x_xidindirizzo2_ragionesociale_table").style.display	= 'none';
			document.getElementById("x_x_xidindirizzo2_indirizzo_table").style.display		= 'none';
			document.getElementById("x_x_xidindirizzo2_numero_table").style.display			= 'none';
			document.getElementById("x_x_xidindirizzo2_cap_table").style.display			= 'none';
			document.getElementById("x_x_xidindirizzo2_citta_table").style.display			= 'none';
			document.getElementById("x_x_xidindirizzo2_localita_table").style.display		= 'none';
			document.getElementById("x_x_xidindirizzo2_provincia_table").style.display		= 'none';
			document.getElementById("x_x_xidindirizzo2_nazione_table").style.display		= 'none';

		}
	}
	
	function isDate(data){
		var re = /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]­|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-­9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][2­6])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(­?:1[6-9]|[2-9]\d)?\d{2})$/; 
		return re.test(data); 
	}



function dateAdd(p_Interval, p_Number, gg, mm, aa){

	if(!isDate(gg+'/'+mm+'/'+aa)){return "invalid date: '" + gg+'/'+mm+'/'+aa + "'";}
	if(isNaN(p_Number)){return "invalid number: '" + p_Number + "'";}	

	p_Number 	= new Number(p_Number);
	var dt 		= new Date(aa, mm, gg);
	
	switch(p_Interval.toLowerCase()){
		case "yyyy": {// year
			dt.setFullYear(dt.getFullYear() + p_Number);
			break;
		}
		case "q": {		// quarter
			dt.setMonth(dt.getMonth() + (p_Number*3));
			break;
		}
		case "m": {		// month
			dt.setMonth(dt.getMonth() + p_Number);
			break;
		}
		case "y":		// day of year
		case "d":		// day
		case "w": {		// weekday
			dt.setDate(dt.getDate() + p_Number);
			break;
		}
		case "ww": {	// week of year
			dt.setDate(dt.getDate() + (p_Number*7));
			break;
		}
		case "h": {		// hour
			dt.setHours(dt.getHours() + p_Number);
			break;
		}
		case "n": {		// minute
			dt.setMinutes(dt.getMinutes() + p_Number);
			break;
		}
		case "s": {		// second
			dt.setSeconds(dt.getSeconds() + p_Number);
			break;
		}
		case "ms": {		// second
			dt.setMilliseconds(dt.getMilliseconds() + p_Number);
			break;
		}
		default: {
			return "invalid interval: '" + p_Interval + "'";
		}
	}
	a = Right('0'+dt.getDate(),2) + '/' + Right('0'+dt.getMonth(),2) + '/' + dt.getFullYear();
	return a;
}

	function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
	}
	
	function Right(str, n){
		if (n <= 0)
		   return "";
		else if (n > String(str).length)
		   return str;
		else {
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
	}

	
	function seleziona_tutti_check_dinamico(campo,id,label) {
		var ck = eval('document.cb_edit.'+campo);
		if (label=="Seleziona tutti"){
			if(ck.length){
				for(var i = 0; i < ck.length; i++){
					if(ck[i].type == 'checkbox'){
						ck[i].checked = true;
						ck[i].parentNode.style.fontWeight = "bold";
					}
	
				}
			}else{
				ck.checked = true;
			}
		}else{
			if(ck.length){
				for(var i = 0; i < ck.length; i++){
					if(ck[i].type == 'checkbox') ck[i].checked = false;
					ck[i].parentNode.style.fontWeight = "normal";
				}
			}else{
				ck.checked = false;
			}
		}	
	}

	function cambia_lo_stile(campo,id) {
		var ck = eval('document.cb_edit.'+campo);
		if(ck.length){
			for(var i = 0; i < ck.length; i++){
				if(ck[i].type == 'checkbox'){
					if(ck[i].checked == true){
						ck[i].checked = true;
						ck[i].parentNode.style.fontWeight = "bold";
					}else{
						ck[i].checked = false;
						ck[i].parentNode.style.fontWeight = "normal";
					}
				}

			}
		}
	}

	function calcola_prezzo_iva_no_iva() {

		prezzo_iva_esclusa 	= document.cb_edit.prezzo.value;
		prezzo_iva_inclusa 	= document.cb_edit.x_x_xprezzoivainclusa.value;
		percentualeiva		= document.cb_edit.x_x_xpercentualeiva.value;

		if(prezzo_iva_inclusa!=''){
			if(percentualeiva == ''){
				alert('Aliquota I.V.A.: Selezionare Aliquota I.V.A.');
				document.cb_edit.idaliquota1.focus();
			}else{
				if(isNumeric(prezzo_iva_inclusa)){
					var a = prezzo_iva_inclusa / (1+(percentualeiva/100));
					document.cb_edit.prezzo.value = Math.round(a*100)/100
				}else{
					document.cb_edit.x_x_xprezzoivainclusa.value = '';
				}
			}
		}
		
	}

	function seleziona_tutti(campo,checked) {
		var ck = eval('document.cb_edit.'+campo);
//		alert(checked);
		if (!checked){
//			id.innerHTML = "Deseleziona tutti";		
			if(ck.length){
				for(var i = 0; i < ck.length; i++){
					if(ck[i].type == 'checkbox'){
						ck[i].checked = true;
//						ck[i].parentNode.style.fontWeight = "bold";
					}
	
				}
			}else{
				ck.checked = true;
			}
		}else{
//			id.innerHTML = "Seleziona tutti";		
			if(ck.length){
				for(var i = 0; i < ck.length; i++){
					if(ck[i].type == 'checkbox'){
						ck[i].checked = false;
					}
				}
			}else{
				ck.checked = false;
			}
		}	
	}

