// **** Create ID palette object : rgb #FFFFFF, art=1 usa colore artistico, neg=1 inverti palette chiaro/scuro
function IDpal (rgb, art, neg) {
// if (art === undefined) {art=0};
// if (neg === undefined) {neg=0};
// alert(art);
kd=3;kdd=6;kl=3;kld=6;
col = $.xcolor.average(rgb, rgb);
pcol=col;
if (art == 2) {
scol = $.xcolor.opacity(col, '#666', 0.4);
}
else if (art == 0) {
scol=$.xcolor.complementary(col)
} else {
scol=$.xcolor.complartist(col);
scol=$.xcolor.darken(scol,1,14);
};
ncol = $.xcolor.opacity(col, '#666', 0.95);

pdd = $.xcolor.darken(pcol,kdd);
pd  = $.xcolor.darken(pcol,kd);
p   = pcol;
pl  = $.xcolor.lighten(pcol,kl);
pld = $.xcolor.lighten(pcol,kld);

sdd = $.xcolor.darken(scol,kdd);
sd  = $.xcolor.darken(scol,kd);
s   = scol;
sl  = $.xcolor.lighten(scol,kl);
sld = $.xcolor.lighten(scol,kld);

ndd = $.xcolor.darken(ncol,kdd,16);
nd  = $.xcolor.darken(ncol,kd,16);
n   = ncol;
nl  = $.xcolor.lighten(ncol,kl,32);
nld = $.xcolor.lighten(ncol,kld,25);

if (neg ==1) {
return {pdd: pld , pd : pl , p  : pcol , pl : pd , pld: pdd , sdd: sld , sd : sl , s  : scol , sl : sd , sld: sdd , ndd: nld , nd : nl , n  : ncol , nl : nd, nld: ndd}
} else {
return {pdd: pdd , pd : pd , p  : pcol , pl : pl , pld: pld , sdd: sdd , sd : sd , s  : scol , sl : sl , sld: sld , ndd: ndd , nd : nd , n  : ncol , nl : nl, nld: nld}
}
};

// **** RESET FCK EDITORS ***/
function resetEditors()
{
    // If the editor API does not exist, there are no editors
    if (typeof FCKeditorAPI == "undefined") return;

    // Loop through all FCK instances, in case there are several editors
    for (var sEditorName in FCKeditorAPI.__Instances)
    {
        // The initial value that was set when the form was created
        // is stored in a hidden <INPUT> with the same name as the
        // editor (the editor itself is in an <IFRAME> with ___Frame
        // appended to the name.  Check whether that INPUT exists
        if (document.getElementById(sEditorName))
        {
            // Get the initial value
            var sInitialValue = document.getElementById(sEditorName).value;

            // Overwrite the editor's current value
            FCKeditorAPI.__Instances[sEditorName].SetHTML(sInitialValue);
        }
    }
} 

// ****** HIDE OR SHOW A LAYER

function showhide(id){
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none"){
obj.style.display = "";
} else {
obj.style.display = "none";
}
}
}

// ****** SHOW A LAYER

function show(id){
if (document.getElementById){
obj = document.getElementById(id);
obj.style.display = "";
}
}

// ****** HIDE A LAYER

function hide(id){
if (document.getElementById){
obj = document.getElementById(id);
obj.style.display = "none";
}
}


// ****** ENABLE FORM ELEMENT

function enable(id){
if (document.getElementById){
obj = document.getElementById(id);
obj.disabled = false;
}
}

// ****** DISABLE FORM ELEMENT

function disable(id){
if (document.getElementById){
obj = document.getElementById(id);
obj.disabled = true;
}
}

// ****** POPUP FUNCTION
function apri(cosa,dove,larg,alt)
{
window.open(cosa,dove,'toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=1,resizable=yes,width='+larg+',height='+alt+',left=10,top=10');
        }

// ****** POPUP FUNCTION
function openpopns(cosa,dove,larg,alt)
{
window.open(cosa,dove,'toolbar=1,location=1,directories=0,status=1,menubar=0,scrollbars=0,resizable=yes,width='+larg+',height='+alt+',left=10,top=10');
        }


