//-- MINDTAKE POPUP-SURVEY INVITATION
//-- COPYRIGHT by www.mindtake.com
//-- CREATION_DATE 2001-10-15
//-- LAST ALTERED 2006-08-14 (virtual popup)
//-- AUTHOR benjamin.zotter@mindtake.com




//----------------------CONFIGURATION-----------

var ivPopup_PopupWidth = 370; //in pixel
var ivPopup_PopupHeight = 300; //in pixel;
var ivPopup_ShowPopupInTheMiddleOfTheScreen = true; // the Popup Window will be displayed in the middle of the screen
var ivPopup_PopupPositionTop = 70; //default position X (note: if ivPopup_ShowPopupInTheMiddleOfTheScreen is set this will have no effect!)
var ivPopup_PositionLeft = 350; //default position Y (note: if ivPopup_ShowPopupInTheMiddleOfTheScreen is set this will have no effect!)
var ivPopup_autoMinimizeVirtualPopup = 0; //VirtualPopup is automatically minimized after x Seconds. (set to 0 in order to deactivate this feature)
var ivPopup_disableBackground_ = true;

//----------------------------------------------

//---- Virtual Popup
//-- private variables: (do not change!!)
var ivPopup_autoMinimizeActive = true;
var ivVirtPopup_DnDController = null;
var ivPopup_VirtPopupPositionLeft = ivPopup_PositionLeft;
var ivPopup_VirtPopupPositionTop = ivPopup_PopupPositionTop;
var ivPopup_FrameHeight = 700;

function ivPopup_initPopupPosSize(){
	ivPopup_VirtPopupPositionLeft = ivPopup_PositionLeft;
	ivPopup_VirtPopupPositionTop = ivPopup_PopupPositionTop;

	if( ivPopup_ShowPopupInTheMiddleOfTheScreen && screen.width && screen.height ){
		ivPopup_VirtPopupPositionLeft = ivPopup_PositionLeft;
		ivPopup_VirtPopupPositionTop = ivPopup_PopupPositionTop;

		ivPopup_PopupWidth  = Math.min( screen.width - 40, ivPopup_PopupWidth );
		ivPopup_PopupHeight = Math.min( screen.height - 60, ivPopup_PopupHeight );
		var tmpLeft = Math.round( Math.max( 20, ( screen.width - ivPopup_PopupWidth - 15 ) / 2 ) );
		var tmpTop  = Math.round( Math.max( 20, ( screen.height - ivPopup_PopupHeight - 40 ) / 2 ) );

		var frameWidth = null;
		var frameHeight = null;
		//--see if we can detect the size of the html-frame (of this web-page)
		if( self.innerWidth ){
			frameWidth = self.innerWidth;
			frameHeight = self.innerHeight;
		} else if( document.documentElement && document.documentElement.clientWidth ){
			frameWidth = document.documentElement.clientWidth;
			frameHeight = document.documentElement.clientHeight;
		} else if( document.body ){
			frameWidth = document.body.clientWidth;
			frameHeight = document.body.clientHeight;
		}
		if( frameHeight ) ivPopup_FrameHeight = frameHeight;
		if( frameWidth && frameHeight ){
			ivPopup_VirtPopupPositionLeft = Math.round( Math.max( 20, ( frameWidth - ivPopup_PopupWidth - 20 ) / 2 ) );
			ivPopup_VirtPopupPositionTop  = Math.round( Math.max( 20, ( frameHeight - ivPopup_PopupHeight - 50 ) / 2 ) );

			//---do not position the popup further down/right than the initially intended position:
			//alert( "intended: "+ivPopup_PositionLeft+",\ncalculated: "+ ivPopup_VirtPopupPositionLeft );
			ivPopup_VirtPopupPositionLeft = Math.round( Math.min( ivPopup_PositionLeft, ivPopup_VirtPopupPositionLeft ) );
			ivPopup_VirtPopupPositionTop  = Math.round( Math.min( ivPopup_PopupPositionTop, ivPopup_VirtPopupPositionTop  ) );
		} else {
			ivPopup_VirtPopupPositionLeft = tmpLeft;
			ivPopup_VirtPopupPositionTop = tmpTop;
		}
	}

}

/**/var ivPopup_onlyOneVirtualPopup = false;

