/**
 * @package deutsche-sparkassenakademie.de
 * @subpackage javascript
 * @file jquery.akademie.js
 * contains all general javascript for deutsche-sparkassenakademie.de
 * @author Juergen Arne Klein 
 * <juergen-arne-klein@unitb-consulting.de>
 */
/* GLOBALS */
// browser detection
var b_isBadBrowser = typeof(window.XMLHttpRequest) == 'undefined';
var b_isIEx        = (b_isIE6 == true || b_isIE7 == true || b_isIE8== true) ? true : false;

// general paths
var s_php_path = "../resources/_php";

// for IE6 png-fix
var blank = new Image();
blank.src = "/resources/_img/system/transparent.gif";

// fotostrecke detect screen and browser window dimensions:
var i_screenWidth  = screen.width;
var i_screenHeight = screen.height;
var i_winOutWidth  = window.outerWidth;
var i_winInnWidth  = window.innerWidth;
var i_winOutHeight = window.outerHeight;
var i_winInnHeight = window.innerHeight;

//detect screen and browser window dimensions for IE6/7:
if(typeof(i_winInnWidth)  == 'undefined') {
	i_winInnWidth = document.documentElement.clientWidth;
}
if(typeof(i_winInnWidth)  == 'undefined') {
	i_winInnWidth = document.body.clientWidth;
}
if(typeof(i_winInnHeight) == 'undefined') {
	i_winInnHeight = document.documentElement.clientHeight;
}
if(typeof(i_winInnHeight) == 'undefined') {
	i_winInnHeight = document.body.clientHeight;
}

// kontaktformular
var a_contactFormValues   = new Array();
// bilderstrecke
var images    		  = new Array();
var fsElement = '.fotostrecke';
// searchengine
var newLabel              = '';


/* GLOBAL FUNCTIONS */
// class searchEngine
var searchEngine = function(s_target) {
	var s_mySearchEngine ='/resources/_php/searchengine.php';
	var s_myTarget       = '';
	if(typeof(s_target) != 'undefined') {
		s_myTarget       	 = s_target;
	}
	var s_mySuchBegriff  = '';
	var i_myOff          = 0;
	var i_myAnz          = 5;
	var file_filter ="";
	var url_filter="";
	
	this.setFileFilter=function(file_name){
	   		if(typeof(file_name) != 'undefined') {
			file_filter = file_name;
		}
	}
	
	var setSuchBegriff = function(s_suchBegriff) {
		if(typeof(s_suchBegriff) != 'undefined') {
			s_mySuchBegriff = s_suchBegriff;
		}
	}
	this.setSuchBegriff = setSuchBegriff;
	
	var getSearchData = function(i_offset, s_suchbegriff){
		if(typeof(i_offset) != 'undefined') {
			i_myOff = i_offset;
		}
		setSuchBegriff(s_suchbegriff);
		
		$('#searchresults').css("display","block");
		
		$(s_myTarget).html('<div id="search_wait"><img style="margin-bottom: 14px; margin-left: 150px;" src="/resources/_img/site/search_wait.gif"/></div>');
		$.post(s_mySearchEngine, {suchbegriff: s_mySuchBegriff, off: i_myOff, anz: i_myAnz,file_filter: file_filter,url_filter:url_filter}, function(data){$(s_myTarget).html(data);});
	}
	this.getSearchData = getSearchData;
	
	this.setSearchEngine=function(engine_path){
	    s_mySearchEngine=engine_path;
	}
		
	
	this.getSearchEngine=function(){
	  // console.log( s_mySearchEngine);
	}
	
	this.setUrlFilter=function(data){
	if(data && data!='undefined'){
	url_filter=data;
	}
	else{
	url_filter="";
	}
	}
		
}
var se = new searchEngine('#searchresults');

