﻿//*******************************************************//
//  程式代碼: Customer.js                                //
//  程式名稱: 客戶專區 javascript                        //
//  撰寫日期: 2009.11.27                                 //
//  撰寫人員: Gordon                                     //
//*******************************************************//
//  修改日期:                                            //
//  修改人員:                                            //
//*******************************************************//

/// <reference path="Common.js" />

/******************** cs_custm_view.aspx *********************/

/********************
    初始化網頁&查詢
*********************/
var cs_custm_view01 = {
     "xslFile": "../xslt/cs_custm_view.xslt"
    ,"xslFile2": "../xslt/cs_custm_view2.xslt"
    ,"InitialPage" : function(){
        cs_custm_view.InitialPage(cs_custm_view01.InitialPage_Progress);
    }
    ,"EditPage" : function(){
        cs_custm_view.InitialPage(cs_custm_view01.InitialPage_Progress2);
    }
    ,"SetPWD" : function(pwd){
        cs_custm_view.SetPWD(pwd,cs_custm_view01.SetPWD_Progress);
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, cs_custm_view01.xslFile, "DivOutput", "cs_custm_view01.InitialPage_Progress");
        scroll(0,0);
    }
    ,"InitialPage_Progress2": function(response) {
        CreateHTML(response.value, cs_custm_view01.xslFile2, "DivOutput", "cs_custm_view01.InitialPage_Progress2");
        scroll(0,0);
    }
    ,"SetPWD_Progress": function(response) {        
        if(response.value == "false")
        {
            scroll(0,0);
            alert("更新密碼失敗");
        }
        else
        {
            cs_custm_view01.InitialPage();
        }
    }
}

/******************** cs_custm_invd_list.aspx *********************/

/********************
    初始化網頁&查詢
*********************/
var cs_custm_invd_list01 = {
     "xslFile": "../xslt/cs_custm_invd_list.xslt"
    ,"InitialPage" : function(){
        cs_custm_invd_list.InitialPage(cs_custm_invd_list01.InitialPage_Progress);
    }
    ,"DeleteData" : function(){
        if(!confirm("是否確定刪除？"))
        {
            return;
        }
        
        var CSInvIDList="";
        
        var objchkData = document.getElementsByName("chkData");
        for(i = 0;i<objchkData.length;i++)
        {
            if(objchkData[i].checked)
            {
                //alert(objchkData[i].value);
                CSInvIDList = CSInvIDList + objchkData[i].value + ",";
            }
        }
        
        if(CSInvIDList !="")
        {
            cs_custm_invd_list.DeleteData(CSInvIDList,cs_custm_invd_list01.DeleteData_Progress);
        }
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, cs_custm_invd_list01.xslFile, "DivOutput", "cs_custm_invd_list01.InitialPage_Progress");
    }
    ,"DeleteData_Progress": function(response) {
        if(response.value == "")
        {
            location.href("../Sys07_Customer/cs_custm_invd_list.aspx");
        }
        else
        {
            alert(response.value);
        }
    }
}

/******************** cs_custm_invd_mod.aspx *********************/

/********************
    初始化網頁&查詢
*********************/
var cs_custm_invd_mod01 = {
     "xslFile": "../xslt/cs_custm_invd_mod.xslt"
    ,"InitialPage" : function(CSInvID){
        cs_custm_invd_mod.InitialPage(CSInvID,cs_custm_invd_mod01.InitialPage_Progress);
    }
    ,"SaveData" : function(CSInvID,sType){
        if(cs_custm_invd_modCheck01(sType))
        {
            var sCSInvTitle = document.getElementById("txtCSInvTitle").value;
            var sCSInvUNO = document.getElementById("txtCSInvUNO").value;
            
            var objrdCSInvType = document.getElementsByName("rdCSInvType");
            var sCSInvType ="";
            for(i = 0;i<objrdCSInvType.length;i++)
            {
                if(objrdCSInvType[i].checked)
                {
                    sCSInvType = objrdCSInvType[i].value;
                }
            }
            
            var objrdCSInvDef = document.getElementsByName("rdCSInvDef");
            var sCSInvDef ="";
            for(i = 0;i<objrdCSInvDef.length;i++)
            {
                if(objrdCSInvDef[i].checked)
                {
                    sCSInvDef = objrdCSInvDef[i].value;
                }
            }

            var sCSInvAddr = document.getElementById("txtCSInvAddr").value;
            
            cs_custm_invd_mod.SaveData(CSInvID,sCSInvTitle,sCSInvUNO,sCSInvType,sCSInvDef,sCSInvAddr,cs_custm_invd_mod01.SaveData_Progress);
        }
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, cs_custm_invd_mod01.xslFile, "DivOutput", "cs_custm_invd_mod01.InitialPage_Progress");
    }
    ,"SaveData_Progress": function(response) {
        if(response.value == "")
        {
            location.href("../Sys07_Customer/cs_custm_invd_list.aspx");
        }
        else
        {
            alert(response.value);
        }
    }
}

