/* Fixer une valeur  un cookie */
function SetCookie(sName, sValue) {
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + ";";
}

/* Rcupere la valeur d'un cookie */
function GetCookie(sName) {
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++) {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return true;
  }
  return false;
}



function openmsg(titre,theme,message,w,h,notModal){

  if(notModal){
    w = window.open("message.aspx?titre="+escape(titre)+"&theme="+escape(theme)+"&message="+escape(message),'msg','WIDTH='+w+',HEIGHT='+h+',scrollbars=yes,resizable=yes');
	  if (navigator.userAgent.indexOf('MSIE')!=-1) {w.focus()}
  }else{
	  w = window.showModalDialog("message.aspx?titre="+escape(titre)+"&theme="+escape(theme)+"&message="+escape(message),'msg',"dialogWidth:"+w+"px;dialogHeight:"+h+"px;");
  }
}
/**
 * Ouvre une url
 *
 * @params url  l'url
 * @params w width
 * @params h height
 */
function openurl(url, w, h, n) {
  if (!n || n==null){n = 'ami';}
	if(navigator.userAgent.indexOf('MSIE')!=-1){ // ie
	  wnd= window.open(url,n,'WIDTH='+w+',HEIGHT='+h+',scrollbars=1,resizable=1');
	}else{
	  wnd= window.open(url,n,'WIDTH='+w+',HEIGHT='+h+',scrollbars=yes,resizable=yes');
	}
	
	if(wnd.resizeTo){wnd.resizeTo(w,h);}
	if(wnd.focus){wnd.focus();}
}



function openurlSortie(url, w, h) {
	var wnd = window.open(url,'sortie','WIDTH='+w+',HEIGHT='+h+',scrollbars=1,resizable=1');
	wnd.resizeTo(w,h)
	if (navigator.userAgent.indexOf('MSIE')!=-1) {wnd.focus()}
}

function openurlkilo(url, w, h) {
	var wnd = window.open(url,'ami','WIDTH='+w+',HEIGHT='+h+',scrollbars=yes,resizable=yes');
	if (navigator.userAgent.indexOf('MSIE')!=-1) {wnd.focus()}	
	wnd.resizeTo(w,h);
	return wnd;
}

function mygetElementById(v) {
  return eval("document.all." + v);
}

if (!document.getElementById) {
  document.getElementById = mygetElementById;
}


function ensureSize(image,wnd,xPadding,yPadding){
 if (navigator.userAgent.indexOf('MSIE')!=-1) {
  var rX=image.clientWidth+xPadding+20;
  var rY=image.clientHeight+yPadding+28;
  if(rX<200)
    rX=200;
  if(rY<100)
    rY=100;
  if(rY>(screen.height-50))
    rY=screen.height-100;
  wnd.resizeTo(rX,rY);
 }
}
/**
 * arrondi au centime
 */
function monetaire(valeur){
 return formatCurrency(Math.round(valeur * 100) /100); 
}
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}

function showAffiner(show){
  parent.trouver.document.getElementById("lbAffiner").style.display=(show?'block':'none');
  parent.trouver.document.getElementById("imgAffiner").style.display=(show?'block':'none');
  parent.trouver.document.getElementById("imgValider").style.display=(show?'none':'block');
  parent.trouver.document.getElementById("lbSearch").style.display=(show?'none':'block');
}

var memotoggleDivid = "";
var memotoggleDivimg = "";
var memotoggleDivimgref = "";

function toggleDiv(id,img, imgref){ 
 if (memotoggleDivid != id) { //On a quelquechose a faire
	if(memotoggleDivid != "") { //Il faut cacher l ancien
		document.getElementById(memotoggleDivid).style.display='';
	}
	if(memotoggleDivimg != "") {
		document.getElementById(memotoggleDivimg).src='/img/auto_desc/'+memotoggleDivimgref+'_off.gif';
	}
	memotoggleDivid = id;
	memotoggleDivimg = img;
	memotoggleDivimgref = imgref;
	document.getElementById(memotoggleDivid).style.display='block';
	document.getElementById(img).src='/img/auto_desc/'+imgref+'_on.gif';	
 }
}


function preloadim3() {
	var chamin_img = "/img/auto_desc/";
	var ref_img = new Array("ongl_photo_on.gif", "ongl_photo_off.gif", "ongl_techn_on.gif", "ongl_confort_on.gif", "ongl_secur_on.gif");
	var imgs = new Array();
	for(i=0; i < ref_img.length; i++) {
		imgs[i] = new Image();
		imgs[i].src = chamin_img + ref_img[i];
	}
}