var xmlHttp;
var SortBy = 'Username';
var Page = 1;

function showResults() {
	if (allowSearch == 1) {
		var str = document.SearchForm.Search.value;
	} else {
		str = '';
	}
	if (str == 'Search...') {
		str = '';
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=showResultsPage;
	url=url+"?Search="+str;
	url=url+"&SortBy="+SortBy;
	url=url+"&Page="+Page;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function showCalendar() {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	} 
	var url=showResultsPage;
	url=url+"?CalendarID="+CalendarID;
	url=url+"&thisMonth="+thisMonth;
	url=url+"&thisYear="+thisYear;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("txtOutput").innerHTML=xmlHttp.responseText;
		document.getElementById("txtMessage").innerHTML='&nbsp;';
	} else {
		document.getElementById("txtMessage").innerHTML='Loading...';
	}
}

function GetXmlHttpObject() { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}

function setSearch() {
	Page = 1;
	showResults();
}

function setSort(str) {
	if (SortBy == str) {
		SortBy = str + ' desc';
	} else {
		SortBy = str;
	}
	Page = 1;
	showResults();
}

function setPage(pg) {
		Page = pg;
		showResults();
}

function moveCalendar(intMonth, intYear) {
		thisMonth = intMonth;
		thisYear = intYear;
		showCalendar();
}

function clearSearch() {
	if (document.SearchForm.Search.value == 'Search...') {
		document.SearchForm.Search.value = '';
	} else {
		return true;
	}
}

function swapdiv(id) {
	if (document.getElementById) {
		if (document.getElementById(id).style.display == 'none') {
			document.getElementById(id).style.display = 'block';
		} else {
			document.getElementById(id).style.display = 'none';
		}
	} else {
		if (document.layers) {
			if (document.id.display == 'none') {
				document.id.display = 'blank';
			} else {
				document.id.display = 'none';
			}
		} else {
			if (document.all.id.style.display == 'none') {
				document.all.id.style.display = 'block';
			} else {
				document.all.id.style.display = 'none';
			}
		}
	}
}

function hidediv(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = 'none';
	} else {
		if (document.layers) {
			document.id.display = 'none';
		} else {
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	if (document.getElementById) {
		document.getElementById(id).style.display = 'block';
	} else {
		if (document.layers) {
			document.id.display = 'block';
		} else {
			document.all.id.style.display = 'block';
		}
	}
}

function setRecurdiv(id) {
	if (id == 'RecurDaily') {
		showdiv('RecurDaily');
		hidediv('RecurWeekly');
		hidediv('RecurMonthly');
		hidediv('RecurYearly');
	} else if (id == 'RecurWeekly') {
		hidediv('RecurDaily');
		showdiv('RecurWeekly');
		hidediv('RecurMonthly');
		hidediv('RecurYearly');
	} else if (id == 'RecurMonthly') {
		hidediv('RecurDaily');
		hidediv('RecurWeekly');
		showdiv('RecurMonthly');
		hidediv('RecurYearly');
	} else if (id == 'RecurYearly') {
		hidediv('RecurDaily');
		hidediv('RecurWeekly');
		hidediv('RecurMonthly');
		showdiv('RecurYearly');
	} else {
		hidediv('RecurDaily');
		hidediv('RecurWeekly');
		hidediv('RecurMonthly');
		hidediv('RecurYearly');
	}
}

function tinyCalendar(selectDate, m, y) {
	addEventWindow = window.open('calendars_tiny.asp?selectDate=' + selectDate + '&thisMonth=' + m + '&thisYear=' + y, 'miniCalendar', 'width=250, height=160, scrollbars=0, resizable=no');
}

function editSettings() {
	addEventWindow = window.open('settings.asp', 'EditUser', 'width=350, height=500, scrollbars=1, resizable=yes');
}

function addUser() {
	addEventWindow = window.open('users_add.asp', 'EditUser', 'width=350, height=450, scrollbars=1, resizable=yes');
}

function editUser(str) {
	addEventWindow = window.open('users_edit.asp?UserID=' + str, 'EditUser', 'width=350, height=450, scrollbars=1, resizable=yes');
}

function removeUser(str) {
	addEventWindow = window.open('users_remove.asp?UserID=' + str, 'EditUser', 'width=300, height=200, scrollbars=1, resizable=yes');
}

function addCategory() {
	addEventWindow = window.open('categories_add.asp', 'EditUser', 'width=350, height=265, scrollbars=1, resizable=yes');
}

function editCategory(str) {
	addEventWindow = window.open('categories_edit.asp?CategoryID=' + str, 'EditUser', 'width=350, height=265, scrollbars=1, resizable=yes');
}

function removeCategory(str) {
	addEventWindow = window.open('categories_remove.asp?CategoryID=' + str, 'EditUser', 'width=300, height=200, scrollbars=1, resizable=yes');
}

function addCalendar() {
	addEventWindow = window.open('calendars_add.asp', 'EditUser', 'width=400, height=500, scrollbars=1, resizable=yes');
}

function editCalendar(str) {
	addEventWindow = window.open('calendars_edit.asp?CalendarID=' + str, 'EditUser', 'width=400, height=500, scrollbars=1, resizable=yes');
}

function copyCalendar(str) {
	addEventWindow = window.open('calendars_copy.asp?CalendarID=' + str, 'EditUser', 'width=350, height=200, scrollbars=1, resizable=yes');
}

function removeCalendar(str) {
	addEventWindow = window.open('calendars_remove.asp?CalendarID=' + str, 'EditUser', 'width=300, height=200, scrollbars=1, resizable=yes');
}

function addStyle() {
	addEventWindow = window.open('styles_add.asp', 'EditUser', 'width=475, height=500, scrollbars=1, resizable=yes');
}

function editStyle(str) {
	addEventWindow = window.open('styles_edit.asp?StyleID=' + str, 'EditUser', 'width=475, height=500, scrollbars=1, resizable=yes');
}

function removeStyle(str) {
	addEventWindow = window.open('styles_remove.asp?StyleID=' + str, 'EditUser', 'width=300, height=200, scrollbars=1, resizable=yes');
}

function addEvent(str) {
	addEventWindow = window.open('events_add.asp?CalendarID=' + str, 'EditUser', 'width=410, height=440, scrollbars=1, resizable=yes');
}

function editEvent(str) {
	addEventWindow = window.open('events_edit.asp?EventID=' + str, 'EditUser', 'width=410, height=440, scrollbars=1, resizable=yes');
}

function viewEvent(str) {
	addEventWindow = window.open('events_view.asp?EventID=' + str, 'EditUser', 'width=410, height=440, scrollbars=1, resizable=yes');
}

function removeEvent(str, strDate) {
	addEventWindow = window.open('events_remove.asp?EventID=' + str + '&Date=' + strDate, 'EditUser', 'width=300, height=200, scrollbars=1, resizable=yes');
}

function importExport() {
	addEventWindow = window.open('import.asp', 'EditUser', 'width=300, height=300, scrollbars=1, resizable=yes');
}

function embedCode(str) {
	addEventWindow = window.open('embed.asp?CalendarID=' + str, 'EditUser', 'width=300, height=400, scrollbars=1, resizable=yes');
}

function viewRSVP(str) {
	addEventWindow = window.open('events_rsvp.asp?EventID=' + str, 'EditUser', 'width=400, height=300, scrollbars=1, resizable=yes');
}

function helpMenu(str) {
	addEventWindow = window.open('help.asp?ID=' + str, 'HelpWindow', 'width=300, height=200, scrollbars=1, resizable=yes');
}