// Licensed to Look and Learn Magazine Ltd
// Copyright Edward Leigh (2006-2008)
// Last modified: 4 January 2008

function getElement(id)
{
  if (document.getElementById)
  {
	  return document.getElementById(id);
  }
  else if (document.layers)
	{
	  return document.layers[id];
  }
  else if (document.all)
  {
    return document.all[id];
  }
  else
  {
	  return document[id];
  }
}

function getFormElement(form, name)
{
	return document.forms[form][name];
}

function getStrValue(id, defaultValue)
{
	var ob = getElement(id);
	var val = ob ? ob.value : defaultValue;
	return val == null ? '' : val;
}

function getIntValue(id, defaultValue)
{
	var val = parseInt(getStrValue(id, defaultValue));
	return isNaN(val) ? 0 : val;
}


function getSelectedValue(theSelect)
{
  if (theSelect.selectedIndex < 0)
    return null;
  return theSelect.options[theSelect.selectedIndex].value;
}

function getSelectedOptionText(theSelect)
{
  if (theSelect.selectedIndex < 0)
    return null;
  return theSelect.options[theSelect.selectedIndex].text;
}

function getNewHttpObject()
{
	var xmlhttp;
	
	/** Special IE only code ... */
	/*@cc_on
	  @if (@_jscript_version >= 5)
	      try
	      {
	          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	      }
	      catch (e)
	      {
	          try
	          {
	              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	          }
	          catch (E)
	          {
	              xmlhttp = false;
	          }
	     }
	  @else
	     xmlhttp = false;
	@end @*/
	
	/** Every other browser on the planet */
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
	    try
	    {
	        xmlhttp = new XMLHttpRequest();
	    }
	    catch (e)
	    {
	        xmlhttp = false;
	    }
	}
	
	return xmlhttp;
}

function getShortDate()
{
  month = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
  today = new Date();
  return today.getUTCDate() + ' ' + month[today.getUTCMonth()] + ' ' + today.getUTCFullYear();
}

function checkAll(prefix, state)
{
  var checkbox;
  var i;
 
  for (i = 0; i < 100; i++)
  {
    checkbox = document.getElementById(prefix + i);
    if (checkbox == null) break;
    checkbox.checked = state;
  }
}

function getImageDirectory(imageName)
{
	var re = /^(Z[0-9A-Z]{4})-(\d{3})(\d{3})/;
	var matches = imageName.match(re);
	if (matches && matches.length == 4)
		return 'Z/' + matches[1] + '/' + matches[1] + '-' + matches[2] + '/' + matches[1] + '-' + matches[2] + matches[3];
 	
 	re = /^(X?[A-Y])(\d{3})/;
 	matches = imageName.match(re);
	if (matches && matches.length == 3)
		return matches[1] + '/' + matches[1] + matches[2]
 	
 	re = /^([A-Y]+)(\d+)-/;
 	matches = imageName.match(re);
	if (matches && matches.length == 3)
		return matches[1] + '/' + matches[1] + matches[2]
 	
  return '';
}


$(document).ready(function()
{
	var message = getElement('smartid-message');
	if (!message) return;
	
	$(message).effect("highlight", { color: "#FBEE2B" }, 2000);
});


