/*
function setAction(act_name)
{
	var action = window.document.forms[0].action;
	action = action + '&action=' + act_name;
	window.document.forms[0].action = action;
	window.document.forms[0].action.value = act_name;
	window.document.forms[0].submit();
}


function opendoor()
{
	var passwd = '';
	passwd = getParameter('mypasswd');
	if (passwd == 'css_strutture'){
		window.document.forms[0].action += '&mypasswd=css_strutture';
	}
	window.document.forms[0].submit();
}
*/

function setAction(act_name)
{
	window.document.forms[0].action = 'index.php?' + setParameter('action', act_name);
	window.document.forms[0].action.value = act_name;
	window.document.forms[0].submit();
}


/**
 * Pesca un parametro dalla query string dell'URL
 * @param whichOne il parametro
 * @return il valore associato al parametro
 */
function getParameter(whichOne) {
  var pairs = location.search.substring(1).split('&');
  var r = "";
  var tp = new Array();
  for (var i = 0; i < pairs.length; i ++) {
    tp = pairs[i].split('=');
    if (whichOne == tp[0])
      r = unescape(tp[1].replace(/\+/g, " "));
  }
  return r;
}


/**
 * Ritorna i nomi di tutti parametri della query string
 * @return l'array contenente i nomi dei parametri
 */
function getParameterNames() {
  var ar = location.search.substring(1).split('&');
  for (var i = 0; i < ar.length; i++) {
    ar[i] = ar[i].substring(0, ar[i].indexOf('='));
  }
  return ar;
}


/**
 * Genera una nuova query string updatando il parametro passato
 * @param thePar il parametro
 * @param theValue il valore da assegnare
 * @return la stringa contenente la query string completa
 */
function setParameter(thePar, theValue) {
  var pc = "";
  var pa = getParameterNames();
  for (var i = 0; i < pa.length; i++) {
    if (pa[i] != thePar) {
      pc += "&" + pa[i] + "=" + getParameter(pa[i]);
    }
  }
  pc += "&" + thePar + "=" + escape(theValue);
  return pc.substring(1);
}

function displayElement(target,onoff)
{
   obj=(document.all) ? document.all[target] : document.getElementById(target);
   obj.style.display = onoff;
}


function toggleDisplayElement(target)
{
    obj=(document.all) ? document.all[target] : document.getElementById(target);
    obj.style.display=(obj.style.display=='none') ? '' : 'none';
}


function setImgLocation(target)
{
	obj=(document.all) ? document.all[target] : document.getElementById(target);
	img_target = target +'_img';
	obj_img = (document.all) ? document.all[img_target] : document.getElementById(img_target);
	if (obj.style.display=='none'){
		obj_img.src = 'images/fap_FFF.gif';
	}
	else {
		obj_img.src = 'images/fsu_FFF.gif';
	}
}


function setVisibility(target)
{
	toggleDisplayElement(target);
	setImgLocation(target);
}


function toggleDisplayDetails(target)
{
	target1 = 'ahref' + target;
	target2 = 'div' + target;
	target3 = 'dfc' + target;
	toggleDisplayElement(target1);
	toggleDisplayElement(target2);
	toggleDisplayElement(target3);
}


function toggleDisplayElementGen(target1, target2, cachefield)
{
    mycache_obj = (document.all) ? document.all[cachefield] : document.getElementById(cachefield);
    target = mycache_obj.value;
    toggleDisplayElement(target);
}


function setTurnOffOn(target1, target2, cachefield)
{
	mycache_obj = (document.all) ? document.all[cachefield] : document.getElementById(cachefield);
	if (mycache_obj.value == target1) mycache_obj.value = target2;
	else mycache_obj.value = target1;
	
	obj1 = (document.all) ? document.all[target1] : document.getElementById(target1);
	obj2 = (document.all) ? document.all[target2] : document.getElementById(target2);
	
	obj1.style.display = (obj1.style.display=='none') ? '' : 'none';
	obj2.style.display = (obj2.style.display=='none') ? '' : 'none';
}


function setImgLocationGen(targetris, cachefield)
{
	mycache_obj = (document.all) ? document.all[cachefield] : document.getElementById(cachefield);
	target = mycache_obj.value;
	obj = (document.all) ? document.all[target] : document.getElementById(target);
	img_target = targetris +'_img';
	obj_img = (document.all) ? document.all[img_target] : document.getElementById(img_target);
	if (obj.style.display=='none'){
		obj_img.src = 'images/fap_FFF.gif';
	}
	else {
		obj_img.src = 'images/fsu_FFF.gif';
	}
}


function setOpenClose(target1, target2, cachefield)
{
	toggleDisplayElementGen(target1, target2, cachefield);
	setImgLocationGen(target1, cachefield);
	toggleDisplayElement(target2 + '_img');
}



function openPopup(url_to_open, title) {
   var w = 800;
   var h = 600;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
   window.open(url_to_open, title, "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
   window.open(this.href, title, 'scrollbars,resizable,menubar,toolbar,directories,location,status,width=' + w + ',height=' + h + ',top=' + t + ',left=' + l);
   return false;
}
