// @version $Rev: 1936 $
function evalKeySubmit(event, frm) {  
  if (event && (event.which == 13 || event.keyCode==13 )){
    frm.submit();
   } else{ 
  return true;
  }  
}  

function changeBackground(i){
  if (document.alles) document.alles.background.value=i;
   $('.gradient').attr('class','gradient background'+i);
   $('.related').attr('class','related background'+i);

}

function popup_x_y(x_,y_,url_) {
 parameter='height='+y_+',width='+x_+',top=0,left=0,toolbar=no,menubar=no,location=no,scrollbars=no,statusbar=no';
 if (popup_x_y.arguments) { parameter+=((popup_x_y.arguments.length>=4)&&(typeof(popup_x_y.arguments[3])!='undefined')) ? ','+popup_x_y.arguments[3] : ''; };
 window.open(url_,'',parameter);
};

function reloadIVW()
{
        var ref = document.referrer;
        var ivw = document.getElementById("ivwpixel");
        if (ivw != null) {
        if ( (reloadIVW.arguments) && (reloadIVW.arguments.length==2))
        {
            var _agof=reloadIVW.arguments[0]; 
            var _ivw=reloadIVW.arguments[1]; 
            var imgurl = "http://rtl.ivwbox.de/cgi-bin/ivw/CP/"+_agof+';'+_ivw+'?r='+ref+'&d=' + Math.round(1000000*Math.random());
        }
        else if ( ((typeof _initialAGOF) == 'string') && ((typeof _initialIVW) == 'string') )
        {
            var imgurl = "http://rtl.ivwbox.de/cgi-bin/ivw/CP/"+_initialAGOF+';'+_initialIVW+'?r='+ref+'&d=' + Math.round(1000000*Math.random());
        }
        else
        {
            var pos = ivw.src.indexOf("&");
            var imgurl = ivw.src.substring(0, pos) + "&d=" + Math.round(1000000*Math.random());
            imgurl = imgurl.replace(/r=&/, "r="+ref+"&");
        }
        ivw.src = imgurl;
    }
    adReload.reloadAll();
}

var adReload = {};

adReload._ord = 0;

adReload.reloadAll = function() {
	if (typeof(ip_stopadreload) != undefined && ip_stopadreload === true) {
		return false;
	}
	try {
	    adReload.ord();
	    adReload.rectangle();
	    adReload.banner();
	    adReload.sky();
    } catch (e) {
    	return e;
    }
	return true;
};

adReload.ord = function () {
	adReload._ord = Math.round(1000000 * Math.random());
};

adReload.rectangle = function () {
	var urls = [];
	var i = 0;
	$.each(adSlotsDelivered['300x250'], function(idx, val) {
		if (val == undefined) {
	    	return;
	    }
	    var url = val.url;
	    delete (val.ord);
	    $.each(val, function(k, v) {
	        if (k == 'url' || k == 'u') {
	            return;
	        }
	        url = url + k + '=' + v + ';';
	    });
	    if (typeof n_pbt != 'undefined' && n_pbt != '') {
	        url = url + n_pbt + ';';
	    }
    	url += (typeof adVisibility == 'function' ? adVisibility($('.pageRectangleAd.isAdVisible').eq(i)) : '');
	    
	    url = url + 'u=' + val.u + ';ord=' + adReload._ord;
	    urls[i] = url;
	    i = i + 1;
	});
	if (i == 1) {
		$('.rectangel .media').html('').html(writeCapture.sanitize('<script type="text/javascript" src="' + urls[0] + '?"></script>'));
	} else if (i == 2) {
		$('.rectangel .media').each(function(i) {
			$(this).html('').html(writeCapture.sanitize('<script type="text/javascript" src="' + urls[i] + '?"></script>'));
		});
	}
};

adReload.banner = function () {
	    var banner = adSlotsDelivered['468x60'];
	    if (banner == undefined) {
	    	return;
	    }
	    var url = banner.url;
	    delete (banner.ord);
	    $.each(banner, function(k, v) {
	        if (k == 'url' || k == 'u') {
	            return;
	        }
	        url = url + k + '=' + v + ';';
	    });
	    if (typeof n_pbt != 'undefined' && n_pbt != '') {
	        url = url + n_pbt + ';';
	    }
    	url += (typeof adVisibility === 'function' ? adVisibility($('#bannerDummy.isAdVisible').filter(':last')) : '');	    
	    
	    url = url + 'u=' + banner.u + ';ord=' + adReload._ord;
	    $('#banner').html('').html(writeCapture.sanitize('<script type="text/javascript" src="' + url + '?"></script>'));
};

