var font_reset_em = 0.579;
//var em_step = 0.07;
var em_step = 0.071;
var font_current_step = 0;
var font_max_steps = 1;

function changeFontSize (new_size)
{
    var coeff = font_current_step + new_size;
    if (coeff <= font_max_steps && coeff >= 0)
    {
        font_current_step += new_size;
        font_current_em = font_reset_em + font_current_step * em_step;
        $("#container").css("fontSize", font_current_em + "em");
    }
}

function ToggleCategory (category_active)
{
    $("#categories_div").toggle();

    if ($("#categories_div").css('display') == 'block')
    {
        $("#menu2_2").removeClass("menu2_2");
        $("#menu2_2").addClass("menu2_2_active");
    }
    else
    {
        $("#menu2_2").removeClass("menu2_2_active");
        $("#menu2_2").addClass("menu2_2");
    }
}





var shown_index = -1;
var hide_all_timeout = null;

function CategoryOver (index)
{
    clearTimeout (hide_all_timeout);
    for (i = 0; i < 6; i++)
    {
        $('#categories_div_' + i).hide ();
    }
    $('#categories_div_' + index).show ();
    shown_index = index;
}

function CategoryOut (index)
{
    shown_index = -1;
    hide_all_timeout = window.setTimeout("CategoryHideAll()", 1500);
}

function CategoryHideAll ()
{
    if (shown_index == -1)
    {
        for (i = 0; i < 6; i++)
        {
            $('#categories_div_' + i).hide ();
        }
    }
}

function SubOver (index)
{
    clearTimeout (hide_all_timeout);
    shown_index = index;
}

function SubOut (index)
{
    shown_index = -1;
    hide_all_timeout = window.setTimeout("CategoryHideAll()", 1000);
}






 
function ShowZielGruppe (zielgruppe_parent_id, zielgruppe_child_id)
{
    //zielgruppe_parent_id = element.options[element.selectedIndex].value;
    $("#zielgruppe_child").load ("post_ajax.php?action=get_zielgruppe&parent_id=" + zielgruppe_parent_id + "&child_id=" + zielgruppe_child_id);
}

function ToggleAH ()
{
    $("#ah_container").toggle();


    if ($("#ah_container").css('display') == 'block')
    {
        document.getElementById("ah_img").src = "images/arrow_up.gif";
    }
    else
    {
        document.getElementById("ah_img").src = "images/arrow_down.gif";
    }
}

//clear the Content
function ClearField(sNameValue){
    document.getElementsByName(sNameValue)[0].value = "";
}

//write a standard text into the field
function GetStandardText(sNameValue,sTextValue){
    sValue = trim(document.getElementsByName(sNameValue)[0].value);
    
    if( sValue.length == 0 ){
        document.getElementsByName(sNameValue)[0].value = sTextValue;
    }else{
        if(sValue == sTextValue)
            ClearField(sNameValue);
    }
}

function TrimField(sNameValue){
    document.getElementsByName(sNameValue)[0].value=trim(document.getElementsByName(sNameValue)[0].value)
}

// removing whitespace 
function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
    return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
    return stringToTrim.replace(/\s+$/,"");
}

function TogglePutCart (content_id)
{
    //debugger;
    var lt_cart_image = document.getElementById ("lt_cart_image_" + content_id);
    var lt_cart_hidden = document.getElementById ("lt_cart_hidden_" + content_id);
    var url_put = "post_ajax.php?action=cart_add&content_id=" + content_id;
    var url_remove = "post_ajax.php?action=cart_remove&content_id=" + content_id;
    var new_url;
    var new_src;
    var new_value;

    var hidden_value = parseInt (lt_cart_hidden.value);
    
    //document.getElementById('anzahl').value= "Sie haben "+hidden_value+" Produkte im Warenkorb";

    if (hidden_value == 1)
    {
        new_url = url_remove;
        new_src = "images/cart.gif";
        new_value = 0;
    }
    else
    {
        new_url = url_put;
        new_src = "images/cart_active.gif";
        new_value = 1;
    }
    lt_cart_image.src = new_src;
    lt_cart_hidden.value = new_value;

    $("#cartblock").load (new_url);
}

