String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

/*
function goPage(page)
{
	if (page != null)
	{
		path = _web + "?p="+page;
		location.href=path;
	}
}
*/
function goPage(page, sfx)
{
	if (page != null)
	{
		path = _web + "?p="+page;
		
		if (sfx != undefined)
			path += "&" + sfx;
		
		location.href=path;
	}
}

function unescapeText(txt)
{
	txt = txt.replace("&egrave;", "è");
	txt = txt.replace("&eacute;", "é");
	txt = txt.replace("&agrave;", "à");
	txt = txt.replace("&igrave;", "ì");
	txt = txt.replace("&ograve;", "ò");
	txt = txt.replace("&ugrave;", "ù");
	
	return txt;
}

function setMethod(method)
{
	document.forms[0].method.value = method;
	document.forms[0].submit();
}

function aggiornaLivello(selId, uid) {
	sel = document.getElementById(selId);
	levl = sel.options[sel.selectedIndex].value;

    var myData = {
        id: uid,
        lvl: levl
    }
    
    
 $.ajax({
   type: "POST",
   url:  _web+"/ajax/setlevel.php",
   data: myData,
   success: function(rmsg){
      msg = rmsg.split("|");
      alert(msg[1]);   }
 });
    
}

function aggiornaPassword(selId, uid) {
	sel = document.getElementById(selId);
	pawd = sel.value;
    
    var myData = {
        id: uid,
        pwd: pawd
    }
    
 $.ajax({
   type: "POST",
   url: _web+"/ajax/setpassword.php",
   data: myData,
   success: function(rmsg){
      msg = rmsg.split("|");
      alert(msg[1]);
      sel.value = "";   
   },
   error: function(XMLHttpRequest, textStatus, errorThrown) {
       alert(XMLHttpRequest.status + " " + XMLHttpRequest.statusText);
       
       
   }
 });

}

function aggiornaAbilitazione(selId, uid) {
	enab = 1;
	for (i=0; i < document.forms[0][selId].length; i++)
	{
		o = document.forms[0][selId][i];
		if (o.checked)
			enab = o.value;
	}
    
    var myData = {
        id: uid,
        enb: enab
    }

    
 $.ajax({
   type: "POST",
   url: _web+"/ajax/setenabled.php",
   data: myData,
   success: function(rmsg){
      msg = rmsg.split("|");
      alert(msg[1]);   }
 });
}

function setTab(tab)
{
	document.forms[0].selectedTab.value = tab;
}

function refreshTable(uid, pg) {

    var myData = {
        id: uid,
        page: pg
    };
    
 $.ajax({
   type: "POST",
   url:  _web+"/ajax/refreshtable.php",
   data: myData,
   success: function(rmsg){
        $("#tbl-" + uid + "-results").replaceWith(rmsg);   
   }
 });
    
}

