/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * BERN-OST CLIENT-SIDE-SCRIPTS
 * >> verwendet jquery - www.jquery.com
 * >> objekt "bernost" wird initialisiert in der document-ready-funktion kurz vor dem </body>
 * >> während dem php-output können je nach seite (_php/N.php) diverse zusätzliche onload-
 *    funktionen hinzukommen, diese werden nach dieser initialisierung angehängt
 * >> weitere verwendete scripts, siehe index.php: google maps, google analytics, facebook api,
 *    tinyMCE, jquery>tooltip, jquery>datepicker, jquery>jflow
 * have fun :-) marc christen, worb, 27.7.2011
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /


/* objekt-container*/

var bernost=false;
function _bernost(){

/* inline-popup (iframe) */

	this.inline_popup=false;

	(function($){$.fn.popup=function(params){
		inline_popup=this;
		var popup_width=arguments[0];var popup_height=arguments[1];var popup_url=arguments[2];var popup_fade=arguments[3];
		if(popup_fade=='fade'){$('#drag_bg').fadeIn(100);}
		inline_popup.mousedown(function(emd){var offset=inline_popup.offset();var mxOff=emd.pageX-offset.left;var myOff=emd.pageY-offset.top;$("body").mousemove(function(emm){var x=emm.pageX-mxOff-$(window).scrollLeft();var y=emm.pageY-myOff-$(window).scrollTop();inline_popup.css({'left':x,'top':y});}).addClass("no-select").attr('unselectable','on');}).mouseup(function(e){$('body').unbind('mousemove').removeClass("no-select").attr('unselectable','off');});
		$('#drag_elem').html('');$('<a id="drag_bar" href="">&times;</a>').bind('click',function(event){drag_hide(event)}).appendTo(inline_popup);$('#drag_bg').bind('click',function(event){drag_hide(event)});
		$('<iframe id="drag_frame" src="'+popup_url+'" frameborder="0" scrolling="no" style="display:none;width:'+popup_width+'px;height:'+popup_height+'px;"></iframe>').appendTo(inline_popup);$('#drag_frame').fadeIn(100);
		inline_popup.detach();$('body').append(inline_popup);inline_popup.animate({height:(popup_height+25)+'px',width:popup_width+'px'},200,function(){});inline_popup.fadeIn(100);
	};})(jQuery);

	function drag_show(url,len_x,len_y,fade_in){$('#drag_elem').popup(len_x,len_y,url,fade_in);return false;}
	this.drag_show=drag_show;

	function drag_hide(event){if(typeof(event)!="undefined"){event.preventDefault();}$('#drag_bg').fadeOut(100);$('#drag_elem').hide();$('#drag_bar').remove();}
	this.drag_hide=drag_hide;

	function display_info(){drag_show('_html_popup/_bernost.php',420,315,'fade');bernost.clear_keybuffer();}
	this.display_info=display_info;


/* startseite: suchfunktion */

	this.search_on=0;

	function start_search_blur(){
		var search_value=id('input_searchbox').val();
		if((search_value=='')||(search_value=='suche')){id('input_searchbox').css({'color':'#a5bae5'});id('input_searchbox').val('suche');}
		id('suchfeld_ergebnisse').fadeOut();
	} this.start_search_blur=start_search_blur;

	function start_search_focus(){
		var search_value=id('input_searchbox').val();
		if((search_value.length>3)&&(search_value!='suche')){start_search();}
		if(id('suchfeld_ergebnisse').html()!=''){id('suchfeld_ergebnisse').fadeIn();}
		id('input_searchbox').css({'color':'#000000'});
		if (search_value=='suche')id('input_searchbox').val('');
	} this.start_search_focus=start_search_focus;

	function start_search(){
		clearTimeout(bernost.search_on);
		bernost.search_on=setTimeout('bernost.do_search()',250);
	} this.start_search=start_search;

	function do_search(){
		var search_value=id('input_searchbox').val();
		if(search_value.length>2)
		{
			if(id('suchfeld_ergebnisse').css('display')=='none'){id('suchfeld_ergebnisse').fadeIn();}
			var search_url='_ajax/suchergebnisse.php?search='+encodeURIComponent(search_value);
			$.get(search_url,function(data){if(data!=''){$('#suchfeld_ergebnisse').html(data);}});
		}
		else{id('suchfeld_ergebnisse').fadeOut();}
	} this.do_search=do_search;


/* ajax */

	function check_xml(i){$.ajax({url:'_ajax/enable_ajax.php?q='+i,success:function(){}});}
	this.check_xml=check_xml;

	function ajax_update_main(get_url){if(get_url!=''){if(get_url.indexOf('#')>=0){get_url=get_url.substring(0,get_url.indexOf('#'));}$.ajax({url:get_url,success:function(transport){$('#bomcon').html(transport);if(typeof(FB)!='undefined'){FB.XFBML.parse($("#fb_like").get(0));}_gaq.push(['_trackPageview',get_url]);}});return false;}return true;}
	this.ajax_update_main=ajax_update_main;

    function ajax_cursor(){$("html").bind("ajaxStart",function(){$(this).addClass('busy');}).bind("ajaxStop", function(){$(this).removeClass('busy');});}
	this.ajax_cursor=ajax_cursor;


/* formularüberprüfung */

	function form_fields_empty(a){var f='';for(i=0;i<a.length;i++){if(id(a[i][0]).val()==''){f+='- '+a[i][1]+'\n';}}if(f!=''){alert('Bitte prüfen Sie Ihre Angaben:\n'+f);return false;}else{return true;}}
	this.form_fields_empty=form_fields_empty;

	function check_userform(){return form_fields_empty([['adr_nachname','Nachname'],['adr_vorname','Vorname'],['adr_passwort','Passwort'],['adr_strasse','Strasse/Nr.'],['adr_ort','PLZ/Ort'],['adr_telefon','Telefon']]);}
	this.check_userform=check_userform;

	function check_adminform(){return form_fields_empty([['email','E-Mail-Adresse'],['passwort','Passwort']]);}
	this.check_adminform=check_adminform;

	function validate_mail(email){var reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;if(reg.test(email)==false){return false;}return true;}
	this.validate_mail=validate_mail;

	function check_captcha_submit_mailform(){var captcha=bernost.id("captcha").val();var captcha_id=bernost.id("captcha_id").val();$.get('_ajax/check_captcha.php?c='+captcha+'&k='+captcha_id,function(data){if(data=='fehler'){alert('Bitte überprüfen Sie das Feld "Spam-Schutz"');}else{bernost.id('mf').submit();}});}
	this.check_captcha_submit_mailform=check_captcha_submit_mailform;

	function sende_mail_eintrag(){if((bernost.id('sender_name').val()!='')&&(bernost.id('sender_mail').val()!='')&&(bernost.id('empfaenger_mail').val()!='')&&(bernost.id('nachricht').val()!='')){if((bernost.validate_mail(bernost.id('sender_mail').val())!=false)&&(bernost.validate_mail(bernost.id('empfaenger_mail').val())!=false)){ bernost.check_captcha_submit_mailform();}else{alert('Bitte geben Sie gültige E-Mail-Adressen ein.');}}else{alert('Bitte füllen Sie alle Felder aus, um eine Nachricht abzusenden.');}return false;}
	this.sende_mail_eintrag=sende_mail_eintrag;

	function check_nachname(){var nn=bernost.id('nnform').val();var err=bernost.id('nnerr');if(nn.length>2){err.css({'color':'#009900'});err.val('ok');}else{err.css({'color':'#ff0000'});err.val('fehlt');}}
	this.check_nachname=check_nachname;

	function check_vorname(){var vn=bernost.id('vnform').val();var err=bernost.id('vnerr').val();if(vn.length>2){err.css({'color':'#009900'});err.val('ok');}else{err.css({'color':'#ff0000'});err.val('fehlt');}}
	this.check_vorname=check_vorname;

	function check_adresse(){var adr=bernost.id('strform').val();var err=bernost.id('val');if(adr.length>2){err.css({'color':'#009900'});err.val('ok');}else{err.css({'color':'#ff0000'});err.val('fehlt');}}
	this.check_adresse=check_adresse;

	function check_telefon(){var tel=bernost.id('t1form').val();var err=bernost.id('telerr');if(tel.length>9){err.css({'color':'#009900'});err.val('ok');}else{err.css({'color':'#ff0000'});err.val('fehlt');}}
	this.check_telefon=check_telefon;

	function check_pw(){var pw1=bernost.id("cform").val();var pw2=bernost.id("cform2").val();var err=bernost.id("pwerr");if((pw1.length>2)&&(pw1==pw2)){err.css({'color':'#009900'});err.val('ok');}else{err.css({'color':'#ff0000'});err.val('fehler');}}
	this.check_pw=check_pw;

	function check_mail(){var email=bernost.id('mform').val();if(bernost.validate_mail(email)!=false){$.get('_ajax/check_email_avail.'+'php?email='+email,function(data){var err=bernost.id('emerr');var input=bernost.id('mform');if(data=='besetzt'||data=='ungültig'){input.val('');err.css({'color':'#ff0000'});err.val(data);}else{err.val('ok'); err.css({'color':'#009900'});}});}else{bernost.id("emerr").css({'color':'red'});bernost.id("emerr").val('ungültig');bernost.id("mform").val('');}}
	this.check_mail=check_mail;

	function anm_check_captcha(){var captcha=bernost.id("captcha").val();if(captcha.length>2){var captcha_id=bernost.id('captcha_id').val();$.get('_ajax/check_captcha.php?c='+captcha+'&k='+captcha_id,function(data){var err=bernost.id('captcha_err');var input=bernost.id('captcha');if(data=='fehler'){input.val('');err.css({'color':'#ff0000'});err.val(data);}else{err.val('ok'); err.css({'color':'#009900'});}});}else{bernost.id('captcha_err').css({'color':'red'});bernost.id('captcha_err').val('falsch');bernost.id('captcha').val('');}}
	this.anm_check_captcha=anm_check_captcha;

	function submit_anmeldung(){
		var error=false;var email=bernost.id('mform');var nachname=bernost.id('nnform');var vorname=bernost.id('vnform');var strasse_nr=bernost.id('strform');var plz=bernost.id('plzform');var ort=bernost.id('ortform');var telefon1=bernost.id('t1form');var fax=bernost.id('faxform');var pw=bernost.id('cform');var cap=bernost.id('captcha');var err_pw=bernost.id('pwerr');var err_cap=bernost.id('captcha_err');var err_email=bernost.id('emerr');var err_nachname=bernost.id('nnerr');var err_vorname=bernost.id('vnerr');var err_strasse_nr=bernost.id('adrerr');var err_plz=bernost.id('plzerr');var err_ort=bernost.id('orterr');var err_telefon1=bernost.id('telerr');
		if(email.val()==''){err_email.css({'color':'#ff0000'});error=true;err_email.val('fehlt');}else{err_email.css({'color':'#009900'});err_email.val('ok');}if(nachname.val()==""){err_nachname.css({'color':'#ff0000'});error=true;err_nachname.val('fehlt');}else{err_nachname.css({'color':'#009900'});err_nachname.val('ok');}if(vorname.val()==""){err_vorname.css({'color':'#ff0000'});error=true;err_vorname.val('fehlt');}else{err_vorname.css({'color':'#009900'});err_vorname.val('ok');}if(strasse_nr.val()==""){err_strasse_nr.css({'color':'#ff0000'});error=true;err_strasse_nr.val('fehlt');}else{err_strasse_nr.css({'color':'#009900'});err_strasse_nr.val('ok');}
		if(ort.val()==""){err_ort.css({'color':'#ff0000'});error=true;err_ort.val('fehlt');}else{err_ort.css({'color':'#009900'});err_ort.val('ok');}if(email.val()==""){err_email.css({'color':'#ff0000'});error=true;err_pw.val('fehlt');}else{err_pw.css({'color':'#009900'});err_pw.val('ok');}if(cap.val()==""){err_cap.css({'color':'#ff0000'});err_cap.val('fehlt');error=true;}else{err_cap.css({'color':'#009900'});err_cap.val('ok');}if(telefon1.val().length<10){err_telefon1.css({'color':'#ff0000'});error=true;err_telefon1.val('fehlt');}else{err_telefon1.css({'color':'#009900'});err_telefon1.val('ok');}
		if(!error){bernost.id('anmeldeformular').attr('action','index.php?p=44');bernost.id('senden').attr('disabled',true);bernost.id('anmeldeformular').submit();}else{bernost.id("mainerr").val('Bitte pruefen Sie alle Angaben.');}
	} this.submit_anmeldung=submit_anmeldung;

	function search_check_zusatzfelder(){
		var inserate_button = bernost.id('b_inserate');
		if (inserate_button.attr("checked") != "undefined" && inserate_button.attr("checked") == "checked")
		{
			bernost.id('inserate_suchfeld').show();
		}
		else
		{
			bernost.id('inserate_suchfeld').hide();
		}
	} this.search_check_zusatzfelder=search_check_zusatzfelder;


/* screen und positionierung */

	function wwidth(){
		var viewportwidth=0;
		if(typeof window.innerWidth!='undefined'){viewportwidth=window.innerWidth}
		else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined'&&document.documentElement.clientWidth!=0){viewportwidth=document.documentElement.clientWidth}
		else {viewportwidth=document.getElementsByTagName('body')[0].clientWidth}
		return viewportwidth;
	} this.wwidth=wwidth;

	function wheight(){
		var viewportheight=0;
		if(typeof window.innerWidth!='undefined'){viewportheight=window.innerHeight}
		else if(typeof document.documentElement!='undefined'&&typeof document.documentElement.clientWidth!='undefined'&&document.documentElement.clientWidth!=0){viewportheight=document.documentElement.clientHeight}
		else{viewportheight=document.getElementsByTagName('body')[0].clientHeight}
		return viewportheight;
	} this.wheight=wheight;

	function find_position(obj_id){var curleft=curtop=0;obj=document.getElementById(obj_id);if(obj.offsetParent){do{curleft+=obj.offsetLeft;curtop+=obj.offsetTop;}while(obj=obj.offsetParent);}return [curleft,curtop];}
	this.find_position=find_position;

	function pageScrollOffset(){if(window.pageYOffset){return window.pageYOffset;}else{return document.documentElement.scrollTop;}}
	this.pageScrollOffset=pageScrollOffset;


/* keybuffer, experimentell */

	this.keybuffer=[];

	$(document).keyup(function(event){bernost.keybuffer.push(event.keyCode);bernost.check_keybuffer();});

	function clear_keybuffer(){bernost.keybuffer=[];}
	this.clear_keybuffer=clear_keybuffer;

	function build_keystring(a){var b='';for (i=0;i<a.length;i++){b+=a[i];}return b;}
	this.build_keystring=build_keystring;

	function check_keybuffer(){var k=bernost.build_keystring(bernost.keybuffer);if((k.substring(k.length-22,k.length)=='8365737884693276857685')||(k.substring(k.length-20,k.length)=='83657378846976857685')){bernost.display_info();}}
	this.check_keybuffer=check_keybuffer;


/* bildgalerien */

	function showMarker(x1,y1,x2,y2){var bild_pos=find_position('galerieBild');var rahmen=id('marker_rahmen');rahmen.css({'left':bild_pos[0]+x1-4+'px','top':bild_pos[1]+y1-3+'px','width':x2+'px','height':y2-3+'px','display':'block'});}
	this.showMarker=showMarker;

	function hideMarker(){id('marker_rahmen').css({'display':'none'});}
	this.hideMarker=hideMarker;


/* abk. */

	function id(get_id){return $('#'+get_id);}
	this.id=id;

	function go(url){if((go.arguments.length==2)&&(go.arguments[1]==false)){window.location.replace(url);}else{window.location.href=url;}}
	this.go=go;


/* diverses */

	function eintrag_mm_tools_hide(i){id('arrows_'+i).css({'display':'none'});id('delete_'+i).css({'display':'none'});}
	this.eintrag_mm_tools_hide=eintrag_mm_tools_hide;

	function eintrag_mm_tools_show(i){id('arrows_'+i).css({'display':'block'});id('delete_'+i).css({'display':'block'});}
	this.eintrag_mm_tools_show=eintrag_mm_tools_show;

	function bestaetige(message,nexturl){if(confirm(message)){this.go(nexturl);}}
	this.bestaetige=bestaetige;

	function show_form(formid,linkid){id(linkid).css({'display':'none'});id(formid).css({'display':'block'});}
	this.show_form=show_form;

	function hide_form(formid,linkid){id(formid).css({'display':'none'});id(linkid).css({'display':'block'});}
	this.hide_form=hide_form;

	function grow(get_id,jetzt,limit){id(get_id).animate({height:limit},250,function(){});}
	this.grow=grow;

	function shrink(get_id,maximum,jetzt){id(get_id).animate({height:0},250,function(){});}
	this.shrink=shrink;

	function toggle_menu(get_id,maximum){if(id(get_id).height()==0){this.grow(get_id,0,maximum);}else {this.shrink(get_id,maximum,0);}}
	this.toggle_menu=toggle_menu;

	function radio_play(n){var url='';switch(n){case 0:url='http://login.streamplus.de/player.php?spt=8112.asx';break;case 1:url='http://login.streamplus.de/player.php?spt=8112.m3u';break;}if(url!='')window.open(url);}
	this.radio_play=radio_play;

	function request_pw(){var email=id('req_email').value;if(email!=''){document.pwform.action='_ajax/send_password.php';document.pwform.submit();}}
	this.request_pw=request_pw;

	function style(id,s){return eval('document.getElementById("'+id+'").style.'+s);}
	this.style=style;
}
