function isIE()
{
  var detect = navigator.userAgent.toLowerCase();
  var place = detect.indexOf('msie') + 1;
  return place;
}

function isLeapYear(year)
{
  return ( ((year)>0) && !((year)%4) && ( ((year)%100) || !((year)%400) ) );
}
  
function monthDays(month,year)
{
  month = parseInt(month);
  year = parseInt(year);
  switch(month)
  {
    case 1: return 31;
    case 2: 
      if(year == 0 || isLeapYear(year)) 
        return 29; 
      else 
        return 28;
      break;
    case 3: return 31;
    case 4: return 30;
    case 5: return 31;
    case 6: return 30;
    case 7: return 31;
    case 8: return 31;
    case 9: return 30;
    case 10: return 31;
    case 11: return 30;
    case 12: return 31;
    default: return 31;
  }
}

function submitenter(myfield,e)
{
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  
  if (keycode == 13)
  {
   myfield.form.submit();
   return false;
  }
  else return true;
}

function isValidFloat(nmr)
{
	var reg = new RegExp("^[0-9]+(\.[0-9]+)?$");
	return reg.test(nmr);
}

function isValidInt(nmr)
{
	var reg = new RegExp("^[0-9]+$");
	return reg.test(nmr);
}

function isValidIdentifier(ident, minlength)
{
  var reg = new RegExp("^[A-Za-z0-9_\-]{" + minlength.toString() + ",}$");
  return reg.test(ident);
}

function isValidEntityName(entityname)
{
  var reg = new RegExp("^[A-Za-z0-9_\-]{2,}(\.[A-Za-z0-9_\-]{2,})*$");
  return reg.test(entityname);
}
function getViewPortHeight()
{
  if (typeof window.innerWidth != 'undefined') // Mozilla
  {
    return window.innerHeight;
  }
  else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth !=
      'undefined' && document.documentElement.clientWidth != 0) // IE Standards compliant
  {
    return document.documentElement.clientHeight;
  }
  else // Old IE
  {
    return document.getElementsByTagName('body')[0].clientHeight;
  }  
}

function prepareIE(height, overflow)
{
  bod = document.getElementsByTagName('body')[0];
  bod.style.height = height;
  bod.style.overflow = overflow;
  
  htm = document.getElementsByTagName('html')[0];
  htm.style.height = height;
  htm.style.overflow = overflow; 
}
	
function toggleSelects(visibility)
{
	return;
  selects = document.getElementsByTagName('select');
  for(i = 0; i < selects.length; i++) 
  {
  	selects[i].style.visibility = visibility;
  }
}

function shade()
{
	if(isIE())
	{
    prepareIE('100%', 'hidden');
	  toggleSelects("hidden");
	  $('shader').style.top = document.body.scrollTop + "px";
	}
	
  $('shader').setStyle({ opacity: 0.50 });
  $('shader').style.display = "block";
  $('lightbox').style.display = "block";
}

function unshade()
{
	if(isIE())
	{
		prepareIE("auto","auto");
		toggleSelects("visible");
    $('shader').hide();
    $('lightbox').hide();
	}
	else
	{
		$('lightbox').hide();
		Effect.Fade($('shader'), { duration: 0.4 });  
	}
}

function centerWindow(id)
{
  var wnd = $(id);
  var viewheight = getViewPortHeight();
  var winheight = wnd.offsetHeight;
  var newtop = (viewheight - winheight)/2;
  if(isIE())
  {
  	newtop += document.body.scrollTop;
  }
  wnd.style.top = newtop.toString() + "px";
}

function openWindow(id)
{
  shade();
  var window = $(id);
  window = window.remove();
  $('lightbox').appendChild(window);
  window.show();
  new Draggable(window, { revert: false, handle: "window-caption" });
  window.setStyle({ opacity: 1.00 });
  centerWindow(id);
}

function closeWindow(id)
{
	var window = $(id);
  window.hide();
  unshade();
}

function showSuccess(txt)
{
  var success = $('success');
	success.innerHTML = txt;
	success.show();
	new PeriodicalExecuter(function(pe) {
    pe.stop();
    Effect.Fade(success);
	}, 8);
}

/*
 *  Global responders for Ajax events.
 *  OnCreate   - an Ajax request was initiated. Show the throbbing loader.
 *  OnComplete - an Ajax request was completed. Hide the throbbing loader 
 *               (but only when there are no more active requests).
 *
 */
var globalResponders = 
{
  onCreate: function()
  {
    //Element.show('loader');
  },
  onComplete: function() 
  {
    if(Ajax.activeRequestCount == 0)
    {
      //Element.hide('loader');
    }
  }
};
Ajax.Responders.register(globalResponders);



