
var EnabledCount = 0;
var FormToggle = true;

function ToggleColor(ele, button1, button2)
	{
		var trows = document.getElementById("tr" + ele);
		var tcheck = document.getElementById("ck" + ele);
	
		if (tcheck.checked == true)
		{
			if (trows.getAttribute("active") == 0)
			{
				trows.style.backgroundColor = "red";
			} else {
				trows.style.backgroundColor = "96B3CF";
			}
			EnabledCount++;
			button1.disabled=false;
			if (button2)
			{
			button2.disabled=false;
			}
		}
		else
		{
			if (trows.getAttribute("active") == 0)
			{	trows.style.backgroundColor = "FFCCCC";
			} else {
			trows.style.backgroundColor = "D6D7D6";
			}
			EnabledCount--;
			if (EnabledCount == 0)
			{
				button1.disabled=true;
				if (button2)
				{
				button2.disabled=true;
				}				
			}
		}
	}
	
	function displayBody(ele)
	{
		if (ele.style.display == 'none')
		{
			ele.style.display = 'inline';
		}
		else
		{
			ele.style.display = 'none';
		}
	}
	
	function displayCalendars(eleShow, eleHide, newDate)
	{
		eleHide.style.display='none';
		//eleShow.value = newDate;
		displayBody(eleShow);
	}

	function toggleTimes(ele,ele2)
	{
		if (ele.style.display == 'none')
		{
			ele.style.display = 'inline';
			ele2.style.display = 'inline';
		}
		else		
		{
			ele.style.display = 'none';
			ele2.style.display = 'none';
		}
	}

	 function CalDoneButton(objInputBox, objOtherBox, mode, date, objElement, objStartTime, objEndTime)
	 {
		myDate = new Date(date);
		dayOfWeek = DayOfWeek(myDate);
		objInputBox.value = date;
		objElement.style.display = 'none';
		
		if (mode == "start")
		{
			if (Date.parse(objInputBox.value) > Date.parse(objOtherBox.value))
			{
				objOtherBox.value = objInputBox.value;
				verifyTimeButton(objStartTime, objEndTime, objInputBox, objOtherBox);
				objInputBox.focus();
			}
		}
		else
		{
			if (Date.parse(objInputBox.value) < Date.parse(objOtherBox.value))
			{
				alert("Start Date cannot be after End Date");
				objInputBox.value = objOtherBox.value;
				verifyTimeButton(objStartTime, objEndTime, objOtherBox, objInputBox);
				objInputBox.focus();
			}
		}
		
		verifyTimeButton(objStartTime, objEndTime, objOtherBox, objInputBox);
		
	 }
	 
	 function verifyTimeButton(objStartTime, objEndTime, objStartDate, objEndDate)
	 {
		if (Date.parse(objStartDate.value) == Date.parse(objEndDate.value))
		{
			if (objStartTime.selectedIndex >= objEndTime.selectedIndex)
			{
				objEndTime.selectedIndex = (objStartTime.selectedIndex + 1);
			}
		}
	 }
	 
	 function verifyEndButton(objEnd, objStart, objStartTime, objEndTime)
	 {
	 	if ((Date.parse(objEnd.value) < Date.parse(objStart.value)) || (objEnd.value == "") || (objStart.value == ""))
		{
			if (objStart.value == "")
			{
				alert("Start Date is a required field.");
				objStart.value = objEnd.value;
				verifyTimeButton(objStartTime, objEndTime, objStart, objEnd);
				objStart.focus();
			}
			else
			{
				if (objEnd.value == "")
				{
				alert("End Date is a required field.");
				}
				else
				{
				alert("Start Date cannot be after the End Date");
				}
				objEnd.value = objStart.value;
				verifyTimeButton(objStartTime, objEndTime, objStart, objEnd);
				objEnd.focus();
			}
		}
		
		verifyTimeButton(objStartTime, objEndTime, objStart, objEnd);
	 }
	 
	 function DayOfWeek(dateObj)
	 {
	 	switch ( dateObj.getDay() )
		{
			case 0 :
				return 'Sun';
				break;
			case 1 :
				return 'Mon';
				break;
			case 2 :
				return 'Tue';
				break;
			case 3 :
				return 'Wed';
				break;
			case 4 :
				return 'Thu';
				break;
			case 5 :
				return 'Fri';
				break;
			case 6 :
				return 'Sat';
				break;
								
		
		}
	 }
	 
	function verifyNewEvent(formname)
	{
		var oFrm = document.getElementById(formname);

		if (oFrm.Title.value == "")
		{
			alert("Event Title is a required field");
			oFrm.Title.focus();
			return false;
		}

		if (oFrm.ShortCalendarTitle.value == "")
		{
			alert("Short Title is required to maintain the monthly calendar");
			oFrm.ShortCalendarTitle.focus();
			return false;
		}
		
		if (oFrm.FileUpload.value != "")
		{
			return verifyFileType('newEvent');
		}
		
		return true;
	
	}

function loadEditor(URL,iFrame1,iFrame2)
	 {
		var oFrame1 = document.getElementById(iFrame1);
		var oFrame2 = document.getElementById(iFrame2);
		var oFrameSection = document.getElementById('frameSection');
		var oFrameCall = document.getElementById("frameToggle");		
		
		oFrameSection.style.display = 'block';
		oFrameCall.innerHTML = 'Close Form';		
		oFrame1.style.visibility = 'hidden';
		oFrame1.style.display = 'none';
		oFrame2.style.visibility = 'visible';
		oFrame2.style.display = 'block';
		oFrame2.contentWindow.location = URL;
	 }

function reloadAddiFrame()
	 {  
	 	var oFrame1 = document.getElementById("add_iFrame");
		var oFrame2 = document.getElementById("edit_iFrame");
		var oFrameSection = document.getElementById("frameSection");
		var oFrameCall = document.getElementById("frameToggle");
	
		if (oFrameSection.style.display == 'none')
		{
			oFrameSection.style.display = 'block';
			oFrameCall.innerHTML = 'Close Form';
			oFrame1.style.visibility = 'visible';
			oFrame1.style.display = 'inline';
			oFrame2.style.visibility = 'hidden';
			oFrame2.style.display = 'none';
		} else
		{
			oFrameSection.style.display = 'none';
			oFrameCall.innerHTML = 'Add New File';
			oFrame1.style.visibility = 'visible';
			oFrame1.style.display = 'inline';
			oFrame2.style.visibility = 'hidden';
			oFrame2.style.display = 'none';	
			oFrame1.src = oFrame1.src;
		}
	 }

function resetButtons(button1,button2)
	{
		button1 = document.getElementById(button1);
		button1.disabled = true;
		
		if (button2)
		{
			button2 = document.getElementById(button2);
			button2.disabled = true;
		}

		EnabledCount = 0;
	}
	
function confirmDelete() {
	if (confirm("Are you sure you would like to delete the selected calendar entry/entries? Press OK to confirm your request.")) {
		return true;
	} else {
		return false;
	}	
	}
	







