function init() {
  get_calendar();
}

function get_calendar() {
  FL.responseHandler = 'show_calendar';
  FL.handle( 'retrieve', 'modules/site/showcalendar.php' ); 
}

function show_calendar( response ) {
  getObj( 'content' ).innerHTML = URLDecode( response );
  fixPNG();
}

function readCookie(cname) {
    var cookieName = cname + '=';
    var cookies = document.cookie;
    var pos = cookies.indexOf(cookieName);

    if (pos != -1) {
        var start = pos + cookieName.length;
        var end = cookies.indexOf(';', start);

        if (end == -1) {
            end = cookies.length;
        }
        return unescape(cookies.substring(start, end));
    }
}

function setCookie(pName, pValue, expire_period) {
    var expireDate = new Date();
    expireDate.setTime( (new Date()).getTime() + expire_period );
    document.cookie = pName + '=' + escape(pValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}

function setFocus( obj ) {
  getObj( obj ).focus();
}

function catchKey( evt, func, params ) {
  evt = (evt) ? evt : (window.event) ? event : null;
  if (evt) {
    var charCode = (evt.charCode) ? evt.charCode :
                   ((evt.keyCode) ? evt.keyCode :
                   ((evt.which) ? evt.which : 0));
    if (charCode == 13) func(params);
  }  
}

function URLDecode( encoded )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   
   return plaintext;
};
function getObj(object) {
  if(document.all) myObject=eval('document.all[object]');
  else if(document.layers) myObject=eval('document.layers[object]');
  else if(document.getElementById && !document.all) myObject=eval('document.getElementById(object)');
  else return;
  return myObject;
}








  function isFunction(a) { return typeof a=='function'; }
  function isObject(a) { return a&&typeof a=='object'||isFunction(a); }
  function isArray(a) { return isObject(a)&&a.constructor==Array; }
  function isUndefined(a) { return typeof a=='undefined'; }
  function isDefined(a) { return !isUndefined(a); }
  function isString(a) { return typeof a=='string'; }
  function isDigit(num) { if (num.length>1) return false; var string="1234567890"; return string.indexOf(num)!=-1; }
    


function fixPNG() {
  
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])
  
  if ((version >= 5.5) && (document.body.filters)) 
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
        
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML

         i = i-1
      }
    }
  }
  
}


  function selectCalendarDate( field, day, month, year ) {
    if( isObject( getObj( field + '_day' ) ) )
      getObj( field + '_day' ).value = day;  
    if( isObject( getObj( field + '_month' ) ) )
      getObj( field + '_month' ).value = month;      
    if( isObject( getObj( field + '_year' ) ) )
      getObj( field + '_year' ).value = year;    
    if( isObject( getObj( field ) ) )
      getObj( field ).value = day + '/' + month + '/' + year;       
    CL.closeCalendar( field );
  }
  
  function popup(url, w, h) {
    if( !w ) w = '500';
    if( !h ) h = '400';
    window.open(url, "popupscreen","width=" + w + ",height=" + h + ",menubar=0,toolbar=0, location=0,directories=0,status=0,scrollbars=0,resizable=0,top=100,left=300");
  }  
  
  
function disableSelectBoxes( id ) {
  if( $('#' + id ).val() != '' ) { 
    $('.selbox').each( function() { 
      if( $(this).attr('id') != id ) { 
        $(this).attr( 'disabled', true ); 
      } 
    }); 
  } else {
    $('.selbox').attr( 'disabled', false );  
  }
}
