// active image filename
var _activeImage = "";
var old_item='';

function showHint(filter, str)
{
  if (!str) str="";
  if (str.length==0)
    { 
    //return;
    }

    var url="getspot.php";
    url=url+"?q="+str;
    url=url+"&filter="+filter;
    
    // var responsemsg = 
    $.ajax({
    url: url,
    async: false,
        error:function(xhr, status, errorThrown) { 
            alert(errorThrown+'\n'+status+'\n'+xhr.statusText); 
        },     
    success: function(data) {
      $('#txtHint').html(data);
      // alert('Load was performed.');
    }    
    });// .responseText;
    // $('#txtHint').html(responsemsg);
    // alert(responsemsg);
} 

function show_new_thread(ID, msg_ID, box_size1)
{
  $('#_newthread').html('<form name="new_thread" action="?action=save_msg" onsubmit="return validate_msg1()" method="post" style="width:640px; height:120px; font-size:12px; color:black; background-color:white; text-align:center; float:right; z-index:10;"><span style="float:left; width:75px; text-align:right; margin-top:5px;">Titel:</span><input type="text" name="new_msg_title" onchange="noschrott(this)" maxlength="75" style="margin:5px; width:505px; height:14px; min-height:14px; font-size:12px; border:solid 1px darkgrey;" /><br /><span style="float:left; width:75px; text-align:right; margin-top:5px;">Nachricht:</span><textarea name="new_msg_text" style="margin:5px; width:505px; height:50px; min-height:50px; font-size:12px; border:solid 1px darkgrey; " ></textarea><br /><input type="submit" class="FieldButton" value="neues Thema" /><input name="msg_ID" type="hidden" value="0" /></form><div style="clear:both;"></div>');
  $('#_newthread').show();
}

function show_new_message(ID, msg_ID, box_size1, re_msg_title)
{

  xitem="_newmessage"+msg_ID;
  // alert(xitem);
  // document.getElementById(xitem).style.height='200px;';
  $('#'+xitem).html('<form name="new_message" action="?action=save_msg" method="post" onsubmit="return validate_msg()" style="width:640px; height:175px; min-height:175px; font-size:12px; color:#9a9a9a; background-color:white; text-align:center; float:right; z-index:10;">Titel: <input type="text" name="new_msg_title" onchange="noschrott(this)" maxlength="75" style="margin:5px; width:'+(box_size1-15)+'px; height:14px; min-height:14px; font-size:12px; " value="'+re_msg_title+'" /><br />Text: <textarea name="new_msg_text" style="margin:5px; width:'+(box_size1-15)+'px; height:50px; min-height:50px; font-size:12px; " ></textarea><br /><div id="SendButton"><input type="submit" class="FieldButton" value="neuer Eintrag"  /><input name="msg_ID" type="hidden" value="'+msg_ID+'" /></div></form>');
  $('#'+xitem).show(); 
  if (old_item) $('#'+old_item).hide(); 
  old_item=xitem;
   
}

function show_new_message1(ID, msg_ID, box_size1, re_msg_title)
{

  xitem="_newmessage"+msg_ID;

  $('#'+xitem).html('<form name="new_message_form" style="width:530px; height:170px; min-height:170px; font-size:12px; color:#9a9a9a; background-color:white; text-align:center; float:right; z-index:10; clear:both;margin: 0 0 10px; 0;">Titel: <input type="text" name="new_msg_title" onchange="noschrott(this)" maxlength="75" style="margin:5px; width:'+(box_size1-15)+'px; height:14px; min-height:14px; font-size:12px; " value="'+re_msg_title+'" /><br />Text: <textarea name="new_msg_text" style="margin:5px; width:'+(box_size1-15)+'px; height:50px; min-height:50px; font-size:12px; " ></textarea><br /><div id="SendButton"><input type="button" class="FieldButton" name="sendbutton" style="cursor:pointer;" onclick="saveMSG('+msg_ID+', document.new_message_form.new_msg_title.value, document.new_message_form.new_msg_text.value)" value="Eintrag speichern" /></div></form>');
  $('#'+xitem).show(); 
  if (old_item) $('#'+old_item).hide(); 
  old_item=xitem;
   
}

