//////////////////////////////////////////////
// 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();
	}

//Print document
//**************
	function printDoc(){
	  openWin('printdoc','',640,480,'yes')
	  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()
	}

//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;
	  //document.getElementById(id).style.top=document.getElementById(menu).offsetHeight+110;
	} 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;
	  //document.all[id].style.top=document.getElementById(menu).offsetHeight+110;
	} 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;
	  //document.layers[id].top=document.getElementById(menu).offsetHeight+110;
	} }

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';
	} }

// LEFT MENU: Display a sublevel
// *****************************
function displaySubLev(IdContent,IdHeader) {
	if(document.getElementById(IdContent) != null) {
		if(document.getElementById(IdContent).style.display=='none') {
			document.getElementById(IdContent).style.display='';
			document.getElementById(IdHeader).className='WithSubRub';
		} else {
			document.getElementById(IdContent).style.display='none';
			document.getElementById(IdHeader).className='SingleRub';
		}
	}
}

// HOME PAGE : Open a slot
// ***********************
function DisplayRightSection(IdContent) {
	if(document.getElementById('SLOT_OPEN' + IdContent) != null) {
		document.getElementById('SLOT_OPEN' + IdContent).style.display='';
		document.getElementById('SLOT_CLOSE' + IdContent).style.display='none';
	}
}

// HOME PAGE : Close a slot
// ************************
function CloseRightSection(IdContent) {
	if(document.getElementById('SLOT_OPEN' + IdContent) != null) {
		document.getElementById('SLOT_CLOSE' + IdContent).style.display='';
		document.getElementById('SLOT_OPEN' + IdContent).style.display='none';
	}
}
