/* matc.js
 * MITSUE-LINKS Auto Tracking Code
 * Version 2.2.1
 * Copyright (C) 2010 MITSUE-LINKS
 * 
 * This JavaScript was created using "gatag.js" provided by Goodwebpractices.com.
 */

//変更可能箇所
//統合解析ドメイン（対象ドメインを「|」で追加）
//var integrateddomain = /^integrateddomain$/i;
//統合解析サブドメイン（対象ドメインを「|」で追加）
var subdomain = /re-model\.jp$/i;
//外部遷移トラッキングドメイン（デフォルトは「.*」。対象を絞る際は、対象ドメインを「|」で追加）
var externaldomain = /\./i;
//外部遷移トラッキングパス（任意入力。先頭の「/」は必須）
var externalpath = '/outgoing/';
//ダウンロードトラッキング対象拡張子（対象拡張子を「|」で追加）
var filetypes = /\.(doc|eps|svg|xls|ppt|pdf|zip|vsd|vxd|rar|exe|wma|mov|avi|wmv|mp3|mp4|m4v)/i;

//以下、変更不可

//「onload」重複対応
if (window.addEventListener) {
    window.addEventListener('load', autotracking, false);
} else if (window.attachEvent) {
    window.attachEvent('onload', autotracking);
}
//条件分岐
function autotracking() {
	if(typeof firstTracker._trackPageview != 'function') return;
	var anchors = document.getElementsByTagName("a");
	for(var l = 0; l < anchors.length; l++) {
		var hn = anchors[l].hostname;
		if(anchors[l].protocol == "mailto:") {
			startListening(anchors[l],"click",trackMailto);
		//} else if(anchors[l].hostname == location.hostname)) { //サブドメイン未統合用
		} else if(anchors[l].hostname == location.hostname || hn.match(subdomain)) { //サブドメイン統合用
			var path = anchors[l].pathname + anchors[l].search;
			var matchtype = path.match(filetypes);
			var matchtype = hn.match(subdomain);
			if(matchtype) {
				startListening(anchors[l],"click",multipletrack);
			}
			startListening(anchors[l],"click",remodel_club_view);
		//} else if(hn.match(integrateddomain)) {
		//	startListening(anchors[l],"click",integrationtrack);
		} else if(hn.match(subdomain)) {
		} else if(hn.match(externaldomain)) {
			startListening(anchors[l],"click",remodel_club_view);
			startListening(anchors[l],"click",multipletrack);
		} else {}
	}
}
//クリック判定
function startListening(obj,evnt,func) {
	if(obj.addEventListener) {
		obj.addEventListener(evnt,func,false);
	} else if(obj.attachEvent) {
		obj.attachEvent("on" + evnt,func);
	}
}
//メールリンクのトラッキング
function trackMailto(evnt) {
	var href = (evnt.srcElement) ? evnt.srcElement.href : this.href;
	var mailto = "/mailto/" + href.substring(7);
	if(typeof(firstTracker) == "object")
	firstTracker._trackPageview(mailto);
}
//ダウンロード・外部リンクのトラッキング
function multipletrack(evnt) {
	var e = (evnt.srcElement) ? evnt.srcElement : this;
	while(e.tagName != "A") {
		e = e.parentNode;
	}
	var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname;
	if(e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search;
	if(e.hostname != location.host) lnk = externalpath + e.hostname + lnk;
	//if(typeof(firstTracker) == "object") firstTracker._trackPageview(lnk);
}
//RC 店舗詳細の外部リンクのクリック計測
function remodel_club_view(evnt) {

	var e = (evnt.srcElement) ? evnt.srcElement : this;
	while(e.tagName != "A") {
		e = e.parentNode;
	}
	var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname;
	if(e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search;
	if(e.hostname != location.host) lnk = e.hostname + lnk;
	
	if(location.pathname.indexOf("/webapp/remodel_club/view/",0) != -1){
		var rc_path = location.pathname;
		var rc_l = rc_path.length;
		if (location.hostname.match(/re-model\.jp$/i)) {
		var rc_id = rc_path.substr(rc_path.lastIndexOf("/",rc_l) + 1,rc_l - rc_path.lastIndexOf("/",rc_l) - 1); //パスから RC ID の取得：本番用
		} else if (location.hostname.match(/mitsue\.com$/i)){
		var rc_id = rc_path.substr(rc_path.lastIndexOf("/",rc_l) + 1,rc_path.lastIndexOf(".",rc_l) - rc_path.lastIndexOf("/",rc_l) - 1); //パスから RC ID の取得：検証用
		}

		//もっと事例を見るリンク計測
		if(e.hostname == "jirei.re-model.jp" && e.pathname.indexOf("/project_list/") != -1) {
		firstTracker._trackEvent("店舗詳細：もっと事例を見るリンク",rc_id,lnk);
		//alert("店舗詳細：もっと事例を見る" + "," + rc_id + "," + lnk);
		
		//その他の外部リンク
		} else if(e.hostname.match(/toto.co.jp$|daiken.jp$|ykkap.co.jp$|com-et.com$/i)) {
		firstTracker._trackEvent("店舗詳細：その他の外部リンク",rc_id,lnk);
		//alert("店舗詳細：その他の外部リンク" + "," + rc_id + "," + lnk);
		
		//HPリンク：上記以外の外部リンク
		} else if(e.hostname != location.host && e.hostname != "re-model.jp" && e.hostname != "jirei.re-model.jp") {
		firstTracker._trackEvent("店舗詳細：HPリンク",rc_id,lnk);
		//alert("店舗詳細：HPリンク" + "," + rc_id + "," + lnk);
		}
	}
}
//統合ドメインへの遷移トラッキング
/*
function integrationtrack(evnt) {
	var e = (evnt.srcElement) ? evnt.srcElement : this;
	while(e.tagName != "A") {
		e = e.parentNode;
	}
	if(typeof(firstTracker) == "object") {
		if(e.target == "_blank") {
			window.open(firstTracker._getLinkerUrl(e.href),'_blank');
		} else {
			firstTracker._link(e.href);
		}
		evnt.returnValue = false;
		evnt.preventDefault();
	}
}
*/
//gatrack.js
try {
//本番用アカウント firstTracker
var firstTracker = _gat._getTracker("UA-12215560-1");
firstTracker._setDomainName(".re-model.jp");

firstTracker._addOrganic("yahoo","va",true);
firstTracker._addOrganic("google","as_q",true);
firstTracker._addOrganic("search.goo","MT",true);
firstTracker._addOrganic("nifty","q",true);
firstTracker._addOrganic("infoseek","qt",true);
firstTracker._addOrganic("jword","name",true);
firstTracker._addOrganic("luna","q",true);
firstTracker._addOrganic("livedoor","q",true);
firstTracker._addOrganic("hatena","word",true);

firstTracker._trackPageview();
} catch(err) {}

