// doNothing()
// preloadImage( imageName );
// preloadImages( imageNameArray[] );
// findImage( id, doc );
// findLayer( id, doc );
// writeLayer( id,  value, align, valign )
// rollover( orgImage, effektImage, optionGroup )
// getGroup( group )
// optionClick( id, orgImage, effektImage, optionGroup )
// openFullSizeWindow( side )
// openPopUpWindow( side, width, height, top, left, scrolling )
// openNewWindow( side, target )
// putHtmlIntoLayer( contentLayer, srcHtml )
// putHtmlIntoFrame( srcHtml, target )
// setLayerVisible( object, value)
// isLayerVisible( object )
// setLayerPosition( object, xPos, yPos)
// setLayerAttribute( object, attribute, value )
// getLayerAttribute( object, attribute )
// loadStyles( ieStyle, nsStyle )
// getDocumentSize()
// setCookie( cookieName, value )
// getCookie( cookieName )
// getCookies( )
// deleteCookie( cookieName )
// getArrayValue( array, id )
// getArrayValuePos( array, id )
// getCookies()
// resizeLayer( layer, width, height )
// resizeEffekt()

// the current optiongroup with his functions
var optionGroups = new Array();
function OptionGroup( id )
{
	this.id = id;
	this.imageId = null;
	this.orgImage = null; 
	this.effektImage = null;
	this.optionGroup = null;
 
	this.setCurrentObject = XsetCurrentObject;

	this.getId = XgetId;
	this.getImageId = XgetImageId; 
	this.getOrgImage = XgetOrgImage;
	this.getEffektImage = XgetEffektImage;
	this.getOptionGroup = XgetOptionGroup;
	return;
}

function XsetCurrentObject( id, orgImage, effektImage, optionGroup)
{
	this.imageId = id; 
	this.orgImage = orgImage; 
	this.effektImage = effektImage;
	this.optionGroup = optionGroup;
	return;
}

function XgetId( )
{
	return this.id;
}

function XgetImageId( )
{
	return this.imageId;
}

function XgetOrgImage( )
{
	return this.orgImage;
}

function XgetEffektImage( )
{
	return this.effektImage;
}

function XgetOptionGroup( )
{
	return this.optionGroup;
}

// this is a empty function
function doNothing()
{
	return;
}

// preload images
function preloadImage( imageName )
{
	if ( imageName && imageName != null && isNaN( imageName ) )
	{
		var img = new Image();
		img.src = imageName;
		return img;
	}
	return null;
}

// preload images
function preloadImages( )
{
	var d=document; 
	if( d.images )
	{
		var parameter = preloadImages.arguments;
		if ( parameter && parameter != null)
		{
			for(i = 0; i < parameter.length; i++)
			{
				if (parameter[i] && parameter[i] != null && parameter[i].length > 0)
				{
					preloadImage( parameter[i] );
				}
			}
		}
	}
	return;
}

// find a layer in the document IE, NS and W3C --------------------------------------
function findImage( id, doc )
{
	if (id && id  != null)
	{
		if (!doc || doc == null)
		{
			doc = document;
		}
		var node = null;
		if ( doc.layers )
		{
			node = doc.images[id];
			for( var i=0; !node && i < doc.layers.length; i++)
			{ 
				node = findImage( id, doc.layers[i].document );
			}   
		}
		else
		{
			node = doc.images[id];
		}
		return node;
	}
	return null;
}

// find a layer in the document IE, NS and W3C --------------------------------------
function findLayer( id, doc )
{
	if (id && id  != null)
	{
		if (!doc || doc == null)
		{
			doc = document;
		}
		var node = null;
		if ( doc.all )
		{
			node = doc.all[id];
		}
		else if ( doc.getElementById )
		{
			node = doc.getElementById(id);
		}
		else if ( doc.layers )
		{
			node = doc.layers[id];
			for( var i=0; !node && doc.layers && i < doc.layers.length; i++)
			{
				node = findLayer( id, doc.layers[i].document );
			}   
		}
		return node;
	}
	return null;
}

// write the value to the given layer
function writeLayer( id,  value, align, valign )
{
	var object = null;
	if ( typeof( id ) == "string" )
	{
		object = findLayer( id );
	}
	else
	{
		object = id;
	} 
	if ( !object == null || value == null )
	{
		window.status = "No object or value found to write!";
		return;
	}
	if ( align || valign  )
	{
		var source = "<p "
		if ( align && align != null )
		{
			source += " align='" + align + "' "; 
		}
		if ( valign && valign != null )
		{
			source += " valign='" + valign + "' "; 
		}
		value = source + ">" + value + "</p>";
	}
	if ( document.all || document.getElementById )
	{
		object.innerHTML = value;
	}
	else
	{
		object.document.open();
		object.document.write( value );
		object.document.close();
	}
	return;
}

