;-=-=-=-=-=-
; DeadLy Script - TAGLISH
;-=-=-=-=-=-
dialog taglish {
  title Tag-Lish Dictionary - $sc
  icon $icons(online)
  size -1 -1 400 220
  box "", 1, 10 1 260 190
  text Select Server, 2, 283 55 100 14
  text Word: , 3, 285 8 110 14
  edit "", 101, 20 15 240 170, multi read vsbar
  edit "", 102, 280 21 110 20, autohs
  combo 201, 280 70 110 100, drop 
  button define, 401, 300 120 70 18, default
  button stop, 402, 300 140 70 18
  button reset, 405, 300 160 70 18
  button english dictionary, 403, 210 200 100 18, cancel 
  button exit, 404, 320 200 70 18, cancel 
}
on 1:DIALOG:taglish:*:*: {
  if $devent = init { 
    did -a taglish 201 Tagalog -> English 
    did -a taglish 201 English -> Tagalog
    did -c taglish 201 1 | did -f taglish 102
    hadd -m events server.taglish $did(taglish,201)
  }
  if $devent = sclick { 
    if $did = 201 { hadd -m events server.taglish $did(taglish,201) }
    if $did = 401 { xlate $$did(102) | did -b taglish 102,201,401 | did -ra taglish 101 Connecting . . . | did -f taglish 401 }
    if $did = 402 { sockclose -n xlate | tagena  | did -r taglish 101 }
    if $did = 403 { sf3 }
    if $did = 405 { did -r taglish 101,102 | tagena }
  }
  if $devent = close { .remove xlate.txt | unloads taglish }
  if $devent = edit { hadd -m events dic $did(102) }
}

alias tagena did -e taglish 102,201,401
alias xlate {
  sockclose xlate 
  if ($hget(events,server.taglish) = Tagalog -> English) sockopen xlate www.tagalog-dictionary.com 80
  if ($hget(events,server.taglish) = English -> Tagalog) sockopen xlate www.foreignword.com 80
}
on 1:SOCKOPEN:xlate: { 
  if ($sockerr != 0) && ($dialog(taglish) != $null) { tagena | did -r taglish 101 | did -a taglish 101 $sock($sockname).wsmsg . . . Can't open sockets, try again later . . . | return } 
  if ($hget(events,server.taglish) = Tagalog -> English) sockwrite -tn $sockname GET http://www.tagalog-dictionary.com/cgi-bin/search.pl?s= $+ $hget(events,dic)
  if ($hget(events,server.taglish) = English -> Tagalog) sockwrite -tn $sockname GET http://www.foreignword.com/cgi-bin/engtag.cgi?language=engtag&termbox= $+ $hget(events,dic)
}
on 1:SOCKREAD:xlate: { 
  sockread -n %wor 
  if ($hget(events,server.taglish) = Tagalog -> English) {
    if (*<!-- Google AdSense -->* iswm %wor) { set %ok off }
    if (%ok = on) { 
      set %row $remove(%wor,<p>,<b>,<hr>,<font color=#846D31>,<em>,</b>,</em>,<font color='#990033'>,</p>,</font>,<font color=green>,<i>,</i>)
      if (*interj.* $+ $hget(events,dic) $+ * !iswm %wor) { inc %k 1 | did -a taglish 101 $gettok($replace(%row,<br>,$crlf,$nbsp;,$chr(32)),1,60)  }
    }
    if (*<!-- InstanceBeginEditable name="mycodehere" -->* iswm %wor) { set %ok on | did -r taglish 101 }
  }

  if ($hget(events,server.taglish) = English -> Tagalog) { 
    if (*<tr>*<td width="45%">*<font*>*</font>* iswm %wor) did -r taglish 101 
    if (*<p>*<b>*</b>* iswm %wor) {
      did -a taglish 101 $replace($remove(%wor,<tr>,<td width="45%">,<font color="#0000A0"face="Verdana" size="2">,&nbsp;,</font>,</td>,<font face="Verdana" size="2">,<b>,</b>,</tr>),<td width="55%">,$crlf,<p>,$crlf)
    }
    if (*was not found in the dictionary* iswm %wor) { did -ra taglish 101 Word was not found in the dictionary }
  }
  if (%wor = </html>) { tagena | unset %k %row %wor %ok }
}
on *:EXIT: unloads taglish
on *:LOAD: dialog $iif($dialog(taglish),-v,-m) taglish taglish | s.open
;-=-=-=-=-=-
;-=-=-=-=-=-
