<!--// hide from old browsers

// Show and Hide Object
function showHide(ObjectID) {
	 objElement = $(ObjectID);
	 if (objElement.style.display == 'none')	{
		  objElement.style.display = 'block';
	 } else {
		  objElement.style.display = 'none';
	 }
}

// Swap Image
function swapImage( imgRef, imgSrc ) {
	 eval( "document." + imgRef + ".src = '" + imgSrc + "'" );
}

// Panel Open and Close
function showHideDivSwapImage( ObjectID, showBtn, closeBtn ) {
	 objElement = $(ObjectID);
	 objShowBtn = $(showBtn);
	 objCloseBtn = $(closeBtn);
	
	 if (objElement.style.display == 'none')	{
		  objElement.style.display = 'block';
		  objShowBtn.style.display = 'none';
		  objCloseBtn.style.display = 'block';
	 } else {
		  objElement.style.display = 'none';
		  objShowBtn.style.display = 'block';
		  objCloseBtn.style.display = 'none';
	 }
}

// Position Window
function PositionWindow ( popupWidth , popupHeight, position ) {
  if (position == 'center') {
    var popupLeft = (screen.width-popupWidth)/2;
    var popupTop = (screen.height-popupHeight)/2;
    var popupPosition = ',width=' + popupWidth + ',height=' + popupHeight + ',screenX=' + popupLeft + ',screenY=' + popupTop + ',left=' + popupLeft + ',top=' + popupTop;
  } else {
    var popupPosition = ',width=' + popupWidth + ',height=' + popupHeight;
  }
  return popupPosition;
}

// Set Focus to input tag of tabindex = 1
function setFocusTabIndex1() {
  var arrObjs = $("input");
  for(i = 0; i < arrObjs.length; i++) {
    if (arrObjs[i].tabIndex == 1) {
      if (arrObjs[i].isContentEditable ) { 
        arrObjs[i].focus();
      }
      i = arrObjs.length;
    }
  }
}

//Add Load Event Function
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//Add UnLoad Event Function
function addUnLoadEvent(func) {
  var oldonunload = window.onunload;
  if (typeof window.onunload != 'function') {
    window.onunload = func;
  } else {
    window.onunload = function() {
      oldonunload();
      func();
    }
  }
}

// global storage object for type-ahead info, including reset() method
var typeAheadInfo = {
  last:0, 
  accumString:"", 
  delay:1500,
  timeout:null, 
  reset:function() {this.last=0; this.accumString=""}
};

// function invoked by select element's onkeydown event handler
// Jason Badke, sourced from Danny Goodman, O'Reilly Networks
function typeAhead() {
   if (window.event && !window.event.ctrlKey) {
      var now = new Date();
      if (typeAheadInfo.accumString == "" || now - typeAheadInfo.last < typeAheadInfo.delay) {
         var evt = window.event;
         var selectElem = evt.srcElement;
         var charCode = evt.keyCode;
         var newChar =  String.fromCharCode(charCode).toUpperCase();
         typeAheadInfo.accumString += newChar;
         var selectOptions = selectElem.options;         
         var txt, nearest;
         for (var i = 0; i < selectOptions.length; i++) {
            txt = selectOptions[i].text.toUpperCase();            
            nearest = (typeAheadInfo.accumString > txt.substr(0, typeAheadInfo.accumString.length)) ? i : nearest;
            if (txt.indexOf(typeAheadInfo.accumString) == 0) {
               clearTimeout(typeAheadInfo.timeout);
               typeAheadInfo.last = now;
               typeAheadInfo.timeout = setTimeout("typeAheadInfo.reset();", typeAheadInfo.delay);
               selectElem.selectedIndex = i;
               evt.cancelBubble = true;
               evt.returnValue = false;
               return false;   
            }            
         }
         /*if (nearest != null) {
           selectElem.selectedIndex = nearest;
         }*/
      } else {
         clearTimeout(typeAheadInfo.timeout);
      }
      typeAheadInfo.reset();
   }
   return true;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

/***
Returns true if the given year is a leap year according to the following rules:
1. Years divisible by four are leap years, unless...
2. Years also divisible by 100 are not leap years, except...
3. Years divisible by 400 are leap years.
***/
function isLeapYear(year) 
{ 
	return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}

/***
Returns true if the combination of day/month/year is a valid date, returns false otherwise.
Takes into account number of days in each month (eg 28,29,30 or 31), handles Feb & leap years.
day: expected to be a string representing an integer value from 1 to 31
month: expected to be a 2 digit string representing a month from 01 to 12
year: expected to be a 4 digit string representing a year
***/
function isValidDate(day, month, year){
  if (day == "" || month=="" || year=="")  return false;
  
  if(parseInt(day) > 28 && month == "02" && (!isLeapYear(year) || parseInt(day) > 29)){
		//don't allow dates past 28th in Feb unless its a leap year, then Feb 29 is OK
		return false;
	}
	else if(parseInt(day) > 30 && (month == "09" || month == "04" || month == "06" || month == "11"))
	{
		//don't allow dates past 30th for months that only have 30 days
		return false;		
	}
	else
	{
		//date is valid 
		return true;
	}
}

function toggleLayer(whichLayer){
    var div = $(whichLayer).style;
    div.height = '138px';
    div.width = '760px';
}
//-->