/** */
var checkFormContact = {
	errmsg: null, theForm: null, fields:[], originVal : [], submitButton: null,
	set : function(){
		this.errmsg = document.getElementById('message_error_alert2');

		this.theForm = document.form_contact;
		this.fields = this.theForm.elements;

		for (var i=0;i<this.fields.length;i++){/** saving original values */
			this.originVal[i] = this.fields[i].value;
			this.fields[i].saveVarI  =i;
			this.fields[i].onfocus = function(){
				if (this.value==checkFormContact.originVal[this.saveVarI] || this.value==mailErrorMsg) this.value = '';
			}
			this.fields[i].onblur = function(){
				if (this.value.trim()=='') this.value = checkFormContact.originVal[this.saveVarI];
			}
			if(this.fields[i].type=='submit'){
				this.submitButton = this.fields[i];
				this.submitButton.oldValue = this.submitButton.value;
			}
		}
		
		this.theForm.onsubmit = function () {
			if (checkFormContact.submitForm()==false) { // test des champs
				checkFormContact.submitButton.disabled = false;//reactive le bouton submit
				checkFormContact.submitButton.value = checkFormContact.submitButton.oldValue;
				return false;
			} else {
				checkFormContact.sendAjaxRqst();
				return false;
			}
		}
	},
	submitForm : function () {
		this.submitButton.disabled = true;
		var errors=0;
		for (var i=0;i<this.fields.length;i++){
			this.fields[i].className = this.fields[i].className.replace(' error','');//restauration du style
			if (this.fields[i].className.indexOf('textchk')>=0) {
				if (onforms.emptyCheck(this.fields[i].value)==false || this.fields[i].value == this.originVal[i]){
					errors++;
					this.fields[i].className += " error";
				}
			}
			if (this.fields[i].className.indexOf('mailchk')>=0) {
				if (onforms.mailcheck(this.fields[i].value)==false) {
					errors++;
					this.fields[i].className += " error";
					this.fields[i].value = mailErrorMsg;
				}
			}
		}
		if (errors>0) {
			this.errmsg.innerHTML = emptyErrorMsg;
			return false;
		}
		return true;
	},
	sendAjaxRqst: function(){/** envoi form ajax */
		var oFormElts = this.theForm.elements;
		var dataElts = {};
		for (var i=0; i<oFormElts.length; i++){
			dataElts[oFormElts[i].name] = oFormElts[i].value;
		}
		$.ajax({
			type: 'POST', url: '/ajax.contact.php',
			data: (dataElts),
			success: function(msg) {
				checkFormContact.errmsg.innerHTML = msg;//'';

				for (var j=0; j<oFormElts.length; j++){
					if ((oFormElts[j].type!="submit") && (oFormElts[j].type!="hidden")){
						oFormElts[j].value = checkFormContact.originVal[j];
					}
				}
				checkFormContact.submitButton.disabled = false;//reactive le bouton submit
				checkFormContact.submitButton.value = checkFormContact.submitButton.oldValue;
			}
		});
	}
}
var getAjaxAnswer = {
	sending : function (theForm) {

		var ajaxTab = new Array;
		var oForm = document.getElementById(theForm);
		var oFormElts = oForm.elements;
		for (var i=0; i<oFormElts.length; i++){
			ajaxTab[oFormElts[i].id]	= oFormElts[i].value;
		}
		tfc.getXmlList( oForm.action, ajaxTab );
		getAjaxAnswer.hideElts();
	},
	hideElts : function() {
		document.getElementById("response").style.display = 'block';
		document.getElementById("tableau").style.display = 'none';
		document.getElementById("send").style.display = 'none';
		document.getElementById("message_error").style.display = 'none';
	},
	resetForm : function() {
		document.getElementById("response").style.display = 'none';
		document.getElementById("tableau").style.display = '';
		document.getElementById("send").style.display = 'block';
		var formsArray = document.getElementsByTagName("form");
		for (var i=0;i<formsArray.length;i++){
			var oFormElts = formsArray[i].elements;
			for (var j=0; j<oFormElts.length; j++){
				if (oFormElts[j].type!="submit") {
					oFormElts[j].value = '';
				}
			}
		}
	}
}
/** */
var theDoc = document;
	
