/**
 * get current host
 */
function getHost() {
	if(String(window.location).indexOf("http://test.") != "-1") {
	    return 'http://test.freizeit-branchenbuch.de/';
	} else {
	    return 'http://www.freizeit-branchenbuch.de/';
	}
}

/**
 * open window
 */
function openWindow(file) {
    window.open(getHost()+'/html/'+file,"javarea","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=700,left=0,top=0");
}

/**
 * back Button
 */
function backButton() {
    window.history.back();
}

/**
 * set a entry as marked
 */
function sendMarked(sender, id) {
	$.post("../setMarked.php", { id: id }, function(data) {
	  //alert(data);
      $('#'+sender).html('Wurde markiert');
	});
	return false;
}

/**
 * in Entry List
 */
function inEntryList(id) {
    $.post("../inEntryList.php", { id: id }, function(data) {  
	  $('#ml'+id).html('<span id="ml'+id+'"><a href="#" onclick="outEntryList('+id+');return false;"><img src="./images/but_delete.gif" alt="Entfernen" title="Entfernen" border="0" /></a></span>');
	  // toggle noticelist
	  if( data == '1 Eintrag' ) {
	  	  $('#noticelist').fadeIn("slow");
	  }
	  //alert(data);
	  $('#notice_nums').html(data);
    });
}

/**
 * out Entry List
 */
function outEntryList(id) {
    $.post("../inEntryList.php", { did: id }, function(data) {
	  $('#ml'+id).html('<span id="ml'+id+'"><a href="#" onclick="inEntryList('+id+');return false;"><img src="./images/but_merken.gif" alt="Merken" title="Merken" border="0" /></a></span>');
	  // toggle noticelist
	  if( data == '0 Eintr&auml;ge' ) {
	  	  $('#noticelist').fadeOut("slow", function() {
                      $('#noticelist').hide();
                  });
	  }
	  //alert(data);
	  $('#notice_nums').html(data);	  
    });
}

/**
 * del Entry List from noticelist
 */
function delEntryList(id) {
    $.post("../inEntryList.php", { did: id }, function(data) {
	  $('#rben'+id).slideUp("slow");
	  // toggle noticelist
	  if( data == '0 Eintr&auml;ge' ) {
	  	  $('#noticelist').fadeOut("slow", function() {
                      $('#noticelist').hide();
                  });
	  	  // close email fields if visible
	      if (!$("#notice_email").is(":hidden")) {
              $("#notice_email").slideUp("slow");    
          }
	  }
	  //alert(data);
	  $('#notice_nums').html(data);
    });
}

/**
 * in Event List
 */
function inEventList(id) {
    $.post("../inEventList.php", { id: id }, function(data) {  
      $('span#ml'+id).each(function (i) {
        $(this).html('<span id="ml'+id+'"><a href="#" onclick="outEventList('+id+');return false;"><img src="./images/but_delete.gif" alt="Entfernen" title="Entfernen" border="0" /></a></span>');
	  });
	  // toggle noticelist
	  if( data == '1 Eintrag' ) {
	  	  $('#noticelist').show();
	  }
	  //alert(data);
	  $('#notice_nums').html(data);
    });
}

/**
 * out Event List
 */
function outEventList(id) {
    $.post("../inEventList.php", { did: id }, function(data) {
      $('span#ml'+id).each(function (i) {
        $(this).html('<span id="ml'+id+'"><a href="#" onclick="inEventList('+id+');return false;"><img src="./images/but_merken.gif" alt="Merken" title="Merken" border="0" /></a></span>');
	  });	
	  // toggle noticelist
	  if( data == '0 Eintr&auml;ge' ) {
	  	  $('#noticelist').hide();
	  }
	  //alert(data);
	  $('#notice_nums').html(data);
    });
}

/**
 * del Event List from noticelist
 */
function delEventList(id) {
    $.post("../inEventList.php", { did: id }, function(data) {
	  $('#rbev'+id).slideUp("slow");
	  // toggle noticelist
	  if( data == '0 Eintr&auml;ge' ) {
	  	  $('#noticelist').hide();
	  	  // close email fields if visible
	      if (!$("#notice_email").is(":hidden")) {
              $("#notice_email").slideUp("slow");    
          }
	  }
	  //alert(data);
	  $('#notice_nums').html(data);
    });
}

/**
 * open notice email field
 */
