function get_object(obj){
if (document.getElementById)
    return document.getElementById(obj);
else if (document.all)
    return document.all[obj];
}

function expandObj(obj_name) {
   
var obj;

obj = get_object(obj_name);

if (obj.style.display=="none") {
    eval('obj.style.display=""');
    }
else {
    eval('obj.style.display="none"');
    }  
}

function hideObj(obj_name) {
    
var obj;
obj = get_object(obj_name);
if(obj==null) return;
eval('obj.style.display="none"');
}

function showObj(obj_name) {
    
var obj;
obj = get_object(obj_name);
eval('obj.style.display=""');

}

function nouveau_calendrier() {
	expandObj('nouveau');
}

function reservation_expresse() {
	expandObj('express');
}

function reservation_fix() {
	expandObj('express');
}

function bar_new_fix() {
	expandObj('bar_new_fix');
	expandObj('fix_resv_detail');	
	expandObj('bar_view_fix');
	expandObj('express');		
}

function bar_view_fix() {
	expandObj('bar_new_fix');
	expandObj('fix_resv_detail');	
	expandObj('bar_view_fix');
	expandObj('express');	
}

function bar_new_ponc() {
	expandObj('bar_new_ponc');
	expandObj('resv_detail');	
	expandObj('bar_view_ponc');
	expandObj('express');		
}

function bar_view_ponc() {
	expandObj('bar_view_ponc');
	expandObj('express');		
	expandObj('bar_new_ponc');
	expandObj('resv_detail');
}
function hide_plage(i) {
	expandObj('p_'+i);		
}


function actuelle() {
	document.data_form.todo.value='actuelle'; 
	document.data_form.submit();	
}

function nouvelle() {
	document.data_form.todo.value='nouvelle'; 
	document.data_form.submit();	
}

function exp_chk() {
	b = false;
	for(dayCode = 1; dayCode <= 7; dayCode++) {
		if((get_object('sem' + dayCode).checked) && (get_object('sem' + dayCode).style.display != 'none')) b = true;
	}
	
	if(!b) {
		alert('Veuillez sélectionner un jour!');
		return;
	}
	document.reservation_express.stage.value='2'; 
	document.reservation_express.submit();	
}

function exp_resv() {
	document.reservation_express.stage.value='3'; 
	document.reservation_express.submit();	
}

function exp_okey() {
	expandObj('resv_result');
}

function rvls_group() {
	document.reservation_filter.report_model.value='0'; 
	document.reservation_filter.submit();	
}

function inv_html() {
	document.reservation_filter.todo.value='html'; 
	document.reservation_filter.submit();	
}

function inv_pdf() {
	document.reservation_filter.todo.value='pdf'; 
	document.reservation_filter.submit();	
}

function inv_delete() {
	document.reservation_filter.todo.value='delete'; 
	document.reservation_filter.submit();	
}

function rvls_class() {
	document.reservation_filter.report_model.value='1'; 
	document.reservation_filter.submit();	
}

function tsls_group() {
	document.reservation_filter.report_model.value='0'; 
	document.reservation_filter.submit();	
}

function tsls_class() {
	document.reservation_filter.report_model.value='1'; 
	document.reservation_filter.submit();	
}

function switch_calendar(id) {
	expandObj('b'+id);
	expandObj('t'+id);
}

function exp_populate(room_id, StartDate, StartHour, EndHour, wday) {
	document.reservation_express.StartCalDate.value = StartDate;	
	document.reservation_express.EndCalDate.value = StartDate;	
	document.reservation_express.StartHour.value = StartHour;
	document.reservation_express.EndHour.value = EndHour;	
	
	var semCheckbox = get_object('sem'+wday);
	semCheckbox.checked = true;
	
	var roomSelect = get_object('exp_room');
	
	for (optionCounter = 0; optionCounter < roomSelect.options.length; optionCounter++) { 
					
		if(roomSelect.options[optionCounter].value == room_id) {
			roomSelect.selectedIndex = optionCounter;	
		}
	}
	
	showObj('express');
	hideObj('nouveau');
	
	hideObj('resv_available');
	hideObj('resv_result');
}

function user_save_new() {
	document.data_form.todo.value='save_new'; 
	document.data_form.submit();	
}

function change_critical() {
	document.data_form.todo.value='change_critical'; 
	document.data_form.submit();			
}

function trait_delete(id) {
	eval("document.data_form."+"content_"+id+".value=''");
}

function user_delete(id) {
	if (confirm("Êtes vous certain de vouloir détruire la fiche de cet utilisateur?") == true) {
		document.data_form.todo.value='delete'; 
		document.data_form.submit();			
	}
}

function fix_chk() {
	document.reservation_fix.stage.value='2'; 
	document.reservation_fix.submit();	
}

function pop_fix_chk() {
	document.pop_form_fix.stage.value='2'; 
	document.pop_form_fix.submit();	
}

function pop_fix_chg() {
	document.pop_form_fix.todo.value='change'; 
	document.pop_form_fix.stage.value='1'; 
	document.pop_form_fix.submit();	
}

