//***********************************************************************************//
//Ajax 取得《 訂購方案變化 》的資料 Function;
//***********************************************************************************//
function getVirHost_Change()
{
// i_VirHost_id       虛擬主機 方案 ID;
// i_VirHost_inherit  虛擬主機 類別 ID;
// i_domain_type      虛擬主機網址《購買型態》 ID;

   document.getElementById('S1_Send_Btn').disabled  = true;

   var i_VirHost_id      = document.getElementById('i_VirHost_id').value;
   var i_VirHost_inherit = document.getElementById('i_VirHost_inherit').value;
   var i_domain_type     = document.getElementById('i_domain_type').value;
   var url       = '/w_order/w_order_VirH/ajax_lib/aj_S1_VirHost_Change.php';
   var postStr   = 'i_VirHost_id=' + i_VirHost_id + '&i_VirHost_inherit=' + i_VirHost_inherit + '&i_domain_type=' + i_domain_type + '&parm=' + new Date().getTime();
   var XmlHR_Obj = InitXMLHttpRequestObject();

//   obj.innerHTML = '<font color="#FF0000">Loading..........  Please Wait!!</font>';

   if(XmlHR_Obj)
   {
      XmlHR_Obj.open('POST', url, true);
      XmlHR_Obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      XmlHR_Obj.send(postStr);

      XmlHR_Obj.onreadystatechange = function()
      {
       if(XmlHR_Obj.readyState == 4 && XmlHR_Obj.status == 200) {
          var retren_Val = XmlHR_Obj.responseText.split('|');

          document.getElementById('Show_Domain_Type').innerHTML       = retren_Val[0];  // 虛擬主機網址《購買型態》;
          document.getElementById('Show_Domain_Text').innerHTML       = retren_Val[1];  // 虛擬主機網址 後續變化 內容;
          document.getElementById('Show_Domain_Period').innerHTML     = retren_Val[2];  // 繳費方式 下拉選單;          
          document.getElementById('Show_Fee_Period_Prompt').innerHTML = retren_Val[3];  // 繳費期間 提示詞;
          document.getElementById('Show_Fee_Period_Price').innerHTML  = retren_Val[4];  // 繳費金額;
          document.getElementById('Show_Fee_Domain_Price').innerHTML  = retren_Val[5];  // 網址費用;
          document.getElementById('Show_Fee_Setup_Price').innerHTML   = retren_Val[6];  // 設定費用;
          document.getElementById('Show_Ext1_Title').innerHTML        = retren_Val[7];  // 主機規格 提示詞;
          document.getElementById('Show_Ext1_List').innerHTML         = retren_Val[8];  // 主機規格 條列內容;
          document.getElementById('Show_SofeWare_Title').innerHTML    = retren_Val[9];  // 我要安裝的軟體 提示詞;
          document.getElementById('Show_SofeWare_List').innerHTML     = retren_Val[10]; // 我要安裝的軟體 條列內容;
          document.getElementById('Show_Ext2_Title').innerHTML        = retren_Val[11]; // 我要加購規格 提示詞;
          document.getElementById('Show_Ext2_List').innerHTML         = retren_Val[12]; // 我要加購規格 條列內容;
          document.getElementById('Show_Fee_Ext2_Price').innerHTML    = retren_Val[13]; // 加購小計;                                                                                                              

//###### 總計金額 ######//
          getTotal_Price();

          document.getElementById('S1_Send_Btn').disabled  = false;
          }

      }//End of XmlHR_Obj.onreadystatechange = function();

   }//End of if(XmlHR_Obj);

}//End of function getVirHost_Change();



