var bild;
function Foto(img, alt){
  bild = img;
  foto1= new Image();
  foto1.src=(img);
  Controlla(img, alt);
}
function Controlla(img, alt){
  if((foto1.width!=0)&&(foto1.height!=0)){
    viewFoto(img, alt);
  }
  else{
    funzione="Controlla('"+img+"','"+alt+"')";
    intervallo=setTimeout(funzione,20);
  }
}
function viewFoto(img, alt){
  largh=foto1.width;
  altez=foto1.height;
  stringa="width="+largh+",height="+altez;
  		neu=window.open("","img",stringa);
		neu.document.open();
		neu.document.writeln("<!DOCTYPE html public \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>Zoom<\/title>");
		neu.document.writeln("<\/head><body style=\"margin:0px;\">");
		//Falls speichersperre erwünscht, Kommentar weg
		//neu.document.writeln("<script language=\"JavaScript\">");
		//neu.document.writeln("function Position(Ereignis)");
		//neu.document.writeln("{");
		//neu.document.writeln("alert(\"COPYRIGHT\");");
		//neu.document.writeln("}");
		//neu.document.writeln("document.onmousedown = Position;");
		//neu.document.writeln("<\/script>");
		if (alt!='')
			neu.document.writeln("<img src=\""+bild+"\" alt=\"\" title=\""+alt+"\">");
		else
			neu.document.writeln("<img src=\""+bild+"\" alt=\"\">");
		neu.document.writeln("<\/body><\/html>");
		neu.document.close();
}

function PopUp(seite,breite,hoehe)
{
	window.open (seite,'new','scrollbars=no,status=no,width='+breite+',height='+hoehe+'menubar=no,left=50,top=50,location=no,resizable=no,directories=no')
}

function PopUp_Scroll(seite,breite,hoehe)
{
	window.open (seite,'new','scrollbars=yes,status=no,width='+breite+',height='+hoehe+'menubar=no,left=50,top=50,location=no,resizable=no,directories=no')
}

function PopUpS_NoScroll(seite,breite,hoehe,wb_id)
{
	window.open (seite,'new','scrollbars=no,status=no,width='+breite+',height='+hoehe+',menubar=no,left=50,top=50,location=no,resizable=no,directories=no')
}

function CenterPopUpS(seite,format,breite,hoehe)
{
   f2=window.open (seite,format,'scrollbars=no,status=no,width='+breite+',height='+hoehe+'menubar=no,left=50,top=50,location=no,resizable=no,directories=no');
   f2.moveTo((screen.width-breite)/2,(screen.height-hoehe)/2);
   f2.focus();
}

function ResizeCenterPopUpS(seite,breite,hoehe)
{
   f2=window.open (seite,'new','scrollbars=yes,status=no,width='+breite+',height='+hoehe+'menubar=no,left=50,top=50,location=no,resizable=yes,directories=no');
   f2.moveTo((screen.width-breite)/2,(screen.height-hoehe)/2);
   f2.focus();
}

// PopUp-Function (resizable + no scrollbars)
function PopUpS_R(seite,breite,hoehe)
{
	window.open (seite,'new','scrollbars=no,status=no,width='+breite+',height='+hoehe+'menubar=no,left=100,top=100,location=no,resizable=yes,directories=no')
}

function PopUpAdvertDetail(seite,breite,hoehe,wb_id)
{
	window.open (seite,'new','scrollbars=yes,status=no,width='+breite+',height='+hoehe+',menubar=no,left=50,top=50,location=no,resizable=yes,directories=no')
}

//save item statistic
function item_statistic(shortcode, dataset_id, pu_id, reg_id, type)
{
	if(!pu_id) var pu_id = '';
	if(!reg_id) var reg_id = '';
	if(!type) var type = '';
	//create image element
	var iElem = document.createElement("img");

	// write image
	document.write("<img src=\"/redFACT/kernel/scripts/frontend/item_statistic.php?shortcode="+shortcode+"&dataset_id="+dataset_id+"&pu_id="+pu_id+"&reg_id="+reg_id+"&type="+type+"&rand="+(Math.random()*100000)+"\" width=\"1\" height=\"1\" />");
}