function addNews() {
	if (theDoc.getElementById("droitenews").style.display=="none") {
		theDoc.getElementById("droitenews").style.display = "block";
		theDoc.getElementById("droitenews2").style.display = "none";
		theDoc.getElementById("ex_newsletterclose").style.display = "none";
		theDoc.getElementById("ex_newsletter").style.display = "";
		theDoc.getElementById("ex_newsletter").height = "83";
	} else {
		theDoc.getElementById("droitenews").style.display="none";
		theDoc.getElementById("droitenews2").style.display="block";
		theDoc.getElementById("ex_newsletter").height="66";
		theDoc.getElementById("ex_newsletterclose").style.display = "";
		theDoc.getElementById("ex_newsletter").style.display = "none";
	}
}

function addMap() {
	if (theDoc.getElementById("plan").height=="241") {
		theDoc.getElementById("visionerclose").style.display='none';
		theDoc.getElementById("visioner").style.display='';
		theDoc.getElementById("plan").height="42";
/*theDoc.getElementById('plan').src="http://maps.google.fr/maps?f=q&source=s_q&hl=fr&geocode=&q=134+Boulevard+Haussmann+75008+Paris,+France&sll=46.75984,1.738281&sspn=9.726294,19.665527&ie=UTF8&hq=&hnear=134+Boulevard+Haussmann,+75008+Paris,+Ile-de-France&ll=48.875159,2.314425&spn=0.006802,0.024934&z=15&output=embed";*/
	} else {
		theDoc.getElementById("visioner").style.display='none';
		theDoc.getElementById("visionerclose").style.display='';
		theDoc.getElementById("plan").height="241";
		theDoc.getElementById('plan').src="http://maps.google.fr/maps?f=q&source=s_q&hl=fr&geocode=&q=134+Boulevard+Haussmann+75008+Paris,+France&sll=46.75984,1.738281&sspn=9.726294,19.665527&ie=UTF8&hq=&hnear=134+Boulevard+Haussmann,+75008+Paris,+Ile-de-France&ll=48.875159,2.314425&spn=0.006802,0.024934&z=15&output=embed";
		
	}
}

function createQCObject() { 
   var req; 
   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      alert('Problem creating the XMLHttpRequest object'); 
   } 
   return req; 
} 

var http = createQCObject(); 

function NewsletterAjax(n,p,m,t,s) {
	http.open('POST', '/ajax.newsletter.php?n='+n+'&p='+p+'&m='+m+'&t='+t+'&s='+s+'');
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
			var response = http.responseText;
			if(response) {
				document.getElementById("message_error_alert").innerHTML = http.responseText;
				document.getElementById("confirmerimg").style.visibility = "";
				document.getElementById("confirmerimg").disabled = false;
			} 
		} 
	} 
	http.send(null);
}

function verif_nombre(champ) {
	var chiffres = new RegExp("[0-9\+]");
	var verif;
	var points = 0;

	for(x = 0; x < champ.value.length; x++) {
		verif = chiffres.test(champ.value.charAt(x));
		if(champ.value.charAt(x) == "."){points++;}
		if(points > 1){verif = false; points = 1;}
		if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
	}
}
/**
 * funds popin alert + login
 */
