/**************************/
/*       rollover         */
/**************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**************************/
/*         layers         */
/**************************/
// show/hide a layer
function makeDivVisible(divName, visble) {
	var popupDivStyle = getStyleOfObj(divName);
	if (popupDivStyle) {
		if (document.layers) {
			popupDivStyle.visibility = (visble ? "show" : "hide");
		}
		else {
			popupDivStyle.visibility = (visble ? "visible" : "hidden");
		}
	}
}


// show/hide a layer
function makeDivVisibleUsingDisplay(divName, visble) {
	var popupDivStyle = getStyleOfObj(divName);
	if (popupDivStyle) {
		popupDivStyle.display = (visble ? "block" : "none");
    }
}

// changes the content of a layer
function writeLayer(layerID, txt){
	if (document.getElementById) {
		document.getElementById(layerID).innerHTML = txt;
	}
	else if (document.all) {
		document.all[layerID].innerHTML = txt;
	}
	else if (document.layers) { // Nestcape 4 only (but buggy)
		with (document.layers[layerID].document) {
			open();
			write(txt);
			close();
		}
	}
}

// returns the content of a layer (does not work in netscape 4)
function readLayer(layerID) {
	if (document.getElementById) {
		return document.getElementById(layerID).innerHTML;
	}
	else if (document.all) {
		return document.all[layerID].innerHTML;
	}
	// Netscape 4 only
	//else if (document.layers) {
	//	return document.layers[layerID].document;
	//}
}

// changes left and top values of a div that would be placed in absolute coordinates
function moveDivTo(divName, x, y) {
	var popupDivStyle = getStyleOfObj(divName);
	if (popupDivStyle) {
		popupDivStyle.left = x + 'px';
		popupDivStyle.top = y + 'px';
	}
}

// gets the style object of the specified layer
function getStyleOfObj(name) {
  if (document.getElementById) {
    return document.getElementById(name).style;
  }
  else if (document.all) {
    return document.all[name].style;
  }
  else if (document.layers) {
    return document.layers[name];
  }
  else return false;
}

/******************************************************************************/
/*                         window/popup managment                             */
/******************************************************************************/
// opens a popup centered on the screen
function openCenteredPopup(windowName, targetURL, w, h) {
	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;
	return openPopup(windowName, targetURL, x, y, w, h);
}
// opens a popup window resizable with no bar at all and returns it
function openPopup(windowName, targetURL, x, y, w, h) {
	return openPopup(windowName, targetURL, x, y, w, h, 'no', 'no', 'no', 'no', 'no', 'no', 'yes');
}
// opens a popup centered on the screen
function openCenteredPopup(windowName, targetURL, w, h, toolbar, location,
                           directories, status, menubar, scrollbars, resizable) {
	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;
	return openPopup(windowName, targetURL, x, y, w, h, toolbar, location,
	                 directories, status, menubar, scrollbars, resizable);
}
// opens a popup window and returns it
function openPopup(windowName, targetURL, x, y, w, h, toolbar, location,
                   directories, status, menubar, scrollbars, resizable) {
	var properties = '';
 	properties = 'toolbar=' + toolbar + ',location=' + location + 
 	             ',directories=' + directories + ',status=' + status + 
 	             ',menubar=' + menubar + ',scrollbars=' + scrollbars + 
 	             ',resizable=' + resizable + 
 	             ',width=' + w + ',height=' + h +
				 ',left=' + x  + ',top=' + y + '';
	try {
		var winD = window.open(targetURL, windowName, properties);
		if (isWindowOpen(winD) && !winD.opener == window.self) {
			winD.opener = window.self;
		}
		return winD;
	}
	catch(ex) {} // do nothing
	return null;
}
function isWindowOpen(winD) {
	return !(!winD || (winD && (winD.closed)));
}
// sets the focus on the specified window
function focusOnWindow(windowObject) {
	if (windowObject) {
		if (windowObject.focus) {
			windowObject.focus();
		}
	}
}

