/* ================================================================ 
This copyright notice must be untouched at all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/gallery/simply_more.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */

window.onload = function() {
f1();
f2();
f3();
EmailUnobsfuscate();
}

/*===========identity gallery=================================================*/

function f1() {
	var e, i = 0;
	while (e = document.getElementById('identity_gallery').getElementsByTagName ('B') [i++]) {
		if (e.className == 'switch') {
		e.onclick = function () {
				var getEls = document.getElementById('identity_gallery').getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) {
				getEls[z].className=getEls[z].className.replace('show', 'hide');
				w=getEls[z].previousSibling;
				while (w.nodeType!=1) {
					w=w.previousSibling;
					}
				w.className=w.className.replace('switch over', 'switch');
				w.className=w.className.replace('switch off', 'switch over');
				}
			this.className = this.className == 'switch' ? 'switch off' : 'switch';
			x=this.nextSibling;
			while (x.nodeType!=1) {
				x=x.nextSibling;
				}
			x.className = this.className == 'switch off' ? 'show' : 'hide';
			}
		}
	}
}


/*===========print gallery=================================================*/

function f2() {
	var e, i = 0;
	while (e = document.getElementById('print_gallery').getElementsByTagName ('B') [i++]) {
		if (e.className == 'switch') {
		e.onclick = function () {
				var getEls = document.getElementById('print_gallery').getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) {
				getEls[z].className=getEls[z].className.replace('show', 'hide');
				w=getEls[z].previousSibling;
				while (w.nodeType!=1) {
					w=w.previousSibling;
					}
				w.className=w.className.replace('switch over', 'switch');
				w.className=w.className.replace('switch off', 'switch over');
				}
			this.className = this.className == 'switch' ? 'switch off' : 'switch';
			x=this.nextSibling;
			while (x.nodeType!=1) {
				x=x.nextSibling;
				}
			x.className = this.className == 'switch off' ? 'show' : 'hide';
			}
		}
	}
}


/*===========web gallery=================================================*/

function f3() {
	var e, i = 0;
	while (e = document.getElementById('web_gallery').getElementsByTagName ('B') [i++]) {
		if (e.className == 'switch') {
		e.onclick = function () {
				var getEls = document.getElementById('web_gallery').getElementsByTagName('DIV');
				for (var z=0; z<getEls.length; z++) {
				getEls[z].className=getEls[z].className.replace('show', 'hide');
				w=getEls[z].previousSibling;
				while (w.nodeType!=1) {
					w=w.previousSibling;
					}
				w.className=w.className.replace('switch over', 'switch');
				w.className=w.className.replace('switch off', 'switch over');
				}
			this.className = this.className == 'switch' ? 'switch off' : 'switch';
			x=this.nextSibling;
			while (x.nodeType!=1) {
				x=x.nextSibling;
				}
			x.className = this.className == 'switch off' ? 'show' : 'hide';
			}
		}
	}
}




/*===========E-mail=================================================*/


function EmailUnobsfuscate() {
	
	
	var link = document.getElementsByTagName && document.getElementsByTagName("a");
	var email, e;
	
	
	for (e = 0; link && e < link.length; e++) {
	
	
		if ((" "+link[e].className+" ").indexOf("linkm") >= 0) {
		
			
			email = link[e].firstChild.nodeValue.toLowerCase() || "";
			
		
			email = email.replace(/dot/ig, ".");
			email = email.replace(/\(at\)/ig, "@");
			email = email.replace(/\s/g, "");
			
	
			if (/^[^@]+@[a-z0-9]+([_\.\-]{0,1}[a-z0-9]+)*([\.]{1}[a-z0-9]+)+$/.test(email)) {
			
			
				link[e].href = "mailto:" + email;
				link[e].firstChild.nodeValue = email;
		
			}
		}
	}
}

/*=========== validation form=================================================*/

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' : merci de mettre une adresse mail.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' : merci de mettre un numéro de téléphone.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' est demandé.\n'; }
    } if (errors) alert('Oupppsss une petite erreur:\n'+errors);
    document.MM_returnValue = (errors == '');
} }