// rollover action
function rollover( orgImage, effektImage, optionGroup )
{
	if( orgImage != null && effektImage != null )
	{
		if( optionGroup != null && optionGroup.length > 0 )
		{
			var group = getGroup( optionGroup );
			if ( group && group != null )
			{
				var id = group.getImageId();
				if ( id && id != null && id == orgImage)
				{ 
					return;
				}
			}
		}
		var img = null;
		if ( typeof( orgImage ) == "string" )
		{
			img = findImage(orgImage);
		}
		else
		{
			img = orgImage;
		}
		if (img && img != null)
		{
			if (typeof( effektImage ) == "string" )
			{
				img.src = effektImage;
			}
			else
			{
				img.src = effektImage.src;
			}
			return;
		}
	}
	return;
}

// check if this rollover image is in a option group
function getGroup( group )
{
	var isInside = -1;
	for( var i=0; i < optionGroups.length; i++ )
	{
		if ( optionGroups[i].getId() == group )
		{
			isInside = i;
			break;
		}
	}
	if ( isInside < 0 )
	{
		optionGroups[ optionGroups.length ] = new OptionGroup( group );
		isInside = optionGroups.length - 1;
	}
	return optionGroups[ isInside ];
}

// get the array object with the given id
function getArrayValue( array, id )
{
	var pos = getArrayValuePos( array, id );
	if ( pos > -1)
	{
		return array[pos];
	}
	return null;
}

// get the array object with the given id
function getArrayValuePos( array, id )
{
	if ( id && id != null && array && array != null)
	{
		for( var i=0; i < array.length; i++ )
		{
			if ( array[i].id == id )
			{
				return i;
			}
		}
	}
	return -1;
}

// rollover effekt with image-name-----------------------------------------------------------
function optionClick( id, orgImage, effektImage, optionGroup )
{
	if( orgImage != null && effektImage != null )
	{
		if( optionGroup != null && optionGroup.length > 0 )
		{
			var group = getGroup( optionGroup );
			if ( group && group != null )
			{
				var current = group.getImageId();
				if ( current && current != null && current != id )
				{
					rollover( current, group.getOrgImage() );
				}
				rollover( id, effektImage );
				group.setCurrentObject(id, orgImage, effektImage, optionGroup );
			}
		}
	}
	return;
}

// open the given side in fullscrren modus (kiosk-mode) ------------------------------
function openFullSizeWindow( side )
{
	if (side && side != null)
	{
		var newWindow = null;
		if (document.layers)
		{
			newWindow = window.open( side, "_blank", "width=" + (screen.width-10) + ",height=" + (screen.height-50) + ",top=0,left=0, fullscreen=yes, toolbar=no, status=no, scrollbars=no, location=no, menubar=no, directories=no, resizable=no" );
		}
		else
		{
			newWindow = window.open( side, "_blank", "fullscreen=yes" );
		}
		newWindow.focus();
	}
	return;
}

// open a window with the given side, size, and pos
function openPopUpWindow( side, width, height, top, left, scrolling )
{
	if (side && side != null)
	{
		var parameters = "";
		if ( width != null )
		{
			parameters += ",width=" + width;
		}
		if ( height != null )
		{
			parameters += ",height=" + height;
		}
		if ( top != null )
		{
			parameters += ",top=" + top;
		}
		if ( left != null )
		{
			parameters += ",left=" + left;
		}
		if ( scrolling == "true" )
		{
			parameters += ",scrollbars=auto";
			parameters += ",scrollbars=yes";
		}
		else
		{
			parameters += ",scrollbars=no";
		}
		var newWindow = window.open( side, "_blank","toolbar=no,status=yes,location=no,menubar=yes,directories=no,resizable=no" + parameters );  
		newWindow.focus();
	}
	return;
}

//open new window
function openNewWindow( side, target )
{
	if (side && side != null)
	{
		if ( target == null || !target )
		{
			target = "_blank";
		}
		var newWindow = window.open( side, target );  
		newWindow.focus();
	}
	return;
}

