 
function checkRadio (var1) {
	document.getElementById(var1).checked = true;
}

function checkAim () {
	var targetElement_aim = document.getElementById('aim');
	var targetElement_other;
	//targetElement_other = document.getElementById('aim-other');

	if (targetElement_aim.options[targetElement_aim.selectedIndex].value == "1") {
		//targetElement_other.style.display = "";
	} else {
		//targetElement_other.style.display = "none";
	}
	//public ou privé pour selectionner l'etat directement
	st = targetElement_aim.value;
}

function checkPartCondit () {
	var targetElement_part = document.getElementById('partcb'),
		targetElement_submit = document.getElementById('part-popup-valid');

	if (targetElement_part.checked == true) {
		targetElement_submit.disabled = false;
		targetElement_submit.className = '';
	} else {
		targetElement_submit.disabled = true;
		targetElement_submit.className = 'disabledBt';
	}
}

function checkSignupCondit() {
	var targetElement_part = document.getElementById('cgv');
	targetElement_part2 = document.getElementById('realinfos');
	targetElement_submit = document.getElementById('signup-submit');
	ValidateFirstname();
	ValidateLastname();
	ValidateForm();
	pass1 = document.getElementById('signuppassword').value;
	pass2 = document.getElementById('password2').value;
	passwordStrength(pass1);
	checkifsame(pass2);	
	captchavalue();

	if ((targetElement_part.checked == true) && (targetElement_part2.checked == true)) {
		document.getElementById('cgvcheck').className = 'strength3';
		document.getElementById('realcheck').className = 'strength3';
	}
	else if(targetElement_part.checked == true){
		document.getElementById('realcheck').className = 'strength0';
		document.getElementById('cgvcheck').className = 'strength3';
	}
	else if(targetElement_part2.checked == true){
		document.getElementById('cgvcheck').className = 'strength0';
		document.getElementById('realcheck').className = 'strength3';
	}
	else {				
		document.getElementById('cgvcheck').className = 'strength0';
		document.getElementById('realcheck').className = 'strength0';
	}
}
function captchavalue(){	
	if(document.getElementById('captcha').value.length==3){	
		document.getElementById('captchavalue').className = '';			
	}
	else{
		document.getElementById('captchavalue').className = 'strength0';		
	}
}


function popupOpen(var1, var2, varid) {
	document.popupForm.popupboxkey.value = varid;
	opacity(var1, '0', '70', '500');
	opacity(var2, '0', '100', '700');
}

function popupClose(var1, var2) {
	opacity(var1, '70', '0', '100');
	opacity(var2, '100', '0', '200');
}
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style;
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = 'alpha(opacity='+ opacity +')';
}
function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	if (opacStart > opacEnd) {
		var i = 0;
		for (i = opacStart; i >= opacEnd; --i) {
			setTimeout('changeOpac('+ i +', \''+ id +'\')', timer * speed);
			timer++;
		}
		setTimeout('hideObject(\''+ id +'\')', millisec);
	} else if (opacStart < opacEnd) {
		objet = document.getElementById(id);
		objet.style.display = 'block';
		for (i = opacStart; i <= opacEnd; ++i) {
			setTimeout('changeOpac('+ i +', \''+ id +'\')', timer * speed);
			timer++;
		}
	}
}

function hideObject(aCacher) {
	forceClass(aCacher, 'hidden');
}

function eltHasClass(o, className) {
	if (!o || !o.className) {
		return false;
	}

	return new RegExp('\\b' + className + '\\b').test(o.className);
}

function toggleClass(o, className){
	if (!eltHasClass(o,className)) {
		o.className += ' '+ className;
	} else {
		rmClass(o, className);
	}
}

function addClass(o, className) {
	if (!eltHasClass(o,className)) {
		o.className += ' '+ className;
	}
}

function rmClass(o, className) {
	o.className = o.className.replace(new RegExp('\\s*\\b'+ className +'\\b'), '');
}

function forceClass(o, className) {
	if (o && !eltHasClass(o, className)) {
		o.className = className;
	}
}

function getId(id) {
	return document.getElementById(id);
}

function showHide(id) {
	toggleClass(getId(id), 'hidden');
}

function visibilityOn(id) {
	rmClass(getId(id), 'hidden');
}

function visibilityOff(id) {
	forceClass(getId(id), 'hidden');
}

function temporisedVisibilityOff(id) {
	a = setTimeout('visibilityOff(\''+ id +'\');', 150);
}

function getImagePageTop(img){
	var y = 0, obj = img;

	if (img != null) {
		while (obj.offsetParent != null) {
			y += obj.offsetTop;
			obj = obj.offsetParent;
		}
		y += obj.offsetTop;
		return y;
	} else {
		return -1;
	}
}

