// ****** HIDE OR SHOW A LAYER

function showhide(id){
if (document.getElementById)
	{
	obj = document.getElementById(id);
	if (obj.style.display == "none")
		{
		obj.style.display = "";
		} 
	else 
		{
		obj.style.display = "none";
		}
	}
};


function hide(id){
if (document.getElementById)
	{
	obj = document.getElementById(id);
	obj.style.display = "none";
	}
};

function show(id){
if (document.getElementById)
	{
	obj = document.getElementById(id);
	obj.style.display = "";
	}
};


function parhide(id){
if (parent.document.getElementById)
	{
	obj = parent.document.getElementById(id);
	obj.style.display = "none";
	}
};

function parshow(id){
if (parent.document.getElementById)
	{
	obj = parent.document.getElementById(id);
	obj.style.display = "";
	}
};



// ****** POPUP FUNCTION
function apri(cosa,dove,larg,alt)
{
var new_windows='';
new_windows = 'width='+larg+',height='+alt+',scrollbars=no';
window.open(cosa, dove, new_windows );
        };
        
// ****** CONFIRM FUNCTION
function confirm_dialog(message)
{
	return confirm(message)
};    

// ****** CHANGE OPTIONS OF A PAGE USING PREFIX AND OPTION SELECTED
function prefix_navigation(prefix,selection){
var URL = selection.options[selection.selectedIndex].value;
window.location.href = prefix+URL;
};  

// ****** COPY VALUE FUNCTION
function copy_value(frmname,fielda,fieldb)
{  
	formobj=document.forms[frmname];
	if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
	if(!formobj[fielda])	{alert("BUG: Il campo "+fielda+" non è definito");return;};
	if(!formobj[fieldb])	{alert("BUG: Il campo "+fieldb+" non è definito");return;};
/*	if (formobj[fielda].value!='') {*/
	if (formobj[fieldb].value!='') {if (confirm('Sostituire valori ?')){formobj[fieldb].value=formobj[fielda].value;}}
	else {formobj[fieldb].value=formobj[fielda].value;};
//}
}; 



// **** METTI ALLEGATI
function allega(frmname,divname,fielda,nrdoc,descstring)
{
	
		formobj=parent.document.forms[frmname];
		if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
		destfield=formobj[fielda];
		if(!destfield)	{alert("BUG: Il campo "+fielda+" non è definito");return;};
		destdiv=parent.document.getElementById(divname);
		if(!destdiv)	{alert("BUG: Il riquadro "+divname+" non è definito");return;};

		if (destfield.value.indexOf(','+nrdoc+',')==-1) 
			{
			if (formobj['allegaticount'].value==0) {destdiv.innerHTML=""};
			formobj['allegaticount'].value++;
			obj = parent.document.getElementById('alle'+nrdoc);
			if (!obj) 
				{destdiv.innerHTML=destdiv.innerHTML+descstring}
			else {parshow('alle'+nrdoc)}
			destfield.value=destfield.value+nrdoc+',';
			//document.getElementById("daalle"+nrdoc).innerHTML = '<table border="1" BORDERCOLOR="red"><TR><TD>'+document.getElementById("daalle"+nrdoc).innerHTML+'</TD></TR></table>';
			}
};


// **** TOGLI ALLEGATI.... 
function deallega(frmname,divname,fielda,nrdoc)
{
	formobj=self.document.forms[frmname];
	if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
		listfield=formobj[fielda];
		if(!listfield)	{alert("BUG: Il campo "+fielda+" non è definito");return;};
		listdiv=self.document.getElementById(divname);
		if(!listdiv)	{alert("BUG: Il riquadro "+divname+" non è definito");return;};
valore=listfield.value;
var reg = new RegExp(","+nrdoc+",")
listfield.value=valore.replace(reg,",");		
hide('alle'+nrdoc);
formobj['allegaticount'].value--;
if (formobj['allegaticount'].value==0) {listdiv.innerHTML="&#160;Nessun documento allegato"};

//var prova = self.document.getElementById("allesearch");
//alert(prova.getElementById("allelist") );

//alert(self.document.getElementById("daalle"+nrdoc).innerHTML );
};


// **** TOGLI ALLEGATI.... 
function deallegaNEW(frmname,divname,fielda,nrdoc)
{alert(document.alleserach.location);
		formobj=document.alleserach.forms[frmname];
		if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
		listfield=formobj[fielda];
		if(!listfield)	{alert("BUG: Il campo "+fielda+" non è definito");return;};
		listdiv=document.getElementById(divname);
		if(!listdiv)	{alert("BUG: Il riquadro "+divname+" non è definito");return;};

valore=listfield.value;
var reg = new RegExp(","+nrdoc+",")
listfield.value=valore.replace(reg,",");
hide('alle'+nrdoc);
formobj['allegaticount'].value--;

if (formobj['allegaticount'].value==0) {listdiv.innerHTML="&#160;Nessun documento allegato"};
};