function pop_long_chk() {
	document.pop_form_long.stage.value='2'; 
	document.pop_form_long.submit();	
}

function pop_long_chg() {	
	document.pop_form_long.stage.value='1'; 
	document.pop_form_long.submit();	
}

function fix_terminate(id) {
	document.reservation_list.todo.value='delete'; 
	document.reservation_list.delete_id.value=id; 
	document.reservation_list.submit();	
}

function modi_resv_cancel() {
	document.data_form.todo.value='cancel'; 
	document.data_form.submit();		
}

function change_client(act) {
	//all form names in n
	var v = get_object('admin_rep').value; 
/*	var ls = n.split(',');
	for(i=0; i < ls.length; i++) {
		eval('document.'+ls[i]+'.user_id.value='+v);	
	}
*/
	if(act == 0) { //keep in form
		for(i=0; i < document.forms.length; i++) {
			document.forms[i].user_id.value=v;		
		}
		
		get_object('admin_info').innerHTML = 'Usager : ' + users[v];
	}
	
	if(act == 1) { //modify directly
		document.school.user_id.value=v;
		document.school.submit();		
	}
//need ajax to modify session 'user_id'	 
}

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

function populatePlage() {	
  var selObj = document.getElementById('plageSelect');
  var foundPlage = false;
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.remove(i);
    }
    selObj.options.length=0;
    selObj.selectedIndex = 0;
  // Populate the drop down with Plages from the selected room
  var PlageLineArray = Plage.split("|");  // Split into lines
  var optionCntr = 0;
  //alert('arr'+PlageLineArray.length);
  for (var loop = 0; loop < PlageLineArray.length; loop++) {
    lineArray = PlageLineArray[loop].split("#");
    roomCode  = TrimString(lineArray[0]);
    PlageCode    = TrimString(lineArray[1]);
    PlageName    = TrimString(lineArray[2]);
  if (document.getElementById('roomSelect').value == roomCode && roomCode != '' ) {
    // If it's a input element, change it to a select    
      if ( PlageCode != '' ) {
        selObj.options[optionCntr] = new Option(PlageName, PlageCode);
      }
      // See if it's selected from a previous post
      if ( PlageCode == postPlage && roomCode == postRoom ) {
        selObj.selectedIndex = optionCntr;
        //alert(optionCntr);
      }
      foundPlage = true;
      optionCntr++
    }
  }
  //alert('populate');
  // If the room has no Plages, change the select to a text box
  if ( ! foundPlage ) {
  
  }

}

function selectDay(obj) {	
	a = obj.value.split('.');
	var d = new Date();
	d.setFullYear(a[2], a[1] - 1 ,a[0]);
	
	var selObj = document.getElementById('daySelect');
  for (var i = 0; i < selObj.options.length; i++) {  
  	w = d.getDay();
  	w = (w == 0) ? 7 : w;
    if( selObj.options[i].value == w) {
    	 selObj.selectedIndex = i;	
    }
  }    
}

function populateDay() {	
	var arr_days = new Array( 'Dimanche',	
		'Lundi',
		'Mardi',
		'Mercredi',
		'Jeudi',
		'Vendredi',
		'Samedi',
		'Dimanche'	);
  var selObj = document.getElementById('daySelect');
  var foundDay = false;
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.remove(i);
    }
    selObj.options.length=0;
    selObj.selectedIndex = 0;
  // Populate the drop down with Plages from the selected room
  var DayLineArray = workday.split("|");  // Split into lines
  var optionCntr = 0;
  //alert('arr'+PlageLineArray.length);
  for (var loop = 0; loop < DayLineArray.length; loop++) {
    lineArray = DayLineArray[loop].split("#");
    roomCode  = TrimString(lineArray[0]);
    DayCode    = TrimString(lineArray[1]);
    DayStatus    = TrimString(lineArray[2]);
  if (document.getElementById('roomSelect').value == roomCode && roomCode != '' && DayStatus == 'A') {
    // If it's a input element, change it to a select    
      if ( DayCode != '' ) {
        selObj.options[optionCntr] = new Option(arr_days[DayCode], DayCode);
      }
      // See if it's selected from a previous post
      if ( DayCode == postDay && roomCode == postRoom ) {
        selObj.selectedIndex = optionCntr;
        //alert(optionCntr);
      }
      foundDay = true;
      optionCntr++
    }
  }
  //alert('populate');
  // If the room has no Plages, change the select to a text box
  if ( ! foundDay ) {
  
  }

}
function checkMail(x)
{
	//var x = document.forms[0].email.value;
	//alert(x);	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	//if (filter.test(x)) alert('YES! Correct email address');
	//else alert('NO! Incorrect email address');
	return filter.test(x);
}

/*==================================================
  Cookie functions
  ==================================================*/
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

var old_div = 0;
function showmeonly(id) {
	if (old_div == id) {
		expandObj('doctor_'+id);
		old_div = 0;
		return;
	} else if (old_div > 0) {
		expandObj('doctor_'+old_div);		
	}	
	expandObj('doctor_'+id);
	old_div = id;
}          

