const PinyinInitials = [ "b", "c", "ch", "d", "f", "g", "h", "j", "k", "l", "m",
                          "n", "p","q", "r", "s", "sh", "t", "w", "x", "y", "z", "zh"];

const PinyinFinals = ["a","ai", "an", "ang", "ao", "e", "ei", "en", "eng", "er",
                       "i", "ia", "ian", "iang", "iao", "ie", "in", "ing", "io", "ion", "iong",
                       "iou", "iu", "o", "on", "ong", "ou", "u", "ua", "uai", "uan",
                       "uang", "ue", "uei", "uen", "ueng", "ui", "un", "uo", "v", "van",
                       "ve", "vn"];
const PinyinTones = ["ā", "á", "ă", "à", "ō", "ó", "ǒ", "ò", "ū", "ú", "ǔ", "ù", 
                     "ī", "í", "ǐ", "ì", "ē", "é", "ě", "è", "ǖ", "ǘ", "ǚ", "ǜ"]; 


var KeyInput = function() { this.init(); };

KeyInput.prototype = 
{
    pinyinInitials: [],
    pinyinFinals: [],
    pinyinTones: [], 
    init: function()
    {
      for(var i=0; i<PinyinInitials.length; i++)
         this.pinyinInitials[PinyinInitials[i]] = PinyinInitials[i];

       for(var i=0; i<PinyinFinals.length; i++)
         this.pinyinFinals[PinyinFinals[i]] = PinyinFinals[i];

       for(var i=0; i<PinyinTones.length; i++)
         this.pinyinTones[PinyinTones[i]] = PinyinTones[i];
    }
}

var PinyinInput = function()  { };