function saveVOTE(id, vote)
{ 
  if (vote)
  { 
    var url="ajax_savevote.php";
    var url="ajax_function.php?function=savevote";
    url=url+"&id="+id;
    url=url+"&vote="+vote;
    
    var responsemsg = $.ajax({
    url: url,
    async: false
    }).responseText;
    $('#VotingButton').html('<span class="kleingedruckt">'+responsemsg+'</span>');
  }

} 

function saveMSG(msg_id, msg_title, msg_str)
{
  if (msg_str.length==0)
    { 
    // document.getElementById("txtHint").innerHTML="";
    // str=""; 
    //return;
    }

  var url="ajax_function.php?function=saveMSG";
  var poststr="msg_id="+msg_id;
  poststr=poststr+"&msg_title="+( msg_title );
  poststr=poststr+"&msg_str="+( msg_str );

  $.post(url, poststr, function(data) {
   // alert("Data Loaded: " + data);
 });

  $('#'+'_newmessage'+msg_id).html('Danke fuer Deinen Eintrag!');
  //  alert(poststr);
  // location.reload();  
 
} 

function changestars(stars, id)
  {
    if (id>0) star_zusatz="-"+id; else { star_zusatz=""; id=""; }
    for (astar=1;astar<=stars;astar++)
    {
      istar="starimg"+astar+star_zusatz;
      // writeImage(istar,istar,"images/star_full.gif");
      $("#"+istar).attr("src", "images/star_full.gif");
      
      for (anstar=stars+1;anstar<6;anstar++)
      {
        instar="starimg"+anstar+star_zusatz;
        $("#"+instar).attr("src", "images/star_none.gif");
        // writeImage(instar,instar,"images/star_none.gif");
      }
    }
    // if (document.voting.votingbutton) document.voting.votingbutton.style.visibility="visible";
    // if (document.voting.vote) document.voting.vote.value=stars;
    eval("document.voting"+id+".votingbutton"+id+".style.visibility='visible';");
    eval("document.voting"+id+".vote"+id+".value=stars;");
  }


function showSearch(str)
{
  if (str>"")
  {
    var responsemsg = $.ajax({
    url: "search_parkour-board.php?search="+str,
    async: false
    }).responseText;
    
    if (!responsemsg)
        {
          responsemsg = "Keine Einträge gefunden ...";
        }
  
        $("#search_results").html(responsemsg);
        $("#search_results").show();  
  }
}

function save_ProfilePic(str)
{
  if (str>"")
  {
    var Save = $.ajax({
    url: "ajax_function.php?function=save_ProfilePic&Picture="+str,
    async: false
    });
  }
}
function delete_ProfilePic(str)
{
  if (str>"")
  {
    var Save = $.ajax({
    url: "ajax_function.php?function=delete_ProfilePic&Picture="+str,
    async: false
    }).responseText;
  }
  location.reload();

}

function make_ProfilePic(str)
{
  if (str>"")
  {
    var Save = $.ajax({
    url: "ajax_function.php?function=make_ProfilePic&Picture="+str,
    async: false
    }).responseText;
  }
  location.reload();
}

function delete_SpotPic(Spot_ID,str)
{
  if (str>"")
  {
    var Save = $.ajax({
    url: "ajax_function.php?function=delete_SpotPic&Spot_ID="+Spot_ID+"&Picture="+str,
    async: false
    }).responseText;
  }
  // alert(Save);
  location.reload();
}

function make_SpotPic(Spot_ID,str)
{
  if (str>"")
  {
    var Save = $.ajax({
    url: "ajax_function.php?function=make_SpotPic&Spot_ID="+Spot_ID+"&Picture="+str,
    async: false
    }).responseText;
  }
  location.reload();
}

function make_SpotAddress(Spot_ID, lat, lng)
{
  if (Spot_ID>"")
  {
    
    // codeLatLng(Spot_ID, lat, lng); 
    // alert(spot_address);
    var Save = $.ajax({
    url: "ajax_function.php?function=make_SpotAddress&Spot_ID="+Spot_ID+"&Spot_address_land="+spot_address_land+"&Spot_address_land_full="+spot_address_land_full+"&Spot_address_PLZ="+spot_address_PLZ+"&Spot_address_ort="+spot_address_ort+"&Spot_address="+spot_address,
    async: false
    }).responseText;
  }
  // location.reload();
}

