// LTrim(string) : Returns a copy of a string without leading spaces.
function ltrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

//RTrim(string) : Returns a copy of a string without trailing spaces.
function rtrim(str)
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}

// Trim(string) : Returns a copy of a string without leading or trailing spaces
function trim(str) {
   return rtrim(ltrim(str));
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		B_01_over = newImage("images/B_01-over.jpg");
		B_02_over = newImage("images/B_02-over.jpg");
		B_03_over = newImage("images/B_03-over.jpg");
		B_04_over = newImage("images/B_04-over.jpg");
		B_05_over = newImage("images/B_05-over.jpg");
		B_06_over = newImage("images/B_06-over.jpg");
		preloadFlag = true;
	}
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function changeLegend(newtext) {
  MM_findObj('legende').innerHTML=newtext;
//  MM_findObj('legende').innerHTML="<p>" + newtext + "</p>";
}

function changeNomChateauIn(newtext) {
  MM_findObj('nomchateau').style.border = '2px rgb(255,45,0) solid';
  MM_findObj('nomchateau').innerHTML="<p>" + newtext + "</p>";
}

function changeNomChateauOut() {
  MM_findObj('nomchateau').style.border = '0px';
  MM_findObj('nomchateau').innerHTML="<p>&nbsp;</p>";
}

function changeMainPhoto(path, idphoto, w, h) {
  MM_findObj('MainPhotoCell').innerHTML='<img src="' + path + '" border="0" width="' + w + '" height="' + h + '" onMouseOver="this.style.cursor=\'pointer\'" onClick="window.open(\'photo.php?pid=' + idphoto + '\',\'nom\',\'width=640,height=640,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no\')">';
}

function changeMainPhotoPresta(path, idphoto, w, h) {
	if (!w) {w="335";}
	if (!h) {h="300";}
  MM_findObj('MainPhotoCell').innerHTML='<img src="' + path + '" border="0" width="' + w + '" height="' + h + '" onMouseOver="this.style.cursor=\'pointer\'" onClick="window.open(\'photo_presta.php?pid=' + idphoto + '\',\'nom\',\'width=640,height=640,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no\')">';
}

function changeMainPhotoPromo(path, num) {
  MM_findObj('MainPhotoCell' + num).innerHTML='<img src="' + path + '" border="0" width="300" height="225">';
}


function checkAll( n ) {
	var f = document.dossier;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.cb' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	if (c) {
		document.dossier.boxchecked.value = n2;
	} else {
		document.dossier.boxchecked.value = 0;
	}
}

function isChecked(isitchecked){
	if (isitchecked == true){
		document.dossier.boxchecked.value++;
	}
	else {
		document.dossier.boxchecked.value--;
	}
}



/**
 *  Check the browser version
 **/
 
function BrowserCheck() {
  var b = navigator.appName
    if (b=="Netscape") this.b = "ns"
    else if (b=="Microsoft Internet Explorer") this.b = "ie"
    else this.b = b
    this.v = parseInt(navigator.appVersion)
    this.ns = (this.b=="ns" && this.v>=4)
    this.ns4 = (this.b=="ns" && this.v==4)
    this.ns5 = (this.b=="ns" && this.v==5)
    this.ns6 = (this.b=="ns" && this.v==6)
    this.ns7 = (this.b=="ns" && this.v==7)
    this.ie = (this.b=="ie" && this.v>=4)
    this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
    this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
    if (this.ie5) this.v = 5
    this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0)
    if (this.ie6) this.v = 6			  
    this.min = (this.ns||this.ie)
}





















//###NAL #####
function	id2obj(id)
  {
  // form
  if (eval('document.forms.'+ id))
    return eval('document.forms.'+ id);
    // ie
    if (document.all)
      return document.all(id);
      // others (mozilla, firebird/fox, netscape)
      if (document.getElementById(id))
        return document.getElementById(id);
	// iframe
	if (eval('frames.'+ id))
	  return eval('frames.'+ id);
	  // object is found directly
	  return 0;
 }


function	browser() {
	// opera
	if (navigator.userAgent.toLowerCase().indexOf('opera') != -1)
	 {
		return 'opera';
	 }
	// internet explorer
	if (navigator.userAgent.toLowerCase().indexOf('msie') != -1 &&
	    navigator.userAgent.toLowerCase().indexOf('opera') == -1) // Opera can pretend it's other browser
	 {
		return 'ie';
	 }
	// firebird
	if (navigator.userAgent.toLowerCase().indexOf('firebird') != -1)
	 {
		return 'firebird';
	 }
	// firefox
	if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1)
	 {
		return 'firefox';
	 }
	// netscape
	if (navigator.userAgent.toLowerCase().indexOf('netscape') != -1)
	 {
		return 'netscape';
	 }
	// mozilla
	if ((navigator.userAgent.toLowerCase().indexOf('mozilla') != -1) &&
	    (navigator.userAgent.toLowerCase().indexOf('gecko') != -1) &&
	    (navigator.userAgent.toLowerCase().indexOf('netscape') == -1) &&
	    (navigator.userAgent.toLowerCase().indexOf('firebird') == -1))
	 {
		return 'mozilla';
	 }
	// unlisted browser
	return 'unknown';
 }

function	launcher()
 {
	//
 }

function	setHeightCenter()
 {
	var scr_height = (browser() == "ie" ? document.body.offsetHeight : window.innerHeight);
	var scr_padding = (scr_height <= 430 ? 10 : (scr_height - 430) / 2);

	setTagProp('body', 'paddingTop', '5px', document);

	id2obj('body').style.height = (scr_height > 430 ? scr_height - 155 : 320) +'px';
	id2obj('f_content').height = (scr_height > 430 ? scr_height - 155 : 320) +'px';

	setTagProp('body', 'paddingBottom', '10px', document);
 }

function	setTagProp(tag, prop, value, target)
 {
	var     tgt = (target ? target : document);
	for (k = 0; k < tgt.getElementsByTagName(tag).length; k++)
	  eval('tgt.getElementsByTagName(\''+ tag +'\')['+ k +'].style.'+ prop +'=\''+ value +'\';');
 }

function	loadTitle(target)
 {
	if (target.page_title)
	  id2obj('title').innerHTML = '<b>'+ (target.page_type ? target.page_type : '') +'</b><h1>'+
	  (target.page_icon ? '<img src="/picture/'+ target.page_icon +'" align="absmiddle">' : '') +
	  target.page_title +'</h1>';
	else
	  id2obj('title').innerHTML = '';
 }

function	display_header(target)
 {
	document.write('<table class="printit" cellpadding="0" cellspacing="0"><tr>'
		+'<td class="print_left"><img src="/picture/bg_head_print.gif"></td>'
		+'<td class="print_right"><b>'+ target.page_type +'</b>'
		+'<br><h1>'+ (target.page_icon ? '<img src="/picture/'+ target.page_icon +'" align="absmiddle">' : '')
		+ target.page_title +'</h1></td>'
		+'</tr></table>');
 }