// class searchEngine Yacy
var searchEngine_yacy = function(s_target) {
	var s_mySearchEngine = s_php_path + '/searchengine_yacy.php';
	var s_myTarget       = '';
	if(typeof(s_target) != 'undefined') {
		s_myTarget       	 = s_target;
	}
	var s_mySuchBegriff  = '';
	var i_myOff          = 0;
	var i_myAnz          = 5;
	var file_filter ='';

	this.setFileFilter=function(file_name){
	   		if(typeof(file_name) != 'undefined') {
			file_filter = file_name;
		}
	}

	var setSuchBegriff = function(s_suchBegriff) {
		if(typeof(s_suchBegriff) != 'undefined') {
			s_mySuchBegriff = s_suchBegriff;
		}
	}
	this.setSuchBegriff = setSuchBegriff;

	var getSearchData = function(i_offset, s_suchbegriff){
		if(typeof(i_offset) != 'undefined') {
			i_myOff = i_offset;
		}
		setSuchBegriff(s_suchbegriff);
		$(s_myTarget).html('<div id="search_wait"><img style="margin-bottom: 14px; margin-left: 150px;" src="/resources/_img/site/search_wait.gif"/></div>');
		$.post(s_mySearchEngine, {suchbegriff: s_mySuchBegriff, off: i_myOff, anz: i_myAnz,file_filter: file_filter}, function(data){$(s_myTarget).html(data);});
	}
	this.getSearchData = getSearchData;
}
var se_yacy = new searchEngine_yacy('#searchresults');

// feedparser
var feedparser = function(s_feedurl, s_target){
	var s_myParser  = '/resources/_php/feedparser.php';
	var s_myFeedurl = s_feedurl;
	var s_myTarget  = s_target;
	var s_mySuchstr = '';
	var i_myIndex   = 0;
	var i_myMax     = 5;
	
	var loadData    = function(i_index, s_suchstring){
		if(typeof(i_index) != 'undefined') {
			i_myIndex   = i_index;
		}
		if(typeof(s_suchstring) != 'undefined') {
			s_mySuchstr = s_suchstring;
		}
		$.post(s_myParser, {myurl:s_myFeedurl,pre:i_myIndex,max:i_myMax,such:s_mySuchstr}, function(data){$(s_myTarget).html(data);});
	}
	this.loadData   = loadData;
	
	var setMax      = function(i_max) {
		if(typeof(i_max) != 'undefined') {
			i_myMax   = i_max;
		}
	}
	this.setMax = setMax;
	
	var setSuchstring = function(s_suchstring) {
		if(typeof(s_suchstring) != 'undefined') {
			s_mySuchstr = s_suchstring;
		}
	}
	this.setSuchstring = setSuchstring;
}

/**
 * class fotostrecke
 * @version 1.1 vom 12.05.2010
 * @author Juergen Arne Klein <juergen-arne.klein@unitb-consulting.de>
 */
