/*******************************************************/
/* QUESTI SCRIPT SONO STATI GENERATI DA MARCO DI MITRO */
/* E-MAIL: m.dimitro@ingeniaweb.com                    */
/* DATO CHE NON  POSSO  OBBLIGARVI A NON RUBARE QUESTO */
/* CODICE,  SE PROPRIO  VOLETE FARLO ALLORA  INCLUDETE */
/* QUESTA BREVE INTESTAZIONE. ;-)                      */
/*******************************************************/

//determino il tipo di browser
switch (navigator.appName) {
    case "Netscape":
        var Browser="NS";
        break;
        
    default:
        var Browser="IE";
        break;
}

//Restituisce una stringa corrispondente ai due parametri altezza e larghezza da passare a window.open per centrare
//una finestra popup. E' dipendente dal browser correntemente utilizzato.
function Centered(W,H) {
    var X=screen.width / 2 - W / 2;
    var Y=screen.height / 2 - H / 2;
    switch (Browser) {
        case "IE":
            return "left=" + X + ", top=" + Y;
            break;
            
        default:
            return "screenX=" + X + ", screenY=" + Y;
            break;
    }
}

function ViewLayer(LayerName, View) {
    if (document.getElementById) { 
        //browser W3C compatibili
        if (View) {
            var SView="visible";
        } else {
            var SView="hidden";
        }
        eval("document.getElementById(\"" + LayerName + "\").style.visibility = \"" + SView + "\"");
    } else {          
        if (document.layers) { 
            //NS browser
            if (View) {
                var SView="show";
            } else {
                var SView="hidden";
            }
            document.layers[LayerName].visibility = SView;
        } else {
            if (document.all) {
                //browser IE
                if (View) {
                    var SView="visible";
                } else {
                    var SView="hidden";
                }
                eval("document.all." + LayerName + ".style.visibility = \"" + SView + "\""); 
            } 
        } 
    }
}

function StatusBarScroll() {
	var WinStatus=window.status;
	window.status=WinStatus.substr(1)+WinStatus.substr(0,1)
	setTimeout("StatusBarScroll()",150);
}


function VerifyEmail(email) {
	if (email.length>=5) {	//primo controllo: almeno 5 chr (a@b.c)
		//in nAt memorizzo il n° di @ trovate; in pAt la posizione dell'ultima trovata
        //in pPt memorizzola posizione dell'ultimo punto 
		for (i=0,nAt=0,pAt=0,pPt=0;i<email.length;i++) {
			switch (email.substr(i,1)) {
                case "@":
				    nAt++;
				    pAt=i;
                    break;
                case ".":
                    pPt=i;
                    break;
			}
		}
		//controllo il n° di @
		if (nAt!=1) {  	//ci deve essere un @
			return false;
		} else {	//c'è un @
			if (pPt>pAt) {
                //c'è un punto dopo l'@
                return true;
			} else {
                //manca il punto dopo l'@
				return false;
			}
		}
	} else {
		return false;
	}
}

//crea un vettore dividendo la stringa Str ad ogni occorrenza del carattere separatore Sep
//E' un sostituto di split.
function Explode(Sep,Str) {	
	var NVal=0;
	var SubS="";
	for (var I=0; I<Str.length; I++) {
		if (Str.substr(I,1)==Sep) {
			if (NVal==0) {
				var A=new Array(1);
				A[0]=SubS;				
			} else {
				A[A.length]=SubS;
			}
			SubS="";
			NVal++;
		} else {
			SubS=SubS+Str.substr(I,1)
		}
	}
	if (SubS.length>0) {
		if (NVal==0) {			
			var A=new Array(1);
    		A[0]=SubS;				
    	} else {
    		A[A.length]=SubS;
    	}
	}
	return A;
}

function Implode(Sep,Ar) {	
	var S="";
    for (I=0; I<Ar.length; I++) {
        if (S=="") {
            S=Ar[I];
        } else {
            S=S+Sep+Ar[I];
        }
    }
    return S;
}

function in_array(A,What) {
    var Found=-1;
    if ((A!="") && (typeof(A)!="undefined")) {
        if (A.length>0) {
            for (var I=0; (I<A.length) && (Found==-1); I++) {            
                if (A[I]==What) {
                    Found=I;
                }
            }
        }        
    }
    return Found;
}

//sostituisce le occorrenze di Cosa con la stringa Con all'interno di Dove.
function Replace(Dove, Cosa, Con) {
    if ((Dove!="") && (Cosa!="")) {
        var I=0;
        do {
            if (Dove.substr(I,Cosa.length)==Cosa) {
                //trovata l'occorrenza, la sostituisco
                Dove=Dove.substr(0,I)+Con+Dove.substr(I+Cosa.length);
            }
            I++;
        } while (I<Dove.length);
    }
    return Dove;
}

