var LabelEscape = new Object();
LabelEscape['&#202;'] = 'Ê';
LabelEscape['&#233;'] = 'é';
LabelEscape['&#232;'] = 'è';
LabelEscape['&#234;'] = 'ê';
LabelEscape['&#146;'] = '’';
LabelEscape['&#224;'] = 'à';
LabelEscape['&#8217;'] = '’';
LabelEscape['&#226;'] = 'â';


function GetLabel(l)
{
	var ret = l;
	for (var key in LabelEscape) 
	{
		ret = ret.replace(new RegExp(key,'g'), LabelEscape[key]);
	}
// 	alert(ret);
	return ret;
}



function CalculatorSWFNavigation (template) {
	$("#calculator_navigation_expand li ul li a.active").removeClass('active');
	to_activate = ".CalculatorSWFNavigation_"+template;
	$(to_activate).addClass('active');
	title = $(to_activate+":first").text();
	link = $(to_activate+":first").attr('href');
	jslink = "CalculatorSWFNavigation('"+template+"');";
	breadcrumb_change = "#breadcrumb li:last a";
	$(breadcrumb_change).text(title);
	$(breadcrumb_change).attr('href', link);
	$(breadcrumb_change).removeAttr('onclick');
	$(breadcrumb_change).attr('onClick', jslink);
	get_profile_completion('4219');
	if($("#flashcontent_description")) {
		url = document.location.href;
		start = url.indexOf('ID=') + 3;
		ID = url.substr(start,4);
		$.get("CalculatorSWFDescription.php", { ID: ID, template: template },
		  function(data){
			$('#flashcontent_specific_description').html(data);
		  });
	}
}

function check_mandatory_fields (form, alert_message) {
	fields = "#"+form+" select.mandatory, #"+form+" input.mandatory";
	to_check = $(fields).map(function(){if ($(this).val() == "" | $(this).val() == "null") {return "empty_field";} else {return $(this).val();}}).get();
	to_check = to_check.toString();
	if (to_check.indexOf('empty_field') > -1) {
		alert(alert_message);
	} else {
		$("#"+form).submit();
	}
}
function get_profile_completion (ID) {
	$.get("CalculatorProfileCompletion.php", {ID:ID, display:'preview'}, function(data){
		$('#media_'+ID+" h1").replaceWith(data);
	});
}
function get_comparaison_graphic (hID) {
	$.get("GraphiqueComparaison.php", {hID:hID}, function(data){
		$('#comparaison_graphic').append(data);
		$('#comparaison_graphic_loader').remove();
	});
}
function get_graphic (type, hID) {
	$.get("GraphiqueCSS.php", {type:type, hID:hID}, function(data){
		$('#'+type).append(data);
		$('#'+type+'_loader').remove();
	});
}
function check_subscribtion_form (message_not_full, message_email, message_psw) {
	if ($('#email').val() != "") {
		if (($('#password').val() == $('#check_password').val()) && ($('#password').val() != "")) {
			check_mandatory_fields('subscription', message_not_full);
		} else {
			alert(message_psw);
		};		
	} else {
		alert_message = message_email;
		alert(alert_message);
	};
}
