
/* file: ./addons/plugins/groups/tabs/tabs.js */
var plg_groups_tabs = function(){

	var _self = this;
	this.ajaxLoading				= false;
	this.ajaxMethod					= 'plg_groups_list_category::getListByUri';
	this.perCategory				= 6;
	this.containerSelector			= null;
	this.activeClass				= 'active';
	this.itemSelector				= 'a';
	this.textAttribute				= 'title';
	
	this.current					= null;
	this.links						= null;
	
//	this.tabCssActive				= {'font-size':'15px'};
//	this.tabCssInactive				= {'font-size':'15px'};
	
	this.groupsContainer			= '#jQ_groups_categories';
	this.groupsElement				= 'div.jQ_categoryAggregator'; 
	this.groupsAttribute			= 'title';
	
	this.setItemsContainer			= function( selector ){
		this.groupsContainer = selector;
	};
	
	/**
	 * sets 'active' class for an item and removes
	 * this class from any other item
	 */
	this.setActiveClass				= function( item ){
		item = $(item);
		if( !item.hasClass( this.activeClass ) ) {
			this.links.removeClass( this.activeClass );
			item.addClass( this.activeClass );
		}
		return item;
	};
	
	/**
	 * switches between 'shortened' and 'full' tab text
	 * @param {Object} item jQuery object or a valid jQuery selector
	 * @return jQuery
	 */
	this.switchText					= function( item ){
		//disabled text effect
		return true;
		item = $(item);
		var txt1	= item.attr( this.textAttribute );
		var txt2	= item.text();
		item.attr( this.textAttribute, txt2 ).text( txt1 );
		return txt1 != txt2;
	}
	
	/**
	 * handles mouseover event - switches text to full, adds 'active' class
	 */
	this.mouseover					= function( event ){
		if( event.data.switchText( t = event.data.setActiveClass( $(this) ) ) ){
			t.css( event.data.tabCssActive );
		} 
	};
	
	/**
	 * handles mouseout event - switches the text back to shortened version
	 */
	this.mouseout					= function( event ){
		event.data.setActiveClass( event.data.current );
		if( event.data.switchText( t = $(this) ) ){
			$(this).css( event.data.tabCssInactive );
		}
	};
	
	/**
	 * handles click event - changes category
	 */
	this.click						= function( event ){
		try {
			if( event.data.ajaxLoading ) {
				//load categories via AJAX
				majax.call_callback( event.data.ajaxMethod, event.data.onCategoriesLoaded, [ $(this).attr('href'), _perCategory ] );
			} else {
				//perform just a tab switch
				$( event.data.groupsContainer ).children( event.data.groupsElement ).hide().filter( '[@' + event.data.groupsAttribute + '=' + $(this).text() + ']' ).show();
			}
			//save calling tab as current
			event.data.current = $(this);
		} catch ( e ){
		};
		//dispatch event
		event.data.onClick( event );
		//disable traditional clicks
		return false;
	};
	
	/**
	 * override it for simple event dispatching
	 */
	this.onClick					= function ( element ){
	}; 
	
	this.onCategoriesLoaded			= function( response ){
	};
	
	this.enableDynamicSwitching		= function(){
		try {
			this.links.bind( 'click', this, this.click );
		} catch( e ){
		}
	};
	
	this.disableDynamicSwitching	= function(){
		this.links.unbind( 'click', this.click ); 
	};
	
	this.hideTabsWithoutPanel = function(selector , callback ){
		var links = $( _self.itemSelector, selector );
		
		links.each(function( i ){
			var text = $( this ).text();
			var filter = '[@' + _self.groupsAttribute + '=' + text + ']:contains("a")';
			var panel = $( _self.groupsContainer ).children( _self.groupsElement ).filter( filter );
			
			if( panel.length == 0){
				$( this ).hide();	
			}			
		});
		
		callback( selector );	
	}
	
	this.setContainerSelector		= function( selector ){
		_self.hideTabsWithoutPanel(selector,function(selector){
			_self.links		= $( _self.itemSelector+':visible', selector ).bind( 'mouseover', _self, _self.mouseover ).bind( 'mouseout', _self, _self.mouseout );
			_self.current	= _self.setActiveClass( _self.links.filter( '.' + _self.activeClass ) );
		});
	};
};