var fotostrecke = function(fsElement) {
	/**
	 * members:
	 */
	var myElement   = fsElement;
	var e_stage     = null;
	var a_bigImgs   = new Array();
	var a_imgMap    = new Array();
	var i_ind       = 0;
	var i_aID       = 0;
	var s_actSrc    = '';
	
	/* function: */
	/** 
	 * @method init void
	 * @author Juergen Arne Klein <juergen-arne.klein@unitb-consulting.de>
	 * @access public
	 * @return void
	 */
	var init = function() {
		$(myElement).each(function() {
			f_setMainStage($(this), 0);
		});
	}
	this.init = init; // make init public
	
	/**
	 * @method f_loadImg
	 * @author Juergen Arne Klein <juergen-arne.klein@unitb-consulting.de>
	 * @access private
	 * @param DOM-Element target
	 * @param DOM-Element e_stage
	 * @return void 
	 */
	var f_loadImg = function(target, e_stage) {
		if(!b_isBadBrowser){$(target).blur();}
		var k = $(target).attr('rel');		
		f_setMainStage(e_stage, k);
	}
	
	var f_nextImg = function(e_stage) {
		if(!b_isBadBrowser){$(e_stage).find('div.next_ico a').blur();}
		var i_index = $(e_stage).find('.navigation > ul.index > li.active:first a').attr('rel');
		f_setMainStage(e_stage, parseInt(i_index) + 1);
	}

	var f_prevImg = function(e_stage) {
		if(!b_isBadBrowser){$(e_stage).find('div.prev_ico a').blur();}
		var i_index = $(e_stage).find('.navigation > ul.index > li.active:last a').attr('rel');
		f_setMainStage(e_stage, parseInt(i_index) - 1);
	}

	var f_setMainStage = function(e_stage, i_index) {
		var i_sID        = $(e_stage).attr('id');
		a_bigImgs[i_sID] = new Array();
		for(var y = 0;y < images[i_sID].length; y ++) {
			if(typeof(images[i_sID][y]['src_big']) != 'undefined' && images[i_sID][y]['src_big'] != '' && !images[i_sID][y]['src_big'].match(/\?\?\?/)) {
				a_bigImgs[i_sID].push(y);
			}
		}

		if(typeof(i_index) == 'undefined') {
			i_index = 0;
		}
		// hauptbild setzen
		$(e_stage).find('.main_img > img + img').attr('src', images[i_sID][i_index]['src_sml']);
		$(e_stage).find('.description').html(images[i_sID][i_index]['sub_sml']);

		// seitliche navigation aufbauen
		$(e_stage).find('div.prev_ico a').unbind('click').one('click',function() {f_prevImg(e_stage);}).hide();
		$(e_stage).find('div.next_ico a').unbind('click').one('click',function() {f_nextImg(e_stage);}).hide();

		// untere navigation aufbauen
		if(1 < images[i_sID].length) {
			$(e_stage).find('.navigation').html('<ul class="index"></ul>');
			for(var i = 0; i < images[i_sID].length; i++) {
				$(e_stage).find('.navigation > ul.index').append('<li><a title="'+images[i_sID][i]['tit_sml']+'" href="javascript:void(0);" rel="'+i+'">&nbsp;</a></li>');
			}
			var i_child = parseInt(i_index) + 1;
			$(e_stage).find('.navigation > ul.index > li:nth-child('+i_child+')').addClass('active');
			$(e_stage).find('.navigation > ul.index > li > a').each(function() {
				$(this).click(function(ev) {f_loadImg(ev.target, e_stage);});
			});
		}
		
		if(i_index > 0) {
			$(e_stage).find('div.prev_ico a').show();
		}
		if(i_index < (images[i_sID].length - 1)) {
			$(e_stage).find('div.next_ico a').show();
		} 

		// klick auf bild oeffnet overlay
		if(typeof(images[i_sID][i_index]['src_big']) != "undefined" && images[i_sID][i_index]['src_big'] != "" && images [i_sID][i_index]['src_big'].search('de.deutsche_sparkassenakademie.template') == -1) {
			$(e_stage).find('.stage .main_img img:first').css({cursor:'pointer'}).click(function() {
				f_showOverlay(e_stage);
			});
		} else {
			$(e_stage).find('.stage .main_img img:first').css({cursor:'default'}).unbind('click');
		}
	}

	var f_setOverlay = function(e_stage, i_index) {
		var i_sID     = $(e_stage).attr('id');
		var i_myIndex = 0;
		var i_child   = 0;
		var i_myChild = 1;
		if(typeof(i_index) == 'undefined'){
			var i_index = $(e_stage).find('.navigation > ul.index > li.active:first a').attr('rel');
		}

		if(typeof(i_index) == 'undefined') {
			i_index = 0;
		}
		for(var b = 0; b < a_bigImgs[i_sID].length; b ++) {
			if(a_bigImgs[i_sID][b] == i_index){
				i_myIndex = i_index;
				i_myChild = parseInt(b)+1;
				
			}
		}

		$('#imgBox .lbStage .lbImg').html('<img src="'+images[i_sID][i_myIndex]['src_big']+'" alt="'+images[i_sID][i_myIndex]['alt_big']+'" title="'+images[i_sID][i_myIndex]['tit_big']+'" />');
		$('#imgBox .lbStage .subtitle').html(images[i_sID][i_myIndex]['sub_big']);

		// untere navigation aufbauen
		$('.lbStage > .navigation').html($('#'+i_sID+ ' > .navigation').html());
		$('.lbStage > .navigation > ul.index > li > a').unbind('click');
		for(var c = 0; c < images[i_sID].length; c ++) {
			if(typeof(images[i_sID][c]['src_big']) == 'undefined' || images[i_sID][c]['src_big'] == '') {
				i_child = parseInt(c)+1;
				$('.lbStage > .navigation > ul.index > li:nth-child('+i_child+')').hide();
			}
		}
		$('.lbStage > .navigation > ul.index > li.active').removeClass('active');
		i_child = parseInt(i_index) + 1;
		$('.lbStage > .navigation > ul.index > li:nth-child('+i_child+')').addClass('active');
		
		$('#imgBox .lbStage .navigation > ul.index > li:visible > a').each(function() {
			$(this).click(function() {f_setOverlay(e_stage, $(this).attr('rel'));});
		});

		// seitliche navigation aufbauen
		$('#imgBox div.bod_right a').unbind('click').hide();
		$('#imgBox div.bod_left a').unbind('click').hide();
		
		if(i_index > 0) {
			var i_prev = parseInt(i_index) - 1;
			if(!b_isBadBrowser){$('#imgBox div.bod_left a').blur();}
			for(var d = i_prev; d >= 0; d --) {
				if(typeof(images[i_sID][d]['src_big']) != 'undefined' && images[i_sID][d]['src_big'] != '') {
					$('#imgBox div.bod_left a').one('click',function() {f_setOverlay(e_stage, d);}).show();
					break;
				}
			}
		}

		if(i_index < (images[i_sID].length - 1)) {
			var i_next = parseInt(i_index) + 1;
			if(!b_isBadBrowser){$('#imgBox div.bod_right a').blur();}
			for(var e = i_next; e < images[i_sID].length;e ++) {
				if(typeof(images[i_sID][e]['src_big']) != 'undefined' && images[i_sID][e]['src_big'] != '') {
					$('#imgBox div.bod_right a').one('click',function() {f_setOverlay(e_stage, e);}).show();
					break;
				}
			}
		} 
	}

	var f_showOverlay = function(e_stage) {
		f_setOverlay(e_stage);
		$('#overBox').show().one('click', function() {f_hideOverlay(e_stage);});
		$('a.closebtn').one('click', function() {f_hideOverlay(e_stage);});
		$('#imgBox').show();
		$().unbind('keyup');
		$('').keyup(function (e) {
			switch(e.keyCode) {
				case 27:
					$('#overBox').click();
					break;
			}
		});
		f_center();
	}
	
	var f_center = function() {
		i_screenWidth  = screen.width;
		i_screenHeight = screen.height;
		i_winOutWidth  = window.outerWidth;
		i_winInnWidth  = window.innerWidth;
		i_winOutHeight = window.outerHeight;
		i_winInnHeight = window.innerHeight;

		//detect screen and browser window dimensions for IE6/7:
		if(typeof(i_winInnWidth) == 'undefined') {
			i_winInnWidth = document.documentElement.clientWidth;
		}
		if(typeof(i_winInnWidth) == 'undefined') {
			i_winInnWidth = document.body.clientWidth;
		}
		if(typeof(i_winInnHeight) == 'undefined') {
			i_winInnHeight = document.documentElement.clientHeight;
		}
		if(typeof(i_winInnHeight) == 'undefined') {
			i_winInnHeight = document.body.clientHeight;
		}

		var i_top  = (i_winInnHeight - $('#imgBox').height()) / 2;
		var i_left = (i_winInnWidth - $('#imgBox').width()) / 2;
		
		$('#imgBox').css({top: i_top+'px', left: i_left+'px'});
	}
	
	var f_hideOverlay = function(e_stage) {
		$().unbind('keyup');
		var i_index = $('#imgBox .lbStage .navigation > ul.index > li.active:first a').attr('rel');
		f_setMainStage(e_stage, i_index);
		$('#imgBox div.lbImg').html('');
		$('#imgBox, #overBox').hide();
	}
}
var fs = new fotostrecke(fsElement);


