/* TODO: REPLACE ADOBE SCRIPT WITH OWN ONE  */

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// Tooltips
tt = null;
function updatett(e) {
  if (tt != null) {

   tt.style.left   = (-45) + "px";

  }
}

function showtt(id) {
  tt = document.getElementById(id);
  tt.style.display = "block"
}

function hidett() {
  tt.style.display = "none";
}


// Flash Gallery
function fgToggleGallery() {
    thisMovie("flashgallery").fgToggleGallery();
}

function fgToggleDisplayMode() {
    thisMovie("flashgallery").fgToggleDisplayMode();
}

function fgNextImage() {
    thisMovie("flashgallery").fgNextImage();
}

function fgPreviousImage() {
    thisMovie("flashgallery").fgPreviousImage();
}

/*
Passes the ID of the album from the XML file
we want SlideShowPro inside the SWF to load
*/
function fgLoadAlbum(album) {
    thisMovie("flashgallery").fgLoadAlbum(album);
}

function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName]
} else {
    return document[movieName]
}
}

function changeFlashHeight(id, newH, gal_id, maskid){
	document.getElementById(id).style.height = newH+"px";
	if(maskid){
		loadContentDetails(gal_id,maskid);
	}
}
function flashPutHref(href) {
	location.href = href;
}
function flashReload() {
	document.location.reload();
}
// END FLASH GALLERY

function openTerms(){
	window.open("/popup/terms", "_blank", "top=100,left=100,width=690,height=550,scrollbars=yes");
}
function openImprint(){
	window.open("/popup/imprint", "_blank", "top=100,left=100,width=690,height=290,scrollbars=yes");
}
function openDataPrivacy(){
	window.open("/popup/dataprivacy", "_blank", "top=100,left=100,width=690,height=550,scrollbars=yes");
}

// Layers
function openFinishSignup(){
	AJAX.load("FinishSignup", "new", "");
}
function openSignupReminderLayer(){
	AJAX.load("SignupReminderLayer", "new", "");
}

// Message system
function writeMessage(to_username){
	AJAX.load("WriteMessage", "new", "to="+to_username);
}

function replyMessage(message_id){
	AJAX.load("ReplyMessage", "reply", "msgid="+message_id);
}

function markMessage(module_id, message_id){
	AJAX.load(module_id, "mark", "msgid="+message_id);
}

function unmarkMessage(module_id, message_id){
	AJAX.load(module_id, "unmark", "msgid="+message_id);
}

function markAllMessages(module_id){
	AJAX.load(module_id, "markAll", "");
}

function unmarkAllMessages(module_id){
	AJAX.load(module_id, "unmarkAll", "");
}

function moveMessage(module_id, message_id, dest){
	if(confirm('Soll diese Nachricht wirklich verschoben werden?')){
		AJAX.load(module_id, "movemsg", "msgid=" + message_id + "&dest=" + dest);
	}
}

function moveMessages(module_id, dest){
	var select = document.getElementById(module_id + '_action');
	if(confirm('Sollen die markierten Nachrichten wirklich verschoben werden?')){
		AJAX.load(module_id, "movemsgs", "dest=" + dest);
	}
	if(select) select.value = "";
}

function moveOutMessage(module_id, message_id, dest){
	if(confirm('Soll diese Nachricht wirklich verschoben werden?')){
		AJAX.load(module_id, "moveoutmsg", "msgid=" + message_id + "&dest=" + dest);
	}
}

function moveOutMessages(module_id, dest){
	var select = document.getElementById(module_id + '_action');
	if(confirm('Sollen die markierten Nachrichten wirklich verschoben werden?')){
		AJAX.load(module_id, "moveoutmsgs", "dest=" + dest);
	}
	if(select) select.value = "";
}


// Notification system

function writeComplaintNote(record_type, record_id){
	AJAX.load("ComplaintNote", "new", "rtype=" + record_type + "&rid=" + record_id);
}

// Beta Reporting Box As Layer
function openBetaReportingLayer(){
	AJAX.load("BetaReportingLayer","show_box","");
}

