hPosition = 0;
canScroll = true;

addLoadListener(loadPrograms);
addLoadListener(hideDivsOnMouseOverOrClick);


function addLoadListener(fn)
{
  if(typeof window.addEventListener !='undefined')
  {
    window.addEventListener('load',fn,false);
  }
  else if(typeof document.addEventListener !='undefined')
  {
    document.addEventListener('load',fn,false);
  }
  else if(typeof window.attachEvent !='undefined')    
  {
    window.attachEvent('onload',fn);
  }
  else
  {
    var oldfn=window.onload
    if(typeof window.onload !='function')
	{
	  window.onload=fn;
	}
    else
	{
      window.onload=function(){oldfn();fn();}
    }
  }
} 


function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    curleft = obj.offsetLeft;
	curtop = obj.offsetTop;
	while (obj = obj.offsetParent)
	{
	  curleft += obj.offsetLeft;
	  curtop += obj.offsetTop;
	}
  }
  return [curleft,curtop];
}


function openWindow(URL, title, features)
{
  window.open(URL, title, features);
}


function hideDivsOnMouseOverOrClick()
{
	document.onmouseover = hideFloatingDivs;
	document.onclick = hideFloatingDivs;
}

function hideFloatingDivs()
{
	hideDailyPrograms();
}


function none()
{
}


function hScrollLogos(minHPosition)
{
  if (canScroll){
	  hPosition -= 2;
	  if (hPosition < minHPosition) hPosition = 0;
	  document.getElementById('logoContainer').style.left = hPosition + 'px';
  }
}


function loadPrograms(date)
{ 
  if (document.getElementById('programs') == null){
	  return;
  }
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', '/includes/ajax/loadprograms.php?date=' + date, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('programs').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true; 
}


function loadDailyPrograms(date, requesterObj)
{
  var xhr;
  try 
  {
	  xhr = new XMLHttpRequest();
  } catch (error)
  {
	try
	{
		  xhr = new ActiveXObject('Microsoft.XMLHTTP');
	} catch (error)
	{
		  xhr = null;
	}
  }

  if (xhr != null)
  {
	  xhr.open('GET', '/includes/ajax/loaddailyprograms.php?date=' + date, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('dailyPrograms').innerHTML = xhr.responseText;
				  position = findPos(document.getElementById(requesterObj));
				  document.getElementById('dailyPrograms').style.top = position[1] + "px";
				  document.getElementById('dailyPrograms').style.left = (position[0] + 20) + "px";
				  document.getElementById('dailyPrograms').style.visibility = 'visible';
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true; 
}

function hideDailyPrograms()
{
	if (document.getElementById('dailyPrograms'))
	{
		document.getElementById('dailyPrograms').style.visibility='hidden';
	}
}