// Variablen
activeBrowser = navigator.appName;
var activeElement;
var activePopupBack, activePopup;
var activeRider;

// --------------------------------------------------------------------------------------
// Element
function openElement(elementId) {
  
	var element = document.getElementById(elementId);	
	element.style.display = "block";

} // openElement


function openPopup(elementId) {
  
	var element = document.getElementById(elementId);	
	var popupBack = document.getElementById(elementId + "Back");	
	
	popupBack.style.display = "block";
	popupBack.style.height = document.getElementById("regionBody").offsetHeight + 200 + "px";
			
	element.style.opacity = "0";
	element.style.display = "block";
	
	this.activePopup = element;
	this.activePopupBack = popupBack;
	
	smoothIn(1);

} // openPopup

function smoothIn(opacity) {

  this.activePopup.style.opacity = "" + (opacity/4);
		
	opacity++;
	// alert(opacity);
	if (opacity <= 4) 
	  window.setTimeout("smoothIn(" + opacity + ")",0);
}


function closePopup(elementId) {
  
	var element = document.getElementById(elementId);	
	var popupBack = document.getElementById(elementId + "Back");	
	
	element.style.display = "none";
	popupBack.style.display = "none";

} // closePopup


// --------------------------------------------------------------------------------------
// Reiter
function openProfilRider(elementId, riderElement) {
  
	var element = document.getElementById(elementId);
	
	if (this.activeElement == null) {
	  this.activeElement = document.getElementById("information");
	  this.activeRider = document.getElementById("riderInformation");
	}
	
	this.activeElement.style.display = "none";
  this.activeRider.className = "";
	
	if (element != this.activeElement) {
	  element.style.display = "block";
		this.activeElement = element;
		this.activeRider = riderElement;
	}
	
	riderElement.className = "active";
	 
} // openElement


// --------------------------------------------------------------------------------------
// Element
function check_textlength(element, counterId, maxCounter) {
	
	var counter = document.getElementById(counterId);
	counter.innerHTML = maxCounter - element.value.length;
	
	if (element.value.length >= maxCounter) {
	  element.value = element.value.substring(0,(maxCounter-1));
	} // if:value
	
} // check_textlength

// --------------------------------------------------------------------------------------
function doSearchPageHandle(page,formular,page) {
  doSearch(formular,'/_member/search/result.html',"page_nr="+page);
}
function doSearchAdvancedPageHandle(page,formid) {
  $('#hidpagenr').attr('value',''+page);
  $('#'+formid).attr('action','');
  $('#'+formid).submit();
  //document.getElementById('hidpagenr').value = page;
  return false;
}
function doSearch(formular, actionfile, strPosts) {

  req1create();
  if (strPosts != undefined){
	  strPosts = strPosts +"&control=true";	
  }
  
  else {
    var strPosts = "control=true";
  }
  
	if (formular != false) {
	  var numElements = formular.elements.length;  
		
		for (var i = 0; i < numElements; i++) {

			activeElement = formular.elements[i];
			
			if (activeElement.type != "radio" && activeElement.type != "checkbox" && activeElement.name != undefined && activeElement.type != "submit")		  
	
				strPosts = strPosts + "&" + activeElement.name + "=" + escape(activeElement.value);
			  
			else {		  
				
				activeElementName = activeElement.name;
				
				if (activeElement.type == "radio")
				  activeElementName = activeElementName.substring(0,activeElement.name.length-2);
				
				if (activeElement.checked)
			    strPosts = strPosts + "&" + activeElementName + "=" + escape(activeElement.value);
				
			}
			
		} // for:i
	} // if:formular 			
  doAjax(strPosts,actionfile,document.getElementById("content"))
	return false;
}

// --------------------------------------------------------------------------------------
function save_member_img(element, targetElement) {
	element.form.submit();
  document.getElementById(targetElement).innerHTML = "<img src=\"/images/loader.gif\" align=center style=margin:30px> <br>Bitte warten...";
}

