var sito_title = 'ILPA - ILIP'
var sito_url = 'http://www.ilip.it'

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number (no symbols and no blank spaces).\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}



//defult status
defaultStatus = sito_title

// tira fuori dal frameset
setTimeout ("Killer()", 0);
function Killer()
    {
    if (self.parent.frames.length != 0)
    if (self.parent.location != document.location)
    {self.parent.location=document.location};
}

// javascript:PopUPThis('imm/1.jpg');
function PopUPThis(img) {
	var fpop = window.open("","nome","width=100,height=100,menubar=no,toolbar=no,resizable=no,scrollbars=no");
	fpop.document.write('<html>\n');
	fpop.document.write('<head>\n');
	fpop.document.write('<title>' + sito_title + '</title>\n');  
	fpop.document.write('</head>\n');
	fpop.document.write('<script language=\'JavaScript\' type="text/javascript">\n');  
	fpop.document.write('function fitPic() {\n');  
	fpop.document.write('	var NS = (navigator.appName=="Netscape")?true:false;\n');
	fpop.document.write('	iWidth  = (NS)?window.innerWidth:document.body.clientWidth;\n');
	fpop.document.write('	iHeight = (NS)?window.innerHeight:document.body.clientHeight;\n');  
	fpop.document.write('\n');
	fpop.document.write('	var l = Math.floor((screen.availWidth  - document.images[0].width)/2);\n');
	fpop.document.write('	var a = Math.floor((screen.availHeight - document.images[0].height)/2);\n');
	fpop.document.write('\n');
	fpop.document.write('	iWidth  = document.images[0].width  - iWidth;\n');
	fpop.document.write('	iHeight = document.images[0].height - iHeight;\n');
	fpop.document.write('	window.resizeBy(iWidth, iHeight-1);\n');
	fpop.document.write('\n');
	fpop.document.write('	window.moveTo(l, a);\n');
	fpop.document.write('\n');
	fpop.document.write('	self.focus();\n');
	fpop.document.write('}\n');	
	fpop.document.write('</script>\n');
	fpop.document.write('<body style="margin:0px;" onLoad="fitPic();">\n');  
	fpop.document.write('<a href="javascript:self.close()" title="x"><img src="' + img + '" border="0" galleryimg="no" alt=""></a>\n');  
	fpop.document.write('</body>\n');
	fpop.document.write('</html>\n');
	fpop.document.close();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// *********


// indici vuoti con funzionalita' tutti all'inizio di ogni combo
var ind_s = 1;



function upd_v1(box) {

		var number = box.selectedIndex;
		if (box.options[number].value != '') {
			number = number + 1 - ind_s;
		} else {
			number = '';
		}
		
		var list = eval('v2_' + document.getElementById('IDA').value + '_' + number);
		var box  = document.getElementById('v2');

		popola_cb(list, box);
		
		upd_v2(box);

}


function upd_v2(box) {
	
	if (document.getElementById('v3')) {

		var number = box.selectedIndex;
		if (box.options[number].value != '') {
			number = number + 1 - ind_s;
		} else {
			number = '';
		}
		
		var n_v1 = document.getElementById('v1').selectedIndex;
		if (document.getElementById('v1').options[n_v1].value != '') {
			n_v1 = n_v1 + 1 - ind_s;
			n_v1 = n_v1 ;
		} else {
			n_v1 = '0';
		}
				
		var list = eval('v3_' + document.getElementById('IDA').value + '_' + n_v1 + '_' + number);
		var box  = document.getElementById('v3');

		popola_cb(list, box);
		
		upd_v3(box);
	
	}

}


function upd_v3(box) {
	
	if (document.getElementById('v4')) {

		var number = box.selectedIndex;
		if (box.options[number].value != '') {
			number = number + 1 - ind_s;
		} else {
			number = '';
		}
		
		var n_v1 = document.getElementById('v1').selectedIndex;
		if (document.getElementById('v1').options[n_v1].value != '') {
			n_v1 = n_v1 + 1 - ind_s;
			n_v1 = n_v1 ;
		} else {
			n_v1 = '0';
		}
		
		var n_v2 = document.getElementById('v2').selectedIndex;
		if (document.getElementById('v2').options[n_v2].value != '') {
			n_v2 = n_v2 + 1 - ind_s;
			n_v2 = n_v2 ;
		} else {
			n_v2 = '0';
		}
				
		var list = eval('v4_' + document.getElementById('IDA').value + '_' + n_v1 + '_' + n_v2 + '_' + number);
		var box  = document.getElementById('v4');

		popola_cb(list, box);
	
	}

}


function popola_cb(list, box) {

	box.options.length = 0;
	if (list.length > 0) {
		for(i=0;i<ind_s;i+=1) {
			box.options[i] = new Option((i==0?txt_all:''),'');
		}
		for(i=ind_s;i<(list.length+ind_s);i+=1) {
			var lar = list[i-ind_s].split("#-#");
			box.options[i] = new Option(lar[0],lar[1]);
		}
	}	else {
		box.options[0] = new Option('Tutti','');
	}

}


function sel_val(tid, valore) {
	
	var obj = document.getElementById(tid);
	
	for (var i = 0; i < obj.length; i++) {
		if (obj.options[i].value == valore) {
			obj.options[i].selected = true;
		}
	}
	
}

function hide(a) {
	if(document.getElementById(a)) document.getElementById(a).style.display = 'none';	
}

