/*
	_library classes:
	$Revision: 1.9 $
*/

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
		cntfield.value = maxlimit - field.value.length;
}

/*	TRIM SPACES	*/
function trim(str)	{
	return str.replace(/^\s*|\s*$/g,"");
}

/*	JUMP MENU FOR FORM SELECT	*/
function jumpMenu(targ,selObj,restore)	{	//v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/*	FORM SUBMIT FROM JUMP MENU	*/
function jumpTo(formName,selObj,url)	{
	var myForm		= document.forms['' + formName + ''];
	var valUrl		= selObj.options[selObj.selectedIndex].value;
	myForm.action	= url + '.htm';
	myForm.submit();
}

function regExReplace(string,regEx,replacement) {
	var re = new RegExp(regEx, "gi");
	string = string.replace(re, replacement);
	return string;
}

IE4 = document.all;
function newConfirm(title,mess,icon,defbut,mods) {
   if (IE4) {
      icon		= (icon==0) ? 0 : 2;
      defbut	= (defbut==0) ? 0 : 1;
      retVal	= makeMsgBox(title,mess,icon,4,defbut,mods);
      retVal	= (retVal==6);
   }
   else {
      retVal = confirm(mess);
   }
   return retVal;
}

/**	FIREFOX & IE Search Engine	**/
function addEngine(uri, name, ext, cat)
{
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
        window.sidebar.addSearchEngine(uri+"/"+name+".src", uri+"/images/"+name+"."+ext, name, cat);
    } else {
        alert('Mozilla Firefox, Mozilla or Netscape 6 or later is needed to install the search plugin!');
    }
}

/*	Set width of Form Field	and add class	*/
function setFieldDim(maxWidthIE,maxWidthAlt,fieldName,styleClass,fieldType,fieldValue,mouseOver,mouseOut,onFocus,onChange)	{
	var i;
	if (navigator.appName.indexOf("Explorer")>=0) {
		if (maxWidthIE > 0)	{
			i = 'size="' + maxWidthIE + '"'
		} else {
			i = ''
		}
		addStyle	= styleClass
	} else  {
		if (maxWidthAlt > 0)	{
			i = 'size="' + maxWidthAlt + '"'
		} else {
			i = ''
		}
		addStyle	= ''
	}
	fieldType	= (fieldType)		? fieldType : "text";
	fieldValue	= (fieldValue)		? regExReplace(fieldValue,'"','&quot;') : "";
	fieldValue	= (fieldValue)		? ' value="' + fieldValue + '" ' : '';
	mouseOver	= (mouseOver)		? ' onMouseOver="' + mouseOver + '" ' : '';
	mouseOut	= (mouseOut)		? ' onMouseOut="' + mouseOut + '" ' : '';
	onFocus		= (onFocus)			? ' onFocus="' + onFocus + '"' : '';
	onChange	= (onChange)		? ' onChange="' + onChange + '" ' : '';
	styleClass	= (styleClass)		? ' class="' + styleClass + '" ' : "";
	finalField	= '<input type="' + fieldType + '" ' + fieldValue + ' name="' + fieldName + '" ' + i + '' + styleClass + '' + onFocus + '' + mouseOver + '' + mouseOut + '' + onChange + '>';
	//alert(finalField);
	//return finalField;
	document.write (finalField);
}
/*	Set width of Form Field	and add class for TextAreas	(open tag only)	*/
function setFieldDimTextArea(maxColsIE,maxRowsIE,maxColsAlt,maxRowsAlt,fieldName,styleClass,fieldValue,mouseOver,mouseOut,onFocus)	{
	var i;
	if (navigator.appName.indexOf("Explorer")>=0) {
		if (maxColsIE > 0)	{
			i = 'cols="' + maxColsIE + '"'
			y = 'rows="' + maxRowsIE + '"'
		} else {
			i = ''
			y = ''
		}
		addStyle	= (styleClass != '')	? ' class="' + styleClass + '" ' : '';
	} else  {
		if (maxColsAlt > 0)	{
			i = 'cols="' + maxColsAlt + '"'
			y = 'rows="' + maxRowsAlt + '"'
		} else {
			i = ''
			y = ''
		}
		addStyle	= ''
	}
	//fieldValue	= (fieldValue)		? '' + fieldValue + '' : "";
	mouseOver	= (mouseOver)		? ' onMouseOver="' + mouseOver + '" ' : "";
	mouseOut	= (mouseOut)		? ' onMouseOut="' + mouseOut + '" ' : "";
	onFocus		= (onFocus)			? ' onFocus="' + onFocus + '"' : "";
	finalField	= '<textarea name="' + fieldName + '" ' + i + ' ' + y + '' + addStyle + '' + onFocus + '' + mouseOver + '' + mouseOut + '>'	// + fieldValue + '</textarea>';
	return finalField;
	//document.write (finalField);
}