function openNotice() {
    if (!$("#noticelist").is(":hidden")) {
        if ($("#notice_email").is(":hidden")) {
            $("#notice_email").slideDown("slow", function() {
                $('#notice_email_val').select();
            });
        } else {
            $("#notice_email").slideUp("slow");
        }
    }
}

/**
 * send notice email
 */
function sendEmail() {
    var foul = false;
    if ( $("#notice_email_val").val() == "" ) {
        foul = true;
    }
    if ( $("#notice_email_val").val() == "E-Mail Adresse" ) {
        foul = true;
    }
    if ( $("#notice_name_val").val() == "" ) {
        foul = true;
    }
    if ( $("#notice_name_val").val() == "Dein Name" ) {
        foul = true;
    }

    if(foul == false) {
        $.post("../inSendList.php", { mail: $("#notice_email_val").val(), user: $("#notice_name_val").val() }, function(data) {
	  if( data == 'go' ) {
            $("#response_msg").html('<div style="padding:4px;"><strong>E-Mail wird versendet.</strong></div>');
            $("#notice_email_val").val('E-Mail Adresse');
            $("#notice_name_val").val('Dein Name');
            setTimeout('$("#notice_email").slideUp("slow")', 3000);
            setTimeout('$("#response_msg").html(\'\')', 3100);
          } else if( data == 'email' ) {
            $("#response_msg").html('<div style="padding:4px;"><strong>E-Mail hat ein falsches Format.</strong></div>');
	  } else {
            $("#response_msg").html('<div style="padding:4px;"><strong>An diese E-Mail wurde heute genug verschickt. Morgen wieder.</strong></div>');
          }
        });
    } else {
        $("#response_msg").html('<div style="padding:4px;"><strong>E-Mail leer oder nicht Dein Name.</strong></div>');
    }
    return false;
}

/** 
 * set Bookmark 
 */
function lesezeichen() {
  var url=window.location.href,t=document.title,ap=navigator.appName;
  if(ap=="Microsoft Internet Explorer"){
    window.external.AddFavorite(url,t);
    return;
  } else if(ap=="Netscape") {
    if((typeof window.sidebar=="object") && (typeof window.sidebar.addPanel=="function")) {
      window.sidebar.addPanel(t,url,"");
      return;
    }
  } else {
    alert("Das automatische Anlegen von Lesezeichen wird\nvon Ihrem Browser nicht unterst�tzt.\nBitte benutzen Sie die Lesezeichenfunktion Ihres Browsers.");
  }
}
// ---
function toURL(str) {
  var pat = /./g;    
  var reg1 = str;
  var liste = reg1.match(pat);
  if(liste) {
    for(var i=0; i<=liste.length; i++) {
      reg1 = reg1.replace("�","ae");
      reg1 = reg1.replace("ä","ae");
      reg1 = reg1.replace("�","oe");
      reg1 = reg1.replace("ö","oe");
      reg1 = reg1.replace("�","ue");
      reg1 = reg1.replace("ü","ue");
      reg1 = reg1.replace("�","Ae");
      reg1 = reg1.replace("�","Ae");
      reg1 = reg1.replace("�","Oe");
      reg1 = reg1.replace("�?","Oe");
      reg1 = reg1.replace("�","Ue");
      reg1 = reg1.replace("�","Ue");
      reg1 = reg1.replace(" ","_");
      reg1 = reg1.replace("&amp;","UnD");
    }
  }  
  return reg1;
}
// ---
function fromURL(str) {
  var pat = /./g;    
  var reg1 = str;
  var liste = reg1.match(pat);
  if(liste) {
    for(var i=0; i<=liste.length; i++) {
      reg1 = reg1.replace("ae","�");
      reg1 = reg1.replace("oe","�");
      reg1 = reg1.replace("ue","�");
      reg1 = reg1.replace("Ae","�");
      reg1 = reg1.replace("Oe","�");
      reg1 = reg1.replace("Ue","�");
      reg1 = reg1.replace("_"," ");
      reg1 = reg1.replace("UnD","und");
    }
  }  
  return reg1;
}

// ---
function sendSearch() {
  if( ($('#location').val() != '') && ($('#location').val() != 'Ort - PLZ - Stadtteil') && ($('#location').val().indexOf(" ") == "-1") ) {
    var location = $('#location').val();	
  } else {
    var location = 'locations';
  }
  
  var action = getHost() + toURL(location) + '.html';
  $('#frm_search').attr({action: action});	
}


