// controlli locali 
//
var NN4=(document.layers);
var IE4=(document.all);
//...................... controllo che il campo non sia vuoto
function isblank(s)
   {
    for(var i = 0; i < s.value.length; i++)
     {
        var c = s.value.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
     }
        return true;
    }
//...................... controllo che il campo contenga  '@'
function isNoMail(s)
   {
    for(var i = 0; i < s.value.length; i++)
     {
        var c = s.value.charAt(i);
        if (c == '@') return false;
     }
        return true;
    }
//...................... controllo che siano solo numeri
function isNotNumeric(s,flag_obblig)
{
   	var a;
   	do 	{
   		a = s.value.indexOf(" ",0);
   		if (a !=-1)
   			s.value = s.value.substring(0,a) + s.value.substring(a+1,s.value.length);
   	} while (a != -1);
   
   if (s.value.length == 0 && flag_obblig==true)
   		return true;
   	   
   for(var i = 0; i < s.value.length; i++)
	{
        var c = s.value.charCodeAt(i);
        var b = s.value.charAt(i);

        if (b == ' ')
         	return true
		 else
        	if ((c < 48)||(c > 57)) return true;
	}
    return false;
}


function isDate(s)
{
   	var a;
        separatore = new Array(30);
        var x = 0;
        var giorno;
        var mese;
        var anno;
        var ritorno =true;
        // tolgo i caratteri blank dallinerno della string
   	do 	{
   		a = s.indexOf(" ",0);
   		if (a !=-1)
   			s.value = s.value.substring(0,a) + s.value.substring(a+1,s.value.length);
   	} while (a != -1);
   //se rimane una stringa di lung. zero ritorno false
   if (s.length == 0)
   		ritorno = false;
   	
   for(var i = 0; i < s.length; i++)
	{
        var c = s.charCodeAt(i);
        var b = s.charAt(i);

           	if ((c < 48)||(c > 57)){
                    separatore[x]=i;
                    x=x+1; 
                 }
	}
    if (x != 0) {
       if (x != 2) {
          ritorno = false;
         }
       else {
       giorno=s.substring(0,separatore[0]); 
       mese=s.substring(separatore[0]+1,separatore[1]);
       anno=s.substring(separatore[1]+1,s.length);
        }
     }
    else {
       switch(s.length){
       case 6 :
          giorno=s.substring(0,2); 
          mese=s.substring(2,4);
          anno=s.substring(4,6);
          break;
       case 8 :
          giorno=s.substring(0,2); 
          mese=s.substring(2,4);
          anno=s.substring(4,8);
          break;
       default :
           ritorno = false;
       }// end switch   
      } // end if
  
  // verifico che non ci siano stringhe vuote dopo il parsing
  if (giorno=="") 
      ritorno=false;
  if (anno=="")
     ritorno=false;
  if (mese=="")
     ritorno=false
  
  if ((parseInt(giorno)>31) || (parseInt(giorno)<1)){
        ritorno = false;
        //alert ("giorno sbagliato");
        }
  if ((parseInt(mese)<1) || (parseInt(mese)>12)){
        ritorno = false;
        //alert ("mese sbagliato");
        }
  switch (parseInt(mese)){
     case 4,6,9,11:
          if (giorno>30){
            ritorno=false;
          //alert ("mese e giorni non coerenti");
          } 
          break;
     case 2:
        if ((parseInt(anno)/4) == Math.floor(parseInt(anno)/4)) {
            if (parseInt(giorno)>29){
                //alert ("bisest");
                ritorno=false;}
            } 
        else { 
            if (parseInt(giorno)>28){
               //alert ("no bisest");
               ritorno=false;}
        }
    }// end switch
  if (ritorno==true) {
    if (parseInt(anno)<35)  
           anno="20"+anno;
        else
           anno="19"+anno;
    if (mese.length<2) 
       mese="0"+mese; 

    if (giorno.length<2) 
       giorno="0"+giorno;  
   }// end if
  if (ritorno == false) {
//     alert("false");
     return false;
     }
   else {
//     alert ("true");
     return "data:" + giorno + "/" + mese + "/" + anno;
    }
}

function show_error(allErr)
 {
   var msg =  "_____________________________________________________________\n\n";
   msg += "Il modulo non è stato accettato a causa di errori.\n";
   msg += "Si prega di correggere e rieseguire.\n";
   msg += "_____________________________________________________________\n\n";
   msg += allErr;
   alert(msg); 
   }

//controllo data a partire dai numeri di anno,mese,giorno
function check_data(anno,mese,giorno) {

  var ritorno;

  anno = parseInt(anno);
  mese = parseInt(mese);
  giorno = parseInt(giorno);

  if (giorno==0) return false;

  ritorno = true;

  switch (mese){
     case 1:
     case 3:
     case 5:
     case 7:
     case 8:
     case 10:
     case 12:
          if (giorno>31){
            ritorno = false;
          }
          break;
     case 4:
     case 6:
     case 9:
     case 11:
          if (giorno>30){
            ritorno = false;
          } 
          break;
     case 2:
        if ((anno/4) == Math.floor(anno/4)) {
          if (giorno>29){
            ritorno = false;
          }
        }
        else { 
          if (parseInt(giorno)>28){
            ritorno = false;
          }
        }
  }

  return ritorno;
}
