
//JQuery body onload equivalent - but better. Be sure Jquery library is loaded first
$(document).ready(function() {
	//Facebook stuff
	FB.init({appId: '118723894868971', status: true,cookie: true, xfbml: true, oauth: true});
	
	//CLOSING POPUP  
	//Click the x event!  
	$("#popupFacebookAlertClose").click(function(){  
		disablePopupAsso(true);  
	});
	
	$("#popup_ok_button").click(function(){  
		disablePopupAsso(true);
	});
	
	$("#popup_birthday_ok_button").click(function(){  
		
		if ($("#popup_birthday_ok_button").attr("href") != "javascript:getFriendsAlert();"){
			window.location = '/account.php?sp=birthdays';
			disablePopupAsso(false);
		}
	});
	
	$("#popup_birthday_cancel_button").click(function(){  
		disablePopupBirthdayAlert();
	});
	
	$("#popup_fail_button").click(function(){  
		disablePopupAsso(true);
		fb_logout();
	});
	
	$("#popup_create_asso_button").click(function(){  
		createFBAsso();  
	});
	
	$("#popup_cancel_button").click(function(){  
		cancelFBAsso();  
	});
	
	//tags for drill down
	$(":checkbox[name='tags']").click(function() {
		
		var tags_list= new Array();
		var data = new Array();
		
		$("input:checkbox[name='tags']:checked").each(function(){ 
			tags_list.push(this.value); 
		}) ;
		
		data['tags_list'] =  new Array();
		data['tags_list'] = tags_list;
		data['socid'] = $("#socid").val();
		
		$.post("/drill_down_handler.php",{'tags': array2json(tags_list), 'socid' : $("#socid").val()},
		function(data){
			if (data){
				//$("#templates_previews").html(data);
				
				var result = eval("(" + data + ")");
				var ord;
				var i;
				var html_text = '<tr>';
				var cnt=0;
				
				//for(ord = 0; ord < result.length; ord++) {
				for(i = 0; i < result.length; i++) {
					cnt++;
					if (cnt%4==0){
						html_text+="</tr><tr>";
						cnt=1;
					}	
					html_text+='<td class="ImagePrevTable_ref"><a href="'+result[i].ref_link+'"><img src="'+result[i].link+'" class="clickable" alt="'+result[i].ref_name+'"></a><a href="'+result[i].ref_link+'" class="category_ref">'+result[i].ref_name+'</a><br/><br/></td>';
				}
				//}
				if (cnt==1)
				html_text+='<td class="ImagePrevTable_ref">&nbsp;</td><td class="ImagePrevTable_ref">&nbsp;</td>';
				else if (cnt==2)
				html_text+='<td class="ImagePrevTable_ref">&nbsp;</td>';

				$("#templates_previews").html(html_text);
				
			}
		});
	});

$("input[name=logo]:radio").change(function() {
		
		if ($('input[type=radio][name=logo]:checked').attr('value') == 1){
			$('#logo_prices').show();
			$('#logo_active').val(1);
		} else {
			$('#logo_prices').hide();
			$('#logo_active').val(0);
		}
	});
	
	$("[name='menulink']").click(function(){  
		var id = $(this).attr('id');
		$('#td_'+id).show();
	});
	
	$("#button_more_cards").click(function(){
		var base=0;
		var found=false;
		$('.ImagePrevTable_ref').each(function(index) {
			if ($(this).css('display') == "none"){
				base = $(this).attr('id').substring(5);
				return false;
			}
		});
		if (base != 0){
			var max_iter = $("#cards_limit").val();
			var num=0;
			for(i=0;i<max_iter;i++){
				num = parseInt(base)+i;
				if ($("#tmplimg_"+num).length){ //exists
					$("#tmplimg_"+num).attr('src',$("#tmplimg_"+num).attr('name'));
					$("#tmpl_"+num).css('display','table-cell');
				}
				else $("#td_more_cards").hide();
			}
			
		} else $("#td_more_cards").hide();
		return false;
	});
	
	$(".paycell_clickable").click(function(){
		id = $(this).attr('id').substring(3);
		$('#radio_'+id).click();
	});
	
	$(window).scroll(function(){
		
		var num=parseInt($(document).height())-parseInt($(window).height())-1500;
		if ($(window).scrollTop() > num){
			var base=0;
			var found=false;
			$('.ImagePrevTable_ref').each(function(index) {
				if ($(this).css('display') == "none"){
					base = $(this).attr('id').substring(5);
					return false;
				}
			});
			if (base != 0){
				var max_iter = $("#cards_limit").val();
				var num=0;
				for(i=0;i<max_iter;i++){
					num = parseInt(base)+i;
					if ($("#tmplimg_"+num).length){ //exists
						$("#tmplimg_"+num).attr('src',$("#tmplimg_"+num).attr('name'));
						$("#tmpl_"+num).css('display','table-cell');
					}
					else $("#td_more_cards").hide();
				}
				
			}else $("#td_more_cards").hide();
		}
	});
	
	$('.menu_entry').click(function(){
		$(this).parent().parent().children('.menu_loader').show();
	});
});

function fb_login(){

	FB.login(function(response) {

		if(response.authResponse)
		{
			$.get("/FB_login.php",
			function(data){
				
				var result = eval("(" + data + ")");
				
				if (result){
					code = result['code'];
					
					switch(code){
						
					case 201 : 
						//OK. Association
						
						centerPopupAsso();  
						setPopupAssoText(result['text']);
						loadPopupAsso();
						getFriendsInfo();
						break;
						
					case 202 : 
						
						centerPopupAsso();  
						setPopupAssoText(result['text']);
						loadPopupAssoConfirm();
						getFriendsInfo();
						break;
						
					case 200 : 
						//Ok.
						getFriendsInfo();
						if (window.location.pathname == "/login.php" || window.location.pathname == "/registration.php") //if login, redirect to my account
						document.location.href = '/account.php?sp=my_account';
						else if (window.location.pathname == "/regCommand.php" )
						document.location.href = '/command.php';
						else if (window.location.pathname == "/Facebook_photos.php")
						launchAlbumRetrieving();
						else window.location.reload();
						
						break;
						
					case 401 :
					case 402 :
					case 403 :
						centerPopupAsso();  
						setPopupAssoText(result['text']);
						loadPopupFail();
						break;
						
					default:break;
						
					}
					
				}
				//window.location.reload();
				//else alert(data);
				
			});
			
			
		}
	},{scope:'user_photos, email, friends_birthday'});
}