// Gets a pointer on the popup with the specified name and a certain page.
// The pointer will be returned if a window exists with the specified name and
// if the page opened in it defines a JavaScript method with the specified name,
// otherwise null is returned.
// If close is true, this method will always closes the window with the
// specified name if it exists but does display the requested page.
// NOTICE: setting close to true seems to crash Internet Explorer systematically
//         when the window that called catchPopupBack(...) is closed if the
//         Yahoo! Toolbar is installed and active at the time the window is closed
function catchPopupBack(windowName, methodName, close) {
	var windowObject = openPopup(windowName, '', 5000, 5000, 1, 1);
	if (windowObject) {
		try {
			eval('windowObject.' + methodName + '()');
		}
		catch (ex) {
			//alert('catchPopupBack(windowName, methodName) exception:' + ex);
			if (close) {
				windowObject.close();
			}
			return null;
		}
		return windowObject;
	}
}

// set the window size to fit a speficied portView size
// this window can be optionnaly centered in screen
// winD the window to resize
// w width of the portView
// h height of the portView
// center true to center the window on screen
function setWindowSizeForPortview(winD, w, h, center) {
	if (!winD) {
		return;
	}
	// calculates the margins of the window around the portView by setting the
	// window to a known size and mesuring the size of the portView
	// this will work only if the size of body is the size of the portView, this
	// can be achieved by setting width and height of html and body tags to 100% with css
	// and having a content that will never make the body bigger than the portview
	// (no or small content works great)
	var marginW = 0;
	var marginH = 0;
	if (winD.document.all && winD.document.body) {
	  winD.resizeTo(w, h);
	  marginW = w - winD.document.body.offsetWidth;
	  marginH = h - winD.document.body.offsetHeight;
	}
	else if (winD.outerHeight && winD.outerWidth){
	  winD.outerHeight = h;
	  winD.outerWidth = w;
	  marginW = w - winD.innerWidth;
	  marginH = h - winD.innerHeight;
	}

	w = w + marginW;
	h = h + marginH;
	if (center) {
		winD.moveTo((screen.availWidth - w) / 2, (screen.availHeight - h) / 2);
	}
	if (document.all) {
	  winD.resizeTo(w, h);
	}
	else if (winD.outerHeight && winD.outerWidth && (winD.outerHeight < h || winD.outerWidth < w)){
	  winD.outerHeight = h;
	  winD.outerWidth = w;
	}
}
/******************************************************************************/
/*           Cookie methods, from TechPatterns.com                            */
/******************************************************************************/
function setCookie(name, value, expires, path, domain, secure) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	
	document.cookie = name + "=" + escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

// this deletes the cookie when called
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/******************************************************************************/
/*                            Flash movies                                    */
/******************************************************************************/
// return the html code to embed a flash movie into an HTML document
// script is allowed from the same domain and align attribute is set to 'middle'
// @param scheme ['http'/'https']
// @param swf path to the swf file
// @param idName name and id of the flash movie
// @param w width
// @param h height
// @param bgColor background color of the flash movie, ex.: #cccccc
// @param quality ['low'/'high']
// @param menu [true/false]
// @param wmode ['window'(default)/'opaque'/'transparent'], optionnal
function getFlashEmbeddingString(scheme, swf, flashVars, idName, w, h,
                                 bgColor, quality, menu, wmode) {
  if (!wmode) {
  	wmode = 'window';
  }
	var str = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
	  ' codebase="' + scheme + '://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"' +
	  ' id="' + idName + '" width="' + w + '" height="' + h + '" align="middle">' +
	  '<param name="allowScriptAccess" value="sameDomain" />' +
	  '<param name="movie" value="' + swf + '" />' +
	  '<param name="menu" value="' + menu + '" />' +
	  '<param name="quality" value="' + quality + '" />' +
	  '<param name="bgcolor" value="' + bgColor + '" />' +
	  '<param name="wmode" value="' + wmode + '">' +
    '<param name="seamlesstabbing" value="false">' +
	  '<param name="flashvars" value="' + flashVars + '">' +
	  '<embed' +
	  ' src="' + swf + '"' +
	  ' menu="' + menu + '"' +
	  ' quality="' + quality + '"' +
	  ' bgcolor="' + bgColor + '"' +
	  ' wmode="' + wmode + '"' +
    ' seamlesstabbing="false"' +
	  ' flashvars="' + flashVars + '"' +
	  ' width="' + w + '"' +
	  ' height="' + h + '"' +
	  ' id="' + idName + '"' +
	  ' name="' + idName + '"' +
	  ' align="middle"' +
	  ' swLiveConnect="true"' +
	  ' allowScriptAccess="sameDomain"' +
	  ' type="application/x-shockwave-flash"' +
	  ' pluginspage="' + scheme + '://www.macromedia.com/go/getflashplayer" />' +
	  '</object>';
	return str;
}

