var ns4 = (document.layers) ? 1:0;
var ie = (document.all) ? 1:0;
var dom = (document.getElementById) ? 1:0;
var activeColor = '#CBAF94';
var inactiveColor = '#F1EEEA';
var selectedColor = '#CBAF94';
var state = new Array(1000);
var datestr = new Array(1000);
var i;
for (i = 0; i < 1000; i ++) state[i] = false;
for (i = 0; i < 1000; i ++) datestr[i] = '';

function calendarAddDate(day, str) {
	//alert(str);
	datestr[day] = str;
}

function calendarSetActive(day, prefix, str) {
	var id = prefix + day;
	var e;
	state[day] = !state[day];
	if (ie) {
		e = document.all(id);
		e.style.background = (state[day])? selectedColor: inactiveColor;
	}
	else if (dom) {
		e = document.getElementById(id);
		e.style.background = (state[day])? selectedColor: inactiveColor;
	}
	else {
		e = document.layers(id);
		e.style.background = (state[day])? selectedColor: inactiveColor;
	}
}

function calendarAct(day, prefix) {
	var id = prefix + day;
	var e;
	if (ie) {
		e = document.all(id);
		if (!state[day]) e.style.background = activeColor;
	}
	else if (dom) {
		e = document.getElementById(id);
		if (!state[day]) e.style.background = activeColor;
	}
	else {
		e = document.layers(id);
		if (!state[day]) e.style.background = activeColor;
	}
}

function calendarInact(day, prefix) {
	var id = prefix + day;
	var e;
	if (ie) {
		e = document.all(id);
		if (!state[day]) e.style.background = inactiveColor;
	}
	else if (dom) {
		e = document.getElementById(id);
		if (!state[day]) e.style.background = inactiveColor;
	}
	else {
		e = document.layers(id);
		if (!state[day]) e.style.background = inactiveColor;
	}
}

function calendarSubmit(hID) {
	var i, str;
	str = "";
	for (i = 0; i < 1000; i ++) {
		if (state[i]) str = str + "'" + datestr[i] + "'" + ",";
	}
	if (str == "") {	//if no date is selected, select all open house dates
		for (i = 0; i < 1000; i ++) {
			if (datestr[i] != "") str = str + "'" + datestr[i] + "'" + ",";
		}
	}

	str = str.substring(0, str.length - 1);
	//document.forms["frmSearch"].elements["selectedDates"].value = str;	
	document.forms[0].elements[hID].value = str;
	//alert(document.forms[0].elements[hID].value)
}