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 findObj( obj ) { return getObj( obj ) }






  var view_X = 0;
  var view_Y = 0;
  var mouse_Xpos = 0;
  var mouse_Ypos = 0;
  var	page_X = 0;
  var	page_Y = 0;
  var scroll_X = 0;
  var scroll_Y = 0;
  var elmLeft = 0;
  var elmWidth = 0;
  var elmTop = 0;
  var IE = document.all?true:false

  /*
  if (!IE) {
    document.captureEvents(Event.MOUSEMOVE)
    document.captureEvents(Event.MOUSEUP);
  
    document.onmousemove = getMouseXY;
    document.onmouseup = clickHandler;
  
  }
  if( IE && window.parent.document.readyState ) {
    document.onmousemove = getMouseXY;
    document.onmouseup = clickHandler;
  }
  */
  
  function clickHandler (evt) {
    if (document.layers)
      alert(evt.target + '1: ' + evt.target.constructor + ': ' + evt.target.id);
    else if (window.event && window.event.srcElement) {
      elmWidth = findPosX( window.event.srcElement );
      elmLeft = window.event.srcElement.offsetWidth;
      elmTop = findPosY( window.event.srcElement );
    } else if (evt && evt.stopPropagation && !window.opera) {
      if (evt.target.nodeType == 1) {
        elmWidth = findPosX( evt.target );
        elmLeft = evt.target.offsetWidth;
        elmTop = findPosY( evt.target );
      } else 
        alert(evt.target.parentNode + ': ' + evt.target.parentNode.nodeName + ': ' + evt.target.parentNode.id)
    }
    else if (window.opera && evt)
      alert(evt.target + '3: ' + evt.target.tagName + ': ' + evt.target.id);
  
    return true;
  }

  function findPosX(obj) {
  	var curleft = 0;
  	if (obj.offsetParent) {
  		while (obj.offsetParent) {
  			curleft += obj.offsetLeft
  			obj = obj.offsetParent;
  		}
  	} else if (obj.x)
  		curleft += obj.x;
  	//alert( curleft );
  	return curleft;
  }

  function findPosY(obj) {
  	var curtop = 0;
  	if (obj.offsetParent) {
  		while (obj.offsetParent) {
  			curtop += obj.offsetTop
  			obj = obj.offsetParent;
  		}
  	} else if (obj.y)
  		curtop += obj.y;
  	return curtop;
  }
  
  function getPageDims() {
    var test1 = document.body.scrollHeight;
    var test2 = document.body.offsetHeight
    if (test1 > test2) {
    	page_X = document.body.scrollWidth;
    	page_Y = document.body.scrollHeight;
    } else {
    	page_X = document.body.offsetWidth;
    	page_Y = document.body.offsetHeight;
    }
    if( !IE ) {
      view_X = window.innerWidth;
      view_Y = window.innerHeight;
    } else {
      view_X = document.body.clientWidth;
      view_Y = document.body.clientHeight;
    }
  }
  
  // Main function to retrieve mouse x-y pos.s
  function getMouseXY(e) {
    if (IE) {
      mouse_Xpos = event.clientX + document.body.scrollLeft
      mouse_Ypos = event.clientY + document.body.scrollTop
    } else {
      mouse_Xpos = e.pageX
      mouse_Ypos = e.pageY
    }  
    // catch possible negative values in NS4
    if (mouse_Xpos < 0){mouse_Xpos = 0}
    if (mouse_Ypos < 0){mouse_Ypos = 0}  

    //get scrollo
    if (self.pageYOffset) {
    	scroll_X = self.pageXOffset;
    	scroll_Y = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
    	scroll_X = document.documentElement.scrollLeft;
    	scroll_Y = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers {
    	scroll_X = document.body.scrollLeft;
    	scroll_Y = document.body.scrollTop;
    }
    return true
  }



  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");
  }  