// Code section for Track clicks to download links.
function dcsDownload(evt){
	evt=evt||(window.event||"");
	var agt=navigator.userAgent.toLowerCase();
	var major=parseInt(navigator.appVersion);
	var nn=((agt.indexOf("mozilla")!=-1)&&(agt.indexOf("compatible")==-1));
	var nn_e=(nn&&(major>=4));
	var click = false;
	if (nn_e){
		if (typeof(evt.keyCode) == 'undefined') {
			if (evt.which == 1) {
				click = true;
			}
		} else {
			if (evt.keyCode == 13) {
				click = true;
			}
		}
	} else {
		if (evt.keyCode == 13) {
			click = true;
		} else if (typeof(evt.button) != 'undefined') {
			if (evt.button == 1) {
				click = true;
			}
		}
	}
	if (click) {
		var e=dcsEvt(evt,"A");
		var host=e.hostname;
		if (host&&dcsIsOnsite(host)){
			var path=e.pathname;
			if (dcsAllowTypes(path)){
				gHref="";
				dcsMultiTrack("DCS.dcssip",host,"DCS.dcsuri",path,"DCS.dcsref",window.location.href,"DCS.dcsqry",e.search||"","WT.ti",dcsDownloadTitle(e,path),"WT.dl","1");
				DCS.dcssip=DCS.dcsuri=DCS.dcsqry=WT.ti=WT.dl="";
			}
		}
	}
}

// Code section for Track right clicks to download links.
function dcsRightClick(evt){
	evt=evt||(window.event||"");
	if (evt){
		var btn=evt.which||evt.button;
		if (btn!=1){
			var e=dcsEvt(evt,"A");
			var host=e.hostname;
			if (host&&dcsIsOnsite(host)){
				var path=e.pathname;
				if (dcsAllowTypes(path)){
					gHref="";
					dcsMultiTrack("DCS.dcssip",host,"DCS.dcsuri",path,"DCS.dcsref",window.location.href,"DCS.dcsqry",e.search||"","WT.ti",dcsDownloadTitle(e,path),"WT.dl","1","WT.rc","1");
					DCS.dcssip=DCS.dcsuri=DCS.dcsqry=WT.ti=WT.dl=WT.rc="";
				}
			}
		}
	}
}

// typesに設定した拡張子へのリンクのみをSDC送信対象とする
// path_info形式(/aaa/bbb/ccc.cgi/ddd/eeeのようなURL)に対応
function dcsAllowTypes(path){
	var types="wvx,wmv,doc,pdf,xls,exe,swf";
	var ex_idx_from=path.lastIndexOf(".");
	var ex_idx_to=path.indexOf("/",ex_idx_from);
	ex_idx_to=ex_idx_to==-1?path.length:ex_idx_to
	if (path&&types.indexOf(path.substring(ex_idx_from+1,ex_idx_to))!=-1){
		return true;
	}
	return false;
}

// WT.tiにセットする文字列
function dcsDownloadTitle(e,path){
	if (!e.firstChild.tagName){										// アンカーのインラインが文字列の場合
		return e.innerHTML||"";										// WT.ti=(インラインの文字列)にする
	} else if (e.firstChild.alt!=""){								// アンカーのインラインがalt設定つきのimgの場合
		return e.firstChild.alt;									// WT.ti=(altの文字列)にする
	} else {														// それ以外の場合
		return "Download:"+((path.indexOf("/")!=0)?"/"+path:path);	// WT.ti=("Download:"+ファイルのトップからのパス)にする
	}
}

