function hidePubApp(cp_pk) {
	// {{{
	if(document.getElementById('addPubApp_'+cp_pk)) {
		$('#addPubApp_'+cp_pk).hide();
	}
	// }}}
}

function updatePubApp(cp_pk,ca_pk) {
	// {{{
	id = "pubAppOut_"+cp_pk+"_"+ca_pk;
	if(document.getElementById(id)) {
		setTimeout("xajax_refreshPubAppOutput("+cp_pk+","+ca_pk+");", 1000);
	}
	// }}}
}

function hideShow(b1, b2) {
	// {{{
	if(!document.getElementById(b1)) {
		alert(b1+ ' nicht vorhanden' );
		return;
	}
	if(!document.getElementById(b2)) {
		alert(b2+ ' nicht vorhanden' );
		return;
	}
	$('#'+b1).hide('fast');
	$('#'+b2).show('fast');
	//new Effect.Fade(b1, {duration:0.2, queue: 'end'});
	//new Effect.Appear(b2, {duration:0.2, queue: 'end'});
	// }}}
}

var lastEditButtonsId = '';
function showEditButtons(id) {
	// {{{
	if(lastEditButtonsId==id) return;
	if(lastEditButtonsId!='') {
		//new Effect.Fade('c3_'+lastEditButtonsId, {duration: 0.2, queue: 'end'});
		document.getElementById('c3_'+lastEditButtonsId).style.display = 'none';
		document.getElementById('c2_'+lastEditButtonsId).style.borderBottom="1px solid white"; 
		lastEditButtonsId = '';
	}
	document.getElementById('c2_'+id).style.borderBottom="1px solid #FFD493";
	//new Effect.Appear('c3_'+id, {duration:0.2, queue: 'end'});
	document.getElementById('c3_'+id).style.display = 'block';
	lastEditButtonsId = id;
	// }}}
}
function addNewFile(id, file, view) {
	// {{{
	document.getElementById('filelist_'+id).value += "|uploads/"+file;
	var f = document.getElementById('filelist_'+id).value.split('|');
	var html = "";
	var img = "";
	for(var i=0;i<f.length;i++) {
		if(f[i]!='') {
			if(view=='single') img = '';
			var ext = f[i].substring(f[i].lastIndexOf(".")).toLowerCase();
			if(ext==".jpg" || ext==".png" || ext==".gif") {
				img += "<img src='"+dataDir+f[i]+"' width=150><br/>";
			} else {
				var dn = f[i];
				dn = dn.substring(19);
				img += "Datei: "+dn+"<br>"; 
			}
			
		}
	}
	html += img;
	document.getElementById('upload_'+id).innerHTML = html;
	// }}}
}

function goToViewPoint(id,lat,lng,zoom) {
	// {{{
	GEvent.trigger(marker[id],'click');
	viewMap.setCenter(new GLatLng(lat,lng),zoom*1);
	// }}}
}

var myLytebox = "";
function callPopup(modul, method, param) {
	// {{{
	
	var L = pageLink+"popup";
	if(modul) L += "/"+modul;
	if(method) L += "/"+method;
	if(param) L += "/"+param;
	document.getElementById('popuplink').href = L;
	//alert($('popuplink').href);
	//$('popuplink').click();
	myLytebox = new LyteBox(); 
	myLytebox.start(document.getElementById('popuplink'), false, true);
	// }}}
}
function laterfocus(id, time) {
	// {{{
	setTimeout("$('#"+id+"').focus();", time);
	// }}}
}

function openclose(closeObj, openObj) {
	// {{{
	if(closeObj=='') {
		$('#'+openObj).show();
	} else if(closeObj=='') { 
		$('#'+closeObj).hide();
	} else {
		$('#'+closeObj).hide();
		$('#'+openObj).show();
	}
	// }}}
}

function resizeTextArea(obj) {
	// {{{
	var lines = obj.value.split("\n");
	var extra = 0;


        //var dim = $(obj).getDimensions();

        w = $(obj).width;
        var maxLineLength = Math.round(w/20);

        for(var i=0;i<lines.length;i++) {
            while(lines[i].length>maxLineLength) {
                extra++;
                lines[i] = lines[i].substr(maxLineLength);
            }
        }
        var h = $(obj).height();
	/*
        var h = obj.style.height+"";
	h = h.replace("px", "");
	h = h*1;
        */

        var ll = lines.length*1 + extra;

	if(ll<3) ll=3;
	if(ll>30) ll=30;
	
	if(h<ll*14) {
		$(obj).height(14*ll);
	}
	if(h>ll*14+50) {
		$(obj).height(14*ll);
	}
	// }}}
}

function previewtags(inputFieldId, divId) {
	// {{{
	xajax_findSimilarTag(divId, inputFieldId , document.getElementById(inputFieldId).value);
	// }}}
}

function setVorschlagTag(oldTag, newTag, inputFieldId, id) {
	// {{{
	//alert('tagsinput_'+id);
	document.getElementById(inputFieldId).value = document.getElementById(inputFieldId).value.replace(oldTag,newTag);
	previewtags(inputFieldId,id);
	//$('tagsinput_'+id).focus();
	// }}}
}

function getScrollPos() {
	var ScrollTop = document.body.scrollTop;

	if (ScrollTop == 0) {
	    if (window.pageYOffset)
		ScrollTop = window.pageYOffset;
	    else
		ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return(ScrollTop);
}

function getInnerHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return(myHeight);
}