function ivPopup_initialPrint(){
	if( ivPopup_onlyOneVirtualPopup ) return;
	ivPopup_onlyOneVirtualPopup = true;
	document.writeln(
		 '<div style="position:absolute;top:'+ivPopup_PopupPositionTop+'px;left:'+ivPopup_PositionLeft+'px;z-index:9999;display:none;background-image: url(skins/main/img/empty.gif); layer-background-image: url(skins/main/img/empty.gif); border: 1px none #000000; " id="MindTake_VirtPopup" >'
    +'  <table class="IVPopup" border="0" cellspacing="0" cellpadding="0" style="height:18px;">'
    +'    <tr id="MindTake_MaxPopupTitleBar">'
    +'      <th height="18"><img src="skins/main/img/tab_links_oben_popup.gif" border="0"></th>'
    +'      <th class="th_kopf">'
    +'        <table cellspacing="0" cellpadding="0" width="100%">'
    +'          <tr>'
    +'            <th style="text-align:left;vertical-align:center;color:#ffffff;font-size:11pt;font-family:Arial;font-weight:bold;" onmousedown="ivVirtPopup_titleBarMouseDown();" width="100%">'
+'<div style="" id="MindTake_VirtPopupTitle">tipp3 fan.tv Login</div>'
    +'            </th>'
    +'            <th nowrap="nowrap" style="padding-top:2px;"><a href="#" onClick="{ ivPopup_hide(); return false; }"><img src="skins/main/img/icon_close_window.gif" height="10" width="10" border="0" alt="close window" /></a></th>'
    +'          </tr>'
    +'        </table>'
    +'      </th>'
    +'      <th><img src="skins/main/img/tab_rechts_oben_popup.gif" border="0"></th>'
    +'    </tr>'
    +'    <tr id="MindTake_MinPopupTitleBar" style="display:none;">'
    +'      <th height="1"></th>'
    +'      <th>'
    +'        <table cellspacing="0" cellpadding="0" >'
    +'          <tr>'
    +'            <th style="text-align:left;vertical-align:center;" width="100%"><div style="margin-top:3px;margin-left:5;margin-right: 5px;vertical-align:top;" id="MindTake_VirtPopupTitleMin"></div></th>'
    +'            <th nowrap="nowrap"><a href="#" onClick="{ ivPopup_hide(); return false; }"><img src="skins/main/img/icon_close_window.gif" height="1" width="1" border="0" alt="close window" /></a></th>'
    +'          </tr>'
    +'        </table>'
    +'      </th>'
    +'      <th></th>'
    +'    </tr>'
    +'    <tr id="MindTake_PopupBody">'
    +'      <td class="td_links" width="7"></td>'
    +'      <td valign="top" style="background-color:#377600;"><div id="MindTake_PopupBodyContent" style="margin:0px;padding:0px;white-space:normal;"></div>'
    +'      </td>'
    +'      <td class="td_rechts" width="7"></td>'
    +'    </tr>'

    +'    <tr>'
    +'      <td height="8" width="7" valign="top" style="padding:0px;margin:0px;"><b><img src="skins/main/img/tab_links_unten_popup.gif" border="0"></td>'
    +'      <td height="8" valign="top" style="padding:0px;margin:0px;"><img src="skins/main/img/tab_fuss_popup.gif" border="0" width="400" height="8"></td>'
    +'      <td height="8" width="7" valign="top" style="padding:0px;margin:0px;"><img src="skins/main/img/tab_rechts_unten_popup.gif" border="0"></td>'
    +'    </tr>'

    +'  </table>'
    +'</div>'

    +'<div style="position:absolute;top:0px;left:0px;width:1000px;height:'+ ( self.innerHeight ? self.innerHeight : 700 )
    +'px;z-index: 9998;display:none;border:0px;margin:0px;padding:0px;" id="MindTake_DisablePage" >'
    +'<img src="skins/main/img/pixel.gif" width="1000" height="'+ ( self.innerHeight ? self.innerHeight : 700 ) +'" alt="" /></div>'
  );
	if( document.getElementById( 'MindTake_PopupBodyContent' ) ){
		//initBetTicketScrolling( 'MindTake_VirtPopup' );
		//init D&D controller and register eventhandler:
		ivVirtPopup_DnDController = new MtInfVal_DragNDropController();
		document.onmousemove = function( event ){ ivVirtPopup_DnDController.drag( event ); };
		document.onmouseup = function(){ ivVirtPopup_DnDController.dragstop();}
	}

}


