alias ajoin { dialog -m ajoin ajoin }
dialog ajoin {
  title "Авто-Join"
  size 460 300 251 237
  option pixels
  icon $mircdirBECT.ico, 0
  button "OK", 1, 15 116 45 25, flat
  combo 2, 81 24 100 120
  radio "Вкл.", 3, 85 153 40 9, flat
  radio "Выкл.", 4, 135 150 40 15, flat
  button "Доб.", 5, 15 26 45 25, flat
  button "Удaл.", 6, 15 56 45 25, flat
  button "Очист.", 7, 15 86 45 25, flat
  icon 8, 10 185 230 32, icons\ajoin.ico, 0
  box "Aвто-Join", 9, 6 6 238 223
  box "", 10, 11 16 59 131
  box "", 11, 75 14 116 133
  box "", 12, 74 141 118 30
}

on 1:dialog:ajoin:sclick:*: {
  if ( $did = 3 ) { set %autojoin ON }
  if ( $did = 4 ) { set %autojoin OFF }
  if ( $did = 5 ) { 
    did -r ajoin 2
    set %channelsjoin $addtok(%channelsjoin,%channel.temp,44) 
    set %temp.count 0
    if ( %channelsjoin != $null ) { 
      set %temp.real $count(%channelsjoin,$chr(44)) + 1
      :ok
      inc %temp.count
      did -a ajoin 2 $gettok(%channelsjoin,%temp.count,44)
      if ( %temp.count = %temp.real ) { halt }
      goto ok
    }
  }
  if ( $did = 6 ) { 
    set %channelsjoin $remtok(%channelsjoin,%channel.temp,44)
    did -r ajoin 2
    set %temp.count 0
    if ( %channelsjoin != $null ) { 
      set %temp.real $count(%channelsjoin,$chr(44)) + 1
      :ok
      inc %temp.count
      did -a ajoin 2 $gettok(%channelsjoin,%temp.count,44)
      if ( %temp.count = %temp.real ) { halt }
      goto ok
    }
  }
  if ( $did = 7 ) { unset %channelsjoin | did -r ajoin 2 }
  if ( $did = 2 ) { set %channel.temp $did(2).text }
}
on 1:dialog:ajoin:init:0: {
  if ( %autojoin = ON ) { did -c ajoin 3 }
  else { did -c ajoin 4 }
  set %temp.count 0
  if ( %channelsjoin != $null ) {   
    set %temp.real $count(%channelsjoin,$chr(44)) + 1
    :ok
    inc %temp.count
    did -a ajoin 2 $gettok(%channelsjoin,%temp.count,44)
    if ( %temp.count = %temp.real ) { halt }
    goto ok
  }
}
on 1:dialog:ajoin:edit:*: {
  if ( $did = 2 ) { 
    if ( $left($did(2).text,1) != $chr(35) ) { error3 }
    else { set %channel.temp $did(2).text }
  }
}
dialog error3 {
  title "Error"
  size -1 -1 150 96
  option pixels
  button "OK", 1, 50 59 40 20, flat cancel
  text "Поставьте # вначале", 2, 15 17 110 19
  box "", 3, 7 5 127 82
}

alias error3 { dialog -m error3 error3 }
on 1:dialog:error3:sclick:1: {
  did -r ajoin 2
  set %temp.count 0
  if ( %channelsjoin != $null ) { set %temp.real $count(%channelsjoin,$chr(44)) + 1
    :ok
    inc %temp.count
    did -a ajoin 2 $gettok(%channelsjoin,%temp.count,44)
    if ( %temp.count = %temp.real ) { did -f ajoin 2 | halt }
    goto ok
  }
}

on *:start: {
  if (%allowautoconnect = on) {
    /server %connserv
  } | else { /halt }
}
