/**
 * Harfentreffen.de
 *
 * Functions for switching framesets
 *
 * @TODO: remove frames from website and delete this module!
 *
 */

/**
 * Name of frame in frameset with main content
 * This variable is not used anymore, becaus IE does not allow, 
 * to access name-property of frames in a frameset.
 * So this is hard coded in @frameUpdate()!
 * @var string
 */
// var strMainFrame = 'Inhalt';

/**
 * Path to site
 * Should be empty on live system!
 * @var string
 */
var strSitePath = '';

/**
 * URL of frameset
 * @var string
 */
var strRedirectTo = 'index1.html';

/**
 * Limit of window size, where @strRedirectTo is used
 * @var integet
 */
var intWindowSwitchWidth = 900;

/**
 * URL of frameset for small window size
 * @var string
 */
var strCssForSmall = 'harfentreffensmall.css';

/**
 * Check location of sites of mainframe
 *
 * Redirects to mainpage and adds hash to redirect URL,
 * if we are not in a frameset
 */
function siteCheck() {
	if(top.frames.length == 0)
		window.location.href = window.location.href.replace(/^(https?:\/\/[^\/]*\/)(.*)$/,'$1'+ strSitePath + strRedirectTo +'#$2');
}

/**
 * Update content of frameset
 *
 * If a hash is given in URL, content of mainframe is switched to hash
 * Be sure, to have named main frame "Inhalt"!
 *
 */
function frameUpdate() {
	if (window.location.hash)
	{
		var strUrl = window.location.hash.substring(1);
		if (strSitePath.length > 0 && strUrl.indexOf(strSitePath) == 0)
			strUrl = strUrl.substring(strSitePath.length);
		frames.Inhalt.location.href=strUrl;
	}
	if (getWindowWidth() < intWindowSwitchWidth)
	{
		if (document.getElementById('wrapperframe'))
			document.getElementById('wrapperframe').setAttribute('cols','*,800,*');
		if (document.getElementById('headerframe'))
			document.getElementById('headerframe').setAttribute('rows','85,*');
		if (document.getElementById('menueframe'))
			document.getElementById('menueframe').setAttribute('cols','150,*');
	}
}

/**
 * Update css for small frameset
 *
 * Bind to window.resize this function loads
 * an additional css file, to change some settings
 *
 */
function resizeFrame() {
	cssUpdate(strCssForSmall);
}

/**
 * Update css for smaller windows
 *
 * Loads an additional css file
 *
 */
function cssUpdate(strCss)
{
	if(document.createStyleSheet)
	{
		document.createStyleSheet(strCss);
	}
	else
	{
		var objStyle = document.createElement("style");
		var objText = document.createTextNode("@import url("+strCss+") screen;");
		objStyle.appendChild(objText);
		document.getElementsByTagName("body")[0].appendChild(objStyle);
	}
}

/**
 * Get window width
 *
 * @return integer
 *
 */
function getWindowWidth()
{
	var intWidth = 0;
	if (typeof(window.innerWidth) == 'number')
		intWidth = window.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth)
		intWidth = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth)
		intWidth = document.body.clientWidth;
	return intWidth;
}
/**
 * Get window height
 *
 * @return integer
 *
 */
function getWindowHeight()
{
	var intHeight = 0;
	if (typeof(window.innerHeight) == 'number')
		intHeight = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight)
		intHeight = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight)
		intHeight = document.body.clientHeight;
	return intHeight;
}