var fundManager = {
	fondName : null, fondId : null, pop : null, linksToBe:[], popHTML : null, divNoLogPool : [], divLogPool : [], isSet: false,
	set : function(){
		this.isSet = true;
		this.pop = document.getElementById('popatt');
		this.popHTML = this.pop.innerHTML;
		var getLinks = document.getElementById('contenu2').getElementsByTagName('A');
		for (var i=0;i<getLinks.length;i++){
			if (getLinks[i].className =='closed') {
				this.linksToBe[this.linksToBe.length] = getLinks[i];
				getLinks[i].style.cursor = 'pointer';
				getLinks[i].onclick = function(){
					if (this.rev.indexOf('file_download')>=0) {/** for files*/
						var fundId = this.parentNode.parentNode.getElementsByTagName('A')[0].rev.split(',')[1].split('.')[0];
					} else {
						var fundId = this.rev.split(',')[1].split('.')[0];
					}
					fundManager.getInfoFromAjax(this.rev, this.title, '', fundId);
//					fundManager.alert(this.rev, this.title, '');
					return false;
				}
			}
		}
		var getDivs = document.getElementById('contenu2').getElementsByTagName('DIV');
		for (var i=0;i<getDivs.length;i++){
			if (getDivs[i].className =='nolog') {
				this.divNoLogPool[this.divNoLogPool.length] = getDivs[i];
				var elt = getDivs[i].getElementsByTagName('A')[0];
				elt.saveI = (this.divNoLogPool.length-1);
				if (elt.className =='closed') {
					elt.onclick = function(){
						fundManager.alert('', this.title, String(this.saveI));
						return false;
					}
				} else {
					elt.onclick = function(){
						fundManager.hideNoLog(this.saveI);
					}
				}

			} else if (getDivs[i].className =='userlog') {
				this.divLogPool[this.divLogPool.length] = getDivs[i];

			} else if (getDivs[i].className =='nologonlist') { /** from press */

				var elts = getDivs[i].getElementsByTagName('A');
				var saveIvar = (this.divNoLogPool.length-1);
				
				for (var j=0;j<elts.length;j++){
					elts[j].style.cursor = 'pointer';
					elts[j].onclick = function(){
						fundManager.hideNoLog(saveIvar);
						return false;
					}
				}
			}
		}
		var getInputs = document.getElementById('contenu2').getElementsByTagName('input');
	},
	alert : function(url, name, action, fundIdSet){
		document.onkeydown = fundManager.getKey;
		this.pop.innerHTML = this.popHTML.replace('{fund_name}', name); 
		document.getElementById('popatt').style.display = 'block';
		document.getElementById('closepop').onclick = function(){fundManager.closeAlert()};

		if (url!='') {
//			document.getElementById('openpage').href = url;
			if(fundIdSet!=undefined) var fundId = fundIdSet;
			else var fundId = url.split(',')[1].split('.')[0];

			document.getElementById('openpage').onclick = function(){
				fundManager.sendAjaxRqst(fundId, url);
				fundManager.closeAlert();
			}
		} else if(action!='') {
			document.getElementById('openpage').onclick = function(){
				fundManager.hideNoLog(action);
				fundManager.closeAlert();
			}
		}
	},
	closeAlert: function(){
		this.pop.style.display = 'none';
		this.pop.innerHTML = this.popHTML;
		document.getElementById('closepop').onclick = function(){return false};
		document.getElementById('openpage').removeAttribute('href');
	},
	hideNoLog: function(n){
		this.divNoLogPool[n].style.display = 'none';
		this.divLogPool[n].style.display = 'block';
	},
	hideLog : function(n){
		this.divLogPool[n].style.display = 'none';
		this.divNoLogPool[n].style.display = 'block';
	},
	getKey : function (e) {
		var e = e||window.event;
		var key = e.charCode||e.keyCode;//e.which||e.keyCode;
		if (key==27) {// escape
			fundManager.closeAlert();
		}
	},
	sendAjaxRqst: function(fundId, lurl){/** ajout id fond à la session */
		$.ajax({
			type: 'POST', url: '/save_disclaimer.php', data: 'fund_id=' + fundId,
			success: function(msg) {
				window.location.href = lurl;
			}
		});
	},
	getInfoFromAjax: function(rev, title, nothing, fundId){/** verfie si ok dans la session */
		$.ajax({
			type: 'POST', url: '/get_disclaimed.php', data: 'fund_id=' + fundId,
			success: function(msg) {
				if (msg=='1') {
					window.location.href = rev;
				} else
					fundManager.alert(rev, title, '', fundId);
			}
		});
	}
}
/**
 * frise popin activator
 */
