
<!--
/////////////////////////////////////// START FUNCTIONS ///////////////////////////////////////////


function cs_isExternalLink(url){
  if(!url){ return false; }
  if(typeof(url) != 'string'){ return true; }
  url = url.toLowerCase();

  /* what else is missing from the protocol list below? */
  if(url.indexOf('https://') == 0){ url = url.substring(8); }
  else if(url.indexOf('http://') == 0){ url = url.substring(7); }
  else if(url.indexOf('ftp://') == 0){ url = url.substring(6); }
  else if(url.indexOf('ssl://') == 0){ url = url.substring(6); }
  else if(url.indexOf('mailto:') == 0){ return true; }
  else{ return false; }

  if(url.indexOf('www.') == 0){ url = url.substring(4); }
  var hn = document.location.hostname.toLowerCase();
  if(hn.indexOf('www.') == 0){ hn = hn.substring(4); }

  if(url.indexOf(hn) != 0){ return true; }
  return false;
}

function cs_getParentClickable(obj, flag){
  for(var j=0; j<=5; j++){
    if(flag == 1){ if(obj && obj.nodeName.toUpperCase() == 'A'){ return obj; } } //look for <A> tag
    if(flag == 2){ if(obj && obj.nodeName.toUpperCase() != 'BODY' && obj.onclick){ return obj; } } //look onclick tag
    obj = obj.parentNode;
  }
  return null;
}

function cs_context_click(e){//right click on link
  var tg = null;
  if(e){ tg = e.target; }
  else{ tg = window.event.srcElement; }
  cs_do_track(tg, false);
}

function cs_on_click(e){//left click
  var tg = null;
  if(e){ tg = e.target; }
  else{ tg = window.event.srcElement; }
  cs_do_track(tg, true);
}

function cs_do_track(tg, delay){



  var url = null;
  var text = null;
  try{
    if(tg){
      tgP = cs_getParentClickable(tg, 1);
      if(tgP && tgP.nodeName.toUpperCase() == 'A'){ tg = tgP; }

      if(tg.nodeName.toUpperCase() == 'A'){//A tag - most popular case
        url = tg.href;
        if(tg.innerHTML){ text = tg.innerHTML; } //most browsers
        else if(tg.innerText){ text = tg.innerText; } //ie only
        else if(tg.text){ text = tg.text; } //mozilla only
        else{}
      }else if(tg.nodeName.toUpperCase() == 'INPUT' && tg.type.toUpperCase() == 'SUBMIT'){//form submit button
        url = tg.form.action;
        text = tg.value;
      }else{
       /* this eliminates all other onclick events */

      }
      if(url == null || text == null){ return true; } //both url and text must not be NULL 

      if(cs_isExternalLink(url)){//単なるアクセス解析に使うので、外部リンクのみでなくてよい
      }

        if(cs_mbl_isAOL_V8 && (tg.target == '_new' || tg.target == '_blank')){ return true; }
        url = encodeURI(url);
		url = url.replace(/=/g, '%3D').replace(/&/g, '%26');
        text = encodeURI(text);
        cs_track_oc(text, url, delay);

    }
  }catch(err){ }
}


// THIS FUNCTION TRACKS EXTERNAL URL CLICKS //
function cs_track_oc(text, url, delay){      
  try{

    //lurl = encodeURI(document.location.href);
    lurl = document.location.href;
	//lurl = lurl.replace(/=/g, '%3D').replace(/&/g, '%26');
    var now = new Date();


    //var trackURL = cs_url_trker + '?t=2&lu=' + lurl  + '&ru=' + rurl + '&u=' + url + '&te=' + text + '&a=' + encodeURI(navigator.userAgent); 


    var trackURL = cs_url_trker + '?' + lurl + '<><>' + id + '<>2<>' + url  + '<>' + text + '<>'; 


    var x = new Image();
    x.src = trackURL;
    if(delay){ cs_pause(900); }
  }catch(err){ }
}




// THIS FUNCTION RECORDS APACHE-LIKE LOG INFO ON EVERY PAGE LOAD //
function cs_track_onload(){
  try{
    //lurl = encodeURI(document.location.href);
    //rurl = encodeURI(document.referrer);

    lurl = document.location.href;
    rurl = document.referrer;

	//rurl = rurl.replace(/=/g, '%3D').replace(/&/g, '%26');
	//lurl = lurl.replace(/=/g, '%3D').replace(/&/g, '%26');

    //var trackURL = cs_url_trker + '?t=1&lu=' + lurl + '&ru=' + rurl + '&a=' + encodeURI(navigator.userAgent) ;

    var trackURL = cs_url_trker + '?' + lurl + '<>' +  rurl + '<>' + id + '<>1<><><>'; 

	//document.write('<font size=-3>' + trackURL + '</font>');


	//document.write('aa <img src="' + trackURL + '" width="0" height="0">');
	//document.write('-- <img src="' + trackURL + '">');

    var x = new Image();
    x.src = trackURL;

  }catch(err){ }
}

function cs_pause(numberMillis) {
  var now = new Date();
  var exitTime = now.getTime() + numberMillis;
  while(true){
    now = new Date();
    if(now.getTime() > exitTime){ return; }
  }
}

/////////////////////////////////////// END FUNCTIONS ///////////////////////////////////////////


var cs_mbl_isAOL_V8 = false;
if(navigator.userAgent.indexOf('AOL 8.0') > 0){ cs_mbl_isAOL_V8 = true; }


var cs_url_trker = 'http://nition.com/analyze/togo/addlog.cgi';
if(document.body){	//bodyタグの内側
  document.body.onclick = cs_on_click;
  document.body.oncontextmenu = cs_context_click;
}else if(document){	//bodyタグの外側
  document.onclick = cs_on_click;
  document.oncontextmenu = cs_context_click;  
}else{}
cs_track_onload();

// -->
