function setDocumentAction(theForm){

  var actionSelected = theForm.paramDocumentAction.value;

  if (actionSelected == 'chronology'){
    theForm.action = "viewAppDocumentChronology.do";
  }else if (actionSelected == 'checkin'){
    theForm.action = "viewAppCheckInDocument.do";
  }else if (actionSelected == 'checkout'){
    theForm.action = "viewAppCheckOutDocument.do";
  }else if (actionSelected == 'unlock'){
    theForm.action = "unlockDocumentByUpdateDoc.do";
  }else{
    theForm.action = "appViewSearchDocument.do";
  }

  return;

}

function selectUserRow(userId) {
  document.location = "selectUserRow.do?rowId=" + userId;
}


function textCounter(field, countfield, limit) {
	if (field.value.length > limit) {
		field.value = field.value.substring(0, limit);
	}
	else {
		countfield.value = limit - field.value.length;
	}
}

function wrapLines(field, limit, prefix, suffix) {

/* Disabilitato 17 Ottobre 2003
	var newtext = "";
	var start = 0;
	var posBla = 0;
	var posRet = 0;
	var orig = field.value;
	var len = orig.length;
	var temp = "";

	while ((len - start) > limit) {
		//alert('start:' + start + ' - temp:' + temp + ' - posBla:' + posBla + ' - posRet:' + posRet);
		temp = orig.substring(start, start + limit);

		posRet = temp.lastIndexOf('\n');

		if (posRet != -1) {
			newtext += temp.substring(0, posRet + 1);
			start += posRet + 1;
			continue;
		}

		posBla = temp.lastIndexOf(' ');

		if (posBla != -1) {
			newtext += temp.substring(0, posBla + 1);
			newtext += '\n';
			start += posBla + 1;
		}
		else {
			newtext += temp;
			newtext += suffix;
			newtext += '\n';
			newtext += prefix;
			start += limit;
		}
	}

	newtext += orig.substring(start);

	field.value = newtext;
*/
}


/**
 * Funzione che si occupa di aprire una popup nel momento in cui
 * scade la sessione in modo da avvisare l'utente.
 */
function openSessionPopup(){
  var width = 500;
  var height = 200;
  if (document.all) {
    var x = window.screenLeft;
    var y = window.screenTop;
    var w = window.document.body.offsetWidth;
    var h = window.document.body.offsetHeight;
  } else {
    var x = window.screenX;
    var y = window.screenY;
    var w = window.outerWidth;
    var h = window.outerHeight;
  }

  var cntx = x + Math.round((w - width) / 2);
  var cnty = y + Math.round((h - height) / 2);

  var queryStr = "sessionExpiration.do?show=Y";
	var param = "titlebar=no,width="+width+",height="+height+",top="+cnty+",left="+cntx+",menubar=no,toolbar=no,resizable=no,scrollbars=no,dependent=yes";
	openPopup(queryStr, 'sessionExpirationPopup', param);
}

/**
 * Funzioni per il logout sulla chiusura del browser
 * AL MOMENTO solo in Explorer
 */
function ConfirmClose() {
 if (event.clientY < 0 && myclose == false) {
        //event.returnValue = 'Messaggio';
        setTimeout('myclose=false',100);
        myclose=true;
    }
}

function HandleOnClose() {
 if (myclose==true) {
     document.location="logout.do";
     //alert("Window is closed");
 }
}

function openPopupMyProfile() {
  var queryString = "goToUpdateProfile.do";
  var titlePopup = "updateProfile";
  var param = "width=800,height=600,menubar=no,toolbar=no,resizable=yes,scrollbars=yes";

  openPopup(queryString, titlePopup, param);
}

function openPopupAdminProfile() {
  var queryString = "goToUpdateAdminProfile.do";
  var titlePopup = "updateAdminProfile";
  var param = "width=800,height=600,menubar=no,toolbar=no,resizable=yes,scrollbars=yes";

  openPopup(queryString, titlePopup, param);
}

function openPopupMyPassword() {
  var queryString = "goToUpdatePassword.do";
  var titlePopup = "updatePassword";
  var param = "width=400,height=300,menubar=no,toolbar=no,resizable=yes,scrollbars=yes";

  openPopup(queryString, titlePopup, param);
}

function openPopupAdminPassword() {
  var queryString = "goToUpdateAdminPassword.do";
  var titlePopup = "updateAdminPassword";
  var param = "width=800,height=600,menubar=no,toolbar=no,resizable=yes,scrollbars=yes";

  openPopup(queryString, titlePopup, param);
}

function openPopupAbout() {
  var queryString = "about.do";
  var titlePopup = "About";
  var param = "width=520,height=640,menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=10,top=10";

  openPopup(queryString, titlePopup, param);
}

function openPopupBarcode() {
  var queryString = "printBarcode.do";
  var titlePopup = "printBarcode";
  var param = "width=200,height=200,menubar=no,toolbar=no,resizable=no,scrollbars=no,left=10,top=10";

  openPopup(queryString, titlePopup, param);
}

function openPopupWatermarkDocument() {
	  var queryString = "watermarkDocument.do";
	  var titlePopup = "Anteprima documento";
	  var param = "width=800,height=600,menubar=no,toolbar=no,resizable=no,scrollbars=yes,left=10,top=10";

	  openPopup(queryString, titlePopup, param);
}

function openPopup(queryString, titlePopup, param) {
	var win = window.open(queryString, titlePopup, param);
	if (window.focus) {win.focus()}
}

/*
Funzione JS per la selezione delle righe in una tabella.
Come parametri vengono passati:
Id della tabella
Eventuale URL da invocare sul click della riga
Eventuale nome del parametro con il quale identificare l'id della riga
*/
function highlightTableRows(tableId, baseURL, paramName) {
    var previousClass = null;
    var table = document.getElementById(tableId);
    var tbody = table.getElementsByTagName("tbody")[0];
    var rows = tbody.getElementsByTagName("tr");
    for (i=0; i < rows.length; i++) {
        if (rows[i].id != ''){
	        rows[i].onmouseover = function() { 
	        	previousClass=this.className;
	        	this.className='onMouseOver';
	       	};
	        rows[i].onmouseout = function() { this.className=previousClass };
	        if (baseURL != '' && paramName != ''){
		        rows[i].onclick = function() {
		            var link = baseURL + '?'+paramName+'=' + this.id;
		            location.href = link;
			}
		}
    }
  }
}

function reloadGroup(obj){
	 
	var selectedGroup = document.getElementById("groupSelection").value;
	if (selectedGroup!=null&&selectedGroup!=''&&selectedGroup!="") {
		document.location = "changeGroup.do?groupId="+selectedGroup;
	}
} 



