// il faut utiliser les getElementById pour pouvoir se passer du nom du formulaire ! 

function chg_type(sexe){
	document.getElementById('brun').src="../layoutElems/types/"+sexe+"/brun.gif";
	document.getElementById('blond').src="../layoutElems/types/"+sexe+"/blond.gif";
	document.getElementById('roux').src="../layoutElems/types/"+sexe+"/roux.gif";
	document.getElementById('black').src="../layoutElems/types/"+sexe+"/black.gif";
	document.getElementById('chauve').src="../layoutElems/types/"+sexe+"/chauve.gif";
}

function envoi() {
	var modified=false;
	if (document.form2.selected_id.value==""){
		document.form2.action="?form=submitted";
	}else{
		modified=true;
		document.form2.action="?form=modified";
	}
	document.form2.submit();
}
function modif(id) {
	document.form2.action="?form=toModif";
	document.form2.selected_id.value=id;
	document.form2.submit();
}

function recMois(m,a){
	if (m>=2) {
		m--;
	}else{ 
		m=12 ;
		a--;
	}
	document.calendar.selectedMonth.value = m;
	document.calendar.selectedYear.value = a;
	document.calendar.submit();
}
function avMois(m,a){
	if (m<=11) {
		m++;
	}else{ 
		m=1 ;
		a++;
	}
	document.calendar.selectedMonth.value = m;
	document.calendar.selectedYear.value = a;
	document.calendar.submit();
}

// Fonctions de préload
function load() {
	if (document.images) {
		this.length=load.arguments.length;
		for (var i=0;i<this.length;i++) {
			this[i+1]=new Image();
			this[i+1].src=load.arguments[i];
		}
	}
}

function checkInt(champ){
	var chiffres = new RegExp("[0-9]");
	var verif;
	for(x = 0; x < champ.value.length; x++){
		verif = chiffres.test(champ.value.charAt(x));
		if(verif == false){champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1); x--;}
	}
}

// _________________________________________________

//	scripts DialogBox

// _________________________________________________

// function getPageHeight() inspired of getPageSize() function by Lokesh Dhakar - http://www.huddletogether.com
function getPageHeight(){
	var pageHeight;

	var yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
	}
	
	var windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	return pageHeight;
}

function getObject(id){
	if (document.getElementById){
		var id = document.getElementById(id);
	}else{
		var id = document.all[id];
	}
	return id;
}

function setFullHeight(elem){
	pageHeight = getPageHeight();
	elemHeight = elem.style.height;
	elem.style.height = (elemHeight + pageHeight) + 'px';
}

function showMsg(){
	$("body").append("<div id='overlay'></div>");
	var overlay = getObject('overlay');
	var dialogBox = getObject('dialogBox');
	setFullHeight(overlay);
	nav = navigator.appVersion;
	if(nav.indexOf("MSIE")!=-1){
		t = nav.split("MSIE");
		ieversion = parseFloat(t[1]);
	}
	if (navigator.appName == "Microsoft Internet Explorer" && ieversion < 7){
	    selects = document.getElementsByTagName('select');
	    for(i = 0; i < selects.length; i++) {
	        selects[i].style.display = 'none';
	    }
		dialogBox.style.position = 'absolute';
		dialogBox.style.display = 'block';
		overlay.style.display = 'block';
	}else{
		$('#overlay').css({filter: 'alpha(opacity=80)','-moz-opacity': 0.8, opacity: 0.8}); 
		$("#overlay").animate({opacity: "show"}, 300);
		$("#dialogBox").animate({opacity: "show"}, "slow", "easeOut");
	}
}

function hideMsg(){
	var overlay = getObject('overlay');
	var dialogBox = getObject('dialogBox');
	nav = navigator.appVersion;
	if(nav.indexOf("MSIE")!=-1){
		t = nav.split("MSIE");
		ieversion = parseFloat(t[1]);
	}
	if (navigator.appName == "Microsoft Internet Explorer" && ieversion < 7){
		dialogBox.style.display = 'none';
		overlay.style.display = 'none';
	    selects = document.getElementsByTagName('select');
	    for(i = 0; i < selects.length; i++) {
	        selects[i].style.display = 'block';
	    }
	}else{
		$("#dialogBox").animate({opacity: "hide"}, "slow", "easeIn");
		$("#overlay").animate({opacity: "hide"}, 300);
	}
}
function displayWait(block){
    document.getElementById(block).innerHTML = '<div align="center"><img src="/media/loader.gif"/></div>';
}
function allowSubmitChooseAvatar()
{
    document.getElementById('btnChoose').style.visibility = 'visible';
}