/* a supprimer
function moveTools() {
	toolsStartY = 210;
	scrollY = document.documentElement.scrollTop;
	if (scrollY <= getImagePageTop(getId("fichecommtable"))) {
		toolsY = toolsStartY;
	} else {
		toolsY = document.documentElement.scrollTop + toolsStartY - getImagePageTop(getId("fichecommtable"));
	}
	getId("tools").style.marginTop = toolsY+"px";
}

function RefreshToolsPosition(Duree) {
  b = window.setInterval("moveTools();", Duree);
}
*/

/* For greybox(popup) participate */
function loadPage(url) {
	window.top.location.href = url;
}


/*
function urlbox(urlbox,titre,description,idbox)
{//fonction a virer
   document.getElementById("urlbox").value = urlbox;
   var adressbox = urlbox;
   document.flashform.titre.value = titre; 
   document.flashform.desc.value = description;  
   document.getElementById("email-title").value = titre;
   //document.getElementById("email-content").value = "Bonjour,\n j'ai cree un evenement,\n je vous invite a y participer en cliquant sur ce lien: \n \n" + urlbox + "";
   document.getElementById("idpublicEmail").value = idbox;
   
   document.flashform.idbox.value = idbox; 
   document.getElementById('invite-url-valid').innerHTML = "<img src='"+urlSite+"public/images/tick.png' />";
   rmClass($('invite-url-networks'), 'hidden');
   document.getElementById('invite-url-networks').innerHTML = "<a href='http://www.facebook.com/sharer.php?u="+adressbox+"' target='_blank'><img src='"+urlSite+"public/images/ico_facebook.gif' /></a><a href='http://blogmarks.net/my/new.php?mini=1&simple=1&url="+adressbox+"' target='_blank'><img src='"+urlSite+"public/images/ico_blogmarks.gif' /></a><a href='http://del.icio.us//post?url="+adressbox+"' target='_blank'><img src='"+urlSite+"public/images/ico_delicious.gif' /></a><a href='http://www.furl.net/savedialog.jsp?p=1&u="+adressbox+"' target='_blank'><img src='"+urlSite+"public/images/ico_furl.gif' /></a> <a href='http://www.google.com/bookmarks/mark?op=add&bkmk="+adressbox+"' target='_blank'><img src='"+urlSite+"public/images/ico_google.gif' /></a><a href='http://digg.com/submit?phase=2&url="+adressbox+"' target='_blank'><img src='"+urlSite+"public/images/ico_digg.gif' /></a>";
   
   reloadflash();
}*/



function webmailchange(webmail){
	addClass($('webmail-log'),'hidden');
	addClass($('webmail-manuel'),'hidden');
	addClass($('webmail-widget'),'hidden');
	addClass($('webmail-cbox'), 'hidden');
	addClass($('webmail-csv'), 'hidden');
	addClass($('webmail-widget-insert'),'hidden');
	addClass($('webmail-right'), 'hidden');
	addClass($('explain-email'), 'hidden');
	addClass($('webmail-widget-options'),'hidden');

 	if (webmail == 'csv') {
 		rmClass($('webmail-csv'), 'hidden');
 		rmClass($('webmail-right'), 'hidden');
 		rmClass($('explain-email'), 'hidden');

 	} else if (webmail == 'cbox') {
 		rmClass($('webmail-cbox'), 'hidden');
 		rmClass($('webmail-right'), 'hidden');
 		rmClass($('explain-email'), 'hidden');

 	} else if (webmail == 'widget') {
 		rmClass($('webmail-widget'), 'hidden');
 		rmClass($('webmail-widget-insert'), 'hidden');
 		rmClass($('webmail-widget-options'), 'hidden');

 	} else if (webmail == 'manuel') {
 		rmClass($('webmail-manuel'), 'hidden');
 		rmClass($('webmail-right'), 'hidden');
 		rmClass($('explain-email'), 'hidden');

 	} else {
 		rmClass($('webmail-log'), 'hidden');
 		rmClass($('webmail-right'), 'hidden');
 		rmClass($('explain-email'), 'hidden');

 		document.getElementById('log-webmail-choice').innerHTML = webmail;
 		document.getElementById('log-webmail-choice2').innerHTML = webmail;
 		document.getElementById('webmaillogin').focus();
 	}

 	document.getElementById('webmail-list').value = webmail;
}

function reloadflash(color) {
	titre = document.flashform.titre.value;		
	flashidbox = document.flashform.idbox.value;
	idpublic = document.flashform.idpublic.value;		
	flashidbox = urlSite + lg +'/invite/widget/id/'+ idpublic;

	codeflash = '<object codebase="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="125" height="125" id="flashvars" align="middle">'+
		'<param name="allowScriptAccess" value="sameDomain" />'+
		'<param name="movie" value="'+ urlSite +'/public/flash/widget/cboxwidget.swf" />'+
		'<param name="quality" value="high" />'+
		'<embed src="'+ urlSite +'/public/flash/widget/cboxwidget.swf" FlashVars="titre='+ titre +'&langue='+ lang +'&devise='+ currency +'&couleur='+ color +'&flashidbox='+ flashidbox +'" quality="high" bgcolor="#FFFFFF" wmode="transparent" width="125" height="125" name="flashvars" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />'+
	'</object>';

	txt = document.getElementById('flashbanner');
	txt.innerHTML = codeflash;

	flashcode = document.getElementById('flashcode');
	flashcode.innerHTML = codeflash;
}

