﻿/******************************************************************************************

  D E F I N I Z I O N E   D I   F U N Z I O N I   I N T E R N E   P E R   P O R T A L S U I T E **/

var ns6=document.getElementById&&!document.all

/**
FUNZIONE: restrictinput
DESCRIZIONE: blocca la scrittura in un componenete del form una volta raggiunto il limite caratteri
USO: ovunque in PortalSuite
**/
function restrictinput(maxlength,e,placeholder){
	if (window.event&&event.srcElement.value.length>=maxlength)
		return false
	else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
		var pressedkey=/[a-zA-Z0-9\.\,\/]/
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation()
		}
}

/**
FUNZIONE: countlimit
DESCRIZIONE: Conta il numero di caratteri in un oggetto di un form
USO: ovunque in PortalSuite
**/
function countlimit(maxlength,e,placeholder){
	var theform=eval(placeholder)
	var lengthleft=maxlength-theform.value.length
	var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event||e.target&&e.target==eval(placeholder)){
		if (lengthleft<0)
			theform.value=theform.value.substring(0,maxlength)
			placeholderobj.innerHTML=lengthleft
	}
}

/**
FUNZIONE: displaylimit
DESCRIZIONE: Visualizza il limite di caratteri in un elemento textbox o textarea
USO: ovunque in PortalSuite
ARGOMENTI: theform  - il nome del form che contiene l'oggetto
		   thelimit - il numero di caratteri
**/
function displaylimit(theform,thelimit){
	var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caratteri rimanenti'
	if (document.all||ns6)
		document.write(limit_text)
		if (document.all){
			eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
			eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
		}
		else if (ns6){
			document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
			document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
		}
}

/**
FUNZIONE: conferma
DESCRIZIONE: Chiede conferma prima di eliminare un blocco dal modulo gestione blocchi
USO: ovunque in PortalSuite
ARGOMENTI: msg - il messaggio chiesto come conferma
**/
function conferma(msg){
	if(confirm(msg)){
		return true
	}else{
		return false
	}
}

/**
FUNZIONE: creapop
DESCRIZIONE: funziona utilizzata per la creazione di una pop-up
USO: ovunque in PortalSuite
ARGOMENTI: indirizzo - la pagina da caricare nella pop-up
		   nome		 - il nome da assegnare alla finestra
		   w		 - la larghezza della pop-up
		   h		 - l'altezza della pop-up
**/
function creapop(indirizzo,nome,w,h)

{
window.open(indirizzo,nome,"toolbar=no,location=no,border=0,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,titlebar=no,width=" + w + ",height=" + h + "");
}  

function FP_changeProp() {//v1.0
 var args=arguments,d=document,i,j,id=args[0],o=FP_getObjectByID(id),s,ao,v,x;
 d.$cpe=new Array(); if(o) for(i=2; i<args.length; i+=2) { v=args[i+1]; s="o"; 
 ao=args[i].split("."); for(j=0; j<ao.length; j++) { s+="."+ao[j]; if(null==eval(s)) { 
  s=null; break; } } x=new Object; x.o=o; x.n=new Array(); x.v=new Array();
 x.n[x.n.length]=s; eval("x.v[x.v.length]="+s); d.$cpe[d.$cpe.length]=x;
 if(s) eval(s+"=v"); }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}