function fb_relogin(){

}

function fb_logout(){
	FB.logout();
}

function getFriendsInfo(){

	$.post("/FB_friends_info.php", { 'choices[]': ["Jon", "Susan"] }, function(data){

	});

}

function createFBAsso(){

	$.get("/FB_login_asso.php",{create:"1"},
	function(data){
		
		var result = eval("(" + data + ")");
		
		if (result){
			code = result['code'];
			
			switch(code){
				
			case 201 : 
				centerPopupAsso();  
				setPopupAssoText(result['text']);
				loadPopupAsso();
				break;
				
			default:break;
			}
		}
		

	});

}

function cancelFBAsso(){

	$.get("/FB_login_asso.php",{create:"0"},
	function(data){
		
		var result = eval("(" + data + ")");
		
		if (result){
			code = result['code'];
			
			switch(code){
				
			case 201 : 
				centerPopupAsso();  
				setPopupAssoText(result['text']);
				loadPopupAsso();
				break;
				
			default:break;
			}
		}
		
		fb_logout();

	});

}

function birthdays_alert_selection(){

	if ($('input[type=radio][name=pop_chk]:checked').attr('value') == 1){
		
		
		$.post("/FB_friends_alert.php", "friends=all", function(data){
			
			$("#popupFacebookAlert").width(300);
			$("#popupFacebookAlert").height(200);
			centerPopupAsso();  
			setPopupAssoText(decodeURIComponent( encodeURIComponent('Votre sélection a bien été prise en compte !')));
			loadPopupBirthday();
			
		});
		
	}
	else {
		
		$.get('/account.php',{ sp: "birthdays", cmd: "get_friends" }, function(data){
			
			
			var result = eval("(" + data + ")");
			
			if (result){
				setPopupWithFriends(result);
			}
			
			
		});
		
	}
}

function setPopupWithFriends(friends){

	code = '<table>';

	$("#popupFacebookAlert").width(650);
	$("#popupFacebookAlert").height(600);
	centerPopupAsso();


	$("#popup_birthday_ok_button").attr("href","javascript:getFriendsAlert();");

	$("#popupFacebookAlertText").html(decodeURIComponent(encodeURIComponent('Veuillez sélectionner les amis à ajouter à l\'alerte<br><br>'))); 

	$("#popupFacebookAlert").css("font-size","12px");

	$("#popupFacebookAlertContent").css("height","480px");


	$("#popupFacebookAlertHeader").css("background-color","#627AAD");
	$("#popupFacebookAlertText").css("color","#FFFFFF");
	$("#popupFacebookAlertText").css("font-weight","bold");
	$("#popupFacebookAlertText").css("margin","auto");
	$("#popupFacebookAlert").css("border","2px solid #939594");
	$("#popupFacebookAlertFooter").css("text-align","right");
	$("#popup_birthday_ok_button_image").attr("src","img/facebook_ok.jpg");
	$("#popup_birthday_cancel_button").show();

	code='<tr>';
	for(i = 0; i < friends.length; i++) {

		if (i%3==0)
		code += '</tr><tr>';
		
		code += '<td><br><input id="chk_'+friends[i].fbid+'" name="chk_friend" value="'+friends[i].fbid+'" type="checkbox"';

		if (friends[i].in_alert)
		code+=' checked';

		code+='></input><img src="http://graph.facebook.com/'+friends[i].fbid+'/picture" \> '+friends[i].first_name+' '+friends[i].last_name+'</td>';

	}

	code += '</tr>';


	$("#popupFacebookAlertContent").html(code);

	$("#popupFacebookAlert").scrollTo("0px");

	loadPopupBirthday();
}

function getFriendsAlert(){
	
	friends = new Array();
	i=0;
	$("input:checkbox[name=chk_friend]:checked").each(function()
	{
		friends[i] = $(this).val();
		i++;
	});

	$.post("/FB_friends_alert.php", "friends="+array2json(friends), function(data){
		
		$("#popupFacebookAlertContent").html('');
		$("#popupFacebookAlert").css("font-size","16px");
		$("#popupFacebookAlertContent").css("height","30px");
		$("#popupFacebookAlert").width(300);
		$("#popupFacebookAlert").height(200);
		$("#popup_birthday_ok_button").attr("href","javascript:nothing();");
		$("#popupFacebookAlertHeader").css("background-color","");
		$("#popupFacebookAlertText").css("color","");
		$("#popupFacebookAlertText").css("font-weight","");
		$("#popupFacebookAlertText").css("margin","");
		$("#popupFacebookAlert").css("border","2px solid #FF7C00");
		$("#popupFacebookAlertFooter").css("text-align","");
		$("#popup_birthday_cancel_button").hide();
		$("#popup_birthday_ok_button_image").attr("src","/img/popup_fb_ok.gif");
		
		centerPopupAsso();  
		setPopupAssoText(decodeURIComponent( encodeURIComponent('Votre sélection a bien été prise en compte !')));
		loadPopupBirthday();
	});

}

//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0;  

//loading popup with jQuery magic!  
function loadPopupAsso(){  
	//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});
		$("#popupFacebookAlertClose").show();
		$("#popup_create_asso_button").hide();
		$("#popup_cancel_button").hide();
		$("#popup_birthday_ok_button").hide();
		$("#popup_birthday_cancel_button").hide();
		$("#popup_fail_button").hide();
		$("#popup_ok_button").show();
		$("#backgroundPopup").show();  
		$("#popupFacebookAlert").show();  
		popupStatus = 1;  
	}
	else {
		$("#popupFacebookAlertClose").show();
		$("#popup_create_asso_button").hide();
		$("#popup_cancel_button").hide();
		$("#popup_birthday_ok_button").hide();
		$("#popup_birthday_cancel_button").hide();
		$("#popup_fail_button").hide();
		$("#popup_ok_button").show();
		
	}
}

function loadPopupAssoConfirm(){  
	//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});
		$("#popup_ok_button").hide();
		$("#popupFacebookAlertClose").hide();
		$("#popup_birthday_cancel_button").hide();
		$("#popup_fail_button").hide();
		$("#popup_birthday_ok_button").hide();
		$("#popup_create_asso_button").show();
		$("#popup_cancel_button").show();		
		$("#backgroundPopup").show();  
		$("#popupFacebookAlert").show();  
		popupStatus = 1;  
	}  
}

