// JavaScript Document

function check_length(elementStr, maxLen){
	var element = document.getElementById(elementStr);
	if (element.value.length >= maxLen) {
	// Reached the Maximum length so trim the textarea
	element.value = element.value.substring(0, maxLen);
	}
}

function validateEmail(elementValue){
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailPattern.test(elementValue); 
} 

function validateOnSubmit(form,lang) {
    var elem;
    var errs=0;
    // execute all element validations in reverse order, so focus gets
    if (!validateEmail (form.email.value)) errs += 1; 

    if (errs>0 && lang=='en') alert('Email address is invalid.');
	if (errs>0 && lang=='fr') alert('Le courriel est invalide.');

    return (errs==0);
  };
  

function openJukebox(href){
	jukebox = window.open('','jukebox','width=850,height=550,scrollbars=no,top=0,left=0,status=no,toolbar=no,resizable=yes,location=no,menubar=no');
	
	var myMatch = href.search("playlist=");
	
	if(myMatch!=-1 || jukebox.location=="about:blank" ){
		jukebox.location.href = href;
	}
	
	jukebox.focus();
	return false;
}

function openMediaWindow(href) {
// set the default sizes if none were provided, usually for audio
	mediaWidth = 240;
	mediaHeight = 180;
	
	var popWidth = 350, popHeight = mediaHeight + 40; 
	// if media is wider than the default 300 then expand the window 
	if (mediaWidth > 300) {
		popWidth = mediaWidth + 50;} 

	//setup the rest of the window varibles	
	var features = 'fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no', winAlign = 'center', ignorelink = 'ignorelink' ;
	//setup the popup window centering 
  var leftPos=0,topPos=0, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + (popHeight + 110);
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
	// detect whether the media windows was evoked form the en or fr site
		popupWindow[wp] = window.open(href,'winMedia',features);
}


function clearDefault(obj){
	if(obj.value=="Email" || obj.value=="Courriel" || obj.value=="Password" || obj.value=="Mot de passe"){
		obj.value="";
	}
}

function toggleMovements(movements){
	var element = document.getElementById(movements);
	
	if(element.className=='movements-expanded'){
		element.className = "movements-collapsed";
	}else{
		element.className = "movements-expanded";
	}
	
	return false;
}