PinyinInput.prototype = extend(new KeyInput(), 
{
    getAllowedInputKey: function()
    {
       return "abcdefghijklmnopqrstuvwxyzāáăàōóǒòūúǔùīíǐìēéěèǖǘǚǜü";
    },

    validateInputKey: function(inputkey)
    {
       for(var i = inputkey.length -1; i > 0; i--)
       {
          var s = inputkey.substr(i, 1); 
           
          if((typeof(this.pinyinFinals[s]) == 'undefined' && 
             typeof(this.pinyinInitials[s]) == 'undefined' && 
             typeof(this.pinyinTones[s]) == 'undefined') && 
             s != ' ' && s != "'")
          {
             return false; 
          }
       }

       return true; 
    }, 

    parseOneKey: function (keyInitial, keyFinal)
    {
       var keyInitialLen = keyInitial.length;

       if(typeof(this.pinyinFinals[keyFinal]) != 'undefined')
       {
         var pinyinKey = {};
         pinyinKey.key = keyInitial + keyFinal;
         pinyinKey.type = keyInitialLen>0 ? KEY_FULL : KEY_FINAL;
         pinyinKey.pos = keyInitialLen + keyFinal.length;
         return pinyinKey;
       }
       else
       {
          for(var i=keyFinal.length-1; i>0; i--)
          {
             var subFinal = keyFinal.substring(0, i);
             if(typeof(this.pinyinFinals[subFinal]) != 'undefined')
             {
                var pinyinKey = {};
                pinyinKey.key = keyInitial + subFinal;
                pinyinKey.type = keyInitialLen>0 ? KEY_FULL : KEY_FINAL;
                pinyinKey.pos = keyInitialLen + i;
                return pinyinKey;
             }
          }
       }
       // When we reach here, it means the engine might encounter the unsupported input chars. 
       // let move to next but ignore this keyFinal chars 
       keyInitialLen = keyInitialLen>0 ? keyInitialLen : keyFinal.length;
       return ({key: keyInitial, type: KEY_INITIAL, pos: keyInitialLen});
    },

    parseKeys: function(inputchar)
    {
       var keys = new Array();
       // the space is from updateFrequency. Treat them as single quot
       var keyList = inputchar.replace(/\s+/g, "'");

       // if there are single quot delimiters, process them first
       if(keyList.search(/\'/) != null)
       {
           var keyListArray = keyList.split("'");
           var keyListArrayLength = keyListArray.length;
           for(var i=0; i<keyListArrayLength; i++)
           {
              var retArray = this.parseKeySteps(keyListArray[i]);

              if(retArray != null)
                 arrayInsert(keys, keys.length, retArray.slice(0, retArray.length));
           }

           return keys;
        }
        return this.parseKeySteps(keyList);
    },

    parseKeySteps: function(keyList)
    {
       var keys = new Array();

       var keyListLength = keyList.length;

       for(var i=0; i< keyListLength;)
       {
          var key1 = keyList.substr(i, 1);
          var key2 = keyList.substr(i, 2);

          if(typeof(this.pinyinInitials[key2]) != 'undefined')
          {
              var finals = keyList.substr(i+2, 4);
              if(finals.length <= 0)
              {
                    keys.push({key: key2, type: KEY_INITIAL});

                 break;
              }
              var pinyinKey = this.parseOneKey(key2, finals);
              if(pinyinKey.type == KEY_INITIAL)
              {
                 // No finals. Store them each one as Initial
                    keys.push({key: key2, type: KEY_INITIAL});
              }
              else
              {
                 keys.push({key: pinyinKey.key, type: pinyinKey.type});
              }

              i += pinyinKey.pos;
          }
          else if(typeof(this.pinyinInitials[key1]) != 'undefined')
          {
              var finals = keyList.substr(i+1, 4);
              if(finals.length <= 0)
              {
                 keys.push({key: key1, type: KEY_INITIAL});
                 break;
              }
              var pinyinKey = this.parseOneKey(key1, finals);

              keys.push({key: pinyinKey.key, type: pinyinKey.type});
              i += pinyinKey.pos;
          }
          else
          {
              var finals = keyList.substr(i, 4);
              if(finals.length <= 0)
              {
                 // we don't know what kind of key it's              
                 break;
              }
              var pinyinKey = this.parseOneKey("", finals);
              if(pinyinKey.pos <= 0)
              {
                 // some invalid chars, ignore it by increase position by 1
                 i++;
              }
              else
              {
                 keys.push({key: pinyinKey.key, type: KEY_FINAL});
                 i += pinyinKey.pos;
              }
          }
       }
       return keys;
    }
              
}); 

var WubiInput = function() { }; 

WubiInput.prototype = extend(new KeyInput(),
{
    validateInputKey: function(inputkey)
    {
       var allowedkeys = "abcdefghijklmnopqrstuvwxy"; 
       for(i = inputkey.length -1; i > 0; i--)
       {
          var s = inputkey.substr(i, 1);
          if(!allowedkeys.indexOf(s))
              return false; 
       }
       return true;
    },

    parseKeys: function(inputchar)
    {
       if(inputchar.length > 4 || inputchar.length <= 0)
          return null; 
       return inputchar; 
    }
});

var Cangjie5Input = function() { };

Cangjie5Input.prototype = extend(new KeyInput(),
{
    validateInputKey: function(inputkey)
    {
       var allowedkeys = "abcdefghijklmnopqrstuvwxyz"; 
       for(i = inputkey.length -1; i > 0; i--)
       {
          var s = inputkey.substr(i, 1);
          if(!allowedkeys.indexOf(s))
              return false; 
       }
       return true;
    },

    parseKeys: function(inputchar)
    {
       if(inputchar.length > 5 || inputchar.length <= 0)
          return null; 
       return inputchar;
    }
});

function imeChange(sel)
{
    // clear error fist 
    showError("&nbsp");
    if(sel.value != SMART_PINYIN)
    {
      $("#keySuggestion").hide(); 
      $("#keyConfirm").hide(); 
    }

    $("#inputkey").show(); 
    $("#inputword").attr("defvalue", ""); 

    $("#freqData").hide(); 
    $("#addNew").removeAttr("disabled"); 
}
 
function checkkey(inputkey, imetype)
{
    var parser = null; 

    switch(imetype)
    {
       case SMART_PINYIN: 
          parser = new PinyinInput(); 
       break; 
       case WUBI_86: 
       case WUBI_98:
          parser = new WubiInput(); 
       break; 
       case CANGJIE_5:
          parser = new Canjie5Input(); 
       break; 
       default: 
          showError("对不起,不支持此输入法");
          return false; 
    }
   
    if(!parser.validateInputKey(inputkey))
    {
       showError("输入键含有不合法的字母");
       return false; 
    }
 
    var list = parser.parseKeys(inputkey); 
    if(!list)
    {
       errstr = "读入输入键失败"; 
       if(imetype == WUBI_86 || imetype == WUBI_98)
          errstr += ", 五笔输入键最多是四键";

       showError(errstr);
       return false; 
    }
 
    if(typeof(list) == 'string')
       return list; 
   
    var s = "";
    for(var i=0; i<list.length; i++)
    {
       s += list[i].key + " ";
    }
    return s; 
}

function showError(error)
{
    $("#formError").html(error);
}

function goSubmit(step)
{
   $.historyLoad(step);
}

function checkWord()
{
    var inputword = document.tableForm.inputword.value; 
    var imetype = document.tableForm.imetype.value; 
    var inputkey = document.tableForm.hiddeninputkey.value; 
    var keyconfirmvalue = document.tableForm.keyconfirmvalue; 

    // clear error fist 
    showError("&nbsp");
    if(!inputword)
    {
       showError("词组不能是空");
       return false; 
    }

    if(inputword.length < 2)
    {
       showError("词组必须至少两个字");
       return false; 
    }

    if(!inputkey && !keyconfirmvalue)
    {
       showError("输入键不能是空");
       return false; 
    }

    // take keyconfirmvalue #keyConfirm is displayed 
    // other use inputkey as real one 
    result = ($("#keyConfirm").css("display") != "none" && keyconfirmvalue) ? keyconfirmvalue.value : inputkey; 
    if(result === false)
       return false; 

    // check whether username and email are given after keyconfirmvalue is provided 
    if($("#keyConfirm").css("display") != "none" && $("#userInfoData").css("display") != "none")
    {
          var guestname = document.tableForm.realname.value; 
          var email = document.tableForm.email.value; 
          if(guestname.length <= 0 || email.length <= 0)
          {
             showError("你还没有登录, 请提供笔名和邮箱"); 
             return false; 
          }
          addWordServer(inputword, imetype, result, guestname, email);
          return false; 
    }

    // send to server 
    addWordServer(inputword, imetype, result);

    return true; 
}


function addWordServer(inputword, imetype, inputkey, guestname, email)
{
    var params = "inputword="+encodeURIComponent(inputword) + "&inputkey="+encodeURIComponent(inputkey) + "&imetype=" + imetype;
    if(guestname && email)
    {
       params += "&name=" + encodeURIComponent(guestname) + "&email=" + encodeURIComponent(email);
    }

    var url = "/table/addnew.php";
    var ajax = new Ajax();
    ajax.setOptions(
        {
          method: 'post',
          postBody: params,
          contentType: 'application/x-www-form-urlencoded',
          onSuccess: function(p) { addWordServerSuccess(p); },
          onFailure: function(p) { addWordServerFailure(p); }
        });

    ajax.request(url);
}

function addWordServerSuccess(p)
{
    try 
    {
      var jsonMsg = JSON.parse(p.responseText);
      switch(jsonMsg.step)
      {
         case '1': 
           // success 
           var str = "<div style='margin-left: 8px'><span>成功加入.</span>";
           str += "&nbsp;&nbsp;<a href='/table/new.php'>加其他词组?</a></div>";
           $("#tableForm").html(str); 
         break; 
         case '2': 
         case '3': 
            showConfirmForm(jsonMsg); 
         break; 
      }
    }
    catch(e) { showError(e);}

}

function addWordServerFailure(p)
{
    try 
    {
      var jsonMsg = JSON.parse(p.responseText); 
      if(jsonMsg.errCode == 1)
      {
         showError(jsonMsg.errMsg); 
      }
      else if (jsonMsg.errCode == 2)
      {
         // the word exists, show form to update the freq  
//         alert(jsonMsg.errCode); 
         showFreqForm(jsonMsg.key, jsonMsg.keyindex); 
      }
    }
    catch(e) { showError(e); }
}

function showConfirmForm(data)
{
    $("#keySuggestion").hide();
    $("#keyConfirmData").html("");
    $("#freqData").hide(); 
    $("#addNew").removeAttr("disabled"); 
    $("#toggleKeySuggestion").hide(); 

    if(typeof(data.mnumtone) != 'undefined' && typeof(data.nmnumtone) == 'undefined')
    {
      // only match 
      var html = "<table cellspacing=3 cellpadding=3>";
      html += "<tr><td valign='center'><span>" + data.mchartone +
                  "</span></td><td><input value='" + data.mnumtone + "' name='keyconfirmvalue' type='hidden'></td></tr>";
      $("#keyConfirmData").html(html); 
      $("#confirmChoose").html("选择的输入键:"); 
    }
    else if(typeof(data.mnumtone) != 'undefined' && typeof(data.nmnumtone) != 'undefined')
    {

       var charToneKeyList = data.nmchartone.split(",");
       var numToneKeyList =  data.nmnumtone.split(",");
       var html = "<table cellspacing=3 cellpadding=3>";

       html += "<tr><td colspan=2 valign='center'><span><select name='keyconfirmvalue'>";
       for(var i=0; i<charToneKeyList.length; i++)
       {
          if(data.mchartone == charToneKeyList[i])
          {
             html += "<option value='" + numToneKeyList[i] +
                  "' selected>" + charToneKeyList[i] + "</option>";
          }
          else 
             html += "<option value='" + numToneKeyList[i] +
                  "'>" + charToneKeyList[i] + "</option>";

       }
       data += "</select></td></tr>";

       html += "</table>";
       $("#keyConfirmData").html(html);
       $("#confirmChoose").html("请选择正确的键:"); 
     }

     // user information form is displayed 
     if(data.step == 2)
        $("#userInfoData").show(); 
     else 
        $("#userInfoData").hide(); 

     $("#keyConfirm").show();   
     $("#inputkey").hide();   
}

function showKeySuggestion()
{
    var inputword = document.tableForm.inputword.value; 
    var imetype = document.tableForm.imetype.value; 

    // only do key suggestion for pinyin 
    if(imetype != SMART_PINYIN)
       return false; 
 
    if($("#inputword").attr("defvalue") == inputword)
       return; 
 
    if(this.ischecking == true)
       return;

    this.ischecking = true; 

    $("#freqData").hide();
    $("#addNew").removeAttr("disabled"); 
    $("#keyConfirm").hide(); 
    $("#keySuggestion").hide(); 
    $("#inputkey").show(); 
    document.tableForm.inputkey.value = '';

    // reset defvalue to to use new inputword 
    $("#inputword").attr("defvalue", '');

    //keep key suggestion silent 
    if(!inputword || inputword.length < 2)
    {
       this.ischecking = false; 
       return false; 
    }

    // query the key suggestion 
    var url = "/table/getpinyinkey.php";

    var params = "inputword="+encodeURIComponent(inputword);
    var ajax = new Ajax();
    var self = this; 
    ajax.setOptions(
        {
          method: 'post',
          postBody: params,
          contentType: 'application/x-www-form-urlencoded',
          onSuccess: function(p) { addKeySuggestion(p); self.ischecking = false;},
          onFailure: function(p) { $("#inputword").attr("defvalue", ""); self.ischecking = false;},
        });

    ajax.request(url);

}

function checkRadioButton(button)
{
    if(button.getAttribute("ischecked")=="true")
    {
      button.checked = false;
      button.setAttribute("ischecked","false");
    } 
    else
    {
      button.setAttribute("ischecked","true");
    }
}

function keySuggestionClick(button)
{
    var buttons = document.tableForm.keysuggestionvalue; 

    for(var i=0; typeof(buttons.length) != 'undefined' && i<buttons.length; i++)
    {
      if(button != buttons[i] && buttons[i].getAttribute("ischecked") == "true")
      {
         buttons[i].setAttribute("ischecked","false"); 
      }
    }

    checkRadioButton(button); 
    if(button.checked)
      document.tableForm.inputkey.disabled = true; 
    else 
      document.tableForm.inputkey.disabled = false; 
}


function addKeySuggestion(p)
{
    if(p.responseText.length <= 0)
       return; 

    var inputword = document.tableForm.inputword.value; 
    $("#inputword").attr("defvalue", inputword); 
    try {
       var jsonMsg = JSON.parse(p.responseText); 
       var charToneKeyList = jsonMsg.chartone.split(","); 
       var numToneKeyList = jsonMsg.numtone.split(","); 
       var fcharTone = jsonMsg.fchartone; 
       var fnumTone = jsonMsg.fnumtone; 
       if(!fcharTone || !fnumTone)
       {
          fnumTone = numToneKeyList[0]; 
          fcharTone = charToneKeyList[0]; 
       }

       var data = "<table cellspacing=3 cellpadding=3>"; 

       if(charToneKeyList.length > 1)
       {
         data += "<tr><td colspan=2 valign='center'><span><select id='myselect' onchange='keySuggestionChange(this)'>"; 
         for(var i=0; i<charToneKeyList.length; i++)
         {
            data += "<option value='" + numToneKeyList[i] + 
                  "'>" + charToneKeyList[i] + "</option>"; 
         }
         data += "</select></td></tr>";
       }

       data += "</table>"; 
       $("#keySuggestionData").html(data); 
     
       // add suggestion into inputkey textbox 
       document.tableForm.inputkey.value = fcharTone; 
       document.tableForm.hiddeninputkey.value = fnumTone;
       if(charToneKeyList.length > 1)
       {
          $("#toggleKeySuggestion").show(); 
       }
       else 
       {
          $("#toggleKeySuggestion").hide(); 
       }

     }
     catch(e) { }

}

function keySuggestionChange(option)
{
       document.tableForm.inputkey.value = option.options[option.selectedIndex].text;
       document.tableForm.hiddeninputkey.value = option.value; 
}

function showFreqForm(key, keyIndex)
{
     $("#keyConfirm").show();   
     $("#inputkey").hide();   
     $("#keySuggestion").hide();
    
     $("#word_keyindex").attr("value", keyIndex);
     $("#freqData").show(); 
     $("#addNew").attr("disabled", "true"); 
}
    
function increaseWordFreq(order)
{
    var word_keyindex = document.tableForm.word_keyindex.value; 
    var imetype = document.tableForm.imetype.value; 

    // query the key suggestion 
    var url = "/table/updatefreq.php";

    var params = "imetype=" + encodeURIComponent(imetype) + 
                 "&keyindex=" + encodeURIComponent(word_keyindex) + "&order=" + encodeURIComponent(order);
    var ajax = new Ajax();
    var self = this; 
    ajax.setOptions(
        {
          method: 'post',
          postBody: params,
          contentType: 'application/x-www-form-urlencoded',
          onSuccess: function(p) { increaseFreqDone(p);},
          onFailure: function(p) { increaseFreqDone(p);}
        });

    ajax.request(url);
}

function increaseFreqDone (p)
{
    // success 
    var str = "<div style='margin-left: 8px'><span>词频成功调整.</span>";
    str += "&nbsp;&nbsp;<a href='/table/new.php'>加其他词组?</a></div>";
    $("#tableForm").html(str); 
}



function searchWord(pagenum)
{
    var inputword = document.searchForm.inputword.value; 
    var inputkey = document.searchForm.inputkey.value; 
    var imetype = document.searchForm.imetype.value; 

    var sortby = document.searchForm.sortby; 
    for (var i=0; i<sortby.length; i++) 
    {
       if (sortby[i].checked) {
          sortby = sortby[i].value; 
          break; 
       }
    }

    showError("&nbsp;"); 
    if(inputword.length <= 0 && inputkey.length <= 0)
    {
       showError("查找词组和输入键不能都是空");
       return false;
    }

    var result = ""; 
    if(inputkey.length > 0)
    {
       result = checkkey(inputkey, imetype);
       if(result === false)
         return false;
    }

    // query the key suggestion 

    var params = "inputword="+encodeURIComponent(inputword) + "&imetype=" + encodeURIComponent(imetype) + 
                 "&inputkey=" + encodeURIComponent(result) + "&pagenum=" + encodeURIComponent(pagenum) + 
                 "&sortby=" + encodeURIComponent(sortby); 

    var url = "/table/searchtable.php?" + params;
    var ajax = new Ajax();
    var self = this; 
    ajax.setOptions(
        {
          method: 'get',
          contentType: 'application/x-www-form-urlencoded',
          onSuccess: function(p) { searchWordDone(p);},
          onFailure: function(p) { showError(p.responseText); disableButton("searchButton", false);}
        });

    ajax.request(url);

    disableButton("searchButton", true); 
}

function searchWordDone(p)
{
   disableButton("searchButton", false); 
   $("#searchResult").html(p.responseText); 

   $(".freqnumbereditable").editable("/table/updatefreq.php", { 
      indicator : "<img src='/images/loading.gif'>", 
      name      : "freq", 
      type      : "freqnumber",
      submitdata: function () { var sd = {}; 
                                $('input:hidden', this).each(function() { sd[$(this).attr('name')] = $(this).val(); }); 
                                return sd; }, 
      onblur    : "submit",
      tooltip   : "点击调频..."
   });

   $(".inputkeyeditable").editable("/table/updatekey.php", { 
      indicator : "<img src='/images/loading.gif'>", 
      name      : "inputkey", 
      type      : "inputkey",
      loadurl   : "/table/getinputkey.php", 
      loadtext  : "", 
      loaddata  : function() { var ld = {}; 
                               ld['keyindex'] = $(this).attr('keytable_index'); 
                               ld['imetype'] = $(this).attr('imetype'); 
                               return ld; }, 
      submitdata: function () { var sd = {}; 
                                sd['keyindex'] = $(this).attr('keytable_index'); 
                                sd['imetype'] = $(this).attr('imetype'); 
                                return sd; }, 
      onblur    : "submit"
   });
}

function disableButton(button, flag)
{
    var id = document.getElementById(button); 
    if(flag)
    {
      id.setAttribute("oldtype", id.type); 
      id.type = "image"; 
      id.src="/images/loading.gif"; 
      id.disabled = true; 
    }
    else
    {
      id.type = id.hasAttribute("oldtype") ? id.getAttribute("oldtype") : "button"; 
      id.disabled = false; 
    }
}


function showDownloadWord(pagenum)
{
    var limit = document.downloadForm.limit.value; 
    var imetype = document.downloadForm.imetype.value; 
    var bylatest = document.downloadForm.bylatest.checked ? 1:0; 
    var byfreq = document.downloadForm.byfreq.checked ? 1:0; 
    var bylength = document.downloadForm.bylength.checked ? 1:0; 

    showError("&nbsp;"); 

    var params = "imetype=" + encodeURIComponent(imetype) + 
                 "&limit=" + encodeURIComponent(limit) + "&bylatest=" + encodeURIComponent(bylatest) + 
                 "&byfreq=" + encodeURIComponent(byfreq) + "&bylength=" + encodeURIComponent(bylength) + 
                 "&pagenum=" + encodeURIComponent(pagenum);

    var url = "/table/downloadtable.php?" + params;
    var ajax = new Ajax();
    var self = this; 
    ajax.setOptions(
        {
          method: 'get',
          onSuccess: function(p) { downloadWordDone(p);},
          onFailure: function(p) { showError(p.responseText); disableButton("showDownloadButton", false);}
        });

    ajax.request(url);

    disableButton("showDownloadButton", true); 
}

function downloadWordDone(p)
{
   disableButton("showDownloadButton", false);
   $("#downloadResult").html(p.responseText);
}


function saveDownloadWord(pagenum)
{
    var limit = document.downloadForm.limit.value; 
    var imetype = document.downloadForm.imetype.value; 
    var bylatest = document.downloadForm.bylatest.checked ? 1:0; 
    var byfreq = document.downloadForm.byfreq.checked ? 1:0; 
    var bylength = document.downloadForm.bylength.checked ? 1:0; 

    showError("&nbsp;"); 


    var params = "imetype=" + encodeURIComponent(imetype) + 
                 "&limit=" + encodeURIComponent(limit) + "&bylatest=" + encodeURIComponent(bylatest) + 
                 "&byfreq=" + encodeURIComponent(byfreq) + "&bylength=" + encodeURIComponent(bylength) + 
                 "&save=1"; 

    var url = "/table/downloadtable.php?" + params;

    $("#saveDownloadResult").attr("src", url); 
}

function deleteMyHistory(event, tableevent_index)
{
    var url = "/table/deletehistory.php?" + "tindex=" + tableevent_index; 
    var ajax = new Ajax();
    var self = this;
    ajax.setOptions(
        {
          method: 'get',
          onSuccess: function(p) { 
 				   $("#hist_" + tableevent_index).attr("bgcolor", "#eee");
				   $(event.target).html('已删除').attr("onclick", "").css("cursor", "default"); 
		     }, 
          onFailure: function(p) { alert(p.responseText);}
        });

    ajax.request(url);
}


function deleteWord(event, wordtable_index)
{
    var url = "/table/deleteword.php?" + "windex=" + wordtable_index; 
    var ajax = new Ajax();
    var self = this;
    ajax.setOptions(
        {
          method: 'get',
          onSuccess: function(p) { $(event.target).html('词已删除').attr("onclick", "").css("cursor", "default"); }, 
          onFailure: function(p) { alert(p.responseText);}
        });

    ajax.request(url);
}