function loadPopupFail(){  
	//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});
		$("#popupFacebookAlertClose").hide();
		$("#popup_create_asso_button").hide();
		$("#popup_birthday_ok_button").hide();
		$("#popup_birthday_cancel_button").hide();
		$("#popup_cancel_button").hide();
		$("#popup_fail_button").show();
		$("#popup_ok_button").hide();
		$("#backgroundPopup").show();  
		$("#popupFacebookAlert").show();  
		popupStatus = 1;  
	}
	else {
		$("#popupFacebookAlertClose").hide();
		$("#popup_create_asso_button").hide();
		$("#popup_birthday_ok_button").hide();
		$("#popup_birthday_cancel_button").hide();
		$("#popup_cancel_button").hide();
		$("#popup_fail_button").show();
		$("#popup_ok_button").hide();
		
	}
} 

function loadPopupBirthday(){  
	//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#backgroundPopup").css({  
			"opacity": "0.7"  
		});
		$("#popupFacebookAlertClose").hide();
		$("#popup_create_asso_button").hide();
		$("#popup_cancel_button").hide();
		$("#popup_fail_button").hide();
		$("#popup_birthday_cancel_button").hide();
		//$("#popup_birthday_ok_button").attr("href","javascript:nothing();");
		$("#popup_birthday_ok_button").show();
		$("#popup_ok_button").hide();
		//$("#backgroundPopup").fadeIn("slow");  
		//$("#popupFacebookAlert").fadeIn("quick");
		$("#backgroundPopup").show();  
		$("#popupFacebookAlert").show();
		
		if ($("#popup_birthday_ok_button").attr("href")=="javascript:getFriendsAlert();"){
			$("#popupFacebookAlertClose").hide();
			$("#popup_birthday_cancel_button").show();
		}
		
		popupStatus = 1;  
	}
}

function setPopupAssoText(text){

	$("#popupFacebookAlertText").html(text);

}

//disabling popup with jQuery magic!  
function disablePopupAsso(reload){  
	//disables popup only if it is enabled  
	if(popupStatus==1){  
		//$("#backgroundPopup").fadeOut("slow");  
		//$("#popupFacebookAlert").fadeOut("slow");  
		$("#backgroundPopup").hide();  
		$("#popupFacebookAlert").hide();  
		popupStatus = 0;  
	}
	if (reload)
	location.reload();
}  

function disablePopupBirthdayAlert(){  
	//disables popup only if it is enabled  
	if(popupStatus==1){  
		$("#backgroundPopup").hide();  
		$("#popupFacebookAlert").hide(); 
		$("#popupFacebookAlertContent").html('');
		$("#popupFacebookAlert").css("font-size","16px");
		$("#popupFacebookAlertContent").css("height","30px");
		$("#popupFacebookAlert").width(300);
		$("#popupFacebookAlert").height(200);
		$("#popup_birthday_ok_button").attr("href","javascript:nothing();");
		$("#popupFacebookAlertHeader").css("background-color","");
		$("#popupFacebookAlertText").css("color","");
		$("#popupFacebookAlertText").css("font-weight","");
		$("#popupFacebookAlertText").css("margin","");
		$("#popupFacebookAlert").css("border","2px solid #FF7C00");
		$("#popup_birthday_cancel_button").hide();
		$("#popup_birthday_ok_button_image").attr("src","/img/popup_fb_ok.gif");
		$("#popupFacebookAlertFooter").css("text-align","");
		popupStatus = 0;  
	}
	
}  

