var OBJ = {

	title:"",
	url: "",
	host: "",
	res: "",
	msg: "",
	use_before: "",
	use_after: "",
	path: "http://blog.lookjtb.com/",
	img_folder_path: "http://blog.lookjtb.com/acc_original/vote/img/",
	img_before: "hakusyu_before.gif",
	img_after: "hakusyu_after.gif",
	img_t_before: "hakusyu_t_before.gif",
	img_t_after: "hakusyu_t_after.gif",
	front_msg: "ここをクリック→ ",
	add_msg : "人の方が参考になったと答えています",
	com_msg : "ありがとうございました!",
	reg_1: "http://blog.lookjtb.com/test_t",
	reg_2: "http://blog.lookjtb.com/test_h",
	reg_3: "http://blog.lookjtb.com/tour_conductor",

	ajax: function(mode) {
		// XMLHttpRequestオブジェクトを生成
		try {
			// IEの場合
			xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			// ゲッコなどその他のブラウザの場合
			xmlReq = new XMLHttpRequest();
		}
		 // サーバーからの応答時の処理(PHPから受け取った文字列など)を定義
		xmlReq.onreadystatechange = function() {
			///var msg = document.getElementById("res");
			if (xmlReq.readyState == 4) { //readyStateが4の場合すべての処理が完了または失敗
				if (xmlReq.status == 200) {
					
					var rand = Math.random() * 100;

					OBJ.reg();
					var split_res = xmlReq.responseText.split(',');
					if(split_res[1] == "w"){
						OBJ.res.innerHTML = OBJ.front_msg + "<img src='" + OBJ.img_folder_path + OBJ.use_after + "' style='cursor:pointer;vertical-align:-5px'> " + split_res[0] + OBJ.add_msg;
						//OBJ.res.innerHTML = OBJ.front_msg + "<img src='" + OBJ.img_folder_path + OBJ.use_after + "?" + 	rand + "' style='cursor:pointer;vertical-align:-5px'>";
						OBJ.msg.innerHTML = OBJ.com_msg;
					}else{
						OBJ.res.innerHTML = OBJ.front_msg + "<img src='" + OBJ.img_folder_path + OBJ.use_before + "' style='cursor:pointer;vertical-align:-5px' onclick='OBJ.ajax();'>　" + split_res[0] + OBJ.add_msg;
						//OBJ.res.innerHTML = OBJ.front_msg + "<img src='" + OBJ.img_folder_path + OBJ.use_before + "' style='cursor:pointer;vertical-align:-5px' onclick='OBJ.ajax();'>　";
					}
				} else {

				}
			} else {

			}
		}

		var date = new Date();
		var timestamp = date.getTime();


		 // サーバー(PHP)との通信
		xmlReq.open("GET", OBJ.path + "acc_original/vote/vote_ajax.php?url=" + encodeURI(OBJ.url) + "&time=" + timestamp + "&mode=" + mode + "&title=" + encodeURI(OBJ.title), true);
		xmlReq.send(null);
	},

	reg : function() {
		var str = OBJ.url;
		re1 = new RegExp(OBJ.reg_1, "i");
		re2 = new RegExp(OBJ.reg_2, "i");
		re3 = new RegExp(OBJ.reg_3, "i");
		if (str.match(re1) || str.match(re3)) {
			OBJ.use_before = OBJ.img_t_before;
			OBJ.use_after  = OBJ.img_t_after;
		}else{
			OBJ.use_before = OBJ.img_before;
			OBJ.use_after  = OBJ.img_after;
		}
	},

	get : function() {
		var location = window.location.href;
		var split  = location.split('?');
		var split2 = split[0].split('#')
		OBJ.url = split2[0];
		OBJ.host =  window.location.host;

		var title = document.title.split('|');
		OBJ.title = title[0];

	},

	create_field : function() {
		OBJ.res = document.getElementById('res');
		OBJ.ajax("r");

	},

	complete_field : function() {
		OBJ.msg = document.getElementById('msg');
	}

}
window.onload = function() {
	OBJ.get();
	OBJ.create_field();
	OBJ.complete_field();
	//document.getElementById('res').onclick = OBJ.ajax;
}