function CreateBookmarkLink() 
{
	title = "SZON - Online-Dienst fuer die Region von Aalen bis zum Bodensee, von Ulm bis zum Schwarzwald";
	url = "http://www.szon.de";
	if (window.sidebar) 
	{
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} 
	else if( window.external ) 
	{
		// IE Favorite
		
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print) 
	{
		// Opera Hotlist
		return true; 
	}
}

function GetRandom( min, max ) {
	if( min > max ) {
		return( -1 );
	}	
	if( min == max ) {
		return( min );
	}
	return( min + parseInt( Math.random() * ( max-min+1 ) ) );
}

// encrypt function implemented in nfyc_community_totallokal.php
function DecryptMailto( s )
{
	var n = 0;
	var r = "";
	for( var i = 0; i < s.length; i++)
	{
		n = s.charCodeAt( i );
		if( n >= 8364 )
		{
			n = 128;
		}
		r += String.fromCharCode( n - 1 );
	}
	return r;
}

function DecryptMailLink( s )
{
	location.href=DecryptMailto( s );
}

// Setzen eines Cookies ueber JavaScript
// Verwendung in Voting
function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "; path=/" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

//schaltet in Suchmasken die zusätzlichen Felder an/aus
function lokal_list_additional_search_toggle() {
	if (document.getElementById('lokal_list_additional_search_tog_on').style.display == "none") {
		document.getElementById('lokal_list_additional_search_tog_on').style.display = "block";
		document.getElementById('lokal_list_additional_search_tog_off').style.display = "none";
		$('#lokal_list_additional_search_list').slideDown();
	} else {
		document.getElementById('lokal_list_additional_search_tog_on').style.display = "none";
		document.getElementById('lokal_list_additional_search_tog_off').style.display = "block";
		$('#lokal_list_additional_search_list').slideUp();
	}
}


//datum schreiben:
function setHeaderDate() {
	var heute = new Date(); 
	var Jhr = heute.getYear(); 
	var korryear = ( Jhr >= 2000 ) ? Jhr : ( ( Jhr < 80 ) ? Jhr + 2000 : Jhr + 1900 ) 
 
	var TAGArray = new Array("Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"); 
	var wtag = TAGArray[(heute.getDay())]; 
	var ktag = heute.getDate(); 
	ktag = ((ktag < 10) ? "0" + ktag : ktag); 
	
	var kmonat = heute.getMonth() + 1; 
 	kmonat = ((kmonat < 10) ? "0" + kmonat : kmonat); 
	var MONArray = new Array("Januar","Februar","M\xE4rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"); 
	var monl = MONArray[(heute.getMonth())];
	
   	$('#curdate').html(wtag+", "+ktag+". "+monl+" "+korryear);
}

/*
// läd ein velinktes bild über die rest-schnittstelle
function SCHWAEBISCHE_linked_picture (link_data,image_data, contentbox, image_type, caching) {
	$.get('/REST/frontend/render/img/'+image_data+'/'+ image_type +'/'+caching, function(image_code) {
		if (link_data != "") {
			$.get('/REST/frontend/render/li/'+link_data+'/href_content/'+caching, function(href_code) {	
   				var banner_code = "<a "+href_code+">"+image_code+"</a>";
   				$(contentbox).append(banner_code);
			});
		} else {
   			var banner_code = image_code;
   			$(contentbox).append(banner_code);  
		}
   	});
}*/

function trim(s) {
  if (s)
  {
    while (s.substring(0,1) == ' ') {
      s = s.substring(1,s.length);
    }
    while (s.substring(s.length-1,s.length) == ' ') {
      s = s.substring(0,s.length-1);
    }
    return s;
  }
  else return false;
}