//***********************************************************************************//
//Ajax 取得《 虛擬主機網址--購買型態變化 》的資料 Function;
//***********************************************************************************//
function getDomain_Type_Change()
{
// i_VirHost_id       虛擬主機 方案 ID;
// i_VirHost_inherit  虛擬主機 類別 ID;
// i_domain_type      虛擬主機網址《購買型態》 ID;

   document.getElementById('S1_Send_Btn').disabled  = true;

   var i_VirHost_id      = document.getElementById('i_VirHost_id').value;
   var i_VirHost_inherit = document.getElementById('i_VirHost_inherit').value;
   var i_domain_type     = document.getElementById('i_domain_type').value;

   var url       = '/w_order/w_order_VirH/ajax_lib/aj_S1_Domain_Type_Change.php';
   var postStr   = 'i_VirHost_id=' + i_VirHost_id + '&i_VirHost_inherit=' + i_VirHost_inherit + '&i_domain_type=' + i_domain_type + '&parm=' + new Date().getTime();
   var XmlHR_Obj = InitXMLHttpRequestObject();

//   obj.innerHTML = '<font color="#FF0000">Loading..........  Please Wait!!</font>';

   if(XmlHR_Obj)
   {
      XmlHR_Obj.open('POST', url, true);
      XmlHR_Obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      XmlHR_Obj.send(postStr);

      XmlHR_Obj.onreadystatechange = function()
      {
       if(XmlHR_Obj.readyState == 4 && XmlHR_Obj.status == 200) {
          var retren_Val = XmlHR_Obj.responseText.split('|');

          document.getElementById('Show_Domain_Button').innerHTML     = retren_Val[0];  // 是否呈現《按鈕》『加購新網址請查詢是否已經註冊』;
          document.getElementById('Show_Domain_Text').innerHTML       = retren_Val[1];  // 虛擬主機網址 後續變化 內容;
          document.getElementById('Show_Domain_Period').innerHTML     = retren_Val[2];  // 繳費方式 下拉選單;
          document.getElementById('Show_Fee_Period_Prompt').innerHTML = retren_Val[3];  // 繳費期間 提示詞;
          document.getElementById('Show_Fee_Period_Price').innerHTML  = retren_Val[4];  // 繳費金額;
          document.getElementById('Show_Fee_Domain_Price').innerHTML  = retren_Val[5];  // 網址費用;
          document.getElementById('Show_Fee_Setup_Price').innerHTML   = retren_Val[6];  // 設定費用;
          document.getElementById('Show_Ext2_Title').innerHTML        = retren_Val[7];  // 我要加購規格 提示詞;
          document.getElementById('Show_Ext2_List').innerHTML         = retren_Val[8];  // 我要加購規格 條列內容;
          document.getElementById('Show_Fee_Ext2_Price').innerHTML    = retren_Val[9];  // 加購小計;

//###### 總計金額 ######//
          getTotal_Price();

          document.getElementById('S1_Send_Btn').disabled  = false;
          }

      }//End of XmlHR_Obj.onreadystatechange = function();

   }//End of if(XmlHR_Obj);

}//End of function getDomain_Type_Change();



//***********************************************************************************//
//Ajax 取得《 網址 》的資料 Function;
//***********************************************************************************//
function getDomain_Change()
{
// i_domain_id  網址 ID;
// i_period_id  繳費期間方式 ID;

   document.getElementById('S1_Send_Btn').disabled  = true;

   var i_domain_id = document.getElementById('i_domain_id').value;
   var i_period_id = document.getElementById('i_period_id').value;

   var obj       = document.getElementById('Show_Fee_Domain_Price');
   var url       = '/w_order/w_order_VirH/ajax_lib/aj_S1_Domain_Change.php';
   var postStr   = 'i_domain_id=' + i_domain_id + '&i_period_id=' + i_period_id + '&parm=' + new Date().getTime();
   var XmlHR_Obj = InitXMLHttpRequestObject();

//   obj.innerHTML = '<font color="#FF0000">Loading..........  Please Wait!!</font>';

   if(XmlHR_Obj)
   {
      XmlHR_Obj.open('POST', url, true);
      XmlHR_Obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      XmlHR_Obj.send(postStr);

      XmlHR_Obj.onreadystatechange = function()
      {
       if(XmlHR_Obj.readyState == 4 && XmlHR_Obj.status == 200) {
          obj.innerHTML = XmlHR_Obj.responseText;

//###### 總計金額 ######//
          getTotal_Price();

          document.getElementById('S1_Send_Btn').disabled  = false;
          }

      }//End of XmlHR_Obj.onreadystatechange = function();

   }//End of if(XmlHR_Obj);

}//End of function getDomain_Change();