function show_PeopleOnSpot(Spot_ID, Spot_Name)
{
  if (!Spot_ID) Spot_ID ="";

  var PeopleOnSpot = $.ajax({
  url: "ajax_function.php?function=PeopleOnSpot&Spot_ID="+Spot_ID+"&Spot_Name="+Spot_Name,
  async: false
  }).responseText;

  $('#Friendlist').html(PeopleOnSpot);
  // location.reload();
}

function save_PeopleOnSpot(Spot_ID, Spot_Name, rangeDemoStart, rangeDemoFinish, EventMSG)
{
  if (Spot_ID) 
  {
    var PeopleOnSpot = $.ajax({
    url: "ajax_function.php?function=PeopleOnSpotSave&Spot_ID="+Spot_ID+"&rangeDemoStart="+rangeDemoStart+"&rangeDemoFinish="+rangeDemoFinish+"&EventMSG="+EventMSG,
    async: false,
    success: function(){show_PeopleOnSpot(Spot_ID, Spot_Name)}
    });
    
    // $('#Friendlist').html(PeopleOnSpot);
  }
  // location.reload();
}

function OnRsz(dummy)
{
    //  alert($(window).width());
    if ($(window).width()<=960)
    {
      $('#wrapper_out').css('left',0);
    }
    else if ($(window).width()>=961 ) 
    {

      pos_x_diff=$(window).width()-1280;
      pos_x_diff1=$(window).width()-960;
      
      $('#wrapper_left').css('left',Math.floor( (pos_x_diff1/2.6))-122 ); 
      $('#wrapper').css('left',Math.floor( (pos_x_diff1/2.6)) ); 
      $('#wrapper_right').css('left',Math.floor( 960+(pos_x_diff1/2.6)) );
      if ($(window).width()<1280 ) $('#wrapper_right').css('width',Math.floor(198+(pos_x_diff/1.615)) );
      else $('#wrapper_right').css('width',198 );

    }

}

var akt_zeilenlength = 1;
  
function check_length(my_form)
{
  maxLen = 500; // max number of characters allowed
  InputmaxLen = 500; // max number of characters allowed
  akt_length=Personalanfrage.Anmerkungen.value.length;
  lastchar=Personalanfrage.Anmerkungen.value.substr(akt_length);
  // alert (lastchar+"-"+akt_zeilenlength)
  // if (lastchar>=" ") 
  akt_zeilenlength+=1; 
  // else akt_zeilenlength = 0; 
  /*
  if (Personalanfrage.Anmerkungen.value.length >= InputmaxLen) 
  {
    Personalanfrage.Anmerkungen.value = Personalanfrage.Anmerkungen.value+"\n";
    akt_zeilenlength = 1;
  }
  */
  // else akt_zeilenlength+=1; 
  
  if (Personalanfrage.Anmerkungen.value.length > maxLen) 
  {
  // Alert message if maximum limit is reached.
  // If required Alert can be removed.
  // var msg = "You have reached your maximum limit of characters allowed";
  // alert(msg);
  // Reached the Maximum length so trim the textarea
    Personalanfrage.Anmerkungen.value = Personalanfrage.Anmerkungen.value.substring(0, maxLen);
    // akt_zeilenlength = maxLen;
  }
  else
  {
    zz="Zeichen:"+Personalanfrage.Anmerkungen.value.length;
    writeLayer("Personalanfrage_zz",zz)
  }
}  


// userprofil.style.display="none";

  function open_profile(UserID)
  {
    /*
    var userprofil=document.getElementById("UserProfil");
    userprofil.style.display="block";
    */
    // location.href="parkour-userprofile.php?show_user="+UserID;
    location.href="parkour-userprofile.php";
        // alert("-");
  }
  function close_profile(UserID)
  {
    var userprofil=document.getElementById("UserProfil");
    userprofil.style.display="none";
    // alert("-");
  }