//läd einen link über die rest-schnittstelle und soll SCHWAEBISCHE_linked_picture ersetzen
function SCHWAEBISCHE_RESTLink (link_data, div, image_data, nofollow, caching) 
{
	//achtung: in (u.a.?!) servicebox.tpl wird noch ohne "nofollow" gearbeitet; hier crasht die funktion sonst:
	if (caching == undefined) {
		caching = 600;
	}

    $.get('/REST/frontend/render/li/'+link_data+'/link_data/'+caching, 
      function(href_code) 
      {	
	 var href_data = href_code.split(",");
	  if (image_data != "")
	  {
	    if(trim(href_data[4]) == "_self")
	    {
	      if (trim(href_data[3]) == "free")
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\" rel=\"nofollow\">"+image_data+"</a>";
		  }
		  else var link_code = "<a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\">"+image_data+"</a>";
	      } 
	      else 
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<a href=\""+trim(href_data[5])+"\" rel=\"nofollow\">"+image_data+"</a>";
		  }
		  else  var link_code = "<a href=\""+trim(href_data[5])+"\">"+image_data+"</a>";
	      }
	    }
	    else
	    {
	      if (trim(href_data[3]) == "free")
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\" target=\"_blank\" rel=\"nofollow\">"+image_data+"</a>";
		  }
		  else var link_code = "<a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\" target=\"_blank\">"+image_data+"</a>";
	      } 
	      else 
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<a href=\""+trim(href_data[5])+"\" target=\"_blank\" rel=\"nofollow\">"+image_data+"</a>";
		  }
		  else  var link_code = "<a href=\""+trim(href_data[5])+"\" target=\"_blank\">"+image_data+"</a>";
	      }
	    }
	  }
	  else
	  {
	    var lnktxt = trim(href_data[2]);
	    lnktxt = lnktxt.replace(/__/g,",");

	    if(trim(href_data[4]) == "_self")
	    {
	      if (trim(href_data[3]) == "free")
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<br /><span class=\"text_more\"><a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\" rel=\"nofollow\">"+lnktxt+"</a></span>";
		  }
		  else var link_code = "<br /><span class=\"text_more\"><a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\">"+lnktxt+"</a></span>";
	      } 
	      else 
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<br /><span class=\"text_more\"><a href=\""+trim(href_data[5])+"\" rel=\"nofollow\">"+lnktxt+"</a></span>";
		  }
		  else  var link_code = "<br /><span class=\"text_more\"><a href=\""+trim(href_data[5])+"\">"+lnktxt+"</a></span>";
	      }
	    }
	    else
	    {
	      if (trim(href_data[3]) == "free")
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<br /><span class=\"text_more\"><a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\" target=\"_blank\" rel=\"nofollow\">"+lnktxt+"</a></span>";
		  }
		  else  var link_code = "<br /><span class=\"text_more\"><a href=\"http://www.schwaebische.de/click.php?id="+trim(href_data[0])+"\" target=\"_blank\">"+lnktxt+"</a></span>";
	      } 
	      else 
	      {
		  if (nofollow == 1)
		  {
		    var link_code = "<br /><span class=\"text_more\"><a href=\""+trim(href_data[5])+"\" target=\"_blank\" rel=\"nofollow\">"+lnktxt+"</a></span>";
		  }
		  else var link_code = "<br /><span class=\"text_more\"><a href=\""+trim(href_data[5])+"\" target=\"_blank\">"+lnktxt+"</a></span>";
	      }
	    }
	  }
	  $(div).append(link_code);
      }
    );
}

function registereintraegeImage (link_data, div, image_data, caching) 
{
    if ( image_data != '' )
    {
    	$(div).html(image_data);
    }
}

