// JavaScript Documentvar js;
var dummyDate = new Date();
var __tmpscript;
var __tmpcss;
var __loaded_files    = new Array();
var __included_files  = new Array();
var __defaultFontSize = 100;
var __currentFontSize = __defaultFontSize;

///////////////////////////////////////////////////////////////////////
//
//   Utilities
//
//
/**
 * Checks if a value exists in an array
 *
 * @return Boolean
 */
function in_array(needle, haystack)
{
    for (var i = 0; i < haystack.length; i++)
    {
        if (haystack[i] == needle) 
        {
            return true;
        }
    }
    return false;
}
/**
 * String Buffer Class
 *
 *
 */
function StringBuffer(){
	this.__strings__ = new Array();
}

StringBuffer.prototype.append = function(str){
	this.__strings__.push(str);
	return this;
};

StringBuffer.prototype.toString = function(){
	return this.__strings__.join("");	
};

///////////////////////////////////////////////////////////////////////
//
//   Includes
//
//
/**
 * Includes JS file dynamically
 *
 * @return void
 */
function include_js(file, is_count_loaded) 
{
    var html_doc = document.getElementsByTagName('head')[0];
    __tmpscript = document.createElement('script');
    __tmpscript.setAttribute('type', 'text/javascript');
    __tmpscript.setAttribute('src', file);
	__tmpscript.file = file;
    html_doc.appendChild(__tmpscript);

    __tmpscript.onreadystatechange = function ()
    {
       
	   if(this.readyState == 'complete' || this.readyState == 'loaded')
		{
			__loaded_files[__loaded_files.length] = this.file;
		}
    }

    __tmpscript.onload = function ()
    {
        __loaded_files[__loaded_files.length] = this.file;
    }
    return false;
}
/**
 * Includes CSS file dynamically
 *
 * @return void
 */
function include_css(css_file) 
{
    var html_doc = document.getElementsByTagName('head')[0];
    __tmpcss = document.createElement('link');
    __tmpcss.setAttribute('rel', 'stylesheet');
    __tmpcss.setAttribute('type', 'text/css');
    __tmpcss.setAttribute('href', css_file);
	__tmpcss.file = css_file;
    html_doc.appendChild(__tmpcss);

    // alert state change
    __tmpcss.onreadystatechange = function ()
    {
        if (this.readyState == 'complete' || this.readyState == 'loaded')
		{
		   __loaded_files[__loaded_files.length] = this.file;
		}
    }
    __tmpcss.onload = function ()
    {
          __loaded_files[__loaded_files.length] = this.file;
    }

    return false;
}
/**
 * The include_once() statement includes and evaluates the specified file by manipulation DOM model. File can be either 'js' or 'css'
 *
 * @return void
 */
function include_once(file, type) 
{

	if (!in_array(file, __included_files))
    {
        __included_files[__included_files.length] = file;

        switch(type)
        {
            case 'js':
                include_js(file);
                break;
            case 'css':
                include_css(file);
                break;
            default:
                include_js(file);
                break;
        }
    }
}
/**
 * Wait till files are loaded
 *
 */
function waitToLoadFiles(postLoadFunc)
{
    if(areAllFilesLoaded())
	{
		setTimeout(postLoadFunc+"()", 1);
	}
	else
    {
		setTimeout("waitToLoadFiles('"+postLoadFunc+"')", 1000);
    }
}
/**
 * Check if files are loaded
 *
 */
function areAllFilesLoaded()
{
    if(__included_files.length == __loaded_files.length)
        return true;
    else
        return false;
}

////////////////////////////////////////////////////
//
// Font manipulations
//
//
/**
 * Apply default font size to document
 *
 * @return void
 */
function revertStyles()
{
	__currentFontSize = __defaultFontSize;
	changeFontSize(0);
}
/**
 * Calculate new font size and apply this value to document
 *
 * @return void
 */
function changeFontSize(sizeDifference)
{
	__currentFontSize = parseInt(__currentFontSize) + parseInt(sizeDifference * 5);

	if(__currentFontSize > 220)
	{
		__currentFontSize = 220;	
	}
	else if(__currentFontSize < 60)
	{
		__currentFontSize = 60;
	}

	setFontSize(__currentFontSize);
};
/**
 * Set new Font Size - Global
 *
 * @return void
 */
function setFontSize(fontSize)
{
	var stObj = (document.getElementById) ? document.getElementById('content_area') : document.all('content_area');
	document.body.style.fontSize = fontSize + '%';
};