if(document.images) 
{
	pics = new Array();
	pics[1] = new Image();
	pics[1].src = "images/submit_a.gif";
	pics[2] = new Image();
	pics[2].src = "images/submit_b.gif";
	pics[3] = new Image();
	pics[3].src = "images/search_a.gif";
	pics[4] = new Image();
	pics[4].src = "images/search_b.gif";
	pics[5] = new Image();
	pics[5].src = "images/reset_a.gif";
	pics[6] = new Image();
	pics[6].src = "images/reset_b.gif";	
	pics[7] = new Image();
	pics[7].src = "images/add_event_a.gif";
	pics[8] = new Image();
	pics[8].src = "images/add_event_b.gif";	
	
}
function checkValidDate()
{
	// convert string into a date
	var dateEntered = document.Form1.txtstartdate.value;
	var comp = dateEntered.split('/');
	var de = new Date(parseInt(comp[2]), parseInt(comp[0]) - 1, parseInt(comp[1]));
	// create today value
	var now = new Date();
	var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());			
	// compare
	if (de <= today) 
	{
		alert("The date you entered must be later than today's date.");
		status = "invalid";			
	}
}
function changer(from,to) 
{
	if(document.images) 
	{
		document.images[from].src = pics[to].src;
	}
}
function CheckPhoneNum(src) 
{			
	var val = src.value;
	var reP = /^\d{3}-\d{3}-\d{4}$/; // Phone Number 
	var reT = /^\d{1}-\d{3}-\d{3}-\d{4}$/; // Toll Free Number
		
	if (src.value != "")
	{
			if ( !( reP.test(val) || reT.test(val) )  ) 
			{
				alert( 'Invalid phone number.\nShould be of the form: 000-000-0000 or 1-800-000-0000' );
				src.focus();
				status = "invalid";                  
				return false;
			}                                          
	}
}
function CheckEmail(src) 
{ 
	a = src.value;
	var at = a.indexOf("@") 
	var name = a.substring(0, at) 
	var isp = a.substring(at + 1, a.length) 
	var dot = a.lastIndexOf(".") 
	if (src.value != "")
	{
		if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (a.length - 1)) { 
				alert("Please make sure that you include your correct email address.") 											
				src.focus() 
				status = "invalid";	
		} 
	}
}
function CheckPhoneNum(src) 
{			
	var val = src.value;
	var reP = /^\d{3}-\d{3}-\d{4}$/; // Phone Number 
	var reT = /^\d{1}-\d{3}-\d{3}-\d{4}$/; // Toll Free Number
		
	if (src.value != "")
	{
			if ( !( reP.test(val) || reT.test(val) )  ) 
			{
				alert( 'Invalid phone number.\nShould be of the form: 000-000-0000 or 1-800-000-0000' );
				src.focus();
				status = "invalid";                  
				return false;
			}                                          
	}
}
function CheckEmail(src) 
{ 
	a = src.value;
	var at = a.indexOf("@") 
	var name = a.substring(0, at) 
	var isp = a.substring(at + 1, a.length) 
	var dot = a.lastIndexOf(".") 
	if (src.value != "")
	{
		if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (a.length - 1)) { 
				alert("Please make sure that you include your correct email address.") 											
				src.focus() 
				status = "invalid";	
		} 
	}
}		
function CheckStartTimeStatus()
{
	status = "valid";		
	if ((document.Form1.ddStartHour.value == "hour") && (document.Form1.ddStartMinute.value == "minute") && (document.Form1.ddStartTOD.value == "time of day"))
	{
		alert("You must specify the Start Time of the event.");
		status = "invalid";					
		return;					
	}
	else if ((document.Form1.ddStartHour.value != "hour") && (document.Form1.ddStartMinute.value == "minute") || (document.Form1.ddStartTOD.value == "time of day"))
	{
		alert("You must specify the complete Start Time.");
		status = "invalid";	
		return;					
	}
	else if ((document.Form1.ddStartHour.value == "hour") || (document.Form1.ddStartMinute.value == "minute") && (document.Form1.ddStartTOD.value != "time of day"))
	{
		alert("You must specify the complete Start Time.");
		status = "invalid";	
		return;					
	}
	else if ((document.Form1.ddStartHour.value == "hour") || (document.Form1.ddStartTOD.value == "time of day") && (document.Form1.ddStartMinute.value != "minute"))
	{
		alert("You must specify the complete Start Time.");
		status = "invalid";		
		return;					
	}
}
function CheckEndTimeStatus()
{			
	//End Time										
	if ((document.Form1.ddEndHour.value == "hour") && (document.Form1.ddEndMinute.value == "minute") && (document.Form1.ddEndTOD.value == "time of day"))
	{
		alert("You must specify the End Time of the event");
		status = "invalid";					
		return;					
	}
	else if ((document.Form1.ddEndHour.value != "hour") && (document.Form1.ddEndMinute.value == "minute") || (document.Form1.ddEndTOD.value == "time of day"))
	{
		alert("You must specify the complete End Time.");
		status = "invalid";	
		return;					
	}
	else if ((document.Form1.ddEndHour.value == "hour") || (document.Form1.ddEndMinute.value == "minute") && (document.Form1.ddEndTOD.value != "time of day"))
	{
		alert("You must specify the complete End Time.");
		status = "invalid";	
		return;					
	}
	else if ((document.Form1.ddEndHour.value == "hour") || (document.Form1.ddEndTOD.value == "time of day") && (document.Form1.ddEndMinute.value != "minute"))
	{
		alert("You must specify the complete End Time.");
		status = "invalid";		
		return;					
	}
}
function calculateTime()
{
	var startHourAmt = document.Form1.ddStartHour.value;
	var endHourAmt = document.Form1.ddEndHour.value;
	if (document.Form1.ddStartTOD.value == "PM")
	{
		startHourAmt = (parseFloat(document.Form1.ddStartHour.value) + 12);
	}
	startMinutes = calculateMinutes(document.Form1.ddStartMinute);
	startHourAmt = parseFloat(startHourAmt) + parseFloat(startMinutes);				
	if (document.Form1.ddEndTOD.value == "PM")
	{
		endHourAmt = (parseFloat(document.Form1.ddEndHour.value) + 12);
	}
	//alert(startHourAmt);
	//alert(endHourAmt);
	endMinutes = calculateMinutes(document.Form1.ddEndMinute);
	endHourAmt = parseFloat(endHourAmt) + parseFloat(endMinutes);				
	var hoursWorked;
	hoursWorked = parseFloat(endHourAmt) - parseFloat(startHourAmt);									
	if (startHourAmt != 24 && startHourAmt != 12 && endHourAmt != 12 && endHourAmt != 24 && startHourAmt != 24.5 && startHourAmt != 12.5 && endHourAmt != 12.5 && endHourAmt != 24.5)
	{
		if(hoursWorked < 0 && document.Form1.ckbAfterMidnight.checked == false)
		{
			alert("Your time of event is not valid, please check your start and end time.");
			status = "invalid";		
			return;					
		}
	}
}		
function calculateMinutes(src)
{
	var amtTime = "";
	if(src.value == "1" || src.value == "2")
	{
		amtTime = src.value
	}
	else if (src.value == "15")
	{
		amtTime = ".25";
	}
	else if (src.value == "30")
	{
		amtTime = ".50";
	}
	else if (src.value == "45")
	{
		amtTime = ".75";
	}
	else if (src.value == "00")
	{
		amtTime = "0";
	}			
	return amtTime;
}	
//moved here from default.aspx
function submit_onclick()
{			
	document.all["hiddencategory"].value = "Y";
	if(document.all["ddCategory"].value == "Select a Category")
	{
		document.all["hiddencategory"].value = "N";
		document.all["hiddencategoryvalue"].value = "";					
	}			
	document.Form1.submit();		
}
function viewAll_onclick()
{
	document.all["ddCommunity"].value = "Select a Community";
	document.all["ddCategory"].value = "Select a Category";
	document.all["txtSearch"].value = "";
	document.Form1.submit();
}
function search_onclick()
{		
	document.all["hiddenaction"].value = "S";		
	if((document.all["txtSearch"].value == "") && (document.all["ddCategory"].value == "Select a Category") && (document.all["ddCommunity"].value == "Select a Community"))
	{
		alert("You must specify a search criteria to search for.");
	}
	else
	{				
		document.all["hiddencategory"].value = "Y";
		if(document.all["ddCategory"].value == "Select a Category")
		{
			document.all["hiddencategory"].value = "N";
			document.all["hiddencategoryvalue"].value = "";						
		}					
		document.Form1.submit();				
	}				
}
function createFilter_onclick()
{
var searchQuery = "";
var used = "N";
	if((document.all["txtSearch"].value == "") && (document.all["ddCategory"].value == "Select a Category") && (document.all["ddCommunity"].value == "Select a Community"))
	{
		alert("You must specify a search criteria.");
		return;
	}
	if (document.all["txtSearch"].value != "")
	{
		searchQuery = "search=" + document.all["txtSearch"].value;
		used = "Y";
	}
	if (document.all["ddCategory"].value != "Select a Category")
	{
		if (used == "Y")
		{
			searchQuery += "&category=" + document.all["ddCategory"].value;
		}
		else
		{
			searchQuery += "category=" + document.all["ddCategory"].value;					
			used = "Y";
		}
	}
	else
	{
		document.all["hiddencategoryvalue"].value = "";
	}
	if (document.all["ddCommunity"].value != "Select a Community")
	{
		if (used == "Y")
		{				
			searchQuery += "&community=" + document.all["ddCommunity"].value;
		}
		else
		{
			searchQuery += "community=" + document.all["ddCommunity"].value;					
			used = "Y";
		}					
	}				
	alert("Your view to link to this page has been copied to your clipboard, please paste this link into your desired page.");
	
	theForm = document.Form1;
	theForm.copyArea.value= "http://www.chatham-kent.ca/calendar/default.aspx?" +  searchQuery;
	r= theForm.copyArea.createTextRange();
	r.select();
	r.execCommand('copy');				
	
//	alert("http://www.chatham-kent.ca/calendar/WebForm1.aspx?" + searchQuery);		
}

