addLoadListener(loadPrograms);

function openWindow(URL, title, features){
  window.open(URL, title, features);
}

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 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 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';
	}
}

function loadNewsSummary(id, 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/loadnewssummary.php?id=' + id, true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('floatingNewsSummary').innerHTML = xhr.responseText;
				  position = findPos(document.getElementById(requesterObj));
				  document.getElementById('floatingNewsSummary').style.top = (position[1] + 16) + "px";
				  document.getElementById('floatingNewsSummary').style.left = position[0] + "px";
				  document.getElementById('floatingNewsSummary').style.visibility = 'visible';
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  return true; 
}



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 none()
{
}



function loadNMDTV()
{
  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/loadnmdtv.php', true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('pictureGalleries').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  document.getElementById('bigLeft').innerHTML = '<a href="javascript: none();"><img src="/images/bigleft.jpg" onClick="loadNMDParty();" /></a>';
  document.getElementById('bigRight').innerHTML = '<a href="javascript: none();"><img src="/images/bigright.jpg" onClick="loadNMDPic();" /></a>';
  return true; 
}



function loadNMDPic()
{
  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/loadnmdpic.php', true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('pictureGalleries').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  document.getElementById('bigLeft').innerHTML = '<a href="javascript: none();"><img src="/images/bigleft.jpg" onClick="loadNMDTV();" /></a>';
  document.getElementById('bigRight').innerHTML = '<a href="javascript: none();"><img src="/images/bigright.jpg" onClick="loadNMDParty();" /></a>';
  return true; 
}


function loadNMDParty()
{
  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/loadnmdparty.php', true);
	  
	  xhr.onreadystatechange = function()
	  {
		  if (xhr.readyState == 4)
		  {
			  if (xhr.status == 200 || xhr.status == 304)
			  {
				  document.getElementById('pictureGalleries').innerHTML = xhr.responseText;
			  }else
			  {
			  }
		  }
	  };

      xhr.send(null);
  }
  document.getElementById('bigLeft').innerHTML = '<a href="javascript: none();"><img src="/images/bigleft.jpg" onClick="loadNMDPic();" /></a>';
  document.getElementById('bigRight').innerHTML = '<a href="javascript: none();"><img src="/images/bigright.jpg" onClick="loadNMDTV();" /></a>';
  return true; 
}