function changeBodyClass(cName)	{
	//alert('moh te cambio la classe in ' + cName);
	document.body.className	= 'noLoggedBox';
	document.getElementById('myBody').className	= 'noLoggedBox';
}

function changeClass(divID,cName)	{
	//alert('moh te cambio la classe in ' + cName);
	//document.body.className	= 'noLoggedBox';
	document.getElementById(divID).className	= cName;
}
/************************************

	Custom Alert Demonstration
	version 1.0
	last revision: 02.02.2005
	steve@slayeroffice.com

	Should you improve upon this source please
	let me know so that I can update the version
	hosted at slayeroffice.

	Please leave this notice in tact!
	http://slayeroffice.com/code/custom_alert/

	maurizio@more.it
	Last changes:
		added 2 more vars for the function: title & buttonText;
		now title and button can be customized too.
	For this changes, the check for "getElementById" was added in the function
	and patched for Macintosh.

************************************/
/*
if(document.getElementById) {
	window.alert = function(txt,title,buttonText) {
		createCustomAlert(txt,title,buttonText);
	}
} else {
	alertAlt(txt,title,buttonText);
}
*/


function theAlert(txt,title,buttonText) {
	var sysOp	= navigator.userAgent.toLowerCase();
	//if(document.getElementById) {
	if(document.getElementById && sysOp.indexOf('mac') == -1) {
		d = document;

		if(d.getElementById("modalContainer")) return;

		mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
		mObj.id = "modalContainer";
		mObj.style.height = d.documentElement.scrollHeight + "px";

		alertObj = mObj.appendChild(d.createElement("div"));
		alertObj.id = "alertBox";
		if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
		alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
		alertObj.style.visiblity="visible";

		if (title == '')	{
			title	= 'ERRORE';
		}
		h1 = alertObj.appendChild(d.createElement("h1"));
		h1.appendChild(d.createTextNode(title));

		msg = alertObj.appendChild(d.createElement("p"));
		msg.appendChild(d.createTextNode(txt));

		if (buttonText == '')	{
			buttonText	= 'Chiudi';
		}
		btn = alertObj.appendChild(d.createElement("a"));
		btn.id = "closeBtn";
		btn.appendChild(d.createTextNode(buttonText));
		btn.href = "#";
		btn.onclick = function() { removeCustomAlert();return false; }
	} else {
		alert(txt);
	}
}

function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}

function _changeOp(op)	{
	var myForm	= document.f2;
	myForm.pollGo.value	= op;
	//alert(myForm.pollGo.value);
	myForm.submit();
}

/***************************************
	Function Copy To ClipBoard
	http://www.krikkit.net/
***************************************/

function copy_clip(meintext){
 if (window.clipboardData)
   {

   // the IE-manier
   window.clipboardData.setData("Text", meintext);

   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape)
   {

   // dit is belangrijk maar staat nergens duidelijk vermeld:
   // you have to sign the code to enable this, or see notes below
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;

   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;

   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');

   // om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig   om het in op te slaan
   var str = new Object();
   var len = new Object();

   var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

   var copytext=meintext;

   str.data=copytext;

   trans.setTransferData("text/unicode",str,copytext.length*2);

   var clipid=Components.interfaces.nsIClipboard;

   if (!clip) return false;

   clip.setData(trans,null,clipid.kGlobalClipboard);

   }
   alert("Indirizzo del file copiato negli appunti!");
   //return false;
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

/**
 * enables highlight and marking of rows in data tables
 *
 */
function PMA_markRowsInit() {
    // for every table row ...
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += ' hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( ' hover', '' );
            }
        }
        // Do not set click events if not wanted
        if (rows[i].className.search(/noclick/) != -1) {
            continue;
        }
        // ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }

            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }

        // ... and disable label ...
        var labeltag = rows[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = rows[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
}
window.onload=PMA_markRowsInit;




ver		= parseInt(navigator.appVersion)
ie4		= (ver>3  && navigator.appName!="Netscape")?1:0
ns4		= (ver>3  && navigator.appName=="Netscape")?1:0
ns3		= (ver==3 && navigator.appName=="Netscape")?1:0


function _writeEmbedSound(soundFile)	{
	embeddedSound	= '';
	embeddedSound	+= '<BGSOUND id="soundEteams" LOOP=1 SRC="' + soundFile + '">';
	embeddedSound	+= '<EMBED NAME="soundEteams" SRC="' + soundFile + '"';
	embeddedSound	+= 'LOOP=FALSE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>';
 	document.write(embeddedSound);
}

function changeGroup(grp)	{
	var myForm		= document.kenderGrp;
	myForm.action	= 'groupChanger.htm';
	myForm.a.value	= grp;
	myForm.submit();
}

/**	**/
function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}
