

/* --------------------------------------------------------------------- */
/*                                                                       */
/*                            WWW.ASSEILS.COM                            */
/*      L'association des propriétaires et copropriétaires de Seils      */
/*                                                                       */
/* --------------------------------------------------------------------- */



/* -------------------------- Scripts généraux ------------------------- */



// [ Swap et préchargement d'image ]

function imgSwap(F_id,F_src) {
	
	document.getElementById(F_id).src = F_src;
	
}

function imgPreload() {
	
	var d = document;
	if (document.images) {
		if (!document.arrPreloaded) document.arrPreloaded = new Array();
		var i;
		var j = document.arrPreloaded.length;
		var args = imgPreload.arguments;
		for (i = 0 ; i < args.length ; i++) {
			if (args[i].indexOf("#") != 0) {
				document.arrPreloaded[j] = new Image;
				document.arrPreloaded[j++].src = args[i];
			}
		}
	}
	
}

// [ Ouverture d'une popup ]

function openWindow(F_url,F_name,F_width,F_height,F_options) {
	
	var myURL     = (F_url == null                     ) ? "" : F_url     ;
	var myNAME    = (F_name == null                    ) ? "" : F_name    ;
	var myWIDTH   = (F_width == null  || F_width == "" ) ? 50 : F_width   ;
	var myHEIGHT  = (F_height == null || F_height == "") ? 50 : F_height  ;
	var myOPTIONS = (F_options == null                 ) ? "" : F_options ;
	
	var posLeft = ( screen.width - myWIDTH ) / 2;
	var posTop = ( screen.height - myHEIGHT ) / 2;
	
	var realOptions = "left=" + posLeft + ",top=" + posTop + ",width=" + myWIDTH + ",height=" + myHEIGHT + ( (myOPTIONS != "") ? "," + myOPTIONS : "" );
	
	var windowOpenned = window.open(myURL,myNAME,realOptions);
	
}

function resizeWindow(F_width,F_height) {
	
	var pos_left = ( screen.width - F_width ) / 2;
	var pos_top = ( screen.height - F_height ) / 2;
	window.moveTo(pos_left,pos_top);
	window.resizeTo(F_width,F_height);
	
}

function popflash(fSwf,fWidth,fHeight,fColor,fVersion) {
	
	openWindow("./swf.php?swf=" + fSwf + "&width=" + fWidth + "&height=" + fHeight + "&color=" + fColor + "&version=" + fVersion,"popflash");
	
}

// [ Chiffrement et emails ]

function base64_decode(input) {
   
	var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	
	var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
	
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
	
}

function CryptMail(fUser,fDomain,fId) {
	
	var FinalMail = base64_decode(fUser) + "@" + base64_decode(fDomain);
	document.getElementById(fId).innerHTML = FinalMail;
	document.getElementById(fId).href = "mailto:" + FinalMail;
	
}

function strPad(fStr,fNbe,fBef,fAft) {
	
	fStr = fStr ? fStr : "" ;
	fNbe = fNbe ? fNbe : 0 ;
	fBef = fBef ? fBef : "" ;
	fAft = fAft ? fAft : "" ;
	
	while (fStr.length < fNbe) fStr = fBef + fStr + fAft;
	
	return(fStr);
	
}

function checkEmail(fStr) {
	
	var cm =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
	if (cm.test(fStr)) {
		return(true);
	} else {
		return(false);
	}
	
}

// [ Gestion du focus dans les champs de texte ]

function setFocus(F_obj,F_txt,F_class) {
	
	if (F_obj) {
		if (F_obj.value == F_txt) {
			if (F_txt != null) F_obj.value = "";
			if (F_class != null) F_obj.className = F_class;
		}
	}
	
}

function setBlur(F_obj,F_txt,F_class) {
	
	if (F_obj) {
		if (F_obj.value == "") {
			if (F_txt != null) F_obj.value = F_txt;
			if (F_class != null) F_obj.className = F_class;
		}
	}
	
}

// [ Vote ]

function VoteImage(F_id) {
	
	
	
}

// [ Affichage du sous menu correspondant ]

function showMenu(F_num) {
	
	document.getElementById("menu_Rub0").className = "hidden";
	document.getElementById("menu_Rub1").className = "hidden";
	document.getElementById("menu_Rub2").className = "hidden";
	document.getElementById("menu_Rub3").className = "hidden";
	
	document.getElementById("menu_Img0").src = "images/menu_01_off.gif";
	document.getElementById("menu_Img1").src = "images/menu_02_off.gif";
	document.getElementById("menu_Img2").src = "images/menu_03_off.gif";
	document.getElementById("menu_Img3").src = "images/menu_04_off.gif";
	
	document.getElementById("menu_Img" + F_num).src = "images/menu_0" + (F_num + 1) + "_on.gif";
	
	document.getElementById("menu_Rub" + F_num).className = (F_num == 0) ? "nosub" : "sub" ;
	
	CURRENT_rub = F_num;
	
}

// [ Déplacement des bateaux de pied de page en fonction de la taille du contenu ]

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}


function moveFooter() {
	
	var footerElement = document.getElementById("footer_boats");
	var swfFooterElement = document.getElementById("swf_boats");
	var mainElement = document.getElementById("main");
	
	var myWindowHeight = getWindowHeight();
	var mainElementHeight = mainElement.clientHeight + 67;
	
	if (myWindowHeight > mainElementHeight + 20) {
		footerElement.style.height = "auto";
		footerElement.style.bottom = "0px";
		swfFooterElement.style.marginBottom = "0px";
	} else {
		footerElement.style.height = mainElementHeight + "px";
		footerElement.style.bottom = "auto";
		swfFooterElement.style.marginBottom = "-30px";
	}
	
}

window.onresize = function() { moveFooter(); }