function cs_custm_invd_modCheck01(sType)
{
    var sErrMsg="";
    
    //發票抬頭
    if(FunCheck_ISNULL("txtCSInvTitle"))
    {
        FunAlertAndFocus("發票抬頭不可為空白","txtCSInvTitle");
        return false;
    }

    sErrMsg = FunisIllegalStrByObject("txtCSInvTitle");
    if(sErrMsg !="")
    {
        FunAlertAndFocus("發票抬頭 " + sErrMsg,"txtCSInvTitle");
        return false;
    }
        
    if(sType == "2")
    {
        //統一編號
        if(FunCheck_ISNULL("txtCSInvUNO"))
        {
            FunAlertAndFocus("統一編號不可為空白","txtCSInvUNO");
            return false;
        }
        
        sErrMsg = FunisIllegalStrByObject("txtCSInvUNO");
        if(sErrMsg !="")
        {
            FunAlertAndFocus("統一編號 " + sErrMsg,"txtCSInvUNO");
            return false;
        }
        
        if(!FunCheckLenByObject("txtCSInvUNO",8))
        {
            FunAlertAndFocus("請正確填寫「統一編號」！","txtCSInvUNO");
            return false;
        }
    }
    else
    {
        //身分證字號
        if(FunCheck_ISNULL("txtCSInvUNO"))
        {
            FunAlertAndFocus("身分證字號不可為空白","txtCSInvUNO");
            return false;
        }
        
        sErrMsg = FunisIllegalStrByObject("txtCSInvUNO");
        if(sErrMsg !="")
        {
            FunAlertAndFocus("身分證字號 " + sErrMsg,"txtCSInvUNO");
            return false;
        }
        
        if(!FunCheckLenByObject("txtCSInvUNO",10))
        {
            FunAlertAndFocus("請正確填寫「身分證字號」！","txtCSInvUNO");
            return false;
        }
    }
    
    //發票地址
    sErrMsg = FunisIllegalStrByObject("txtCSInvAddr");
    if(sErrMsg !="")
    {
        FunAlertAndFocus("發票地址 " + sErrMsg,"txtCSInvAddr");
        return false;
    }
    
    return true;
}

/******************** cs_custm_invd.aspx *********************/

/********************
    初始化網頁&查詢
*********************/
var cs_custm_invd01 = {
     "xslFile": "../xslt/cs_custm_invd.xslt"
    ,"InitialPage" : function(){
        cs_custm_invd.InitialPage(cs_custm_invd01.InitialPage_Progress);
    }
    ,"SaveData" : function(mgsu_rfnbr2,sType){
        if(cs_custm_invd_modCheck01(sType))
        {
            var sCSInvTitle = document.getElementById("txtCSInvTitle").value;
            var sCSInvUNO = document.getElementById("txtCSInvUNO").value;
            
            var objrdCSInvType = document.getElementsByName("rdCSInvType");
            var sCSInvType ="";
            for(i = 0;i<objrdCSInvType.length;i++)
            {
                if(objrdCSInvType[i].checked)
                {
                    sCSInvType = objrdCSInvType[i].value;
                }
            }
            
            var objrdCSInvDef = document.getElementsByName("rdCSInvDef");
            var sCSInvDef ="";
            for(i = 0;i<objrdCSInvDef.length;i++)
            {
                if(objrdCSInvDef[i].checked)
                {
                    sCSInvDef = objrdCSInvDef[i].value;
                }
            }

            var sCSInvAddr = document.getElementById("txtCSInvAddr").value;
            
            cs_custm_invd.SaveData(mgsu_rfnbr2,sCSInvTitle,sCSInvUNO,sCSInvType,sCSInvDef,sCSInvAddr,cs_custm_invd01.SaveData_Progress);
        }
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, cs_custm_invd01.xslFile, "DivOutput", "cs_custm_invd01.InitialPage_Progress");
    }
    ,"SaveData_Progress": function(response) {
        if(response.value == "")
        {
            location.href("../Sys07_Customer/cs_custm_invd_list.aspx");
        }
        else
        {
            alert(response.value);
        }
    }
}

/******************** vt_VetCustmMT_Edit.aspx *********************/

/********************
    初始化網頁
*********************/
var vt_VetCustmMT_Edit01 = {
     "xslFile": "../xslt/vt_VetCustmMT_Edit.xslt"
    ,"InitialPage" : function(){
        vt_VetCustmMT_Edit.InitialPage(vt_VetCustmMT_Edit01.InitialPage_Progress);
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, vt_VetCustmMT_Edit01.xslFile, "DivOutput", "vt_VetCustmMT_Edit01.InitialPage_Progress");
    }
}

/******************** vt_VetCustm05_Edit.aspx *********************/

/********************
    初始化網頁
*********************/
var vt_VetCustm05_Edit01 = {
     "xslFile": "../xslt/vt_VetCustm05_Edit.xslt"
    ,"InitialPage" : function(){
        vt_VetCustm05_Edit.InitialPage(vt_VetCustm05_Edit01.InitialPage_Progress);
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, vt_VetCustm05_Edit01.xslFile, "DivOutput", "vt_VetCustm05_Edit01.InitialPage_Progress");
    }
}

/******************** vt_CustmHist.aspx *********************/

/********************
    初始化網頁
*********************/
var vt_CustmHist01 = {
     "xslFile": "../xslt/vt_CustmHist.xslt"
    ,"InitialPage" : function(){
        vt_CustmHist.InitialPage(vt_CustmHist01.InitialPage_Progress);
    }
    ,"InitialPage_Progress": function(response) {
        CreateHTML(response.value, vt_CustmHist01.xslFile, "DivOutput", "vt_CustmHist01.InitialPage_Progress");
    }
}
