// JavaScript Document

function weMail(x){
	location.href="mailto:"+ x + "@" + "safeairfitness.com";
	}
	
var glogalTM;

function init_js(){
	
	rollOvers();

	
	// fonctions pour IE seulement ...
	if(window.attachEvent){
		startList();
		overBtn();
		highLights();
		ieupdate();
	}
	if (self.parent.frames.length != 0) {
		self.parent.location='/accueil';
		}

}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


	
function rollOvers(){
	if (!document.getElementById) return
	
	var imgOriginSrc;
	var MouseOverHappened;
	var oldtop;
	var imgTemp = new Array();
	var imgarr = document.getElementsByTagName('img');
	
	for (var i = 0; i < imgarr.length; i++) {
		//Attribut hsrc pour Rollovers
		if (imgarr[i].getAttribute('hsrc')) {
			imgTemp[i] = new Image();
			imgTemp[i].src = imgarr[i].getAttribute('hsrc');
			imgarr[i].onmouseover = function() {
				imgOriginSrc = this.getAttribute('src');			
				this.setAttribute('src',this.getAttribute('hsrc'));
				MouseOverHappened=true;
			}
			imgarr[i].onmouseout = function() {
				if(MouseOverHappened)
					this.setAttribute('src',imgOriginSrc);
			}
		}
	
		//Attribut csrc pour action de click comme boutons
		if (imgarr[i].getAttribute('csrc')) {
			imgTemp[i] = new Image();
			imgTemp[i].src = imgarr[i].getAttribute('csrc');
			imgarr[i].onmousedown = function() {
				imgOriginSrc = this.getAttribute('src');			
				this.setAttribute('src',this.getAttribute('csrc'));
				MouseOverHappened=true;
			}
			imgarr[i].onmouseup = function() {
				if(MouseOverHappened)
					this.setAttribute('src',imgOriginSrc);
			}
		}
	}
}

function ieupdate(){
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++) {
		objects[i].outerHTML = objects[i].outerHTML;
	}
}

function startList(){
	if(document.getElementById("sm")){
		var sfEls = document.getElementById("sm").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

function checkform(theform) {
	var tags = new Array("input","textarea");
	for (var k = 0; k < tags.length; ) {
		var ar = theform.getElementsByTagName(tags[k++]);
		var cc = null;
		for (var i = 0; i < ar.length;) {
			cc = ar[i++];
			var nfos;
			if (cc.getAttribute('obg')) {
				nfos = cc.getAttribute('obg');
				if (nfos!=0) {
					if (cc.value=="") {
						alert(cc.getAttribute("err"));
						cc.focus();
						return false;
					}
					else {
						var isValid;
						var oComments = '';
						switch(cc.getAttribute("special")) {
							case null : 
								isValid = true;
								break;
							case "email" : 	
								isValid = validMail(cc.value);
								oComments = "\nEx.: nom@site.com";
								break;
							case "date" :  	
								isValid = validDate(cc.value);
								oComments = "\nEx.: 1982-03-25";
								break;
							case "nospecial" :  
								isValid = validSpecial(cc.value);
								oComments = "\nCaract&egrave;res autoris&eacute;s : <strong>a-z</strong>, <strong>A-Z</strong>, <strong>0-9</strong>";
								break;
							case "numeric" :  	
								isValid = validNumeric(cc.value);
								oComments = "\nEx.: 0-9";
								break;
							case "money" : 
								isValid = validCurrency(cc.value);
								oComments = "\nEx.: 159 ou 1979.23";
								break;
						}
						if(!isValid){
							alert(cc.getAttribute("err")+oComments);
							cc.focus();
							return false;
						}
					}
				}
			}
		}
	}
	return true;
} 

function validMail(email) {
	var result = false
	var theStr = new String(email)
	var index = theStr.indexOf("@");
	if (index > 0) {
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1)) result = true;
	}
	return result;
}

function validDate(dateaaaammjj) {
	var dt=dateaaaammjj.split("-"),date=new Date(dt[0],dt[1]-1,dt[2]);
	return date.getDate()==dt[2]&&date.getMonth()+1==dt[1]&&date.getFullYear()==dt[0]?date:false;
}

function validSpecial(fStr) {
	myReg = new RegExp("[A-Za-z0-9]+");
	if(myReg.exec(fStr)!=fStr) return false;
	return true;
}

function validNumeric(fStr) {
	myReg = new RegExp("[0-9]+");
	if(myReg.exec(fStr)!=fStr) return false;
	return true;
}

function validCurrency(fStr) {
	return RegExp(/^\$?\d+(\.\d{2})?$/).test(String(fStr).replace(/^\s+|\s+$/g, ""));
}

	
var displayed="0";

function showHide(x){
	if (displayed != "0") document.getElementById(displayed).style.display = "none";
	if (displayed != x) {
		document.getElementById('safe1').style.display="none";
			document.getElementById(x).style.display="block";
			displayed = x;
	} else {
		document.getElementById(x).style.display="none";
		displayed = "0";
	}
}
