// Fixing Drupal's noConflict
$ = jQuery;

// Example
(function($){$.fn.example=function(text,args){if(!text){text=function(){return $(this).attr('title');}}
var isCallback=$.isFunction(text);var options=$.extend({},args,{example:text});return this.each(function(){var $this=$(this);if($this.width()>0){$this.width($this.width());}
if($.metadata){var o=$.extend({},$.fn.example.defaults,$this.metadata(),options);}else{var o=$.extend({},$.fn.example.defaults,options);}
if(isCallback){$this.data("exampleText",o.example.call(this));}else{$this.data("exampleText",o.example);}
if(!$.fn.example.boundClassNames[o.className]){$(window).unload(function(){$('.'+o.className).val('');});$('form').submit(function(){$(this).find('.'+o.className).val('');});$.fn.example.boundClassNames[o.className]=true;}
if($.browser.msie&&!$this.attr('defaultValue')&&$this.val()==$this.data("exampleText"))
$this.val('');if($this.val()==''&&this!=document.activeElement){$this.addClass(o.className);$this.val($this.data("exampleText"));}
$this.focus(function(){if($(this).is('.'+o.className)){$(this).val('');$(this).removeClass(o.className);}});$this.change(function(){if($(this).is('.'+o.className)){$(this).removeClass(o.className);}});$this.blur(function(){if($(this).val()==''){$(this).addClass(o.className);$(this).val($this.data("exampleText"));}});});};$.fn.example.defaults={className:'example'};$.fn.example.boundClassNames=[];})(jQuery);

jQuery(function() { jQuery(":text[title]").example(false,{class_name:"example"}); });

// Static URL
var staticurl = location.protocol + "//static." + document.location.hostname.replace(/^[^\.]*\./i, "");

// Load CSS
function loadCSSURI(filename){filename = filename.replace("http:", document.location.protocol);var fileref=document.createElement("link");fileref.setAttribute("rel","stylesheet");fileref.setAttribute("type","text/css");fileref.setAttribute("href",filename);document.getElementsByTagName("head")[0].appendChild(fileref);}

