var preloadFlag = false;
var movieName = "soundPlay";
var msgWindow = null;
var currentImageName = "";

function thisMovie(movieName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}

function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}

function clickSound(soundName) {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).TGotoLabel("_level0/"+soundName,"stopSound");
    thisMovie(movieName).TGotoLabel("_level0/"+soundName,"playSound");
  }
}

function tabOnEnter (field, evt, nextfield) {
	var keyCode = document.layers ? evt.which : document.all ? evt.keyCode : evt.keyCode;
	if ((keyCode != 13) && (keyCode != 9))
		return true;
	else {
		if (nextfield == "soumettre") {document.getElementById("checpassword").submit()} else {document.getElementById(nextfield).focus()};
		return false;
	}
}

function checkNewPassword () {
	message00 = "Your password has been changed.";
	message01 = "Please try again. The two password values do not match.";
	message02 = "Please try again. Your password must contain at least 5 characters.";
	message03 = "Please try again. Your password contains illegal characters (only letters and numbers are allowed).";
	
	var illegalChars = /[\W_]/;
	if (illegalChars.test(document.getElementById("pwd1").value)) {
		alert(message03);
	} else {
		if (document.getElementById("pwd1").value == document.getElementById("pwd2").value) {
			if (document.getElementById("pwd1").value.length < 5) {
				alert(message02);
			} else {
				alert(message00);
				document.getElementById('checpassword').submit();
			};
		} else {
			alert(message01);
		};
	};
};

function switchLanguage(newLang) {
	setCookie("myLanguage", newLang, 365);
	myURL = "http://" + window.location.hostname + "/" + newLang + window.location.pathname.substring(3,window.location.pathname.length);
	window.location.href=myURL;
}

function focusField () {
	if (document.getElementById("email")) {
		document.getElementById("email").value = document.getElementById("email").value;
		document.getElementById("email").focus();
	};
}

function frameImage(imgName, iLink, imgWidth, imgHeight, tM, rM, bM, lM, alignLCR, figCap) {
  var tWidth=imgWidth+6;
  if (iLink != "") {linkStart="<A href=\""+iLink+"\">"; linkEnd="</A>"} else {linkStart=""; linkEnd=""};
  document.writeln("<table style=\"margin: 0px; margin-right:"+rM+"px; margin-left:"+lM+"px; margin-top:"+tM+"px; margin-bottom:"+bM+"px;\" border=0 cellpadding=0 cellspacing=0 align=\""+alignLCR+"\" width=\""+tWidth+"\">");
  document.writeln("	<tr><td><div style=\"border: 1px solid #d0c8c0; padding: 0px;\"><div style=\"padding: 2px;\">"+linkStart+"<img src=\""+imgName+"\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" hspace=\"0\" vspace=\"0\" border=\"0\" alt=\"\">"+linkEnd+"</div></div></td></tr>");
  document.writeln("	<tr><td><p class=\"caption\">"+figCap+"</td></tr>");
  document.writeln("</table>");
};

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}
function changeLogo(imgSrc, overState) {
	if (document.images && (preloadFlag == true)) {
		if (overState == "On") {
			document.getElementById(imgSrc).src = eval(imgSrc+'B'+overState).src;
		} else {
			document.getElementById(imgSrc).src = eval(imgSrc+'B').src;
		}
	}
}

if (document.images) {
	spacerLoad = newImage("/images/spacer.gif");
}

function preloadImages() {
	logoacoaB = newImage("/images/logoacoa.gif");
	logoacoaBOn = newImage("/images/logoacoaOn.gif");
	logoairportB = newImage("/images/logoairport.gif");
	logoairportBOn = newImage("/images/logoairportOn.gif");
	logodieppeB = newImage("/images/logodieppe.gif");
	logodieppeBOn = newImage("/images/logodieppeOn.gif");
	logomonctonB = newImage("/images/logomoncton.gif");
	logomonctonBOn = newImage("/images/logomonctonOn.gif");
  	preloadFlag = true;
  	if (window.location.pathname.substring(1,3)) {
		setCookie("myLanguage", window.location.pathname.substring(1,3), 365);
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function dummyF() {
}

function goBackClear() {
  history.back();
}

wwwCookieName = "";

function getCookie(name){
  var cname = name + "=";
  var dc = document.cookie;
  if (dc.length > 0) {
    begin = dc.indexOf(cname);
    if (begin != -1) {
      begin += cname.length;
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
        return unescape(dc.substring(begin, end));
    }
  }
  return null;
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