function ivPopup_clear(){
	document.getElementById( 'MindTake_PopupBodyContent' ).writebuffer = '';
	document.getElementById( 'MindTake_PopupBodyContent' ).innerHTML = '';
	document.getElementById( 'MindTake_VirtPopupTitle' ).innerHTML = '';
	document.getElementById( 'MindTake_VirtPopupTitleMin' ).innerHTML = '';
}
function ivPopup_writeln( htmlcontent ){
	if( !document.getElementById( 'MindTake_PopupBodyContent' ).writebuffer )
		document.getElementById( 'MindTake_PopupBodyContent' ).writebuffer = htmlcontent;
	else
		document.getElementById( 'MindTake_PopupBodyContent' ).writebuffer += htmlcontent;
}

function ivPopup_setTitle( title ){
	if( document.getElementById( 'MindTake_VirtPopupTitle' ) )
		document.getElementById( 'MindTake_VirtPopupTitle' ).innerHTML = title;
	if( document.getElementById( 'MindTake_VirtPopupTitleMin' ) )
		document.getElementById( 'MindTake_VirtPopupTitleMin' ).innerHTML = title;
	/**/else alert( 'ERROR Title element not found!!' );
}

function ivPopup_showVirtualPopUP( popupURL, title ){
	if( document.getElementById( 'MindTake_PopupBodyContent' ) ){

		//---auto hide virtual popup
		if( ivPopup_autoMinimizeVirtualPopup > 0 )	setTimeout( "ivPopup_autoClose()", ivPopup_autoMinimizeVirtualPopup * 1000 );

		//---fill virtual popup with content and show it:
		ivPopup_writeln(
			'<iframe src="' + popupURL + '"'
			+ ' frameborder="0" scrolling="yes"'
			+ ' border="0" width="'+ivPopup_PopupWidth+'" height="'+ivPopup_PopupHeight+'"'
			+ '></iframe>'
		);

		if( title != null )
				ivPopup_setTitle( title );

		ivPopup_flushShow();
	}
}

function ivPopup_flushShow(){
	document.getElementById( 'MindTake_PopupBodyContent' ).innerHTML = document.getElementById( 'MindTake_PopupBodyContent' ).writebuffer;
	ivPopup_initPopupPosSize();
	ivPopup_maximize();
	if( ivPopup_disableBackground_ ) document.getElementById( 'MindTake_DisablePage' ).style.display='';
	document.getElementById( 'MindTake_VirtPopup' ).style.display='';
}
function ivPopup_hide(){
	if( ivPopup_disableBackground_ ) document.getElementById( 'MindTake_DisablePage' ).style.display='none';
	document.getElementById( 'MindTake_VirtPopup' ).style.display='none';
	ivPopup_autoMinimizeActive = false;
}
function ivPopup_setPos( top, left ){

	var scrollLeft,scrollTop;
	if( self.pageYOffset ){ // all except Explorer
		scrollLeft = self.pageXOffset;
		scrollTop = self.pageYOffset;
	}	else if( document.documentElement && document.documentElement.scrollTop ){ // Explorer 6 Strict
		scrollLeft = document.documentElement.scrollLeft;
		scrollTop = document.documentElement.scrollTop;
	}	else if( document.body ){ // all other Explorers
		scrollLeft = document.body.scrollLeft;
		scrollTop = document.body.scrollTop;
	}

	document.getElementById( 'MindTake_VirtPopup' ).style.top = top + scrollTop;
	document.getElementById( 'MindTake_VirtPopup' ).style.left = left + scrollLeft;
	//document.getElementById( 'MindTake_VirtPopup' ).style.position = "fixed";
}
function ivPopup_minimize(){
	ivPopup_autoMinimizeActive = false;
	document.getElementById( 'MindTake_MinPopupTitleBar' ).style.display='';
	document.getElementById( 'MindTake_MaxPopupTitleBar' ).style.display='none';
	document.getElementById( 'MindTake_PopupBody' ).style.display='none';
	ivPopup_setPos( 5, 5 );
}
function ivPopup_maximize(){
	ivPopup_autoMinimizeActive = false;
	document.getElementById( 'MindTake_MinPopupTitleBar' ).style.display='none';
	document.getElementById( 'MindTake_MaxPopupTitleBar' ).style.display='';
	document.getElementById( 'MindTake_PopupBody' ).style.display='';
	ivPopup_position();
}
function ivPopup_position(){ ivPopup_setPos( ivPopup_VirtPopupPositionTop, ivPopup_VirtPopupPositionLeft ); }
function ivPopup_autoClose(){	if( ivPopup_autoMinimizeActive ) ivPopup_minimize(); }
function MtInfVal_DragNDropController(){
	this.draggedObject_ = null;
	this.dragStartX_ = 0;
	this.dragStartY_ = 0;
	this.mousePosX_ = 0;
	this.mousePosY_ = 0;

	this.preExistingEventHandler_MouseMove = document.onmousemove;
	this.preExistingEventHandler_MouseUp = document.onmouseup;

	this.dragstop = function() { this.draggedObject_ = null; if( this.preExistingEventHandler_MouseUp ) this.preExistingEventHandler_MouseUp(); }
	this.drag = function( event ) {
		this.mousePosX_ = document.all ? window.event.clientX : event.pageX;
		this.mousePosY_ = document.all ? window.event.clientY : event.pageY;
		if( this.draggedObject_ != null) {
			this.draggedObject_.style.left = Math.max( 0, this.mousePosX_ - this.dragStartX_) + "px";
			this.draggedObject_.style.top = Math.max( 0, this.mousePosY_ - this.dragStartY_) + "px";
		}
		//--pass on to external eventhandler:
		if( this.preExistingEventHandler_MouseMove ) this.preExistingEventHandler_MouseMove( event );
	}
	this.dragstart = function( element ){
		this.draggedObject_ = element;
		this.dragStartX_ = this.mousePosX_ - this.draggedObject_.offsetLeft;
		this.dragStartY_ = this.mousePosY_ - this.draggedObject_.offsetTop;
	}

}
function ivVirtPopup_titleBarMouseDown(){
	if( document.getElementById('MindTake_VirtPopup') == null ) return;
	ivVirtPopup_DnDController.dragstart( document.getElementById('MindTake_VirtPopup') );
	ivPopup_autoMinimizeActive = false;
}





