function getmainurl() {
				$('#p_dist').val(0);
				$('#test38').val(0);
				//alert ('n');
				$('form.selection').serialize();
				$('form.selection').submit();
				//location.href='http://www.delo-bg63.ru/testing/?vid=9&';
				}
				
function getmainurl2() {
				//$('#p_dist').val(0);
				//$('#test38').val(0);
				//alert ('n');
				$('input[name="p"]').val(0);
				$('#form_cool').serialize();
				$('#form_cool').submit();
				//location.href='http://www.delo-bg63.ru/testing/?vid=9&';
				}




function scrollto(){
	var destination = $('div.pager_cool').eq(0).offset().top - 15;
	var w = $.browser.webkit ? $('body') : $('html');
	w.animate({ scrollTop: destination}, 400 );
}

function getcookie(name) {  
	var aCookie = document.cookie.split(';');  
	for (var i = 0; i < aCookie.length; i++) {  
		while(aCookie[i][0] == ' ') {  
		   aCookie[i] = aCookie[i].substr(1);  
		}  
		var aCrumb = aCookie[i].split('=');  
		if (name == aCrumb[0]) {  
		   return unescape(aCrumb[1]);  
		}  
	}  
	return null;  
}

function setHistory() {  
	//alert (getcookie('s0'));
	if (getcookie('filter')){
		if (getcookie('filter') == 'cool'){
			if (getcookie('name')) $('input[name="name"]').val(getcookie('name'));
			if (getcookie('id')) $('input[name="id"]').val(getcookie('id'));
			if (getcookie('s0') == 1) $('input[name="s0"]').attr('checked', 'checked');
			if (getcookie('s1') == 1) $('input[name="s1"]').attr('checked', 'checked');
			if (getcookie('s2') == 1) $('input[name="s2"]').attr('checked', 'checked');
			if (getcookie('s3') == 1) $('input[name="s3"]').attr('checked', 'checked');
			if (getcookie('s4') == 1) $('input[name="s4"]').attr('checked', 'checked');
			var i=0;
			for (i=0; i<100; i++){
				if (getcookie('d'+i) == 1) $('input[name="d'+i+'"]').attr('checked', 'checked');
			}
			for (i=0; i<1000; i++){
				if (getcookie('vid'+i) == 1) $('input[name="vid'+i+'"]').attr('checked', 'checked');
			}
			
			if (getcookie('sort_with')) $('select[name="sort_with"]').find('option[value="'+getcookie('sort_with')+'"]').attr('selected', 'selected');
		}
	}
}

function mail(name, domain, style) {
	document.write('<a h'+'ref="'+'mai'+ 'lto:'+name+'@'+domain+'" style="'+style+'">'+name+'@'+domain+'</a>');
}


		function check(myname,text) {
			if($(myname).attr('value')==text)
			{
				$(myname).val('');
			}else{
				if($(myname).attr('value')==''){
				$(myname).val(text);
				}
			}
		}