//***********************************************************************************//
//Ajax 取得《 虛擬主機網址--繳費方式 》的資料 Function;
//***********************************************************************************//
function getPeriod_Change()
{
// i_VirHost_id       虛擬主機 方案 ID;
// i_VirHost_inherit  虛擬主機 類別 ID;
// i_domain_type      虛擬主機網址《購買型態》 ID;
// i_period_id        繳費期間方式 ID;
// i_domain_id        網址 ID;

   document.getElementById('S1_Send_Btn').disabled  = true;

   var i_VirHost_id      = document.getElementById('i_VirHost_id').value;
   var i_VirHost_inherit = document.getElementById('i_VirHost_inherit').value;
   var i_domain_type     = document.getElementById('i_domain_type').value;
   var i_period_id       = document.getElementById('i_period_id').value;
   var i_domain_id       = document.getElementById('i_domain_id').value;
      
   var url       = '/w_order/w_order_VirH/ajax_lib/aj_S1_Period_Change.php';
   var postStr   = 'i_VirHost_id=' + i_VirHost_id + '&i_VirHost_inherit=' + i_VirHost_inherit + '&i_domain_type=' + i_domain_type + '&i_period_id=' + i_period_id + '&i_domain_id=' + i_domain_id + '&parm=' + new Date().getTime();
   var XmlHR_Obj = InitXMLHttpRequestObject();

//   obj.innerHTML = '<font color="#FF0000">Loading..........  Please Wait!!</font>';

   if(XmlHR_Obj)
   {
      XmlHR_Obj.open('POST', url, true);
      XmlHR_Obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      XmlHR_Obj.send(postStr);

      XmlHR_Obj.onreadystatechange = function()
      {
       if(XmlHR_Obj.readyState == 4 && XmlHR_Obj.status == 200) {
          var retren_Val = XmlHR_Obj.responseText.split('|');

          document.getElementById('Show_Fee_Period_Prompt').innerHTML = retren_Val[0];  // 繳費期間 提示詞;
          document.getElementById('Show_Fee_Period_Price').innerHTML  = retren_Val[1];  // 繳費金額;
          document.getElementById('Show_Fee_Domain_Price').innerHTML  = retren_Val[2];  // 網址費用;
          document.getElementById('Show_Fee_Setup_Price').innerHTML   = retren_Val[3];  // 設定費用;
          document.getElementById('Show_Ext2_Title').innerHTML        = retren_Val[4];  // 我要加購規格 提示詞;
          document.getElementById('Show_Ext2_List').innerHTML         = retren_Val[5];  // 我要加購規格 條列內容;
          document.getElementById('Show_Fee_Ext2_Price').innerHTML    = retren_Val[6];  // 加購小計;

//###### 總計金額 ######//
          getTotal_Price();

          document.getElementById('S1_Send_Btn').disabled  = false;
          }

      }//End of XmlHR_Obj.onreadystatechange = function();

   }//End of if(XmlHR_Obj);

}//End of function getPeriod_Change();



