/********************************************************
*  LOADING EVENTS
********************************************************/
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


/********************************************************
*  FONCTION POPUP POUR LA NEWSLETTER
********************************************************/

function PopupCentrerNl(page,nom,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,nom,'top='+top+',left='+left+',width='+largeur+',height='+hauteur+','+options);
}

function go(){
	PopupCentrerNl('','popup',500,300,'menubar=no,scrollbars=no,statusbar=no');
	document.forms['f_newsletter'].submit();
}


/********************************************************
*  EASY GET ELEMENT BY ID
********************************************************/

function $(obj) {
	var to_get = document.getElementById(obj);
	if( to_get )
		return to_get;
}


/********************************************************
*  EXTERNAL LINK
********************************************************/
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 


/********************************************************
*  FONCTION PERMETTANT DE VERIFIER LES CHAMP D'UN FORMULAIRE
********************************************************/

function verifForm(formobj, fieldRequired, fieldDescription){
	
	// intro des messages de la boite de dialogue
	var alertMsg = "Vous devez completer :\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == "" || obj.options[obj.selectedIndex].value == "rien"){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;

			case "checkbox":
					alert(obj.checked);
					if (obj.checked == false){
						alertMsg += " - " + fieldDescription[i] + "\n";
					}
					break;

			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
					obj.className = "error";
				}else{
					obj.className =	"";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		var field = formobj.elements["info_email"];
		if(field.value != null && field.value != ""){
			if(!checkmail(field.value)){
					alert("votre email est incorrect");
					field.className 	=	"error";
					return false;
			}else{
				field.className 		= 	"";
				return true;
			}
		}else{
			return true;
		}
	}else{
		alert(alertMsg);
		return false;
	}
}


function checkmail(email) {
         var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
         return (reg.exec(email)!=null)
}



 
/********************************************************
*  FORM FOCUS
********************************************************/
function focusForm()
{
	if($('info_nom'))$('info_nom').focus();
}
 
 
 /********************************************************





/********************************************************
*  FLASH JS CONNEXION
********************************************************/
   
function affPoint(type,id,zone) {
	var type = type;
	var id = id;
	var zone = zone
	thisMovie("carte").updateCarte(type,id,zone);
}
function affPoint2(type) {
	var type = type;
	var id = "none";
	thisMovie("carte").updateCarte2(type,id);
}
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}


/********************************************************
*  NAVHOVER
********************************************************/

navHover = function() {
	var lis = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<lis.length; i++) {
		lis[i].onmouseover=function() {
			this.className+=" iehover";
			//document.getElementById('main').style.display="none";
		}
		lis[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			//document.getElementById('main').style.display="block";
		}
	}
}
/********************************************************
*  PNG FILE
********************************************************/
function correctPNG() 
   {
   for(var i=0; i<document.images.length; i++)
      {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='image');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
      }
   } 

addLoadEvent(externalLinks);
//addLoadEvent(initLightbox);
if( navigator.userAgent.indexOf('MSIE') > 0)addLoadEvent(navHover);
if( navigator.userAgent.indexOf('MSIE') > 0 )addLoadEvent(correctPNG);


