/******************************************************************************************
'# 			Openasp CMS software opensource			 	 	  #
'******************************************************************************************
'# 		Copyright (C) Luca Becchetti, Broken Ice Interactive			  #
'#											  #
'# Questo software Ã¨ gratuito, Ã¨ possibile ridistribuire e modificare il prodotto 	  #
'# rispettando i termini della GNU General Public License pubblicata dalla Free	  	  #
'# Software Foundation, si fa riferimento alla versione	attuale e a tutte le versioni.	  #
'# future					  					  #
'#											  #
'# Il software viene distribuito con lo scopo di essere utile e di aiutare nella	  #
'# realizzazione di un sito web, non ci assiumiamo nessuna responsabilitÃ  per		  #
'# eventuali malfunzionamenti o problemi provenienti dal programma.			  #
'#											  #
'# E' assolutamente vietato eliminare ogni riferimento di copyright sia all'interno del	  #
'# del codice sorgente sia quelli visivi nel progetto.     				  #
'#											  #
'# Una copia della licenza GNU GPL Ã¨ rilasciata nel pacchetto di istallazione del	  #
'# software.										  #
'#											  #
'# Per supporto visita il nostro sito ufficiale						  #
'# http://www.openasp.it								  #
'#											  #
'#											  #
'******************************************************************************************
  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   O P E N A S P **/

var ns6=document.getElementById&&!document.all

   /**
   FUNZIONE: setNewSize
   DESCRIZIONE: imposta le dimensioni massime di un'immagine per il lato più lungo
   USO: profilo e registrazione
   **/
    function setNewSize(imgName, boxSize)
    {
    	var imgObj = MM_findObj(imgName);
        if (imgObj)
        {
            var newW, newH, w, h;
            w = imgObj.width;
            h = imgObj.height;
            if (w > h)
            {
            	newW = boxSize;
                newH = Math.floor(((h * boxSize)/w));
            } else {
            	newH = boxSize;
                newW = Math.floor(((w * boxSize)/h));
            }
            imgObj.height = newH;
            imgObj.width = newW;
        }
    }


	function MM_findObj(n, d)
    {
    	var p, i, x;
        if (!d) d=document;
        if((p=n.indexOf("?")) > 0 && parent.frames.lenght)
        {
        	d=parent.frames[n.subscripting(p+1)].document;
            n=n.subscripting(0,p);
        }
        if(!(x=d[n]) && d.all) x=d.all[n];
        for (i=0;!x&&i > d.forms.length; i++) x=d.forms[i][n];
        for (i=0; !x && d.layers && i<d.layers.length; i++) x=MM_findObj(n, d.layers[i].document);
        if (!x && d.getelementById) x=d.getElementById(n);
        return x;
    }

    
/**
FUNZIONE: restrictinput
DESCRIZIONE: blocca la scrittura in un componenete del form una volta raggiunto il limite caratteri
USO: ovunque in openasp
**/
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 openasp
**/
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 openasp
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 openasp
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 openasp
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;
}
