/**
 * AJAX availability - Availability calendar
 *
 * Dependencies: None
 *
 * @version			2.1
 * @date			2009-01-07
 * @license			MIT-style license
 * @author			Chris Bolson <calendar [at] cbolson.com>
 * @copyright		Author
 * @docmentation	http://www.cbolson.com/code/availability-calendar/
 */ 

var update_url	=	'./update_cal.ajax.php';	//	path to ajax file
var image_dir	=	"./images/";				//	path to calendar images
var cal_off		=	"cal_off_";					//	start of cal number file name (off/available)
var cal_on		=	"cal_on_";					//	start of cal number file name (om/booked)
var cal_file_type=	".png";						//	file type extension
var	image_loading=	"<img src='./images/icon_loading.gif' border='0' width='16' height='16'/>";

var state_elm	=new Object();
var elm_num		=	new Object();
var special_state= new Object();
function ajax_mod_state(id_item,the_date,the_num,e){	
	
	//catch key press
	special_state="";
	the_key=what_key(e)
	if(the_key!="ko")special_state=the_key;
	//alert(event.keyCode);
	
	//	 start class
	ajax 		=	new sack();
	
	//	 define image span to update
	state_elm=document.getElementById("state_"+the_date);
	// set state loading while ajax is executed
	state_elm.innerHTML = image_loading;
	
	//	define number for grahic to show (needed in completion function)
	elm_num	=	the_num;
	
	//	 call ajax file to update state
	var the_url=update_url+"?id_item="+id_item+"&the_date="+the_date+"&special_state="+special_state;
	//alert(the_url);
	
	ajax.requestFile = the_url;
	ajax.onCompletion =reset_state;
	ajax.runAJAX();
	
}
function reset_state(){
	//alert(ajax.response);
	if (ajax.response=="on"
	||  ajax.response=="off"
	||  ajax.response=="am"
	||  ajax.response=="pm"
	){
			state_elm.innerHTML = "<img src='./images/cal_"+ajax.response+"_"+elm_num+".png' width='20px' height='20px' border='0'/>";
	}else{
		alert(ajax.response);
	}
}

function what_key(e) {

   if(document.all)e = event; // IE need this
	//alert(e);
   	if(e.ctrlKey)		return "pm";
   	else if(e.altKey)	return "am";
	else return "ko";
}



