// Copyright Hippocampe 2001
browserVer = parseInt(navigator.appVersion);
browserName = navigator.appName;
browser = 0;
url = "" + document.location;

// Netscape ou IE
if ((browserName == 'Netscape') && (browserVer >= 2) && (browserVer != 5))
	browser = 1;
else
	browser = 2;

function addHeader(){
	var buffer =null;
	buffer = "<html>\r\n";
	buffer += "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'\r\n";
	buffer += "'http://www.w3.org/TR/html4/strict.dtd'>\r\n";
	buffer += "		<head>\r\n";
    buffer += "			<title>Impression</title>\r\n";
    buffer += "			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\r\n";
    buffer += "			<meta name='robots' content='index,follow'>\r\n";
    buffer += "			<meta http-equiv='Expires' content='0'>\r\n";
    buffer += "		 	<meta http-equiv='Pragma' content='no-cache'>\r\n";
    buffer += "			<meta http-equiv='Cache-Control' content='no-cache'>\r\n";
    if (browser==1) {
    	buffer += "			<link rel=stylesheet type='text/css' href='../configuration/css/ns_site.css' title='Feuille de style du site'>\r\n";
		buffer += "			<link rel=stylesheet type='text/css' href='../configuration/css/ns_rubrique.css' title='Feuille de style du site'>\r\n";
	} else {
		buffer += "			<link rel=stylesheet type='text/css' href='../configuration/css/ie_site.css' title='Feuille de style du site'>\r\n";
		buffer += "			<link rel=stylesheet type='text/css' href='../configuration/css/ie_rubrique.css' title='Feuille de style du site'>\r\n";
	}
    buffer += "		</head>\r\n";
	buffer += "		<body bgcolor='#ffffff' style='background-color: white;'>\r\n";
	return buffer;
}

function addFooter(){
	var buffer = null;
	buffer = "		</body>\r\n";
	buffer += "</html>\r\n";
	return buffer;
}

function imprime(){
	var bufferHtml = null;
	bufferHtml = addHeader();
   	bufferHtml += document.getElementById('content').innerHTML+"\r\n";
   	bufferHtml += addFooter();
   	var win = open('', 'plateform_preview')
   	if (win) {
        win.document.open();
		win.moveTo(-1000, -1000);
		win.resizeTo(670, 400);
        
        win.document.write(bufferHtml);
        win.document.close();
        
        win.focus();
        win.print();
        win.close();
    }
}

function imprimeUsine(){
	var bufferHtml = null;
	bufferHtml = addHeader();
   	bufferHtml += document.getElementById('printArea').innerHTML+"\r\n";
   	bufferHtml += addFooter();
   	var win = open('', 'plateform_preview')
   	if (win) {
        win.document.open();
		win.moveTo(-1000, -1000);
        
        win.document.write(bufferHtml);
        win.document.close();
        
        win.focus();
        win.print();
        win.close();
    }
}


/**
 * Ouvre la popup url
 *
 * @param url de la page
 */
// si x==-1 et y==-1 alors centrage par rapport à l'écran
var wPopWindow 				= null; // Popup
function windowOpen(urlPage,x,y,w,h) {
	if (wPopWindow && !wPopWindow.closed) {
		wPopWindow.close();
		wPopWindow = null;
	}
   	if (x==-1) x = (screen.width / 2) - (w / 2);
   	if (y==-1) y = (screen.height / 2) - (h / 2);
   	wPopWindow = window.open(urlPage,'wPopWindow','width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=NO');
   	wPopWindow.focus();
   	return false;
}
/**
 * Ouvre la popup url
 *
 * @param url de la page
 */
// si x==-1 et y==-1 alors centrage par rapport à l'écran
function windowOpenFixed(urlPage,x,y,w,h) {
	if (wPopWindow && !wPopWindow.closed) {
		wPopWindow.close();
		wPopWindow = null;
	}
   	if (x==-1) x = (screen.width / 2) - (w / 2);
   	if (y==-1) y = (screen.height / 2) - (h / 2);
   	wPopWindow = window.open(urlPage,'wPopWindow','width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no');
   	wPopWindow.focus();
   	return false;
}

/**
 * Ouvre la popup url
 *
 * @param url de la page
 */
// si x==-1 et y==-1 alors centrage par rapport à l'écran
var wPopWindow 				= null; // Popup
function windowOpenDiff(urlPage,name,x,y,w,h) {
	if (x==-1) x = (screen.width / 2) - (w / 2);
   	if (y==-1) y = (screen.height / 2) - (h / 2);
   	name = window.open(urlPage,name,'width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=NO');
   	name.focus();
   	return false;
}

