/*******************************************************************************************************************
* Gère le calcul de l'espace
*/

/* Moteur : Combien de personne ?
*****************************************************************************************************/
function getperso_mcalcspace(){
	var iRoomType		= -1;
	rs = $('ce_surface').value;
	if(rs == "") rs = "0";	
	var b				= valid_mcalcspace(rs);
	
	if(b == 1){
	//	//alert(lb_nonb);
	}else{
		nogo			= 0;			
		if($('ce_disposition').selectedIndex >= 0){
			iRoomType	= $('ce_disposition').options[$('ce_disposition').selectedIndex].value;
			
			switch(iRoomType){
				case "3":															// Conference					
					if(rs > 1000) {
						//alert(lb_notfor1000);
						nogo	= 1;
					}
				break;
				case "4":															// H-Square		
					if(rs > 2000 || rs < 300) {
						//alert(lb_for300_2000);
						nogo	= 1;
					}	
				break;
				case "10":															// Trade Show - 8 x 10
					if(rs < 1500) {
						//alert(lb_norfor1500);
						nogo	= 1;
					}	
				break;
				case "11":															// Trade Show - 10 x 10		
					if(rs < 1500) {
						//alert(lb_norfor1500);
						nogo	= 1;
					}	
				break;
				default: nogo = 0;
			};
		}
								
		if(nogo != 1){
			i			= 0;
			if(1 == iRoomType) i = .0832;
			if(2 == iRoomType) i = .0832;
			if(3 == iRoomType) i = .024;
			if(4 == iRoomType) i = .024;
			if(5 == iRoomType) i = .100;
			if(6 == iRoomType) i = .069;
			if(7 == iRoomType) i = .057;
			if(8 == iRoomType) i = .100;
			if(9 == iRoomType) i = .111;
			if(10 == iRoomType) i = .00625;
			if(11 == iRoomType) i = .0050;
			if(12 == iRoomType) i = .0286;
			if(13 == iRoomType) i = .04163;

			peeps		= rs*i;
			peeps		= Math.round(peeps);		
			$('ce_partmax').value=peeps;
		}
	}
}

/* Moteur : Quelle surface ?
*****************************************************************************************************/
function getroom_mcalcspace(){
	var iRoomType		= -1;
	pp					= $('ce_participant').value;
	if(pp == "") pp = "0";
	var d				= valid_mcalcspace(pp);
	
	if(d == 1){
		//alert(lb_nonb);
	}else{
		nogo			= 0;	
		if($('ce_disposition').selectedIndex >= 0){
			iRoomType = $('ce_disposition').options[$('ce_disposition').selectedIndex].value;
			switch(iRoomType){
				case "3":															// Conference
					if(pp > 24) {
						//alert(lb_notfor24);
						nogo	= 1;
					}	
				break;
				case "4":															// H-Square
					if(pp > 52 || pp < 10) {
						//alert(lb_for10_52);
						nogo	= 1;
					}
				break;
				default: nogo = 0;
			};		
		}

		if(nogo != 1){
			i			= 0;
			if(1 == iRoomType) i = 12.0321;
			if(2 == iRoomType) i = 12.0321;
			if(3 == iRoomType) i = 40.16667;
			if(4 == iRoomType) i = 38.461;
			if(5 == iRoomType) i = 9.46969;
			if(6 == iRoomType) i = 14.492;
			if(7 == iRoomType) i = 17.543;
			if(8 == iRoomType) i = 10;
			if(9 == iRoomType) i = 9.009;
			if(10 == iRoomType) i = 160;
			if(11 == iRoomType) i = 200;
			if(12 == iRoomType) i = 35;
			if(13 == iRoomType) i = 24.0211;
			
			roomz		= pp*i;			
			roomz		= Math.round(roomz);
			$('ce_surface_sf').value=roomz;
		}
	}
}

/* Initialisation du moteur
*****************************************************************************************************/
function init_mcalcspace(){
	nogo			= 0;
	$('ce_surface_sf').value		= "";
	$('ce_partmax').value		= "";
	$('ce_surface').value		= "";
	$('ce_participant').value	= "";
}

/* Validation du résultat de la conversion
*****************************************************************************************************/
function valid_mcalcspace(mNombre){
	var valid			= "0123456789"
	var mNbTaille		= eval(mNombre.length);
	var b_valid			= true;
	var temp			= "";

	if (mNombre == "0"){
		b_valid			= false;
	}else{
		for(var i = 0; i < mNbTaille; i++){
			temp		= "" + mNombre.substring(i, i+1);
			if(valid.indexOf(temp) == "-1"){ b_valid = false; }
		}
	}
	return (b_valid == false) ? 1 : 0;
}

Event.observe(window, 'load', function() {
	$('bySize').onclick = getperso_mcalcspace ;
	$('byPeople').onclick = getroom_mcalcspace ;
});
