/*Pico Script per visualizzazione link in nuova finestra*/
/*Pico Script per esplosione delle form della ricerca avanzata*/
function changeLabelNbsp( obj, labelValue ) {
	var spanElem;
	obj.innerHTML = '&nbsp;' + labelValue;
}


function changeLabel( obj, labelValue ) {
  var browser = navigator.userAgent.toLowerCase();
  if (browser.indexOf("opera 8") == -1 ) {
     obj.innerHTML = labelValue;
  }
}
 

 	function isNum(obj) {
		if (isNaN(obj.value) || parseInt(obj.value) < 0 || parseInt(obj.value) > 9999) {
			alert("Nel campo e' possibile immettere solo numeri!");
			obj.value="";
			obj.focus();
		}
		return true;
	}

	function controllaForm(frm){
		
		new_win = "tcom";
		frm.target = new_win;
		window.open('',new_win);

		return true;
	}
	
	function setField(q,v){
		if (document.getElementById(q)) {
			document.getElementById(q).value = v;
		}
	}

	function zeroFill(q,z){
		q=String(q);
		while(q.length<z)q="0"+q;
		return q;
	}
	
	function setFormAbbDefault(){		
		now=new Date();
		now.setDate(now.getDate()+1);			//la data odierna diventa la data di domani	
		
		d=zeroFill(now.getDate(),2);
		m=zeroFill(now.getMonth()+1,2);
		Y=now.getFullYear();
		if(document.getElementById("datag")){
			setField("datag",d);
			setField("datam",m);
			setField("dataa",Y);
		}
	}
 
 
function intercetta() {
	var url="";
	for (var i=0; i<document.links.length; i++) {
		url=document.links[i].href;
		if(url.substring(0,7)!="mailto:"){
			url=url.split("'");
			url=url.join("\\'");
			
			/* CASO: blank non piu usato da rimuovere!*/
			if (document.links[i].className.indexOf('blank') != -1)  
				document.links[i].href="javascript:open_linkEsterno('"+url+"');";
				
			if (document.links[i].className.indexOf('linkEsterno') != -1)  
				document.links[i].href="javascript:open_linkEsterno('"+url+"');";
			
			if (document.links[i].className.indexOf('linkExt_amico') != -1){
				var params = "width=516,height=255,status=yes";
				document.links[i].href="javascript:open_linkEsterno('"+url+"', '"+params+"');";				
			}			
			if (document.links[i].className.indexOf('linkExt_print') != -1){
				var params = "width=660,menubar=yes,scrollbars=yes,resizable=yes,status=yes";
				document.links[i].href="javascript:open_linkEsterno('"+url+"', '"+params+"');";				
			}						
		}
	}
	
	if (document.getElementById("indexForm")) {
                nascondiDIV('indexForm');
	}

	if (document.getElementById("redationalForm")) {
                nascondiDIV('redationalForm');
	}

	if (document.getElementById("siteForm")) {
                nascondiDIV('siteForm');
	}
}

function open_linkEsterno(url, params){
	var o;
	if(params)
		o=window.open(url,'_blank', params);
	else
		o=window.open(url,'_blank');
	
	if(o==undefined){
		if(confirm("E' stata bloccata l'apertura della pagina in una nuova finestra:\n\n"+url+"\n\nVuoi aprire la pagina nella finestra corrente?"))document.location.href=url;
	}
}

function nascondiDIV( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

window.onload = intercetta;

