var time = new Date();
randnum= (time.getTime());

//
//	Mini API
if (!Array.prototype.push) {
	Array.prototype.push = function() {
		var startLength = this.length;
		for (var i = 0; i < arguments.length; i++)
		this[startLength + i] = arguments[i];
		return this.length;
	}
}

function $() {
	var elements = new Array();

	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);

		if (arguments.length == 1)
			return element;

		elements.push(element);
	}

	return elements;
}

function isset(varname){
	if (typeof varname == 'string') {
		return(document.getElementById(varname) != null && typeof(document.getElementById(varname)) != 'undefined');
	}
	else {
		return(varname != null && typeof varname != 'undefined');
	}
}

function mvd(element){
	var text = '';
	for(i in element){
		text += i + '\t';
	}

	alert(text);
}

function imprime() {
	if (typeof(window.print) != 'undefined') { 
		window.print(); 
	}
} 

function toogleCheckoxes(master, name){
	if($(master).checked)
		select_checkboxes(name);
	else
		deselect_checkboxes(name);
}

function select_checkboxes(name){
	checkboxes = document.getElementsByName(name);
	for(i=0; i<checkboxes.length; i++)
		checkboxes[i].checked = true;
}

function deselect_checkboxes(name){
	checkboxes = document.getElementsByName(name);
	for(i=0; i<checkboxes.length; i++)
		checkboxes[i].checked = false;
}

function checkSRD(){
  return true;
}

function calculCleRIB(banque, guichet, compte) {
  if (5 != banque.length || 5 != guichet.length || 11 != compte.length)
    return;
  function replaceAlpha(alpha)
  {
  	return '12345678912345678923456789'.charAt(alpha.charCodeAt(0) - 65);
	}
  compte= parseInt(compte.toUpperCase().replace(/[A-Z]/g, replaceAlpha), 10);
  cle =  97 - (((parseInt(banque, 10)% 97 * 100000 + parseFloat(guichet)) % 97 * 100000000000 + compte) % 97) * 100 % 97;
  return cle;
}

/**
 * Donne le focus à l'élement suivant automatiquement
 *
 * @param field Le champ courant
 * @param limit La limite de caractère souhaitée
 * @param next Le champ suivant
 * @param evt Evénement envoyé à la pression de la touche
 *
 * Ex: onkeyup="autofocus(this, 2, 'cc2', event)"
 */
function autofocus(field, limit, next, evt) {
		var stop = field.value.length == limit;
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && stop) {
    		field.form.elements[next].select();
    }
    return false;
}

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.version = navigator.appVersion;
        this.userAgent = navigator.userAgent;
        this.v = parseInt(this.version);
        this.ns = (this.b=="ns" && this.v>=5);
        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.ie = (this.b=="ie" && this.v>=4);
        this.ie4 = (this.version.indexOf('MSIE 4')>0);
        this.ie5 = (this.version.indexOf('MSIE 5.0')>0);
        this.ie55 = (this.version.indexOf('MSIE 5.5')>0);
        this.ie6 = (this.version.indexOf('MSIE 6.0')>0);
        this.min = (this.ns||this.ie);
}
is = new BrowserCheck();  /* automatically create the "is" object*/

//
//	Formulaire
//
/*
function goto_location(code,pays,bourse,categorie) {
  if(code=='')
     {location.href="/resultat_recherche_code.phtml";return false;}
  if(parent!=null)
     parent.location.href='/cours.phtml?code='+escape(code)+'&choix_bourse='+escape(bourse)+'&categorie='+escape(categorie);
  else
     location.href='/cours.phtml?code='+escape(code)+'&choix_bourse='+escape(bourse)+'&categorie='+escape(categorie);
  return false;
}
*/

function select_value(select,value){
	for(i=0;i < select.options.length;i++){
		if(select.options[i].value==value){
			select.options[i].selected=true;
			return true;
		}
	}

	return false;
}

function select_radio(radio,value){
	if (radio.selectionEnd) {
	   for(i=0;i<radio.length;i++){
	      if(radio[i].value==value){
	         radio[i].checked=true;
	         return;
	      }
	   }
	}
	else {
		radio.checked=true;
	}
}

//
//	POPUP
//
function popup(f,nom, w, h) {
   var top=0;
   var left=0;
   if (self.screen)
      left=(screen.width-(w+((screen.width*1)/100)));
   myWin = window.open(f, nom, 'resizable,screenX=0,screenY=0,scrollbars=yes,menubar=yes,top='+top+',left='+left +',width=' + w + ',height=' + h );
   myWin.focus();
}

function tinypopup(f,nom, w, h) {
   var top=0;
   var left=0;
   if (self.screen)
      left=(screen.width-(w+((screen.width*1)/100)));
   myWin = window.open(f, nom, 'resizable,screenX=0,screenY=0,scrollbars=no,menubar=no,top='+top+',left='+left +',width=' + w + ',height=' + h );
   myWin.focus();
}