//***********************************************************************************//
//Ajax 取得《加購小計》變化 的資料 Function;
//***********************************************************************************//
function getExt2_Change()
{
// i_Ext2_Val :我要加購規格 ID - 費用;
// i_Ext2[0]  :我要加購規格 ID;
// i_Ext2[1]  :我要加購規格 總費用;
// i_Ext2[2]  :我要加購規格 單價(設定費);

   var i_Ext2_SubTotal = 0;//我要加購規格 總費用;
   var i_Ext2_Tmp      = 0; //我要加購規格 暫存檔;
   var Select_Name     = document.getElementsByTagName("select"); //取出所有的 select 的 id(這樣子IE與FireFox才能共用);

   for(var i = 0 ; i < Select_Name.length ; i++) { 
       if(Select_Name[i].name.substring(0, 4) == 'Ext2') {
          i_Ext2_Tmp = document.getElementById(Select_Name[i].name).value.split('-');
          i_Ext2_SubTotal += parseInt(i_Ext2_Tmp[1]);
          }
       }//End of for(var i = 0 ; i < theForm.elements.length ; i++) { ;

   document.getElementById('Show_Fee_Ext2_Price').innerHTML   = "$<span>" + i_Ext2_SubTotal + "</span><input type=\"hidden\" id=\"i_Fee_Ext2_Price\" name=\"i_Fee_Ext2_Price\" value=\"" + i_Ext2_SubTotal + "\">"; // 加購小計;

//###### 總計金額 ######//
   getTotal_Price();

}//End of function getExt2_Change();



//***********************************************************************************//
//Ajax 取得《 總計金額 》的資料 Function;
//***********************************************************************************//
function getTotal_Price()
{
// i_Fee_Period_Price  期間費用 == 虛擬主機 ;
// i_Fee_Domain_Price  期間費用 == 網址 ;
// i_Fee_Setup_Price   設定費用 == 虛擬主機;
// i_Fee_Ext2_Price    加購費用總計;

   var i_Fee_Period_Price = document.getElementById('i_Fee_Period_Price').value; 
   var i_Fee_Domain_Price = document.getElementById('i_Fee_Domain_Price').value; 
   var i_Fee_Setup_Price  = document.getElementById('i_Fee_Setup_Price').value; 
   var i_Fee_Ext2_Price   = document.getElementById('i_Fee_Ext2_Price').value; 

   var obj       = document.getElementById('Show_Fee_Total_Price');
   var url       = '/w_order/w_order_VirH/ajax_lib/aj_S1_Total_Price.php';
   var postStr   = 'i_Fee_Period_Price=' + i_Fee_Period_Price + '&i_Fee_Domain_Price=' + i_Fee_Domain_Price + '&i_Fee_Setup_Price=' + i_Fee_Setup_Price + '&i_Fee_Ext2_Price=' + i_Fee_Ext2_Price + '&parm=' + new Date().getTime();
   var XmlHR_Obj = InitXMLHttpRequestObject();

//   obj.innerHTML = '<font color="#FF0000">Loading..........  Please Wait!!</font>';

   if(XmlHR_Obj)
   {
      XmlHR_Obj.open('POST', url, true);
      XmlHR_Obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      XmlHR_Obj.send(postStr);

      XmlHR_Obj.onreadystatechange = function()
      {
       if(XmlHR_Obj.readyState == 4 && XmlHR_Obj.status == 200) {
          obj.innerHTML = XmlHR_Obj.responseText;
          }

      }//End of XmlHR_Obj.onreadystatechange = function();

   }//End of if(XmlHR_Obj);

}//End of function getTotal_Price();