var firsePopin = {
	set : function(){
		if (document.getElementById('frisebloc')== undefined) return;
		var frisebloc = document.getElementById('frisebloc').getElementsByTagName('A');
		for (var i=0;i<frisebloc.length;i++){
			frisebloc[i].onclick=function(){
				firsePopin.openDiv(this.href.split('#')[1]);
			}
		}
	},
	openDiv: function(id){
		if (document.getElementById(id)==undefined) return;
		document.onkeydown = firsePopin.getKey;
		var getHTML = document.getElementById(id).innerHTML;
		document.getElementById('htmlcontent').innerHTML = getHTML;
		document.getElementById('mainpopin').style.display = 'block';
		document.getElementById('closebt').onclick = firsePopin.closeDiv;
		$('#mainpopin > .shadow').css( 'height', $('#mainpopin > .content').height()+'px');
		$('#mainpopin').css( 'top', (($(window).height()-$('#htmlcontent').height())/2)+'px' );
	},
	getKey : function (e) {
		var e = e||window.event;
		var key = e.charCode||e.keyCode;//e.which||e.keyCode;
		if (key==27) {// escape
			firsePopin.closeDiv();
		}
	},
	closeDiv : function(){
		document.getElementById('mainpopin').style.display = 'none';
	}
}

/**
 *
 */
var globalFundManager = {
	set : function(){
		if (fundManager.isSet) return false;
		if (document.getElementById('contenu2')==undefined)  
			var getLinks = document.getElementById('contenu').getElementsByTagName('A');
		else 
			var getLinks = document.getElementById('contenu2').getElementsByTagName('A');

		for (var i=0;i<getLinks.length;i++){
			if (getLinks[i].href.indexOf('nos-fonds/')>=0 || getLinks[i].href.indexOf('en/our-funds/')>=0)  {
				var linkExploded = getLinks[i].href.split(',');
				var partLinkForId = linkExploded[linkExploded.length-1].split('.')[0];
				if (fundsinf[partLinkForId][2]==1) {//online
					if (fundsinf[partLinkForId][1]) {//close
						getLinks[i].onclick = function(){
							fundManager.pop = document.getElementById('popatt');
							fundManager.popHTML = fundManager.pop.innerHTML;
var fundId = this.href.split(',')[1].split('.')[0];
							fundManager.getInfoFromAjax(this.href, fundsinf[partLinkForId][3], '', fundId);
//							fundManager.alert(this.href, fundsinf[partLinkForId][3], '');
							return false;
						}

					} else if(fundsinf[partLinkForId][1]) {//log
						
					}
				} else {
					
				}

//				if ( partLinkForId

/*				this.linksToBe[this.linksToBe.length] = getLinks[i];
				getLinks[i].style.cursor = 'pointer';
				getLinks[i].onclick = function(){
					fundManager.alert(this.rev, this.title, '');
					return false;
				}*/
			}
		}
	}
}

/**
 *
 */
var fileSeek = {
	count : [], divs:[], links:[],
	set: function(){
		var getLinks = document.getElementById('contenu').getElementsByTagName('SPAN');
		for (var i=0;i<getLinks.length;i++){
			this.links[i] = [];
			if (getLinks[i].className=='hideseek')  {
			
				this.links[i] = getLinks[i].getElementsByTagName('A');
				this.links[i][0].numr = this.links[i][1].numr = i;
				this.links[i][0].onclick = function(){
					fileSeek.hideseek(this.numr, 'show');
				}
				this.links[i][1].onclick = function(){
					fileSeek.hideseek(this.numr, 'hide');
				}

				this.divs[i] = getLinks[i].parentNode.getElementsByTagName('DIV');
				var _count = 0;
				for (var d=0;d<this.divs[i].length;d++){
					if(this.divs[i][d].style.display != 'none') _count++;
				}
				this.count[i] = _count;
			}
		}
	},
	hideseek: function(n, action){
		if (action=='show') {
			for (var i=0;i<this.divs[n].length;i++){
				this.divs[n][i].style.display = 'block';
			}
			this.links[n][0].style.display = 'none';
			this.links[n][1].style.display = 'block';
		} else {
			for (var i=0;i<this.divs[n].length;i++){
				if (i>=this.count[n])
					this.divs[n][i].style.display = 'none';
			}
			this.links[n][0].style.display = 'block';
			this.links[n][1].style.display = 'none';
		}
		if (($.browser.msie) && ($.browser.version==8)) {
			this.divs[n][i-1].parentNode.style.height = '0';
			this.divs[n][i-1].parentNode.style.height = 'auto';
		}
	}
}
