
var color_off = '#ffffff';
var color_over = '#EFECD9';
var color_selected = '#AF8B57';

var color_calendar_header = '#CFC594';
var color_calendar_blank = '#DFDFDF';

function validate_reserve(f) {
	var e = new Errors();
	if(!f.first_name.value) e.add("Please enter your first name.");
	if(!f.last_name.value) e.add("Please enter your last name.");
	if(!validate_email(f.email.value)) e.add("Sorry, Invalid Email Address!");
	if(!f.address_1.value) e.add("Please enter your street address.");
	if(!f.city.value) e.add("Please enter your city.");
	if(!f.state.value) e.add("Please select your state.");
	if(!f.zip.value) e.add("Please enter your postal code.");
	if(!f.country.value) e.add("Please select your country.");
	if(!f.phone_home.value) e.add("Please enter your home phone.");

	return e.alert() ? false : true;
}

function validate_email(email) {
	if(email.length <= 5) return false;
	if(email.indexOf('@', 0) == -1) return false;
	return true;
}

function SelectCell(cell) {
	if (!cell.getAttribute('selected') * 1) {
    	cell.style.backgroundColor = color_over;
	}
}

function unSelectCell(cell) {

	if (!cell.getAttribute('selected') * 1) {
    	cell.style.backgroundColor = color_off;
	}
}
function MarkCell(cell) {
	if (cell.getAttribute('selected') * 1) {
		cell.setAttribute('selected', 0);
    	cell.style.backgroundColor = color_off;
		return 0;
	} else {
		cell.setAttribute('selected', 1);
    	cell.style.backgroundColor = color_selected;
		return 1;
	}
}

function saveDate(that, date) {
	var val = MarkCell(that);

	var f = document.forms['reserve_form'];
	if (f.reservation_date.value.indexOf(date) ==-1 ) {
		f.reservation_date.value = f.reservation_date.value + date + ", ";
	} else {
		var str = f.reservation_date.value;
		var takeoff = date + ', ';
		f.reservation_date.value = str.replace(takeoff, "");
	}
	
}
function calendar(month,year,specials) {
	var special_days = new Array();
	special_days = specials.split(',');
	var day_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
	var month_of_year = new Array('January','February','March','April','May','June','July','August','September','October','November','December');

	month = month-1;
	var Calendar = new Date();
	var days_per_week = 7;
	var days_per_month = 31;
	var cal_html;

	Calendar.setDate(1);
	Calendar.setMonth(month);
	Calendar.setYear(year);

	var tr_open = '<tr>';
	var tr_close = '</tr>';
	var td_start = '<td align="center" bgcolor="'+color_calendar_blank+'" width="28" class="small">';
	var td_open_txt = '<td align="center" bgcolor="'+color_calendar_header+'" class="small" width="28">';
	var td_close = '</td>';

	cal_html =  '';
	cal_html += '<table border=0" cellspacing="1" cellpadding="1">' + tr_open;
	cal_html += '<td colspan="' + days_per_week + '" class="small" align="center"><b>';
	cal_html += month_of_year[month]  + '&nbsp;' + year + '</b>' + td_close + tr_close;
	cal_html += tr_open;

	for(index=0; index < days_per_week; index++) {
		cal_html += td_open_txt + day_of_week[index] + td_close;
	}

	cal_html += td_close + tr_close;
	cal_html += tr_open;

	for(index=0; index < Calendar.getDay(); index++) {
		cal_html += td_start + '&nbsp;' + td_close;
	}

	for(index=0; index < days_per_month; index++) {
		if( Calendar.getDate() > index ) {
			week_day =Calendar.getDay();
			if(week_day == 0) {
				cal_html += tr_open;
			}
			if(week_day != days_per_week) {
				var day  = Calendar.getDate();
				var day_found=0;
				for (i=0; i<special_days.length; i++){
					if(day==special_days[i]){
						day_found = 1;
					} 
				}	
				if(day_found == 1) {
			cal_html += '<td style="cursor:pointer;" align="center" bgcolor="'+color_off+'" onmouseover="SelectCell(this);" onmouseout="unSelectCell(this);" onclick="saveDate(this, \'' + month_of_year[month] + ' ' + day + ' - ' + year + '\');" class="small"><b>' + day  + '</b>' + td_close;
				} else {
  					cal_html += td_start + day + td_close;
  				}
			}

		if(week_day == days_per_week)
			cal_html += tr_close;
		}
  		Calendar.setDate(Calendar.getDate()+1);
	}

	cal_html += '</td></tr></table><br>';

	
	document.write(cal_html);

}

//  End -->