// Overlay box
(function($){var staticurl=location.protocol+"//static."+document.location.hostname.replace(/^[^\.]*\./i,"");loadCSSURI(staticurl+"/css/jquery.olbox.css");$.jsBox=function(data,klass,type){if($("#jsBox").css("display")=="block"){$("#jsBox .content > *").css("visibility","hidden");}
else{$.jsBox.init();$.jsBox.loading();}
$('#jsBox').find('div.header').show();$('#jsBox').find('div.footer').hide();$('#jsBox').find('a.ok, .ok_image').hide();$('#jsBox').find('a.cancel, .cancel_image').hide();$('#jsBox').find('a.close, .close_image').show();if(type=="ajax"){$.get(data,{},function(data){$.jsBox.reveal(data,klass,'jsBox',type);try{activateEventHandlersForAjaxableItems();}catch(e){};},'html');}
else{$.isFunction(data)?data.call($):$.jsBox.reveal(data,klass,'jsBox',type);}}
$.modalBox=function(data,klass,callback,type){$.jsBox.init();$.jsBox.loading();$('#jsBox').find('div.header').hide();$('#jsBox').find('div.footer').show();$('#jsBox').find('a.ok, img.ok_image').show();$('#jsBox').find('a.cancel, img.cancel_image').show();$('#jsBox').find('a.close, img.close_image').hide();if(type=="ajax"){$.get(data,function(data){$.jsBox.reveal(data,klass,'modal',type);try{activateEventHandlersForAjaxableItems();}catch(e){};});}
else{$.isFunction(data)?data.call($):$.jsBox.reveal(data,klass,'modal',type);}
$(document).bind('ok.jsBox',function(){$(document).unbind('ok.jsBox');$.isFunction(callback)?callback():window.location.href=callback;});}
$.alertBox=function(data,klass,callback,type){$.jsBox.init();$.jsBox.loading();$('#jsBox').find('div.header').hide();$('#jsBox').find('div.footer').show();$('#jsBox').find('a.ok, img.ok_image').show();$('#jsBox').find('a.cancel, img.cancel_image').hide();$('#jsBox').find('a.close, img.close_image').hide();if(type=="ajax"){$.get(data,function(data){$.jsBox.reveal(data,klass,'modal',type);try{activateEventHandlersForAjaxableItems();}catch(e){};});}
else{$.isFunction(data)?data.call($):$.jsBox.reveal(data,klass,'modal',type);}
$(document).bind('ok.jsBox',function(){$(document).unbind('ok.jsBox');if(callback){$.isFunction(callback)?callback():window.location.href=callback;}});};$.jsBox.settings={loading_image:staticurl+'/images/olbox/loading.gif',close_image:staticurl+'/images/olbox/close.gif',ok_image:staticurl+'/images/olbox/ok.gif',cancel_image:staticurl+'/images/olbox/cancel.gif',image_types:['png','jpg','jpeg','gif'],jsBox_html:'<div id="jsBox_overlay" style="display:none;"></div><div id="jsBox" style="display:none;"><div class="popup"><table><tbody><tr><td class="tl"/><td class="b"/><td class="tr"/></tr><tr><td class="b" /><td class="body"><div class="header"><a href="#" class="close"><img src="'+staticurl+'/images/olbox/close.gif" title="close" class="close_image" /></a></div><div class="content"></div><div class="footer"><a href="#" class="ok"><img src="'+staticurl+'/images/olbox/ok.gif" title="ok" class="ok_image" style="display: none;" /></a><a href="#" class="cancel"><img src="'+staticurl+'/images/olbox/cancel.gif" title="cancel" class="cancel_image" style="display: none;" /></a><a href="#" class="close"><img src="'+staticurl+'/images/olbox/close.gif" title="close" class="close_image" /></a></div></td><td class="b"/></tr><tr><td class="bl"/><td class="b"/><td class="br"/></tr></tbody></table></div></div>'};$.jsBox.loading=function(nocleanup){if($('#jsBox .loading').length==1){return true;}
if(!nocleanup){$('#jsBox .content').empty();$('#jsBox .header').show();$('#jsBox .content').hide();$('#jsBox .footer').hide();}
$('#jsBox .body').prepend('<div class="loading"><img src="'+$.jsBox.settings.loading_image+'"/></div>');var pageScroll=$.jsBox.getPageScroll();$('#jsBox').css({top:pageScroll[1]+($.jsBox.getPageHeight()/10),left:pageScroll[0]}).show()
$(document).bind('keydown.jsBox',function(e){if(e.keyCode==27)$.jsBox.close();})}
$.jsBox.reveal=function(data,klass,mode,datatype){if(mode)$('#jsBox_overlay').addClass(mode);$('#jsBox_overlay').css("height",$.jsBox.getRealPageHeight()).show();$('embed, object, select').css('visibility','hidden');if(klass)$('#jsBox .content').addClass(klass);if(datatype=='dom'){$('#jsBox .content').empty().append($(data).clone(true).show());}
else{$('#jsBox .content').empty().html(data);}
$('#jsBox .loading').remove();$('#jsBox .content').fadeIn('normal',function(){var height=$.jsBox.getRealPageHeight();$('#jsBox_overlay').css("height",height+5);});}
$.jsBox.close=function(){$(document).trigger('close.jsBox');return false;}
$.jsBox.ok=function(){$(document).trigger('close.jsBox');$(document).trigger('ok.jsBox');return false;}
$.jsBox.cancel=function(){$(document).trigger('close.jsBox');return false;}
$(document).bind('close.jsBox',function(){$(document).unbind('keydown.jsBox')
$('#jsBox').fadeOut(function(){$(document).trigger('forceClose.jsBox');});}).bind('forceClose.jsBox',function(){$(document).unbind('keydown.jsBox')
$('#jsBox').hide();$('#jsBox .content').removeClass().addClass('content');$('#jsBox_overlay').hide();$('embed, object, select').css('visibility','visible');});$.fn.jsBox=function(settings){$.jsBox.init(settings);var image_types=$.jsBox.settings.image_types.join('|');image_types=new RegExp('\.'+image_types+'$','i');function click_handler(){if($("#jsBox").css("display")=="block"){$("#jsBox .content > *").css("visibility","hidden");$.jsBox.loading(true);}
else{$.jsBox.loading();}
var klass=this.rel.match(/jsBox\[\.(\w+)\]/);if(klass){klass=klass[1];}
if(this.href.match(/#/)){var url=window.location.href.split('#')[0];var target=this.href.replace(url,'');$.jsBox($(target).clone().show());}else if(this.href.match(image_types)){var image=new Image();image.onload=function(){$.jsBox('<div class="image"><img src="'+image.src+'" /></div>');}
image.src=this.href;}else{$.get(this.href,function(data){$.jsBox(data);try{activateEventHandlersForAjaxableItems();}catch(e){};});}
return false;}
this.unbind("click").click(click_handler);return this;}
$.jsBox.init=function(settings){if($.jsBox.settings.inited){return true;}else{$.jsBox.settings.inited=true;}
if(settings){$.extend($.jsBox.settings,settings);}
$('body').append($.jsBox.settings.jsBox_html);var preload=[new Image(),new Image()];preload[0].src=$.jsBox.settings.close_image;preload[1].src=$.jsBox.settings.loading_image;$('#jsBox').find('.b:first, .bl, .br, .tl, .tr').each(function(){preload.push(new Image());preload.slice(-1).src=$(this).css('background-image').replace(/url\((.+)\)/,'$1');})
$('#jsBox .close_image').click($.jsBox.close);$('#jsBox .close_image').attr('src',$.jsBox.settings.close_image);$('#jsBox .ok_image').click($.jsBox.ok);$('#jsBox .ok_image').attr('src',$.jsBox.settings.ok_image);$('#jsBox .cancel_image').click($.jsBox.cancel);$('#jsBox .cancel_image').attr('src',$.jsBox.settings.cancel_image);}
$.jsBox.getPageScroll=function(){var xScroll,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;xScroll=self.pageXOffset;}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;}else if(document.body){yScroll=document.body.scrollTop;xScroll=document.body.scrollLeft;}
return new Array(xScroll,yScroll);}
$.jsBox.getPageHeight=function(){var windowHeight
if(self.innerHeight){windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowHeight=document.documentElement.clientHeight;}else if(document.body){windowHeight=document.body.clientHeight;}
return windowHeight;}
$.jsBox.getRealPageHeight=function(){var yScroll;if(window.innerHeight&&window.scrollMaxY){yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){yScroll=document.body.scrollHeight;}else{yScroll=document.body.offsetHeight;}
var windowHeight=$.jsBox.getPageHeight();if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
return pageHeight;}})(jQuery);function jsConfirm(msg,callback,type){jQuery.modalBox(msg,null,callback,type);}
function jsAlert(msg,callback,type){jQuery.alertBox(msg,null,callback,type);}
function jsBox(data,type){jQuery.jsBox(data,null,type);}




