﻿// JScript File
    function setPromoter()
    {
      var href = String(window.location.href);
      var uid = "";
      if (href.indexOf("3d&UID=") != -1) {
        uid = href.substr(href.indexOf("3d&UID=")).substr(8);
      }
      else {
        if (href.indexOf("UID=") != -1)
          uid = href.substr(href.indexOf("UID=")).substr(4);
      }
      document.getElementById("hrefPromoter").setAttribute("href","Promoter.aspx?UID=" + uid);
      document.getElementById("hrefPromoter").appendChild(document.createTextNode(uid));
      var hrefs,h,th;
      hrefs = document.getElementsByTagName('a');
      for(var h = 0; h < hrefs.length; h++)
      {
        for(var x = 0; x < hrefs[h].attributes.length; x++ )
        {
          if (hrefs[h].attributes[x].nodeName.toLowerCase() == 'href')
          {
            th = hrefs[h].attributes[x].nodeValue;
            if (th.indexOf("javascript") == -1)
            {
              if(th.indexOf("UID") == -1)
              {
                if (th.indexOf("&") != -1)
                {
                  th = th + "&UID=" + uid;
                }
                else {
                  if (th.indexOf("?") != -1) {
                    th = th + "&UID=" + uid;
                  }
                  else {
                    th = th + "?UID=" + uid;
                  }
                }
                hrefs[h].attributes[x].nodeValue = th;
              }
            }
          }
        }
      }
      return false;
    }
    function search() {
      var href = String(window.location.href);
      var uid = "";
      if (href.indexOf("UID") != -1) {
        uid = href.substr(href.indexOf("UID")).substr(4);
      }
      var pSTR = document.getElementById("qp").value;
      var crSTR = document.getElementById("qcr").value;
      if (crSTR == "Search for Car-Reg...")
        crSTR = "";
      if (pSTR == "Search for Retailer...")
        pSTR = "";
      if ((crSTR != "") || (pSTR != "")) {
        window.navigate("./Search.aspx?crSTR=" + crSTR + "&pSTR=" + pSTR + "&cStr=&UID=" + uid);
      }
      return false;
    }
    function searchCheck() {
      var pSTR = document.getElementById("qp").value;
      var crSTR = document.getElementById("qcr").value;
      if (crSTR == "Search for Car-Reg...")
        crSTR = "";
      if (pSTR == "Search for Retailer...")
        pSTR = "";
      if ((crSTR != "") || (pSTR != "")) {
        window.navigate("./Search.aspx?crSTR=" + crSTR + "&pSTR=" + pSTR + "&cStr=&UID=" + uid);
      }
    }
    function searchPromo()
    {
      var href = String(window.location.href);
      var uid = href.substr(href.indexOf("UID")).substr(4);
      var pSTR = document.getElementById("qp").value;
      var crSTR = document.getElementById("qcr").value;
      if (crSTR == "Search for Car-Reg...")
        crSTR = "";
      if (pSTR == "Search for Retailer...")
        pSTR = "";
      window.navigate("../Search.aspx?crSTR=" + crSTR + "&pSTR=" + pSTR + "&cStr=&UID=" + uid);
      return false;
    }
    function catsearch(cSTR)
    {
      var href = String(window.location.href);
      var uid = href.substr(href.indexOf("UID")).substr(4);
      window.navigate("Search.aspx?crSTR=&pSTR=&cSTR=" + cSTR + "&UID=" + uid);
      return false;
    }
    function noenter() 
    {
      return !(window.event && window.event.keyCode == 13); 
    }
  function setPromoterPromo() {
      var href = String(window.location.href);
      var uid = "";
      if (href.indexOf("UID") != -1)
        uid = href.substr(href.indexOf("UID")).substr(4);
      document.getElementById("hrefPromoter").setAttribute("href", hrefPathStandard + "/./Promoter.aspx?UID=" + uid);
      document.getElementById("hrefPromoter").appendChild(document.createTextNode(uid));
      var hrefs, h, th;
      hrefs = document.getElementsByTagName('a');
      for (var h = 0; h < hrefs.length; h++) {
        for (var x = 0; x < hrefs[h].attributes.length; x++) {
          if (hrefs[h].attributes[x].nodeName.toLowerCase() == 'href') {
            th = hrefs[h].attributes[x].nodeValue;
            if (th.indexOf("javascript") == -1) {
              if (th.indexOf("UID") == -1) {
                if (th.indexOf("&") != -1) {
                  th = th + "&UID=" + uid;
                }
                else {
                  if (th.indexOf("?") != -1) {
                    th = th + "&UID=" + uid;
                  }
                  else {
                    th = th + "?UID=" + uid;
                  }
                }
                hrefs[h].attributes[x].nodeValue = th;
              }
            }
          }
        }
      }
      return false;
    }


    function recalculate()
    {
      if (validateInt("icarins") &&
          validateInt("ihomeins") &&
          validateInt("ipetins") &&
          validateInt("icarbreak") &&
          validateInt("itravins") &&
          validateInt("imobcon") &&
          validateInt("ienergy") &&
          validateInt("idiy") &&
          validateInt("ijewel") &&
          validateInt("isport") &&
          validateInt("iclothes") &&
          validateInt("icd") &&
          validateInt("idvd") &&
          validateInt("itoilet") &&
          validateInt("ifamday") &&
          validateInt("ihol") &&
          validateInt("ibreak"))
      {
        document.getElementById("itotal").value = r2((parseInt(document.getElementById("icarins").value) * 17.5) 
                                                   + (parseInt(document.getElementById("ihomeins").value) * 17.5)
                                                   + (parseInt(document.getElementById("ipetins").value) * 12.5)
                                                   + (parseInt(document.getElementById("icarbreak").value) * 21.25)
                                                   + (parseInt(document.getElementById("itravins").value) * 12.0)
                                                   + (parseInt(document.getElementById("imobcon").value) * 36.5)
                                                   + (parseInt(document.getElementById("ienergy").value) * 50.0)
                                                   + (parseInt(document.getElementById("idiy").value) * 0.025)
                                                   + (parseInt(document.getElementById("ijewel").value) * 0.09)
                                                   + (parseInt(document.getElementById("isport").value) * 0.045)
                                                   + (parseInt(document.getElementById("iclothes").value) * 0.0375)
                                                   + (parseInt(document.getElementById("icd").value) * 0.0375)
                                                   + (parseInt(document.getElementById("idvd").value) * 0.0375)
                                                   + (parseInt(document.getElementById("itoilet").value) * 0.0375)
                                                   + (parseInt(document.getElementById("ifamday").value) * 0.0375)
                                                   + (parseInt(document.getElementById("ihol").value) * 0.0225)
                                                   + (parseInt(document.getElementById("ibreak").value) * 0.03));
        document.getElementById("ifacebookComm1").value = r2((parseInt(document.getElementById("ifacebook1").value) *
                                                              parseInt(document.getElementById("itotal").value) *
                                                              0.10 *
                                                              0.5));
        document.getElementById("ifacebookComm2").value = r2((parseInt(document.getElementById("ifacebook1").value) *
                                                              parseInt(document.getElementById("ifacebook2").value) *
                                                              parseInt(document.getElementById("itotal").value) *
                                                              0.05 *
                                                              0.25));
        document.getElementById("itotalFinal").value = r2(parseInt(document.getElementById("ifacebookComm1").value) +
                                                          parseInt(document.getElementById("ifacebookComm2").value) +
                                                          parseInt(document.getElementById("itotal").value));
        document.getElementById("icarinscom").value = r2((parseInt(document.getElementById("icarins").value) * 17.5));
        document.getElementById("ihomeinscom").value = r2((parseInt(document.getElementById("ihomeins").value) * 17.5));
        document.getElementById("ipetinscom").value = r2((parseInt(document.getElementById("ipetins").value) * 12.5));
        document.getElementById("icarbreakcom").value = r2((parseInt(document.getElementById("icarbreak").value) * 21.25));
        document.getElementById("itravinscom").value = r2((parseInt(document.getElementById("itravins").value) * 12.0));
        document.getElementById("imobconcom").value = r2((parseInt(document.getElementById("imobcon").value) * 36.5));
        document.getElementById("ienergycom").value = r2((parseInt(document.getElementById("ienergy").value) * 50.0));
        document.getElementById("idiycom").value = r2((parseInt(document.getElementById("idiy").value) * 0.025));
        document.getElementById("ijewelcom").value = r2((parseInt(document.getElementById("ijewel").value) * 0.09));
        document.getElementById("isportcom").value = r2((parseInt(document.getElementById("isport").value) * 0.045));
        document.getElementById("iclothescom").value = r2((parseInt(document.getElementById("iclothes").value) * 0.0375));
        document.getElementById("icdcom").value = r2((parseInt(document.getElementById("icd").value) * 0.0375));
        document.getElementById("idvdcom").value = r2((parseInt(document.getElementById("idvd").value) * 0.0375));
        document.getElementById("itoiletcom").value = r2((parseInt(document.getElementById("itoilet").value) * 0.0375));
        document.getElementById("ifamdaycom").value = r2((parseInt(document.getElementById("ifamday").value) * 0.0375));
        document.getElementById("iholcom").value = r2((parseInt(document.getElementById("ihol").value) * 0.0225));
        document.getElementById("ibreakcom").value = r2((parseInt(document.getElementById("ibreak").value) * 0.03));
      }
    }
    function validateInt(ctrlID)
    {
      var varValue = document.getElementById(ctrlID).value;
      if (document.getElementById(ctrlID).value == "")
      {
        document.getElementById(ctrlID).value = "0.00";
      }
      else if (isNaN(varValue))
      {
        alert("Enter numeric data");
        document.getElementById(ctrlID).value="";
        document.getElementById(ctrlID).focus();
        return false;
      }
      return true;
    }
    function r2(n) 
    {
      ans = n * 1000;
      ans = Math.round(ans /10) + "";
      while (ans.length < 3) 
      {
        ans = "0" + ans;
      } 
      len = ans.length;
      ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len);
      return ans;
    } 
