//***********************************************************************************//
//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_domain_type     = document.getElementById('i_domain_type').value;

   var url       = '/w_products/w_eshop/w_order/ajax_lib/aj_S1_Domain_Type_Change.php';
   var postStr   = 'i_VirHost_id=' + i_VirHost_id + '&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];  // 網址費用;

//###### 總計金額 ######//
          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_products/w_eshop/w_order/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_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_products/w_eshop/w_order/ajax_lib/aj_S1_Period_Change.php';
   var postStr   = 'i_VirHost_id=' + i_VirHost_id + '&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];  // 網址費用;

//###### 總計金額 ######//
          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 getTotal_Price()
{
// i_Fee_Period_Price  期間費用 == 虛擬主機 ;
// i_Fee_Domain_Price  期間費用 == 網址 ;
// i_Fee_Setup_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 obj       = document.getElementById('Show_Fee_Total_Price');
   var url       = '/w_products/w_eshop/w_order/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 + '&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_products/w_eshop/w_order/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;
      } 	


   document.S1_Form.i_Fee_Total_Price_FM.value = document.getElementById('i_Fee_Total_Price').value;

   Chk_RepDomain(document.getElementById('vc_domain').value, document.getElementById('i_domain_type').value, document.getElementById('i_domain_id').value);

}

//***********************************************************************************//
//END
//***********************************************************************************//