function insertWrongEmail() {
	visibilityOn('emailDescription');
	document.getElementById('emailcheck').className = 'strength0';
}

function insertGoodEmail(){
	visibilityOff('emailDescription');
	document.getElementById('emailcheck').className = 'strength3';
}

function echeck(str) {
	var at = '@',
		dot = '.',
		lat = str.indexOf(at),
		lstr = str.length,
		ldot = str.indexOf(dot);

	if (str.indexOf(at) == -1) {
	   insertWrongEmail();
	   return false;
	}
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
	   insertWrongEmail();
	   return false;
	}
	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
		insertWrongEmail();
		return false;
	}
	if (str.indexOf(at, lat + 1) != -1) {
		insertWrongEmail();
		return false;
	}
	if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot){
		insertWrongEmail();
		return false;
	}
	if (str.indexOf(dot, lat + 2) == -1){
		insertWrongEmail();
		return false;
	}
	if (str.indexOf(' ') != -1){
		insertWrongEmail();
		return false;
	}

	return true;
}

function ValidateForm() {
	var emailID = document.test.email;

	if (emailID.value == null || emailID.value == '') {
		insertWrongEmail();
	} else if (echeck(emailID.value) == false) {
		return false;
	} else {
		insertGoodEmail();
	}

	return true;
}

function ValidateFirstname() {
	document.getElementById('firstnamecheck').className = document.test.firstname.value.length > 1 ? 'strength3' : 'strength0';
}
function ValidateLastname(){
	document.getElementById('lastnamecheck').className = document.test.lastname.value.length > 1 ? 'strength3' : 'strength0';
}



function passwordStrength(password) {
	var desc = new Array(),
		score = 0;

	//if password bigger than 6 give 1 point
	if (password.length > 6) score++;

	//if password has both lower and uppercase characters give 1 point	
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

	//if password has at least one number give 1 point
	if (password.match(/\d+/)) score++;

	//if password has at least one special caracther give 1 point
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) )	score++;

	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++;

	document.getElementById('passwordStrength').className = 'strength1';
	
	if (password.length < 8) {
		if(score==0) {visibilityOn('passwordDescription0');}	
		if(score==1) {visibilityOn('passwordDescription0');}	
		if(score==2) {visibilityOn('passwordDescription0');}	
		if(score==3) {visibilityOn('passwordDescription0');}	
		if(score==4) {visibilityOn('passwordDescription0');}	
		if(score==5) {visibilityOn('passwordDescription0');}	
	}
	 
	if (password.length > 7) {
	 	document.getElementById('passwordStrength').className = 'strength3';	 	
		visibilityOff('passwordDescription0');
	}
}

function checkifsame(password2) {
	var pass1 = document.getElementById('signuppassword').value,
		pass2 = document.getElementById('password2').value,
		class1 = document.getElementById('passwordStrength').className;

 	if (pass1 == pass2 && (class1 == 'strength2' || class1 == 'strength3' || class1 == 'strength4' || class1 == 'strength5')) {
		document.getElementById('samepassword').className = 'strength3';
	} else {
		document.getElementById('samepassword').className = 'strength0';
	}
}

function checkpaiement(modepaiement) {
	var IDcheckbox = document.getElementById(modepaiement);

	if (IDcheckbox.checked == true) {
		visibilityOn(modepaiement +'-text');
	} else if(IDcheckbox.checked == false) {
		visibilityOff(modepaiement +'-text');
	}
}


function reloadCaptcha(urlCaptcha) {
	var currentTime = new Date();
	var minutes = currentTime.getMinutes();
	var secondes = currentTime.getSeconds();

	document.getElementById('captchaImg').src = urlCaptcha +'?change='+ minutes + secondes;
}

//function changeimageInvite(){
//	document.getElementById('inviteFormBTN').innerHTML='envoi en cours';
//}


function WaitSend(id) {
	addClass($(id),'disabledBt');
	document.getElementById(id).value = 'envoi en cours...';		
}
function WaitLoad(id) {
	addClass($(id),'disabledBt');
	document.getElementById(id).value = 'chargement en cours...';		
}
function emailcontentchange(content) {
	emailperso = content;
	emailtosend = document.getElementById('emailpersocontent');
	emailtosend.innerHTML = emailperso;
}
function showPublicboxTitle(title) {
	document.getElementById('home-publicbox-title').innerHTML = title;  
}
function hidePublicboxTitle() {
	document.getElementById('home-publicbox-title').innerHTML = '';  
}

