
//====global====//
document.body.onscroll = function() {setCurrentScroll()};
document.body.onload = function(){moveScroll()};

function setCurrentScroll()
{
	var txtBoxScrollTop = document.getElementById("ctl00$ctl01$ctl00$txtBoxScrollTop");
	if(txtBoxScrollTop != null)
	{
		txtBoxScrollTop.value = document.documentElement.scrollTop;
	}
	else
	{
		window.status = "cannot find txtBoxScrollTop object 1";
	}
}

function moveScroll()
{
	var txtBoxScrollTop = document.getElementById("ctl00$ctl01$ctl00$txtBoxScrollTop");
	if(txtBoxScrollTop != null)
	{
		window.scrollTo(0, txtBoxScrollTop.value);
	}
	else
	{
		window.status = "cannot find txtBoxScrollTop object 2";
	}
}

function doIt(s)
{
    var adiv = document.getElementById("adiv");
    adiv.innerHTML = s;
}

function rolesopen (e)
{
    if (!e) e = window.event;
    doIt("type (x, y) = " + e.type + " (" + e.clientX + ", " + e.clientY + ")");
}

function rolesclose()
{
    doIt("");
}

//===== event calendar =====/
function showEventDetail(e, id)
{
    if (window.event)
    { //IE compliant
	    x= window.event.clientX;
	    y= window.event.clientY + document.documentElement.scrollTop;
    }
    else
    { //Firefox
	    x= e.clientX;
	    y= e.clientY + document.documentElement.scrollTop;
    }

	var container = document.getElementById("toolTip_eventDetail");
	if(container != null)
	{
		var eventsTable = document.getElementById("dtl_" + id);
		if(eventsTable != null)
		{
			//container.innerHTML = "<div><span style=\"font-weight:bold;color:#006666;font-family:Arial;font-size:16px;background-color:white\">Events</span></div>";
			container.innerHTML = eventsTable.innerHTML;
		}
		else
		{
			container.innerHTML = '<div style="background-color:#ffffcc">There is no event assigned to this date</div>';
		}
		container.style.display = "inline";
		//container.style.border = "solid 1px black";
		container.style.pixelTop = y+5;
		container.style.pixelLeft = x+5;
	}
	else
	{
		alert("Unable to Dispay Event Detail");
	}
	document.body.onclick = function () {hideDetail(e)};
}

function hideDetail(e)
{
    var e = e || window.event; // event object
    var target = e.target || window.event.srcElement; // event target
    var targetID = target.id.lastIndexOf("d_"); // event target id
 
    if(targetID < 0)
    {
	    var container = document.getElementById("toolTip_eventDetail");
	    if(container != null && container.style.display != "none")
	    {
		    container.style.display = "none";
	    }
    }
}

function redirect(target)
{
   window.location.href  = target;
   return false;
}

//=========Editing Layers ===============//

//this global variable is used for Color panel tooltip
var g_srcId = "";
function showColorPanel(obj)
{
    if (window.event)
    { //IE compliant
	    x= window.event.clientX;
	    y= window.event.clientY + document.documentElement.scrollTop;
    }
    else
    { //Firefox
	    x= e.clientX;
	    y= e.clientY + document.documentElement.scrollTop;
    }


	var container = document.getElementById("ColorPanel");
	if(container != null)
	{
		container.style.display = "inline";
		container.style.border = "solid 1px black";
		container.style.pixelTop = y+5;
		container.style.pixelLeft = x+5;
	}
	else
	{
		alert("Unable to Dispay Event Detail");
	}
	
	g_srcId = obj.id;
	document.body.onclick = function () {hideColorPanelBody()};

}

function hideColorPanelBody()
{
	if(event.srcElement.id.lastIndexOf(g_srcId) < 0)
	{
		var container = document.getElementById("ColorPanel");
		if(container != null && container.style.display != "none")
		{
			container.style.display = "none";
		}
	}
	//document.body.onclick = function() {g_srcId = ""};
}

function hideColorPanel(objId)
{
	document.getElementById(objId).style.display = "none";
}

//called from each color span.
function selectColor(target, thisObj)
{
	var targetObj = document.getElementById(g_srcId);
	if(targetObj != null)
	{
		targetObj.style.backgroundColor = thisObj.style.backgroundColor;
		targetObj.value = thisObj.style.backgroundColor;

	}
	else
	{
		alert("Cannot find text box");
	}
	
}

function confirmDeleteLayer()
{
	if (confirm("It will delete all events under this Layer. Are you sure you want to delete this Layer?")==true)
		return true;
	else
		return false;
}

function confirmDeleteEvent()
{
	if (confirm("Are you sure you want to delete this Event Item?")==true)
		return true;
	else
		return false;
}
//=============== Editing Events =====================//
function getCoordinate()
{
	var x = document.getElementById("_ctl0__ctl1__ctl0_lblX");
	var y = document.getElementById("_ctl0__ctl1__ctl0_lblY");
	
    if (window.event)
    { //IE compliant
	    x.value= window.event.clientX + 20;
	    y.value= window.event.clientY + document.documentElement.scrollTop;
    }
    else
    { //Firefox
	    x.value= e.clientX + 20;
	    y.value= e.clientY + document.documentElement.scrollTop;
    }
	
	//alert(x.innerHTML + ":" + y.innerHTML);
}

function checkTime(obj)
{
	var t = obj.value;
	//check format of the time string.
	//It h and min must be seperated by ':'
	if( t.length > 0)
	{
		var isTime = false;
		if(t.length < 6 || t.lastIndexOf(":") != -1)
		{
				var ta = t.split(":");
				
				//check there is h and min
				if(ta.length == 2)
				{
					//check if h and min are numeric
					if(!isNaN(ta[0]) && !isNaN(ta[1]))
					{
						//check range of h
						if(ta[0] < 24)
						{	
							//check range of min
							if(ta[1] < 60)
							{
								//format h to two digit
								if(ta[0].length == 1)
								{
									ta[0] = "0" + ta[0];
								}
								//format min to two digit
								if(ta[1].length == 1)
								{
									ta[1] = "0" + ta[1];
								}	
								
								obj.value = ta[0] + ":" + ta[1];								
								isTime = true;
							}
							else
							{
								alert("minutes must be between 0 and 59");
							}
						}
						else
						{
							alert("hour must be between 0 and 24");
						}
					}
					else		
					{
						alert("Numeric only for time");
					}
				}
				else
				{
					alert("Invalid format of time. Valid format is HH:MM");
				}
		}
		else
		{
			alert("Invalid format of time. Valid format is HH:MM");
		}
		
		if(!isTime)
		{
			obj.value = "";
			obj.focus();
		}
	}
}
	