function TogglePutPlaylist (content_id, box_id, content_title)
{
    var lt_cart_image = document.getElementById ("lt_cart_image_" + content_id);
    var lt_cart_hidden = document.getElementById ("lt_cart_hidden_" + content_id);
    var url_put = "post_ajax.php?action=playlist_add&content_id=" + content_id + "&box_id=" + box_id + "&content_title=" + URLEncode(content_title);
    var url_remove = "post_ajax.php?action=playlist_remove&content_id=" + content_id;
    var new_url;
    var new_src;
    var new_value;

    if (lt_cart_hidden != null)
    {
        var hidden_value = parseInt (lt_cart_hidden.value);
    
        if (hidden_value == 1)
        {
            new_url = url_remove;
            new_src = "images/playlist.gif";
            new_value = 0;
        }
        else
        {
            new_url = url_put;
            new_src = "images/playlist_active.gif";
            new_value = 1;
        }
        lt_cart_image.src = new_src;
        lt_cart_hidden.value = new_value;
    }
    
    $("#playlist_block").load (new_url);
}

function RemoveFromPlayList (content_id)
{
    $("#playlist_block").load ("post_ajax.php?action=playlist_remove&content_id=" + content_id);
    setTimeout("location.reload(true)",1);
}

function MoveWindowToCenter (w, width, height)
{
    var Ycor = (screen.height-height) / 2;
    var Xcor = (screen.width-width) / 2;
    w.moveTo (Xcor, Ycor);
}

function OpenWindow (url, windowname, width, height)
{
    var w = window.open ('' + url + '','','fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width=' + width + ',height=' + height + '');
    MoveWindowToCenter (w, width, height);
}

function OpenFlashStreamWindow (url, windowname)
{
    var width = 590;
    var height = 380;
    OpenWindow (url, windowname, width, height)
}

function URLEncode (plaintext)
{
    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do...
    var SAFECHARS = "0123456789" +                    // Numeric
                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +    // Alphabetic
                    "abcdefghijklmnopqrstuvwxyz" +
                    "-_.!~*'()";                    // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
        var ch = plaintext.charAt(i);
        if (ch == " ") {
            encoded += "+";                // x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
            encoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {
                alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
                          "(URL encoding only supports 8-bit characters.)\n" +
                          "A space (+) will be substituted." );
                encoded += "+";
            } else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    } // for
    return encoded;
}

function URLDecode (encoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
       if (ch == "+") {
           plaintext += " ";
           i++;
       } else if (ch == "%") {
            if (i < (encoded.length-2)
                    && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
                    && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
                plaintext += unescape( encoded.substr(i,3) );
                i += 3;
            } else {
                alert( 'Bad escape combination near ...' + encoded.substr(i) );
                plaintext += "%[ERROR]";
                i++;
            }
        } else {
           plaintext += ch;
           i++;
        }
    } // while
    return plaintext;
}

function EraseOrGetField(fieldid,input_text,eraseorget)
{
    if(document.getElementById(fieldid).value == input_text && eraseorget == 'erase' )
    {
        document.getElementById(fieldid).value = "";
        document.getElementById(fieldid).style.color = "#333333";
        document.getElementById(fieldid).style.fontSize = "12px";
    }
        
    if(document.getElementById(fieldid).value == '' && eraseorget == 'get' )
    {
        document.getElementById(fieldid).value = input_text;
        document.getElementById(fieldid).style.color = "#9D9DA1";
        document.getElementById(fieldid).style.fontSize = "12px";
    }
}

function changeBGImage(image,kw,kb,go,mkl,klv)
{
    document.getElementById('community_content').style.backgroundImage = "url("+image+")";
    document.getElementById('kw').style.backgroundImage = "url('"+kw+"')";
    document.getElementById('kb').style.backgroundImage = "url('"+kb+"')";
    document.getElementById('go').style.backgroundImage = "url('"+go+"')";
    document.getElementById('mkl').style.color = mkl;
    document.getElementById('klv').style.color = klv;
}

function showHideField(id,showOrHide)
{       
        document.getElementById(id).style.visibility = showOrHide;
}

function eraseFieldcontent(id)
{
	document.getElementById(id).value = "";
}

//Limit the number of charactes per textarea
function textCounter(field,cntfield,maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
    else
        cntfield.value = maxlimit - field.value.length;
}

//schaltet das entsprechende objekt an oder aus z.b bei buttons
function disable(id,id_ok)
{
    if (0 < document.getElementById(id).value.length )
    {
        document.getElementById(id_ok).disabled = false;
    }else
    {
        document.getElementById(id_ok).disabled = true;
    }
}
//diese funktion soll das bestimmte Element focusieren
function focusIt(id)
{
    document.getElementById(id).focus();
}