$(document).ready(function() {
	
	$center_b = true;
	setInterval(function(){
		if ($center_b){
			$('div.center_b').find('img.swn').fadeOut(500);
			$('div.center_b').find('img.hid').fadeIn(500);
			$center_b = false;
		}
		else {
			$('div.center_b').find('img.hid').fadeOut(500);
			$('div.center_b').find('img.swn').fadeIn(500);
			$center_b = true;
		}
	},3000);

	// tooltips on maps
	$('map *').each(function(){
		var title = $(this).attr('title');
		var alt = $(this).attr('alt');
		var middle = -60;
		var top = -60;
		middle = Math.round(alt.length/2)*(-6.6);
		if ( alt.length <= title.length )  middle = Math.round(title.length/2)*(-8.1);
		//alert (title.length);
		var icon = '<div id="icon"><div class="td_center"><div class="td_left"></div><span>'+title+'</span>';
		if (alt.length > 2) {icon = icon+'<br /><font>'+alt+'</font>';} else middle = -60;
		icon = icon+'<div class="td_right">&nbsp;</div></div></div>';
		
		if($(this).hasClass('big')){
			icon = '<div class="big_icon">'+title+alt+'</div>';
			middle = -78;
			top = -140;
		}
		
		$(this).tooltip({ 
			delay: 50, 
			showURL: false, 
			fixPNG: true,
			top: top,
			left: middle,
			track: true,
			fade: 200,
			bodyHandler: function() { 
				return icon;
			} 
		});
	});

	$('map *').click(function(){ return false; });
	$('map *').css('cursor', 'hover');


	
	$('div.pager').find('a').live("click",function(){
		$page = $(this).find('span').text();
		$('#p_dist').val($page);
		$page2 = $('#new_url').val();
		//$('#test5').click();
		$request = $('form.selection').serialize();
		$request = $request+'&p='+$page2;
		//location.href='http://www.delo-bg63.ru/filter/?vid=9&p='+$page;
		//window.location.search = '?vid=9&p='+$page;
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
				
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_filter_refresh.php",
			data: $request,
			success: function(msg){
			window.location.href='http://www.delo-bg63.ru/filter/?vid=9&p='+$page+$page2;
			//window.location.search = '?vid=9&p='+$page+$page2;
				//setTimeout($('div#ajax_inner').html(msg);,3000);
				//$('div#ajax_inner').html(msg);
		    }
		});
		return false;
	});
	
	$('div#buypager').find('a').live("click",function(){
		$page = $(this).find('span').text();
		$request = $('#form_buy').serialize();
		$request = $request+'&p='+$page;
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_buy_refresh.php",
			data: $request,
			success: function(msg){
				//$('div.older_table').html(msg);
				document.getElementById('ajax_insert').innerHTML = msg;
		    }
		});
		return false;
	});
	
	$('div.pager_cool').find('a').live("click",function(){
		$page = $(this).find('span').text();
		$('input[name="p"]').val($page);
		$request = $('#form_cool').serialize();
		$ajax_ins = '';
		if ($('#form_cool').hasClass('small_form')) $ajax_ins = 'ajax_inner'; else $ajax_ins = 'ajax_insert';
		//$request = $request+'&p='+$page;
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_cool_refresh.php",
			data: $request,
			success: function(msg){
				//$('div.older_table').html(msg);
				
				$('#form_cool').submit();
				//document.getElementById($ajax_ins).innerHTML = msg;
				//scrollto();
		    }
		});
		return false;
	});
	
	$('a.ajax_podbor').click(function(){
		$request = $('form.selection').serialize();
		//$page = $(this).find('span').text();
		//$request = $request+'&p='+$page;
		//$request = $request+'&p='+$page;
		$page2 = $('#new_url').val();
		
		//alert('test'+$request);
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_filter_refresh.php",
			data: $request,
			success: function(msg){
				//alert(msg.length);
				$('div#ajax_inner').html(msg);
				
				
		    }
		});
		return false;
	});
	
	/*
	$('#H1Header').click(function(){
		$request = $('#form_cool').serialize();
		alert($request);
	});
	*/
	
	//setHistory();
	
	$is_cool_first = false;
	
	$('a.cool_go').click(function(){
	
		if ($is_cool_first) {
			$('input[name="p"]').val(0);
		}
		$is_cool_first = true;
		$request = $('#form_cool').serialize();
		//alert($request);
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_cool_refresh.php",
			data: $request,
			success: function(msg){
				//alert(msg.length);
				$('div#ajax_insert').html(msg);
		    }
		});
		return false;
	});
	
	$('#last_task').change(function(){
		//if ($is_cool_first) {
			//$('input[name="p"]').val(0);
		//}
		$is_cool_first = true;
		$request = $('#form_cool').serialize();
		//alert($request);
		$.ajax({
			type: "GET",
			beforeSend: function(){
				$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_cool_refresh.php",
			data: $request,
			success: function(msg){
				//alert(msg.length);
				$('#ajax_inner').html(msg);
		    }
		});
		return false;
	});
	
	$('#find_buy').click(function(){
		$request = $('#form_buy').serialize();
		//alert('test'+$request);
		$.ajax({
			type: "GET",
			beforeSend: function(){
				//$('#ajax_loading').css('background','url(/ajax/loading.gif) top left no-repeat');
			},
			complete: function(){
				//$('#ajax_loading').css('background','none');
			},
			url: "/ajax/ajax_buy_refresh.php",
			data: $request,
			success: function(msg){
				//alert(msg.length);
				//$('.older_table').html(msg);
				//$('#form_buy').append(msg);
				document.getElementById('ajax_insert').innerHTML = msg;
				//$('.older_table').append(msg.substring(1001,2000));
				//$('.older_table').append(msg.substring(2001,3000));
				//$('.older_table').append(msg.substring(3001,4000));
				//$('.older_table').append(msg.substring(4001,5000));
				//$('.older_table').append(msg.substring(5001,6000));
				
		    }
		});
		return false;
	});
	
	$('#find_buy').click();
	
	$toggle1 = true;
	$toggle2 = true;
	$toggle3 = true;
	
	$toggle_buy = true;
	
	$('span.check_all_buy').click(function(){
		if($toggle_buy){
			$(this).parent().find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle_buy = false;
		}
		else{
			$(this).parent().find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle_buy = true;
		}
	});
	
	$('span.check_all').eq(0).click(function(){
		if($toggle1){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle1 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle1 = true;
		}
	});
	$('span.check_all').eq(1).click(function(){
		if($toggle2){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().next().next().next().find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle2 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().next().next().next().find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle2 = true;
		}
	});
	$('span.check_all').eq(2).click(function(){
		if($toggle3){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).text('Снять все');
			$toggle3 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).text('Отметить все');
			$toggle3 = true;
		}
	});
	
	$toggle_cool1 = true;
	$toggle_cool2 = true;
	$toggle_cool3 = true;
	
	$('#check1').click(function(){
		//alert('opa');
		if($toggle_cool1){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().find('font').text('Снять все');
			$toggle_cool1 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().find('font').text('Отметить все');
			$toggle_cool1 = true;
		}
	});
	$('#check2').click(function(){
		if($toggle_cool2){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().next().next().next().find('input').attr('checked','checked');
			$(this).parent().find('font').text('Снять все');
			$toggle_cool2 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().next().next().next().find('input').attr('checked','');
			$(this).parent().find('font').text('Отметить все');
			$toggle_cool2 = true;
		}
	});
	$('#check3').click(function(){
		if($toggle_cool3){
			$(this).parent().next().find('input').attr('checked','checked');
			$(this).parent().find('font').text('Снять все');
			$toggle_cool3 = false;
		}
		else{
			$(this).parent().next().find('input').attr('checked','');
			$(this).parent().find('font').text('Отметить все');
			$toggle_cool3 = true;
		}
	});
	
	$('a.cool_go').click();
	
	//$('#last_button').click();
	$('#last_task').change();
	
	/*
	$('span.clear_all').eq(0).click(function(){
		$(this).parent().next().find('input').attr('checked','');
	});
	$('span.clear_all').eq(1).click(function(){
		$(this).parent().next().find('input').attr('checked','');
		$(this).parent().next().next().next().find('input').attr('checked','');
	});
	$('span.clear_all').eq(2).click(function(){
		$(this).parent().next().find('input').attr('checked','');
	});
	*/
	
	$('a.other_districts').next().hide();
	$('a.other_districts').click(function(){
		$(this).next().slideToggle(300);
		return false;
	});

		$("#older_pred a").click(function() {
            if ($(this).attr("id")=="show_prod") {
                $(".visible").hide();
                $(".hide").show();
            }else{
                $(".visible").show();
                $(".hide").hide();
            };
			$("#older_pred li").removeClass("select");
			$(this).parent("li").addClass("select");
			return false;
		});
		
	});