/* Flash player functions by troos */
function playaudio(file,container,id) {
	var flashvars = {};
  flashvars.audio = file;
  /* flashvars.autoplay = false; */
  var params = {};
    params.scale = "noscale";
    params.allowfullscreen = "true";
    params.salign = "tl";
  var attributes = {};
    attributes.align = "left";
  swfobject.embedSWF("/js/flashaudioplayer.swf", container, "200", "35", "9.0.28", "/js/expressInstall.swf", flashvars, params, attributes);
  $.ajax({
      type: "POST",
      url:  '/vxMedia/audio.html',
      data: 'control=true&id='+id,
      success: function(msg){
        
      }
   });
  return false;
}


function playvideo(container,id) {
    x = $('#'+container);
    x.load("/inc/get/loadflv.php?id="+id);
    $.ajax({
      type: "POST",
      url:  '/vxMedia/video.html',
      data: 'control=true&id='+id,
      success: function(msg){
        
      }
   });
}


function checkFlash() {
          var v = swfobject.getFlashPlayerVersion();
          if ( v.major<8 ) {
            window.location.href="/de/information/noflash";
          }
}

//Connection
function openAddConnection(id,typ) {
  if(!typ) typ='profil';
  $.ajax({
      type: "POST",
      url:  '/inc/add/connection.html',
      data: 'id='+id+'&typ='+typ,
      success: function(msg){
        document.getElementById("addConnectionPopup").innerHTML = msg;
        openPopup("addConnection");
      }
  });
  return false;
}

function checkCheckbox(id,message) {
  x = $("#"+id);
  if(x.is(':checked')==true) {
    return true;
  }
  else {
    if(message) alert(message);
    return false;
  }
}

function checkBuyForm() {
    if(!$('input[name=paymethod]:checked').val()) { alert('Bitte w'+unescape("%E4")+'hlen Sie eine Bezahlm'+unescape("%F6")+'glichkeit aus.'); return false; }
    if(checkCheckbox('agb','Sie m'+unescape("%FC")+'ssen die AGB akzeptieren.')
       &&(
          ($('input[name=paymethod]:checked').val()=='banktransfer') 
          || (
            $('input[name=paymethod]:checked').val()=='debit' && checkCheckbox('debit','Sie m'+unescape("%FC")+'ssen das Lastschriftverfahren best'+unescape("%E4")+'tigen.')
          )
        ) && confirm('Bestellung absenden?')) return true; else return false;
}

function setup_frameworks() {
    // setup wysiwyg editors
    // Setup Lightboxes
    $('.lbimg').lightBox();
    $('.wysiwyg').each(function() {
      tinyMCE.execCommand('mceAddControl', true, $(this).attr("id"));
      tinyMCEarray[tinyMCEarray.length] = $(this).attr("id");
    });
}

function unload_tinymce_editors() {
    $.each(tinyMCEarray,function() {
      if($(this)) {
        tinyMCE.execCommand('mceRemoveControl',false,this);
      }
    });
    j = tinyMCEarray.length-1;
    while (j >= 0) {
      tinyMCEarray.splice(j, 1);
      j = tinyMCEarray.length-1;
    }
}

function setup_advanced_search() {
    $('#advanced_search_button').click(function() {
      $('#advanced_search').toggle("slow");
      return false;
    });
}



$().ready(function() {
    setup_frameworks();
    setup_advanced_search();

    $('#nav').droppy({speed: 100});
    //window.setTimeout("fixBranchenverzeichnisImgs()", 1000);
});

function requestsforwardtoregistry() {
    if(confirm('Sie ben'+unescape("%F6")+'tigen eine Premium- oder Basis-Plus Anzeige um auf eine Suchanfrage zu antworten. M'+unescape("%F6")+'chten Sie zur Registrierung weitergeleitet werden?')) document.location.href='/de/registry/index';
}