function littlepopup(f,nom, w, h) {
   var top=0;
   var left=0;
   if (self.screen)
      left=(screen.width-(w+((screen.width*1)/100)));
   myWin = window.open(f, nom, 'resizable,screenX=0,screenY=0,scrollbars=yes,menubar=no,top='+top+',left='+left +',width=' + w + ',height=' + h );
   myWin.focus();
}

function centeredpopup(f,nom, w, h) {
  var posX = (screen.width / 2) - (w / 2);
  var posY = (screen.height / 2) - (h / 2);
   if (self.screen)
      left=(screen.width-(w+((screen.width*1)/100)));
   myWin = window.open(f, nom, 'resizable,screenX=0,screenY=0,scrollbars=no,menubar=no,top='+posY+',left='+posX +',width=' + w + ',height=' + h );
   myWin.focus();
}

//
//	SmartAdServer
//
sas_tmstp=Math.round(Math.random()*10000000000);

function SmartAdServer(sas_pageid,sas_formatid,sas_master,sas_target) {
	if ((sas_master!='M')&&(sas_master!='S')) {sas_master='S'};
	document.write('<SCR'+'IPT SRC="' + document.location.protocol +'//ads.boursorama.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></SCR'+'IPT>');
}

/*
function SmartAdServer_div(sas_pageid,sas_formatid,sas_master,sas_target, mondiv)
{
  if((sas_master != 'M') && (sas_master != 'S'))
    sas_master='S';

  $(mondiv).innerHTML = '<SCR'+'IPT SRC="' + document.location.protocol +'//ads.boursorama.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></SCR'+'IPT>';
}
*/

function SmartAdServer_iframe(sas_pageid,sas_formatid,sas_master,sas_target,sas_w,sas_h) {
   if ((sas_master!='M')&&(sas_master!='S'))
      {sas_master='S'};
   document.write('<IFRAME SRC="'+ document.location.protocol +'//ads.boursorama.com/call/pubif/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?" width=' + sas_w + ' height=' + sas_h + ' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center>');
   document.write('<scr'+'ipt language=Javascr'+'ipt>\ndocument.write\(\'<SCR\'+\'IPT SRC="'+ document.location.protocol +'//ads.boursorama.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></SCR\'+\'IPT>\'\)\;\n</scr'+'ipt>');
   document.write('</IFRAME>');
}

/*
function SmartAdServer_iframe_div(sas_pageid,sas_formatid,sas_master,sas_target,sas_w,sas_h, mondiv)
{
  if((sas_master!='M')&&(sas_master!='S'))
    sas_master='S';

  code_html = '<IFRAME SRC="'+ document.location.protocol +'//ads.boursorama.com/call/pubif/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?" width=' + sas_w + ' height=' + sas_h + ' marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no align=center>';
  code_html = code_html + '<scr'+'ipt language=Javascr'+'ipt>\ndocument.write\(\'<SCR\'+\'IPT SRC="'+ document.location.protocol +'//ads.boursorama.com/call/pubj/' + sas_pageid + '/' + sas_formatid + '/'+sas_master + '/' + sas_tmstp + '/' + escape(sas_target) + '?"></SCR\'+\'IPT>\'\)\;\n</scr'+'ipt>';
  code_html = code_html + '</IFRAME>';

  $(mondiv).innerHTML = code_html;
}
*/


function changeParent(url)
{
   if(document.opener)
      opener.document.location.href(url);
   else
      window.open(url,'nouveau');
   return false;
}
function blank(url){
	window.open(url,'nouveau');
}
function show_layer(layer) {
   var elm;
   if (is.ns4){
      elm = document.layers[layer];
   }
   else if (is.ie4) {
      elm = document.all[layer];
   }
   else if(document.getElementById(layer)) {
      elm = document.getElementById(layer);
   }
   elm.style.visibility = "visible";
}

function hide_layer(layer) {
	var elm;

	if (is.ns4)
		elm = document.layers[layer];
	else if (is.ie4)
		elm = document.all[layer];
	else if ($(layer))
		elm = $(layer);
	if(elm) {
	   if(elm.style.display)
		   elm.style.display = "none";
	   else
		   elm.style.visibility = "hidden";
	}
}

function reload_layer(layer) {
   var elm;

   if (is.ns4){
      elm = document.layers[layer];
   }
   else if (is.ie4) {
      elm = document.all[layer];
   }
   else if (document.getElementById(layer)) {
      elm = document.getElementById(layer);
   }
   if(elm) { elm.location.reload(); }
}


function ereg_replace(tx,rg,ch) {
   var regEx = new RegExp(rg,"g")
   return tx.replace(regEx,ch)
}

function checkIdentifiant(login,password,formulaire)
{
  if(login.search(/^[0-9]+$/) > -1 && password=='')
  {
  		return false;
  }
  if(login=='')
  {
     alert('Vous devez renseigner votre login.');
     return false;
  }
  else if(password=='')
  {
     alert('Vous devez renseigner votre mot de passe.');
     return false;
  }
  return true;
}


function hideLogAuto(login, idCheckBox){
	if(login.search(/^[0-9]+$/) > -1)
		$(idCheckBox).style.visibility = "hidden";
	else
		$(idCheckBox).style.visibility = "visible";
}

