/**
 * 
 * @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();
	return false;
	
}//end function

function voirNewsletter(sUrl){
	popup(sUrl, 100,500, 'newsletter');
	return false;
}


/**
 *
  * @param integer iIdConteneur;
 * @param integer iLargeur;
  * @return void
 */
 
function setTailleFenetre(iIdConteneur,iLargeur,bCentre){
	hauteur=elem(iIdConteneur).offsetHeight;
	if(hauteur>650){
		hauteur=650;
	}
	if(document.all){
		window.resizeTo(iLargeur,hauteur+100);	
	}
	else{
		window.outerHeight =hauteur+105;	
		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 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 swapImage(oImg){
	var reg = /off\./i;
	
	if(oImg){
		if(!oImg.oSrc){
			oImg.oSrc = oImg.src; 
		}//end if
		
		if(!oImg.rSrc){
			oImg.rSrc = oImg.src.replace(reg, 'on.'); 
		}//end if
		
		oImg.src = oImg.rSrc;
	}//end if
	
}//end function

function swapImgRestore(oImg){
	if(oImg){
		oImg.src = oImg.oSrc;
	}//end if
}//end function

function swapImg(id) {
	swapImage(document.getElementById(id));
}

function restoreImg(id) {
	swapImgRestore(document.getElementById(id));
}

function changeClass(id,classname) {
	document.getElementById(id).className = classname;
}

function voirActu(lien){
	popup(lien.href,600,200,'actu');
	return false;
}

function ajoutDocument(lienDoc){	
		document.location.href=lienDoc;
}

function retraitDocument(lienDoc){
		document.location.href=lienDoc;
}

function showImage(sUrlImage,sNameImage){
	popup('popupPhoto.php?urlImage='+sUrlImage+'&name='+sNameImage,300,300,sNameImage);
}