/* file: ./addons/plugins/html/input/messages/messages.js */

var plg_html_input_messages = new function(){
	
	var type2class 	= ['errors','infos','MSG_ok','confirm'];
	var pattern 	= '<div><p></p></div>';
	
	this.addMessage = function(containerSelector,type,message){
		$msg = $(pattern).addClass(type2class[type])
		$msg.find('p').html(message);
		$(containerSelector).append($msg);
	}
	
	this.clean = function(containerSelector){
		$('div',containerSelector).replaceWith('');
	}
}


/* file: ./addons/plugins/tabs/tabs.js */
var plg_tabs = new function(){
	var _self = this;
	this.tabs = null;
	this.selector = '';
	
	this.setSelector = function(className){
		this.selector = ".tabsmenu"+(className.indexOf("_") != 0 ? '.':'')+className;
		this.tabs = $(this.selector);
		return this;	
	}
	
	this.resetStates = function(){
		this.tabs.find("a.active").removeClass('active');
		return this;
	}
	
	this.setActiveTab = function(index){
		this.resetStates().tabs.find("a:eq("+index +')' ).addClass('active');
		return false;	
	}
	
	this.setActiveTabByReference = function(tab){
		this.resetStates();
		$(tab).addClass('active');
		return false;	
	}
	
	this.getTabs = function(){
		return this.tabs.find("a");
	}
}


/* file: ./addons/plugins/groups/list/category/all/all.js */
function plg_groups_list_category_all(){
	try {
		plg_groups_tabs_categories.onClick = function( evt ) {
			setMoreUri( evt.target );
		}
		setMoreUri( plg_groups_tabs_categories.current );
	} catch( e ) {
	}
}

function setMoreUri( element ){
	try {
		$('#jQ_groups_categories_uri').attr( 'href', $(element).attr('href') );
	} catch( e1 ) {
	}
}

/* file: ./addons/plugins/photos/gallery/gallery.js */

var plg_photos_gallery = new function(){	

	var _self = this;
	var _itemSelector = '.box_images .item';
	var _viewCountSelector = '.jQ_vc';
	var _commentsCountSelector = '.jQ_cc';
	var $_items = null;
	 
	this.viewCountMethod = '';
	
	function getCounters( ids ){
		
		function setVieCounts( data ){
			$_items.each(function(i){
				var id = $('img', this).attr('id'); 
				$(_viewCountSelector,this).html( data[id].viewCount );
				$(_commentsCountSelector,this).html( data[id].commentsCount );
			});
		}
		
		majax.call_callback(_self.viewCountMethod,setVieCounts,[ids]);
	}
	
	function getItems(){
		return $_items == null ? $_items = $( _itemSelector ) : $_items;		
	}
	
	this.init = function(){
		var ids = [];
		
		getItems().each(function(i){
			if( $(_viewCountSelector,this).length > 0){
				ids[ids.length] = $('img', this).attr('id');
			}
		});
		
		if (ids.length > 0) {
			getCounters(ids);
		}
	}	
}

$('document').ready(function(){
	plg_photos_gallery.init();
});


/* file: ./addons/plugins/header/search/search.js */

var plg_header_search = new function(){
	var _self = this;
	
	/**
	 * filled by php
	 */
	this.searchPattern = '';
	this.searchKeyword = '';
	this.searchCity	   = '';
	
	var _submitSelector		=	'#jQ_header_search button[@type=submit]';
	var _fieldKeySelector 	= 	'#jQ_header_search input[@name=keyword]';
	var _fieldCitySelector	=	'#jQ_header_search input[@name=city]'	;
	var _advSearch			= 	'.jQ_advSearch';
	
	function search(){
		
		window.location.replace( prepareSearchLink() );
	return false;
	}
	
	function prepareSearchLink(){
		var link = '';
		if($(_fieldKeySelector).val()){
			link = _self.searchPattern.replace(/--keyword--/,Url.encode($(_fieldKeySelector).val()));
		} else {
			link = _self.searchPattern.replace(/--keyword--/,Url.encode('-'));
		}
		if($(_fieldCitySelector).val()) {
			return link.replace(/--city--/,Url.encode($(_fieldCitySelector).val()));
		}else {
			return link.replace(/--city--/,Url.encode(''));
		}
	}
	
	this.init = function(){
		$(_submitSelector).unbind('click').click( search );
		
		if( this.searchKeyword ){
			$(_fieldKeySelector).val( this.searchKeyword );
		}
		if( this.searchCity ){
			$(_fieldCitySelector).val( this.searchCity);
		}
		
		$(_advSearch).click(function(){
			plg_header_search_advanced.show();
		return false;	
		});
		
	}
}

