var update_url = 'http://www.theresolutionvineyard.com/update_cal.ajax.php';
var image_dir =	"http://www.theresolutionvineyard.com/images/calendar/";
var icon_loading = "http://www.theresolutionvineyard.com/images/calendar/icon_loading.gif";
var cal_on = "cal_on_"; // start of cal number file name (om/booked)
var cal_num_img_type = ".png";
var num_w	=	"20px";	// width of numbers
var num_h	=	"20px";	// height of numbers
var	image_loading = '<img src="'+icon_loading+'" style="border:none; width:16px; height:16px;" />';

var state_elm	= new Object();
var elm_num		=	new Object();
var special_state = new Object();

function ajax_mod_state(the_date,the_num,e) {
	
	// catch key press
	special_state="";
	the_key=what_key(e)
	if(the_key!="ko")special_state=the_key;
	
	// 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+"?the_date="+the_date+"&am_pm="+special_state;
	
	ajax.requestFile = the_url;
	ajax.onCompletion = reset_state;
	ajax.runAJAX();	
}

function reset_state(){
	if(ajax.response == "on" || ajax.response == "off" || ajax.response == "am" || ajax.response == "pm") {
		state_elm.innerHTML = "<img src='"+image_dir+"cal_"+ajax.response+"_"+elm_num+cal_num_img_type+"' width='"+num_w+"' height='"+num_h+"' border='0'/>";
	} else {
		alert(ajax.response);
	}
}

function what_key(e) {

	if(document.all)e = event;
  if(e.ctrlKey)		return "pm";
  else if(e.altKey)	return "am";
	else return "ko";
		
}