function popup(strUrl, intWidth, intHeight, intToTop, intToRight) {

    if(intWidth == null)
        intWidth = screen.availWidth - 150;
    if(intHeight == null)
        intHeight = screen.availHeight - 200;
    if(intToTop == null)
        intToTop = 0;
    if(intToRight == null)
        intToRight = 0;


    var intX = (screen.availWidth / 2) - (intWidth / 2) + intToRight;
    var intY = (screen.availHeight / 2) - (intHeight / 2) - intToTop;

    win = window.open(strUrl, '_blank', 'width = ' + intWidth +', height = ' + intHeight +', left=' + intX + ', top = '+ intY + ', screenX = ' + intX + ', screenY=' + intY + ', scrollbars=yes, resizable=1');
    //win.window.resizeTo(intWidth, intHeight);
    //win.window.focus();
}

var dwLoginLinkURL = function() {
    var $login      = jQuery("#header_menu_registration a[href*='/login/']");
    var currentURI  = $login.attr("href");
    var connector   = "&";

    if (false === /\?/.test(currentURI)) {
        connector = "?";
    }

    $login.attr("href", currentURI + connector + "url=" + encodeURIComponent(jQuery("#header_menu_registration :hidden").val()));
}

var DW = {};
DW.browser = { ie6: false, iphone: false, tinyMCECompatible: true };
if (jQuery.browser.msie && jQuery.browser.version == "6.0") {
    DW.browser.ie6 = true;
}
if (true === /iPhone/i.test(navigator.userAgent)) {
    DW.browser.iphone = true;
    DW.browser.tinyMCECompatible = false;
} else if (true === /iP(?:a|o)d/i.test(navigator.userAgent)) {
    DW.browser.tinyMCECompatible = false;
} else if (true === /Android/i.test(navigator.userAgent)) {
    DW.browser.tinyMCECompatible = false;
} else if (true === /BlackBerry/i.test(navigator.userAgent)) {
    DW.browser.tinyMCECompatible = false;
} else if (true === /SymbianOS/i.test(navigator.userAgent)) {
    DW.browser.tinyMCECompatible = false;
}

