function buyRegion(
        uint _start_section_index,
        uint _end_section_index,
        uint _image_id,
        string _md5
    ) payable returns (uint start_section_y, uint start_section_x,
    uint end_section_y, uint end_section_x){
        if (_end_section_index < _start_section_index) throw;
        if (_start_section_index >= sections.length) throw;
        if (_end_section_index >= sections.length) throw;
        
        
        var (available, ext_price, ico_amount) = regionAvailable(_start_section_index, _end_section_index);
        if (!available) throw;

        
        uint area_price =  ico_amount * ipo_price;
        area_price = area_price + ext_price;
        AreaPrice(_start_section_index, _end_section_index, area_price);
        SentValue(msg.value);
        if (area_price > msg.value) throw;

        
        
        ico_amount = 0;
        
        
        ext_price = 0;

        
        start_section_x = _start_section_index % 100;
        end_section_x = _end_section_index % 100;
        start_section_y = _start_section_index - (_start_section_index % 100);
        start_section_y = start_section_y / 100;
        end_section_y = _end_section_index - (_end_section_index % 100);
        end_section_y = end_section_y / 100;
        uint x_pos = start_section_x;
        while (x_pos <= end_section_x)
        {
            uint y_pos = start_section_y;
            while (y_pos <= end_section_y)
            {
                
                Section s = sections[x_pos + (y_pos * 100)];
                if (s.initial_purchase_done)
                {
                    
                    
                    
                    if(s.price != 0)
                    {
                        
                        ethBalance[owner] += (s.price / 100);
                        
                        ethBalance[s.owner] += (s.price - (s.price / 100));
                    }
                    
                    
                    ext_price += s.price;
                    
                    balanceOf[s.owner]--;
                    
                    balanceOf[msg.sender]++;
                } else
                {
                    
                    
                    ethBalance[owner] += ipo_price;
                    
                    
                    
                    ico_amount += ipo_price;
                    
                    pool--;
                    
                    balanceOf[msg.sender]++;
                }

                
                
                s.owner = msg.sender;
                s.md5 = _md5;
                s.image_id = _image_id;
                
                s.for_sale = false;
                s.initial_purchase_done = true; 

                Buy(x_pos + (y_pos * 100));
                
                y_pos = y_pos + 1;
            }
            x_pos = x_pos + 1;
        }
        ethBalance[msg.sender] += msg.value - (ext_price + ico_amount);
        return;
    }