//!umgeht den document.getElementsByClassName IE Bug:
function SZONgetElementByClassName(classname, tagtype) {
	if (!tagtype) {
		 tagtype = "div";
	}
	if (document.getElementsByClassName) {
		return document.getElementsByClassName(classname);
	} else {
	 	i = 0;
	 	returnelements = new Array();
  		tags = document.getElementsByTagName(tagtype);
  		while (element = tags[i++]) {
    		if (element.className.indexOf(classname) != -1) {
     			returnelements.push(tags[i-1]);
     	 	}
   	 	}
   	 	return returnelements;
  	}

}
	


	function eins_slider_automatictoggle() {
		if (eins_slider_pos < (eins_slider_element_ids.length-1)) {
			eins_slider_pos = eins_slider_pos + 1;
		} else {
			eins_slider_pos = 0;
		}
		idtoshow = eins_slider_element_ids[eins_slider_pos];
		eins_slider_toggle();
		automatic_slider = setTimeout("eins_slider_automatictoggle()", 5000);
	}
	function kill_automatictoggle() {
		clearTimeout(automatic_slider);
	}
	
	function eins_slider_show_element(idtoshow) {
		$("#slider_cobo_"+idtoshow).animate({ "opacity": "show"}, 750, function() {lock_toggle = "false";});
	}
	
	function eins_slider_toggle() {
		if (lock_toggle == "false") {
			var elementList = $(".tab_button");
			for (var i = 0; i < elementList.length; i++) {
				if (elementList[i].id == "slider_button_"+idtoshow) {
					elementList[i].className = "tab_button active";
				} else {
					elementList[i].className = "tab_button";
				}
			}
			var elementList2 = $(".entry_box_sub");
			for (var i = 0; i < elementList2.length; i++) {
				if (elementList2[i].id != "slider_cobo_"+idtoshow) {
					$(elementList2[i]).hide();
				} else {
					eins_slider_show_element(idtoshow);
				}
			}
		} 
	}
	function eins_slider_slide_to(idtoshow_fuc) {
		idtoshow = idtoshow_fuc;
		clearTimeout(act_sliding_progress);
		kill_automatictoggle();
		act_sliding_progress = setTimeout("eins_slider_toggle()", 300);
	}
	function eins_slider_slide_to_click(idtoshow_fuc) {
		idtoshow = idtoshow_fuc;
		clearTimeout(act_sliding_progress);
		kill_automatictoggle();
		eins_slider_toggle();
	}

	function ReloadIVWPixel(){
		var url = '';
		var newUrl = '';
		if(arguments[0]){
			if($(".ivwpixel").length > 0){
				url = $(".ivwpixel").attr('src').split('CP/');
				newUrl = url[0] + "CP/" + arguments[0] + ";" + "?r=" + escape(document.referrer) + "&d=" + (Math.random()*100000);	
			}
			else{
				newUrl = "http://szon.ivwbox.de/cgi-bin/ivw/CP/" + arguments[0] + ";" + "?r=" + escape(document.referrer) + "&d=" + (Math.random()*100000);
				$('body').append('<img class="ivwpixel" src="" width="1" height="1" alt="szmtag" />');
			}
		}
		else{ 
			url = $(".ivwpixel").attr('src').split('?');
			newUrl = url[0] + "?" + "r=" + escape(document.referrer) + "&d=" + (Math.random()*100000);
		}
		$(".ivwpixel").attr('src', newUrl);			 
	}	

//jquery initialisierungen:
$(document).ready(function(){
  	
  	//datum auf der seite setzen:
  	setHeaderDate();

	//print_content verschieben:
	$('body').append($('#print_content'));

	
	//Hauptmenü:
	$(".navigation_link").hover(
	    function(){
	    	$("#"+this.id).addClass("link_active");
	      //$("#sub"+this.id).animate({height: "show"},1, function(){});
	      	if ((window.ActiveXObject)) {
	      		$("#hideforie").hide();
	      	}
	      	$("#sub"+this.id).show();	
	    },
	    function(){
		    $("#"+this.id).removeClass("link_active");
		    //$("#sub"+this.id).animate({height: "hide"},1, function(){});
	      	if ((window.ActiveXObject)) {
	      		$("#hideforie").show();
	      	}
	      	$("#sub"+this.id).hide();
	    }
  	);
  	
  	// Drop Down Menüs
	$(".dropdown dt").click(function() {
		var akt_dropdown = $(this).parent().attr("id");
        $("#"+akt_dropdown+" dd div").toggle();
    });
                
    $(".dropdown dd ul li a").click(function() {
		var akt_dropdown = $(this).parent().parent().parent().parent().parent().attr("id");
        var text = $(this).html();
        $("#"+akt_dropdown+" dt span").html(text);
        $("#"+akt_dropdown+" dd div").hide();
    });
                
    function getSelectedValue(id) {
        return $("#" + id).find("dt a span.value").html();
    }

    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("dropdown"))
            $(".dropdown dd div").hide();
    });
    
    if (document.getElementById('eins_slider')) {
		automatic_slider = setTimeout("eins_slider_automatictoggle()", 5000);
	}
});
