function fenster(){
	fensterb = 0;
  fensterh = 0;
  if (document.all){
    fensterb = document.body.offsetWidth// + window.scrollMaxX;
		fensterh = document.body.offsetHeight;// + window.scrollMaxY;
	}else if ( document.documentElement.clientWidth ){
		fensterb = document.documentElement.clientWidth;
		fensterh = document.documentElement.clientHeight;
 	}
	return Array( fensterb, fensterh );
}
function getScrollingY(){
  if (typeof window.pageYOffset != 'undefined'){
    this.position = window.pageYOffset;
  }else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0){
    this.position = document.documentElement.scrollTop;
  }else if (typeof document.body.scrollTop != 'undefined'){
    this.position = document.body.scrollTop;
  }
  return this.position;
}

function toggleCycle(){
  Effect.toggle("lifeCycle",'slide');
}

function toggleDiv(_div){
  var object = document.getElementById(_div).style;
  //document.designForm.passreq.value == "on"
  if(object.display == "none"){
    object.display = "inline";
  }else{
    object.display = "none";
  }
}
function toggleFade(_obj){
  Effect.toggle(_obj,'slide');
  return false;
}
var curReiter = "de";
function toggleReiter(_lang){
  if(_lang == "en"){
    document.getElementById("reiterde").style.display = "none";
    document.getElementById("reiteren").style.display = "inline";
    document.getElementById("addContentEn").style.display = "inline";
  }else{
    document.getElementById("reiterde").style.display = "inline";
    document.getElementById("reiteren").style.display = "none";
    document.getElementById("addContentEn").style.display = "none";
  }
}

var oldOverviewObject = "public";
function showOverview(_object){
	if(oldOverviewObject != _object){
		if(oldOverviewObject != null){
			$(oldOverviewObject).hide();
			t = 'href' + oldOverviewObject;
			$(t).setStyle({color:"#FFFFFF"});
		}
		$(_object).show();
		t = 'href' + _object;
		$(t).setStyle({color:"#ccff66"});
		oldOverviewObject = _object;
	}
}

function validateForm(formName,formObject){
  if(formName == "newEventForm"){
    if(formObject.eventName.value == "" || formObject.startDate.value == "" || formObject.startTime.value == ""){
      return false;
    }
  }
  return true;
}

function toggleVeranst(_num){
  document.getElementById("veranst" + oldNum).style.display = "none";
  document.getElementById("veranst" + _num).style.display = "inline";
  oldNum = _num;
}

function clearForm(formLayer){
  if(formLayer == "newPlace"){
    document.InputForm.eventPlaceName.value = "";
    $('VeranstOrtSelect').show();
    $('VeranstOrtNew').hide();
  }else if(formLayer == "newOrganizer"){
    document.InputForm.organizerName.value = "";
    $('organizerSelect').show();
    $('organizerNew').hide();
  }
}
function showNewPlace(){
  $('VeranstOrtSelect').hide();
  $('VeranstOrtNew').show();
  document.InputForm.enventPlaceSelection.value = "";
}

function showNewOrganizer(){
  $('organizerSelect').hide();
  $('organizerNew').show();
  document.InputForm.enventOrganizerSelection.value = "";
}