// Friends invitation as layer?
function openFriendsInvitationLayer(){
	AJAX.load("InviteFriendsBL","new","");
}

function showUserImage(user_id, action){

	AJAX.load("ShowUserImage",action,"user_id="+ user_id);

}




//mail content

function mailContent(record_type, record_id){
	AJAX.load("mailContent", "new", "rtype=" + record_type + "&rid=" + record_id);
}

//invite friend
function potentialFriends(to_username){
	AJAX.load("PotentialFriends", "new" );
}

function submitenter(myfield,e){
	var keycode;

	if (window.event)
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	else
		return true;

	if (keycode == 13) {
   		myfield.form.submit();
   		return false;
	} else return true;
}


// Privacy
function switchdisplay(id) {

	if (document.getElementById) {
		if(document.getElementById(id).style.display == 'none') {
			document.getElementById(id).style.display = 'block';
		} else {
			document.getElementById(id).style.display = 'none';
		}
	} else {
		if (document.layers) { 					// Netscape 4
			if(document.id.display == 'none'){
				document.id.display = 'block';
			} else {
				document.id.display = 'none';
			}
		}
	}
}


//-------------------			ETC 		-------------------------//

function getElementPos(element_id){
	var top  = 0;
	var left = 0;
	var offsetTop = 0;
	var offsetLeft = 0;
	var Element = document.getElementById(element_id);
	if(!Element) return false;
	while (Element.offsetParent){
		offsetTop = Element.offsetTop;
		offsetLeft = Element.offsetLeft;

		if(offsetTop<0){
			// IE BUG
			offsetTop = (Element.offsetParent.offsetHeight+offsetTop)-Element.offsetHeight;
		}
		if(offsetLeft<0){
			// IE BUG
			offsetLeft = (Element.offsetParent.offsetWidth+offsetLeft)-Element.offsetWidth;
		}
		//this.left += Element.offsetLeft - Element.scrollLeft;
		// Element.offsetTop - Element.scrollTop;

		left += offsetLeft;
		top  += offsetTop;
		Element = Element.offsetParent;
	}
	left += Element.offsetLeft;
	top  += Element.offsetTop;
	return {top: top, left: left}
}



//-------------------			TOOL TIP 		-------------------------//
var TOOLTIP;

function openTooltip(parent_element_id, rel_x, rel_y, content){
	if(!TOOLTIP){
		// Setup tooltip element
		TOOLTIP = document.createElement("div");
		TOOLTIP.style.position = "absolute";
		TOOLTIP.style.top = "10px";
		TOOLTIP.style.left = "10px";
		TOOLTIP.style.display = "NONE";
		document.getElementsByTagName("body")[0].appendChild(TOOLTIP);
	}

	var pos = getElementPos(parent_element_id);
	alert(pos.top + ' ' + pos.left);
	TOOLTIP.innerHTML = content;
	TOOLTIP.style.display = "BLOCK";
}

function closeTootip(){
	if(TOOLTIP){
		TOOLTIP.style.display = "none";
		TOOLTIP.innerhtml = "";
	}
}



//-------------------			ADMIN AREA 		-------------------------//


//user report (Anmerkungen die von Usern bzg. des Contents abgegeben wurden)
function showUserReport(user_id){
	AJAX.load("ShowUserReportBL", "showUserReport","user_id=" + user_id );
}
//admins reports (nur für interne zwecke, zB. Anmerkungen zum Content oder User)
function showAdminReport(user_id){
	AJAX.load("ShowUserReportBL","showAdminReport","user_id="+user_id);
}
//zeigt content details an und erlaubt änderungen des Contents
function showContentDetails(content_id){
	AJAX.load("ShowUserReportBL", "showEncoderConflicts", "content_id="+content_id);
}
//confirmation window
function showConfirmationWindow(user_id,email,username){
	AJAX.load("ShowUserReportBL", "showConfirmation" , "user_id=" + user_id + "&email="+ email + "&username=" + username);
}



