//////////////////////////////////////////////
// Helper functions
// COPYRIGHT ADVANTYS 2004
// Last modified : March 11 2005
//////////////////////////////////////////////


//Open popup window
//*****************
var tmp;
function openWin(name,src,lngWidth,lngHeight,bScroll) {
  var xCoord;
  var yCoord;
  var strAgent=navigator.userAgent;
  if(tmp)tmp.close();
  if (strAgent.indexOf('Mozilla/3')==-1 && strAgent.indexOf('MSIE 3')==-1){
	xCoord=(screen.width/2 - (lngWidth/2));
	yCoord=(screen.height/2 - (lngHeight/2));
  }
  tmp=open(src,name,'top='+ yCoord +',left='+ xCoord +',directories=no,menubar=no,scrollbars='+bScroll+',resizable=no,location=no,toolbar=no,width='+lngWidth+',height='+lngHeight);
  if (strAgent.indexOf('MSIE 3')==-1) tmp.focus();
}

//Open popup window pour module animé Essentiel 2008
//**********************************************
function fullWin(name,url){
	// IE PC
	if((navigator.appName == "Microsoft Internet Explorer") && (navigator.platform != "MacPPC"))
	{
		fenetre=window.open(url,name,'fullscreen=yes');
	}
	// safari mac
	else {
		height = screen.availHeight;
		width = screen.availWidth;
	
		try
		{
			tmp = window.open(url, null, "height=" + height + "px,width=" + width + "px,top=0,left=0,location=0,menubar=0,resizable=0,scrollbars=0,toolbar=0");
			tmp.resizeTo(width, height);
		} catch(e) {}
	}
}

//Print document
//**************
	function printDoc(){
	  openWin('printdoc','',650,480,'yes');
	  document.PRINT_DOC.PRINTDOC.value = 'Y';
	  document.PRINT_DOC.MASTER.value='MASTER_PRINT_01';
	  document.PRINT_DOC.BANNER.value='Y';
	  document.PRINT_DOC.submit();
	}

//Open document in popup view
//***************************
	function zoom(){
	  openWin('printdoc','',1000,700,'yes');
	  document.PRINT_DOC.PRINTDOC.value = '';
	  document.PRINT_DOC.MASTER.value='MASTER_POPUP_01';
	  document.PRINT_DOC.BANNER.value='N';
	  document.PRINT_DOC.submit();
	}

//Open 'send this page view' in popup view
//****************************************
	function popup(strUrl,strDocId){
	  openWin('printdoc',strUrl+'&DOC_ID='+strDocId,347,450,'no');
	}

//Update locator
//**************
	function showLocation(){
		document.all.ss_location.innerHTML = strCURRENT_LOCATION;
	}

//Return date with numeric value
//******************************
	function getNumericalDate(d,lg) {
		var x = d
		if (typeof(lg)=='undefined') lg='fr';
		j = d.split('/')[(us=(lg && lg.toLowerCase()=='us'))?1:0]*1;
		m = d.split('/')[us?0:1]*1;
		a = parseInt(d.split('/')[2]);
		x = -((-a*20-m)*50-j)
		return x;
	}

//Check date
//**********
	function jsCheckDate(d,lg) {
  		var e = /^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$/;
  		if (d==''||!e.test(d)) return false;
  		if (typeof(lg)=='undefined') lg='fr';
  		j = d.split('/')[(us=(lg && lg.toLowerCase()=='us'))?1:0]*1;
  		m = d.split('/')[us?0:1]*1;
  		a = parseInt(d.split('/')[2]);
  		if (a<100) a+=(a<32?2000:1900);
  		nbJours = new Array(31,(a%4==0 && a%100!=0 || a%400==0)?29:28,31,30,31,30,31,31,30,31,30,31);
  		return (m>=1 && m<=12 && j>=1 && j<= nbJours[m-1]);
	}

//Retourne la date sous forme numérique
//*************************************
	function autoCompleteDate(oInput,lg) {
  		if (oInput.value=='') return;
  		var arrPart = oInput.value.split('/');
  		if (typeof(lg)=='undefined') lg='fr';
  		var bUS = (lg.toLowerCase()=='us')
  		if (isNaN(parseInt(parseFloat(arrPart[bUS?1:0])))||arrPart[bUS?1:0].length>2) arrPart[bUS?1:0] = new Date().getDate();
  		if (isNaN(parseInt(parseFloat(arrPart[bUS?0:1])))||arrPart[bUS?0:1].length>2) arrPart[bUS?0:1] = new Date().getMonth()+1;
  		if (isNaN(parseInt(parseFloat(arrPart[2])))||parseInt(parseFloat(arrPart[2])).toString().length!=4) arrPart[2] = new Date().getYear();
  		if (bUS)
    		oInput.value = parseInt(parseFloat(arrPart[0])) + '/' + parseInt(parseFloat(arrPart[1])) + '/' + parseInt(parseFloat(arrPart[2]));
  		else
    		oInput.value = paddDatePart(arrPart[0]) + '/' + paddDatePart(arrPart[1]) + '/' + arrPart[2];
	}