function validateCheck(box,input,_alert){
  if(box == "ODN" && input.value == "on"){
    if(document.InputForm.organizerName.value == ""){
      alert(_alert);
    }
  }else if(box == "ODT" && input.value == "on"){
    if(document.InputForm.organizerDescription.value == ""){
      alert(_alert);
    }
  }
}
/*new event detail*/
function syncDataUrl(_src,_dest){
  var re = new RegExp("[a-z +0-9]");
  var temp = $(_src).value.toLowerCase().split("");
  for(var i=0;i<temp.length;i++){
  //while(temp.search(' ') > -1 || temp.search('@') > -1 || temp.search('ä') > -1 || temp.search('ö') > -1 || temp.search('ü') > -1 || temp.search('ß') > -1){
    if(!temp[i].match(re)){
      temp[i] = "";
    }
    temp[i] = temp[i].replace(' ', "+");
    temp[i] = temp[i].replace('ä', "ae");
    temp[i] = temp[i].replace('ü', "ue");
    temp[i] = temp[i].replace('ö', "oe");
    temp[i] = temp[i].replace('ß', "ss");
    temp[i] = temp[i].replace('!', "");
    temp[i] = temp[i].replace('"', "");
    temp[i] = temp[i].replace('§', "");
    temp[i] = temp[i].replace('$', "");
    temp[i] = temp[i].replace('%', "");
    temp[i] = temp[i].replace('&', "");
    temp[i] = temp[i].replace('/', "");
    temp[i] = temp[i].replace('(', "");
    temp[i] = temp[i].replace(')', "");
    temp[i] = temp[i].replace('=', "");
    temp[i] = temp[i].replace('?', "");
    
    temp[i] = temp[i].replace('*', "");
    temp[i] = temp[i].replace('{', "");
    temp[i] = temp[i].replace('}', "");
    temp[i] = temp[i].replace('\[', "");
    temp[i] = temp[i].replace('\]', "");
    temp[i] = temp[i].replace('\`', "");
    temp[i] = temp[i].replace('\´', "");
    temp[i] = temp[i].replace('\'', "");
    temp[i] = temp[i].replace('\\', "");
    
    temp[i] = temp[i].replace('#', "");
    temp[i] = temp[i].replace('~', "");
    temp[i] = temp[i].replace('%', "");
    temp[i] = temp[i].replace('@', "");
    
    temp[i] = temp[i].replace('é', "e");
    temp[i] = temp[i].replace('Á', "a");
    temp[i] = temp[i].replace('É', "e");
    temp[i] = temp[i].replace('Í', "i");
    temp[i] = temp[i].replace('Ó', "o");
    temp[i] = temp[i].replace('Ú', "u");
    temp[i] = temp[i].replace('á', "a");
    temp[i] = temp[i].replace('à', "a");
    temp[i] = temp[i].replace('é', "e");
    temp[i] = temp[i].replace('ë', "e");
    temp[i] = temp[i].replace('í', "i");
    temp[i] = temp[i].replace('ó', "o");
    temp[i] = temp[i].replace('ú', "u");
    temp[i] = temp[i].replace('ý', "y");
  }
  $(_dest).value = temp.join("");
}
/**/
var SelectObject;
function fillSelectBox(selectBox,id){
  if(selectBox.name == "eventCatLevel2"){
    for(var i=0;i<100;i++){
      document.InputForm.eventCatLevel2.options[0] = null;
    }
    for(var i=0;i<100;i++){
      document.InputForm.eventCatLevel3.options[0] = null;
    }
  }
  if(selectBox.name == "eventCatLevel3"){
    for(var i=0;i<100;i++){
      document.InputForm.eventCatLevel3.options[0] = null;
    }
  }
  SelectObject = selectBox;
  
  new Ajax.Request('/api/pool/', {
	  method:'post',
	  asynchronous:true,
	  parameters:'ACTION=CategoryByParentId&ID='+id + "&Container=" + selectBox.name,
	  onSuccess: function(transport){
	    var json = transport.responseText.evalJSON(false);
	    for(var i=0;i<=json.count;i++){
	    	if(json.infos[i].name != ""){
		    	newOption = new Option(json.infos[i].name,json.infos[i].id, false, false);
		      SelectObject.options[SelectObject.options.length] = newOption;
	      }
	  	}
	  }
	});
}
function fillSelectBoxData(_arg){
  alert(_arg.toString());
  var temp = _arg.split("#");
  //alert(temp.length);
  for(var i=0;i<temp.length;i++){
    var temp1 = temp[i].split(",");
    if(temp1[1] != undefined){
      newOption = new Option(temp1[1], temp1[0], false, false);
      SelectObject.options[SelectObject.options.length] = newOption;
    }
  }
}