function isLoginClient(login){
	if(login.search(/^[0-9]+$/) > -1) {
		return true;
	}
	else {
		$('blocmemo').style.visibility = "visible";
		return false;
	}
}

function adjustIFrameSize (iframeWindow,adjustX) {
	if (adjustX == undefined) {
		adjustX = false;
	}

	if (iframeWindow.document.height) {
		var iframeElement = parent.document.getElementById(iframeWindow.name);
		iframeElement.style.height = iframeWindow.document.height + 'px';
		if (adjustX)
			iframeElement.style.width = iframeWindow.document.width + 'px';
	}
	else if (document.all) {
		var iframeElement = parent.document.all[iframeWindow.name];
		if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat')  {
			iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight +  5 +  'px';
			if (adjustX)
				iframeElement.style.width = iframeWindow.document.documentElement.scrollWidth +  5 +  'px';
		}
		else {
			iframeElement.style.height = iframeWindow.document.body.scrollHeight  + 5 +  'px';
			if (adjustX)
				iframeElement.style.width = iframeWindow.document.body.scrollWidth  + 5 +  'px';
		}
	}
}


function openInParentWindow(url, selfClose, top){
	if(window.opener){
		var mywindow = window.opener;
		
		if(top){
			mywindow = mywindow.top;
		}
		
		mywindow.location.href=url;
		if(selfClose) self.close();
	}

	else{
		popup(url, 'new_window', 800, 600)
	}
}


function sauveWinPRT(windowprt)
{
   win = windowprt;
   x=win.screenLeft;
   y=win.screenTop;
//   name = win.name;

   // Pour Netscape
   if (x==undefined) x=win.screenX;
   if (y==undefined) y=win.screenY;

  var w=0,h=0;
  if(typeof(win.innerWidth)=='number'){
      w=win.innerWidth;
      h=win.innerHeight;
      }
  if (!w && !h){
    with(win.document){
         if (documentElement && (documentElement.offsetWidth || documentElement.offsetHeight)){
              w=documentElement.offsetWidth;
              h=documentElement.offsetHeight;
              }
        else if (body && (body.offsetWidth || body.offsetHeight)){
              w=body.offsetWidth;
              h=body.offsetHeight;
              }
        }
    }
   try{
     windowprt.opener.parent.framedown.location='https://boursorama.it-finance.com/secure/Boursorama/save_winparams.phtml?name0='+win.name+'&x0='+x+'&y0='+y+'&h0='+h+'&w0='+w;
   }
   catch(e){}

}



//
//	DHTML
//

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}

	else if (obj.x)
		curleft += obj.x;

	return curleft;
}


function findPosY(obj){
	var curtop = 0;

	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}

	else if (obj.y)
		curtop += obj.y;

	return curtop;
}


function getScrollTop(){
	var top = 0;

	if (self.pageYOffset) // all except Explorer
		top = self.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)  // Explorer 6 Strict
		top = document.documentElement.scrollTop;
	else if (document.body)  // all other Explorers
		top = document.body.scrollTop;

	return top;
}


function getScrollLeft(){
	left = 0;

	if (self.pageXOffset)  // all except Explorer
		left = self.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft) // Explorer 6 Strict
		left = document.documentElement.scrollLeft;
	else if (document.body) // all other Explorers
		left = document.body.scrollLeft;

	return left;
}


function getWindowHeight(){
	var y;
	if (self.innerHeight)// all except Explorer
		y = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
		y = document.documentElement.clientHeight;
	else if (document.body) // other Explorers
		y = document.body.clientHeight;

	return y;
}

function getWindowWidth(){
	var x;
	if (self.innerHeight) // all except Explorer
		x = self.innerWidth;
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
	else if (document.body) // other Explorers
		x = document.body.clientWidth;

	return x;
}


//
//	Code
//

if(document.cookie.indexOf('NAVVER=')<0)
{
   if(is.min)
      document.cookie = 'NAVVER=OK';
   else
      document.cookie = 'NAVVER=NOK';
}

function modifySearchForm(selectedValue){
	var searchCategorie = $("searchCategorie");
	var choixBourse = $("span_choix_bourse");
	var searchType = $("searchType");
	var query = $("query");
	//var site = $("site");

	if(selectedValue == "cotations"){
		searchCategorie.style.display = "inline";
		choixBourse.style.display = "inline";
		query.style.width="180";
		//site.style.display="none";
	}

	else if(selectedValue == "actualites"){
		searchCategorie.style.display = "none";
		choixBourse.style.display = "none";
//		searchType.style.width="50";
		query.style.width="300";
		//site.style.display="inline";
	}

	else{
		searchCategorie.style.display = "none";
		choixBourse.style.display = "none";
		query.style.width="300";
		//site.style.display="none";
	}
}


function displayFrame(idFrame,ancre){
	if(idFrame.style.display == 'none' || idFrame.style.display == '') {
		if(ancre.id != 'lienTetiere' && ancre.id!='accueilTetiere')
			idFrame.src = '/membres/mes_icones.phtml?idAdd='+ancre.id;
		idFrame.style.display='inline';
		idFrame.style.left =  findPosX(ancre) - 175 +'px';
		idFrame.style.top =  findPosY(ancre) + ancre.offsetHeight + 4 +'px';
	} else {
		idFrame.style.display='none';
		idFrame.style.top =  '0 px';
		idFrame.style.left =  '0 px';
	}
}


