function showOrHide(eId, thisImg, state) {
  if (e = document.getElementById(eId)) {
      if (state == null) {
	      state = e.style.display == 'none';
	      e.style.display = (state ? '' : 'none');
      }

      var myItm = document.getElementById('li_' + eId);
      if (myItm != null){
	        myItm.className = 'current';      
      }
      
      //...except for this, probably a better way of doing this, but it works at any rate...
      var myImg = document.getElementById(thisImg);
      if (myImg != null){
          if (state == true){				
	          myImg.src="images/collapse.jpg";
          }
          if (state == false){
	          myImg.src="images/expand.jpg";
          }
      }
   
      
  }
}

//opens a window and centers it
function openWin(sPage,w,h,scrollbars,status,resize,percentage){
/*
	var fullHeight = screen.width; //getViewportHeight();
	var fullWidth = screen.height; //getViewportWidth();

	if (percentage != null){
		h = fullHeight*percentage;
		w = fullWidth*percentage;
	}
	
	var winL = (fullWidth - w) / 2;
	var winT = (fullHeight - h) / 2;
*/
			var winL = (screen.width - w) / 2;
		var winT = (screen.height - h) / 2;

//alert(fullWidth);
	
	var myWin = window.open(sPage,'','height=' + h + ',width=' + w + ',left=' + winL + ',top=' + winT + ',status=' + status + ',scrollbars=' + scrollbars + ',resizable=' + resize);
	
	return myWin;
}

function setFocus2(ctl_name){
    var o = getElementById(ctl_name);
    if (o != null){
        o.focus();
    }
    
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

function AllowOnly(Expression)
{
        Expression = Expression.toLowerCase();
        Expression = Replace(Expression, 'a..html', 'abcdefghijklmnopqrstuvwxyz');
        Expression = Replace(Expression, '0..9', '0123456789');
        Expression = Replace(Expression, '|', '');

        var ch = String.fromCharCode(window.event.keyCode);
        ch = ch.toLowerCase();
        Expression = Expression.toLowerCase();
        var a = Expression.indexOf(ch);
        if (a == -1)
                window.event.keyCode = 0;
}

function Replace(Expression, Find, Replace)
{
        var temp = Expression;
        var a = 0;

        for (var i = 0; i < Expression.length; i++)
        {
                a = temp.indexOf(Find);
                if (a == -1)
                        break
                else
                        temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
        }

        return temp;
}

function IsDate(dateStr)
{
        // Checks for the following valid date formats:
        // MM/DD/YYYY   MM-DD-YYYY

        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

        var matchArray = dateStr.match(datePat)
        if (matchArray == null)
                return false

        month = matchArray[1]
        day = matchArray[3]
        year = matchArray[4]
        if (month < 1 || month > 12)
                return false

        if (day < 1 || day > 31)
                return false

        if ((month==4 || month==6 || month==9 || month==11) && day==31)
                return false

        if (month == 2)
        {
                var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
                if (day>29 || (day==29 && !isleap))
                        return false;
        }
        return true;
}