//apre una finestra popup che visualizza l'immagine indicata. I parametri obbligatori sono:
//- PathImg   = percorso dell'immagine
//- Width     = larghezza dell'immagine
//- Height    = altezza dell'immagine
//I parametri opzionali in ordine sono:
//- Title     = titolo che avrà la finestra popup
//- BGColor   = Colore dello sfondo della finestra in formato esadecimale: il cancelletto iniziale può essere omesso
//- PathWin   = directory in cui si trova preview.php; se non è specificato il parametro allora il file verrà
//              cercato nella directory corrente.
function ViewPreview(PathImg, Width, Height) {
    switch (arguments.length) {
        case 3:
            var Title="";
            var BGColor="";
            var PathWin="";
            break;
        case 4: 
            var Title=arguments[3];
            var BGColor="";
            var PathWin="";
            break;
        case 5: 
            var Title=arguments[3];
            var BGColor=arguments[4];
            var PathWin="";
            break;
        case 6: 
            var Title=arguments[3];
            var BGColor=arguments[4];
            var PathWin=arguments[5];
            break;
    }
    if (BGColor.substr(0,1)=="#") BGColor=BGColor.substr(1);
  
    //calcolo le dimensioni della finestra
    switch (Browser) {
        case "IE":
            var WinWidth=Width+10;
            var WinHeight=Height+29;
            var Resizable="no";
            break;
        
        default:
            var WinWidth=Width;
            var WinHeight=Height;
            var Resizable="yes";
            break;
    }        

    
    //- Resizable = è l'opzione da passare al comando window.open.
    //              Se il browser è NS o cmq non permette il ridimensionamento della finestra nemmeno da script quando
    //              è stato preventivamente impostato su false allora passare Resizable=true per permettere al browser
    //              di ridimensionare la finestra nell'eventualità in cui venisse richisto un cambio dell'immagine da
    //              ridimensionare;
    //              Se invece il browser permette in ogni caso il resize (come IE) allora passare Resizable=false
    //              in modo che l'utente non abbia possibilità di ridimensionare la finestra.

    
    //controllo la risoluzione dello schermo e se la finestra da visualizzare non può essere visualizzata
    //alla risoluzione corrente allora riduco le dimensioni.
    var ScrollBars="no";    
    if (WinWidth>window.screen.availWidth) {
        ScrollBars="yes";
        WinWidth=window.screen.availWidth;
    }
    if (WinHeight>window.screen.availHeight) {
        ScrollBars="yes";
        WinHeight=window.screen.availHeight;
    }
    
    //posiziono la finestra di preview al centro dello schermo
    var ScreenX=Math.ceil((screen.width / 2) - (WinWidth / 2));
    var ScreenY=Math.ceil((screen.height / 2) - (WinHeight / 2));
    switch (Browser) {
        case "IE":
            ScreenX="left="+ScreenX;
            ScreenY="top="+ScreenY;
            break;
            
        default:
            ScreenX="ScreenX="+ScreenX;
            ScreenY="ScreenY="+ScreenY;
            break;
    }
    
    PathImg=Replace(PathImg,"/","%2F");
    var WinPreview=window.open(PathWin+"?Img="+PathImg+"&Title="+Title+"&BGColor="+BGColor+"&MaxWinHeight="+window.screen.availHeight+"&MaxWinWidth="+window.screen.availWidth+"&Resizable="+Resizable,"WinPreview","menubar=no,personalbar=no,toolbar=no,resizable="+Resizable+",width="+WinWidth+",height="+WinHeight+",scrollbars="+ScrollBars+","+ScreenX+","+ScreenY);
}
function get_html_translation_table(table, quote_style) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: noname
    // +   bugfixed by: Alex
    // +   bugfixed by: Marco
    // +   bugfixed by: madipta
    // +   improved by: KELAN
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // %          note: It has been decided that we're not going to add global
    // %          note: dependencies to php.js. Meaning the constants are not
    // %          note: real constants, but strings instead. integers are also supported if someone
    // %          note: chooses to create the constants themselves.
    // *     example 1: get_html_translation_table('HTML_SPECIALCHARS');
    // *     returns 1: {'"': '&quot;', '&': '&amp;', '<': '&lt;', '>': '&gt;'}
    
    var entities = {}, histogram = {}, decimal = 0, symbol = '';
    var constMappingTable = {}, constMappingQuoteStyle = {};
    var useTable = {}, useQuoteStyle = {};
    
    // Translate arguments
    constMappingTable[0]      = 'HTML_SPECIALCHARS';
    constMappingTable[1]      = 'HTML_ENTITIES';
    constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
    constMappingQuoteStyle[2] = 'ENT_COMPAT';
    constMappingQuoteStyle[3] = 'ENT_QUOTES';
 
    useTable       = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
    useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
 
    if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
        throw new Error("Table: "+useTable+' not supported');
        // return false;
    }
 
    if (useTable === 'HTML_ENTITIES') {
        entities['160'] = '&nbsp;';
        entities['161'] = '&iexcl;';
        entities['162'] = '&cent;';
        entities['163'] = '&pound;';
        entities['164'] = '&curren;';
        entities['165'] = '&yen;';
        entities['166'] = '&brvbar;';
        entities['167'] = '&sect;';
        entities['168'] = '&uml;';
        entities['169'] = '&copy;';
        entities['170'] = '&ordf;';
        entities['171'] = '&laquo;';
        entities['172'] = '&not;';
        entities['173'] = '&shy;';
        entities['174'] = '&reg;';
        entities['175'] = '&macr;';
        entities['176'] = '&deg;';
        entities['177'] = '&plusmn;';
        entities['178'] = '&sup2;';
        entities['179'] = '&sup3;';
        entities['180'] = '&acute;';
        entities['181'] = '&micro;';
        entities['182'] = '&para;';
        entities['183'] = '&middot;';
        entities['184'] = '&cedil;';
        entities['185'] = '&sup1;';
        entities['186'] = '&ordm;';
        entities['187'] = '&raquo;';
        entities['188'] = '&frac14;';
        entities['189'] = '&frac12;';
        entities['190'] = '&frac34;';
        entities['191'] = '&iquest;';
        entities['192'] = '&Agrave;';
        entities['193'] = '&Aacute;';
        entities['194'] = '&Acirc;';
        entities['195'] = '&Atilde;';
        entities['196'] = '&Auml;';
        entities['197'] = '&Aring;';
        entities['198'] = '&AElig;';
        entities['199'] = '&Ccedil;';
        entities['200'] = '&Egrave;';
        entities['201'] = '&Eacute;';
        entities['202'] = '&Ecirc;';
        entities['203'] = '&Euml;';
        entities['204'] = '&Igrave;';
        entities['205'] = '&Iacute;';
        entities['206'] = '&Icirc;';
        entities['207'] = '&Iuml;';
        entities['208'] = '&ETH;';
        entities['209'] = '&Ntilde;';
        entities['210'] = '&Ograve;';
        entities['211'] = '&Oacute;';
        entities['212'] = '&Ocirc;';
        entities['213'] = '&Otilde;';
        entities['214'] = '&Ouml;';
        entities['215'] = '&times;';
        entities['216'] = '&Oslash;';
        entities['217'] = '&Ugrave;';
        entities['218'] = '&Uacute;';
        entities['219'] = '&Ucirc;';
        entities['220'] = '&Uuml;';
        entities['221'] = '&Yacute;';
        entities['222'] = '&THORN;';
        entities['223'] = '&szlig;';
        entities['224'] = '&agrave;';
        entities['225'] = '&aacute;';
        entities['226'] = '&acirc;';
        entities['227'] = '&atilde;';
        entities['228'] = '&auml;';
        entities['229'] = '&aring;';
        entities['230'] = '&aelig;';
        entities['231'] = '&ccedil;';
        entities['232'] = '&egrave;';
        entities['233'] = '&eacute;';
        entities['234'] = '&ecirc;';
        entities['235'] = '&euml;';
        entities['236'] = '&igrave;';
        entities['237'] = '&iacute;';
        entities['238'] = '&icirc;';
        entities['239'] = '&iuml;';
        entities['240'] = '&eth;';
        entities['241'] = '&ntilde;';
        entities['242'] = '&ograve;';
        entities['243'] = '&oacute;';
        entities['244'] = '&ocirc;';
        entities['245'] = '&otilde;';
        entities['246'] = '&ouml;';
        entities['247'] = '&divide;';
        entities['248'] = '&oslash;';
        entities['249'] = '&ugrave;';
        entities['250'] = '&uacute;';
        entities['251'] = '&ucirc;';
        entities['252'] = '&uuml;';
        entities['253'] = '&yacute;';
        entities['254'] = '&thorn;';
        entities['255'] = '&yuml;';
    }
 
    if (useQuoteStyle !== 'ENT_NOQUOTES') {
        entities['34'] = '&quot;';
    }
    if (useQuoteStyle === 'ENT_QUOTES') {
        entities['39'] = '&#39;';
    }
    entities['60'] = '&lt;';
    entities['62'] = '&gt;';
 
    // ascii decimals for better compatibility
    entities['38'] = '&amp;';
 
    // ascii decimals to real symbols
    for (decimal in entities) {
        symbol = String.fromCharCode(decimal);
        histogram[symbol] = entities[decimal];
    }
    
    return histogram;
}
function html_entity_decode( string, quote_style ) {
    // http://kevin.vanzonneveld.net
    // +   original by: john (http://www.jd-tech.net)
    // +      input by: ger
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +   improved by: marc andreu
    // +    revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +    bugfixed by: Brett Zamir (http://brett-zamir.me)
    // -    depends on: get_html_translation_table
    // *     example 1: html_entity_decode('Kevin &amp; van Zonneveld');
    // *     returns 1: 'Kevin & van Zonneveld'
    // *     example 2: html_entity_decode('&amp;lt;');
    // *     returns 2: '&lt;'
 
    var histogram = {}, symbol = '', tmp_str = '', entity = '';
    tmp_str = string.toString();
    
    if (false === (histogram = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
        return false;
    }
 
    for (symbol in histogram) {
        entity = histogram[symbol];
        tmp_str = tmp_str.split(entity).join(symbol);
    }
    tmp_str = tmp_str.split('&#039;').join("'");
    
    return tmp_str;
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