// retrieves the object for the flash movie with the specified name/id in the
// current window, returns null if the movie can no be found
// the targeted flash movie must have the same name and id
function getFlashMovieObject(swfName) {
  if (window.document[swfName]) {
      return window.document[swfName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[swfName])
      return document.embeds[swfName]; 
  }
  else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
    return document.getElementById(swfName);
  }
  return null;
}

// sets the variable with the specified varName to the specified varValue in
// flash movie in the current window with the specified name/id.
function writeToFlash(swfName, varName, varValue) {
	var swfObject = getFlashMovieObject(swfName);
	if (swfObject) {
		swfObject.SetVariable(varName, varValue);
	}
}

/******************************************************************************/
/*                               Frames                                       */
/******************************************************************************/
// returns true if the window calling this method is inside a frameset
function isFramed() {
	return (top != self);
}

/******************************************************************************/
/*                               Utility                                      */
/******************************************************************************/
// this method return true if a method with the specified name is defined
function functionExists(functionName) {
	try {
		eval(functionName);
		return true;
	}
	catch (ex) {
		//alert('functionExists(' + functionName + ') exception caught:' + ex);
		return false;
	}
}

// retrieves the ViewPort width and height
// returns an object with properties width and height, or null if the
// ViewPort size can not be determined
// based on code of www.quirksmode.org
function getViewPortWidthAndHeight(winD) {
	var x = null;
	var y = null;
	if (self.innerHeight) { // all except Explorer
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) {	// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) { // other Explorers
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	if (x != null) {
		this.width = x;
		this.height = y;
		return this;
	}
	else {
		return null;
	}
}

// retrieves the scroll position
// returns an object with properties x and y, or null if the scroll position can
// not be retrieved
// based on code of www.quirksmode.org
function getScrollPosition() {
	var varX = null;
	var varY = null;
	if (self.pageYOffset) { // all except Explorer
		varX = self.pageXOffset;
		varY = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
		varX = document.documentElement.scrollLeft;
		varY = document.documentElement.scrollTop;
	}
	else if (document.body) { // all other Explorers
		varX = document.body.scrollLeft;
		varY = document.body.scrollTop;
	}
	if (varX != null) {
		this.x = varX;
		this.y = varY;
		return this;
	}
	else {
		alert('varX not defnined');
		return null;
	}
}

function checkEmail(value) {
    var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/;
    return (value.search(reg) != -1);
}

function checkFrenchCP(value) {
    var reg = /^([A-Z]+\-)?[\d]{5}$/;
    return (value.search(reg) != -1);
}

function checkFrenchPhone(value) {
    var reg = /^(\(\d+\))?([\s\.\-]?\d{2,})+$/;
    return (value.search(reg) != -1);
}


function validatePwd(pw1,pw2) {
var invalid = " "; // Invalid character is a space
var numbers = "0123456789";
var minLength = 6; // Minimum length
var minLetters = 2;
var minNumbers = 2;
// check for a value in both fields.
if (pw1 == '' && pw2 == '') {
	alert('Veuillez saisir votre mot de passe');
	return false;
}
if (pw1 == '' || pw2 == '') {
	alert('Veuillez saisir votre mot de passe 2 fois');
	return false;
}
// check for minimum length
if (pw1.length < minLength) {
    alert('votre mot de passe doit au moins faire '+minLength+' caract?res');
    return false;
}

if (pw1 != pw2) {
    alert ("les 2 mots de passe que vous avez saisi ne sont pas identiques. Veuillez les resaisir.");
    return false;
}

// check for spaces
if (pw1.indexOf(invalid) > -1) {
    alert("votre mot de passe ne doit pas contenir d'espace");
    return false;
}

//check for complexity
var lettersCount = 0;
var numbersCount = 0 ;

for(var i = 0;i<pw1.length;i++){
 var c  = pw1.charAt(i);
 if(numbers.indexOf(c) != -1){
        numbersCount++;
        continue;
 }
 lettersCount++;
 }

if(numbersCount<minNumbers){
    alert('votre mot de passe doit contenir au moins ' + minNumbers + ' chiffres');
    return false;
}
if(lettersCount<minLetters){
    alert('votre mot de passe doit contenir au moins ' + minLetters + ' lettres');
    return false;
}


return true;
}