// PNG transparent sous internet Explorer
function IE_CorrectAlpha_PNG(){ 
for(i=0; i<document.images.length; i++){ 
img    = document.images[i]; 
imgExt  = img.src.substring(img.src.length-3, img.src.length); 
imgExt  = imgExt.toUpperCase(); 
if (imgExt == "PNG"){ 
imgID    = (img.id) ? "id='" + img.id + "' " : ""; 
imgClass= (img.className) ? "class='" + img.className + "' " : ""; 
imgTitle= (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; 
imgStyle= "display:inline-block;" + img.style.cssText; 
if (img.align == "left") { imgStyle = "float:left;"  + imgStyle; } else if (img.align == "right"){ imgStyle = "float:right;" + imgStyle; } 
if (img.parentElement.href)   { imgStyle = "cursor:hand;" + imgStyle; }        
strNewHTML    = '<span '+imgID+imgClass+imgTitle+' style="width:'+img.width+'px; height:'+img.height+'px;'+imgStyle+';'+'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img.src+'\', sizingMethod=\'scale\');"></span>'; 
img.outerHTML = strNewHTML; 
i = i-1; 
}}} 
window.attachEvent("onload", IE_CorrectAlpha_PNG)

function chargePage(nompage) {
	top.location.href=nompage;
}

function chargeActivite(activite) {
	top.location.href="activites.php?activite="+activite;
}

function favoris() {
	if ( navigator.appName != 'Microsoft Internet Explorer' ){ 
		window.sidebar.addPanel("Planète Sciences","http://www.vacances-planete-sciences.org",""); 
	}
	else { 
		window.external.AddFavorite("http://www.vacances-planete-sciences.org","Planète Sciences"); 
	} 
}

function construction() {
	window.alert("site en construction");
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Masque de saisie pour les champs
function editMaskPre(obj, mask, evt) {
	var keyCode = evt.keyCode;
	if (keyCode == 0) {
		keyCode = evt.charCode;
	}
	if (obj.value.length == 0 && keyCode != 8 && keyCode != 0 && keyCode!= 9) {
		completeMask(obj, mask);
	}
}

function toregexp(txt) {
	txt = txt.replace(/([-\/\[\]()\*\+])/g, '\\$1');
	txt = txt.replace(/N/g, '\\d');
	txt = txt.replace(/\?/g, '.');
	txt = txt.replace(/A/g, '\\w');
	txt = txt.replace(/C/g, '[A-Za-z]');
	return txt;
}

function editMask(obj, mask, evt) {
	var tmVal = getFirstMatch(obj.value, mask);
	if (obj.value != tmVal) {
		obj.value = tmVal;
	}
	if(evt.keyCode != 8 && obj.value.length != 0) { // backspace and tab
		completeMask(obj, mask);
	}
}

function getFirstMatch(value, mask) {
	var size = value.length;
	if(size == 0) {
		return "";
	}
	var re = new RegExp('^' + toregexp(mask.substr(0, size)) + '$');
	if (!value.match(re)) { 
		return getFirstMatch(value.substr(0, size-1), mask);
	} else {
		return value;
	}
}


function completeMask(obj, mask) {
	var size = obj.value.length;
	var sw=true;
	var tmp = obj.value;
	while (sw) {
		if (mask.length<=size) {
			break;
		}
		switch (mask.charAt(size)) {
			case 'N':
			case 'A':
			case 'C':
			case '?':
				sw = false;
				break;
			default:
				tmp += mask.charAt(size);
		}
		size++;
	}
	if (obj.value != tmp) {
		obj.value = tmp;
		obj.lastMatched = obj.value;
	}
	return;
}

/* Popup impression d'inscription */
function printInscription() {
	titre="Inscription";
	w=open("popup-inscription.php","titre","width=700,height=550,toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0");
	w.document.close();
}
/* Popup impression adhésion */
function printAdhesion() {
	titre="Adhesion";
	w=open("popup-adhesion.php","titre","width=500,height=500,toolbar=yes,scrollbars=yes,resizable=yes,top=0,left=0");
	w.document.close();
}