// put the given html side into the target
function putHtmlIntoFrame( srcHtml, target )
{
	if (  srcHtml != null && target == null )
	{
		document.location = srcHtml;
	}
	else if (  srcHtml != null )
	{
		eval( "parent."+ target + ".location = '" + srcHtml + "';" );
	}
	return;
}

// put the given html side into a layer
function putHtmlIntoLayer( contentLayer, srcHtml )
{
	if ( srcHtml && srcHtml != null )
	{
		if ( contentLayer != null )
		{
			window.scrollTo(0,0);
			var objLayer = null;
			if ( typeof( contentLayer ) == "string" )
			{
				objLayer = findLayer( contentLayer ); 
			}
			else
			{
				objLayer = contentLayer;
			}
			if ( objLayer != null && document.layers)
			{
				objLayer.src = srcHtml;
			}
			else if ( objLayer != null )
			{
				writeLayer( objLayer, "<iframe name='changeableIFrame' src = '" + srcHtml + "' frameborder='0' scrolling=no width='100%' height='100%'></iframe>" );		
			}
			else
			{
				window.status = "Seite >" + srcHtml + "<kann nicht angezeigt werden! Layer >" + contentLayer + "< konnte nicht gefunden werden.";
			}
		}
		else
		{
			var newWindow = window.open( srcHtml, "_blank" );
			newWindow.focus();
		}
	}
 	return;
}

// get the given attribut to the layer IE, NS and W3C --------------------------------------
function getLayerAttribute( object, attribute )
{
	if (!object || !attribute || object == null || attribute == null )
	{
		return;
	}
	var ret = null;
	if (document.layers )
	{
		eval( "ret = object." + attribute + ";" );
	}
	else
	{
		eval( "ret = object.style." + attribute + ";" );
	} 
	return ret;
}


// set the given attribut to the layer IE, NS and W3C --------------------------------------
function setLayerAttribute( object, attribute, value )
{
	if (!object || !attribute || !value || object == null || attribute == null || value == null)
	{
		return;
	}
	if (document.layers )
	{
		if( isNaN( value ) == true)
		{
			eval( "object." + attribute + " = '" + value + "'" );
		}
		else
		{
			eval( "object." + attribute + " = " + value );
		}
	}
	else
	{
		if( isNaN( value ) == true)
		{
			eval(  "object.style." + attribute + " = '" + value + "'" );
		}
		else
		{
			eval(  "object.style." + attribute + " = " + value );
		}
	} 
	return;
}

// shows or hide the layer IE, NS and W3C --------------------------------------
function setLayerPosition( object, xPos, yPos)
{
	if( xPos != null )
	{
		setLayerAttribute( object, 'top', xPos );
	}
	if( yPos != null )
	{
		setLayerAttribute( object, 'left', yPos );
	}
	return;
}

// test the visibilty from a layer IE, NS and W3C --------------------------------------
function isLayerVisible( object )
{
	var bVisible = getLayerAttribute( object, 'visibility' );
	if ( bVisible && bVisible != null &&
		( bVisible.indexOf( "show" ) >= 0 || bVisible.indexOf( "visible" ) >= 0 ) );
	{
		return true;
	}
	return false;
}

// shows or hide the layer IE, NS and W3C --------------------------------------
function setLayerVisible( object, value)
{
	if( value  &&  ( value == "show" || value == "visible" || value == 1 || value == true) )
	{
		value = 'visible';
		if ( document.layers )
		{	
			value = 'show';
		}	
	}
	else
 	{
		value = 'hidden';
		if ( document.layers )
		{
			value = 'hide';
		}
	}
	setLayerAttribute( object, 'visibility', value  );
	return;
}

