/**
 * ana.js
 */

var ana = new Object(
	{
		scriptName:'ana',
		scriptVersion:'0.1',
		useAjax:true,
		qs:'',
		reqMethod:'POST',
	
		_n:navigator,
		_d:document,
		
		createQueryString:function(site, siteId, page, pageId, sub, subId, uid, attr){
			this.qs += 'action_logAPI=true';
			this.qs += '&sn=' + this.scriptName;
			this.qs += '&sv=' + this.scriptVersion;
			
			this.qs += '&site=' + encodeURIComponent(site);
			this.qs += '&siteId=' + siteId;
			this.qs += '&page=' + encodeURIComponent(page);
			this.qs += '&pageId=' + pageId;
			this.qs += '&sub=' + encodeURIComponent(sub);
			this.qs += '&subId=' + subId;
			this.qs += '&uid=' + uid;
			this.qs += '&attr=' + encodeURIComponent(attr);
			
			this.qs += '&nu=' + encodeURIComponent(this._n.userAgent);
			this.qs += '&np=' + this._n.platform;
			this.qs += '&nl=';
			this.qs += this._n.language ? this._n.language : this._n.browserLanguage;
			//TEST
			//this.qs += '&dr=' + encodeURIComponent('http://search.goo.ne.jp/web.jsp?MT=%E3%82%8A%E3%82%93%E3%81%94+%E3%82%AD%E3%82%A6%E3%82%A4&STYPE=web&IE=UTF-8&from=gootop');
			//this.qs += '&dr=' + encodeURIComponent('http://www.google.co.jp/search?hl=ja&lr=lang_ja&ie=SJIS&oe=SJIS&num=100&q=%82%E8%82%F1%82%B2+%83L%83E%83C');
			//this.qs += '&dr=' + encodeURIComponent('http://www.google.co.jp/search?hl=ja&q=%E3%82%8A%E3%82%93%E3%81%94+%E3%82%AD%E3%82%A6%E3%82%A4&btnG=Google+%E6%A4%9C%E7%B4%A2&lr=&aq=f&oq=');
			//this.qs += '&dr=' + encodeURIComponent('http://www.google.co.jp/search?hl=ja&source=hp&q=%E8%96%94%E8%96%87+%E7%8F%88%E7%90%B2%E3%80%80%E5%9C%8B&lr=&aq=f&oq=');
			//this.qs += '&dr=' + encodeURIComponent('http://search.yahoo.com/search;_ylt=A0oGk5U2BZRKBJoAOBhXNyoA?p=%E7%99%87%E7%99%AA+%E7%A2%BC%E7%A2%AF+%E8%80%84%E7%A2%8C&y=Search&fr=yfp-t-153&fr2=sb-top&sao=1');
			//this.qs += '&dr=' + encodeURIComponent('http://search.yahoo.co.jp/search;_ylt=A0oGk5U2BZRKBJoAOBhXNyoA?p=%E7%99%87%E7%99%AA+%E7%A2%BC%E7%A2%AF+%E8%80%84%E7%A2%8C&y=Search&fr=yfp-t-153&fr2=sb-top&sao=1');
			this.qs += '&dr=' + encodeURIComponent(this._d.referrer);
			this.qs += '&dl=' + encodeURIComponent(this._d.location);
		},
		
		exec:function(absUri, site, siteId, page, pageId, sub, subId, uid, attr){
			this.createQueryString(site, siteId, page, pageId, sub, subId, uid, attr);
			if(this.useAjax && this.initAjax()){
				/* Ajax Mode */
				xmlHttpObj.open(this.reqMethod, absUri, true);
				// Call a function when the state changes.
				xmlHttpObj.onreadystatechange = function() {
					if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200) {
						//var result=document.getElementById("div_ana_id");
						//result.innerHTML=xmlHttpObj.responseText;
					}
				}
				if(this.reqMethod == 'POST'){
					xmlHttpObj.setRequestHeader('Content-Type' ,'application/x-www-form-urlencoded; charset=utf-8');
					xmlHttpObj.send(this.qs + '&ajax=1');
				}
				return null;
			}else{
				/* Non-Ajax Mode */
				return absUri + '?' + this.qs + '&ajax=0';
			}
		},
		
		xmlHttpObj:null,
		initAjax:function(){
			if(window.ActiveXObject){
				try {
					xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					try{
						xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
					} catch(e) {
						return false;
					}
				}
			} else if (window.XMLHttpRequest){
				xmlHttpObj = new XMLHttpRequest();
			} else {
				return false;
			}
			return true;
		}
	}
);