adReload.sky = function () {
    var sky = adSlotsDelivered['120x600'];
    if (sky == undefined) {
    	return;
    }
    var url = sky.url;
    delete (sky.ord);
    $.each(sky, function(k, v) {
        if (k == 'url' || k == 'u') {
            return;
        }
        url = url + k + '=' + v + ';';
    });
    if (typeof n_pbt != 'undefined' && n_pbt != '') {
        url = url + n_pbt + ';';
    }
   	url += (typeof adVisibility === 'function' ? adVisibility($('#bannerDummy.isAdVisible').filter(':last')) : '');
    
    url = url + 'u=' + sky.u + ';ord=' + adReload._ord;
    if ($('#skyscraper').size() > 0) {
         $('#skyscraper').html('').html(writeCapture.sanitize('<script type="text/javascript" src="' + url + '?"></script>'));
    } else if ($('#ip_wallsky').size() > 0) {
    	$('#ip_wallsky').remove();
    	$('body').append(writeCapture.sanitize('<script type="text/javascript" src="' + url + '?"></script>'));
    }
};

function IvwPlaybutton() {
	var _agof, _ivw, _r;
	if ((IvwPlaybutton.arguments) && (IvwPlaybutton.arguments.length == 2) && typeof IvwPlaybutton.arguments[0] == 'string' && typeof IvwPlaybutton.arguments[1] == 'string')
	{
   		_agof = IvwPlaybutton.arguments[0];
   		_ivw = IvwPlaybutton.arguments[1];
   	}
	else if (((typeof _initialAGOF) == 'string') && ((typeof _initialIVW) == 'string'))
	{
   		_agof = _initialAGOF;
   		_ivw = _initialIVW;
	}

	if (((typeof _agof) == 'string') && ((typeof _ivw) == 'string'))
	{
		_r = {agof:_agof+'_', ivw: '/videoabrufe'+_ivw};
	}
	else
		_r = {agof:'', ivw:''};
	return _r;
}

var gzszDialog = {
        overlay: {'background-color':'black','opacity':'0.3'},
        modal: true,
        width: 600,
        height: 500,
        resizable: false,
        draggable: true,
        position: [172, 312]
};
function showDialog(id) {
    if(id.charAt(0) !=  '#') {
        id = '#' + id;
    }
    $(id).dialog(gzszDialog).show();
    $(id).dialog('open');
}

function closeDialog(id) {
    if(id.charAt(0) !=  '#') {
        id = '#' + id;
    }
    $(id).dialog('close');
    $(id).hide();
}

function initButtons(selector) {
    if (selector != null) {
        selector = selector + ' .textButton a';
    } else {
        selector = '.textButton a';
    }
    $(selector).hover(function () {
          $(this).children('.divLeft').css('top','-24px');
          $(this).children('.divRight').css('top','-24px');  
    }, function () {
          $(this).children('.divLeft').css('top','0px');
          $(this).children('.divRight').css('top','0px');         
    });
}

function showAjaxLoadOverlay(id) {
    if(id.charAt(0) !=  '#') {
        id = '#' + id;
    }
    $.scrollTo(id, 300, {axis:'y'});
    var width = $(id).width();
    var height = $(id).height();
    $(id).append('<div class="ajaxload" style="width:'+width+'px;height:'+height+'px;">&nbsp;</div>');
}

function initTooltipps(id) {
    if (id != '' && id != 'undefined' && id != null) {
        if(id.charAt(0) !=  '#') {
            id = '#' + id + ' ';
        } else {
            id = id + ' ';
        }
    } else {
        id = '';
    }
    $(id+'.tt *').tooltip({
        track: true,
        extraClass: "jdee",
        top: 25,
        left: 10,
        showURL: false
    });
}

$(document).ready(function(){
    initButtons();
    initTooltipps();
});