//centering popup  
function centerPopupAsso(){  
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#popupFacebookAlert").height();  
	var popupWidth = $("#popupFacebookAlert").width();  
	//centering  
	$("#popupFacebookAlert").css({  
		"position": "absolute",  
		"top": windowHeight/2-popupHeight/2,  
		"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  

	$("#backgroundPopup").css({  
		"height": windowHeight  
	});  

}

function launchAlbumRetrieving(){
	$("#album_fb_loader").show();
	$.get("/Facebook_photos.php",
	function(data){
		$("#album_fb_loader").hide();
		window.location = "/Facebook_photos.php";
	});

}

function disconnect_fb_account(){

	$.get("/FB_disconnect_account.php",
	function(data){
		window.location.reload();
	});
}

function nothing(){}

function doSubmit(param) {
	if (param != ''){
		var hFrm = window.document.getElementById(param);
		if (param == 'img1' && check('photo'))
		showProgress();

		if (param == 'rcv' && !checkReceiver())
		return;

		if (param == 'sponsoring_prog' && !checkSponsoringProgram())
		return;

		if (param == 'audiotel' && !checkAForm())
		return;

		if (param == 'regForm' && !checkRegistrationForm())
		return;

		if (param == 'loginForm' && !checkLoginForm())
		return;

		if (param == 'lgnForm') {
			var hWnd = window.document.getElementsByName("option");
			for (var i=0; i < hWnd.length; i++) {
				if ((hWnd[i].type.toLowerCase() == 'radio') && (hWnd[i].checked)) {
					if (hWnd[i].value == 1) {
						continue;
					} else if (hWnd[i].value == 2) {
						if (!checkLoginForm()) return;
					}
				}
			}
		}

		if (param == 'prForm' && !checkForm())
		return;

		if (param == 'user' && !checkUserForm()){
			return;
		}

		if (param == 'changePasswdForm' && !checkPasswd())
		return;

		if (param == 'byr') {
			_hideErrors();
			if (!checkRegCmdForm())
			return;
			else if (!checkCBox())
			return;
			else if (!checkPaymentType())
			return;
			
		}

		if (param == 'shpmnt') {
			if (!checkShpmnt())
			return;
		}

		if (param == 'frmtForm'){
			if (!checkFrmt())
			return;
		}

		if (param == 'mobile_questionnaire_form'){
			if (!checkMobileQuestionnaire())
				return;
		}
		if (param == 'mobile_questionnaire_form_en'){
			if (!checkMobileQuestionnaire_en())
				return;
		}

		hFrm.submit();
	}
}

function checkMobileQuestionnaire(){
	if ($('input:[name="cb_1"]').length){
		if ($("input:checked").length==0){
		alert("Veuillez sélectionner au moins une raison");
		return false;
		}
	}
		if ($('#usertext_2').val()==''){
		alert("Veuillez répondre à toutes les questions");
		return false;
		}
	return true;
}

function checkMobileQuestionnaire_en(){
	if ($('input:[name="cb_1"]').length){
		if ($("input:checked").length==0){
		alert("Please check at least one reason");
		return false;
		}
	}
	
	if ($('#usertext_2').val()==''){
		alert("Please answer to all the questions");
		return false;
	}
	
	return true;
}

function checkShpmnt() {
	hFrm = window.document.getElementById('stype');
	if(hFrm.value!="rcv" && hFrm.value!="sback"){
		alert('Veuillez choisir une option d\'envoi');
		return false;
	}
	return true;
}

function checkFrmt() {
	if(format_clicked<0){
		alert('Veuillez choisir un format');
		return false;
	}
	return true;
}

function showProgress() {
	var hDiv = window.document.getElementById('progress');

	hDiv.style.left = (screen.availWidth/2)-(196);
	hDiv.style.visibility = 'visible';
	hDiv.style.display = 'block';
	setTimeout('document.images["upl"].src = "/images/popup_telechargement.gif"', 200);
	//hDiv.innerHTML= '<img id="upl" src="images/popup_telechargement.gif" />';
}

function check(id) {
	var hObj = window.document.getElementById(id);

	if (hObj.value != '')
	return true;

	return false;
}

function removeSpaces(string) {
	return string.split(' ').join('');
}

function checkReceiver() {
	var hInputs = window.document.getElementsByTagName("INPUT");
	var prevRec = window.document.getElementsByName("rPrevRec");
	var ret = true;
	var gret = false;
	var reqGroup = new Object;
	var skipcheck = false;

	for (var i=0; i<hInputs.length; i++) {
		hInputs[i].value = hInputs[i].value.replace(/;/g,'');
	}
	for (var i=0; i<prevRec.length; i++) {
		if (prevRec[i].checked && prevRec[i].value!="") skipcheck=true;
	}
	
	if (!skipcheck){
		for (var i=0; i<hInputs.length; i++) {

			if (hInputs[i].name == "rZipcode") {
				hInputs[i].value = removeSpaces(hInputs[i].value) ;
			}
			
			if ((hInputs[i].getAttribute("isRequired") == '1') && (hInputs[i].type != 'checkbox')){
				if (!(hInputs[i].value != "")) {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					_showError("errText");
					ret=false;
				} else {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
				}
			}
			if(hInputs[i].getAttribute("groupRequired")) {
				if(reqGroup[hInputs[i].getAttribute("groupRequired")])
				reqGroup[hInputs[i].getAttribute("groupRequired")].push(hInputs[i]);
				else {
					reqGroup[hInputs[i].getAttribute("groupRequired")] = new Array();
					reqGroup[hInputs[i].getAttribute("groupRequired")].push(hInputs[i]);
				}
			}
		}
	}
	for(var gr in reqGroup) {
		gret = false;
		for(var i = 0; i < reqGroup[gr].length; i++) {
			if(reqGroup[gr][i].value != '') {
				gret = true;
			}
			window.document.getElementById(reqGroup[gr][i].name+"_label").style.color = "#333333";
		}
		if(!gret) {
			_showError("errText");
			ret=false;
			for(var i = 0; i < reqGroup[gr].length; i++) {
				window.document.getElementById(reqGroup[gr][i].name+"_label").style.color = "#ff7f00";
			}
		}
	}
	return ret;
}

function checkForm() {

	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;
	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1')){
			if (!(hInputs[i].value != "")) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				_showError("errText");
				ret=false;
			} else if ( (hInputs[i].name=="rEmail") && !(check_email(hInputs[i].value)) ){
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				ret=false;
				alert("Votre adresse email n'est pas correcte");
				hInputs[i].focus();
			} else {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
			}
		}
	}
	return ret;
}

function checkRegCmdForm() {

	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;
	var emailObj = "";

	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1')){
			if (!(hInputs[i].value != "")) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				_showError("errText");
				ret=false;

			} else if ( hInputs[i].name=="rEmail") {
				if (!(check_email(hInputs[i].value))) {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					ret=false;
					alert("Votre adresse email n'est pas correcte");
					hInputs[i].focus();
				}
				emailObj = hInputs[i];
			} else if ( hInputs[i].name=="rEmailConf" && hInputs[i].value != emailObj.value ){
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				ret=false;
				_showError("errEmailConf");
				hInputs[i].focus();

			} else if ( (hInputs[i].name=="rPasswd") && (hInputs[i].value != hInputs[i+1].value) ) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				//window.document.getElementById(hInputs[i+1].name+"_label").style.color = "#ff7f00";
				ret=false;
				_showError("errPasswd");
			} else {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
			}
		}
	}


	//this if checks if the radiobuttons are present (on command the arent if you are logged in)
	if ($(".rCheck3").length > 0){

		//if the radiobuttons are present this checks if they are clicked
		if (!$(".rCheck3:checked").val()) {
			alert("Vous devez cocher si vous acceptez ou non recevoir les offres de nos partenaires afin de valider votre inscription");
			$('#rCheck3_label').css('color', '#ff7c00');
			return false;
		}
		else {
			$('#rCheck3_label').css('color', '#666');
		}  
	}   


	return ret;
}

function checkLoginForm() {

	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;

	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1')){
			if (!(hInputs[i].value != "")) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				_showError("errText");
				ret=false;
			} else {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
			}
		}
	}
	return ret;
}

function checkCBox() {
	var hC2 = window.document.getElementById('rCheck1');

	if (hC2 && !hC2.checked) {
		window.document.getElementById("rCheck1_label").style.color = "#ff7f00";
		alert("Vous devez accepter nos conditions de vente pour terminer votre commande");

		hC2.focus();
		return false;
	}

	return true;
}

function checkPaymentType() {
	var hR = window.document.getElementsByName('payment_type');
	if(hR.length) {
		for (var i =0; i<hR.length; i++) {
			if (hR[i].checked == true) return true;
		}
		_showError("errPay");
		//   window.document.getElementById("payment_type_label").style.color = "#ff7f00";

		return false;
	}
	return true;
}

function _showError(err) {
	var hObj = window.document.getElementById(err);
	if (hObj)
	hObj.style.display = "block";
}

function _hideError(err) {
	var hObj = window.document.getElementById(err);
	if (hObj)
	hObj.style.display = "none";
}

function _hideErrors() {
	window.document.getElementById("errText").style.display = "none";
	window.document.getElementById("errPay").style.display = "none";
	window.document.getElementById("errPasswd").style.display = "none";
	window.document.getElementById("errEmailConf").style.display = "none";
}

