// Gestion dynamique de la boîte de connexion.
function updateFormField(id, title, password) {
	var field = document.getElementById(id);
	
	if (field.value == field.title) {
		field.value = '';
		field.style.color = '#000000';
	} else if (field.value == '') {
		field.style.color = '#888888';
		field.value = field.title;
	}
}

function openPopup(pageId) {
	switch (pageId) {
		case '3' :
			window.open('/autres-pages/mentions-legales/','popupcecim','scrollbars=1,resizable=1,width=800,height=400');
			return false;
		case '4' :
			window.open('/autres-pages/contact/','popupcecim','scrollbars=1,resizable=1,width=800,height=400');
			return false;
	}
	return true;
}

	
// http://www.dynamicsitesolutions.com/javascript/dynamically-changing-input-type/
// Note: It is known that the dss_addLoadEvent function crashes Netscape 
// versions 4.02 and older. I recommend you use a more comprehensive event 
// management script for production (aka "live") pages.
function dss_addLoadEvent(fn) {
  if(typeof(fn)!="function")return;
  var tempFunc=window.onload;
  window.onload=function() {
    if(typeof(tempFunc)=="function")tempFunc();
    fn();
  }
}

// Example 2 (JS part 1)
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
  if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
    !document.getElementById || !document.createElement) return;
  var newElm = document.createElement('input');
  newElm.type = iType;
  if(oldElm.name) newElm.name = oldElm.name;
  if(oldElm.id) newElm.id = oldElm.id;
  if(oldElm.className) newElm.className = oldElm.className;
  if(oldElm.size) newElm.size = oldElm.size;
  if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
  if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
  newElm.onfocus = function(){return function(){
    if(this.hasFocus) return;
    var newElm = changeInputType(this,'password',iValue,
      (this.value.toLowerCase()==iValue.toLowerCase())?true:false); newElm.style.color = '#000000';
    if(newElm) newElm.hasFocus=true;
  }}();
  newElm.onblur = function(){return function(){
    if(this.hasFocus)
    if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
      changeInputType(this,'text',iValue,false,true); newElm.style.color = '#888888';
    }
  }}();
 // hasFocus is to prevent a loop where onfocus is triggered over and over again
  newElm.hasFocus=false;
  oldElm.parentNode.replaceChild(newElm,oldElm);
  if(!blankValue) newElm.value = iValue;
  if(!noFocus || typeof(noFocus)=='undefined') {
    window.tempElm = newElm;
    setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
  }
  return newElm;
}

// Example 2 (JS part 2)
dss_addLoadEvent(function(){
  // Normally I use object detection, however, in this case since I need to 
  // detect Konqueror and Safari which don't have unique objects,
  // I will use the user agent string to detect them. Only use this type of 
  // detection as a last resort.
  // I'm doing this because example 2 crashes Konqueror and Safari and 
  // generates errors in IE5/Mac

  var ua = navigator.userAgent.toLowerCase();
  if(!((ua.indexOf('konqueror')!=-1) && (document.all || 
    (ua.indexOf('khtml/3.4')!=-1))) && !(((ua.indexOf('safari')!=-1) && 
    !window.print) || (document.defaultCharset && !window.print))) {

      // Set the third value to the text you want to appear in the field.
      if (document.getElementById('pass') != null)
      	changeInputType(document.forms[0].pass,'text','Mot de passe',false,true);
  }
});

	