local tubiao = -1
local tb = -1
local fengsu = 0
local index=0

sc_Page0 = 0
sc_Page1 = 1
sc_Page2 = 2
up_down_slid_screen = 0



function on_screen_sliding(screen, control)

    --local left  = -1
    --local right = -1
    --local up    = -1
    --local down  = -1
    --local index = -1

    if screen >= sc_Page1 and  screen <= sc_Page2 then
		if screen == sc_Page1 then
			left  = sc_Page2
			right = sc_Page2
            up    = sc_Page2
            down  = sc_Page2
            --print(1)
        elseif screen == sc_Page2 then
            left  = sc_Page1
			right = sc_Page1
            up    = sc_Page1
            down  = sc_Page1
           -- print(0)
        end
    end
    return left,right,up,down
end

function on_init()
    set_enable(9,3,0)
    set_enable(9,2,0)
    set_enable(6,2,0)
    set_enable(6,11,0)
    set_enable(5,2,0)
    set_enable(5,11,0)
    set_enable(5,12,0)
    set_enable(4,10,0)
    set_visiable(5,2,0)
    set_visiable(5,11,0)
    set_visiable(5,12,0)
    set_visiable(4,11,0)
end

function on_control_notify(screen,control,value)

    if screen == 4 and control == 4 and value == 1 then
        set_value(5,5,1)
        set_value(6,5,1)
        set_value(4,15,1)
        set_value(6,13,1)
        set_enable(6,2,1)
        set_enable(6,11,1)
        set_enable(5,2,1)
       set_enable(5,11,1)
       set_enable(5,12,1)
       set_enable(4,10,1)
       set_visiable(5,2,1)
       set_visiable(5,11,1)
       set_visiable(5,12,1)
       set_visiable(4,11,1)
    elseif screen == 4 and control == 4 and value == 0 then
        set_value(5,5,0)
        set_value(6,5,0)
        set_value(4,15,0)
        set_value(6,13,0)
        set_enable(6,2,0)
        set_enable(6,11,0)
        set_enable(5,2,0)
       set_enable(5,11,0)
       set_enable(5,12,0)
       set_enable(4,10,0)
       set_visiable(5,2,0)
       set_visiable(5,11,0)
       set_visiable(5,12,0)
       set_visiable(4,11,0)
    end

    if screen == 5 and control == 5 and value == 1 then
        set_value(4,4,1)
        set_value(6,5,1)
        set_enable(6,2,1)
        set_enable(6,11,1)
        set_value(4,15,1)
        set_value(6,13,1)
        set_enable(5,2,1)
       set_enable(5,11,1)
       set_enable(5,12,1)
       set_enable(4,10,1)
       set_visiable(5,2,1)
       set_visiable(5,11,1)
       set_visiable(5,12,1)
       set_visiable(4,11,1)
    elseif screen == 5 and control == 5 and value == 0 then
        set_value(4,4,0)
        set_value(6,5,0)
        set_enable(6,2,0)
        set_enable(6,11,0)
        set_value(4,15,0)
        set_value(6,13,0)
        set_enable(5,2,0)
       set_enable(5,11,0)
       set_enable(5,12,0)
       set_enable(4,10,0)
       set_visiable(5,2,0)
       set_visiable(5,11,0)
       set_visiable(5,12,0)
       set_visiable(4,11,0)
    end

    if screen == 6 and control == 5 and value == 1 then
        set_value(4,4,1)
        set_value(5,5,1)
        set_value(6,13,1)
        set_value(4,15,1)
        set_enable(6,2,1)
        set_enable(6,11,1)
        set_enable(5,2,1)
       set_enable(5,11,1)
       set_enable(5,12,1)
       set_enable(4,10,1)
       set_visiable(5,2,1)
       set_visiable(5,11,1)
       set_visiable(5,12,1)
       set_visiable(4,11,1)
    elseif screen == 6 and control == 5 and value == 0 then
        set_value(4,4,0)
        set_value(5,5,0)
        set_value(6,13,0)
        set_value(4,15,0)
        set_enable(6,2,0)
        set_enable(6,11,0)
        set_enable(5,2,0)
       set_enable(5,11,0)
       set_enable(5,12,0)
       set_enable(4,10,0)
       set_visiable(5,2,0)
       set_visiable(5,11,0)
       set_visiable(5,12,0)
       set_visiable(4,11,0)
    end


    if screen == 9 and control == 4 and value == 1 then
        set_value(9,5,1)
        set_enable(9,3,1)
        set_enable(9,2,1)
    elseif screen == 9 and control == 4 and value == 0 then
           set_value(9,5,0)
           set_enable(9,3,0)
           set_enable(9,2,0)
    end


    if screen == 8 then
        if control == 2 and value == 1 then
           start_timer(0,300,0,0)
        end
        if control == 4 and value == 1 then
            start_timer(1,300,0,0)
        end
        if control == 3 and value == 1 then
            stop_timer(0)
            stop_timer(1)
        end
    end
    if screen==3 then
        if control == 5 then
            index=get_value(3,5)
            index = get_value(3,4)
        end
       if  control==3 and value==1  then
            index=index+1
            set_value(3,5,index)
            if index>50 then
                index=50
            end
            if index >= 1 and index <= 15 then
                set_value(3,4,1)
            end
            if index >= 15 and index <= 25 then
                set_value(3,4,2)
            end
            if index >= 25 and index <= 35 then
                set_value(3,4,3)
            end
            if index >= 35 and index <= 50 then
                set_value(3,4,4)
            end
            print(index)
       end
       if control==2 and value==1 then
           index=index-1
           set_value(3,5,index)
           if index<0 then
              index=0
           end
           if index == 0 then
            set_value(3,4,0)
           end
           if index >= 1 and index <= 15 then
            set_value(3,4,1)
        end
        if index >= 15 and index <= 25 then
            set_value(3,4,2)
        end
        if index >= 25 and index <= 35 then
            set_value(3,4,3)
        end
        if index >= 35 and index <= 50 then
            set_value(3,4,4)
        end
           print(index)
       end
       if control == 5 then
            index = get_value(3,5)
            if index==0 then
                set_value(3,4,0)
            end
            if index>=1 and index<=15 then
               set_value(3,4,1)
            end
            if index >= 15 and index <= 25 then
                set_value(3,4,2)
            end
            if index >= 25 and index <= 35 then
                set_valeu(3,4,3)
            end
            if index >= 35 and index <= 50 then
               set_value(3,4,4)
            end
        end

    end 



       if screen == 4 and control == 10 and value == 1 then
            fengsu = get_value(4,11)
            set_value(4,11,fengsu)
            fengsu = fengsu + 1
            set_value(4,11,fengsu)
           -- set_value(3,13,fengsu)
            if fengsu >= 5 then
                set_value(4,11,0)
                --set_value(3,13,0)
            end
        end
end

function on_timer(timer_id)
    if timer_id == 0 then
        tubiao = get_value(8,8)
        tubiao = tubiao + 1
        set_value(8,8,tubiao)
    end
    if tubiao >= 11 then 
        stop_timer(0)
    end
    if timer_id == 1 then
        tb = get_value(8,8)
        tb = tb - 1
        set_value(8,8,tb)
    end
    if tb == 0 then
        stop_timer(1)
    end
end
