// --- TOOLS --------




/**
 * schaltet ein per ID übergebenes Objekt auf sichtbar/unsichtbar
 * je nachdem welchen zustand es vorher hatte: invertiert.
 *
 */
function expCollDropdown( sId ) {
	oObject = document.getElementById( 'dd_'+sId );
	if ( oObject.style.display == 'none' ) {
		oObject.style.display = 'block';
		changeImages( 'arrow_'+sId, '/_img/buttons/btn.arrowclose.gif' );
	} else {
		oObject.style.display = 'none';
		changeImages( 'arrow_'+sId, '/_img/buttons/btn.arrowopen.gif' );
	}	
}


/**
 * @version 1.00; 09.01.2006; kk; Initial.
 *
 * @returns boolean Liefert True oder False je nachdem ob ein 
 *                  übergebener Wert in einem Array drin ist oder nicht.
 *
 */
function inArray( xFoo, aArray ) {
	for( var i = 0; i < aArray.length; i++ ) {
		if( aArray[ i ] == xFoo ) {
			return true;
			
		}
	}
	return false;
}


/**
 * Öffnet ein neues Popup-Fenster.
 *
 * @version 1.00; 18.12.2005; kk; Initial.
 */
function newWindow(mypage, myname, w, h, scroll, status) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+(scroll ? 'yes' : 'no' )+',resizable=no,status='+(status ? 'yes' : 'no' );
  win = window.open(mypage, myname, winprops);
  if( parseInt( navigator.appVersion ) >= 4 ) {
		win.window.focus();
	}
}

/**
 * Öffnet ein neues Popup-Fenster.
 *
 * @version 1.00; 18.12.2005; kk; Initial.
 */
function newWindow2(mypage, myname, w, h, scroll ) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+(scroll ? 'yes' : 'no' )+',resizable=yes, menubar=no, status=no, toolbar=no, directories=no';
//   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+(scroll ? 'yes' : 'no' )+',resizable=yes, menubar=yes, status=yes, toolbar=yes, directories=yes';
  win = window.open(mypage, myname, winprops);
  if( parseInt( navigator.appVersion ) >= 4 ) {
		win.window.focus();
	}
}
/**
 * Breite und Höhe des aktuellen Anzeigebereichs bestimmen.
 *
 * @version 1.00; 10.01.2006; kk; Angepasst http://www.quirksmode.org/viewport/compatibility.html#link2
 *
 * @returns Ein Array mit den aktuellen Dimensionen.
 */
function getInnerDimensions() {
	var x, y;
	
	// all except Explorer
	if( self.innerHeight ) {
		x = self.innerWidth;
		y = self.innerHeight;
	
	// Explorer 6 Strict Mode
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	
	// other Explorers
	} else if( document.body ) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
		
	}
	
	return new Array( x, y );
}


/**
 * Breite des aktuellen Anzeigebereichs bestimmen.
 *
 * @version 1.00; 10.01.2006; kk; Initial.
 */
function getInnerWidth() {
	aDim = getInnerDimensions();
	return aDim[ 0 ];
}


/**
 * Höhe des aktuellen Anzeigebereichs bestimmen.
 *
 * @version 1.00; 10.01.2006; kk; Initial.
 */
function getInnerHeight() {
	aDim = getInnerDimensions();
	return aDim[ 1 ];
}


/**
 * Liefert Breite und Höhe der Seite (des Body-Elements).
 *
 * @version 1.00; 10.01.2006; kk; Angepasst http://www.quirksmode.org/viewport/compatibility.html#link2
 *
 * @returns Ein Array mit den aktuellen Dimensionen.
 */
function getPageDimensions() {
	var x, y;
	
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	
	 // all but Explorer Mac
	if( test1 > test2 ) {
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	
	// Explorer Mac;
	// would also work in Explorer 6 Strict, Mozilla and Safari
	} else {
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
		
	}
	
	return new Array( x, y );
}


/**
 * Breite des aktuellen body-Elements bestimmen.
 *
 * @version 1.00; 10.01.2006; kk; Initial.
 */
function getPageWidth() {
	aDim = getPageDimensions();
	return aDim[ 0 ];
}


/**
 * Höhe des aktuellen body-Elements bestimmen.
 *
 * @version 1.00; 10.01.2006; kk; Initial.
 */
function getPageHeight() {
	aDim = getPageDimensions();
	return aDim[ 1 ];
}


// --- BILDERSWAPPING --------

/**
 * Läd ein Image nach (für Onover-Effekte notwenig).
 *
 * @version 1.00; 18.12.2005; kk; Initial.
 */
function newImage( arg ) {
	if( document.images ) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}


/**
 * Wechselt ein Image, oder aber auch mehrere Images (einfach mehr Parameter übergeben)
 * bei onover-Effekten.
 *
 * @version 1.00; 18.12.2005; kk; Initial.
 */
function changeImages() {
	if( document.images && ( preloadFlag == true ) ) {
		for( var i = 0; i < changeImages.arguments.length; i += 2 ) {
			document.getElementById( changeImages.arguments[ i ] ).src = changeImages.arguments[ i + 1 ];
		}
	}
}


