<!--

function IsLeapYear(Y) {
 if ( !(Y %4) && (Y %100) || !(Y %400) )
  return true;
 else
  return false;

}

/**************************************
 * Day Number To Week Day (Monday =0)
 */
function dntowd(DN)
   {
//   CALENDAR_ORIGIN = 2415021;
   CALENDAR_ORIGIN = 2415019;

   Temp = ((DN %7 + (CALENDAR_ORIGIN) %7 ) %7);
   if (Temp < 0) Temp += 7;

   return Temp;
   }

function datetodn(Year, Month, Day)
  {

/** JDN:        day 0: Monday -4713 (4714 BC) November 24 at 00:00 */
/**                    Astronomer's count begins at noon           */
//  CALENDAR_ORIGIN = 0;

/** GREG        day 0: (Gregorian) Friday 1582 October (16-1)      */
/**                    Not an astronomer's counting origin         */
//  CALENDAR_ORIGIN = 2299161;

/** MJDN:       day 0: Tuesday 1858 November 16 at 00:00           */
/**                    Astronomer's count also begins at 00:00 GMT */
//  CALENDAR_ORIGIN = 2400000;

/** J2000DN:    day 0: Saturday 2000 January 1 at 00:00       */
/**                    Astronomer's count begins at noon UTC  */
//  CALENDAR_ORIGIN = 2451545;

/** J1900DN:    day 0: 1900 January 1 at 00:00       */
//  CALENDAR_ORIGIN = 2415021;

/** Microsoft Compatible day 0: 1899 December 31 at 00:00 */
  CALENDAR_ORIGIN = 2415019;

  A = (Year+4800);
  B = Math.ceil((Month-14) /12);

  return Math.floor(((1461 * (A + B)) >> 2)
	 +((367 *(Month -2 -12*B)) /12 )
	 -(3 * Math.floor((A +100 + B) /100) >> 2)
	 +Day - 32075 -CALENDAR_ORIGIN) ;
  }

function dntodate(DN)
  {
  CALENDAR_ORIGIN = 2415019;

  DN = parseInt(DN);
  if (DN < 0 || isNaN(DN)) return "";

  A= Math.floor(DN + 68569 + CALENDAR_ORIGIN);
  B= Math.floor(Math.floor(A << 2 ) /146097);
  A -= Math.floor((146097 *B +3) >> 2);
  C= Math.floor((4000 *(A +1)) /1461001);
  A -= Math.floor((Math.floor(1461 *C) >> 2));
  A +=31;
  D= Math.floor((80 *A)/2447);
  Day= A- Math.floor((2447 *D) /80);
  A= Math.floor(D/11);
  /* if above D<11, A is set to 0 causing divide error: */
	if (A>0) Month= D +2 - Math.floor((12 / A));
	else Month= D +2;

  Year= 100 *(B -49) +C +A;

  return  Day + "/" + Month + "/" + Year;
  }


function CheckDate(a){
//	window.onerror=null // for all other strange errors
	var err=0
//        a=document.fff.datatxt.value

	if (a.length > 10) err=1
	if (a.substring(0,1) == '0') a = a.substring(1); 
	pos = a.indexOf("/");
        dd = parseInt(a.substring(0, pos))// day

	a = a.substring(pos+1)// '/'
	if (a.substring(0,1) == '0') a = a.substring(1); 

	pos = a.indexOf("/");
        mm = parseInt(a.substring(0, pos))// month

        yy = parseInt(a.substring(pos+1))// year
	//basic error checking

        if (isNaN(dd) || isNaN(mm) || isNaN(yy)) err = 1

	if (mm<1 || mm>12) err = 1
	if (dd<1 || dd>31) err = 1
	if (yy<0 || yy>9999) err = 1
	
	// year 2000 bug work around
	if (yy<100)
	{
		if (yy > 70) yy = yy + 1900;
			else yy = yy + 2000;
	}

	//advanced error checking

	// months with 30 days
	if (mm==4 || mm==6 || mm==9 || mm==11){
		if (dd==31) err=1
	}

	// february, leap year
	if (mm==2){
		// feb
		var g=parseInt((yy-1900)/4)
		if (isNaN(g)) {
			err=1
		}

		if (dd>29) err=1
		if (dd==29 && (((yy-1900)/4)!=parseInt((yy-1900)/4))) err=1
	}

	if (err==1){
                return -1;
	}
	else{
                return datetodn(yy, mm, dd);
	}

}



function numero(stringa){

		var cerca = "0123456789";
		var str = stringa;
		ok = true;
		if(str.length==0){ ok = false; }
		for(i=0; i<str.length; i++){
			
			for(k=0; k<cerca.length; k++){ 
				if(str.charAt(i)  == cerca.charAt(k)){ break; } 
			}
			if(k == cerca.length){ ok = false; break; }
										
		}
		return ok;
				
	}


function valuta(stringa){

		var cerca = "0123456789,.";
		var str = stringa;
		ok = true;
		if(str.length==0){ ok = false; }
		for(i=0; i<str.length; i++){
			
			for(k=0; k<cerca.length; k++){ 
				if(str.charAt(i)  == cerca.charAt(k)){ break; } 
			}
			if(k == cerca.length){ ok = false; break; }
										
		}
		return ok;
				
	}





//-->
