﻿////
// 動作可能なブラウザ判定
function chkAjaBrowser()
{
	var a,ua = navigator.userAgent;
	this.bw= { 
	  safari    : ((a=ua.split('AppleWebKit/')[1])?a.split('(')[0]:0)>=124 ,
	  konqueror : ((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3 ,
	  mozes     : ((a=ua.split('Gecko/')[1])?a.split(" ")[0]:0) >= 20011128 ,
	  opera     : (!!window.opera) && ((typeof XMLHttpRequest)=='function') ,
	  msie      : (!!window.ActiveXObject)?(!!createHttpRequest()):false 
	}
	return (this.bw.safari||this.bw.konqueror||this.bw.mozes||this.bw.opera||this.bw.msie)
}

////
// XMLHttpRequestオブジェクト生成
function createHttpRequest()
{
	if(window.XMLHttpRequest){
		 //Win Mac Linux m1,f1,o8 Mac s1 Linux k3 & Win e7用
		return new XMLHttpRequest() ;
	} else if(window.ActiveXObject){
		 //Win e4,e5,e6用
		try {
			return new ActiveXObject("Msxml2.XMLHTTP") ;
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP") ;
			} catch (e2) {
				return null ;
 			}
 		}
	} else  {
		return null ;
	}
}

////
// 送受信関数
function sendRequest(callback,data,method,url,async,sload,user,password)
{
	sendRequest.prototype.README	 = {
		url		: "http://jsgt.org/mt/archives/01/000409.html",
		name	: "sendRequest", 
		version	: 0.50, 
		license	: "Public Domain",
		author	: "Toshiro Takahashi http://jsgt.org/mt/01/",memo:""}

	//XMLHttpRequestオブジェクト生成
	var oj = createHttpRequest();
	if( oj == null ) return null;

	//強制ロードの設定
	var sload = (!!sendRequest.arguments[5])?sload:false;
	if(sload || method.toUpperCase() == 'GET')url += "?";
	if(sload)url=url+"t="+(new Date()).getTime();

	//ブラウザ判定
	var bwoj = new chkAjaBrowser();
	var opera	  = bwoj.bw.opera;
	var safari	  = bwoj.bw.safari;
	var konqueror = bwoj.bw.konqueror;
	var mozes	  = bwoj.bw.mozes ;

	//callbackを分解
	if(typeof callback=='object'){
		var callback_onload = callback.onload
		var callback_onbeforsetheader = callback.onbeforsetheader
	} else {
		var callback_onload = callback;
		var callback_onbeforsetheader = null;
	}

	//受信処理
	if(opera || safari || mozes){
		oj.onload = function () { callback_onload(oj); }
	} else {
		oj.onreadystatechange =function () {
			if ( oj.readyState == 4 ){
				//alert(oj.status+"--"+oj.getAllResponseHeaders());
				callback_onload(oj);
			}
		}
	}

	//URLエンコード
	data = uriEncode(data,url)
	if(method.toUpperCase() == 'GET') {
		url += data
	}
		
	//open メソッド
	oj.open(method,url,async,user,password);

	//リクエストヘッダカスタマイズ用コールバック
	if(!!callback_onbeforsetheader)callback_onbeforsetheader(oj)

	//デフォルトヘッダapplication/x-www-form-urlencodedセット
	setEncHeader(oj)

	//send メソッド
	oj.send(data);

	//URIエンコードヘッダセット
	function setEncHeader(oj){
		//ヘッダapplication/x-www-form-urlencodedセット
		var contentTypeUrlenc = 'application/x-www-form-urlencoded; charset=UTF-8';
		if(!window.opera){
			oj.setRequestHeader('Content-Type',contentTypeUrlenc);
		} else {
			if((typeof oj.setRequestHeader) == 'function')
				oj.setRequestHeader('Content-Type',contentTypeUrlenc);
		}
		return oj
	}

	//URLエンコード
	function uriEncode(data,url){
		var encdata =(url.indexOf('?')==-1)?'?dmy':'';
		if(typeof data=='object'){
			for(var i in data){
				encdata+='&'+encodeURIComponent(i)+'='+encodeURIComponent(data[i]);
			}
		} else if(typeof data=='string'){
			if(data=="")return "";
			var encdata = '';
			var datas = data.split('&');
			for(i=1;i<datas.length;i++)
			{
				var dataq = datas[i].split('=');
				encdata += '&'+encodeURIComponent(dataq[0])+'='+encodeURIComponent(dataq[1]);
			}
		} 
		return encdata;
	}
	return oj
}

////
// ゲーム一覧のオンオフ
function toggleWithClass(o,tClassName,initState) {
	var t = o.parentNode.nextSibling;
	while (t.className != tClassName) {
		t = t.nextSibling;
	}

	var s = t.style.display || initState;
	if (s != "block") {
		t.style.display = "block";
		o.title = "閉じる";
		o.innerHTML = "＞＞入荷済みゲーム一覧を閉じる";
	} else {
		t.style.display = "none";
		o.title = "表示";
		o.innerHTML = "＞＞入荷済みゲーム一覧の表示";
	}
}

////
// クーポンの期間判定
function coupon() {
	today = new Date();
	stday = new Date(sty,stm-1,std);
	edday = new Date(endy,endm-1,endd);
	dayms = 24 * 60 * 60 * 1000;
	sta = Math.floor((stday.getTime()-today.getTime())/dayms) + 1;
	end = Math.floor((edday.getTime()-today.getTime())/dayms) + 1;
	if (sta <= 7) {
		if (0 <= end) {
		document.getElementById("coupon").innerHTML =
		'<a href="javascript:void(0)" onclick="window.open(\'.\/coupon\/' + sname + '.html\',\'coupon\',\'width=600,height=400,resizable=yes,scrollbars=yes\')" target="_self">' +
		'<img src="./images/coupon.gif" alt="ネットでオトク！ネットクーポン"><\/a>';
		}
	}
}