var nouvelleFenetre = null;
function fermerFenetre(){
	if (nouvelleFenetre != null){
		if(!nouvelleFenetre.closed)
			nouvelleFenetre.close();
	}
}

function ouvrirFenetre(strURL,strType,strHeight,strWidth) {
	fermerFenetre();
	var strOptions="";
	if (strType=="minimal") strOptions="resizable,height="+strHeight+",width="+strWidth;
	if (strType=="statut") strOptions="status,resizable,height="+strHeight+",width="+strWidth;
	if (strType=="navigateur") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	nouvelleFenetre = window.open(strURL, 'newWin', strOptions);
	nouvelleFenetre.focus();
} 

function isHeure(Heure) {
	
	if( Heure.match(/^([0-9]{1,2})+ h +([0-9]{1,2})+$/) ) {
		return true;
	}
	else {
		return false;
	}
}

function isDateFr(dateVar) {
	val = dateVar.match(/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/);
	ok = true;
	if(val) {
		jour = parseInt(val[1],10);
		mois = parseInt(val[2],10);
		annees = parseInt(val[3],10);
		
		// vérification jour du moi
		ok = true;
		if(jour<1 || mois <1 || annees <1) 
			ok = false;
			
		if(jour>31)
			ok = false;
		
		if(mois>12)
			ok = false;
			
		if(jour>29 && mois==2)
			ok = false;
		
		if( ( (mois==4) || (mois==6) || (mois==9) || (mois==11) ) && (jour>30) )
			ok = false;

		if( (mois==2) && ( (annees%4==0) && (annees%100==0) && (annees%400==0) ) && (jour>28) )
			ok = false;
	}
	else {
		ok = false;
	}
	if(!ok) {
		return false;
	}
	else {
		return true;
	}
}

function trim(strText) {
  while (strText.substring(0,1) == ' ') 
     strText = strText.substring(1, strText.length);
  while (strText.substring(strText.length-1,strText.length) == ' ')
     strText = strText.substring(0, strText.length-1);
  return strText;
} 

function isDate(d) 
{
	e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
	if (e.test(d)==false)
	       return false;
	else{	
	    j = parseInt(d.split("/")[0],10); // jour
	    m = parseInt(d.split("/")[1],10); // mois
	    a = d.split("/")[2]; // année
		
		var nb=a.length
		a=parseInt(a)
		if(nb==2||nb==4)
		{
			if (a < 89)
				a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
			else
				a+=1900;
		}else
			return(false);
			
	    if (a%4 == 0 && a%100 !=0 || a%400 == 0)
			fev = 29;
		else
		    fev = 28;
	
	    nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);
	    return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
	}
}

function isEmail(a)
{
	return ((/^[-_A-Za-z0-9]+(\.[-_A-Za-z0-9]+)*@[-A-Za-z0-9]+(\.[-A-Za-z0-9]+)+$/).test(a));
}

function isCompareDate(d1,d2,v)
{
	var ok=1;
	var ok1=1;
	if((isDate(d1))&&(isDate(d2)))
	{
		tbld1=d1.split("/");
		tbld2=d2.split("/");
		j1=parseInt(tbld1[0]);
		j2=parseInt(tbld2[0]);
		m1=parseInt(tbld1[1]);
		m2=parseInt(tbld2[1]);
		a1=tbld1[2];
		a2=tbld2[2];
		//alert(a1.length+"\n"+a2.length);
		if(a1.length==2)
		{
			a1=parseInt(a1)
			if(a1<89)
			{
				a1+=2000;
			}else{
				a1+=1900;
			}
		}else{
			a1=parseInt(a1);
		}
	
		if(a2.length==2)
		{
			a2=parseInt(a2)
			if(a2<89)
			{
				a2+=2000;
			}else{
				a2+=1900;
			}
		}else{
			a2=parseInt(a2);
		}
		date1=new Date(m1+"/"+j1+"/"+a1);
		date2=new Date(m2+"/"+j2+"/"+a2);
		//alert(date1+"\n"+date2)
		switch (v)
		{
			case"<":
				if(date1<date2)
				{
				}else{
					ok=0;
				}
				break;
			case">":
				if(date1>date2)
				{
				}else{
					ok=0;
				}
				break;
			case"==":
				if((date1-date2)==0)
				{
				}else{
					ok=0;
				}
				break;
			case"!=":
				if((date1-date2)!=0)
				{
				}else{
					ok=0;
				}
				break;
			default:
				ok=0;
				break;
		}
	}else{
		ok=0;
	}
	
	if(ok==0)
	{
		return(false);
	}else{
		return(true);
	}
}