$('document').ready(function(){ plg_header_search.init(); });

/* file: ./system/js/jquery.boxy/src/javascripts/jquery.boxy.js */
// Boxy - Facebook-style dialog, with frills
// (c) 2008 Jason Frame

// TODO: multi-select list
// TODO: allow resizing when not visible
// BUG: modal dialog blackout doesn't resize when window resizes

//
// jQuery Plugin

// single - only show a single instance at a time (default: true)
// cache - if true, data retrieved from AJAX calls will be cached. Inline data
//         will always be cached as we need to stash it someplace outside the DOM
//         to avoid having multiple elements with the same ID.
// message - confirmation message for form submit hook (default: "Please confirm:")
// method - AJAX method to use for loading remote content (default: GET)
// (any leftover options - e.g. 'clone' - will be passed onto the boxy constructor)
$.fn.boxy = function(options) {
    options = $.extend({single: true}, options || {});
    this.each(function() {      
        var node = this.nodeName.toLowerCase(), self = this;
        if (node == 'a') {
            $(this).click(function() {
                var anchor = this,
                    href = this.getAttribute('href'),
                    realOpts = $.extend(options, {title: this.title});
                    
                var loadContent = function(after) {
                    if (Boxy.cache[href]) {
                        after(Boxy.cache[href].clone());   
                    } else if (href.indexOf('#') === 0) {
                        Boxy.cache[href] = $(href).remove();
                        after(Boxy.cache[href].clone());
                    } else { // fall back to AJAX; could do with a same-origin check
                        $.ajax({
                            url: anchor.href,
                            method: options.method || 'GET',
                            dataType: 'html',
                            data: {__math__: Math.random()},
                            success: function(data) {
                                data = $(data);
                                if (options.cache) {
                                    Boxy.cache[href] = data;
                                    data = data.clone();
                                }
                                after(data);
                            }
                        });
                    }
                };
                
                var active;
                if (options.single && (active = $.data(this, 'active.boxy'))) {
                    loadContent(function(content) {
                        active.setContent(content).center().show();     
                    });
                } else {
                    loadContent(function(content) {
                        $.data(anchor, 'active.boxy', new Boxy(content, realOpts));     
                    });
                }
                
                return false;
            });
        } else if (node == 'form') {
            $(this).bind('submit.boxy', function() {
                Boxy.ask(options.message || 'Please confirm:', ['OK', 'Cancel'], function(v) {
                    if (v == 'OK') {
                        $(self).unbind('submit.boxy').submit();
                    }
                }, {modal: true, closeable: false});
                return false;
            });
        }
    });
};

//
// Boxy Class

function Boxy(element, options) {
    
    this.boxy = $(this.WRAPPER);
    $.data(this.boxy[0], 'boxy', this);
    
    this.visible = false;
    this.options = $.extend({
        title: null, closeable: true, draggable: true, clone: false,
        center: true, show: true, modal: false
    }, options || {});
    
    if (this.options.modal) {
        this.options = $.extend(this.options, {center: true, draggable: false});
    }
    
    this.setContent(element || "<div></div>");
    this._setupTitleBar();
    this._setupBehaviours();
    
    this.boxy.css('display', 'none').appendTo(document.body);
    this.toTop();
    
    if (this.options.center
        && typeof this.options.x == 'undefined'
        && typeof this.options.y == 'undefined') {
        this.center();
    } else {
        this.moveTo(this.options.x || Boxy.DEFAULT_X,
                    this.options.y || Boxy.DEFAULT_Y);
    }
    
    if (this.options.show) this.show();

};

