				  
function equalHeight(group) {
 tallest = 0;
 group.each(function() {
 thisHeight = $(this).height();
 if(thisHeight > tallest) {
 tallest = thisHeight;
 }
 });
 group.height(tallest);
}


function set_compSubCategory(id_category){		
		$("#comp_category option").each(function(){
			if($(this).val()==id_category){
				$(this).attr("selected", "selected");
			}
		});
	}
	
	function set_root_category(id_root_category){		
		$("#root_comp_category option").each(function(){
			if($(this).val()==id_root_category){
				$(this).attr("selected", "selected");
			}
		});
	}
	
	function getCompSubCategory(id_sub){
  	var root_category = $('#root_comp_category').val();
  	var tmpSelect = $('#comp_category'); 
  
  	if(root_category == 0) {
  		tmpSelect.attr('disabled','disabled');
  		tmpSelect.clearSelect(); 
		tmpSelect.hide(); 		
  	} else {
  		$("#loader").show("fast"); 	
  		$.getJSON('/organizacii/',{id_root:root_category},
  			function(data) {   				
  				if(data =='err'){  				
  					tmpSelect.clearSelect();
  					//$("#id_category").hide();
  				} else {
  					tmpSelect.fillSelect(data).attr('disabled',''); 
					if(id_sub!=0){
						set_compSubCategory(id_sub);
					}	
					$("#loader").delay(500).hide("fast"); 
  					tmpSelect.show();
  				}
  			}
  		);
  		
  	}  	
  };
  
  
  
  function set_advtSubCategory(id_category){		
		$("#advt_category option").each(function(){
			if($(this).val()==id_category){
				$(this).attr("selected", "selected");
			}
		});
	}
	
	
	
	function getAdvtSubCategory(id_sub){
  	var root_category = $('#root_advt_category').val();
  	var tmpSelect = $('#advt_category'); 
  
  	if(root_category == 0) {
  		tmpSelect.attr('disabled','disabled');
  		tmpSelect.clearSelect(); 
		tmpSelect.hide(); 		
  	} else {
  		$("#loader").show("fast"); 	
  		$.getJSON('/obyavleniya/',{id_root:root_category},
  			function(data) {   				
  				if(data =='err'){  				
  					tmpSelect.clearSelect();
  					//$("#id_category").hide();
  				} else {
  					tmpSelect.fillSelect(data).attr('disabled',''); 
					if(id_sub!=0){
						set_advtSubCategory(id_sub);
					}	
					$("#loader").delay(500).hide("fast"); 
  					tmpSelect.show();
  				}
  			}
  		);
  		
  	}  	
  };

	/*
	*	���� ��� �������� �����
	*
	*/
	
	var file_index = 	1;	
	var phone_index = 	1;	
	var max_phone_index = 	6;
	var max_index = 	6;
	
	function createFileBlock(index){
		var html_block = '';
		html_block += "<div class=\"file\" id=\"file"+index+"\">";		
		html_block += 	"<input type=\"file\" name=\"image"+index+"\">";
		html_block += 	"<a href=\"#\" class=\"delete_file_block\" id_block=\"file"+index+"\"><img src=\"/img/unchecked.gif\"></a>";
		html_block += "</div>";
		
		return html_block;
							
	}

        function createPhoneBlock(index){
		var html_block = '';
                html_block += '<div id="phone'+index+'" class=\"phone\">';
                html_block += '<div class="f_left m_right10px"><span class="title_form pad_bot6px" style="padding-left:35px;">Код:</span>';
                html_block += '+375 ';
                html_block += ' <input name="phones['+index+'][code]" id="pad_t0" type="text" class="digits text phone_code_input code" value="" />';
                html_block += '</div>';
				// оператор
				html_block += '<div class="f_left m_right10px"><span class="title_form pad_bot6px">Оператор:</span>';             
                html_block += ' <select name="phones['+index+'][operator]" id="pad_t0" type="text" class="text" >';
				html_block += ' 	<option value="none" >--</option>';
				html_block += ' 	<option value="beltelecom" >Белтелеком</option>';
				html_block += ' 	<option value="velcom" >Velcom</option>';
				html_block += ' 	<option value="mts" >MTC</option>';
				html_block += ' 	<option value="life" >Life</option>';
				html_block += ' 	<option value="dialog" >Dialog</option>';
                html_block += ' </select>';
                html_block += '</div>';
				
                html_block += '<div class="f_left">';
                html_block += '<span class="title_form">Телефон:</span>';
                html_block += '<input name="phones['+index+'][phone]" type="text" value="" class="input  phone_number pad_t0" />';
                html_block += '<a href=\"#\" class=\"delete_phone_block\" id_block=\"phone'+index+'\"><img src=\"/img/unchecked.gif\"></a>';
                html_block += '</div>';
                html_block += '<div class="clear"></div>';
                html_block += '</div>';
				
		return html_block;

	}
	
	function reindexFiles(){		
		var total = $(".file").size();
		$(".file").each(function (index, domEle) {
			if(index>0){
				current = (index+1)*1;
				$(this).attr("id", "file"+current);
				$(this).find("input").attr("name", "image"+current);
				$(this).find("a").attr("id_block", "file"+current);						
			}
		});
		file_index = total;	
	}

    function reindexPhones(){
		var total = $(".phone").size();
		$(".phone").each(function (index, domEle) {
			if(index>0){
				current = (index+1)*1;
				$(this).attr("id", "phone"+current);
				$(this).find("input.phone_number").attr("name", "phones["+current+"][phone]");
                $(this).find("input.phone_code_input").attr("name", "phones["+current+"][code]");
                $(this).find("select").attr("name", "phones["+current+"][operator]");
				$(this).find("a").attr("id_block", "phone"+current);
			}
		});
		phone_index = total;
	}
  

 $(document).ready(function(){
	 $('div.jsclick').click(function(){
        $(this).parent().toggleClass('show_razdel')
        return false;
    });
	
	//fancybox
	$("a[zoom='true']").fancybox({
		titleShow:false,
		hideOnContentClick: true,
		speedIn: 600
	});
	
	$("#comment").fancybox({
				'width'				: '40%',
				'height'			: '52%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
	});
	
	$("table[border='1']").addClass("border");
	
	$(".small_img").click(function(){
		$("#preloader_img").show("fast");
		$("a#zoom_href").attr("href", $(this).attr("img_big"));
		$("a#lupa").attr("href", $(this).attr("img_big"));
		$("img#medium_image").attr("src", $(this).attr("href"));
		$("#preloader_img").delay(500).hide("slow");
		return false;
		
		
	});
	
	$("#big_image_div").width($("a#zoom_href").width());
	
	$("#add_btn").click(function(){		
		if(file_index<max_index){
			file_index = (file_index+1)*1;
			var html_block = createFileBlock(file_index);
			$("#files_block").append(html_block);
		} else {
			$(this).attr("disabled", "disabled");
		}	
	});

        $("#add_phone_btn").click(function(){		
		if(phone_index<max_phone_index){
			phone_index = (phone_index+1)*1;
			var html_block = createPhoneBlock(phone_index);
			$("#phone_block").append(html_block);
		} else {
			$(this).attr("disabled", "disabled");
		}
                reindexPhones();
	});
	
	$(".delete_file_block").live('click',function(){
		var id_block = $(this).attr("id_block");
		$("#"+id_block+"").remove();		
		if(file_index>1){
			file_index = (file_index-1)*1;
		}
		if(file_index < max_index){
			$("#add_btn").removeAttr("disabled");

		}
		reindexFiles();
		return false;		
	});

        $(".delete_phone_block").live('click',function(){
		var id_block = $(this).attr("id_block");
		$("#"+id_block+"").remove();
		if(phone_index>1){
			phone_index = (phone_index-1)*1;
		}
		if(phone_index < max_index){
			$("#add_phone_btn").removeAttr("disabled");

		}
		reindexPhones();
		return false;
	});
	
	$(".block_offers:even").addClass("b_o_line");
	
	$("#special_offers").click(function(){
		$(".block_offers").toggle();
		return false;

	});

	// ������������
  
        $('input.cyr_only').keypress(  function(e) {
            if($.browser.msie)
                return isAsci(e.keyCode)
            else
                return (e.keyCode) ? true : isAsci(e.charCode)
        });



})

function isAsci(cCode){
    return /[^a-zA-Z0-9@\.]/.test(String.fromCharCode(cCode))
}   