//-- 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 = 300; //in pixel
var ivPopup_PopupHeight = 300; //in pixel;
var ivPopup_ShowPopupInTheMiddleOfTheScreen = false; // the Popup Window will be displayed in the middle of the screen
var ivPopup_PopupPositionTop = 300; //default position X (note: if ivPopup_ShowPopupInTheMiddleOfTheScreen is set this will have no effect!)
var ivPopup_PositionLeft = 0; //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;
var ivPopup_imgTopLeft = 'coolaustria/images/tab_links_oben_popup_ecard.gif';
var ivPopup_imgTopRight = 'coolaustria/images/tab_rechts_oben_popup_ecard.gif';
var ivPopup_imgBottomLeft = 'coolaustria/images/tab_links_unten_popup_ecard.gif';
var ivPopup_imgBottomRight = 'coolaustria/images/tab_rechts_unten_popup_ecard.gif';
var ivPopup_imgTop = 'coolaustria/images/tab_kopf_popup_ecard.gif';
var ivPopup_imgRight = 'coolaustria/images/tab_rechts_popup_ecard.gif';
var ivPopup_imgBottom = 'coolaustria/images/tab_fuss_popup_ecard.gif';
var ivPopup_imgLeft = 'coolaustria/images/tab_links_popup_ecard.gif';
var ivPopup_styleHead = 'ivPopup_Head_ecard';

var ivPopup_imgWidth = 0; //in pixel
var ivPopup_imgHeight = 0; //in pixel;

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

//---- 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;
	//absolute;top:'+ivPopup_PopupPositionTop+'px;left:'+ivPopup_PositionLeft+'px;

	document.writeln(
		'<div style="position: absolute; left: 0px; top: 0px; width:100%; height:100%; z-index:9995; display:none;" id="MindTake_VirtPopup">'
				+'<div id="popup_opacity" style="position: fixed; left: 0; top: 0; width:100%; height:100%; z-index:9995; background-color: #000000; "></div>'
				+'<div style="position: absolute; z-index:9999;left: 0px; top: 300px;width:100%;"><div id="virPopup_Frame" style="padding:20px"><table border="0" cellspacing="0" cellpadding="0" style="margin:auto;background-color: #FFFFFF; width: 1;">'
					+'  <tr>'
						+'<td scope="row">'
							+'<div style="padding: 25px;">'
								+'<div id="MindTake_PopupBodyContent"></div>'
							+'</div>'
						+'</td>'
					+'</tr>'
					+'<tr>'
						+'<td scope="row" style="padding: 0 25px 0 25px;">'
    						+'<div style="font-size:1px;height:5px; display: none;" id="MindTake_VirtPopupTitle">&nbsp;</div>'
							+'<div id="MindTake_VirtPopupTitleMin"></div>'
    					+'</td>'
  					+'</tr>'
					+'<tr>'
						+'<td scope="row">'
							+'<div style="text-align: right; padding: 0px 25px 25px;"><a href="#" onClick="{ ivPopup_hide(); return false; }"><img src="coolaustria/images2/close.jpg" width="27" height="26" border=0 /></a></div>'
						+'</td>'
					+'</tr>'
				+'</table></div></div>'
		+'</div>'
		+'<div style="position:absolute;top:0px;left:0px;width:1000px;height:'+ ( self.innerHeight ? self.innerHeight : 700 )
    	+'px;z-index: 9993;display:none;border:0px;margin:0px;padding:0px;" id="MindTake_DisablePage" >'
    	+'<img src="coolaustria/images/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="10" 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 setPos(top, left){
	ivPopup_VirtPopupPositionTop = top; //default position X (note: if ivPopup_ShowPopupInTheMiddleOfTheScreen is set this will have no effect!)
	ivPopup_VirtPopupPositionLeft = left;	
}


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.marginTop = "-"+top+"px";
	//document.getElementById( 'MindTake_VirtPopup' ).style.top = top+"px";
	//document.getElementById( 'MindTake_VirtPopup' ).style.left = left+"px";
	//document.getElementById( 'MindTake_VirtPopup' ).style.marginLeft = "-"+left+"px";
	//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;
}