$.extend(Boxy, {
    DEFAULT_X:          50,
    DEFAULT_Y:          50,
    cache:              {},
    zIndex:             1337,
    dragConfigured:     false, // only set up one drag handler for all boxys
    dragging:           null,
    
    // allows you to get a handle to the containing boxy instance of any element
    // e.g. <a href='#' onclick='alert(Boxy.get(this));'>inspect!</a>.
    // this returns the actual instance of the boxy 'class', not just a DOM element.
    // Boxy.get(this).hide() would be valid, for instance.
    get: function(ele) {
        var p = $(ele).parents('.boxy-wrapper');
        return p.length ? $.data(p[0], 'boxy') : null;
    },
    
    // asks a question with multiple responses presented as buttons
    // selected item is returned to a callback method.
    // answers may be either an array or a hash. if it's an array, the
    // the callback will received the selected value. if it's a hash,
    // you'll get the corresponding key.
    ask: function(question, answers, callback, options) {
        
        options = $.extend({modal: true, closeable: false}, options, {show: true});
        
        var body = $('<div></div>').append($('<div class="question"></div>').html(question));
        
        // ick
        var map = {}, answerStrings = [];
        if (answers instanceof Array) {
            for (var i = 0; i < answers.length; i++) {
                map[answers[i]] = answers[i];
                answerStrings.push(answers[i]);
            }
        } else {
            for (var k in answers) {
                map[answers[k]] = k;
                answerStrings.push(answers[k]);
            }
        }
        
        var buttons = $('<form class="answers"></form>');
        buttons.html($.map(answerStrings, function(v) {
            return "<input type='button' value='" + v + "' />";
        }).join(' '));
        
        $('input[type=button]', buttons).click(function() {
            var clicked = this;
            Boxy.get(this).hide(function() {
                if (callback) callback(map[clicked.value]);
            });
        });
        
        body.append(buttons);
        
        new Boxy(body, options);
        
    },
    
    _handleDrag: function(evt) {
        var d;
        if (d = Boxy.dragging) {
            d[0].boxy.css({left: evt.pageX - d[1], top: evt.pageY - d[2]});
        }
    },
    
    _nextZ: function() {
        return Boxy.zIndex++;
    }
});