function displayApplet(codeApplet, idElement){
	$(idElement).innerHTML = codeApplet;
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Author: Matt Kruse <matt@ajaxtoolbox.com>
// WWW: http://www.AjaxToolbox.com/
function AjaxRequest(){var req =new Object();
req.timeout =null;
req.generateUniqueUrl =true;
req.url =window.location.href;
req.method ="GET";
req.async =true;
req.username =null;
req.password =null;
req.parameters =new Object();
req.requestIndex =AjaxRequest.numAjaxRequests++;
req.responseReceived =false;
req.groupName =null;
req.queryString ="";
req.responseText =null;
req.responseXML =null;
req.status =null;
req.statusText =null;
req.aborted =false;
req.xmlHttpRequest =null;
req.onTimeout=null;
req.onLoading=null;
req.onLoaded=null;
req.onInteractive=null;
req.onComplete=null;
req.onSuccess=null;
req.onError=null;
req.onGroupBegin=null;
req.onGroupEnd=null;
req.xmlHttpRequest =AjaxRequest.getXmlHttpRequest();
if(req.xmlHttpRequest==null){return null;}req.xmlHttpRequest.onreadystatechange =
function(){if(req==null || req.xmlHttpRequest==null){return;}if(req.xmlHttpRequest.readyState==1){req.onLoadingInternal(req);}if(req.xmlHttpRequest.readyState==2){req.onLoadedInternal(req);}if(req.xmlHttpRequest.readyState==3){req.onInteractiveInternal(req);}if(req.xmlHttpRequest.readyState==4){req.onCompleteInternal(req);}};
req.onLoadingInternalHandled=false;
req.onLoadedInternalHandled=false;
req.onInteractiveInternalHandled=false;
req.onCompleteInternalHandled=false;
req.onLoadingInternal=
function(){if(req.onLoadingInternalHandled){return;}AjaxRequest.numActiveAjaxRequests++;
if(AjaxRequest.numActiveAjaxRequests==1 && typeof(window['AjaxRequestBegin'])=="function"){AjaxRequestBegin();}if(req.groupName!=null){if(typeof(AjaxRequest.numActiveAjaxGroupRequests[req.groupName])=="undefined"){AjaxRequest.numActiveAjaxGroupRequests[req.groupName] =0;}AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==1 && typeof(req.onGroupBegin)=="function"){req.onGroupBegin(req.groupName);}}if(typeof(req.onLoading)=="function"){req.onLoading(req);}req.onLoadingInternalHandled=true;};
req.onLoadedInternal=
function(){if(req.onLoadedInternalHandled){return;}if(typeof(req.onLoaded)=="function"){req.onLoaded(req);}req.onLoadedInternalHandled=true;};
req.onInteractiveInternal=
function(){if(req.onInteractiveInternalHandled){return;}if(typeof(req.onInteractive)=="function"){req.onInteractive(req);}req.onInteractiveInternalHandled=true;};
req.onCompleteInternal=
function(){if(req.onCompleteInternalHandled || req.aborted){return;}req.onCompleteInternalHandled=true;
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(req.groupName!=null){AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd(req.groupName);}}req.responseReceived =true;
req.status =req.xmlHttpRequest.status;
req.statusText =req.xmlHttpRequest.statusText;
req.responseText =req.xmlHttpRequest.responseText;
req.responseXML =req.xmlHttpRequest.responseXML;
if(typeof(req.onComplete)=="function"){req.onComplete(req);}if(req.xmlHttpRequest.status==200 && typeof(req.onSuccess)=="function"){req.onSuccess(req);}else if(typeof(req.onError)=="function"){req.onError(req);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;};
req.onTimeoutInternal=
function(){if(req!=null && req.xmlHttpRequest!=null && !req.onCompleteInternalHandled){req.aborted =true;
req.xmlHttpRequest.abort();
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(req.groupName!=null){AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd(req.groupName);}}if(typeof(req.onTimeout)=="function"){req.onTimeout(req);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;}};
req.process =
function(){if(req.xmlHttpRequest!=null){if(req.generateUniqueUrl && req.method=="GET"){req.parameters["AjaxRequestUniqueId"] =new Date().getTime() + "" + req.requestIndex;}var content =null;
for(var i in req.parameters){if(req.queryString.length>0){req.queryString +="&";}req.queryString +=encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]);}if(req.method=="GET"){if(req.queryString.length>0){req.url +=((req.url.indexOf("?")>-1)?"&":"?") + req.queryString;}}req.xmlHttpRequest.open(req.method,req.url,req.async,req.username,req.password);
if(req.method=="POST"){if(typeof(req.xmlHttpRequest.setRequestHeader)!="undefined"){req.xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}content =req.queryString;}if(req.timeout>0){setTimeout(req.onTimeoutInternal,req.timeout);}req.xmlHttpRequest.send(content);}};
req.handleArguments =
function(args){for(var i in args){if(typeof(req[i])=="undefined"){req.parameters[i] =args[i];}else{req[i] =args[i];}}};
req.getAllResponseHeaders =
function(){if(req.xmlHttpRequest!=null){if(req.responseReceived){return req.xmlHttpRequest.getAllResponseHeaders();}alert("Cannot getAllResponseHeaders because a response has not yet been received");}};
req.getResponseHeader =
function(headerName){if(req.xmlHttpRequest!=null){if(req.responseReceived){return req.xmlHttpRequest.getResponseHeader(headerName);}alert("Cannot getResponseHeader because a response has not yet been received");}};
return req;}AjaxRequest.getXmlHttpRequest =function(){if(window.XMLHttpRequest){return new XMLHttpRequest();}else if(window.ActiveXObject){/*@cc_on @*/
/*@if(@_jscript_version >=5)
try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(E){return null;}}@end @*/}else{return null;}};
AjaxRequest.isActive =function(){return(AjaxRequest.numActiveAjaxRequests>0);};
AjaxRequest.get =function(args){AjaxRequest.doRequest("GET",args);};
AjaxRequest.post =function(args){AjaxRequest.doRequest("POST",args);};
AjaxRequest.doRequest =function(method,args){if(typeof(args)!="undefined" && args!=null){var myRequest =new AjaxRequest();
myRequest.method =method;
myRequest.handleArguments(args);
myRequest.process();}};
AjaxRequest.submit =function(theform, args){var myRequest =new AjaxRequest();
if(myRequest==null){return false;}var serializedForm =AjaxRequest.serializeForm(theform);
myRequest.method =theform.method.toUpperCase();
myRequest.url =theform.action;
myRequest.handleArguments(args);
myRequest.queryString =serializedForm;
myRequest.process();
return true;};
AjaxRequest.serializeForm =function(theform){var els =theform.elements;
var len =els.length;
var queryString ="";
this.addField =
function(name,value){if(queryString.length>0){queryString +="&";}queryString +=encodeURIComponent(name) + "=" + encodeURIComponent(value);};
for(var i=0;i<len;i++){var el =els[i];
if(!el.disabled){switch(el.type){case 'text': case 'password': case 'hidden': case 'textarea':
this.addField(el.name,el.value);
break;
case 'select-one':
if(el.selectedIndex>=0){this.addField(el.name,el.options[el.selectedIndex].value);}break;
case 'select-multiple':
for(var j=0;j<el.options.length;j++){if(el.options[j].selected){this.addField(el.name,el.options[j].value);}}break;
case 'checkbox': case 'radio':
if(el.checked){this.addField(el.name,el.value);}break;}}}return queryString;};
AjaxRequest.numActiveAjaxRequests =0;
AjaxRequest.numActiveAjaxGroupRequests =new Object();
AjaxRequest.numAjaxRequests =0;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