/* LISTENERS */
$().ready(function() {
	/* SCROLLBALKEN */
	$('#tabs_content.scroll_special > div').jScrollPane({showArrows:false, scrollbarWidth: 13, scrollbarMargin: 15})
	$('#tabs_content.scroll_special > .jScrollPaneContainer').hide();
	$('#tabs_content.scroll_special > .jScrollPaneContainer:first').show();

	/* FOTOSTRECKE */
	fs.init();
	
	/* SEARCHENGINE */
	// label lÃƒÂ¶schen
	$('#suchbegriff_o.ini, #suchbegriff.ini, #dlsuchbegriff.ini').each(function() {
		$(this).one('focus', function() {
			$(this).attr('value', '').removeClass('ini');
		});
	});

	// label einfÃƒÂ¼gen
	$('#suchbegriff_o, #suchbegriff, #dlsuchbegriff').each(function() {
		if($(this).attr('value') == '') {
			if(typeof($(this).attr('title')) == 'undefined' || $(this).attr('title') == '') {
				newLabel = lang == 'en' ? 'Search ' + $(this.parentNode.parentNode.parentNode).find('h1:first').text() : $(this.parentNode.parentNode.parentNode).find('h1:first').text() + ' durchsuchen';
			} else {
				newLabel = $(this).attr('title');
			}
			$(this).attr('value', newLabel);
		}
		$(this).blur(function() {
			if($(this).attr('value') == '') {
				if(typeof($(this).attr('title')) == 'undefined' || $(this).attr('title') == '') {
					newLabel = lang == 'en' ? 'Search ' + $(this.parentNode.parentNode.parentNode).find('h1:first').text() : $(this.parentNode.parentNode.parentNode).find('h1:first').text() + ' durchsuchen';
				} else {
					newLabel = $(this).attr('title');
				}
				$(this).attr('value', newLabel).addClass('ini').one('focus', function() {
					$(this).attr('value', '').removeClass('ini');
				});
			}
		});
	});

	$('#pressform, #appointmentsform, #newsform, #suchform, #dlsform').submit(function() {
		return false;
	});
	$('#suchform_o').submit(function() {
	        history('false');
	        $("body").attr("onunload","history('false');"); 
		if($('#suchbegriff_o').hasClass('ini') || $('#suchbegriff_o').attr('value') == '') {
			return false;
		}
	});

	if(typeof($('#suchbegriff').attr('value')) != 'undefined' && $('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini') && typeof(se.setSuchBegriff) != 'undefined'){
		se.setSuchBegriff($('#suchbegriff').attr('value'));
		$('#spdf').attr('checked')?se.setFileFilter("pdf"):$('#sart').attr('checked')?se.setFileFilter("html"):se.setFileFilter("none");

	}

	$('#searchsubmit').click(function() {
		if(!b_isBadBrowser) {$(this).blur();}
		if($('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini')){
			se.setSuchBegriff($('#suchbegriff').attr('value'));
			$('#spdf').attr('checked')?se.setFileFilter("pdf"):$('#sart').attr('checked')?se.setFileFilter("html"):se.setFileFilter("none");
			se.getSearchData(0);
			return false;
		}
	});
	
	 $('#searchsubmit_yacy').click(function() {

		if(!b_isBadBrowser) {$(this).blur();}
		if($('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini')){
			se_yacy.setSuchBegriff($('#suchbegriff').attr('value'));
			$('#spdf').attr('checked')?se_yacy.setFileFilter("pdf"):se_yacy.setFileFilter("none");
			se_yacy.getSearchData(0);
			return false;
		}
	});

	$('#suchbegriff').keypress(function(e) {
           if(!b_isBadBrowser) {$(this).blur();}
		    var characterCode = 0;

                  if (e && e.which) {
                      characterCode = e.which;
                  } else {
                    characterCode = e.keyCode;
                          }

                  if (characterCode == 13) {
		      if($('#suchbegriff').attr('value').match(/[^\ ]+/) && !$('#suchbegriff').hasClass('ini')){
			se.setSuchBegriff($('#suchbegriff').attr('value'));
			$('#spdf').attr('checked')?se.setFileFilter("pdf"):$('#sart').attr('checked')?se.setFileFilter("html"):se.setFileFilter("none");
			$('#url_filter').attr('value')?se.setUrlFilter($('#url_filter').attr('value')):se.setUrlFilter("");
			se.getSearchData(0);
			return false;
		       }
                   }
               $(this).focus();
	  });
	
	
	/* FEEDPARSER */	
	var dlp = new feedparser('/de/downloads.rss', '#dlresults_list');
	$('#dlsearchsubmit').click(function() {
		if(!b_isBadBrowser) {$(this).blur();}
		if($('#dlsuchbegriff').attr('value').match(/[^\ ]+/) && !$('#dlsuchbegriff').hasClass('ini')) {
			dlp.loadData(0,$('#dlsuchbegriff').attr('value'));
		}
	});
	
	$('#cont_main.press a#searchsubmit, #cont_main.appointments a#searchsubmit, #cont_main.newslist a#searchsubmit').click(function() {
		if(!b_isBadBrowser){$(this).blur();}
		if(!$('#suchbegriff').hasClass('ini') && $('#suchbegriff').attr('value').match(/[^\ ]+/)){
			fp.loadData(0,$('#suchbegriff').attr('value'));
		}
	});


	/* RECHTE BOXEN */
	$('.marg_box.mb_2').each(function() {
		$(this).find('.acc_item .acc_head').show();
		$(this).find('.acc_item .mb_cont').hide();
		$(this).find('.acc_item:first .acc_head').hide();
		$(this).find('.acc_item:first .mb_cont').show();
		
		$(this).find('.acc_head a').mouseover(function() {
			if(!$(this.parentNode).hasClass('lock')) {
				$(this.parentNode.parentNode.parentNode).find('.acc_head').addClass('lock');
				$(this.parentNode.parentNode.parentNode).find('.acc_item .mb_cont:visible').slideUp('fast');
				$(this.parentNode.parentNode.parentNode).find('.acc_item .acc_head:hidden').slideDown('fast');
				$(this.parentNode.parentNode).find('.mb_cont:hidden').slideDown('fast');
				$(this.parentNode.parentNode).find('.acc_head:visible').slideUp('fast', function() {$('h4.acc_head.lock').removeClass('lock');});
			}
		});
	});

	/* DOWNLOADLIST */
	$('ul.dlmainmenu > li > a').click(function() {
		if(!b_isBadBrowser) {$(this).blur();}
		$('ul.dlmainmenu > li').removeClass('active');
		$(this.parentNode).addClass('active');

		if($(this.parentNode).attr('id') == 'rbs') {
			$('#downloadsearch').hide();
			$('#downloadslist').show();
		} else if($(this.parentNode).attr('id') == 'sws') {
			$('#downloadsearch').show();
			$('#downloadslist').hide();
		}
	});
	
	
	$('#cont_main.downloads #downloadslist li.topic a').click(function(ev) {
		if(!b_isBadBrowser){$(ev.target).blur();}
		$('#downloadslist li.active ul.lev2:visible').slideUp('fast', function() {
			$('#downloadslist li.active').removeClass('active');
		});
		if(!$(ev.target.parentNode).is('.active')) {
			$(ev.target.parentNode).find('ul.lev2').slideDown('fast', function() {
				$(ev.target.parentNode).addClass('active');			
			});
		}
	});

	/* KONTAKTFORMULAR */
	// beim Start die initial-Werte der Felder sammeln:
	$('.kontaktform input[type!="radio"][type!="checkbox"], .kontaktform textarea, .kontaktform select').each(function() {
		if(typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
			a_contactFormValues[$(this).attr('name')] = $(this).attr('value');
		}
	});
	$('.kontaktform input[type="radio"], .kontaktform input[type="checkbox"]').each(function() {
		if($(this).attr('checked') && typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
			a_contactFormValues[$(this).attr('name')] = $(this).attr('value');
		}
		
	});
		
	// beim fokusieren die Vorbelegung lÃƒÂ¶schen:
	$('.kontaktform input.ini').one('focus', function() {
		$(this).removeClass('ini');
		if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
			$(this).attr('value', '');
		}
	});
	

	// beim Verlassen den vorbelegungswert wiedereinfÃƒÂ¼gen:
	$('.kontaktform input').blur(function() {
		if($(this).attr('value') == ''){
			var myVar = '';
			if(typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
				myVar = $(this).attr('title');
				if($(this).is('.pflicht')) {
					myVar +='*';
				}
			} else {
				myVar = a_contactFormValues[$(this).attr('name')];
			}

			$(this).attr('value',myVar).addClass('ini').one('focus', function() {
				$(this).removeClass('ini');
				if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
					$(this).attr('value', '');
				}
			});
		}
	});

	// beim klick auf den Resetbutton:
	$('.kontaktform a.resetbtn').click(function() {
		if(!b_isBadBrowser){$(this).blur();}

		// Fehlerhinweise entfernen:
		$('h2.error_headline, h2.email_error_headline').slideUp('fast');
		$('.kontaktform .error').removeClass('error');
		
		// werte zurÃƒÂ¼cksetzen:
		$('.kontaktform input, .kontaktform textarea, .kontaktform select').each(function() {
			var myVar2 = '';
			if(typeof(a_contactFormValues[$(this).attr('name')]) == 'undefined') {
				myVar2 = $(this).attr('title');
				if($(this).is('.pflicht')) {
					myVar2 +='*';
				}
			} else {
				myVar2 = a_contactFormValues[$(this).attr('name')];
			}

			$(this).addClass('ini').one('focus', function() {
				$(this).removeClass('ini');
				if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
					$(this).attr('value', '');
				}
			});

			// Textfelder zurÃƒÂ¼cksetzen
			if(!$(this).is('[type="radio"]')) {
				$(this).attr('value',myVar2);
			}

			// radio und checkboxen zurÃƒÂ¼cksetzen
			if($(this).is('[type="radio"], [type="checkbox"]')) {
				$(this).removeAttr('checked');
				if(typeof(a_contactFormValues[$(this).attr('name')]) != 'undefined' && a_contactFormValues[$(this).attr('name')] == $(this).attr('value')) {
					$(this).attr('checked', 'checked');
				} 
			}
			
			// selectboxen zurÃƒÂ¼cksetzen
			if($(this).is('select')){
				var myOvar = '';
				if(typeof(a_contactFormValues[$(this).attr('name')]) != 'undefined') {
					myOvar = a_contactFormValues[$(this).attr('name')];
					$(this).find('option').each(function() {
						$(this).removeAttr('selected');
						if(myOvar == $(this).attr('value')) {
							$(this).attr('selected', 'selected');
						}
					});
				}
			}
		});
	});
	
	// beim Klick auf den Submitbutton:
	$('.kontaktform a.submitbtn').click(function() {
		if(!b_isBadBrowser){$(this).blur();}
		$('h2.email_error_headline, h2.error_headline').hide();
		$('.kontaktform .error, label.error').removeClass('error');
		
		$('.emailadress').each(function() {
			if(!$(this).attr('value').match(/^[a-zA-Z0-9äöüßÄÖÜ\_\.\-]+@[a-zA-Z0-9\_\.\-]+\.[a-z]{2,4}$/)) {
				$('h2.email_error_headline').slideDown('fast');
				$(this).addClass('error').addClass('ini').attr('value', $(this).attr('title')+'*').one('focus', function() {
					$(this).removeClass('ini');
					if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
						$(this).attr('value', '');
					}
				});
			}
		});

		$('.kontaktform .pflicht').each(function() {
			if($(this).is('input[type="checkbox"], input[type="radio"]') && !$(this).is(':checked') && $('.kontaktform').find('[name="'+$(this).attr('name')+'"]:checked').length < 1) {
				$('.kontaktform label[for="'+$(this).attr('id')+'"]').addClass('error');
			}
			
			if($(this).attr('value') == '' || $(this).attr('title') == $(this).attr('value').replace(/\*$/, "")){
				$('h2.error_headline').slideDown('fast');
				$(this).addClass('error').addClass('ini').attr('value', $(this).attr('title')+'*').one('focus', function() {
					$(this).removeClass('ini');
					if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
						$(this).attr('value', '');
					}
				});
				if($(this).is('textarea')) {
					$(this).attr('value','');
				}
			}
		});

		if($('.kontaktform .error').length < 1){
			$('.kontaktform .ini').each(function() {
				if($(this).attr('title') == $(this).attr('value').replace(/\*$/, "")) {
					$(this).attr('value', '');
				} 
			});
			$('.kontaktform form').submit();
		}
	});
	/*
	$('body').ajaxStop(function() {
	       $('body').find('#ajaxwait_bg, #ajaxwait_box').fadeOut('1000').remove();
	}).ajaxStart(function() {
	       $('body').modalWindow(
	               {'w': 180
	               ,'h': 60
	               ,'customId': 'ajaxwait'
	               ,'closable': false
	               ,'url': '../resources/_js/ajax-loader.html #main'
	               ,'callback' : function () { $('#ajaxwait_box').css('background', 'transparent'); }
	               });
	});
	
	$("input[name='srange']").change(function() {
	   se.updateResults(0, $("input[name='srange']:checked").val());
	}); */
});