// **** METTI ALLEGATI
function OLDallega(frmname,divname,fielda,nrdoc,descstring)
{
		formobj=top.document.forms[frmname];
		if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
		destfield=formobj[fielda];
		if(!destfield)	{alert("BUG: Il campo "+fielda+" non è definito");return;};
		destdiv=top.document.getElementById(divname);
		if(!destdiv)	{alert("BUG: Il riquadro "+divname+" non è definito");return;};

		if (destfield.value.indexOf(','+nrdoc+',')==-1) 
			{
				if (destdiv.innerHTML.indexOf("Nessun documento allegato")>-1) {destdiv.innerHTML=""};
			destdiv.innerHTML=destdiv.innerHTML+descstring;
			destfield.value=destfield.value+nrdoc+',';
			}
		
};


// **** TOGLI ALLEGATI.... NON va per la differenza " fra firefox e IE...
function OLD_deallega(frmname,divname,fielda,nrdoc)
{
		formobj=top.document.forms[frmname];
		if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
		listfield=formobj[fielda];
		if(!listfield)	{alert("BUG: Il campo "+fielda+" non è definito");return;};
		listdiv=top.document.getElementById(divname);
		if(!listdiv)	{alert("BUG: Il riquadro "+divname+" non è definito");return;};

valore=listfield.value;
var reg = new RegExp(","+nrdoc+",")
listfield.value=valore.replace(reg,",");

stringa=listdiv.innerHTML;
//alert(stringa);
var reg = new RegExp("<div id=alle"+nrdoc+".*</div>");
// /<(.*)>.*<\/\1>/
listdiv.innerHTML=stringa.replace(reg,"");
if (listdiv.innerHTML.length==0) {listdiv.innerHTML="&#160;Nessun documento allegato"};
};




// TUTTO MAIUSCOLO
function allup(frmname,fielda) {
	formobj=document.forms[frmname];
	if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;}
	if(!formobj[fielda])	{alert("BUG: Il campo "+fielda+" non è definito");return;}	
	if (formobj[fielda].value!='') {if (confirm('TRASFORMARE TUTTO IN MAIUSCOLO ?')){formobj[fielda].value=formobj[fielda].value.toUpperCase();}};
};

//tutto minuscolo
function alldown(frmname,fielda) {
	formobj=document.forms[frmname];
	if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;}
	if(!formobj[fielda])	{alert("BUG: Il campo "+fielda+" non è definito");return;}	
	if (formobj[fielda].value!='') {if (confirm('trasformare tutto in minuscolo ?')){formobj[fielda].value=formobj[fielda].value.toLowerCase();}};
};

//Tutte Le Prime Lettere Maiuscole
function firstallup(frmname,fielda){
	formobj=document.forms[frmname];
	if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;}
	if(!formobj[fielda])	{alert("BUG: Il campo "+fielda+" non è definito");return;}
	if (formobj[fielda].value!='') 
		{
			if (confirm('Trasformare Tutte Le Prime Lettere In Maiuscolo ?'))
				{
				myArray=formobj[fielda].value.split(" ");
				testo="";
				spac="";
				for (i=0;i<myArray.length; i++)
					{
					if (i!=0) {spac=" "};
					testo=testo+spac+myArray[i].substring(0,1).toUpperCase()+myArray[i].substring(1,myArray[i].length).toLowerCase();
					}
				formobj[fielda].value=testo
				}
		}
};

//Prima lettera. Maiuscola
function firstup(frmname,fielda){
	formobj=document.forms[frmname];
	if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;}
	if(!formobj[fielda])	{alert("BUG: Il campo "+fielda+" non è definito");return;}
	if (formobj[fielda].value!='') 
		{	
			if (confirm('Trasformare la prima lettera. La prima diventa maiuscola ?'))
				{			
				primo=1;
				testo="";
				lastc="";
				stringa=formobj[fielda].value;
				for (i=0;i<stringa.length; i++)
					{
					if (primo==1) {testo=testo+stringa.charAt(i).toUpperCase()}
					else {testo=testo+stringa.charAt(i).toLowerCase()};
	
					if (stringa.charAt(i)==" " && stringa.charAt(i-1)==".") {primo=1}
					else {primo=0};
					}
				formobj[fielda].value=testo
				}
		}
};

// ******** ONLOAD HANDLING

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
};

// ******** ONRESIZE HANDLING

function addResizeEvent(func) {
  var oldonresize = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function() {
      oldonresize();
      func();
    }
  }
};


// ******* SET A SINGLE VALUE OF A FORM
function setsinglevalue(frmname,fielda,valuea){
		formobj=document.forms[frmname];
		if(!formobj)	{alert("BUG: Il form "+frmname+" non è definito");return;};
		destfield=formobj[fielda];
		if(!destfield)	{alert("BUG: Il campo "+fielda+" non è definito");return;};
		destfield.value=valuea;
	}
;



	 
function hidepos(divfrom,corx,cory,divto) {
	hide(divfrom);
	hide(divto);
	};

function showpos(divfrom,corx,cory,divto) {
show(divfrom);
show(divto);	
position(divfrom,corx,cory,divto);
	};	