function checkEnter(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable
	alert('hier');
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		e = event;
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		document.getElementById('suchform').submit(); //submit the form
		return false;
	}
	else{
		return true;
	}
}

function limitText(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

//beim upload sollen die Felde vor dem Post gelöscht werden
function clearFields()
{
	if('z.B. Brücke über die Isar bei Nacht' == document.getElementById('titel').value)
		document.getElementById('titel').value = "";
	if('z.B. München' == document.getElementById('ort').value)
		document.getElementById('ort').value = "";
	if('z.B. Brücke, Nachtaufnahme, Liebe' == document.getElementById('schlagworte').value)
		document.getElementById('schlagworte').value = "";
	if('z.B. Ein junges Paar sitzt unter einer Isarbrücke in München und küsst sich.' == document.getElementById('bildbeschreibung').value)
		document.getElementById('bildbeschreibung').value = "";
	if('1971 o. 12.03.1971' == document.getElementById('datum').value)
		document.getElementById('datum').value = "";
}

function indexBoxOver(index)
{
	$('#overlay_' + index).show();
}

function indexBoxOut(index)
{
	$('#overlay_' + index).hide();
}

function ToggleFlashOverlay()
{
	$('#zeitreisen').toggle();
	$('#x').toggle();
}

function previewFromFlash(title, content_id)
{
	alert('hello');
}

function FilterOnclick (url, online_category_id, online_category_id_list)
{
	if (online_category_id_list == '') online_category_id_list = ',';
	online_category_id_list += online_category_id + ',';
	document.forms['form_search_index'].category_id.value = online_category_id_list;
	document.forms['form_search_index'].submit();
	//location.href = url + '&online_category_id=' + online_category_id_list;
}

function FilterDeselectOnclick (url, online_category_id, online_category_id_list)
{
	//online_category_id_list += online_category_id + ',';
    arr = online_category_id_list.split (','); 

    for (i = arr.length - 1; i >= 0; i--)
    {
        if (arr[i] == online_category_id) arr.splice (i, 1);
    }
    str = arr.join (',');
	if (str == ',') str = '';	
	document.forms['form_search_index'].category_id.value = str;
	document.forms['form_search_index'].submit();
}

function TagCloudShowFull(element)
{
	$(element).css({'overflow-y' : 'visible'});
}

function TagCloudHideFull(element)
{
	$(element).css({'overflow-y' : 'hidden'});
}

function FormatOnClick(url, format_name_id, format_name_id_list)
{
	if (format_name_id_list == '') format_name_id_list = ',';
	format_name_id_list += format_name_id + ',';
	
	document.forms['form_search_index'].format_name_id.value = format_name_id_list;
	document.forms['form_search_index'].submit();
}

function FormatDeselectOnClick()
{
	document.forms['form_search_index'].format_name_id.value = '';
	document.forms['form_search_index'].submit();
}

function SearchFormSubmit()
{
	document.forms['form_search_index'].category_id.value = '';	
	document.forms['form_search_index'].format_name_id.value = '';
	return true;
}

$(document).ready(function () {

	  $().mousemove(function(e){
	      mouseX = e.pageX;
	      mouseY = e.pageY;
	      var tooltip = $('.show_tooltip .tooltip');
	      if (tooltip.css('display') == 'block') {
	        set_tooltip_position();
	      }
	   });
 
	  $('.imagebox')
	    .mouseleave(function () {
	      if (tooltipTimeout != undefined) {
	        window.clearTimeout(tooltipTimeout);
	      }
	      close_tooltip();
	      $(this).parent().removeClass('show_tooltip');
	    })
	    .mouseenter(function() {
	    	//alert('here');
	      $(this).parent().addClass('show_tooltip');
	      tooltipTimeout = window.setTimeout('open_tooltip()', 500);
	    });
	});
	function set_tooltip_position () {
	  var tooltip = $('.show_tooltip .tooltip');
	  /*tooltip.css({
	    'left': mouseX + (mouseX + tooltip.outerWidth() + 30 < 733 ? 15 : - tooltip.outerWidth() - 15),
	    'top':  mouseY + (mouseY + tooltip.outerHeight() + 30 < 419 ? 15 : - tooltip.outerHeight() - 15)  
	  });*/
	}
	function close_tooltip () {
	  $('.show_tooltip .tooltip').fadeOut(500);
	}

	function open_tooltip () {
	  set_tooltip_position();
	  $('.show_tooltip .tooltip').fadeIn(500);
	}