//// feedparser home reiter
var feedparser_homepage= function(s_feedurl, s_target,tab_type,items_anz){
	var s_myParser  = '/resources/_php/feedparser_home.php';
	var s_myFeedurl = s_feedurl;
	var s_myTarget  = s_target;
	var i_myIndex   = 0;
	var i_myMax     = items_anz;
        var s_type=tab_type;

	var loadData    = function(i_index, s_suchstring){
		if(typeof(i_index) != 'undefined') {
			i_myIndex   = i_index;
		}
		if(typeof(s_suchstring) != 'undefined') {
			s_mySuchstr = s_suchstring;
		}
		$.post(s_myParser, {myurl:s_myFeedurl,pre:i_myIndex,max:i_myMax,tab_type:s_type}, function(data){
		  $(s_myTarget).html(data); 
		  $(s_myTarget).parent().jScrollPane({showArrows:false, scrollbarWidth: 13, scrollbarMargin: 15});
		});
	}
	this.loadData   = loadData;

	var setMax      = function(i_max) {
		if(typeof(i_max) != 'undefined') {
			i_myMax   = i_max;
		}
	}
	this.setMax = setMax;

}

// back search
function history(elem){
$.ajax({
  url: "/resources/_php/searchengine.php",
  async :false,
  data:{"back":elem},
  success: function(){
  }
});
}