// AJAX error handler
$(function() {
    $("body").ajaxError(function(event, xhr) {
                            jsBox(xhr.responseText);
                        });
});

function getParentProps(elem, prop) {

	var result = 0;

	while(elem != null) {
		result += elem[prop];
		elem = elem.offsetParent;
	}

	return result;
}

function browserSize() {

	var x, y;

	if (self.innerHeight) {

		this.x = self.innerWidth;
		this.y = self.innerHeight;

	} else if (document.documentElement && document.documentElement.clientHeight) {

		this.x = document.documentElement.clientWidth;
		this.y = document.documentElement.clientHeight;

	} else if (document.body) {

		this.x = document.body.clientWidth;
		this.y = document.body.clientHeight;

	}

}

function openIM(intUserId) {
	window.open('/chat.php?item=im&TargetId=' + intUserId, '_blank', 'width=550, height=300, scrollbars=yes, resizable=1');
}

function loadCSSURI(filename) {

 	var fileref = document.createElement("link");
	
	filename = filename.replace("http:", document.location.protocol);

	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", filename);
		
	document.getElementsByTagName("head")[0].appendChild(fileref);
}

function toBookmark(name, url) {
    
	if (window.sidebar) {
		window.sidebar.addPanel(name, url, "");
	} else if(document.all) {
        try {
            window.external.AddFavorite(url, name);
        } catch (e) {
        }
	} else if (window.opera && window.print) {
        var bookmark_element = document.createElement('a');
        bookmark_element.setAttribute('href', url);
        bookmark_element.setAttribute('title', name);
        bookmark_element.setAttribute('rel', 'sidebar');
        bookmark_element.click();
    }

    
}

function lang_switch() {

    var lang_box = document.getElementById("language_box");

    if("block" == lang_box.style.display) {

        lang_box.style.display = "none";

        if(document.getElementById("home_search_form")) {
            document.search_guest.Target.style.visibility = "visible";
        }

    } else {

        lang_box.style.display = "block";

        if(document.getElementById("home_search_form")) {
            document.search_guest.Target.style.visibility = "hidden";
        }
    }

}

function newsletterAdd() {
    try {
		var Email = document.getElementById("NewsletterAdd").value;

		if(false == /^[a-z0-9_\-]+(\.[_a-z0-9\-]+)*@([a-z0-9\-]+\.)+([a-z]{2,})$/i.test(Email)) {
			alert("Not a valid e-mail address");
			return;
		}

		popup("/popup/newsletter/add/?Email=" + Email, 400, 200);
    } catch(e) {
    }
}

// Imprint
//if ("/content/imprint.html" === location.pathname) {
//
//    var text = jQuery("p").each(function() {
//        var $this = jQuery(this);
//        var html = $this.html();
//        html = html.replace(/XXX/, "XXX, YYY");
//        $this.html(html);
//    });
//
//}

