/**
 * DMI Page object
 *
 * @changes 2008-04-17 / mb / created
 *
 * @copyright Copyright © 2005-2008 / CHILIBYTES Böhm & Welte GbR / www.chilibytes.com
 * @author mb
 * @version 1.0.0
 *
 * @package com.deltamed_international
 * @subpackage www
 *
 */

/**
 * Namespaces
 */
if ( !window.com ) window.com = {};
if ( !com.deltamed_international ) com.deltamed_international = {};
if ( !com.deltamed_international.www ) com.deltamed_international.www = {};

/**
 * Requires windows events
 */
var CB_WindowEvents = com.chilibytes.ccl.controls.CB_WindowEvents;
var CB_Environment = com.chilibytes.ccl.html.CB_Environment;
var CB_AjaxConnection = com.chilibytes.ccl.ajax.CB_AjaxConnection;

/**
 * Constructor
 *
 * @access public
 */
com.deltamed_international.www.DMI_Page = function() {
	// Constructor
	this.constructor = com.deltamed_international.www.DMI_Page;
	// Super class
	CB_WindowEvents.call( this );
	this.fAjaxConnection = new CB_AjaxConnection( this );

}

/**
 * Inherit mouse events class
 */
var _dmiPageInherit = function() {};
_dmiPageInherit.prototype = CB_WindowEvents.prototype;
com.deltamed_international.www.DMI_Page.prototype = new _dmiPageInherit();


/**
 * Window on load event
 *
 * @access public
 */
com.deltamed_international.www.DMI_Page.prototype.WindowOnLoad = function( eventP ) {
	this._ResizeBodyFrame();
	this._LayoutFramesTweak();
}

/**
 * Window on resize event
 *
 * @access public
 */
com.deltamed_international.www.DMI_Page.prototype.WindowOnResize = function( eventP ) {
	this._ResizeBodyFrame();
	this._LayoutFramesTweak();
}

/**
 * Splash event
 *
 * @access public
 */
com.deltamed_international.www.DMI_Page.prototype.SplashStateChanged = function( parentObj ) {
	if ( parentObj ) {
		parentObj.DMI_Page.SplashStateChanged( null );
	}
	else {
		var ifBodyObj = document.getElementById( DMI_PAGE_ID_IFRAME_CONTENT );
		if ( ifBodyObj ) {
			ifBodyObj.src = DMI_PAGE_SRC_IFRAME_CONTENT + "?ref=hmi_1.1";
		}
		this.FrameworkShow();
		this._LayoutFramesTweak();
	}
}

/**
 * Changes the visibility status
 *
 * @access
 */
com.deltamed_international.www.DMI_Page.prototype.FrameworkShow = function() {
	var footerObj = document.getElementById( DMI_PAGE_ID_PAGE_FOOTER );
	var headerObj = document.getElementById( DMI_PAGE_ID_PAGE_HEADER );
	if ( footerObj && headerObj ) {
		headerObj.className = headerObj.id + "__visible";
		footerObj.className = footerObj.id + "__visible";
	}
}

/**
 * Change language an reload
 *
 * @access public
 */
com.deltamed_international.www.DMI_Page.prototype.PageLanguageChange = function( selectObj, varName ) {
	if ( selectObj != null ) {
		var lang = selectObj.options[selectObj.selectedIndex].value;
		if ( lang != "#" ) {
			//document.location.href = DMI_PAGE_SRC_INDEX + "?" + varName + "=" + lang;
			//var ssoObject = CBPage.SSOGet();
			//ssoObject.DataFieldWrite( varName, lang );
			//document.cookie = "CBL_LANG_ISO=" + lang;
			if ( this.fAjaxConnection ) {
				this.fAjaxConnection.XMLQueryRequest( "changelang.php", this.EventLanguageChanged, "CBML=" + lang );
			}
		}
	}
}

/**
 *
 */
com.deltamed_international.www.DMI_Page.prototype.EventLanguageChanged = function( xmlDomObj, xmlStructure ) {
	document.location.href = document.location.href;
}

/**
 * Window on load event
 *
 * @access public
 */
com.deltamed_international.www.DMI_Page.prototype._ResizeBodyFrame = function() {
	var contentObj = parent.document.getElementById( DMI_PAGE_ID_IFRAME_CONTENT )
	var tableObj = document.getElementById("leaflets");
	if ( contentObj && tableObj && CB_Environment.CurrentClientBrowser() & ~CB_ENVIRONMENT_BROWSER_IDENT_IE ) {
		tableObj.style.height = ( contentObj.offsetHeight - 40 ) + "px";
	}
}

/**
 * Tweaks the layout of all frames
 *
 * @access private
 */
com.deltamed_international.www.DMI_Page.prototype._LayoutFramesTweak = function() {
 	var headerObj 	 = document.getElementById( DMI_PAGE_ID_PAGE_HEADER );
    var bodyObj 	 = document.getElementById( DMI_PAGE_ID_PAGE_BODY );
    var footerObj 	 = document.getElementById( DMI_PAGE_ID_PAGE_FOOTER );
    var ifBodyObj 	 = document.getElementById( DMI_PAGE_ID_IFRAME_CONTENT );
    //var ifDocBodyObj = document.getElementById( "body-content" );
    if ( headerObj && bodyObj && footerObj && ifBodyObj ) {
        var bodyHeight = bodyObj.offsetParent.offsetHeight - headerObj.offsetHeight - footerObj.offsetHeight;
        bodyObj.style.height = bodyHeight + "px";
        ifBodyObj.style.height = bodyHeight + "px";
    }/*
    else if ( ifDocBodyObj ) {
     	var tableWrap = document.getElementById( "cont-table-wrap" );
     	var ifBodyObj = parent.document.getElementById( "iframe-content" );
	  	if ( ifBodyObj.offsetHeight < tableWrap.offsetHeight ) {
	  		ifDocBodyObj.style.height = tableWrap.offsetHeight + "px";
	  	}
	  	else {
	   		ifDocBodyObj.style.height = "100%";
	  	}
    }*/
}

/**
 * Create instance
 */
var DMI_Page = new com.deltamed_international.www.DMI_Page();