function showPopup(cmd,params) {
	window.open("/popup.php?act="+cmd+params,"_blank","width=740,height=740,toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
}

function showPopup2(image, width, height) {
	window.open(image,"_blank","width="+width+",height="+height+",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1");
}

function maxLen(field,maxlimit){
	var hField = document.getElementById(field);
	if (hField.value.length > maxlimit) {
		hField.value = hField.value.substring(0,maxlimit);
	}
}

function maxLen_flowers(field,maxlimit,event){

	if (event.keyCode == 13 || event.keyCode == 222) {
		return false;
	}
	else {
		var hField = document.getElementById(field);
		if (hField.value.length > maxlimit) {
			hField.value = hField.value.substring(0,maxlimit);
		}
		return true;
	}
}


function isChecked(id, message) {
	var hC2 = window.document.getElementById(id);
	if (!hC2.checked) {
		window.document.getElementById(id+"_label").style.color = "#ff7f00";
		alert(message);
		hC2.focus();
		return false;
	}
	return true;
}

function checkRegistrationForm() {
	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;
	var emailObj = "";

	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1') && (hInputs[i].type != 'checkbox')){
			if (!(hInputs[i].value != "")) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				_showError("errText");
				ret=false;
			} else if (hInputs[i].name=="rEmail") {
				if (!check_email(hInputs[i].value)) {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					ret=false;
					_showError("errEmail");
				} else {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
					_hideError("errEmail");
				}
				emailObj = hInputs[i];
			} else if (hInputs[i].name=="rEmailConf") {
				if (hInputs[i].value != emailObj.value) {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					window.document.getElementById(emailObj.name+"_label").style.color = "#ff7f00";
					ret=false;
					_showError("errEmailConf");
				} else {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
					window.document.getElementById(emailObj.name+"_label").style.color = "#333333";
					_hideError("errEmailConf");
				}
			} else if (hInputs[i].name=="rPasswd") {
				if (hInputs[i].value != hInputs[i+1].value) {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					//window.document.getElementById(hInputs[i+1].name+"_label").style.color = "#ff7f00";
					ret=false;
					_showError("errPasswd");
				} else {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
					_hideError("errPasswd");
				}
			} else if (hInputs[i].name=="rPasswdConf") {
				if (hInputs[i].value != hInputs[i-1].value) {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					//window.document.getElementById(hInputs[i+1].name+"_label").style.color = "#ff7f00";
					ret=false;
					_showError("errPasswd");
				} else {
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
					_hideError("errPasswd");
				}
			} else {
				if (window.document.getElementById(hInputs[i].name+"_label")!=null) window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
			}
		}
	}

	if (ret && !isChecked('rCheck1',"Vous devez accepter nos conditions de vente pour valider votre inscription"))
	return false;
	

	if (!$(".rCheck3:checked").val()) {
		alert("Vous devez cocher si vous acceptez ou non recevoir les offres de nos partenaires afin de valider votre inscription");
		$('#rCheck3_label').css('color', '#ff7c00');
		return false;
	}
	else {
		$('#rCheck3_label').css('color', '#666');
	}


	return ret;
}


//new sponsoring program (this function checks mandatory email)
function checkSponsoringProgram() 
{
	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;

	for (var i=0; i<hInputs.length; i++) 
	{
		if ((hInputs[i].getAttribute("isRequired") == '1') && (hInputs[i].type != 'checkbox'))
		{
			if (!(hInputs[i].value != "")) 
			{
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				_showError("errText");
				ret=false;
			} 
			else if (hInputs[i].name=="rEmail") 
			{
				if (!check_email(hInputs[i].value)) 
				{
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
					ret=false;
					_showError("errEmail");
				} 
				else 
				{
					window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
					_hideError("errEmail");
				}
			}

		} 
		else 
		{
			window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
		}
	}
	return ret;
}



function checkPasswd() {
	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;

	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1') && (hInputs[i].type != 'checkbox')){
			if (!(hInputs[i].value != "")) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				_showError("errText");
				ret=false;
			} else if ( (hInputs[i].name=="rPasswd") && (hInputs[i].value != hInputs[i+1].value) ) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				window.document.getElementById(hInputs[i+1].name+"_label").style.color = "#ff7f00";
				ret=false;
				_showError("errPasswd");
			} else {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
			}
		}
	}
	return ret;
}

function checkAForm() {

	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;
	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1')){
			if (!(hInputs[i].value != "")) {
				alert("Vous n'avez pas entrï¿½ les 2 codes");
				return false;
			}
		}
	}
	return true;
}

function checkUserForm() {

	var hInputs = window.document.getElementsByTagName("INPUT");
	var ret = true;
	for (var i=0; i<hInputs.length; i++) {
		if ((hInputs[i].getAttribute("isRequired") == '1')){
			if (!(hInputs[i].value != "")) {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#ff7f00";
				ret = false;
			} else {
				window.document.getElementById(hInputs[i].name+"_label").style.color = "#333333";
			}
		}
	}
	if (!ret)
	alert("Les informations en orange sont requises pour la modification de votre profil");
	return ret;
}

function check_email(email) {

	var filter=/^.+@.+\..{2,4}$/

	if (email=='') return false;

	return (filter.test(email)) ? true : false;
}

function checkEmail(fieldId) {
	var hField = window.document.getElementById(fieldId);
	if (!check_email(hField.value)){
		alert("Votre adresse email n'est pas correcte");
		return false;
	}

	return true;
}

function changeOption(src, id) {
	var hWnd = window.document.getElementById(id);

	if (hWnd && src) {
		if (src.value != '') {
			hWnd.checked = true;
		}
	}
}

var currentPage=1;
var maxPage=1;
function showMinPage(nb) {

	currentPage = nb;
	for (i=1; i <= maxPage; i++)
	if (i == nb) {
		document.getElementById('page' + i).style.display = "block";
		document.getElementById('pageLnk' + i).style.fontWeight = "bold";
	} else {
		document.getElementById('page' + i).style.display = "none";
		document.getElementById('pageLnk' + i).style.fontWeight = "normal";
	}            
	scrollTo(0,0);
}
function showPagePrev() {
	if (currentPage > 1) {
		currentPage--;
		showMinPage(currentPage);
	}
}
function showPageNext() {
	if (currentPage < maxPage) {
		currentPage++;
		showMinPage(currentPage);
	}
}

//functions for send mode choice

var send_mode_clicked=-1;

function shipmentSwitch(id, highlight){

	var div = window.document.getElementById(id);
	var stype = window.document.getElementById('stype');
	if (send_mode_clicked < 0){
		if (highlight){
			div.style.backgroundColor = "#FFCC66";
			div.style.border = "1px solid #FFCC66";
		}
		else {
			div.style.backgroundColor = "#f7f7f7";
			div.style.border = "1px solid #feb74c";
			stype.value="";	    
		}
	}
}

