function Language() {
	this.vars = new Array();
	this.getVar = function (name) {
		if (typeof(this.vars[name]) != 'undefined') return this.vars[name];
		else return '';
	};
	this.setVar = function (name, value) {
		this.vars[name] = value;
	};
};
Lang = new Language();


function reua_showEl(el,openTitle,closedTitle) {
	if(typeof(openTitle) == 'undefined') openTitle = Lang.getVar("M_SEARCH");
	if(typeof(closedTitle) == 'undefined') closedTitle = Lang.getVar("STR_ADVANCED_SEARCH");
	target = '#' + el;
	link = '#' + el + '-link';
	if($(target).css('display') != 'none') {
		var obj = $(target);
		obj.hide();
		obj.find('select, input, textarea').attr('disabled', 'disabled');
		$(link).text(closedTitle).parent().removeClass('show-hide-open');
		$(link).parent().parent().find('span.add-msg-hide').hide();
		$(link).parent().parent().find('span.add-msg-show').show();
	} else {
		var obj = $(target);
		obj.show();
		obj.find('select:visible, input:visible, textarea:visible').attr('disabled', '');
		$(link).text(openTitle).parent().addClass('show-hide-open');
		$(link).parent().parent().find('span.add-msg-show').hide();
		$(link).parent().parent().find('span.add-msg-hide').show();
	}
	return false;
}

function reua_tabs(id) {
	var tabspan = id+'-pan';
	var tabsnav = id+'-nav';
	$(tabspan+' div.tab-item').hide();
	$(tabsnav).children().each(function(i) {
		$(this).children().click(function() {
			$(tabsnav).children().each(function() {
				$(this).removeClass('active');
			});
			$(tabspan).children('.tab-item').each(function(j) {
				if(i==j) $(this).show();
				else $(this).hide();
			});
			$(this).parent().addClass('active');
		});
	});
	$(tabsnav+' > li:first').addClass('active');
	$(tabspan+' > div.tab-item:first').show();
}


jQuery.each(jQuery.browser, function(i) {
  if($.browser.opera){
	$("head").append('<link href="css/opera.css" type="text/css" rel="stylesheet" title="screenview" />')
  }
});

function refreshCaptcha(captchaUrl){
	$('.captchaImage').attr('src',captchaUrl+'?'+Math.random()*10);
	return false;
}

$(document).ready(function(){
	
	//alert(Lang.getVar('test'));
	/* ShowHide elements for search and searchrent */
	var url = document.location.href;
	if (url.indexOf('advertisment/search/') != -1) {
		var blocks = $('.hideOnSearch');
		blocks.hide().find('input, select, textarea').attr('disabled','disabled');
	}
	if (url.indexOf('advertisment/searchrent/') != -1) {
		var blocks = $('.hideOnSearchRent');
		blocks.hide().find('input, select, textarea').attr('disabled','disabled');
	}
	/* ShowHide elements for search and searchrent END */
	
	/* Hints */
	hint = $('a.hint, #rememberLabel, #regLink, #forgotLink, #zalogLink, #newbuildingLink, #foreign2Link, #foreignLink');
	$('a.hint').click(function(){return false;});
	hint.mouseover(function(e){
		ob = $("span.hintText", $(this).parent());
		ob.css("left", e.pageX+10+'px');
		ob.css("display", 'block');
	});
	hint.mouseout(function(){
		ob = $("span.hintText", $(this).parent());
		ob.css("display", 'none');
	});
	
	$('.tabsnav a.hint').mouseover(function(e){
		ob = $("span.hintText", $(this).parent());
		ob.css("left", e.pageX-($(window).width()-1000)/2-10+'px');
		ob.css("display", 'block');
	});
	
	$('.legend a.hint, .additional-link a.hint, .pink a.hint, label[for="showOnMap"] a.hint').mouseover(function(e){
		ob = $("span.hintText", $(this).parent());
		ob.css("left", e.pageX-($(window).width()-1000)/2-20+'px');
		ob.css("display", 'block');
	});
	
	$('.navright a.hint').mouseover(function(e){
		ob = $("span.hintText", $(this).parent());
		ob.css("left", e.pageX-($(window).width()-500)/2-85+'px');
		ob.css("display", 'block');
	});
	
	
	/* Hints END */
})

function setPrintCSS(templatesRoot) {
	var myVar = $("#container").html();  
	var myWin = window.open("","print_window","status=1,toolbar=1,height=600,width=800,menubar=1,scrollbars=1");   
	myWin.document.write('<html><head>'+
	'<link rel="stylesheet" media="screen,print" type="text/css" href="'+templatesRoot+'css/style.css"/><link rel="stylesheet" media="screen,print" type="text/css" href="'+templatesRoot+'css/print.css"/>'+
	'<style media="print" type="text/css">.print-button{display:none}</style>'+
	'</head><body><div><table><input class="print-button" type="button" value="'+Lang.getVar("STR_PRINT")+'" onclick="window.print();"/>'+myVar+'</table></div></body></html>');
	myWin.document.close();   
}

function strip_tags (str, allowed_tags) {
    // Strips HTML and PHP tags from a string  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/strip_tags
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Luke Godfrey
    // +      input by: Pul
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // +      input by: Alex
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Marc Palau
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Eric Nagel
    // +      input by: Bobby Drake
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Tomasz Wesolowski
    // *     example 1: strip_tags('<p>Kevin</p> <br /><b>van</b> <i>Zonneveld</i>', '<i><b>');
    // *     returns 1: 'Kevin <b>van</b> <i>Zonneveld</i>'
    // *     example 2: strip_tags('<p>Kevin <img src="someimage.png" onmouseover="someFunction()">van <i>Zonneveld</i></p>', '<p>');
    // *     returns 2: '<p>Kevin van Zonneveld</p>'
    // *     example 3: strip_tags("<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>", "<a>");
    // *     returns 3: '<a href='http://kevin.vanzonneveld.net'>Kevin van Zonneveld</a>'
    // *     example 4: strip_tags('1 < 5 5 > 1');
    // *     returns 4: '1 < 5 5 > 1'
    var key = '', allowed = false;
    var matches = [];
    var allowed_array = [];
    var allowed_tag = '';
    var i = 0;
    var k = '';
    var html = '';

    var replacer = function (search, replace, str) {
        return str.split(search).join(replace);
    };

    // Build allowes tags associative array
    if (allowed_tags) {
        allowed_array = allowed_tags.match(/([a-zA-Z0-9]+)/gi);
    }

    str += '';

    // Match tags
    matches = str.match(/(<\/?[\S][^>]*>)/gi);

    // Go through all HTML tags
    for (key in matches) {
        if (isNaN(key)) {
            // IE7 Hack
            continue;
        }

        // Save HTML tag
        html = matches[key].toString();

        // Is tag not in allowed list? Remove from str!
        allowed = false;

        // Go through all allowed tags
        for (k in allowed_array) {
            // Init
            allowed_tag = allowed_array[k];
            i = -1;

            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');}
            if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');}
            if (i != 0) { i = html.toLowerCase().indexOf('</'+allowed_tag)   ;}

            // Determine
            if (i == 0) {
                allowed = true;
                break;
            }
        }

        if (!allowed) {
            str = replacer(html, "", str); // Custom replace. No regexing
        }
    }

    return str;
}
window.onload = function(){
if (
$('.newbuild .body').height() > $('.hot-offers .body').height()
) {
$('.hot-offers .body').height($('.newbuild .body').height())
} else {
$('.newbuild .body').height($('.hot-offers .body').height())
}
};