function checkDate(dd, mm, yy)
{
	var date;
	var d, m;
	var b;
	if(dd > 28)
	{
		d = 28;
		b = false;
		if(mm.charAt(0) == "0")
			m = parseInt(mm.charAt(1)) - 1;
		else
			m = parseInt(mm) - 1;
		date = new Date(2000 + parseInt(yy), m, d);
		while((date.getMonth() == m) && (!b))
		{
			d++;
			date.setDate(d);
			if(date.getDate() == dd)
				b = true;
		}
	}
	else
		b = true;
	return b;
}



function compareTimes(dd1, mm1, yy1, hh1, mn1, dd2, mm2, yy2, hh2, mn2)
{
	var n1, n2;
	var s1, s2;
	s1 = "20" + yy1 + mm1 + dd1 + hh1 + mn1;
	s2 = "20" + yy2 + mm2 + dd2 + hh2 + mn2;
	n1 = parseInt(s1);
	n2 = parseInt(s2);
	if(n1 < n2)
		return -1;
	else
	{
		if(n1 > n2)
			return 1;
		else
			return 0;
	}
}


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.\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);
  else
  	{
		if(!checkDate(document.forms[0].elements[4].value, document.forms[0].elements[5].value, document.forms[0].elements[6].value))
		{
			errors = "Data di scadenza non valida";
			alert(errors);

		}
	}
  document.MM_returnValue = (errors == '');
}



function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function toggle( targetId ){
  if (document.getElementById){
  		target = document.getElementById( targetId );
  			if (target.style.display == "none"){
  				target.style.display = "block";
  			} else {
  				target.style.display = "none";
  			}
  	}
}

function new_window(url) {
link=window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=560,height=500")
}

function new_window2(url) {
link=window.open(url,"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=500,height=400")
}

function right(e) {
if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("Spiacenti, il tasto destro del mouse e' disabilitato");
return false;
}
return true;
}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;

