function IsDigit(strIntValue)
{
        var bIsDigit = true;
        for (i = 0; i < strIntValue.length;i++)
        {
                if (strIntValue.charCodeAt(i) < 48 || strIntValue.charCodeAt(i) > 57)
                {
                        bIsDigit = false;
                        break ;
                }
        }
        return bIsDigit;
}

function Convertit(unConverted)
{
	var i = 0  ;

	var Converted = String("") ;
	for(i=0;i<unConverted.length;i++)
	{
		if(unConverted.charAt(i)>='0' && unConverted.charAt(i)<='9')
		{
			Converted += unConverted.charAt(i) ;
		}			
			
	}
		
	//alert(Converted) ;
	return Converted ;
}

function EatExtraSpace(unConverted)
{
	var i = 0  ;
	var j=0 ;
	var lastnospc =unConverted.length-1 ;
	
	var Converted = String("") ;
	
	while(unConverted.charAt(i)==" ") 
			i++ ;
	
	for(j=0 ; j < unConverted.length;j++)
	{
		if(unConverted.charAt(j)!=" ")
			lastnospc = j ;
	}	
	//alert(unConverted.substring(i,lastnospc)) ;
	while(i<=lastnospc)
	{
		Converted += unConverted.charAt(i) ;
		i++ ;
	}	
	
	//alert(Converted) ;
	return Converted ;
}

function MiseEnMaj(strConvert) {

		 var strConverted = String("");
         var i, nSize = strConvert.length;
         for (i = 0; i < nSize;i++)
         {
         	switch(strConvert.charCodeAt(i))
             {
             	case 232: 
                case 233: 
	        	case 234: 
                case 235:
                strConverted += 'E' ;
                break;
				case 224: 
                case 226: 
                case 228: 
                strConverted += 'A' ;
				break;
				case 239: 
                case 238: 
                strConverted += 'I' ;
				break;
				case 242: 
				case 244: 
                case 246: 
                strConverted += 'O' ;
				break;
				case 249: 
                case 250: 
				case 251: 
                case 252: 
                strConverted += 'U' ;
				break;
                case 231: 
                strConverted += 'C' ;
				break;
                default:
                strConverted += strConvert.charAt(i);
              }
          }
          strConverted = strConverted.toUpperCase();
		return(strConverted);
}

function makeArray(n){
  this.length = n;
  for (i=1;i<=n;i++){
    this[i]=0;
  }
  return this;
}

function AfficheDate(Jour,Mois,Annee) {

var this_month = new makeArray(13);
    this_month[0]  = "";
    this_month[1]  = "January";
    this_month[2]  = "February";
    this_month[3]  = "March";
    this_month[4]  = "April";
    this_month[5]  = "May";
    this_month[6]  = "June";
    this_month[7]  = "July";
    this_month[8]  = "August";
    this_month[9]  = "September";
    this_month[10] = "October";
    this_month[11] = "November";
    this_month[12] = "December";		

	if (Mois == "0") document.write('not specified');
	else {
	
		if (Jour == "0") document.write(this_month[Mois] + ', ' + Annee);
		else document.write(this_month[Mois] + ' ' + Jour + ', ' + Annee);
	}

}

function isLeapYear(year)
{
	//alert("on est dans isLeapYear !!!!")  ;
	if(year % 4 != 0)
		return false ;
	else
		{
			if(year % 100 ==0 && year % 400 != 0)
				return false ;
			else
				return true ;
				
		}
	
}

function CheckDay(day,month,year)
{
	//alert("on est dans CheckDay") ;
	if(day<1)
		return false ;
		
	if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
	{	
		if(day<=31)
			return true ;
		else
			return false ;
		
	}	
	if(month==2)
		{
			if(isLeapYear(year)==true)
			{
				//alert("annee bissextile") ;
				if(day<=29)
					return true ;
				else
					return false ;
			}
			else
			{	
				//alert("annee non bissextile") ;
				if(day<=28)
					return true ;
				else
					return false ;
			}
		}	
		
		if(day<=30)
			return true ;
		else
			return false ;				
}