var gzszMarkitupSettings = {
    nameSpace: "bbcode",
    markupSet: [        
      {name:'Fett', key:'B', openWith:'[b]', closeWith:'[/b]', className:'markItUpButtonBold'}, 
      {name:'Kursiv', key:'I', openWith:'[i]', closeWith:'[/i]', className:'markItUpButtonItalic'}, 
      {name:'Unterstrichen', key:'U', openWith:'[u]', closeWith:'[/u]', className:'markItUpButtonUnderline'}, 
      {separator:'---------------' },
      {name:'Liste', openWith:'[list]\n', closeWith:'\n[/list]', className:'markItUpButtonBulletlist'}, 
      {name:'Listenpunkt', openWith:'[*] ', className:'markItUpButtonListitem'}
   ]
}

function newPW(){
    var postdata={};
    postdata['email']=document.newpwform.email.value;
    $.post('/user/registrierung/neuespasswort',postdata,function (data){responseNewPw(data);}, "json");
}

function responseNewPw(data){
        closeDialog('dialogsendnepw');
        $('#dialogNewPwResponsecontent').html(data.text+'<br/><br/>');
        showDialog('dialogsendnewpwResponse');
}
/************************* GOOGLE AdSense ************************/
function google_ad_request_done(google_ads) {
/*
* This function is required and is used to display
* the ads that are returned from the JavaScript
* request. You should modify the document.write
* commands so that the HTML they write out fits
* with your desired ad layout.
*/
var s = '';
var i;

/*
* Verify that there are actually ads to display.
*/
if (google_ads.length == 0) {
return;
}

/*
* If an image or flash ad is returned, display that ad.
* Otherwise, build a string containing all of the ads and
* then use a document.write() command to print that string.
*/

if (google_ads[0].type == "flash") {

   s += '<a href=\"' +
google_info.feedback_url + '\" style="color:000000">Ads by Google</a><br>' +
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="' +
google_ad.image_width + '" HEIGHT="' +
google_ad.image_height + '"> <PARAM NAME="movie" VALUE="' +
google_ad.image_url + '">' +
'<PARAM NAME="quality" VALUE="high">' +
'<PARAM NAME="AllowScriptAccess" VALUE="never">' +
'<EMBED src="' +
google_ad.image_url + '" WIDTH="' +
google_ad.image_width + '" HEIGHT="' +
google_ad.image_height +
'" TYPE="application/x-shockwave-flash"' +
' AllowScriptAccess="never" ' +
' PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';

} else if (google_ads[0].type == "image") {

   s += '<a href=\"' +
google_info.feedback_url + '\" style="color:000000">Ads by Google</a><br> <a href="' +
google_ads[0].url + '" target="_top" title="go to ' +
google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[0].visible_url + '\';return true"><img border="0" src="' +
google_ads[0].image_url + '"width="' +
google_ads[0].image_width + '"height="' +
google_ads[0].image_height + '"></a>';

} else if (google_ads[0].type == "html") {

s += google_ads[0].snippet;

} else {

if (google_ads.length == 1) {
/*
* Partners should adjust text sizes
* so ads occupy the majority of ad space.
*/
	   s += '<div class="spacer10"></div>';
	   s += '<div class="hGoogle"><a href=\"' + google_info.feedback_url + '\" >Google-Anzeigen</a></div>';

	  /*
	  * For text ads, append each ad to the string.
	  */
	    googlebg = 0;
	    for(i = 0; i < google_ads.length; ++i) {
	        
	        s += '<div class="ad ';
	        if (googlebg % 2 == 0){
	          s += "bg1";
	        } else {
	          s += "bg2";
	        }
	        s += '">';
	        if (i > 0){
	           s += '<div class="horizontal"></div>';
	        }
	        s += '<div class="headline"><a href="' +
	        google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
	        google_ads[i].visible_url + '\';return true"> <b>' +
	        google_ads[i].line1 + '</b></a></div><div class="txtBox">' +
	        google_ads[i].line2 + '<br>' +
	        google_ads[i].line3 + '</div><div class="linkButton"><div class="txt"><a class="adlink" href="' +
	        google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
	        google_ads[i].visible_url + '\';return true">' +
	        google_ads[i].visible_url + '<div class="arrow"></div></a></div></div>';
	        s += '</div><div class="clear"></div>';
	        googlebg++;
	    }
	
	
	
/*	
   s += '<a href=\"' +
google_info.feedback_url + '\" style="color:000000">Ads by Google</a><br> <a style="text-decoration:none" href="' +
google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[0].visible_url + '\';return true"> <span style="text-decoration:underline;font-size:20pt"> <b>' +
google_ads[0].line1 + '</b><br></span></a> <span style="color:#000000;font-size:16pt">' +
google_ads[0].line2 + '&nbsp;' +
google_ads[0].line3 + '<br></span> <span><a style="color:#008000;font-size:14pt;text-decoration:none" href="' +
google_ads[0].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
google_ads[0].visible_url + '\';return true">' +
google_ads[0].visible_url + '</span></a><br>';
*/
	
	
	
} else if (google_ads.length > 1) {
   s += '<div class="spacer10"></div>';
   s += '<div class="hGoogle"><a href=\"' + google_info.feedback_url + '\" >Google-Anzeigen</a></div>';

  /*
  * For text ads, append each ad to the string.
  */
    googlebg = 0;
    for(i = 0; i < google_ads.length; ++i) {
        
        s += '<div class="ad ';
        if (googlebg % 2 == 0){
          s += "bg1";
        } else {
          s += "bg2";
        }
        s += '">';
        if (i > 0){
           s += '<div class="horizontal"></div>';
        }
        s += '<div class="headline"><a href="' +
        google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
        google_ads[i].visible_url + '\';return true"> <b>' +
        google_ads[i].line1 + '</b></a></div><div class="txtBox">' +
        google_ads[i].line2 + '<br>' +
        google_ads[i].line3 + '</div><div class="linkButton"><div class="txt"><a class="adlink" href="' +
        google_ads[i].url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
        google_ads[i].visible_url + '\';return true">' +
        google_ads[i].visible_url + '<div class="arrow"></div></a></div></div>';
        s += '</div><div class="clear"></div>';
        googlebg++;
    }
}
    }
    s += '<div class="spacer10 line"></div>';
    document.write(s);
    return;
  }

