function switchLang(langID) {
	currentURL = window.location.href;
	currentURL = currentURL.replace("?option=sendemail","");
	if (langID == 4105) { 
		location.href=currentURL.replace("_f.", "_e.");
	} else {
		location.href=currentURL.replace("_e.", "_f.");
	}
}

// rollOvers pour les images
// Application : class="roll"
window.addEvent('domready', function() {
	//preload images
	var aPreLoad = new Array();
	var aPreLoadi = 0;
	
	//do rollover
	$$('img.roll', 'input.roll').each(function(el){
		//let's preload
		aPreLoad[aPreLoadi] = new Image();
		aPreLoad[aPreLoadi].src = el.src.replace(el.src.replace('_off_e.', '_on_e.'));
		aPreLoadi++;
	
		el.addEvent('mouseover',function(){
			this.setAttribute('src',this.src.replace('_off_e.', '_on_e.'));
		});
	
		el.addEvent('mouseout',function(){
			this.setAttribute('src',this.src.replace('_on_e.','_off_e.'));
		});
	});

});

// rollOvers for Text
// Application : class="rollText"
window.addEvent('domready',function() {
	$$('.rollText').each(function(el){
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'300' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'color':'#ff8c00' }) },
			'mouseleave' : function() { morph.start({ 'color': original }) }
		});
	});
});

// On IMG Error
window.addEvent('domready',function() {
	$$('img').addEvent('error',function() {
		var notification = new Request({
			url: 'ajax-image-error.php',
			method: 'post',
			data: {
				'image': this.get('src'),
				'page': window.location.href
			}
		}).send();
	});
});

var currentMenu = 3;
window.addEvent('domready', function() {
	$$('#menu a')[currentMenu].getChildren('img').removeEvents('mouseover');
	$$('#menu a')[currentMenu].getChildren('img').removeEvents('mouseout');
	$$('#menu a')[currentMenu].getChildren('img').set('src', $$('#menu a')[currentMenu].getChildren('img').get('src').toString().replace('_off_', '_on_'));
});


function manageMenu(passedID) {
	if (currentMenu != passedID) {
		$$('#menu a')[passedID].getChildren('img').removeEvents('mouseover');
		$$('#menu a')[passedID].getChildren('img').removeEvents('mouseout');
		$$('#menu a')[passedID].getChildren('img').set('src', $$('#menu a')[passedID].getChildren('img').get('src').toString().replace('_off_', '_on_'));
		
		$$('#menu a')[currentMenu].getChildren('img').set('src', $$('#menu a')[currentMenu].getChildren('img').get('src').toString().replace('_on_', '_off_'))
		$$('#menu a')[currentMenu].getChildren('img').addEvent('mouseover',function(){
			this.set('src',this.src.replace('_off_', '_on_'));
		});
	
		$$('#menu a')[currentMenu].getChildren('img').addEvent('mouseout',function(){
			this.set('src',this.src.replace('_on_','_off_'));
		});
	}
	currentMenu = passedID;
}

// Content slider
window.addEvent('domready', function() {

	//variables for making things more simple below
	var itemsHolder = $('content');
	var myItems = $$('.item');
	var numNavHolder = $('menu').getElement('ul');

	//var thePlayBtn = $('play_btn');
	//var thePrevBtn = $('prev_btn');
	//var theNextBtn = $('next_btn');
	
	
	//create an instance of the slider, and start it up
	var mySlider = new SL_Slider({
		slideTimer: 6000,
		isPaused: true,
		container: itemsHolder,
		items: myItems,
		itemNum: 3,
		numNavActive: true,
		numNavHolder: numNavHolder
	});
	mySlider.start(); 
});

function validateContact() {
	if ($('firstname').value == "" || $('firstname').value == "First name") {
		alert('The field "First name" is required.');
		return false;
	}
	if ($('email').value == "" || $('email').value == "Email") {
		alert('The field "Email" is required.');
		return false
	}
	
	if (emailcheck($('email').value)==false) {
		alert('The Email address provided is invalid.');
		return false;
	}

	if ($('comment').value == "" || $('comment').value == "Question") {
		alert('The field "Question" is required.');
		return false;
	}
	sendQuestion();
}

function sendQuestion() {
	var myHTMLRequest = new Request.HTML({
		url:'_includes/contact.php',
		onSuccess: function(html) {
			$('contact_form_response').removeClass('form');
			//Clear the text currently inside the results div.
			$('contact_form_response').set('html', '');
			$('contact_form_response').addClass('form_sent');
			//Inject the new DOM elements into the results div.
			$('contact_form_response').adopt(html);
		},
		onFailure: function() {
			alert('An error occured, please try again.');
		}
	}).post($('contact_form'));
}

function emailcheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		 return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		 return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
			return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
			return false
	 }
	
	 if (str.indexOf(" ")!=-1){
			return false
	 }

	 return true					
}