// Formularfehler abfangen

	function correctemail(feld)
	{
	   if(feld.value == "") return;

	   // Feld analysieren
	   var test = feld.value
	   var objRegExp = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	
	   // OK? Dann zurueck!
	   if(objRegExp.test(test)!=false)
	   {
	      // Ergebnis darstellen
	      feld.value = test;

	      return
	   }

	   // Fehlermeldung
	   alert("Please enter a valid email address!")

	   // Eingabe selektieren und Eingabefokus setzen
	   feld.select();
	   feld.focus();
	   feld.value = "";
	}
	function noschrott(feld)
	{
	   error=false;
	   // alert ('HIER!');
	   if(feld.value == "") error=true;

	   // Feld analysieren
	   var test = feld.value
	   var objRegExp = /^[a-zA-Z0-9+-. -]*$/;
	
	   // OK? Dann zurueck!
	   if(objRegExp.test(test)!=false || error==false)
	   {
	      // Ergebnis darstellen
	      feld.value = test;

	      return
	   }

	   // Fehlermeldung
	   alert("Only chars a-z are valid!")

	   // Eingabe selektieren und Eingabefokus setzen
	   feld.select();
	   feld.focus();
	   feld.value = "";
	}
	// Pruefung, ob Feld numerisch
	function numerisch(feld)
	{
	   if(feld.value == "")
	      return

	   // Feld analysieren
	   var test = feld.value
	   var objRegExp = /^[0-9]*$/;
	
	   // OK? Dann zurueck!
	   if(objRegExp.test(test)!=false)
	   {
	      // Ergebnis darstellen
	      feld.value = test;

	      return
	   }

	   // Fehlermeldung
	   alert("Please enter only numeric values into this field!")

	   // Eingabe selektieren und Eingabefokus setzen
	   feld.select();
	   feld.focus();
	   feld.value = "";
	}
	function numerischmore(feld)
	{
	   if(feld.value == "")
	      return

	   // Feld analysieren
	   var test = feld.value
	   var objRegExp = /^[0123456789 +-/]*$/;
	   // var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	
	   // OK? Dann zurueck!
	   if(objRegExp.test(test)!=false)
	   {
	      // Ergebnis darstellen
	      feld.value = test;

	      return
	   }

	   // Fehlermeldung
	   alert("Please enter only numeric values into this field!")

	   // Eingabe selektieren und Eingabefokus setzen
	   feld.select();
	   feld.focus();
	   feld.value = "";
	}
	function clearfeld(feld)
	{
	   // Eingabe selektieren und Eingabefokus setzen, defaults löschen
	   feld.select();
	   feld.focus();
	   feld.value = "";
	}

	function validate_anfrage() {

		var v1 = document.Anfrage.name.value;
		var v2 = document.Anfrage.email.value;
		var v3 = document.Anfrage.Anfrage1.checked;
		var v4 = document.Anfrage.Anfrage2.checked;
		var v5 = document.Anfrage.Anfrage3.checked;

		
		if (v2.length<5 || v2.indexOf("@")==-1 || v2.indexOf(".")==-1) {
			alert('Please enter correct email address!');
			return false;
		} 
		else 
		{

			if ( v1 == '' || v2 == '' || ( v3 == '' && v4 == '' && v5 == '' ) ) {
				alert('Please fill in all required fields!');
				return false;
			}
			
		}
    return true;
	}
	
	function validate_msg() {

		var v1 = document.new_message.new_msg_title.value;
		var v2 = document.new_message.new_msg_text.value;

	  var objRegExp = /^[a-zA-Z0-9äöüßÄÖÜ+-.,:?!()*^ -]*$/;
	  
	  if( objRegExp.test(v1)==false )
	  {     
			if ( v1 == '' || v2 == '' ) {
				alert('Please fill in all required fields!');
				return false;
			}
			alert('Only alphanumeric chars allowed!');
      return false;
		}
    else return true;
	}
	function validate_msg1() {

		var v1 = document.new_thread.new_msg_title.value;
		var v2 = document.new_thread.new_msg_text.value;

	  var objRegExp = /^[a-zA-Z0-9äöüßÄÖÜ+-.,:?!()*^ -]*$/;
	
	  if( objRegExp.test(v1)==false )
	  {     
			if ( v1 == '' || v2 == '' ) {
				alert('Please fill in all required fields!');
				return false;
			}
			alert('Only alphanumeric chars allowed!');
      return false;
		}
    else return true;
	}