Boxy.prototype = {
    
    WRAPPER:    "<table cellspacing='0' cellpadding='0' border='0' class='boxy-wrapper'>" +
                    "<tr><td class='top-left'></td><td class='top'></td><td class='top-right'></td></tr>" +
                    "<tr><td class='left'></td><td class='boxy-inner'></td><td class='right'></td></tr>" +
                    "<tr><td class='bottom-left'></td><td class='top'></td><td class='bottom-right'></td></tr>" +
                "</table>",
    
    // Returns the size of this boxy instance without displaying it.
    // Do not use this method if boxy is already visible, use getSize() instead.
    estimateSize: function() {
        this.boxy.css('display', 'none')
                 .css({top: 0, left: 0, visibility: 'hidden'})
                 .css('display', 'block');
        var dims = this.getSize();
        this.boxy.css('display', 'none').css('visibility', 'visible');
        return dims;
    },
                
    // Returns the dimensions of the entire boxy dialog as [width,height]
    getSize: function() {
        return [this.boxy.width(), this.boxy.height()];
    },
    
    // Returns the dimensions of the content region as [width,height]
    getContentSize: function() {
        var c = this.getContent();
        return [c.width(), c.height()];
    },
    
    // Returns the position of this dialog as [x,y]
    getPosition: function() {
        var b = this.boxy[0];
        return [b.offsetLeft, b.offsetTop];
    },
    
    // Returns the center point of this dialog as [x,y]
    getCenter: function() {
        var p = this.getPosition();
        var s = this.getSize();
        return [Math.floor(p[0] + s[0] / 2), Math.floor(p[1] + s[1] / 2)];
    },
                
    // Returns a jQuery object wrapping the inner boxy region.
    // Not much reason to use this, you're probably more interested in getContent()
    getInner: function() {
        return $('.boxy-inner', this.boxy);
    },
    
    // Returns a jQuery object wrapping the boxy content region.
    // This is the user-editable content area (i.e. excludes titlebar)
    getContent: function() {
        return $('.boxy-content', this.boxy);
    },
    
    // Replace dialog content
    setContent: function(newContent) {
        newContent = $(newContent).css({display: 'block'}).addClass('boxy-content');
        if (this.options.clone) newContent = newContent.clone();   
        var content = this.getContent();
        if (content.length) {
            content.replaceWith(newContent);   
        } else {
            this.getInner().append(newContent);
        }
        return this;
    },
    
    // Move this dialog to some position, funnily enough
    moveTo: function(x, y) {
        this.boxy.css({left: x, top: y});
        return this;
    },
    
    // Move this dialog so that it is centered at x,y
    centerAt: function(x, y) {
        if (this.visible) {
            var s = this.getSize();
        } else {
            var s = this.estimateSize();
        }
        this.moveTo(x - s[0] / 2, y - s[1] / 2);
        return this;
    },
    
    // Center this dialog in the viewport
    center: function() {
        var s = $.browser.msie ? [document.documentElement.scrollLeft, document.documentElement.scrollTop]
                               : [window.pageXOffset, window.pageYOffset];
        var v = [s[0], s[1], $(window).width(), $(window).height()];
        this.centerAt((v[0] + v[2] / 2), (v[1] + v[3] / 2));
        return this;
    },
    
    // Resize the content region to a specific size
    resize: function(width, height, after) {
        if (!this.visible) return;
        var bounds = this._getBoundsForResize(width, height);
        this.boxy.css({left: bounds[0], top: bounds[1]});
        this.getContent().css({width: bounds[2], height: bounds[3]});
        if (after) after(this);
        return this;
    },
    
    // Tween the content region to a specific size
    tween: function(width, height, after) {
        if (!this.visible) return;
        var bounds = this._getBoundsForResize(width, height);
        var self = this;
        this.boxy.stop().animate({left: bounds[0], top: bounds[1]});
        this.getContent().stop().animate({width: bounds[2], height: bounds[3]}, function() {
            if (after) after(self);
        });
        return this;
    },
    
    isVisible: function() {
        return this.visible;    
    },
    
    // Make this boxy instance visible
    show: function() {
        if (this.visible) return;
        if (this.options.modal) {
            $('<div class="boxy-modal-blackout"></div>')
                .css({zIndex: Boxy._nextZ(),
                      width: $(document).width(),
                      height: $(document).height()})
                .appendTo(document.body);
            this.toTop();
        }
        this.boxy.stop().css({opacity: 1, display: 'block'});
        this.visible = true;
        return this;
    },
    
    // Hide this boxy instance
    hide: function(after) {
        if (!this.visible) return;
        var self = this;
        if (this.options.modal) {
            $('.boxy-modal-blackout').animate({opacity: 0}, function() {
                $(this).remove();
            });
        }
        this.boxy.stop().animate({opacity: 0}, 300, function() {
            self.boxy.css({display: 'none'});
            self.visible = false;
            if (after) after(self);
        });
        return this;
    },
    
    // Move this dialog box above all other boxy instances
    toTop: function() {
        this.boxy.css({zIndex: Boxy._nextZ()});
        return this;
    },
    
    //
    // Don't touch these privates
    
    _getBoundsForResize: function(width, height) {
        var csize = this.getContentSize();
        var delta = [width - csize[0], height - csize[1]];
        var p = this.getPosition();
        return [Math.max(p[0] - delta[0] / 2, 0),
                Math.max(p[1] - delta[1] / 2, 0), width, height];
    },
    
    _setupTitleBar: function() {
        if (this.options.title) {
            var self = this;
            var tb = $("<div class='title-bar'></div>").html(this.options.title);
            if (this.options.closeable) {
                tb.append($("<a href='#' class='close'></a>").html("[close]"));
            }
            if (this.options.draggable) {
                if (!Boxy.dragConfigured) {
                    $(document).mousemove(Boxy._handleDrag);
                    Boxy.dragConfigured = true;
                }
                tb.mousedown(function(evt) {
                    self.toTop();
                    Boxy.dragging = [self, evt.pageX - self.boxy[0].offsetLeft, evt.pageY - self.boxy[0].offsetTop];
                    $(this).addClass('dragging');
                });
                tb.mouseup(function() {
                    $(this).removeClass('dragging');
                    Boxy.dragging = null;
                });
            }
            this.getInner().prepend(tb);
        }
    },
    
    _setupBehaviours: function() {
        var self = this;
        $('.close', this.boxy).click(function() {
            self.hide();
            return false;
        }).mousedown(function(evt) { evt.stopPropagation(); });
    }
    
};


