﻿function setDiv(type, showId, addId) {
    var div_show = document.getElementById(showId);
    var div_add = document.getElementById(addId);
    if (type == "add") {
        div_show.style.display = "none";
        div_add.style.display = "";
    }
    else {
        div_show.style.display = "";
        div_add.style.display = "none";
    }
}

function setDemandDiv(type) {
    if(type == "")
    {
        returnXml = PageMethods.deleteFullFile(document.getElementById("hdn_guid").value, returnFileHtml);
    }
    setDiv(type, "div_show", "div_add");
    document.getElementById("ddl_product").value = 0;
    document.getElementById("ddl_version").length = 0;
    document.getElementById("ddl_subproduct").length = 0;
    document.getElementById("txb_menu").value = "";
    document.getElementById("txb_title").value = "";
    document.getElementById("ddl_priority_level").value = "";
    document.getElementById("txb_notes").value = "";
    document.getElementById("txb_summarize").value = "";
    document.getElementById("txb_propose").value = "";
    document.getElementById("txb_keywords").value = "";
    document.getElementById("txb_finishtime_latest").value = "";
    document.getElementById("hdn_id").value = "";
}

function saveCheck() {
    var strProduct = document.getElementById("ddl_product").value;
    var strTitle = document.getElementById("txb_title").value;
    var strPriority = document.getElementById("ddl_priority_level").value;
    var strFinishtime = document.getElementById("txb_finishtime_latest").value;

    if (strProduct.trim() == "" || strTitle.trim() == "" || strPriority.trim() == "" || strFinishtime.trim() == "") {
        alert("带*的项不能为空!");
        return false;
    }
    var strPriorityNotes =document.getElementById("txb_notes").value;
    if(strPriorityNotes.trim().length >= 256)
    {
        alert("优先备注不能超过256个字！");
        return false;
    }
    
    var strSummarize =document.getElementById("txb_summarize").value;
    if(strSummarize.trim().length >= 1500)
    {
        alert("问题概述不能超过1500个字！");
        return false;
    }
    
    var strPropose =document.getElementById("txb_propose").value;
    if(strPropose.trim().length >= 1500)
    {
        alert("需求建议不能超过1500个字！");
        return false;
    }
    document.getElementById("hdn_finishtime").value = document.getElementById("txb_finishtime_latest").value;
    var div_recover = document.getElementById("div_recover");
    div_recover.style.width = div_recover.parentElement.offsetWidth;
    div_recover.style.height = div_recover.parentElement.offsetHeight;
    div_recover.style.display = "";
    document.getElementById("div_body").style.display = "none";
    return true;
}
function saveTime() {
    document.getElementById("hdn_s_start").value = document.getElementById("txb_s_start").value;
    document.getElementById("hdn_s_end").value = document.getElementById("txb_s_end").value;
}

function deleteValid() {
    var tb = document.getElementById('tc_demand_tp_owner_grv_owner');
    if (tb == null) return false;
    if (!IsChk('tc_demand_tp_owner_grv_owner')) return false;
    if (!confirm('确定要删除所选需求？'))
        return false;
    return true;
}

function IsChk(tbname) {

    var rowsCount = document.getElementById(tbname).rows.length;
    var tb = document.getElementById(tbname);

    for (var i = 0; i < rowsCount; i++) {
        var chk = tb.rows[i].cells[0].children[0];
        if (chk == null || !chk.checked || chk.id == "chk_all") continue;

        return true;
    }

    alert("未选择记录");
    return false;
}

//客户用户登录
function return_validator() {
    var vNum;
    vNum = Math.random();
    vNum = Math.round(vNum * 10000);

    document.getElementById("img_validation_code").setAttribute("src", "../admin/validator.aspx?num=" + vNum);
}

function isValid() {
    var tbxUserName = document.getElementById("txb_userName").getAttribute("Value");
    var tbxPassword = document.getElementById("txb_passWord").getAttribute("Value");

    if (tbxUserName.trim().length == 0 || tbxPassword.trim().length == 0) {
        alert("用户名或密码不能为空!");
        return false;
    }

    return true;

}

function SelectDisplay(img_Hide, img_Show, div, showOrhide) {
    var img_ObjHide = document.getElementById(img_Hide);
    var img_ObjShow = document.getElementById(img_Show);
    var div_Obj = document.getElementById(div);

    if (showOrhide == "show") {
        img_ObjHide.style.display = "";
        img_ObjShow.style.display = "none";
        div_Obj.style.display = "";
    }
    if (showOrhide == "hide") {
        img_ObjHide.style.display = "none";
        img_ObjShow.style.display = "";
        div_Obj.style.display = "none";
    }
}
function BrowserModalDialog(Did) {
    window.showModalDialog('demand_browser.aspx?demandId=' + Did + '&rand=' + Math.random(), window, "status=no;dialogLeft=" + 40 + "px;dialogTop=" + 60 + "px;dialogWidth=" + (screen.width - 120) + "px;dialogHeight=" + (screen.height - 100) + "px;center:yes");
}

function ShowModalDialog(Did) {
    window.showModalDialog('iframe_demand.aspx?demandId=' + Did + '&rand=' + Math.random(), window, "status=no;dialogLeft=" + 40 + "px;dialogTop=" + 60 + "px;dialogWidth=" + (screen.width - 120) + "px;dialogHeight=" + (screen.height - 100) + "px;center:yes");
}

//-----------------------------------------------附件Js部分----------------------------------------------------
//打开文件上传窗口
function openFileLoad()
{
    var demandId = document.getElementById("hdn_guid").value;
    var returnValue;
    returnValue = window.showModalDialog('attachment.aspx?demandId=' + demandId + '&rand=' + Math.random(), window, "status=no;dialogWidth=600px;dialogHeight=320px;center:yes");
    
    returnXml = PageMethods.getUploadFiles(demandId, returnFileHtml);
}
//设置附件临时显示
function returnFileHtml(returnXml)
{   
    var div_file = document.getElementById("div_file");
    div_file.innerHTML = "";
    var arrFiles = returnXml.split(',');
    var strFileHtml = "<table style=\"width:100%; background-color:#aadeca\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">";
    if(returnXml == "")
        return;
    for(var i = 0; i < arrFiles.length; i++)
    {
        strFileHtml += "<tr style=\"height:20px\"><td style=\"width:80%; text-indent:6px; background-color:#ebf7f3;\" align=\"left\">" + arrFiles[i].split('|')[1] + "</td>"
                     + "<td style=\"width:20%; background-color:#ebf7f3;\" align=\"center\"><a href=\"javascript:deleteFile('" + arrFiles[i].split('|')[0] + "');\" style=\"color:red\">删除</a></td></tr>"
    }
    strFileHtml += "</table>";
    div_file.innerHTML = strFileHtml;
}

//删除临时附件
function deleteFile(strFileid)
{
    returnXml = PageMethods.deleteUploadFile(document.getElementById("hdn_guid").value, strFileid, returnFileHtml);
}

//--------------------------attachment.aspx页面-------------------------------
function setAttachmentDiv(type, showId, addId)
{    
    setDiv(type, showId, addId);
    document.getElementById("txb_attachTitle").value = "";
}

function saveAttachCheck() {
    var fileUp = document.getElementById("fu_attachment");
    if (document.getElementById("txb_attachTitle").value.trim() == "") {
        alert("带*的项不能为空!");
        return false;
    }
    
    return true;
}