function clickSendMode(mode){
	send_mode_clicked = mode;
	var stype = window.document.getElementById('stype');
	if (mode == 1){
		window.document.getElementById('shipDiv1').style.backgroundColor = "#feb74c";
		window.document.getElementById('shipDiv1').style.border = "1px solid #FF9900";
		stype.value="rcv";
		window.document.getElementById('imgTick1').style.display = "block";

		window.document.getElementById('shipDiv2').style.backgroundColor = "#f7f7f7";
		window.document.getElementById('shipDiv2').style.border = "1px solid #feb74c";
		window.document.getElementById('imgTick2').style.display = "none";
	}
	else {
		window.document.getElementById('shipDiv2').style.backgroundColor = "#feb74c";
		window.document.getElementById('shipDiv2').style.border = "1px solid #FF9900";
		stype.value="sback";
		window.document.getElementById('imgTick2').style.display = "block";

		window.document.getElementById('shipDiv1').style.backgroundColor = "#f7f7f7";
		window.document.getElementById('shipDiv1').style.border = "1px solid #feb74c";
		window.document.getElementById('imgTick1').style.display = "none";
	}
}

//functions for choose format page

var descriptions = new Array();
descriptions[1]='La carte postale classique, 10x15 cm, papier 350 gr avec une couche de pelliculage brillant sur le recto.<br />Prix d&eacute;gressifs en fonction des quantit&eacute;s et du mode d&prime;envoi &agrave; partir de 0.62 &euro; la carte.<br />';
descriptions[2]='L&prime;&eacute;l&eacute;gante carte carr&eacute;e 15x15 cm, papier 350 gr avec une couche de pelliculage brillant sur le recto. Vendue avec enveloppe.<br />Prix d&eacute;gressifs en fonction des quantit&eacute;s et du mode d&prime;envoi &agrave; partir de 0.95 &euro; la carte.<br />';
descriptions[3]='L&prime;&eacute;l&eacute;gante carte carr&eacute;e 15x15 cm pli&eacute;e, papier 350 gr avec une couche de pelliculage brillant sur le recto. Vendue avec enveloppe.<br />Prix d&eacute;gressifs en fonction des quantit&eacute;s et du mode d&prime;envoi &agrave; partir de 1.25 &euro; la carte.<br />';
descriptions[4]='La belle carte pli&eacute;e &agrave; deux volets 13x18 cm, papier 300 gr. Vendue avec enveloppe.<br />Prix d&eacute;gressifs en fonction des quantit&eacute;s et du mode d&prime;envoi &agrave; partir de 1.30 &euro; la carte.<br />';
descriptions[5]='La surprenante carte g&eacute;ante 20x30 cm, papier 350 gr avec une couche de pelliculage brillant sur le recto.<br />Vendue avec enveloppe. Prix d&eacute;gressifs en fonction des quantit&eacute;s et du mode d&prime;envoi &agrave; partir de 3.75 &euro; la carte.<br />';


var format_clicked = -1;
var first_mouseover = 1;
var default_format = 0;
var default_tmpl = 0;

function is_numeric(input){
	return typeof(input)=='number';
}

function setDefaultFormat(format, elt, url){
	default_format = format;
	document.getElementById('desc').innerHTML=descriptions[format];
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	document.getElementById('prevImage').src="/img/pix.png";
	document.getElementById('prevImage').src=url[format];
}

function setDefaultFormat2(template, elt){
	default_format = template['id'];
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	$('#prevImage').attr('src',"/img/pix.png");
	$('#prevImage').attr('src',template['preview']);
	$('#template_name').html(template['name']);
	$('#template_price').html(template['price']);
	$('#template_compo').html(template['composition']);
	$('#template_width').html(template['width']);
	$('#template_height').html(template['height']);
	$('#template_desc').html(template['desc']);
	
	$('#tid').val(template['id']);
	$('#fid').val(template['fid']);
}


function setGiftDefaultFormat(format, elt, current_tmpl, formats){
	default_format = format;
	document.getElementById('desc').innerHTML=formats[current_tmpl][format]['description'];
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	document.getElementById('prevImage').src="/img/pix.png";
	document.getElementById('prevImage').src=formats[current_tmpl][format]['preview'];
}

function setGiftDefaultMultiFormat(format, elt, current_tmpl, formats){
	default_format = format;
	default_tmpl = current_tmpl; 
	document.getElementById('desc').innerHTML=formats[current_tmpl][format]['description'];
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	document.getElementById('prevImage').src="/img/pix.png";
	document.getElementById('prevImage').src=formats[current_tmpl][format]['preview'];
}


function overFormat(format, elt, url){
	elt.style.cursor='pointer';

	if (format_clicked<0){
		if (first_mouseover){
			outFormat(default_format, document.getElementById('select_'+default_format));
			first_mouseover = 0;
		}
		document.getElementById('desc').innerHTML=descriptions[format];
		elt.style.background='#e7e7e7';
		elt.style.border="1px #feb74c solid";
		document.getElementById('prevImage').src="/img/pix.png";
		document.getElementById('prevImage').src=url[format];
	}
}

function overFormat2(elt, template){

	elt.style.cursor='pointer';
	
	if (format_clicked<0){
		if (first_mouseover){
			outFormat(default_format, document.getElementById('select_'+default_format));
			first_mouseover = 0;
		}
		$('#prevImage').attr('src',"/img/pix.png");
		$('#prevImage').attr('src',template['preview']);
		$('#template_name').html(template['name']);
		$('#template_price').html(template['price']);
		$('#template_compo').html(template['composition']);
		$('#template_width').html(template['width']);
		$('#template_height').html(template['height']);
		$('#template_desc').html(template['desc']);
		elt.style.background='#e7e7e7';
		elt.style.border="1px #feb74c solid";
		elt.style.borderTop="1px #feb74c solid";
		elt.style.borderLeft="1px #feb74c solid";
		elt.style.borderRight="1px #feb74c solid";
		elt.style.borderBottom="1px #feb74c solid";
	}
}

function outFormat(format, elt){
	if (format_clicked<0){
		elt.style.backgroundColor='';
		elt.style.border="";
	}
}