function turnOff()
{
	var currentWeek = "";
	if(document.all["currentweek"].value == "")
	{
		currentWeek = 1;
	}else{
		currentWeek = parseFloat(document.all["currentweek"].value);						
	}
	var nextWeek = currentWeek + 1;
	document.all["divweek" + currentWeek + "s"].style.display = '';
	document.all["divweek" + nextWeek + "s"].style.display = '';
}	
function showList()
{
	document.all["hiddenview"].value = "L";
	document.all["divCalendar"].style.display = 'none';
	document.all["divCalendarList"].style.display = '';
}			
function showMonth()
{
	document.all["hiddenview"].value = "M";
	document.all["divCalendarList"].style.display = 'none';
	document.all["divCalendar"].style.display = '';
	ResetDivs();
	//for (var i=1; i < 6; i++)
	for (var i=1; i <= parseFloat(document.all["amountofweeks"].value); i++)
	{
		document.all["divweek" + i + "s"].style.display = '';
	}			
}
function showWeek()
{
	document.all["hiddenview"].value = "W";
	ResetDivs();
	document.all["divCalendarList"].style.display = 'none';
	var currentWeek = "";

	if((document.all["currentweek"].value == "") && (document.all["hiddendirection"].value  == "F"))
	{
		currentWeek = 1;
	}
	else if((document.all["currentweek"].value == "") && (document.all["hiddendirection"].value  == "B"))
	{

		document.all["currentweek"].value = parseFloat(document.all["amountofweeks"].value);
		currentWeek = parseFloat(document.all["amountofweeks"].value);
	}
	else				
	{
		currentWeek = parseFloat(document.all["currentweek"].value);						
	}			
	for (var i=1; i <= parseFloat(document.all["amountofweeks"].value); i++)
	{
		if(document.all["divweek" + i + "s"])
		{
			document.all["divweek" + i + "s"].style.display = 'none';
		}
	}	
	if(document.all["divweek" + currentWeek + "s"])
	{
		document.all["divweek" + currentWeek + "s"].style.display = '';
	}
}	