/* file: ./addons/plugins/header/search/advanced/advanced.js */

var plg_header_search_advanced = new function(){
	var _self = this;
	
	/**
	 * filled by php
	 */
	this.searchPattern = '';
	this.searchKeyword = '';
	this.searchCity	   = '';
	
	var _container 			=   '#advancedSearching';
	var _submitSelector		=	_container+' button[@type=submit]';
	var _fieldKeySelector 	= 	_container+' input[@name=keyword]';
	var _fieldCitySelector	=	_container+' input[@name=city]'	;
	
	var $boxy = null;
	
	function search(){
		
		window.location.replace( prepareSearchLink() );
	return false;
	}
	
	function prepareSearchLink(){
		var link = '';
		if($(_fieldKeySelector).val()){
			link = _self.searchPattern.replace(/--keyword--/,Url.encode($(_fieldKeySelector).val()));
		} else {
			link = _self.searchPattern.replace(/--keyword--/,Url.encode('-'));
		}
		if($(_fieldCitySelector).val()) {
			return link.replace(/--city--/,Url.encode($(_fieldCitySelector).val()));
		}else {
			return link.replace(/--city--/,Url.encode(''));
		}
	}
	
	this.init = function(){
		$(_submitSelector).unbind('click').click( search );
		
		if( this.searchKeyword ){
			$(_fieldKeySelector).val( this.searchKeyword );
		}
		if( this.searchCity ){
			$(_fieldCitySelector).val( this.searchCity);
		}
		
		$boxy = new Boxy($(_container).get(0),{
			closeable: 		true,
			show: 			false,
			title:			Language.advancedSearchingBoxHeader,
			modal:			true
		});
	
		$( '.title-bar a.close', $boxy.boxy ).html(Language.advancedSearchingBoxClose);
	
	}
	
	this.show = function(){
		$boxy.show();
	}
	
	this.hide = function(){
		$boxy.hide();
	}
}

$('document').ready(function(){ plg_header_search_advanced.init(); });


/* file: ./addons/plugins/autocomplete/autocomplete.js */

var plg_autocomplete = new function(){
	
	var _self = this;
	
	this._ajaxMethodeName = '';
	this._inputSelector = '';
	
	this.bind = function( selector ){
		$( selector ).autocomplete(null, {
			multiple: true,
			mustMatch: false,
//			autoFill: true,
//			matchSubset: false,
			selectFirst: false,
			minChars: 3,
			delay: 200,
			formatItem: function(row){ return row; },
			_method: this._ajaxMethodeName,
			parse: function(data){ 
				var _data = [];
				
				for(var d in data) { 
					_data[_data.length] = { data: data[d], value: data[d], result: data[d] }; 
				}
			return _data; 
			}
		});
	}
	
	this.init = function(){
		this.bind( this._inputSelector  );
	}

}


/* file: ./addons/plugins/autocomplete/city/city.js */

var class_plg_autocomplete_city = function(){

	this.bind = function( selector ){
		$( selector ).autocomplete(null, {
			multiple: false,
			mustMatch: true,
			selectFirst: false,
			matchContains: false,
			minChars: 3,
			delay: 200,
			formatItem: function(row){ return row; },
			_method: this._ajaxMethodeName,
			parse: function(data){ 
				var _data = [];
				
				for(var d in data) { 
					_data[_data.length] = { data: data[d], value: data[d], result: data[d] }; 
				}
			return _data; 
			}
		});
	}

}

class_plg_autocomplete_city.prototype = plg_autocomplete;
var plg_autocomplete_city = new class_plg_autocomplete_city();


/* file: ./addons/plugins/groups/search/local/local.js */

