function getPage(thePage){
	
	document.mainform.azione.value="getpage";
	document.mainform.subaction.value="";
	document.mainform.mainpage.value=thePage;

	document.mainform.submit();
}
function setLabel(label,text){
	f=getElement(label)
	f.innerHTML=text;
}
function getLabel(label){
	var f=getElement(label);
	return f.innerHTML;
}
function truncate(num) {
	string = "" + num;
	if (string.indexOf('.') == -1)
	return string + '.00';
	seperation = string.length - string.indexOf('.');
	if (seperation > 3)
	return string.substring(0,string.length-seperation+3);
	else if (seperation == 2)
	return string + '0';
	return string;
} 
function getFieldValue(field){
	f=getElement(field);
	if (f==null) return 0;
	if (f.tagName=="LABEL")
		return f.innerHTML;
	else
		return f.value;
}
function updateField(field,valore){//,fieldname,theobj
	f=getElement(field)
	if (f.tagName=="LABEL")
		f.innerHTML=valore;
	else
		f.value=valore;
}
function setcheck(obj){
	//alert (obj.checked);

	if (obj.checked) obj.value="1";
	else obj.value="";
	//alert (obj.value);

}
function testCall(){
	alert("CALLED");
}
function getElement(psID) {
	var obj;
   if(document.all) {
      return document.all[psID];
   } else {
      return document.getElementById(psID);
   }
} 
function getItem(idkitem,thePage){
	document.mainform.azione.value=thePage;
	document.mainform.idk_item.value=idkitem;
	document.mainform.subaction.value="getitem";
	document.mainform.mainpage.value=thePage;
	document.mainform.submit();
}
function deleteItem(idkitem,tbaction){
	if (idkitem=="") return;
	var stbp=getElement('stato_bp');
	if (stbp.value=="readonly"){
		alert("Progetto in fase di valutazione!");
		return;
	}
	var resp=confirm ("vuoi cancellare l'elemento ?");
	if (!resp) return;
	document.mainform.azione.value=document.mainform.mainpage.value;
	document.mainform.idk_item.value=idkitem;
	document.mainform.subaction.value="deleteitem";
	document.mainform.tableaction.value=tbaction;
	
//	alert ("vuoi cancellare :" + idkitem);
	document.mainform.submit();
}
function logOut(azione){
	document.mainform.mainpage.value="";
	document.mainform.azione.value=azione;
	document.mainform.idbplan.value="";	
		document.mainform.submit();
}
function postData(azione){
		document.mainform.azione.value=azione;
		document.mainform.thepage.value=azione;
		document.mainform.submit();
}
function showInfo(page){
	var w=window.open("info.php?pg="+page,"info","height=540,width=600,status=yes, toolbar=no,menubar=no, location=no,scrollbars=yes,resizable=yes");
	w.focus();
}
function showPopup(pagina,parametri,titolo){
	window.open(pagina+"?"+parametri,titolo,"height=500,width=450,status=yes,toolbar=no,menubar=no,location=no");
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	//this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	//this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   //	this.style = document.layers[name];
  }
}
 function truncate(num) {
	string = "" + num;
	if (string.indexOf('.') == -1)
		return string + '.00';
	seperation = string.length - string.indexOf('.');
	if (seperation > 3)
		return string.substring(0,string.length-seperation+3);
	else if (seperation == 2)
		return string + '0';
	return string;
} 

function initpage(pg){
	if ('function' == typeof window.pageInit) {
   // use noFunc()
   			pageInit();
	 } else {
	   // do something else
	 }

	
}
function finBplan(id_bplan){
	document.mainform.idbplan.value=id_bplan;
	document.mainform.azione.value="selectbplan_finanz";
		document.mainform.mainpage.value="";
		document.mainform.lastselected.value="tree-1";
	document.mainform.submit()
}
function getBplan(id_bplan){
	document.mainform.idbplan.value=id_bplan;
	document.mainform.azione.value="selectbplan";
		document.mainform.mainpage.value="";
		document.mainform.lastselected.value="tree-1";
	document.mainform.submit();
}
function releaseBplan(id_bplan){
	document.mainform.idbplan.value=id_bplan;
	document.mainform.azione.value="releasebplan";
		document.mainform.mainpage.value="";
		document.mainform.lastselected.value="tree-1";
	document.mainform.submit();
}
function registrazione(){
	window.open("include/iscrizione.php?start=1","Iscrizione","height=500,width=600,status=yes,toolbar=no,menubar=no,location=no");
}
function printBP(iduser){
	if (iduser=="" || iduser==0){
		alert ("selezionare BP");
		return;
	}
	var theW=window.open("sezioni/print_bp.php?id_user="+iduser,"StampaBP","height=500,width=800,status=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes");
	theW.focus();
}
function finanzia(idbp){
	if (idbp==''){
		alert ("selezionare BP");
		return;
	}
	getPage('finanziamento.php');
}
function printSintesi(idbp,idente){
	if (idbp==''){
		alert ("selezionare BP");
		return;
	}
	var theW=window.open("valutazione/stampa_valutazione.php?idbp="+idbp+"&idente="+idente,"StampaValutazione","height=500,width=800,status=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes");
	theW.focus();
}
function selectProposta(idbp){
	var theW=window.open("finanziatore/dettaglio_proposta.php?idbp="+idbp,"Dettaglio","height=500,width=800,status=yes,menubar=yes,location=no,toolbar=no,scrollbars=yes,resizable=yes");
	theW.focus();
	
}
function selectFile(url){
	theW=window.open(url,"File","height=500,width=800,status=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes");
	theW.focus();
}

function proponente(idk,mode,idkp){
	var theW=window.open("sezioni/scheda_proponente.php?idk="+idk+"&mode="+mode+"&idbplan="+idkp,"Proponente","height=600,width=800,status=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
	theW.focus();
}