//----------------------------- resize preview pictures  or better resizing it by style sheets---------------------------------//
var resizeDelay = 0;
var resizeIncrement = 5;
var ImgCache  = new Object();

function resizeThumbImg(ImgElement, percentChange, RolloverImage){

   var per = (percentChange) ? (percentChange / 100) : 1;
   var cacheTag = ImgElement.src;

   var checkCache = ImgCache[cacheTag];
   if(!checkCache){
	  	ImgCache[cacheTag] =  new Array(new createThumbImg(ImgElement,percentChange)); //set details to object => ImgCache
   }else{
    	ImgCache[cacheTag][0].pct = per;
   }
  resizeImgGradual(cacheTag);

  return true;
}


function createThumbImg(ImgElement, percentChange, increment){

  increment = (!increment) ? resizeIncrement : 1;

  var h = ImgElement.height;
  var w = ImgElement.width;

  this.img = ImgElement;
  this.originalSrc = ImgElement.src;
  //start size
  this.originalWidth = w;
  this.originalHeight = h;
  //increment by value
  this.heightIncrement = Math.ceil(Math.min(1, (h/w)) * increment);
  this.widthIncrement  = Math.ceil(Math.min(1, (w/ h)) * increment);

  this.inc = increment;
  this.pct = (percentChange) ? percentChange / 100 : 1;

}

function resizeImgGradual(cacheTag){

	var val = ImgCache[cacheTag];
	if(!val) return false;

   var CacheImgObj = val[0];

   var Element = CacheImgObj.img;
   var pct = CacheImgObj.pct
   var plusMinus = (pct > 1) ? 1 : -1;

   var h_inc = plusMinus * CacheImgObj.heightIncrement;
   var w_inc = plusMinus * CacheImgObj.widthIncrement;

   var current_height = Element.height;
   var current_width = Element.width;

   var startHeight = CacheImgObj.originalHeight;
   var startWidth = CacheImgObj.originalWidth;

   var endHeight = Math.round(startHeight * pct);
   var endWidth = Math.round(startWidth * pct);

   if ((current_height == endHeight) || (current_width == endWidth ) ){
   	  return true;
   }

   //increase or decrease
   var new_height = current_height + h_inc;
   var new_width = current_width + w_inc;

   if (pct > 1) {
		if ((new_height >= endHeight) || (new_width >= endWidth)) {
			new_height = endHeight;
			new_width = endWidth;
		}
	} else {
		if ((new_height <= endHeight) || (new_width <= endWidth)) {
			new_height = endHeight;
			new_width = endWidth;
		}
	}

   Element.width = new_width;
   Element.height = new_height;

   if( (new_height == Element.originalHeight) || (new_width == Element.originalWidth)){
   		Element.src = ImgCache.originalSrc;
	}

   setTimeout("resizeImgGradual('"+ cacheTag +"')", resizeDelay);

}

//resize video thumbnails, (load appropriate image do not resize the current!!!)

function loadPreviewThumbnail(image){

	document.getElementById('bigimage').innerHTML='<img width="300" height="240" src="/admincontent/previewpic/' + image + '" />';
}

function restorePreviewThumbnail(image){

	document.getElementById('bigimage').innerHTML='';
 }


function openstep(module_id, step){
	var element;
	for(var i=1;i<6;i++){
		element = document.getElementById(module_id + '_step' +i);
		if(element)
			element.style.display="none";
	}
	document.getElementById(module_id + '_step' + step).style.display="block";
	return false;
}

//----------------	progressbar testonly  ------------------------------//

/*function sendRequestProgressBar(){
	showProgressBar('progressbar');
}

function showProgressBar(id){
	 replace_html(id, '<img src="http://images.code-head.com/progress-bars/44.gif" border="0" alt="Loading, please wait..."/>');
}

function replace_html(id,content){
	document.getElementById(id).innerHTML = content;
}




var progress = new Image();
progress.src = '/home/cf/Desktop/17.gif';*/