google_ad_client = 'ca-pub-7650911237790646';
google_ad_channel = 'gzszde';
google_ad_output = 'js';
google_max_num_ads = '3';
google_ad_type = 'text';
google_language = 'de';
google_encoding = 'utf8';
google_safe = 'high';
google_feedback = 'on';
google_adtest = 'off';

google_afs_hl = 'de';
google_afs_ie ='utf8';
google_afs_oe = 'utf8';
google_afs_ad = 'n3';



/************************* /GOOGLE AdSense ************************/


function doRelatedSearch() {
    var search = $('#relatedsearch').val();
    if (search == '' || search == 'Suchbegriff eingeben') {
        return;
    }
    
    var option = $('#relatedsearchoption option:selected').val();
    
if (option == 'article') {
        var fakeform = '<form id="fakeform" action="/cms/suche" method="POST"><input type="hidden" name="suchbegriff" value="'+search+'" /></form>';
        $('#fakeformContent').html(fakeform);
        $('#fakeform').submit();
    
    }
    if (option == 'forum') {
        var fakeform = '<form id="fakeform" action="/forum/suche" method="POST"><input type="hidden" name="suchbegriff" value="'+search+'" /><input type="hidden" name="searchforum" value="0" /></form>';
        $('#fakeformContent').html(fakeform);
        $('#fakeform').submit();
    }
    if (option == 'user') {
        var fakeform = '<form id="fakeform" action="/user/suche/ergebnis" method="POST"><input type="hidden" name="nickname" value="'+search+'" /></form>';
        $('#fakeformContent').html(fakeform);
        $('#fakeform').submit();
    }
    
}

/******************* G R U P P EN    J S ********************/

function doGroupSearch() {
	$(document).ready(function() {
        var suchbegriff = $(".inputBox input[name='searchField']").attr("value");
        var suche = $(".inputBox select[name='searchIn']").attr("value");
        if(suche >= 1 && suche <= 5 && jQuery.trim(suchbegriff).length >= 3 && suchbegriff != 'Suchbegriff') {
        	document.formSerachInGroups.submit();
        } else {
            alert('Fehler!\nDer Suchbegriff muss mindestens 3 Zeichen umfassen.\n\nKorrigiere deine Suche und versuche es erneut.');
        }
	});
}

function showEditLayer(id) {
    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "/gruppen/erstellen/bearbeiten/id/"+id+"/format/html",
            success: function(msg){
                $("body").prepend("<div id=\"gruppenBearbeiten\" class=\"bastel\" style=\"display:none;\"><div class=\"contentbox\">"+msg+"</div></div>");
                var dialogData = {
                        overlay: {'background-color':'black','opacity':'0.3'},
                        modal: true,
                        width: 617,
                        closeOnEscape: false,
                        resizable: false,
                        draggable: true,
                        position: [172, 100]
                };
                $("#gruppenBearbeiten").dialog(dialogData).show();
                $("#gruppenBearbeiten").dialog('open');
                //$(document).unbind("keydown.ui-dialog-overlay");
                $(".ui-dialog-titlebar").remove(".ui-dialog-titlebar");
            }
        }); 
    });      
}

