function showSpinner () {var spinner = jQuery('#spinner');if (spinner.is('div'))spinner.show();else jQuery('#wrapper').append('<div id="spinner"></spinner>')}function win_popup(target, width, height){var src = target.href;var name = target.target;var default_left = window.screen.width / 2 - width / 2;var default_top = window.screen.height / 2 - height / 2;var window_params = 'width=' + width +',height=' + height + ',scrollbars=yes,resizable=yes,help=no,status=no,left=' + default_left + ',top=' + default_top;var myWin = open(src, name, window_params);myWin.focus();myWin.document.close();return false;}function initCategoryList(){if(!document.getElementById('categorys'))return;var url = jQuery('#categorys ul li a').get(0).href;var location = window.location.pathname;var category_id = location.substring(location.lastIndexOf('/')+1,location.length);url = url.substring(0,url.lastIndexOf('/')+1);var html = '<select name="category_selector" given_value="-1" class="category_selector" id="category_selector" onchange="if (this.value != -1) window.location.href =\'';html += url + '\' + this.value"><option selected="true" value="-1">Категории предложений</option>';var value;jQuery('#categorys ul li a').each(function(){var selected = "";value = this.href.substring(this.href.lastIndexOf('/')+1,this.href.length);current_category_id = this.href.substring(this.href.lastIndexOf('/')+1,this.href.length);if(current_category_id == category_id) selected = "selected=''";html += '<option value="'+ value +'"' + selected +'>' + jQuery(this).text()+ '</option>';});html += '</select>';jQuery('#categorys ul').hide();jQuery('#categorys').prepend(html)};function agentLogin(url){var agentLogin = jQuery('#agent_login');if (agentLogin.is('div'))agentLogin.toggle();else{var html = '<div id="agent_login"></div>';jQuery('#wrapper').append(html);jQuery("#agent_login").load('agent/login_popup', function(){jQuery("#agent_login").css('background','#fef2f9').append('<a href="javascript:void(0)" onclick="jQuery(\'#agent_login\').hide();" class="close"><img alt="закрыть" src="images/1x1.gif"/></a>');});}};function initActionCatalog(){var action = jQuery('#catalog_list .actions_list');var catalog = jQuery('#catalog_list .goods_list');var tabsItemCatalog  = jQuery('#tabs li:last-child');var tabsItemAction  = jQuery('#tabs li:first-child');catalog.hide();tabsItemCatalog.click(function(event) {var event = event || window.event;if(event.target.tagName.toLowerCase() == 'a') return;if (jQuery(this).attr('class')!='active')return;tabsItemAction.addClass('active');action.toggle('slow');tabsItemCatalog.removeClass('active');catalog.toggle();return false;});tabsItemAction.click(function(event) {var event = event || window.event;if(event.target.tagName.toLowerCase() == 'a') return;if (jQuery(this).attr('class')!='active')return;tabsItemCatalog.addClass('active');catalog.toggle('slow');tabsItemAction.removeClass('active');action.toggle();return false;});};function QueryString(qs) {this.params = new Object();this.get=QueryString_get;if (qs == null) qs=location.search.substring(1,location.search.length);if (qs.length == 0) return qs = qs.replace(/\+/g, ' ');var args = qs.split('&');for (var i=0;i<args.length;i++) {var value;var pair = args[i].split('=');var name = unescape(pair[0]);if (pair.length == 2) value = unescape(pair[1]); else value = name;this.params[name] = value;}}function QueryString_get(key, default_) {if (default_ == null) default_ = null; var value=this.params[key];if (value==null) value=default_;return value;}function openParent(link){if (window.opener){window.opener.location = link.href;window.opener.focus();}else{var window_params = 'width=' + window.screen.width +',height=' + window.screen.height + ',toolbar=yes,directories=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,help=yes,status=yes,left=0,top=0';var myWin = open(link.href, '',window_params);myWin.focus();}return false;};function onWindowLoadPopup(){var container = jQuery('#wrapper');width = 840;height =container.height();var left = Math.round(window.screen.width / 2 - width / 2);var top = Math.round(window.screen.height / 2 - height / 2);window.resizeTo(width, height);window.moveTo(left, top);};function highLightMenu (){var url = window.location.toString();var max = 0;var link = null;jQuery("#menu li a").each(function(){if(url.indexOf(this.href) >= 0 && this.href.length > max){link = this;max = this.href.length;}});if(link)link.parentNode.className = "current";}function initCompanyList(){jQuery('#all_companys .list li').hover(function(){jQuery(this).addClass("over").removeClass('out');},function(){jQuery(this).addClass("out").removeClass('over');});}function initCityList(controller){var cityList = jQuery('#city_list');var wrapper = jQuery('#wrapper');var documentHeight = wrapper.height();var documentWidth = wrapper.width();var bodyHeight = jQuery('body').height();var cityListHeight = cityList.height();var cityListWidth = cityList.width();var controllerPosY = findPosY(controller);var controllerPosX = findPosX(controller);var controllerWidth = jQuery(controller).width();cityList.hide();if (documentHeight > (cityListHeight + controllerPosY))cityList.css('top', controllerPosY);else cityList.css('top', controllerPosY - cityListHeight - 20);if (documentWidth > (cityListWidth + controllerPosX + controllerWidth))cityList.css('left', controllerPosX + controllerWidth + 10);else cityList.css('left', controllerPosX - cityListWidth - 50);cityList.slideDown("fast");}function findPosY(obj){var curtop = 0;while (obj.offsetParent){curtop += obj.offsetTop;obj = obj.offsetParent;}return curtop;}function findPosX(obj){var curleft = 0;while (obj){curleft += obj.offsetLeft;obj = obj.offsetParent;}return curleft;}jQuery(document).ready(function(){initCategoryList();initActionCatalog();highLightMenu();initCompanyList();});