// ****** AUTOCLOSE LOGOUT
function closepop(dove)
{
if (!opener) {self.location=dove }
	else {opener.location=dove;
self.close();
}
}
	        
// ****** CONFIRM FUNCTION
function confirm_dialog(message)
{
	return confirm(message)
}     

// ****** PUT OPENER FORM VALUE

function oputvalue(frmname,fielda,valuea){
		formobj=opener.document.forms[frmname];
		destfield=formobj[fielda];
		destfield.value=valuea;
}

// ****** GET OPENER FORM VALUE

function ogetvalue(frmname,fielda){
		formobj=opener.document.forms[frmname];
		destfield=formobj[fielda];
		return destfield.value;
}



// ****** CHANGE OPTIONS OF A PAGE USING PREFIX AND OPTION SELECTED
function prefix_navigation(prefix,selection){
var URL = selection.options[selection.selectedIndex].value;
window.location.href = prefix+URL;
//alert(prefix+URL);
};


// ******** ONLOAD HANDLING

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
};

// ******** ONRESIZE HANDLING

function addResizeEvent(func) {
  var oldonresize = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function() {
      oldonresize();
      func();
    }
  }
};

//  ***** left
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
};

// ****** right
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 light(number,icon) {
document.images[icon].src=alt_img[number].src
};

function turnoff(number,icon) {
document.images[icon].src=off_img[number].src
};



function getcheckedValue(frmname,fielda) {
		formobj=document.forms[frmname];
		radioObj=formobj[fielda];
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}



function a0401sel(selector) {
	switch (selector.options[selector.selectedIndex].value) {
	case "":
	hide('grupopt');
	warnmsg="Selezionare un\'operazione";
	optgo=false;
	cgroup=false;
	break;
	case "1":
	warnmsg="volete ELIMINARE tutti gli utenti selezionati ??";
	optgo=true;
	cgroup=false;
	hide('grupopt');
	break;
	case "2":
	warnmsg="volete DISABILITARE tutti gli utenti selezionati ??";
	optgo=true;
	cgroup=false;
	hide('grupopt');
	break;
	case "3":
	warnmsg="volete ABILITARE tutti gli utenti selezionati ??";
	optgo=true;
	cgroup=false;
	hide('grupopt');
	break;
	case "4":
	warnmsg="volete ASSEGNARE tutti gli utenti selezionati al gruppo ";
	optgo=true;
	cgroup=true;
	show('grupopt');
	break;
	case "5":
	warnmsg="volete RIMUOVERE tutti gli utenti selezionati dal gruppo ";
	optgo=true;
	cgroup=true;
	show('grupopt');
	break;
		}
	}

function a0401conf() {

if (cgroup) {
	selector=document.a0401.grupopt;
	
	if (selector.options[selector.selectedIndex].value=="") {
		optgo=false;
		alert('Selezionare un gruppo');
		} else {
			optgo=true;
			warnmsg=warnmsg+selector.options[selector.selectedIndex].text;
			}
};


	if (optgo) {
optgo=confirm_dialog(warnmsg);
}
	return optgo;
	}
	
function posnl() {
position('DIV_NEWSBOX_LIST_ICON',-352,-3,'DIV_NEWSBOX_LIST')
	};
	
function hidenl() {
	hide('DIV_NEWSBOX_LIST');
	show('EVENTSBOX_NUMBER');
	show('EVENTSBOX_FAM');
	show('EVENTSBOX_CAT');
};

function shownl() {
	show('DIV_NEWSBOX_LIST');
	hide('EVENTSBOX_NUMBER');
	hide('EVENTSBOX_FAM');
	hide('EVENTSBOX_CAT');
};	

// ******* CONTROLLO DATI PERSONALI

function checkper() {
		formobj=document.forms['REGISTRATION'];
		destfield=formobj['pervalue'];
if (destfield.checked==true) {show('perdata')} else {hide('perdata')};
askper=destfield.checked;
	}
	
	
	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);
    }
};