function closeEditLayer(id) {
	$(document).ready(function() {
		$("#gruppenBearbeiten").dialog('close');
		window.location.reload();
	});
}

function activate_reiter(id) {
	$(".gruppenProfilReiter" + id).addClass("aktivReiter");
}


/******************* / G R U P P EN    J S ********************/

/******************* F O R U M / MOVE THREAD    J S ********************/
function forumShowMovethreadLayer(forumid, threadid, hint) {
	if (typeof (threadid)== "number" ){
		if (hint == 1){
			var threadurl ="/forum/movethread/removehint/forum/"+forumid+"/thread/"+threadid+"/format/html";
		} else {
			var threadurl ="/forum/movethread/target/forum/"+forumid+"/thread/"+threadid+"/format/html";
		}
	} else {
		var threadurl ="/forum/movethread/index/format/html";
	}
    $(document).ready(function() {
        $.ajax({
            type: "GET",
            //url: "/forum/movethread/index/format/html",
            url: threadurl,
            success: function(msg){
                $("body").prepend("<div id=\"forumMovethread\" class=\"bastel\" style=\"display:none;\">"+msg+"</div>");
                var dialogData = {
                        overlay: {'background-color':'black','opacity':'0.3'},
                        modal: true,
                        width: 617,
                        closeOnEscape: false,
                        resizable: false,
                        draggable: true,
                        position: [172, 100]
                };
                $("#forumMovethread").dialog(dialogData).show();
                $("#forumMovethread").dialog('open');
                //$(document).unbind("keydown.ui-dialog-overlay");
                $(".ui-dialog-titlebar").remove(".ui-dialog-titlebar");
            }
        }); 
    });      
}

function forumCloseMovethreadLayer() {
	$(document).ready(function() {
		$("#forumMovethread").dialog('close');
		window.location.reload();
	});
}
/******************* / F O R U M / MOVE THREAD    J S ********************/

var n_pbt = '';

/**
 * adVisibility
 * 
 * @param obj element
 * @return string
 */
function adVisibility(elem)
{
	if ($(elem).length === 0) return ''; 
	
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();
    var docViewLeft = $(window).scrollLeft();
    var docViewRight = docViewLeft + $(window).width();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();
    var elemLeft = $(elem).offset().left;
    var elemRight = elemLeft + $(elem).width();
	
    var elemVisibleTop, elemVisibleLeft, elemVisibleBottom, elemVisibleRight;
	
	if (elemTop >= docViewTop) {
		if (elemTop < docViewBottom) {
			elemVisibleTop = elemTop;
		} else {
			elemVisibleTop = false;
		}
	} else { // elemTop < docViewTop
		elemVisibleTop = docViewTop;
	}

	if (elemLeft >= docViewLeft) {
		if (elemLeft < docViewRight) {
			elemVisibleLeft = elemLeft;
		} else {
			elemVisibleLeft = false;
		}
	} else { // elemLeft < docViewLeft
		elemVisibleLeft = docViewLeft;
	}

	if (elemBottom <= docViewBottom) {
		if (elemBottom >= docViewTop) {
			elemVisibleBottom = elemBottom;
		} else { // elemBottom < docViewTop
			elemVisibleBottom = false;
		}
	} else { // elemBottom > docViewBottom
		elemVisibleBottom = docViewBottom;
	}
	
	if (elemRight <= docViewRight) {
		if (elemRight > docViewLeft) {
			elemVisibleRight = elemRight;
		} else { // elemRight < docViewLeft
			elemVisibleRight = false;
		}
	} else { // elemRight > docViewRight
		elemVisibleRight = docViewRight;
	}

	if (elemVisibleTop === false || elemVisibleLeft === false || elemVisibleBottom === false || elemVisibleRight === false) {
		return 'ip_v=0;';
	} else {
		var elemVisibility = Math.round((elemVisibleRight-elemVisibleLeft)/$(elem).width() * (elemVisibleBottom-elemVisibleTop)/$(elem).height()*100); 
		return 'ip_v=' + (elemVisibility==100 ? '1' : '0') +';';
	}
}
