/************************************************************************************************************
Ajax dynamic content
Copyright (C) 2006  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
	
************************************************************************************************************/	



var enableCache = false;
var jsCache = new Array();

var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId, ajaxIndex, url, ajax_tooltipObj, width, height) { 
    var html = dynamicContent_ajaxObjects[ajaxIndex].response;			
    ajax_showContentHtml(divId, html, url, ajax_tooltipObj, width, height);
}
function ajax_showContentHtml(divId,html,url,ajax_tooltipObj,width,height)
{
    document.getElementById(divId).innerHTML = html;
	if (height)
    {
        if (document.getElementById(divId).clientHeight > height)
            document.getElementById(divId).style.height = height + 'px';
        else
           {                       
                document.getElementById(divId).style.height = document.getElementById(divId).clientHeight;
            }
	    document.getElementById(divId).style.overflow = 'auto';
    }
    else
    {        
	    document.getElementById(divId).style.height = 'auto';	    
    }
    if (ajax_tooltipObj)
      if (ajax_tooltipObj.style)
        {
            if (width)
	            ajax_tooltipObj.style.width = width + 'px';
        	else
	             ajax_tooltipObj.style.width = ajax_tooltipObj.clientWidth;
	       
        if (height)         
           if (ajax_tooltipObj.clientHeight < height)                      
              ajax_tooltipObj.style.height = ajax_tooltipObj.clientHeight;
            else
               ajax_tooltipObj.style.height = height + 'px' ;
        else 
	       ajax_tooltipObj.style.maxHeight = ajax_tooltipObj.clientHeight;
	   }	   
	 
	if (width)
	{
	    document.getElementById(divId).style.width = width  + 'px';
	}	
	
	/*if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}*/
	dynamicContent_ajaxObjects[ajaxIndex] = false;
}

function ajax_loadContent(divId,url,width,height) {    
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		return;
	}
	
	var ajaxIndex = dynamicContent_ajaxObjects.length;
	document.getElementById(divId).innerHTML = 'Loading content - please wait';
	new Ajax.Request(url,
      {
          method: 'get',
          onSuccess: function(transport) {
              ajax_showContentHtml(divId, transport.responseText, null, url, width, height); 
          },
          onFailure: function(transport) {
          }
      });
}
    