function clickFormat(formats, format, elt, url){
	for (var f in formats){
		var _f = document.getElementById('select_'+f);
		if (_f != null){
			_f.style.background='';
			_f.style.border='';
		}
	}
	var date = new Date();
	format_clicked = format;
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	document.getElementById('fid').value=format;
	document.getElementById('desc').innerHTML=descriptions[format];
	document.getElementById('prevImage').src="/img/pix.png";
	document.getElementById('prevImage').style.display="none";
	document.getElementById('prevImage').src=url[format]+'&t2='+date.getTime();
	// document.getElementById('prevImage').src=url[format];
	document.getElementById('prevImage').style.display="block";
}

function clickFormat2(templates, template, elt){
	for (var t in templates){
		var _t = document.getElementById('select_'+t);
		if (_t != null){
			_t.style.background='';
			_t.style.border='';
		}
	}
	var date = new Date();
	format_clicked = template['id'];
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	$('#tid').val(template['id']);
	$('#fid').val(template['fid']);
	$('#template_desc').html(template['desc']);
	$('#template_name').html(template['name']);
	$('#template_price').html(template['price']);
	$('#template_compo').html(template['composition']);
	$('#template_width').html(template['width']);
	$('#template_height').html(template['height']);
	$('#prevImage').attr('src',"/img/pix.png");
	$('#prevImage').hide();
	$('#prevImage').attr('src',template['preview']+'&t2='+date.getTime());
	$('#prevImage').show();
}

function change_gift_tmpl(formats){

	var tid = document.getElementById('tmpl').value;
	document.getElementById('tid').value = tid;

	document.getElementById('prevImage').src="/img/pix.png";

	fs = document.getElementsByName('format_select');

	for(var i=0; i < fs.length; i++)
	{
		document.getElementsByName('format_select').item(i).style.display="none";
	}


	var fid='';

	for (var f in formats[tid]){
		if (fid == '') fid = f;
		document.getElementById('select_'+f).style.display="block";
	}


	var elem = document.getElementById('select_'+fid);

	if (format_clicked<0) overGiftFormat(fid, elem, formats)
	else clickGiftFormat(formats, fid, elem);
}

function clickGiftFormat(formats, format, elt){

	var tid = document.getElementById('tid').value;
	
	for (var f in formats[tid]){
		var _f = document.getElementById('select_'+f);
		if (_f != null){
			_f.style.background='';
			_f.style.border='';
		}
	}

	format_clicked = format;
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	document.getElementById('fid').value=format;
	document.getElementById('desc').innerHTML=formats[tid][format]['description'];
	document.getElementById('prevImage').src="/img/pix.png";
	//document.getElementById('prevImage').style.display="none";
	document.getElementById('prevImage').src=formats[tid][format]['preview'];
	document.getElementById('prevImage').style.display="block";
}

function overGiftFormat(format, elt, formats){
	elt.style.cursor='pointer'; 

	if (format_clicked<0){
		if (first_mouseover){
			outFormat(default_format, document.getElementById('select_'+default_format));
			first_mouseover = 0;
		}
		var tid = document.getElementById('tid').value;
		document.getElementById('desc').innerHTML=formats[tid][format]['description'];
		elt.style.background='#e7e7e7';
		elt.style.border="1px #feb74c solid";
		document.getElementById('prevImage').src="/img/pix.png";
		document.getElementById('prevImage').src=formats[tid][format]['preview'];
	}
}

function overGiftMultiFormat(format, elt, formats, tid){
	elt.style.cursor='pointer'; 

	if (format_clicked<0){
		if (first_mouseover){
			outFormat(default_format, document.getElementById('select_'+default_tmpl+'_'+default_format));
			first_mouseover = 0;
		}

		document.getElementById('desc').innerHTML=formats[tid][format]['description'];
		elt.style.background='#e7e7e7';
		elt.style.border="1px #feb74c solid";
		document.getElementById('prevImage').src="/img/pix.png";
		document.getElementById('prevImage').src=formats[tid][format]['preview'];
		
		document.getElementById('tid').value = tid;
	}
}

function clickGiftMultiFormat(formats, format, elt, tid){
	
	for (var tmpl in formats){
		for (var f in formats[tmpl]){
			var _f = document.getElementById('select_'+tmpl+'_'+f);
			if (_f != null){
				_f.style.background='';
				_f.style.border='';
			}
		}
	}

	format_clicked = format;
	elt.style.background='#e7e7e7';
	elt.style.border="1px #feb74c solid";
	document.getElementById('fid').value=format;
	document.getElementById('desc').innerHTML=formats[tid][format]['description'];
	document.getElementById('prevImage').src="/img/pix.png";
	document.getElementById('prevImage').src=formats[tid][format]['preview'];
	
	document.getElementById('tid').value = tid;
}

function toComDetails(){

	document.getElementById('com_main').style.display="none";
	document.getElementById('com_main').style.visibility="hidden";
	document.getElementById('com_details').style.display="";
	document.getElementById('com_details').style.visibility="";

}

function toComMain(){

	document.getElementById('com_details').style.display="none";
	document.getElementById('com_details').style.visibility="hidden";
	document.getElementById('com_main').style.display="";
	document.getElementById('com_main').style.visibility="";
}


function select_font_alignement(choice){

	//alert('1');

	var left = document.getElementById('alignement_left');
	var center = document.getElementById('alignement_center');
	var right = document.getElementById('alignement_right');

	//alert('2');

	if (choice=='left')
	{
		left.src='/img/align-left_up.gif';
		center.src='/img/align-center.gif';
		right.src='/img/align-right.gif';
	}
	if (choice=='center')
	{
		left.src='/img/align-left.gif';
		center.src='/img/align-center_up.gif';
		right.src='/img/align-right.gif';
	}
	if (choice=='right')
	{
		left.src='/img/align-left.gif';
		center.src='/img/align-center.gif';
		right.src='/img/align-right_up.gif';
	}

	//alert('3');

}

