var menuOut;var menuOver;$(function(){$("#nav > li").live('hover',function(e){var el=$(this);if(e.type=='mouseenter'){if($("#nav > li").hasClass('hover')){$("#nav > li.hover").removeClass('hover');$(el).addClass('hover');clearTimeout(menuOut)}else{menuOver=setTimeout(function(){$(el).addClass('hover')},1000)}}else{clearTimeout(menuOver);menuOut=setTimeout(function(){$(el).removeClass('hover')},1000)}});$("#word").autocomplete("ajax/autocomplete.php",{delay:10,minChars:2,matchSubset:1,autoFill:false,matchContains:1,cacheLength:10,formatItem:liFormat,maxItemsToShow:10,onItemSelect:selectItem});var l=document.location.href;$('#header .share a').attr('target','_blank');$('#header .share .facebook').attr('href','http://facebook.com/share.php?u='+l);$('#header .share .twitter').attr('href','http://twitter.com/share?url='+l);$('#header .share .vkontakte').attr('href','http://vkontakte.ru/share.php?url='+l)});function getSearchMoreParam(action){var cat_id=$("#categories").val();var subcat_id=$("#subcategories").val();var town_id=$("#towns").val();var presence_id=$("#presence").val();var seller_id=$("#sellers").val();switch(action){case'categories':if(cat_id==0){$("#subcategories").attr("disabled",true);$("#towns").attr("disabled",true);break}$.ajax({type:'POST',url:'search_ajax.php',data:'action=categories&cat_id='+cat_id,success:function(subcategories){$("#subcategories").attr("disabled",false);$("#subcategories").html(subcategories)}});$.ajax({type:'POST',url:'search_ajax.php',data:'action=subcategories&cat_id='+cat_id+'&subcat_id='+subcat_id,success:function(towns){$("#towns").attr("disabled",false);$("#towns").html(towns)}});$("#sellers").attr("disabled",true);$("#presence").attr("disabled",true);break;case'subcategories':$.ajax({type:'POST',url:'search_ajax.php',data:'action=subcategories&cat_id='+cat_id+'&subcat_id='+subcat_id,success:function(towns){$("#towns").attr("disabled",false);$("#towns").html(towns)}});$("#sellers").attr("disabled",true);$("#presence").attr("disabled",true);break;case'towns':$.ajax({type:'POST',url:'search_ajax.php',data:'action=towns&cat_id='+cat_id+'&subcat_id='+subcat_id+'&town_id='+town_id,success:function(sellers){$("#sellers").attr("disabled",false);$("#sellers").html(sellers)}});$("#presence").attr("disabled",true);break;case'sellers':$.ajax({type:'POST',url:'search_ajax.php',data:'action=sellers&cat_id='+cat_id+'&subcat_id='+subcat_id+'&town_id='+town_id+'&seller_id='+seller_id,success:function(presence){$("#presence").attr("disabled",false);$("#presence").html(presence)}});break}}function showSubcatList(cat_id){if($("#subcat_list_"+cat_id).is(':visible')){$("#subcat_list_"+cat_id).hide()}else{$("span[id^='subcat_list_']").hide();$("#subcat_list_"+cat_id).show()}}function centerWindow(){var agent=navigator.userAgent.toLowerCase();var browser_version=navigator.appVersion.charAt(0);var is_opera=(agent.indexOf("opera")!=-1);if(browser_version>=4){var r=(is_opera)?100:0;var left=(screen.width-500)/2;var top=(screen.height-400)/2-r;window.moveTo(left,top)}}function checkMail(src){var i=src.indexOf('@');if((i<=0)||i==(src.length-1)){return false}else{var s1=src.substring(0,i);var s2=src.substr(i+1);if(s1.search(/[^A-Za-z\d_\.\-]/)>=0||s2.search(/[^A-Za-z\d_\.\-]/)>=0){return false}if(s2.search(/[A-Za-z\d\-][\.][A-Za-z\d\-]/)==-1||s2.substr(s2.length-1,1)=='.'||s2.search(/[\.]{2,}/)>=0){return false}if(s1.substr(s1.length-1,1)=='.'||s1.search(/[\.]{2,}/)>=0){return false}}return true}function liFormat(row,i,num){var result=row[0]+'<p class="qnt">'+row[1]+' результат'+getResultsName(''+row[1]+'')+'</p>';return result}function selectItem(li){if(li==null){var sValue='Ничего не выбрано!'}if(!!li.extra){var sValue=li.extra[2]}else{var sValue=li.selectValue}}function getResultsName(num){var ArrNames=['ов','','а','а','а','ов','ов','ов','ов','ов'];var numLength=num.length;if(numLength==1){return ArrNames[num]}if(num>4&&num<21){return ArrNames[0]}if(numLength>1&&num>20){return ArrNames[num.substring(numLength-1,numLength)]}}function checkRegistrationForm(field){var check_field=$("#"+field).val();var ok='<img src="i/icons/16/ok.png" />';var flag=false;switch(field){case'email':flag=checkMail($("#"+field).val());break;case'registration_password':if(check_field.length>5){flag=true}break;case'repeat_registration_password':if(check_field.length>5&&$("#registration_password").val().length>5&&check_field==$("#registration_password").val()){flag=true}break;case'company':if(check_field.length>2){flag=true}break;case'fio':if(check_field.length>5){flag=true}break;case'phone':if(check_field.length>7){flag=true}break;case'register_town_id':if(check_field>0){flag=true}break;case'description':if(check_field.length>50){flag=true}break;case'no_robot':if($("#"+field+":checked").length==1){flag=true}break}if(flag){$("#star_"+field).html(ok)}else{$("#star_"+field).html("*")}if(checkMail($("#email").val())&&$("#repeat_registration_password").val().length>5&&$("#registration_password").val().length>5&&$("#repeat_registration_password").val()==$("#registration_password").val()&&$("#company").val().length>2&&$("#fio").val().length>2&&$("#phone").val().length>7&&$("#town_id").val()>0&&$("#description").val().length>50&&$("#no_robot:checked").length==1){$("#registration_submit").attr("disabled",false).addClass('active')}else{$("#registration_submit").attr("disabled",true).removeClass('active')}}