//---default GUI Elements:
function ivVirtPopup_printCloseButton(){
	ivPopup_writeln('<a href="javascript:ivPopup_hide();"><img src="img/butt_speichern_ger.gif" border="0" style="margin-top:10px;"></a>');
}


//----------------------------------------------------
//  Class for displaying tables with alternating background-colors for each line
//----------------------------------------------------
function IVAltLineStyle( bgColor, color ){
	this.backgroundColor_ = bgColor;
	this.fontWeight_ = null;
	this.color_ = color;
	this.borderTop_ = "0px solid white";

	this.apply = function( element ){

		if( this.backgroundColor_ != null )
			element.style.backgroundColor = this.backgroundColor_;


		if( this.fontWeight_ != null )
			element.style.fontWeight = this.fontWeight_;

		if( this.color_ != null )
			element.style.color = this.color_;

		if( this.borderTop_ != null )
			element.style.borderTop = this.borderTop_;
	}
	this.toString = function(){
		return "Style{" +
			( this.backgroundColor_ != null ? 'background-color: '+this.backgroundColor_+'; ' : '' ) +
			( this.color_ != null ? 'color: '+this.color_+'; ' : '' ) +
			( this.fontWeight_ != null ? 'font-weight: '+this.fontWeight_+'; ' : '' ) +
			( this.borderTop_ != null ? 'font-weight: '+this.borderTop_+'; ' : '' ) +
			"}";
	}
}
function IVAltLineStyler( ){
	this.increment_ = 0;
	this.debug_ = false;
	this.debugOut_ = '';

	this.altStyles = new Array(
		new IVAltLineStyle( '#FFFFFF' ),
		new IVAltLineStyle( '#EEEEEE' )
	);
	//this.execute = function(){ document.writeln( 'hallo welt' ); }
	/*private*/ this.elementVisible = function( el ){
			/**/if( this.debug_ ) this.debugOut_ += ( 'Node Visible? - ' + ( ( el.style != null && el.style.display == 'none' ) ? 'FALSE' : 'TRUE' ) + '<br />' );
			if( el.style != null && el.style.display == 'none' ) return false;
			return true;
	}
	this.execFor = function( rootElementID ){
		if( this.debug_ ) this.debugOut_ = '';
		this.increment_ = 0;
		var el;
		el = document.getElementById( rootElementID );
		if( !el ) return;
		if( el.nodeName == 'UL' ){
			/**/if( this.debug_ ) this.debugOut_ += ( 'Found UL-RootTag do Reorganizing<br />' );
			this.doAltColorOnULTable( el, 0 );
		}
		if( el.nodeName == 'DIV' ){
			/**/if( this.debug_ ) this.debugOut_ += ( 'Found DIV-RootTag do Reorganizing<br />' );
			this.doAltColorOnDIVTable( el );
		}
		if( this.debug_ ){
			out = window.open( '', 'meins', '' );
			out.document.writeln( '<br /><br ><div style="border: 1px solid red;">' + this.debugOut_ + '</div>');
			out.focus();
	}


	}
	/*protected*/ this.doAltColorOnDIVTable = function( rootElementID ){
		/**/if( this.debug_ ) this.debugOut_ += ( '<hr>Recurse with: '+rootElementID.nodeName+"<br />" );
		var node;

		for( node = rootElementID.firstChild; node != null; node = node.nextSibling ){
			if( node.nodeName != 'DIV' ) continue;
			if( !this.elementVisible( node ) ) continue;
			/**/if( this.debug_ ) this.debugOut_ += ("Iterate to Tag:<b>" + node.nodeName + "<\/b><br>");
			var subNode;
			var foundSubDiv;
			foundSubDiv = false;
			//--check if this node has DIVS in it, if so recurse because only the "Leave-Div-Tags" shall be reformatted:
			if( node.hasChildNodes() )
				for( subNode = node.firstChild; subNode != null; subNode = subNode.nextSibling ){
					/**/if( this.debug_ ) this.debugOut_ += ( 'checking subnode: <b>' + subNode.nodeName + "</b>" + ( subNode.nodeName == 'P' ? 'PCont['+subNode.innerHTML+']' : '' ) + "<br />" );

					if( subNode.nodeName == 'DIV' ){
						this.doAltColorOnDIVTable( node );
						foundSubDiv = true;
					}

				}
			if( !foundSubDiv ){
				//--if there were no child DIV tags, use this one to set alternate style:
				/**/if( this.debug_ ) this.debugOut_ += ( 'no child divtags found: change style<br />' );
				this.altStyles[ this.increment_++ % this.altStyles.length ].apply( node );
			}

		}

	}


	/*protected*/this.doAltColorOnULTable = function( rootElementID ){
		/**/if( this.debug_ ) this.debugOut_ += ( '<div style="border: 1px solid #c8c8c8; margin-left: 10px;">FOUND: '+rootElementID.nodeName+"<br />" );
		var node;

		for( node = rootElementID.firstChild; node != null; node = node.nextSibling ){
			if( node.nodeName != 'LI' ) continue;
			/**/if( this.debug_ ) this.debugOut_ +=("Einen node mit dem Namen <b>" + node.nodeName + "<\/b><br>");
			//document.write("Assign Style [ "+( this.increment_++ % this.altStyles.length )+"]<br >");
			/**/if( this.debug_ ) this.debugOut_ += ( "Assign Style(" + this.altStyles[ ( this.increment_ + 1 ) % this.altStyles.length ].toString() +")<br />"	);
			this.altStyles[ this.increment_++ % this.altStyles.length ].apply( node );
			var subNode;
			//--check if this node has ULs in it, if so recurse:
			if( node.hasChildNodes() )
				for( subNode = node.firstChild; subNode != null; subNode = subNode.nextSibling ){
					/**/if( this.debug_ ) this.debugOut_ += ( 'checking subnode: <b>' + subNode.nodeName + "</b><br />" );
					if( subNode.nodeName == 'UL' && this.elementVisible( subNode ) )
						this.doAltColorOnULTable( subNode );
				}

		}
		/**/if( this.debug_ ) this.debugOut_ += ( '</div>' );

	}
}