var currentBox;
function showLayer(boxName,args){
  winDims = fenster();
  if(boxName == "newTicketLayer"){
    $('newTicketLayer').innerHTML = "<img src=\"/s/img/loader/loaderBig.gif\">";
    new Ajax.Updater("newTicketLayer", "/api/pool/", { method: 'post', asynchronous:true, parameters:'ACTION=TicketEditService&UID=0' });
  }else if(boxName == "statDetailLayer"){
    if(args.indexOf('TASK=3') > 0){
      if (confirm("Soll die Rechnung storniert werden?")){
        showLoader('detailContent');
        args += "&ACTION=OrderDetail";
        new Ajax.Updater("detailContent", "/api/pool/", { method: 'post', asynchronous:true, parameters:args });
      }
    }else{
      showLoader('detailContent');
      AjaxAction.orderDetail(args);
    }
  }else if(boxName == "guestDetailLayer"){
  	AjaxAction.guestDetail(args);
  }else if(boxName == "inputTextBox"){
    $('headline').innerHTML = args;
    document.inputTextForm.task.value = "copy";
  }
  $('disableLayer').setStyle({width:  winDims[0],height: winDims[1]+MZCore.getScrollingY()});
  Tleft = (MZCore.getWindowWidth() - parseInt($(boxName).getStyle('width'))) / 2;
  $(boxName).setStyle({left: Tleft,top: (MZCore.getScrollingY()+20)});
  currentBox = boxName;
}
function showInputLayer(_text,_task,_id){
  winDims = fenster();
  $('headline').innerHTML = _text;
  document.inputTextForm.TASK.value = _task;
  document.inputTextForm.UID.value = _id;
  $('disableLayer').setStyle({width:  winDims[0],height: winDims[1]+MZCore.getScrollingY()});
  Tleft = (MZCore.getWindowWidth() - parseInt($('inputTextBox').getStyle('width'))) / 2;
  $('inputTextBox').setStyle({left: Tleft,top: (MZCore.getScrollingY()+20)});
  currentBox = 'inputTextBox';
}
function showLoader(_div){
  $(_div).innerHTML = "<img src=\"/s/img/loader/loaderBig.gif\">";
}
function hideLayer(){
  $('disableLayer').setStyle({width:  0,height: 0});
  $(currentBox).setStyle({left: '-2000',top: '30'});
  
  currentBox = null;
}
function toggleoptionalTicket(){
  if($('optionTicker').getStyle('display') == "none"){
    $('optionTicker').show();
  }else{
    $('optionTicker').hide(); 
  }
}
/*global alert*/
function showGlobalAlert(_msg){
  winDims = fenster();
  $('disableLayer').setStyle({width:  winDims[0],height: (winDims[1]+ getScrollingY()) });
  
  Tleft = (winDims[0] - 400) / 2;
  Ttop = (winDims[1] - 200) / 2;
  $('globalAlertBox').setStyle({left: Tleft,top: (Ttop + getScrollingY()) });
  
  $('globalAlertBoxHeadline').innerHTML = "<b>"+_msg+"</b>";
}
function hideGlobalAlert(){
  $('disableLayer').setStyle({width:  0,height: 0});
  $('globalAlertBox').setStyle({left: -1000});
}
/* edit tickets*/
function checkCheckbox(_formName){
  var form = $(_formName);
  var checks = form.getInputs('checkbox', 'ticketVisibility[]');
  for(var i=0;i<checks.length;i++){
    checks[i].checked = true;
  }
}
function uncheckCheckbox(_formName){
  var form = $(_formName);
  var checks = form.getInputs('checkbox', 'ticketVisibility[]');
  for(var i=0;i<checks.length;i++){
    checks[i].checked = false;
  }
}
function checkTheBox(_boxname){
  alert($(_boxname).value);
  var temp = array('infoMobileNumber,infoPhoneNumber');
  if(_boxname == "visitorMust"){
    checkCheckboxArray(temp);
  }else{
    
  }
}
function checkCheckboxArray(_boxArray){
  //var temp = _boxArray.split(",");
  for(var i=0;i<_boxArray.length;i++){
    $(_boxArray[i]).checked = true;
  }
}
function uncheckCheckboxArray(_boxArray){
  //var temp = _boxArray.split(",");
  for(var i=0;i<_boxArray.length;i++){
    $(_boxArray[i]).checked = false;
  }
}
function uncheckCheckboxCsvlist(_csvlist){
  checkCheckboxArray(_csvlist.split(","));
}
function toggleCheckbox(_enable,_diable){
  $(_enable).checked = true;
  $(_diable).checked = false;
}
function toggleCheckboxNum(_form,_name,_pos){
  var form = $(VisitorDataForm);
  var checks = form.getInputs('checkbox', _name);
  
  if(_pos == 0){
    if(checks[0].checked == true){
      checks[0].checked = true;
    }else{
      checks[0].checked = false;
    }
    checks[1].checked = false;
  }else{
    checks[0].checked = false;
    if(checks[1].checked == true){
      checks[1].checked = true;
    }else{
      checks[1].checked = false;
    }
  }
}
function toggleCheckboxQuestions(_name,_pos){
  var form = $(VisitorDataForm);
  var checks = form.getInputs('checkbox', _name);
  
  if(_pos == 0){
    if(checks[0].checked == true){
      checks[0].checked = true;
    }else{
      checks[0].checked = false;
    }
    checks[1].checked = false;
  }else{
    checks[0].checked = false;
    if(checks[1].checked == true){
      checks[1].checked = true;
    }else{
      checks[1].checked = false;
    }
  }
}
function resetCheckPayment(){
  var form = $(FInput);
  var checks = form.getInputs('checkbox');
  for(var i=0;i<3;i++){
    checks[i].checked = false;
    checks[i][checks[i].disabled ? 'enable' : 'disable']();
  }
}
function setHiddenValue(_field,_value){
  _field.value = _value;
  return true;
}
function deleteTicket(_uid,_text){
  Check = confirm(_text);
  if (Check == true){
    divId = "ticketsContent";
    url = "/service/beTicketService.php";
    param = "TASK=delete&UID=" + _uid;
    var ajaxRequest = new Ajax.Updater(divId, url, {
      method: 'post',
      asynchronous:true,
      parameters:param
    });
  }
}
function deleteEvent(_text,_uid){
  Check = confirm(_text);
  if (Check == true){
    location.href = "/pages/12&TASK=delete&UID=" + _uid;
    return true;
  }
  return false;
}
function editTicket(_uid){
  divId = "newTicketLayer";
  url = "/api/pool/";
  param = "ACTION=TicketEditService&UID=" + _uid;
  var ajaxRequest = new Ajax.Updater(divId, url, {
    method: 'post',
    asynchronous:true,
    parameters:param
  });
    
  winDims = fenster();
  $('disableLayer').setStyle({width:  winDims[0],height: winDims[1]});
  Tleft = (MZCore.getWindowWidth() - parseInt($('newTicketLayer').getStyle('width'))) / 2;
  $('newTicketLayer').setStyle({left: Tleft,top: MZCore.getScrollingY()});
  currentBox = "newTicketLayer";
}
function hideShowTicket(_uid){
  divId = "ticketsContent";
  url = "/api/pool/";
  param = "ACTION=TicketService&TASK=toggleVisible&UID=" + _uid;
  var ajaxRequest = new Ajax.Updater(divId, url, {
    method: 'post',
    asynchronous:true,
    parameters:param
  });
}
function checkConfirm(_text){
	if (confirm(_text)){
		return true;
	}
	return false;
}
/*Save design*/
function saveDesign(_msg){
divId = "questionList";
  url = "/service/pageDesignService.php";
  var form = Form.serialize(designForm);
  var ajaxRequest = new Ajax.Request(url, {
    method: 'post',
    parameters:form
  });
  //showGlobalAlert(_msg);
  location.href = "/pages/11";
  return false;
}
function saveDesignEdit(_msg){
divId = "questionList";
  url = "/service/pageEditDesignService.php";
  var form = Form.serialize(designForm);
  var ajaxRequest = new Ajax.Request(url, {
    method: 'post',
    parameters:form
  });
  showGlobalAlert(_msg);
  //location.href = "/index.php?ID=11";
  return false;
}
/*New ticket question box*/
function newQuestion(){
  divId = "ticketQuestionBoxInner";
  url = "/api/pool/";
  param = "ACTION=QuestionService&task=clearQuestion";
  var ajaxRequest = new Ajax.Updater(divId, url, {
    method: 'post',
    evalScripts:true,
    asynchronous:true,
    parameters:param
  });
  showLayer('ticketQuestionBox');
  return false;
}
function checkQuestion(){
  var zeit = new Date();
  divId = "questionList";
  url = "/api/pool/";
  var form = Form.serialize(questionForm);
  form += "&ACTION=QuestionService&r=" + zeit.getMilliseconds();
  var ajaxRequest = new Ajax.Updater(divId, url, {
    method: 'post',
    evalScripts:true,
    asynchronous:true,
    parameters:form
  });
  Form.reset(questionForm);
  hideLayer();
  return false;
}
function updateQuestion(){
  divId = "questionList";
  url = "/api/pool/";
  var form = Form.serialize(questionUpdateForm);
  form += "&ACTION=QuestionService";
  //alert(form);
  var ajaxRequest = new Ajax.Updater(divId, url, {
    method: 'post',
    evalScripts:true,
    asynchronous:true,
    parameters:form
  });
  Form.reset(questionUpdateForm);
  $('ticketQuestionBoxInner').innerHtml = "";
  hideLayer();
  return false;
}