// FAST TRADING
function requestFT(url,ftdiv) {
	ftdiv.style.height='21';
	document.body.onclick=function() { ftdiv.style.display='none';if ($('a_la_une')) $('a_la_une').style.display='inline'; };
	AjaxRequest.get(
	{
	  'url' : url ,
	  'onLoading' : function() { ftdiv.style.display='block';ftdiv.innerHTML='<div>Chargement ...</div>';},
	  'onSuccess' : function(req) {
				chaine=req.responseText;
				var reg=new RegExp("[ ]+", "g");
				arrayOfStrings = chaine.split(reg);
				for(i=0;i<arrayOfStrings.length;i++) {
					eval(arrayOfStrings[i]);
				}
				if(erreur!='') {
					var reg=new RegExp("&nbsp;", "g");
					ftdiv.innerHTML = erreur.replace(reg,' ');
					if(typeof(params_order) == 'undefined') {
						setTimeout("document.all."+ftdiv.id+".style.display='none';",2000);
					}
					else {
						if ($('a_la_une'))
							$('a_la_une').style.display='none';
						ftdiv.style.height='150';
						params_order = params_order.split('|');
						params_string = params_string.split('|');
						for(i=0;i<params_order.length;i++) {
							ftdiv.innerHTML += "<li><a href=\"javascript:littlepopup('/clients/trading/ordres/ordre.phtml?forprint=yes&"+params_order[i]+"','_PO_' + Math.round(Math.random()*10000000000),700,430);\">"+params_string[i]+"</a><br>";
						}
					}
				}
				else if(typeof(annul) != 'undefined') {
					if ($('a_la_une'))
						$('a_la_une').style.display='none';
					ftdiv.style.height='150';
					AjaxRequest.get(
						{
						  'url' : '/clients/fasttrading/?DetailCompte&package=clients&actionEvent=getListeOrdres&compte='+decodeURI(compte) ,
						  'onLoading' : function() { ftdiv.style.display='block';ftdiv.innerHTML='<div>Chargement ...</div>';},
						  'onSuccess' : function(req) {ftdiv.innerHTML=req.responseText;}
						});
				}
				else if(typeof(sold) != 'undefined') {
					if ($('a_la_une'))
						$('a_la_une').style.display='none';
					ftdiv.style.height='150';
					AjaxRequest.get(
						{
						  'url' : '/clients/fasttrading/?DetailCompte&package=clients&actionEvent=getPortefeuille&instantanee&compte='+decodeURI(compte) ,
						  'onLoading' : function() { ftdiv.style.display='block';ftdiv.innerHTML='<div>Chargement ...</div>';},
						  'onSuccess' : function(req) {ftdiv.innerHTML=req.responseText;}
						});
				}
				else {
					ftdiv.style.display='none';
					littlepopup('/clients/trading/ordres/ordre.phtml?forprint=yes&'+params_order,'_PO_' + Math.round(Math.random()*10000000000),700,430);
				}
			}
	}
	);params_order=undefined;params_string=undefined;annul=undefined;sold=undefined;
	return false;
}

