
var Loader = {
    update : function (elt, url){
        new Ajax.Updater(elt , url, {
            evalScripts: false,
            method: 'get',
            onSuccess: function(transport) {
                new Effect.Appear( elt , {
    			     duration: 0.2,
    			     queue: 'end'
                });
            }
       });
   }   
}


function modalbox_serialize( form_name , url_start , title )
{
    var elt = $(form_name).serialize(true);
    var url = url_start;
    alert(elt);
    Modalbox.show( url, {title: title, width: 400, height:300 });
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function highlight_form_error(element_to_focus_on){
	alert("The form is not thoroughly completed.\nPlease check the mandatory fields.");
	if (element_to_focus_on != '') {
		new Effect.ScrollTo($(element_to_focus_on), {
			duration: 0,
			afterFinish:function(){
				new Effect.Highlight($(element_to_focus_on));
			}
		});
		$(element_to_focus_on).focus();
	}
}

function dispMenuLang()
{
	new Effect.BlindUp( 'languageBox', { 
		duration: 0.2, 
		queue : 'end',
		afterFinish:function(){
			new Effect.BlindDown( 'lang_options', { 
				duration: 0.2, 
				queue : 'end' } 
			);
		} 
	} );
}

function scroll_to(container){
	new Effect.ScrollTo($(container), {
		duration: 0.5
	});
}

function hideMenuLang()
{
	new Effect.BlindUp( 'lang_options', { 
		duration: 0.2, 
		queue : 'end',
		afterFinish:function(){
			new Effect.BlindDown( 'languageBox', { 
				duration: 0.2, 
				queue : 'end' } 
			);
		} 
	} );
}

function fantasyAppear(element){
	new Effect.Appear( element, { 
		duration: 0.2, 
		queue : 'end',
		afterFinish:function(){
			
		} 
	} );
}
function fantasyDisappear(element){
	new Effect.Fade( element, { 
		duration: 0.2, 
		queue : 'end',
		afterFinish:function(){
			
		} 
	} );
}

function fantasyAppearToggle(element){
	if($(element).getStyle('display') == 'none'){
		fantasyAppear(element);
	}
	else{
		fantasyDisappear(element);
	}
}

function fantasyBlindDown(element){
	new Effect.BlindDown( element, { 
		duration: 0.5, 
		queue : 'end',
		afterFinish:function(){
			
		} 
	} );
}
function fantasyBlindUp(element){
	new Effect.BlindUp( element, { 
		duration: 0.5, 
		queue : 'end',
		afterFinish:function(){
			
		} 
	} );
}

function fantasyToggle(element){
	if($(element).getStyle('display') == 'none'){
		fantasyBlindDown(element);
	}
	else{
		fantasyBlindUp(element);
	}
}

function submitFeedback(lang){
	
	var elt = $('feedback_email').value.toLowerCase();
	var pattern = /^[a-z0-9_\-\.\+]+@[a-z0-9]+[a-z0-9_\-\.]*\.[a-z]{2,}$/;
	var c = elt.search(pattern) ;
	var c1 = (c != -1);
	var c2 = $('feedback_message').value.length >=10;
	if(c1 && c2) {
		// Ok
		//$('feedback_form').submit();
		//$('feedback_form').request();
		
		$('feedback_form').request({
			onLoaded: function(){
				$('feedback_table_form').hide();
				$('feedback_processing').show();
		  	},
		  	onComplete: function(){ 
		  		$('feedback_processing').hide();
			},
		  	onSuccess: function(transport) {
			    var notice = $('notice');
			    if (transport.responseText.match(/yes/))
			    	$('feedback_success').show();
			    else
			    	$('feedback_failure').show();
			}

		});
		
	}
	else{
		var message = '';
		if(lang == 'EN'){
			message = "Please check your form:\n";
			if(!c1) message = message + "Enter a valid email address\n";
			if(!c2) message = message + "Enter at least 10 characters in your message\n";
		}
		else{
			message = "Veuillez s'il vous plait:\n";
			if(!c1) message = message + "Entrer une adresse mail valide\n";
			if(!c2) message = message + "Entrer au moins 10 caractères dans votre message\n";
		}
		alert(message);
	}
}

function show_team(team_id){
	var url = base_url + 'team/overview/' + team_id + '/index.php';

	//Modalbox.show(url, {title: this.title, width: 500, height: 600}); 

	myLightWindow.activateWindow({
		href: url,
		title: "", 
		author: '', 
		caption: '', 
		width: '490px',
		height: '600px'
	});
}
	