var plg_groups_search_local = new function(){
	
	var _self = this;
	
	/**
	 * filled by php
	 */
	this.searchPattern = '';
	this.searchPatternGroup = '';
	this.searchPatternForum = '';
	this.searchCountry = '';
	this.searchCity = '';
	this.searchZip = '';
	this.searchKeyword = '';
	
	this.container 				= '.jQ_gSearchLocal';
	var _submitSelector 		= 'button.jQ_submit';
	var _countrySelector 		= 'select[@name=country]';
	var _fieldZipSelector 		= 'input[@name=zip]';
	var _fieldCitySelector 		= 'input[@name=city]';
	var _fieldKeywordSelector 	= 'input[@name=keyword]';
	var _errSelector 			= '.errors';
	var _searchInSelector		= 'select[@name=searchIn]';
	var _localOptions 			= '.jQ_localSearchingOptions';
	
	function search(){
		_self.container = $( this ).parents('.jQ_gSearchLocal');
		
		var link = prepareSearchLink();

		if( link ){
			location.href = link;	
		}
		
	return false;
	}
	
	function showErr( message ){
		var $e = $(_errSelector);
		
		$('p',$e).html( message );
		
		sys.showConfirmation($e);
	}
	
	function prepareSearchLink(){
	
		var _city = Url.encode($(_fieldCitySelector, _self.container).val());
		var _country = $(_countrySelector, _self.container).val();
		var _keyword = Url.encode($(_fieldKeywordSelector, _self.container).length > 0 ? $(_fieldKeywordSelector, _self.container).val() : '');
		var _zip = $(_fieldZipSelector, _self.container).val().replace(/[^0-9]+/g, '');
		
		//		if( !_zip && !_city){
		//			showErr( Language.SEARCH_GROUP_LOCAL_NO_ZIP_ERR );
		//		return false;
		//		}
		
		var pattern = '';
		var mode = parseInt($(_searchInSelector, _self.container).val());
		
		switch (mode) {
			default:
			case 0:
				pattern = _self.searchPattern;
				break;
			case 1:
				pattern = _self.searchPatternGroup;
				break;
			case 2:
				pattern = _self.searchPatternForum;
				break;
		}
		
		var link = pattern.replace(/\-\-keyword\-\-/, (_keyword != '' ? _keyword : '-'));
		
		
			link = link.replace(/\-\-country\-\-/, ( ( _country != '' && mode < 2 ) ? _country : '-'));
			link = link.replace(/\-\-city\-\-/, ( ( _city != '' && mode < 2 ) ? _city : '-'));
			link = link.replace(/\-\-zip\-\-/, ( ( _zip != '' && mode < 2 ) ? _zip : '-'));
			
		
	return link;
	}
	
	function setZipMask(){

		var ov = $(_fieldZipSelector).val();
		var settings = {placeholder:'_'};
		
		switch($(_countrySelector).val()){
			case 'ch': 
			case 'at':
				$(_fieldZipSelector).unmask().mask( '9999' , settings);
				ov = ov.substr(0,4);
				break;
			
			case 'pl':
				$(_fieldZipSelector).unmask().mask( '99-999', settings );
				ov = ov.substr(0,5);
				break;
			case 'de':
			default:
				$(_fieldZipSelector).unmask().mask( '99999', settings );
				ov = ov.substr(0,5);
		}
		$(_fieldZipSelector).val( ov );
	}
	
	this.init = function(){
		
		$(_submitSelector,$(_self.container)).unbind('click').click( search );
		
		$('form',$(_self.container)).unbind('submit').submit( search );
		
		$(_countrySelector, $(_self.container)).unbind('click').click(function(){ setZipMask(); });
		
		$(_searchInSelector, $(_self.container)).unbind('change').change(function(){
			
			var $options = $(_localOptions,$(this).parents( _self.container ));
			
			switch( parseInt( $(this).val() ) ){
				default:
				$(':hidden',$options).show();
					break;
				case 2:
				$(':visible',$options).hide();
					break;
			}
		});
		
		if( this.searchCountry ){
			$('option',_countrySelector).removeAttr('selected');
			$('option[@value='+this.searchCountry+']',_countrySelector).attr('selected','selected');
		}
		
		setZipMask();
		
		if( this.searchCity){
			$(_fieldCitySelector,$(_self.container)).val( this.searchCity );
		}
		
		if( this.searchZip ){
			$(_fieldZipSelector,$(_self.container)).val( this.searchZip );
		}
		
		if( this.searchKeyword && $(_fieldKeywordSelector).length > 0 ){
			$(_fieldKeywordSelector,$(_self.container)).val( this.searchKeyword );
		}
	}
	
}
$('document').ready(function(){ plg_groups_search_local.init(); });