function boursoPrint()
{
  fileref=document.createElement('link');
  fileref.setAttribute('rel','stylesheet');
  fileref.setAttribute('type', 'text/css');
  fileref.setAttribute('href', '/css/print.css');
  fileref.setAttribute('media', 'print');
  document.getElementsByTagName('head').item(0).appendChild(fileref);
}

function autoSubmitFT(input,evt) {
	evt = (evt) ? evt : event;
	var target = (evt.target) ? evt.target : evt.srcElement;
	var form = target.form;
	var charCode = (evt.charCode) ? evt.charCode :
		((evt.which) ? evt.which : evt.keyCode);
	if (charCode == 108) {
		if (input.value.search(/annu/) != -1) {
			input.value += 'l';
			if(form.onsubmit())
				form.submit();
			return false;
		}
	 }
	 if (charCode == 101) {
		if (input.value.search(/sold/) != -1) {
			input.value += 'e';
			if(form.onsubmit())
				form.submit();
			return false;
		}
	 }
	return true;
}

function autosearch(input,ftdiv)
{
	if(input.value.length>3)
	{
					ftdiv.style.height='150';
					document.body.onclick=function() { ftdiv.style.display='none';if ($('a_la_une')) $('a_la_une').style.display='inline'; };
					AjaxRequest.get(
						{
						  'url' : '/getListCompany.phtml?search='+input.value,
						  'onLoading' : function() { ftdiv.innerHTML='<div>Chargement ...</div>';},
						  'onSuccess' : function(req) {ftdiv.style.display='block';ftdiv.innerHTML=req.responseText;}
						});
//		return false;
	}
}


//MENU
var idTimeout;

var pause = 400;

var iframesMenu = new Array(2);
iframesMenu[0] = $("iframe_menu1");
iframesMenu[1] = $("iframe_menu2");

var displayedMenus = Array(3);
displayedMenus[0] = "";
displayedMenus[1] = "";
displayedMenus[2] = "";

var menusHiding = Array(3);
menusHiding[0] = "";
menusHiding[1] = "";
menusHiding[2] = "";

var overItems = Array(3);
overItems[0] = "";
overItems[1] = "";
overItems[2] = "";

var overClassNames = Array(3);
overClassNames[0] = "";
overClassNames[1] = "";
overClassNames[2] = "";

function displayMenu(idMenuToDisplay, idOverItem, level){
	if(!iframesMenu[0]){
		iframesMenu[0] = $("iframe_menu1");
		iframesMenu[1] = $("iframe_menu2");
	}

	var menuToDisplay = $(idMenuToDisplay);
	var overItem = $(idOverItem);

	menu_X = findPosX(overItem) + overItem.offsetWidth -1;
	menu_Y = findPosY(overItem);

	//On place le calque
	menuToDisplay.style.display = "block";
	menuToDisplay.style.top = menu_Y + "px";
	menuToDisplay.style.left = menu_X + "px";

	//On vérfie l'espace restant pour afficher le menu
	if(self.innerHeight)
		documentHeight = parseInt(self.innerHeight) + getScrollTop();
	else
		documentHeight = parseInt(document.body.clientHeight) + getScrollTop();

	if(menuToDisplay.offsetHeight + menu_Y > documentHeight)
		menu_Y = menu_Y - ((menu_Y + menuToDisplay.offsetHeight) - documentHeight);


	//On place l'iframe
	if(iframesMenu[level]){
		iframesMenu[level].style.top = menu_Y + "px";
		iframesMenu[level].style.left = menu_X + "px";
		iframesMenu[level].style.height = menuToDisplay.offsetHeight+ "px";
		iframesMenu[level].style.width = menuToDisplay.offsetWidth + "px";
		iframesMenu[level].style.display = "block";
	}

	//Si le menu à atteint le bas de l'écran, on le remonte
	if(menu_Y != menuToDisplay.style.top)
		menuToDisplay.style.top = menu_Y + "px";


	displayedMenus[level] = idMenuToDisplay;
}

