﻿var sSelectedColour = "";
var sOldColour = "";
var currentObj = "";
var eventID = "";

function InitCal(e)
{
	if (document.getElementById("Select_Colour") != null)
	{
		sSelectedColour = document.getElementById("Select_Colour").value;
	}
}

function CalndarMouseOver(e)
{
	setCalObject(e);
   if (isCalObject(e)){
		sOldColour = currentObj.style.backgroundColor;
		currentObj.style.backgroundColor = sSelectedColour
   }
}

function CalndarMouseOut(e)
{
	if (isCalObject(e)){
		currentObj.style.backgroundColor = sOldColour
	}
}

function setCalObject(e)
{
	currentObj = getSrcObj(e);
	eventID = "";
	if ((currentObj.getAttribute("event") != null) && (currentObj.getAttribute("event") != ""))
	{
		eventID = currentObj.getAttribute("event");
	}
	for (i=0; i < 5; i++){
		if (currentObj.getAttribute("day") == null){
			currentObj = currentObj.parentElement;
		}
		else 
		{
			i = 10;
		}
   }
   if (currentObj.getAttribute("day") == null)
   {
		currentObj = null;
   }
}

function isCalObject(e)
{
   return((currentObj != null) && (currentObj.id != null) && (currentObj.id != ""));
}

function getEvent_ID(e)
{
	return eventID;
}

function getGet_Day(e)
{
   var sDay = "";
	if (isCalObject(e)){
		sDay = currentObj.getAttribute("day");
	}
	return sDay;
}

function isEvent(e)
{
	if (eventID == ""){
		return false;
	}
	else {
		return true;
	}
}

function Set_Colour(e)
{
	document.getElementById("tbColour").value = getSrcObj(e).title;
}

function Calendar_Click(e)
{
	if (isEvent(e))
	{
		 window.open("Event_Detail.php?ID=" + getEvent_ID(e));
	}
}

function Grid_Click(e)
{
	if (getSrcObj(e).parentElement.parentElement.getAttribute("ID") != "")
	{
		window.open("Even_Detail.php?ID=" + getSrcObj(e).parentElement.parentElement.getAttribute("ID"));
	}
}

addCustomEvent(window, "load", InitCal);