//Padding d'une partie d'une date
//*******************************
	function paddDatePart(datePart) {
	  if (parseInt(parseFloat(datePart))<10)
	    return '0' + parseInt(parseFloat(datePart));
	  else
	    return datePart;
	}

//Met à jour les champs pour le tri par colonne
//*********************************************
	function sortBy(strForm,strField,strCurrent){
	  var oForm;
	  oForm = eval("document."+strForm);
	  oForm.SORT_FIELD.value=strField;
	  if ((oForm.ORDER.value=='DESC') || (strField!=strCurrent))
	    oForm.ORDER.value='ASC';
	  else
	    oForm.ORDER.value='DESC';
	  oForm.submit();
	}

//Get current page
//****************
function page(strForm,pageNumber){
	  var oForm;
	  oForm = eval("document."+strForm);
  	  oForm.ABSOLUTE_PAGE.value=pageNumber;
  	  oForm.submit();
}

function openSubMenu(menu,id) {
  if (document.getElementById) {
	  document.getElementById(id).style.display='block';
	  document.getElementById(id).style.zIndex=100;
	  document.getElementById(id).style.left= document.getElementById(menu).offsetLeft + document.getElementById('start').offsetLeft;
	  document.getElementById(id).style.width=document.getElementById(menu).offsetWidth;
	}
	else if (document.all) {
	  document.all[id].style.display='block';
	  document.all[id].style.zIndex=100;
	  document.all[id].style.left=document.all[id].offsetLeft;
	  document.all[id].style.width=document.all[id].offsetWidth;
	}
	else if (document.layers) {
	  document.layers[id].display='block';
	  document.layers[id].zIndex=100;
	  document.layers[id].left=document.layers[id].offsetLeft;
	  document.layers[id].width=document.layers[id].offsetWidth;
	}
}

// LEFT MENU: Display a sublevel
// *****************************
function displaySubLev(IdHeader,IdContent) {
	if(document.getElementById(IdContent) != null) {
		if(document.getElementById(IdContent).style.display=='none') {
			document.getElementById(IdContent).style.display='';
		} else {
			document.getElementById(IdContent).style.display='none';
		}
	}
}

// Close sub menu level
// ********************
function closeSubMenu(id) {
  if (document.getElementById) {
	  document.getElementById(id).style.display='none';
	}
	else if (document.all) {
	  document.all[id].style.display='none';
	}
	else if (document.layers) {
	  document.layers[id].display='none';
	}
}


// Check email format
// ******************
function isEmail(str) {
	var r1 = new RegExp('(@.*@)|(\\.\\.)|(@\\.)|(^\\.)');
	var r2 = new RegExp('^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$');
	return (!r1.test(str) && r2.test(str));
}

// Reset years and months input
// ****************************
function resetYearsAndMonths(strForm) {
	strForm.YEARS.value = '';
	strForm.MONTHS.value = '';
}
	
// Get number of days for specified month in year
// **********************************************
function getDate(intYear,intMonth) {
	nbJours = new Array(31,(intYear%4==0 && intYear%100!=0 || intYear%400==0)?29:28,31,30,31,30,31,31,30,31,30,31);
	return nbJours[intMonth-1];
}
	
// Update period hidden fields
// ***************************
function updatePeriod(intCurrentYear,intYear,intMonth,lg,strInputBegin,strInputEnd) {
	var strEnd = (intYear != '') ? intYear : intCurrentYear;
	var strBegin = (intYear == '' && intMonth == '') ? intCurrentYear-4 : strEnd;
	
	if(intMonth != '') {
		if (lg == 'US') {
			strBegin = intMonth + '/01/' + strBegin;
			strEnd = intMonth + '/' + getDate(strEnd,intMonth) + '/' + strEnd;
		} else {
			strBegin = '01/' + intMonth + '/' + strBegin;
			strEnd = getDate(strEnd,intMonth) + '/' + intMonth + '/' + strEnd;
		}
	}
	else {
		strBegin = '01/01/' + strBegin;
		strEnd = (lg == 'US') ? '12/31' : '31/12/' + strEnd;
	}

	strInputBegin.value=strBegin;
	strInputEnd.value=strEnd;
}
// HOME PAGE : Display a news
// **************************
function displayNews(IdClosed,nbNews) {

	for (i=1;i<=nbNews;i++){
		document.getElementById('News' + i).style.display='none';
		document.getElementById('LinkNews' + i).className='LinkInactive';
	}

	document.getElementById(IdClosed).style.display='';
	document.getElementById('Link' + IdClosed).className='LinkActive';

}
// Detect Flash plugin
// *******************
var MM_contentVersion = 7;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin)
{
	var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	for (var i = 0; i < words.length; ++i)
	{
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	}
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1))
{
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}
