var itemIndex = 3;//默认先给出2个

function saveVote(){
    var unvalid = 0;
    $("#voteform").find("input").each(function(i){
        if($(this).val() == "")
            unvalid++;
    });
    if(unvalid > 0){
        alert("信息不完整: " + unvalid + "个未填项");
        return;
    }
    $("#voteform").submit();
}

function createItem(){
    var html;
    html = "<tr id='insert" + itemIndex + "'><td>选项名称：</td>";
    html += "<td><input type=\"text\" id=\"item" + itemIndex + "\" name=\"item" + itemIndex + "\" />&nbsp;<img src='../img/icons/delete.png' width='16' align='absmiddle' onclick=\"removeItem(\'insert"+itemIndex+"\')\" /> </td></tr>";
    $("#voteTable").append(html);
    itemIndex++;
}

function removeItem(name)
{
    $("#" + name).remove();
}

function calendarSetup(field,format,button){
    Calendar.setup({
        inputField  :   field,
        ifFormat    :   format,
        button      :   button,
        align       :   "bR"
    });
}

function voteupdate(button,voteId) {
    //must select at least one
    var cbx = document.getElementsByName("item");
    var selected = new Array();
    var index = 0;
    for(var i = 0; i < cbx.length; i++){
        if (cbx[i].checked){
            selected[index] = cbx[i].value;
            index++;
        }
    }
    if(index == 0){
        alert("请先点击投票选项");
        return;
    }
    $(button).attr("disabled","true");
    $("#dialog").load("../student/vote.do", {method : "update", id : voteId, item : selected});
    alert("投票成功！");
    votedetail(button,voteId);
}

function votedetail(button,voteId) {
    $(button).attr("disabled","true");
    $("#dialog").load("vote.do", {method: 'detail', id: voteId}, function(){
        $("#dialog").Dialog({
            maskOpacity : "65",
            close: "#dialogClose"
        });
    });
    $(button).removeAttr("disabled");
}