function showToday()
{		
	document.all["hiddenview"].value = "";
	//ResetDivs();				
	document.all["divCalendar"].style.display = '';	
	document.all["ddmonth"].value =	document.all["hiddenactualmonth"].value;				
	document.all["ddyear"].value = document.all["hiddenactualyear"].value;
	document.all["hiddencurrentmonth"].value =	document.all["hiddenactualmonth"].value;	
	document.all["hiddencurrentyear"].value = document.all["hiddenactualyear"].value;
	document.Form1.submit();			
}	
function ResetDivs()
{
	document.all["txtSearch"].value = "";
	document.all["divCalendar"].style.display = '';	
}
function showNext()
{
	document.all["hiddendirection"].value = "F";
	if(document.all["hiddenview"].value == "W")
	{
	//	ResetDivs();				
	document.all["divCalendar"].style.display = '';	
	
		if(document.all["currentweek"].value == "")
		{
			currentWeek = 1;
		}
		else
		{
			currentWeek = parseFloat(document.all["currentweek"].value);						
		}
		var nextWeek = currentWeek + 1;

		document.all["divweek" + currentWeek + "s"].style.display = 'none';

		if(document.all["divweek" + nextWeek + "s"])
		{
			document.all["divweek" + nextWeek + "s"].style.display = '';
			document.all["currentweek"].value = nextWeek;					
		}
		else
		{
			showNextMonth();
		}
	}
	else
	{			
		showNextMonth();
	}
}
function showNextMonth()
{
	//ResetDivs();
	document.all["divCalendar"].style.display = '';	
	//if (parseFloat(document.all["hiddencurrentmonth"].value) == 12)
	if (parseFloat(document.all["ddmonth"].value) == 12)				
	{
		newMonth = 1;
		//newYear = parseFloat(document.all["hiddencurrentyear"].value) + 1;
		newYear = parseFloat(document.all["ddyear"].value) + 1;
	}
	else
	{
		//newMonth = parseFloat(document.all["hiddencurrentmonth"].value) + 1;
		//newYear = parseFloat(document.all["hiddencurrentyear"].value);
		newMonth = parseFloat(document.all["ddmonth"].value) + 1;
		newYear = parseFloat(document.all["ddyear"].value);
	}
	document.all["ddmonth"].value =	newMonth;
	document.all["hiddencurrentmonth"].value = newMonth;
	document.all["ddyear"].value = newYear;
	document.all["hiddencurrentyear"].value = newYear;
	document.Form1.submit();	
}			

