/**
 * 
 * @version $Revision $
 * @cvs $id $
 */

/**
 *
 * @param integer iId
 * @return object
 */
function elem(iId){
	return document.getElementById(iId);
}//end function 
 
/**
 *
  * @param string sExt;
 * @param array aExt;
  * @return bool
 */
function in_array(sExt,aExt){
	for(i in aExt){
		if(sExt==aExt[i]){
			return true;
		}
	}
	return false;
} 
 
/**
 *
 * @param string sUrl
 * @param string sUrl
 * @return void
 */
function loadExternalUrl(sUrl, sName){
	if(sName == undefined){
		sName = '';
	}//end if
	var oWindow = window.open( sUrl, sName,'');
	oWindow.focus();
}//end function

/**
 * @param string sUrl
 * @param integer iWidth
 * @param integer iHeight
 * @param boolean bCache
 * @return void
 */
function popup(sUrl, iWidth, iHeight, sName){
	var iCoordX = (screen.width /2) - ( iWidth/2);
	var iCoordY = (screen.height /2) - ( iHeight/2);

	if(sName == undefined){
		sName = '';
	}//end if
	
	var oPopup = window.open( sUrl, sName,'status=0, left=' + iCoordX + ' ,top=' + iCoordY + ' ,height=' + iHeight + ' ,width=' + iWidth + ', toolbar=no, status=no, location=no, resizable=no, scrollbars=yes, copyhistory=0, menubar=no');
	oPopup .focus();
	
}//end function


function setTailleFenetre(iIdConteneur,iLargeur,bCentre){
	hauteur=elem(iIdConteneur).offsetHeight;
	if(hauteur>650){
		hauteur=650;
	}
	if(document.all){
		window.resizeTo(iLargeur,hauteur+50);	
	}
	else{
		window.outerHeight =hauteur+55;	
		window.outerWidth =iLargeur;	
	}
	if(bCentre == undefined || bCentre == true){
		centreFenetre();
	}//end if	
	
}

function centreFenetre(){
	if(document.all){
		var x = (screen.width - document.body.offsetWidth)/2;
		var y = (screen.height - document.body.offsetHeight)/2;
	}
	else{
		var px1 = opener.screenX;
		var px2 = opener.screenX + opener.outerWidth;
		var py1 = opener.screenY;
		var py2 = opener.screenY + opener.outerHeight;
		var x = (px2 - px1 - window.outerWidth) / 2;
		var y = (py2 - py1 - window.outerHeight) / 2;
	}
	window.moveTo(x, y);	
}

function centrePage(){

}


function checkMail(sEmail) {
	return sEmail.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9]{2}[a-z0-9-.]*\.[a-z]{2,4}$/i);
}//end function

function testDate(chaine,champ){
	var msg="";
	var exp1=new RegExp("[/]{1}","g");
	var tabDate=chaine.split(exp1);	
	
	if (tabDate==null || tabDate.length!=3)
		{msg+=champ+" incorrecte\n";}
	else {
		var t1=tabDate[0];
		var t2=tabDate[1];
		var t3=tabDate[2];
		if (!(t1>0 && t1<32)){msg+="Jour de "+champ+" incorrect\n";}
		if (!(t2>0 && t2<13)){msg+="Mois de "+champ+" incorrect\n";}
		if (!(t3>0 && t3.length==4)){msg+="Année de "+champ+" incorrecte\n";}		
		
	}
	return msg;
}

function affichePhoto(id){
popup('index.php?target=showPhoto&idPhoto='+id,600,300,id);
 }	


function zoomPhoto(src){
	var uri = src.split('/');
	var image = uri[uri.length-1];
	var zoom = '';
	for(i=0;i<uri.length-1;i++){
		zoom += uri[i]+'/';
	}
	zoom += 'zoom/'+image;
	popup('index.php?target=showPhoto&image='+zoom,600,300);
}