// write the style sheet in your html file depended form your browser
function loadStyles( ieStyle, nsStyle, macNsStyle )
{
	if ( !nsStyle || nsStyle == null && !ieStyle || ieStyle == null )
	{
		alert('No style-sheet file found!');
		return;
	}
	else if ( !ieStyle || ieStyle == null && nsStyle )
	{
		ieStyle = nsStyle
	}
	else if ( !nsStyle || nsStyle == null && ieStyle )
	{
		nsStyle = ieStyle
	}
	
	var mainParent = getProSiebenComContent();
	if ( mainParent != null )
	{
		mainParent = mainParent.parent.document;
	}
	else
	{
		mainParent = document;
	}
	
	var suffix = "", side = mainParent.URL;		
	if ( side && side.indexOf("/4/3/1") > -1 )
	{
		suffix = "_sat1";		
	}
	else if ( side && side.indexOf("/4/3/2") > -1 )
	{
		suffix = "_pro7";		
	}
	else if ( side && side.indexOf("/4/3/3") > -1 )
	{
		suffix = "_k1";		
	}
	else if ( side && side.indexOf("/4/3/4") > -1 )
	{
		suffix = "_n24";		
	}
	
	if ( navigator.appName.toLowerCase().indexOf("netscape") > -1 && navigator.appVersion.substring(0, 1) <= "4" )
   	{
		if ( suffix.length > 0 && nsStyle.indexOf( suffix ) < 0 )
		{
			var pos = nsStyle.indexOf(".");
			if (pos > -1)
			{
				nsStyle = nsStyle.substring( 0, pos) + suffix + nsStyle.substring( pos, nsStyle.length );
			}
		}
    	document.open();
    	document.writeln("<link rel='stylesheet' type='text/css' href='"+ nsStyle + "'>");
    	document.close();
   	}
  	else
   	{
		if ( suffix.length > 0 && ieStyle.indexOf( suffix ) < 0 )
		{
			var pos = ieStyle.indexOf(".");
			if (pos > -1)
			{
				ieStyle = ieStyle.substring( 0, pos ) + suffix + ieStyle.substring( pos, ieStyle.length );
			}
		}
    	document.writeln("<link rel='stylesheet' type='text/css' href='"+ ieStyle + "'>");
   	}
	return;
}

// get the curent size or the object
function getDocumentSize( )
{
	if ( document.layers)
	{
		return window.innerHeight;
	}
	else
	{
		return document.body.clientHeight;
	}
}

// set the cookie with the given id and the given value
function setCookie( cookieName, value )
{
	if ( cookieName != null )
	{
		if ( value == null)
		{
			value = "";
		}
		cookieName += "=";
		cookieName += escape( value );
		cookieName += ";"
		
		var expire = new Date();
		if ( value.length < 1)
		{
			expire.setTime( expire.getTime() - 1 );
			expire = " expires=" + expire.toGMTString();
			cookieName += expire;
		}		
		document.cookie = cookieName;
	}
	return;
}

// get the cookie with the given id
function getCookie( cookieName )
{
	if ( cookieName != null )
	{
		cookieName += "=";
		var start = document.cookie.indexOf( cookieName );
		if ( start > - 1 )
		{
			var ende = document.cookie.indexOf( ";", start + cookieName.length );
			if ( ende < 0 )
			{
				ende = document.cookie.length;
			}
			return unescape( document.cookie.substring( start + cookieName.length, ende ) );
		}
	}
	return null;
}

// get all cookies from this document
function getCookies( )
{
	if ( document.cookie != null )
	{
		return document.cookie.split(";");
	}
	return null;
}

// delete the given cookie
function deleteCookie( cookieName )
{
	if ( cookieName != null )
	{
		var cookie = getCookie( cookieName );
  		if ( cookie != null )
		{
			var exp = new Date();
  			exp.setTime(exp.getTime() - 1);  		
    		document.cookie = cookieName + "=" + cookie + "; expires=" + exp.toGMTString();
		}
	}
	return;
}

// resize the given layer
function resizeLayer( layer, width, height )
{
	if ( layer != null )
	{
		if ( document.layers )
		{
			if ( height != null && height > -1)
			{
				setLayerAttribute( layer, "clip.height", height );
			}
			if ( width != null && width > -1)
			{
				setLayerAttribute( layer, "clip.width", width );
			}
		}
		else
		{
			if ( height != null && height > -1 )
			{
				setLayerAttribute( layer, "height", height );
			}
			if ( width != null && width > -1)
			{
				setLayerAttribute( layer, "width", width );
			}
		}
	}
	return;
}

// resize effekt on netscape by the option buttons
function resizeEffekt()
{
	if ( document.all || document.getElementById )
	{
		return;
	}
	document.reload();
	if ( optionGroups && optionGroups != null)
	{
		for( var i=0; i < optionGroups.length; i++ )
		{
			var group = optionGroups[i];
			if ( group && group != null )
			{
				var imageId = group.getImageId();
				if( imageId && imageId != null )
				{
					rollover( group.getImageId(), group.getEffektImage() );
				}
			}
		}
	}
	return;
}

function popinfo(t)
{
   meintarget = t;
   MeinFenster = window.open("/programmguide/detail.php?id=" + t, "Detailinformationen", "width=628,height=500,scrollbars");
   MeinFenster.focus();
}