//actif seulement sur VIEW
function checkAmount(amount, min, max) {
	amount = amount.replace(',', '.');
	amount = parseFloat(amount);
	if (amount > max || amount < min || isNaN(amount)) {
		document.getElementById('cbox-otherinfos-amountInfos').className = 'cbox-otherinfos-error';
		document.getElementById('cbox-otherinfos-amount').className = 'cbox-otherinfos-error';
		return false;
	} else {
		document.getElementById('cbox-otherinfos-amount-input').value = amount;
		document.getElementById('cbox-otherinfos-amountInfos').className = ' ';
		document.getElementById('cbox-otherinfos-amount').className = ' ';  	
		return true;  	
	}
}

//actif seulement sur VIEW
function setPaypalTax(amount, devise){
	amount = amount.replace(',','.');
	amount = parseFloat(amount);
	frais_paypal = '';

	if ('EUR' == devise) {
	 	devise = '€';
	 	paypal_commission_fixe = 0.25 ;
	 	paypal_commission_poucentage = 0.034 ;

	} else if('USD' == devise) {
	 	devise = '$';
	 	paypal_commission_fixe = 0.30 ;
	 	paypal_commission_poucentage = 0.039 ;

	} else if('GBP' == devise) {
	 	devise = '£';
	 	paypal_commission_fixe = 0.20 ;
	 	paypal_commission_poucentage = 0.039 ;

	} else if('CHF' == devise) {
	 	devise = 'CHF';
	 	paypal_commission_fixe = 0.55 ;
	 	paypal_commission_poucentage = 0.039 ;
	}

	frais_paypal = Math.ceil( ( ( ( amount + paypal_commission_fixe ) / ( 1 - paypal_commission_poucentage ) ) - amount ) * 100 )   /  100;
	
	if (isNaN(frais_paypal))
	{
		frais_paypal = 0;
	}

	document.getElementById('frais_paypal').innerHTML = frais_paypal +' '+ devise;
}

function changeCurrency(curr) {
	var spanCurrency = document.getElementsByName('currency-exemple');
	
	if (curr == 'EUR'){
		currency = '€';
	} else if(curr == 'USD'){
		currency = '$';
	} else {
		currency = curr;
	}
	
	for (var n = 0; n < spanCurrency.length; ++n) {
		spanCurrency[n].innerHTML = currency; 
	}
	
}

function addInput(mail) {
	var div = document.getElementById('commonbox_invite_destinataires'),
		button = document.getElementById('commonbox_invite_add_input'),
		newnode = document.createElement('span');

	if (mail != undefined) {
		newitem = ' <input class="inputTextSmall" type="text" value="'+ mail +'" name="destinataire[]" onfocus="if(this.value==\'destinataire@email.com\') this.value=\'\'; return false;" onchange="if ( echeck(this.value) ) this.className = \'inputTextSmall\'; else this.className = \'inputTextSmallWrong\';" />';
	} else {
		newitem = ' <input class="inputTextSmall" type="text" value="destinataire@email.com" name="destinataire[]" onfocus="if(this.value==\'destinataire@email.com\') this.value=\'\'; return false;" onchange="if ( echeck(this.value) ) this.className = \'inputTextSmall\'; else this.className = \'inputTextSmallWrong\';" />';
		newitem += newitem;
	}

	newnode.innerHTML = newitem;
	div.insertBefore(newnode,button);
}

//ajoute le textarea sur la page d'invitation pour la liste des destinataires
function addMailsArea() {
	var tabEmails = document.getElementById('commonbox_invite_form_email').getElementsByTagName('input');
	var addInArea = '';
	
	//récupère les emails déjà enregistrés dans le champ input
	for (var i = 0, tabEmail; tabEmail = tabEmails[i++]; ) {
		if (tabEmail.name=="destinataire[]"){
			tabEmail.parentNode.removeChild(tabEmail);
			i--;
			if (tabEmail.value != "destinataire@email.com" && tabEmail.value != "")
			{
				addInArea += tabEmail.value + ' ; ' ;
			}
		}
	}

	//créer le textarea
	newnode=document.createElement('span');
	newnode.innerHTML="<textarea cols='45' rows='4' name='destinataire[]'>" + addInArea + "</textarea>";
	document.getElementById("commonbox_invite_destinataires").insertBefore(newnode,document.getElementById("commonbox_invite_add_input"));	

	//efface le bouton d'ajout email et remplace le lien 'ajouter une liste' par une indication
	document.getElementById("email_add_input").innerHTML= '';
	document.getElementById("email_add_list").innerHTML= 'séparez par un point virgule ";" chaque email.';


}