
$(function() {
    var swurl = "/shop/sa";

    $(document).ready(function(){
      if (typeof(parchaseOrderNo)  == "undefined" || parchaseOrderNo == null) {
        new Image().src = swurl + "/pv/?vr=1.00&dl="+ encodeURIComponent(location.href) + "&dr="+ encodeURIComponent(document.referrer) +"&rn="+ Math.random();
      } else {
        new Image().src = swurl + "/pv/?vr=1.00&od=" + parchaseOrderNo + "&dl="+ encodeURIComponent(location.href) + "&dr="+ encodeURIComponent(document.referrer) +"&rn="+ Math.random();
      }
    });

    $(window).click(function(ev) {
      var trObj = ev.target;
      if(trObj.parentNode != null && trObj.parentNode.tagName == "BUTTON"){
        trObj = chkobj(trObj);
      }
      else if(trObj.tagName != "BUTTON" && trObj.tagName != "A" && !(trObj.tagName == "INPUT" && trObj.type == "button")){
        trObj = chkobj(trObj);
      }
      try{
        if(trObj.tagName == "A" || (trObj.tagName == "INPUT" && trObj.type == "button") || trObj.tagName == "BUTTON"){
          var trTag   = (typeof trObj.tagName === "undefined")   ? "" : "&tg="+encodeURIComponent(trObj.tagName);
          var trType  = (typeof trObj.type === "undefined")      ? "" : "&tp="+encodeURIComponent(trObj.type);
          var trName  = (typeof trObj.name === "undefined")      ? "" : "&n="+encodeURIComponent(trObj.name);
          var trId    = (typeof trObj.id === "undefined")        ? "" : "&i="+encodeURIComponent(trObj.id);
          var trHref  = (typeof trObj.href === "undefined")      ? "" : "&h="+encodeURIComponent(trObj.href);
          var trValue = (typeof trObj.value === "undefined")     ? "" : "&v="+encodeURIComponent(trObj.value);
          var trParam = "&dl="+ encodeURIComponent(location.href);
          trParam = trParam + trTag + trType + trName + trId + trHref + trValue;
          trParam = trParam + "&rn=" + Math.random();
          new Image().src = swurl + "/ev/?vr=1.00&ev=click"+trParam;
        }
      }catch(e){
        alert(e.message);
      }

      function chkobj(trObj){
        var depth = 0;
        var tmpObj = trObj;
        for(depth =0; depth < 5; depth++){
          if(tmpObj.parentNode != null){
            tmpObj = tmpObj.parentNode;
          } else {
            return tmpObj;
          }
          if(tmpObj.tagName == "A"){
            return tmpObj;
          }
        }
        return trObj;
      }
    }
    );
});