com.zetzi.qestionAjaxAction = function(){ };
com.zetzi.qestionAjaxAction.prototype = {
	deleteQuestion : function (uid){
	  param = "ACTION=QuestionService&task=delete&uid=" + uid;
	  var ajaxRequest = new Ajax.Updater("questionList", "/api/pool/", {
	    method: 'post',
	    evalScripts:true,
	    asynchronous:true,
	    parameters:param
	  });
	  return false;
	},
	editQuestion : function (uid){
	  param = "ACTION=QuestionService&task=edit&uid=" + uid;
	  var ajaxRequest = new Ajax.Updater("ticketQuestionBoxInner", "/api/pool/", {
	    method: 'post',
	    evalScripts:true,
	    asynchronous:true,
	    parameters:param
	  });
	  showLayer('ticketQuestionBox');
	  return false;
	}
}
var qestionAjaxAction = com.zetzi.qestionAjaxAction;
var questionAction = new qestionAjaxAction();

/* my data functions */
function changeMyDataTemplate(_templ,_site){
  var params = "template=" + _templ + "&site=" + _site;
  new Ajax.Updater("myDataTemplate", "/service/loadTemplateData.php", { method: 'post', asynchronous:true, parameters:params });
}
function checkMyDataAgb(_msg){
  //alert(document.myDataform.acceptcharges.checked);
  if(document.myDataform.acceptcharges.checked != true){
    showGlobalAlert(_msg);
    return false;
  }
  return true;
}
function changeEventDetail(_args){
  if(_args != 0){
    location.href = "/index.php?ID=16&UID=" + _args;
  }
}
/*my locations*/
function changeEditMode(_element,_id){
  if(_element != ""){
    $(_element).className = "formg";
  }
  $('save'+_id).show();
}