function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");
}
	
$(document).ready(function(){
	$(".ajax_podbor").click();
	/*
	$(".subcomm").each(function(){
		//alert($(this).text());
		//alert($('td.center').find('h1').text());
		if(trim($(this).html())==trim($('td.center').find('h1').html())) { $(this).css('font-weight','bold');}
	});
	*/
	if($('input[name="a1"]').val()==1) $(".subcomm").eq(0).css('font-weight','bold');
	if($('input[name="a2"]').val()==2) $(".subcomm").eq(1).css('font-weight','bold');
	if($('input[name="a3"]').val()==3) $(".subcomm").eq(2).css('font-weight','bold');
	if($('input[name="a4"]').val()==4) $(".subcomm").eq(3).css('font-weight','bold');
	
	
	i=1;
	setInterval(function(){
			
			if (i<3)
					  {
						 $('#blue_banner img').fadeOut(100,function(){
							$('#blue_banner img').attr('src','/images/blue_'+i+'.png');
							$('#blue_banner img').fadeIn(500);
						});
						i++;
					  }
					else
					  {
					  i=1;
					  $('#blue_banner img').fadeOut(500,function(){
							$('#blue_banner img').attr('src','/images/blue_'+i+'.png');
							$('#blue_banner img').fadeIn(500);
						});
					  }	
					
			
				
		
		
		
	},4500);
	
	
});