// va a la page via la navigation interne (suiv-precedent ou combo)
function goToPage(iOrdrePage, sCmdPage){
	if (iOrdrePage && sCmdPage) {
		document.formPage.cmd_page.value	= sCmdPage;
		document.formPage.ordre_page.value = iOrdrePage;
		document.formPage.submit();
		return true;
	}
	return false;
}


	
/**
 * Set une valeur dans le champ caché specialCmd et envoit le formulaire
 *
 * @param <form>
 * @param sCmd
 */
function setValueInSpecialCmd(form, sCmd)
{
	form.specialCmd.value = sCmd;
	form.submit();
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' doit contenir un e-mail valide.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' doit contenir un nombre.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' doit contenir un nombre entre'+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' \n'; }
  } if (errors) alert('Le(s) champ(s) suivants sont manquants :\n'+errors);
  document.MM_returnValue = (errors == '');
}

function setDate(tdId){
    var months=new Array(12);
    var days=new Array(7);
    var laDate;
	today = new Date;
    
    months[1]="Janvier";
	months[2]="Février";
	months[3]="Mars";
	months[4]="Avril";
	months[5]="Mai";
	months[6]="Juin";
	months[7]="Juillet";
	months[8]="Aout";
	months[9]="Septembre";
	months[10]="Octobre";
	months[11]="Novembre";
	months[12]="Décembre";

	days[1]="Lundi";
	days[2]="Mardi";
	days[3]="Mercredi";
	days[4]="Jeudi";
	days[5]="Vendredi";
	days[6]="Samedi";
	days[7]="Dimanche";
    
    var month=months[today.getMonth() + 1];
    var day=days[today.getDay()];
    var date=today.getDate();
    var year=today.getYear();
    
    year=year;
	laDate=day + " " + date + " " + month;
	tdId.innerHTML = laDate;
}

function setDateUk(tdId){
    var months=new Array(12);
    var days=new Array(7);
    var laDate;
	today = new Date;
    
    months[1]="January";
	months[2]="February";
	months[3]="March";
	months[4]="April";
	months[5]="May";
	months[6]="June";
	months[7]="July";
	months[8]="August";
	months[9]="September";
	months[10]="October";
	months[11]="November";
	months[12]="Décember";

	days[1]="Monday";
	days[2]="Tuesday";
	days[3]="Wednesday";
	days[4]="Thursday";
	days[5]="Friday";
	days[6]="Saturday";
	days[7]="Sunday";
	    
    var month=months[today.getMonth() + 1];
    var day=days[today.getDay()];
    var date=today.getDate();
    var year=today.getYear();
	var arraySuffix = ['st', 'nd', 'rd', 'th'];
	if (date>3)
		var suffixe = arraySuffix[3];
	else
		var suffixe = arraySuffix[date-1];
	laDate=day + ", " + month + " " + date + suffixe; 
	tdId.innerHTML = laDate;
}


/* function de scrolling */
function checkBrowser(){
	this.ver=navigator.appVersion
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5)
	return this
}
bw=new checkBrowser()

lstart=100
loop=true 
speed=60
pr_step=1

function makeObj(obj,nest){
    nest=(!nest) ? '':'document.'+nest+'.'
	this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0;
  	this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0;
	this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight
	this.newsScroll=newsScroll;
	this.moveIt=b_moveIt;
	this.x;
	this.y;
    this.obj = obj + "Object"
    eval(this.obj + "=this")
    return this
}
function b_moveIt(x,y){
	this.x=x;
	this.y=y;
	this.css.left=this.x;
	this.css.top=this.y;
}
function newsScroll(speed){
	if(this.y>-this.scrollHeight){
		this.moveIt(0,this.y-pr_step)
		setTimeout(this.obj+".newsScroll("+speed+")",speed)
	} else if(loop) {
		this.moveIt(0,lstart)
		eval(this.obj+".newsScroll("+speed+")")
	}
}
function newsScrollInit(){
	oNewsCont=new makeObj('divNewsCont')
	oNewsScroll=new makeObj('divNewsText','divNewsCont')
	oNewsScroll.moveIt(0,lstart)
	oNewsCont.css.visibility='visible'
	oNewsScroll.newsScroll(speed)
}

function stopScroll(){
	pr_step=0;
}
function resumeScroll(){
	pr_step=1;
}
function forwardScroll(){
	pr_step=4;
}
function backyardScroll(){
	pr_step=-4;
}

function setFocusAndSelect (myField) {
	myField.select();
	myField.focus();
}