function hideLevelMenu(level){
	for(i=level; i<displayedMenus.length; i++){
		menuToHide = $(displayedMenus[i]);

		if(iframesMenu[i]){
			/*
			iframesMenu[i].style.top = "0px";
			iframesMenu[i].style.left = "0px";
			*/
			iframesMenu[i].style.display = "none";
		}

		if(menuToHide){
			/*
			menuToHide.style.top = "0px";
			menuToHide.style.left = "0px";
			*/
			menuToHide.style.display = "none";
		}

		if(overItems[i] != ""){
			//$(overItems[i]).style.backgroundColor="";
			$(overItems[i]).className = overClassNames[i];
			overItems[i] = "";
			overClassNames[i] = "";
		}

		displayedMenus[i] = "";
	}
}


function changeMenu(event, idMenuToDisplay, idOverItem, overClassName, level){
	if(displayedMenus[level] != idMenuToDisplay){
		stopHideMenu(level);
		hideLevelMenu(level);

		if(idMenuToDisplay != null)
			displayMenu(idMenuToDisplay, idOverItem, level);
	}

	if(overItems[level] != ""){
		//$(overItems[level]).style.backgroundColor="";
		$(overItems[level]).className = overClassNames[level];
		//overItems[level] = "";
		//overClassNames[level] = "";
	}

	//$(idOverItem).style.backgroundColor=color;
	overClassNames[level] = $(idOverItem).className;
	$(idOverItem).className=overClassName;

	overItems[level] = idOverItem;
}

function stopHideMenu(level){
	for(i=level; i>=0; i--){
		window.clearTimeout(menusHiding[i]);
		menusHiding[i] = "";
	}
}

function hideMenu(e, idAreaToTest, levelToHide){
	var areaToTest = $(idAreaToTest);

	_X = findPosX(areaToTest);
	_Y = findPosY(areaToTest);
	_width = areaToTest.offsetWidth;
	_height = areaToTest.offsetHeight;

	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}

	var inside = posx > _X && posx < (_X+_width) && posy > _Y && posy <= (_Y+_height);

	if(!inside){
		menusHiding[levelToHide] = window.setTimeout('hideLevelMenu("'+levelToHide+'")', pause);
	}
}

function open_iframe(src, iframe_name, isPopup, iframeWidth, iframeHeight, idInElt, iframeX, iframeY){
	//On recherche si cette iframe a déjà été ouverte
	iframes = document.getElementsByTagName("IFRAME");
	for(i=0; i<iframes.length; i++){
		if(iframes[i].name != "" && iframes[i].name == iframe_name)
			iframes[i].parentNode.removeChild(iframes[i]);
	}

	style = "border:1px solid #9E9FA1;z-index:11;";

	if(isPopup) {
		inElt = document.createElement("DIV");
		document.body.appendChild(inElt);

		style += "position:absolute;top:" + iframeY + "px;left:" + iframeX +"px;";
		
		overlay_width = (is.ie)? document.body.scrollWidth : document.body.offsetWidth;
		overlay_height = (is.ie)? document.body.scrollHeight : document.body.offsetHeight;
		
		var overlay = '<div id="overlay_'+iframe_name+'" style="z-index:10;position:absolute;top:0px;left:0px;height:'+overlay_height+';width:'+overlay_width+';background-color:#000000;opacity:0.5;filter:Alpha(opacity=50);-khtml-opacity:0.5;-moz-opacity:0.5;" onclick="close_iframe(document.getElementById(\''+iframe_name+'\'));"></div>';
	}
	else{
		inElt= $(idInElt);
		inElt.style.display = "block";
		
		var overlay = '';
	}

	inElt.innerHTML = overlay  +
					'<iframe name="'+iframe_name+'" ' +
					'src="'+src+'" id="'+iframe_name+'" ' +
					'style="' + style + '" '+
					'frameborder="no" scrolling="no" ' +
					'height="'+iframeHeight+'" width="'+iframeWidth+'"></iframe>';

	return $(iframe_name);
}

function close_iframe(iframe){
	if (iframe.parent) {
		iframes = iframe.parent.document.getElementsByTagName("IFRAME");
		overlay_div = iframe.parent.document.getElementById('overlay_'+iframe.name);
	}
	else {
		iframes = document.getElementsByTagName("IFRAME");
		overlay_div = document.getElementById('overlay_'+iframe.name);
	}

	for(var i=0; i<iframes.length; i++){
		if(iframes[i].name != "" && iframe.name != "" && iframe.name == iframes[i].name){
			iframes[i].parentNode.style.display = "none";
			iframes[i].parentNode.removeChild(iframes[i]);
			break;
		}
	}
	
	overlay_div.style.display = "none";
	overlay_div.parentNode.removeChild(overlay_div);
}


//
//	Dossier Personnel + contextuel
//
idHiddingContextual = null;
function open_contextual(position,content,iframe){
	if(idHiddingContextual == null){
		eltFrom = $(position);
		elt_dp = $(content);
		elt_iframe_dp = $(iframe);

		elt_dp.style.display="inline";

		_X = findPosX(eltFrom) - (elt_dp.offsetWidth - eltFrom.offsetWidth);
		_Y = findPosY(eltFrom) + parseInt(eltFrom.offsetHeight) - 6;

		elt_dp.style.top = _Y;
		elt_dp.style.left = _X;

		elt_iframe_dp.style.top = _Y;
		elt_iframe_dp.style.left = _X;
		elt_iframe_dp.style.height = elt_dp.offsetHeight;
		elt_iframe_dp.style.width = elt_dp.offsetWidth;
		elt_iframe_dp.style.display="inline";
	}
	else{
		window.clearTimeout(idHiddingContextual);
		idHiddingContextual = null;
	}
}