//----------------------------------------------------
//-- standard alternating color formatter
var stdAltLineStyler = new IVAltLineStyler();


//----------------------------------------------------

//---- Other Functions:

var expandedFolder = new Image();
expandedFolder.src = "img/symb_ordner_pos.gif";
var contractedFolder = new Image();
contractedFolder.src = "img/symb_ordner_neg.gif";

function swapVisibility( elementID ){

	var expandContractSymbolID;
	expandContractSymbolID = elementID + 'expSym';

	if( document.getElementById( elementID ) && document.getElementById( elementID ).style ){
		document.getElementById( elementID ).style.display= (  document.getElementById( elementID ).style.display == 'none' ? '' : 'none' );
		if( document.getElementById( expandContractSymbolID ) ){
				//alert( "Image" + document.getElementById( expandContractSymbolID ).src );
				//var vorher;
				//vorher = document.getElementById( expandContractSymbolID ).src;
				document.getElementById( expandContractSymbolID ).src = (
						document.getElementById( elementID ).style.display == 'none'
						? contractedFolder.src
						: expandedFolder.src
				);
				//document.getElementById( expandContractSymbolID ).style.borderTop = '5px solid red;';
				//alert( 'vorher: ' + vorher + "\nnachher: " + document.getElementById( expandContractSymbolID ).src );


		}

		return true;
	} return false;
}

