var housing_form;
var housing_date;
var housing_time;
var housing_location;
var housing_lang;
var housing_pid = null;
var housing_class = false;

/**
* removes a class from the database
*/
function remove(id,inAddr){
	addr = inAddr;
	var deleteId = confirm("Are you sure you want to delete this entry?");
	if(deleteId){
		set_output_div("result_"+id);
		//set_function_name("disable");
		set_method("POST");
		set_query("opt=deleting&id="+id);
		send_req("admin/update.php");
		setTimeout('reloadPage()',2000);
	}//end if
}//end remove function

/**
* adds a class to the database
*/
function add_class(id,url){
	this.housing_pid = id;
	this.housing_form = document.forms["form_"+id];
	this.housing_date = housing_form.housing_date;
	this.housing_time = housing_form.housing_time;
	this.housing_location = housing_form.housing_location;
	this.housing_lang = housing_form.housing_lang;
	//alert(this.housing_location.value);
	var qstr = "id="+id+
					"&date="+escape(trim(this.housing_date.value))+
					"&time="+escape(trim(this.housing_time.value))+
					"&location="+escape(trim(this.housing_location.value))+
					"&lang="+escape(trim(this.housing_lang.value))+
					"&opt="+this.housing_form.opt.value;	
	set_output_div("saved");
	set_function_name("disable");
	set_method("POST");
	set_query(qstr);
	
	if(trim(this.housing_date.value).length<2 || 
	   trim(this.housing_time.value).length<2 || 
		trim(this.housing_location.value).length<2){
		alert("Please fill in the required fields.");
	}else{
		send_req(url);
	}//end else
	return false;
}//end add_class function

/**
* disables the input fields while the update is in progress
*/
function disable(str){
	str = unescape(str);
	//document.getElementById("save").style.display = "none";
	this.housing_date.disabled = true;
	this.housing_time.disabled = true;
	this.housing_location.disabled = true;
	this.housing_lang.disabled = true;
	document.getElementById("result_"+this.housing_pid).innerHTML = str;
	setTimeout('reloadPage()',3000);
	return false;
}//end disable

/**
* reloads the page after an update is completed
*/
function reloadPage(){
	this.location="/housing/admin.0.html?opt=loadClass";	
}//end reloadPage


/**
* make sure the required fields are filled out
*/
function check(){
	var housing_form = document.form1;
	var name = trim(housing_form.user.value);
	var address = trim(housing_form.address.value);
	//alert(class);
	if(housing_class && name!="" &&address!="" ){
		//alert("set");
	}else{
		alert("Please fill in the required fields.");
		return false;
	}//end else
}//end check

function set_class(in_class){
	this.housing_class = in_class;
}//end set_class


/**
* trim white spaces
*/
function trim(str){
	return str.replace(/(\s\s)+/g,'');
}//end trim