function showPrevious()
{
	document.all["hiddendirection"].value = "B";
	if(document.all["hiddenview"].value == "W")
	{
		//ResetDivs();				
		document.all["divCalendar"].style.display = '';	
		if(document.all["currentweek"].value == "")
		{
			currentWeek = 1;
		}else{
			currentWeek = parseFloat(document.all["currentweek"].value);						
		}
		var nextWeek = currentWeek - 1;
		document.all["divweek" + currentWeek + "s"].style.display = 'none';
		if(document.all["divweek" + nextWeek + "s"])
		{		
			document.all["divweek" + nextWeek + "s"].style.display = '';
			document.all["currentweek"].value = nextWeek;				
		}
		else
		{
			showPreviousMonth();
		}
	}
	else
	{			
		showPreviousMonth();
	}			
}	
function showPreviousMonth()
{
	//ResetDivs();			
	document.all["divCalendar"].style.display = '';	
	//if (parseFloat(document.all["hiddencurrentmonth"].value) == 1)
	if (parseFloat(document.all["ddmonth"].value) == 1)
	{
		newMonth = 11;
		//newYear = parseFloat(document.all["hiddencurrentyear"].value) - 1;
		newYear = parseFloat(document.all["ddyear"].value) - 1;
	}
	else
	{
		//newMonth = parseFloat(document.all["hiddencurrentmonth"].value) - 1;
		//newYear = parseFloat(document.all["hiddencurrentyear"].value);
		newMonth = parseFloat(document.all["ddmonth"].value) - 1;
		newYear = parseFloat(document.all["ddyear"].value);					
	}
	document.all["ddmonth"].value =	newMonth;
	document.all["hiddencurrentmonth"].value = newMonth;
	document.all["ddyear"].value = newYear;
	document.all["hiddencurrentyear"].value = newYear;
	document.Form1.submit();
}			
			
function monthChanged()
{
	document.all["hiddendirection"].value = "";
}		
function showCategory()
{
	document.all["hiddencategory"].value = "Y";
	if(document.all["ddCategory"].value == "Select a Category")
	{
		document.all["hiddencategory"].value = "N";
	}
	document.Form1.submit();
}	
function changeCategory()
{
	if(document.all["hiddencategoryvalue"].value != "")
	{
		var selcat = document.all("ddCategory"); 
		for (var i = 0; i < selcat.options.length; i++) { 
			if (selcat.options[i].text == document.all["hiddencategoryvalue"].value)
			{				
				selcat.options[i].selectedIndex = selcat.options[i].value;
				selcat.options[i].selected = true;
				break;
			}
		}			
	}
}		
function changer(from,to) 
{
	if(document.images) 
	{
		document.images[from].src = pics[to].src;
	}
}
function showPolicy()
{
	window.open("policy.htm","policy","top=0,left=0,width=680,height=600,resizable=yes,scrollbars=yes,status=yes");	
}
function showHelp()
{
	window.open("help.htm","","top=0,left=0,width=680,height=600,resizable=yes,scrollbars=yes,status=yes");	
}
