﻿window.onload = StartJS;
var xmlHttp;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {xmlHttp=new XMLHttpRequest();}
catch (e)
  {
  try
    {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e)
    {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
  }
return xmlHttp;
}

var Campus = "";
var EventCat = "";

function ClearThis(obj){if(obj.value=="Search our Site"){obj.value="";}}

function StartJS()
{
    CampusEvents();
    if((Campus!="") || (EventCat!=""))
    {
        //document.getElementById('divCampusEvents').innerHTML="Gathering events...";
        GetEvents();
    }
}
function CampusEvents()
{
    var url=location.toString();
    url=url.toLowerCase();

    if(url.indexOf("/cyfair")>0 || url.indexOf("cyfair.lonestar.edu")>0){Campus="LSC-CyFair";}
    if(url.indexOf("/kingwood")>0 || url.indexOf("kingwood.lonestar.edu")>0){Campus="LSC-Kingwood";}
    if(url.indexOf("/montgomery")>0 || url.indexOf("montgomery.lonestar.edu")>0){Campus="LSC-Montgomery";}
    if(url.indexOf("/northharris")>0 || url.indexOf("northharris.lonestar.edu")>0){Campus="LSC-North Harris";}
    if(url.indexOf("/tomball")>0 || url.indexOf("tomball.lonestar.edu")>0){Campus="LSC-Tomball";}
    if(url.indexOf("/lsconline")>0 || url.indexOf("online.lonestar.edu")>0){Campus="LSC-Online";}
    if(url.indexOf("/universitycenter")>0 || url.indexOf("university.lonestar.edu")>0){Campus="LSC-University";}
    if(url.indexOf("library")>0){EventCat="Library";}
}
function GetEvents()
{
    var aspurl;

    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){alert ("Your browser does not support AJAX!");return;} 
    aspurl="/eventcalcampus.asp?campus="+Campus+"&eventcat="+EventCat;;
    xmlHttp.onreadystatechange=GetEventsReturn;
    xmlHttp.open("GET",aspurl,true);
    xmlHttp.send(null);   
}
function GetEventsReturn() 
{ 
    if (xmlHttp.readyState==4)
    {
    document.getElementById('divCampusEvents').innerHTML=xmlHttp.responseText;
    }
}
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX;
var tempY;
function CampusEventDetails(id,obj)
{ 
    var div=document.getElementById('divEventDetails');
	if (IE)
	{div.style.top = ((Top(obj))-280)+"px";}
	else
	{div.style.top=(tempY-280)+"px";}   
	div.style.left=(tempX-1100)+"px";
	div.style.display="block";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){alert ("Your browser does not support AJAX!");return;} 
	
	var url="/eventcaldetails.asp?id="+id;
    xmlHttp.onreadystatechange=stateChangedEventDetails;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
    
}

function stateChangedEventDetails() 
{ 
    if (xmlHttp.readyState==4)
    {
    var xmlDoc=xmlHttp.responseXML.documentElement;
    try
    {
    var details=xmlDoc.getElementsByTagName("details")[0].childNodes[0].nodeValue;
    var detailstemp=escape(details);
    detailstemp=detailstemp.replace(/%0A/g,"<br />");
    document.getElementById('divDetails').innerHTML=unescape(detailstemp);//details;
    }
    catch (err)
    {
    document.getElementById('divDetails').innerHTML="";
    }
    try
    {
        var weblink=xmlDoc.getElementsByTagName("weblink")[0].childNodes[0].nodeValue;
        if(weblink.length>1){
    	if(weblink.indexOf("http://")<0)
	    {weblink="http://"+weblink}
        document.getElementById('divWeblink').innerHTML="<a href='"+weblink+"' target='_blank'>"+weblink+"</a>";}
    }
    catch (err)
    {document.getElementById('divWeblink').innerHTML="";}
    }
}
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}
function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function Hide(obj)
{
    document.getElementById(obj).style.display="none";
}