function select_font_color(item_selected){

	//alert('1');

	var c1 = document.getElementById('font_color1');
	var c2 = document.getElementById('font_color2');
	var c3 = document.getElementById('font_color3');
	var c4 = document.getElementById('font_color4');
	var c5 = document.getElementById('font_color5');
	var c6 = document.getElementById('font_color6');
	var c7 = document.getElementById('font_color7');
	var c8 = document.getElementById('font_color8');
	var c9 = document.getElementById('font_color9');
	var c10 = document.getElementById('font_color10');

	var color = document.getElementById('color');
	var color_return = document.getElementById('colorForReturn');
	//alert('2');

	if (item_selected=='font_color1'){
		c1.src='/img/font_color1_up.gif';
		color.value="#000000";
		color_return.value=color.value;
	}
	else {c1.src='/img/font_color1.gif';}

	if (item_selected=='font_color2'){
		c2.src='/img/font_color2_up.gif';
		color.value="#070789";
		color_return.value=color.value;
	}
	else {c2.src='/img/font_color2.gif';}

	if (item_selected=='font_color3'){
		c3.src='/img/font_color3_up.gif';
		color.value="#C2011E";
		color_return.value=color.value;
	}
	else {c3.src='/img/font_color3.gif';}
	
	if (item_selected=='font_color4'){
		c4.src='/img/font_color4_up.gif';
		color.value="#007E08";
		color_return.value=color.value;
	}
	else {c4.src='/img/font_color4.gif';}
	
	if (item_selected=='font_color5'){
		c5.src='/img/font_color5_up.gif';
		color.value="#FFC208";
		color_return.value=color.value;
	}
	else {c5.src='/img/font_color5.gif';}
	
	if (item_selected=='font_color6'){
		c6.src='/img/font_color6_up.gif';
		color.value="#7B7B7B";
		color_return.value=color.value;
	}
	else {c6.src='/img/font_color6.gif';}
	
	if (item_selected=='font_color7'){
		c7.src='/img/font_color7_up.gif';
		color.value="#A4CBE8";
		color_return.value=color.value;
	}
	else {c7.src='/img/font_color7.gif';}
	
	if (item_selected=='font_color8'){
		c8.src='/img/font_color8_up.gif';
		color.value="#D411AD";
		color_return.value=color.value;
	}
	else {c8.src='/img/font_color8.gif';}
	
	if (item_selected=='font_color9'){
		c9.src='/img/font_color9_up.gif';
		color.value="#F25208";
		color_return.value=color.value;
	}
	else {c9.src='/img/font_color9.gif';}
	
	if (item_selected=='font_color10'){
		c10.src='/img/font_color10_up.gif';
		color.value="#ED83AB";
		color_return.value=color.value;
	}
	else {c10.src='/img/font_color10.gif';}

	//alert('3');

}

function select_font_size(){
	var size = document.getElementById('font_size').value;
	document.getElementById('sizeForReturn').value = size;
}

function select_font(item_selected){
	var font = document.getElementById('font').value;
	document.getElementById('fontForReturn').value = font;
}


function linker(link)
{
	var new_link = link.replace(/!/g,"/");
	var final_link = new_link.replace(/@/g,".");
	window.location = final_link;
}



//joursFeries.js
//syntax : d/m/yyyy (without initial 0)
var jourFeries = new Array(
"9/9/2008",
"12/9/2008",
"23/9/2008",
"14/10/2008"
);


//popup.js
var isPopDefined = false;

var xoffset = 15;
var yoffset = 10;

document.onmousemove = function(e) {
	if (!isPopDefined)
	return;

	var x, y, right, bottom;

	try { x = e.pageX; y = e.pageY; yyy = 0; } // FF
	catch(e) { x = event.x; y = event.y; yyy = document.documentElement.scrollTop} // IE

	right = (document.documentElement.clientWidth || document.body.clientWidth || document.body.scrollWidth);
	bottom = (window.scrollY || document.documentElement.scrollTop || document.body.scrollTop) + (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || document.body.scrollHeight);

	x += xoffset;
	y += yoffset;

	if(x > right-pop.offsetWidth)
	x = right-pop.offsetWidth;

	if(y+yyy > bottom-pop.offsetHeight)
	y = bottom-pop.offsetHeight-yyy;

	pop.style.top = y+yyy+'px';
	pop.style.left = x+'px';

}

function popup(elt) {
	if (!isPopDefined) {
		isPopDefined = true;
		pop = document.getElementById('popup');
	}
	document.getElementById('popup_img_over').innerHTML = "";
	//document.getElementById('popup_img').setAttribute('src', '/images/rouegrise.gif');
	document.getElementById('popup_img_over').innerHTML = "<img src='" + elt.getAttribute('srcBig') + "' align='center'>";
	document.getElementById('popup_span').innerHTML = elt.getAttribute('itemName');
	pop.style.display = 'block';
}

function popout() {
	pop.style.display = 'none';
}

function editorSaveStart(msg) {
	window.onbeforeunload = function() {
		return msg;
	}
}
function editorSaveEnd() {
	window.onbeforeunload = null;
}

function orderStatusSwitchDetails(elt){

	if (document.getElementById('details').style.display=="none")
	document.getElementById('details').style.display="block";
	else document.getElementById('details').style.display="none";

}

function validateQuestionnaire(){


}
function facebook_popup(){
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#facebook_popup").height();  
	var popupWidth = $("#facebook_popup").width();  
	//centering  
	$("#facebook_popup").css({  
		"position": "absolute",  
		"top": windowHeight/2-popupHeight/2,  
		"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  

	$("#backgroundPopup").css({  
		"height": windowHeight  
	});  
	
	$('#facebook_popup').show();
	$('#backgroundPopup').show();
}

function facebook_popup_close(){
	$('#facebook_popup').hide();
	$('#backgroundPopup').hide();
}

//POPUP CREATING FUNCTION
function pop_the_popup(url,height,width) {
	newwindow=window.open(url,'name','height='+height+',width='+width);
	if (window.focus) {newwindow.focus()}
	return false;
}

function array2json(arr) {
	var parts = [];
	var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');

	for(var key in arr) {
		var value = arr[key];
		if(typeof value == "object") { //Custom handling for arrays
			if(is_list) parts.push(array2json(value)); /* :RECURSION: */
			else parts[key] = array2json(value); /* :RECURSION: */
		} else {
			var str = "";
			if(!is_list) str = '"' + key + '":';

			//Custom handling for multiple data types
			if(typeof value == "number") str += value; //Numbers
			else if(value === false) str += 'false'; //The booleans
			else if(value === true) str += 'true';
			else str += '"' + convertString(String(value)) + '"'; //All other things
			// :TODO: Is there any more datatype we should be in the lookout for? (Functions?)

			parts.push(str);
		}
	}
	var json = parts.join(",");
	
	if(is_list) return '[' + json + ']';//Return numerical JSON
	return '{' + json + '}';//Return associative JSON
}

function convertString(string){
	string = string.replace(/"/g,"'");
string = string.replace(/&/g,"%26");
string = string.replace(/\\/g,"\\\\");
return string;
}

//DELETING SAVED CARDS CONFIRM
function confirmGo(m,u) {
  if ( confirm(m) ) 
  {
    window.location = u;
  }
}