//***********************************************************************************//
//Ajax 取得新訂單《網址》是否重複的資料 Function;
//***********************************************************************************//
function Chk_RepDomain(vc_domain, i_domain_type, i_domain_id)
{
   var url       = '/w_order/w_order_VirH/ajax_lib/aj_S1_Chk_RepDomain.php';
   var postStr   = 'vc_domain=' + vc_domain + '&i_domain_type=' + i_domain_type + '&i_domain_id=' + i_domain_id + '&parm=' + new Date().getTime();
   var XmlHR_Obj = InitXMLHttpRequestObject();

//   obj.innerHTML = '<font color="#FF0000">Loading..........  Please Wait!!</font>';

   if(XmlHR_Obj)
   {
      XmlHR_Obj.open('POST', url, true);
      XmlHR_Obj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      XmlHR_Obj.send(postStr);

      XmlHR_Obj.onreadystatechange = function()
      {
       if(XmlHR_Obj.readyState == 4 && XmlHR_Obj.status == 200) {
          var retren_Val = XmlHR_Obj.responseText;

          if(parseInt(retren_Val) > 0) {
             alert("--舊客戶續約請登入會員區進行主機續約\n--新客戶請確認你的網域是否正確，或使用其他網域!!");
             document.getElementById('vc_domain').focus();
             document.getElementById('vc_domain').select();
             }
          else {
             document.getElementById('Send_Msg').style.display  = '';
             document.getElementById('Send_Ctrl').style.display = 'none';
	           document.getElementById('S1_Form').submit();
          	 }
          }
      }//End of XmlHR_Obj.onreadystatechange = function();

   }//End of if(XmlHR_Obj);

}//End of function Chk_RepDomain(vc_domain, i_domain_id);



//***********************************************************************************//
//表單(FORM)送出前檢查 Function;
//***********************************************************************************//
function CheckValue()
{
   if(document.getElementById('vc_domain').value == "" ) {
      alert("請填寫網址!!");
      document.getElementById('vc_domain').focus();
      document.getElementById('vc_domain').select();
      return false;
      } 	

   var Input_Name  = document.getElementsByTagName("input"); // 取出所有的 checkbox 的 id,我要安裝的軟體;(這樣子IE與FireFox才能共用);
   var i_total_st   = 0;                                     // 選定的"我要安裝的軟體"個數;

   for(var i = 0 ; i < Input_Name.length ; i++) { 
       if(Input_Name[i].type == "checkbox") {
          if(Input_Name[i].checked) {
             i_total_st += 1;
             }
          }
       }//End of for(var i = 0 ; i < Input_Name.length ; i++) { ;

   if(parseInt(document.getElementById('i_SoftCount').value) < i_total_st) {
      alert("本方案,可安裝軟體個數為 " + document.getElementById('i_SoftCount').value + " 個!!");
      return false;
      }


   var Ext2_FM_TMP  = '';
   var Select_Name  = document.getElementsByTagName("select"); // 取出所有的 select 的 id(這樣子IE與FireFox才能共用);

   for(var i = 0 ; i < Select_Name.length ; i++) { 
       if(Select_Name[i].name.substring(0, 4) == 'Ext2') {
          Ext2_FM_TMP += document.getElementById(Select_Name[i].name).value + '|';
          }
       }//End of for(var i = 0 ; i < theForm.elements.length ; i++) { ;


   var SF_FM_TMP  = '';
   var Input_Name  = document.getElementsByTagName("input"); // 取出所有的 checkbox 的 id,我要安裝的軟體;(這樣子IE與FireFox才能共用);

   for(var i = 0 ; i < Input_Name.length ; i++) { 
       if(Input_Name[i].type == "checkbox") {
          if(Input_Name[i].checked) {
             SF_FM_TMP += Input_Name[i].name + '|';
             }
          }
       }//End of for(var i = 0 ; i < Input_Name.length ; i++) { ;

   document.S1_Form.i_Fee_Ext2_Price_FM.value  = document.getElementById('i_Fee_Ext2_Price').value;
   document.S1_Form.i_Fee_Total_Price_FM.value = document.getElementById('i_Fee_Total_Price').value;
   document.S1_Form.Ext2_FM.value              = Ext2_FM_TMP;
   document.S1_Form.SF_FM.value                = SF_FM_TMP;


   Chk_RepDomain(document.getElementById('vc_domain').value, document.getElementById('i_domain_type').value, document.getElementById('i_domain_id').value);

}

//***********************************************************************************//
//END
//***********************************************************************************//