function CheckMonth(month)
{
	return month>=1 && month<=12 ;
}

function CheckYear(year)
{
	return year>=0 ;
}

function CheckDate(day,month,year,type)
{
	var err = 0 ;
	
	switch(type)
	{
		case 1 ://une date de type 0/0/2000 est legale
			if(year=="")
				err = -1 ;
			if(CheckYear(year)==false)
				err = -1 ;				
			if( (day!=0 && month !=0) && (day!="" && month !="") )
			{
				if(CheckDay(day,month,year)==false)
					err = -1 ;
				if(CheckMonth(month)==false)
					err = -1 ;
				if(CheckYear(year)==false)
					err = -1 ;
			}
			else if( (day==0 && month ==0) ||(day=="" && month =="") )
			{
				dumb = 1 ; //bloc ne faisant rien
			}
			else
				err = -1 ;
			break ;
		case 2 : //une date ou l'annee=0 est legale
			if(CheckDay(day,month,year)==false)
				err = -1 ;
			if(CheckMonth(month)==false)
				err = -1 ;
			if(year<0)
				err = -1 ;
			break ;
		case 3 ://une date de type 0/0/0 est legale
			if(day!=0 && month!=0 && year!=0)
			{
				if(CheckDay(day,month,year)==false)
					err = -1 ;
				if(CheckMonth(month)==false)
					err = -1 ;
				if(CheckYear(year)==false)
					err = -1 ;
			}
			else if(day==0 && month==0 && year==0)
			{
				dumb = true ;//bloc ne faisant rien	
			}
			else
				err = -1 ;
			break ;
		case 0 ://la date doit etre rigoureusement correcte
			if(CheckDay(day,month,year)==false)
				err  = -1 ; 
			if(CheckMonth(month)==false)
				err = -1 		
			if(CheckYear(year)==false)
				err = -1 ; 
			break ;
			
	}	
	
	if(err == 0)
		return true ;
	else 
		return false ;
		
		
}

function FillDate(day,month,year,d,m,y)
{
	if(day.value=="")
		day.value=d ;
	if(month.value=="")
		month.value=m;
	if(year.value=="")
		year.value=y;

}

function CheckField(field,min,max,minalert,maxalert)
{
	var err  = 0 ;
	
	if(min>=0 && field.value.length<min)
	{
		err = -1 ;
		if(minalert != "")
			alert(minalert) ;
		field.focus() ;
	}
	else
		if(max>=0 && field.value.length>max)
		{
			err = -1 ;
			if(maxalert != "")
				alert(maxalert) ;
			field.focus() ;
		}

	if(err == -1)
		return false ;
	return true ;
}		

function CheckMailAddress(email,required) 
{
 var err = 0;
 var arob,ptmail,firstspc,lastspc;
 
 			if(required==0)
 			{
 				//alert("here") ;
 				if(email.value=="")
 				{
 					//alert("email is null") ;
 					return true ;
 				}
 			}
 			
 			lastspc = email.value.lastIndexOf(' ') ;
 			if(lastspc >=0)
 			{
 				//alert("err : "+lastspc) ;
 				err = -1 ;
 			}
 			else
 			{
 				//alert(lastspc) ;
				arob = email.value.indexOf('@');
				if (arob < 1) err = -1;
				else {
			   ptmail = email.value.indexOf('.', arob+1);
		   		if ( ptmail < arob+2) err = -1;
		   		else if (email.value.length == ptmail+1)err = -1;
				}
			}	
			if (err == -1 ) {
		   		alert("E-mail is not correct.");
		   		email.focus() ;
				return false ;
			}
			
			return true ;
}

function CheckCombo(combo,banned,errmess)
{
	var err =  0 ;
	
	if(combo.options[combo.selectedIndex].value==banned)
	{
		alert(errmess) ;
		err = -1 ;
		combo.focus() ;
	}
	
	if(err == -1)
		return false ;
	return true ;
}