// --- FILE UPLOADS --------

/**
 * Dies hier ist die Statusleiste bei einem Upload.
 */
var UPLOADER_POST_LOCATION = "/utils/upload.progress.php";


/**
 * VON MEGAUPLOADER: einfache Prüfung, dass bestimmte Dateitypen nicht 
 * hochgeladen werden.
 *
 * Bei dieser Variante muss das zu belesene Formular angegeben werden.
 *
 * @param sFormName Name des Formulars.
 *
 * @version 1.00; 28.12.2005; kk; Aus Megauploader extrahiert und für uns angepasst.
 */
function check_types( sFormName ) {
	oForm = document.getElementsByName( sFormName )[0];
	
	for( i = 0; i < oForm.elements.length; i++ ) {
		if( oForm.elements[ i ].value.match( /^(\.php)|(\.sh)/ ) ) {
			alert( 'Sorry ' + oForm.elements[ i ].value + ' is not allowed.' );
			return false;
		}
	}

	return true;
}


/**
 * VON MEGAUPLOADER: Startet den Upload.
 *
 * Bei dieser Variante muss das zu belesene Formular angegeben werden.
 *
 * @param sFormName Name des Formulars.
 *
 * @version 1.00; 28.12.2005; kk; Aus Megauploader extrahiert und für uns angepasst.
 */
function postIt( sFormName ) {
	if( check_types( sFormName ) == false ) {
		return false;
	}

	baseUrl = UPLOADER_POST_LOCATION;
	sid = oForm.usid.value;
	iTotal = escape("-1");
	baseUrl += "?iTotal=" + iTotal;
	baseUrl += "&iRead=0";
	baseUrl += "&iStatus=1";
	baseUrl += "&usid=" + sid;

	newWindow( baseUrl, "Uploader", 254, 400, false, false );
	oForm.submit();
}


// --- TOOLTIPS --------

/*
 * Hier wird der aktuell angezeigte Tooltip gespeichert.
 */
var oCurrentTooltipp = null;


/**
 * Zeigt einen Tooltip an (ändert Sichtbarkeit).
 *
 * @param iId Die ID des Tooltips (wie einfefügt).
 *
 * @version 1.00; 03.01.2006; kk; Adaption von http://www.webmatze.de/webdesign/javascript/tooltips.htm
 */
function showTooltipp( sId ) {
	document.onmousemove = updateTooltipp;
	
	oCurrentTooltipp = document.getElementById( sId );
	oCurrentTooltipp.style.display = 'block';

}


/**
 * Bewegt einen Tooltip mit der Maus mit. Wird gecallbackt 
 * wenn die Maus über einen Tooltip ist.
 *
 * @param oEvent Das Event
 */
function updateTooltipp( oEvent ) {
	
	var winW = null;
	var winH = null;
	
	x = (document.all) 
		? window.event.x + document.body.scrollLeft 
		: oEvent.pageX;
		
	y = (document.all) 
		? window.event.y + document.body.scrollTop  
		: oEvent.pageY;
	
	winW = window.innerWidth;
//	winH = window.innerHeight;
	
	if ( navigator.appName.indexOf( "Microsoft" ) != -1 ) {
		winW = document.body.offsetWidth;
//		winH = document.body.offsetHeight;
	}
	
	if( oCurrentTooltipp != null ) {
		// oCurrentTooltipp.style.left = ( x + 20 ) + 'px';
		
//		document.getElementById('tooltipdebug').innerHTML = 
//			//'width: '+winW+', x: '+x+', '+(x+200);
//			winH+' '+(y + oCurrentTooltipp.offsetHeight);
		
		if( ( x + 220 ) > winW ) {
			oCurrentTooltipp.style.left = ( x - 210  ) + 'px';
		} else {
			oCurrentTooltipp.style.left = ( x + 10  ) + 'px';
		}
		
		
		oCurrentTooltipp.style.top  = ( y - 13 ) + 'px';		
	}
}


/**
 * Versteckt einen aktiven Tooltip wieder.
 *
 */
function hideTooltipp() {
	oCurrentTooltipp.style.display = 'none';
	
	document.onmousemove = null;
}



// --- PLEASE WAIT BOX --------

/**
 * Zeit die Bitte Warten Box an.
 *
 */
function showPleaseWaitBox() {
	if( document.getElementById( 'pleasewaitbox' ) != null ) {
		
		document.getElementById( 'pleasewaitbox' ).style.left = ( getPageWidth() / 2  - 125 ) + 'px';
		document.getElementById( 'pleasewaitbox' ).style.top = ( getInnerHeight() / 2 - 150 ) + 'px';
	
		document.getElementById( 'pleasewaitbox' ).style.display = 'block';
		
		document.getElementById( 'alphaimg' ).height = getPageHeight();
		
		document.getElementById( 'alpha' ).style.left = getPageWidth() / 2 - 390;
		document.getElementById( 'alpha' ).style.top = '0px';
		//document.getElementById( 'alpha' ).style.border = 'solid red 1px';
		
		document.getElementById( 'alpha' ).style.display = 'block';
	}
		
}