function getDocumentHeight(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return yWithScroll;
}

var openDiv = 'indexinfo';
function doOpenSearch() {
	// {{{
	if(openDiv=='indexinfo') {
		openDiv = 'indexsearch';
		$('#indexinfo').hide();
		$('#indexsearch').show();
	}
	// }}}
}
function doCloseSearch() {
	// {{{
	if(openDiv=='indexsearch') {
		openDiv = 'indexinfo';
		$('#indexsearch').hide();
		$('#indexinfo').show();
	}
	// }}}
}
function doReduceToGroup(cg_pk) {
	// {{{
	refreshPinnwandFeedlist(lastRPF_tag,lastRPF_search,lastRPF_special,cg_pk,lastRPF_add);
	// }}}
}

var lastRPF_tag = '';
var lastRPF_search = '';
var lastRPF_special = '';
var lastRPF_group = '';
var lastRPF_add = '';
function refreshPinnwandFeedlist(tag,search,special,group,add) {
	// {{{
	lastRPF_tag = tag;
	lastRPF_search = search;
	lastRPF_special = special;
	lastRPF_group = group;
	lastRPF_add = add;
	xajax_refreshPinnwandFeedlist(tag,search,special,group,add);
	if(tag!='') {
		//alert(tag);
		$('#infosearch').val(tag);
	}
	// }}}
}


// Fuss-Userleiste
// <!-- http://csscreator.com/node/33027 -->
var wiob_open = false;
function openclose_wiob() {
        // {{{
        if(!wiob_open) {
                wiob_open=true;
                $('#wiob_list').show();
                xajax_refreshUserList();
                WIOB_i=0;
        } else {
                wiob_open=false;
                $('#wiob_list').hide();
        }
        // }}}
}
var WIOB_i=0;
function repositionWIOB() {
        // {{{
        if(wiob_open) {
                WIOB_i++;
                if(WIOB_i>100) {
                        xajax_refreshUserList();
                        WIOB_i=0;
                }
                //var so = document.viewport.getScrollOffsets();
                var vp = getViewPort();
                var wiob_x = vp[0]/2 + (950/2)-200;
                //var wiob_y = vp[1]+so[1]-25-250;
                //new Effect.Move('wiob_list', {x:wiob_x,y:wiob_y,mode: 'absolute',duration:0})
                $('#wiob_list').css({left: wiob_x});

        }
        setTimeout("repositionWIOB()", 100);
        // }}}
}
setTimeout("repositionWIOB()", 100);
function getViewPort() {
        // {{{
         var viewportwidth;
         var viewportheight;

         if (typeof window.innerWidth != 'undefined') {
              viewportwidth = window.innerWidth,
              viewportheight = window.innerHeight
         } else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0) {
               viewportwidth = document.documentElement.clientWidth,
               viewportheight = document.documentElement.clientHeight
         } else {
               viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
               viewportheight = document.getElementsByTagName('body')[0].clientHeight
         }
         return(new Array(viewportwidth, viewportheight));
        // }}}
}

function getExtraSearchOpt() {
	return 'usershow:'+($('#redUser').attr('checked') ? '1' : '0')+'|appshow:'+($('#redApp').attr('checked') ? '1' : '0');
}
function doInfoSearch(v) {

	if(v=='') doCloseSearch(); else doOpenSearch();
	
	iValue = v;
	icounter = 10;
}
var iValue = '';
var icounter = -1;
function waitInfoSearch() {
	if(icounter>0) {
		icounter--;
		if(icounter==0) {
			if(fw_modul=='index') {
				refreshPinnwandFeedlist('',iValue,'','',getExtraSearchOpt());
			} else {
				xajax_searchInLastFeed(iValue);
			}
			icounter = -1;
		}
	}
	setTimeout('waitInfoSearch()',100);
}
setTimeout('waitInfoSearch()',100);



/* randomUUID.js - Version 1.0
 *
 * Copyright 2008, Robert Kieffer
 *
 * This software is made available under the terms of the Open Software License
 * v3.0 (available here: http://www.opensource.org/licenses/osl-3.0.php )
 *
 * The latest version of this file can be found at:
 * http://www.broofa.com/Tools/randomUUID.js
 *
 * For more information, or to comment on this, please go to:
 * http://www.broofa.com/blog/?p=151
 */

/**
 * Create and return a "version 4" RFC-4122 UUID string.
 */
function randomUUID() {
  var s = [], itoh = '0123456789ABCDEF';

  // Make array of random hex digits. The UUID only has 32 digits in it, but we
  // allocate an extra items to make room for the '-'s we'll be inserting.
  for (var i = 0; i <36; i++) s[i] = Math.floor(Math.random()*0x10);

  // Conform to RFC-4122, section 4.4
  s[14] = 4;  // Set 4 high bits of time_high field to version
  s[19] = (s[19] & 0x3) | 0x8;  // Specify 2 high bits of clock sequence

  // Convert to hex chars
  for (var i = 0; i <36; i++) s[i] = itoh[s[i]];

  // Insert '-'s
  s[8] = s[13] = s[18] = s[23] = '-';

  return s.join('');
}
function moveNF() {
	// {{{
	var uuid = randomUUID();
	$('#placeNewFeeds').prepend('<div id="'+uuid+'" style="display:none;">'+$('#placeNewFeedsContent').html()+'</div>');
	$('#'+uuid).slideDown('slow');
	$('#placeNewFeedsContent').html('');
	// }}}
}