/*
this object is only for Be AJAX actions
*/
com.zetzi.beAjaxAction = function(){ };
com.zetzi.beAjaxAction.prototype = {
	sendReminder : function (args){
		new Ajax.Updater("resultDiv", "/api/pool/", { method: 'POST', asynchronous:true, parameters:args });
	},
	orderDetail : function (args){
		args += "&ACTION=OrderDetail";
		new Ajax.Updater("detailContent", "/api/pool/", { method: 'POST', asynchronous:true, parameters:args });
	},
	guestDetail : function (args){
		args += "&ACTION=GuestDetail";
		new Ajax.Updater("detailContent", "/api/pool/", { method: 'POST', asynchronous:true, parameters:args });
	},
	makeAjaxUpdate : function (box,args){
		new Ajax.Updater(box, "/api/pool/", { method: 'POST', asynchronous:true, parameters:args });
	},
	editAffiliate : function (affId){
		param = "ACTION=EditAffiliate&UID=" + affId;
	  var ajaxRequest = new Ajax.Updater("ticketQuestionBoxInner", "/api/pool/", {
	    method: 'post',
	    evalScripts:true,
	    asynchronous:true,
	    parameters:param
	  });
	  showLayer('NewAffiliate');
	  return false;
	}
}
var beAjaxAction = com.zetzi.beAjaxAction;
var AjaxAction = new beAjaxAction();

/*
 this object is only for Fe AJAX actions
*/
com.zetzi.feAjaxAction = function(){};
com.zetzi.feAjaxAction.prototype = {
	requestNewPsw : function (){
		var form = Form.serialize(loginForm);
  	new Ajax.Updater("forgotpwd", "/api/pool/", { method: 'post', asynchronous:true, parameters:form });
	}
}
var feAjaxAction = com.zetzi.feAjaxAction;
var feAjaxAction = new feAjaxAction();
/*End*/

function calcAllAround(){
  var form = $(addGuestForm);
  var counts = form.getInputs('text','ticketCount[]');
  var price = form.getInputs('hidden','price[]');
  var gesamt = 0.00;
  for(var i=0;i<counts.length;i++){
    gesamt += price[i].value * counts[i].value;
    $('summe' + i).innerHTML = MZCore.priceHtml(price[i].value * counts[i].value) + " &euro;";
  }
  //form.getInputs('text','gesamtPreis').value = price[0] * counts[0];
  $('gesamtPreis').value = MZCore.priceHtml(gesamt);
  $('payAmount').value = gesamt;
  $('gesamtPreisText').innerHTML = MZCore.priceHtml(gesamt) + " &euro;";
}
function loadAddGuestOrderInfo(){
  var form = Form.serialize(addGuestForm);
  new Ajax.Updater("addGuestOrderId", "/service/beOrderInfoForm.php", { method: 'post', evalScripts: true, asynchronous:true, parameters:form });
  return false;
}
function syncAmountInputs(scr,dest){
  $(dest).value = MZCore.priceFloat($(scr).value);
}
function toggleAllTickets(_num){
  if(_num > 9){
    Effect.toggle('displayInputText','slide');
  }else{
    if(document.addGuestForm.allBlankTickets.value == "on"){
      alert("Bitte mehr als 10 Tickets auswählen.");
      document.addGuestForm.allBlankTickets.checked = false;
    }
  }
}