function close_contextual(content,iframe){
	idHiddingContextual = window.setTimeout("close_contextual2('"+content+"','"+iframe+"')", 300);
}

function close_contextual2(content,iframe){
	$(content).style.display="none";
	$(iframe).style.display="none";
	idHiddingContextual = null;
}


function addUrlToDossierPerso(type, url, libelle, id){
	if(type == "favoris"){
		libelle = prompt("Donner un nom à votre raccourci : ", libelle);
		if(libelle == null) return;
		var url = '/membres/dossier_personnel/add.phtml?type='+escape(type)+'&url='+escape(url)+'&libelle='+escape(libelle);
	}
	else
		var url = '/membres/dossier_personnel/add.phtml?type='+escape(type)+'&id='+escape(id);

	AjaxRequest.get({
		'url' : url,
		'onSuccess' : function(req) {
			try{
				var obj = eval('('+req.responseText+')');

				if(obj.debug) alert("add : " + obj.debug);

				if(obj.error)
					alert(obj.error);
				else{
					if(type == "news" && obj.html && $('div_action_news'))
						$('div_action_news').innerHTML = obj.html;
					else if(type == "messages" && obj.html && $('feedback_action'))
						$('feedback_action').innerHTML = obj.html;

					refreshDossierPerso(type);
				}
			}catch(e){
			}
		}
	});
}

function deleteUrlToDossierPerso(type, id){
	var elt = $("dp_"+type+"_" + id);
	if(!elt) return;

	if(confirm("Etes-vous de vouloir supprimer ce lien : " + elt.title + " ?")){
		AjaxRequest.get({
			'url' : '/membres/dossier_personnel/delete.phtml?type='+type+'&id='+id,
			'onSuccess' : function(req) {
				try{
					var obj = eval('('+req.responseText+')');

					if(obj.error)
						alert(obj.error);
					else
						refreshDossierPerso(type);
				}catch(e){
				}
			}
		});
	}
}

function refreshDossierPerso(type){
	if(type != null){
		var div = $('dp_' + type);

		AjaxRequest.get({
			'url' : '/membres/dossier_personnel/refresh.phtml?type='+type,
			'onSuccess' : function(req) {
				try{
					var obj = eval('('+req.responseText+')');

					if(obj.error)
						alert(obj.error);
					else if(typeof obj.html=="string"){
						div.innerHTML = obj.html;
						selectDPDiv(type);
					}
				}catch(e){
				}
			}
		});
	}
}

function selectDPDiv(type){
	var types = new Array(4);
	types[0] = "favoris";
	types[1] = "notes";
	types[2] = "messages";
	types[3] = "news";

	for(i=0; i<types.length; i++){
		if(type == types[i]){
			$("dp_" + types[i]).style.display = 'block';
			$("lien_dp_"+types[i]).className = "lien_dp_selected";
		}
		else{
			$("dp_" + types[i]).style.display = 'none';
			$("lien_dp_"+types[i]).className = "";
		}
	}

	if(type == "favoris")
		$("sousMenu_dp").innerHTML = '<a href="#" onclick="addUrlToDossierPerso(\'favoris\', window.location.pathname+window.location.search, document.title)"> + Ajouter à mes favoris</a>';
	else if(type == "notes")
		$("sousMenu_dp").innerHTML = '<a href="#" onclick="tinypopup(\'/membres/edition/add_webnotes.phtml\', \'add_webnotes_popup\', 500, 210)">Ajouter une note</a> | <a href="/membres/mes_webnotes.phtml" href="/membres/mes_webnotes.phtml">Mes notes</a>';
	else
		$("sousMenu_dp").innerHTML = "&nbsp;";

}


function getUrlParameters(url){
	parameters = {};
	indexCarac = url.indexOf('?');

	if(indexCarac > -1){
		items = url.slice(indexCarac+1).split('&');

		for(a=0; a<items.length; a++){
			indexCarac = items[a].indexOf('=');

			if(indexCarac > -1)
				parameters[items[a].slice(0, indexCarac)] = items[a].slice(indexCarac + 1);
			else if(items[a].length == 1)
				parameters[items[a]] = '';
		}
	}

	return parameters;
}
function switchDisplayDiv(sTrigger,iDisplay,iTotalDivs)
{
	var wantedDiv		= document.getElementById(sTrigger + iDisplay);
	for (var i = 1; i <= iTotalDivs; i++)
	{
		if (i != iDisplay)
		{
			document.getElementById(sTrigger + i).style.display = 'none';
		}
	}
	if (wantedDiv.style.display == 'none')
	{
		wantedDiv.style.display = ''; // /!\ style.display='block' does not work correctly with FF
	}
}