/**
 * Ein- / Ausblenden von Inhalten via ID-Übergabe
 *
 * @author Florian Preusner
 */
function displayContent(effect, id) {

  switch(effect) {

    case 'slide':

      $("#" + id).slideToggle("slow");
    break;

    case 'fade-slide':

      $("#" + id).animate({opacity: 'toggle', height: 'toggle'}, 1200);
    break;
  }
}

/**
 * Scrollt zum übergebenen Objekt anhand der ID
 *
 * @author Florian Preusner
 */
function scrolling(target) {

  $.scrollTo(target, 1000);
}

/**
 * Sendet das Formular ab via übergebener ID
 *
 * @author Florian Preusner
 */
function submitForm(id) {

  document.getElementById(id).submit();
}

/**
 * Funktion die ein Formular anhand einer Enter-Eingabe abschickt
 *
 * @author Florian Preusner
 */
function checkEnter(event, form_id) {

  if(event.which) {

    if(event.which == 13) {

      $("#" + form_id).submit();
    }
  } else {

    var charCode = (event.charCode) ? event.charCode : ((event.which) ? event.which : event.keyCode);

    if(charCode == 13) {

      $("#" + form_id).submit();
    }
  }
}

/**
 * Funktion zum aktuallisieren des vHost-Preises
 * für mehrere
 *
 * @author Florian Preusner
 */
function updateVhostPrice() {

  var price  = document.getElementById('vhost_price').innerHTML;
      price  = price.replace(',', '.');
  var count  = document.getElementById('vhost_count').value;
  var output = document.getElementById('vhost_price_all');

  if(count == parseInt(count)) {

    var new_price  = count * price;
        new_price  = new_price.toFixed(2);
        new_price  = new_price.replace('.', ',');

    output.style.color = '#7FFF2A';
    output.innerHTML   = new_price + " &euro;";

  } else {

    output.style.color = 'red';
    output.innerHTML   = 'Error';
  }

  return false;
}

/**
 * Starten/Stoppen eines Teamspeak-Servers via Ajax
 *
 * @author Florian Preusner
 */
function teamspeakStartStop(url, stop) {

  if(stop) {

    ok = confirm("Sind Sie sicher, dass Sie den Server stoppen wollen?");
  } else {

    ok = true;
  }

  if(ok) {$("#server_status").load(url);}
}

/*
 * Popup
 */
function popup(url, trgt, wdth, hght, scrolling) {

  aleft = (screen.width)  ? (screen.width  - wdth) / 2 : 100;
  atop  = (screen.height) ? (screen.height - hght) / 2 : 100;

  params = "width=" + wdth + ",height=" + hght + ",top=" + atop + ",left=" + aleft + ",scrollbars=" + scrolling + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";
  popup = window.open(url, trgt, params);
  popup.focus();
}

/*
 * Hover-Effekt für Produktpalette
 */
$(document).ready(function() {

  $("#produkt_panel li").append('<img class="shadow" src="/image/icon/product/shadow.png" width="81" height="27" alt="" />');

  $("#produkt_panel li").hover(function() {

    var e = this;
        $(e).find("a").stop().animate({marginTop: "-10px"}, 250, function() {
        	$(e).find("a").animate({marginTop: "-7px"}, 250);
        });
        $(e).find("img.shadow").stop().animate({width: "80%", height: "20px", marginLeft: "8px", opacity: 0.25}, 250);
    }, function() {

    	var e = this;
        $(e).find("a").stop().animate({marginTop: "4px"}, 250, function() {
        	$(e).find("a").animate({marginTop: "0px"}, 250);
        });
        $(e).find("img.shadow").stop().animate({width: "100%", height: "27px", marginLeft: "0px", opacity: 1}, 250);
    });

})

/**
 * Modalbox/Facebox anzeigen
 *
 * @author Florian Preusner
 */
function showModalbox(route) {

  jQuery.facebox({ajax: route});
}

/**
 * Advertising Banner Code
 *
 * @author Florian Preusner
 */
function adBanner(language) {

  selected = $('#code_select').val();
  code     = '<!-- Uplimit Advertising -->\n'
           + '<a href="http://www.uplimit.net" title="Uplimit - eSport Solutions" target="_blank">\n'
           + '  <img src="http://www.uplimit.net/image/banner/advertising/' + language + '/' + selected + '.jpg" alt="Uplimit Advertisement" />\n'
           + '</a>';

  $('#codearea').val(code);
  $('#code_preview_img').val('/image/banner/advertising/example/' + selected + '.png');
}

/**
 * Display image in Modalbox
 *
 * @author Florian Preusner
 */
function showImageByValue(element) {

  img_src = $(element).val();

  $.facebox({image: img_src });
}

/**
 * Post via url + param and refresh site (reload)
 *
 * @author Florian Preusner
 * @param  url
 * @param  token
 * @param  confirm_msg   optional
 */
function postAndRefresh(url, token, confirm_msg) {

  if(confirm_msg) {

    go = confirm(confirm_msg);
  } else {

    go = true;
  }

  if(go) {

    $.post(url, {token: token}, function(data) {

      window.location.href = data;
    });
  }
}

/**
 * display right container on selecting token type
 *
 * @author Florian Preusner
 * @param  type
 */
function tokenChanger(type) {

  if(type == 1) {

    $('#token_server_container').css('display', 'none');
    $('#token_channel_container').css('display', 'block');
  } else {

    $('#token_server_container').css('display', 'block');
    $('#token_channel_container').css('display', 'none');
  }
}

/**
 * create new token
 *
 * @author Florian Preusner
 */
function createToken(url_create) {

  $.post(url_create, $("#token_create_form").serialize(), function(data) {

      eval("response = " + data);

      if(data['url'] != '') {

        window.location.href = response['url'];
      } else {

        $('#facebox .content').response(data['msg']);
      }
  });
}

/**
 * Load customer pannel info
 *
 * @author Florian Preusner
 */
function pannelInfoLoad(url) {

  $('#customer_pannel_info').load(url, function() {

    setTimeout("pannelInfoLoad('" + url + "')", 30000);
  });
}

/*
 * Kundenpannel - Info (anzeigen)
 */
function pannelInfoSwitch(id) {

  $('#customer_pannel_info').clearQueue();

  /*
   * Reset all pannels (display)
   */
  $('#customer_pannel_info div').removeClass('display');
  
  /*
   * Add display to selected element
   */
  $('#' + id).addClass('display');

  $("#customer_pannel_info").slideDown("slow");
}

/*
 * Kundenpannel - Info (ausblenden)
 */
function pannelInfoHide() {

  $("#customer_pannel_info").delay(400).slideUp("slow");
}
