// make unique id

var chDate = '20101201';
var fwkDate = '20080311';

function count() {
	 id = getCookie("Id");
	 if (id == "") {
	         today  = new Date();
		 y = today.getFullYear();
		 m = to2String(today.getMonth() + 1);
		 d = to2String(today.getDate());
		 h = to2String(today.getHours());
		 mm = to2String(today.getMinutes());
	     id = Math.floor(Math.random()*10000000000);
	     lastid = y+m+d+h+mm+id;
	     setCookie("Id", lastid);
	 }
	GetMachineSpec();
}
function getCookie(key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}
function setCookie(key, val, tmp) {
    tmp = key + "=" + escape(val) + "; ";
    tmp += "expires=Tue, 31-Dec-2030 23:59:59 GMT; ";
    tmp += "path=/; ";
    document.cookie = tmp;
}
function clearCookie(key) {
    var tmp = key + "=" + "; expires=Tue, 1-Jan-1980 00:00:00 GMT; path=/; domain=.wni.co.jp;";
    document.cookie = tmp;
}
function to2String(value){
	 label=""+value;
	 if(label.length<2){
		label="0"+label;
	 }
	 return label;
}
function contentWin(url) {
	wx = 330;
	wy = 340;
	x = (screen.width - wx) / 2;
	y = (screen.height - wy) / 2 - 40;
	var options = "scrollbars=1,status=0,toolbar=0,left=" + x + ",top=" + y + ",width=" + wx + ",height=" + wy;
	window.open(url,'oldContents',options);
}
function hanreiWin(url) {
	wx = 440;
	wy = 300;
	x = (screen.width - wx) / 2;
	y = (screen.height - wy) / 2 - 40;
	var options = "scrollbars=0,status=0,toolbar=0,left=" + x + ",top=" + y + ",width=" + wx + ",height=" + wy;
	window.open(url,'hanrei',options);
}


// Get Flash Version
// Globals
var jsVersion = 1.0;

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {

		flashVer = -1;
	}
	return flashVer;
}

function GetFlashVer()
{
	for (i=25;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);
		}
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];

			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			return( versionString );
		}
	}
}

function getWindowHeight()
{
	var height;
	if( height=window.innerHeight ) {
		return( height );
	}
	else if( height=document.documentElement.clientHeight ) {
		return( height );
	}
	else if( height=document.body.clientHeight) {
		return( height );
	}
	else {
		return 0;
	}
}

function getWindowWidth()
{
	var width;
	if( width=window.innerWidth ) {
		return( width );
	}
	else if( width=document.documentElement.clientWidth ) {
		return( width );
	}
	else if( width=document.body.clientWidth) {
		return( width );
	}
	else {
		return 0;
	}
}

function GetMachineSpec()
{
	var query =
		"screen="+screen.width+"x"+screen.height+"&"+
                "win="+getWindowWidth()+"x"+getWindowHeight()+"&"+
		"sx="+screen.width+"&"+
		"sy="+screen.height+"&"+
		"wx="+getWindowWidth()+"&"+
		"wy="+getWindowHeight()+"&"+
		"color="+screen.colorDepth+"&"+
		"flash="+GetFlashVer()+"&"+
		"uid="+getCookie("Id");

	var code = "<img src='/js/zero.gif?"+query+"'>";

	if(document.all){ document.all('countCode').innerHTML = code }
	if(document.getElementById){ document.getElementById('countCode').innerHTML = code }
}

// Write Flash

function WriteSWF (swf, width, height, flashvars, flashver) {

	var cookie = getCookie('mdbauth');
	var statusLogin = 0;
	if(cookie)
	  statusLogin = 1;
	var flashversion = 8;
	if(flashver)
	  flashversion = flashver;

	var code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width=';
	code += width + ' height=' + height;
	code +=	'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + flashversion + ',0,0,0">\n';
	code += '<param name="bgcolor" value="#ffffff">\n';
	code += '<param name="flashvars" value="' + flashvars + '&chDate=' + chDate + '&statusLogin=' + statusLogin + '">\n';
	code += '<param name="MOVIE" value="' + swf + '">\n';
	code += '<param name="PLAY" value="true">\n';
	code += '<param name="LOOP" value="false">\n';
	code += '<param name="QUALITY" value="best">\n';
	code += '<param name="MENU" value="false">\n';
	code += '<param name="allowScriptAccess" value="always">\n';

	code += '<embed src="' + swf + '"\n';
	code += 'width="' + width + '"\n';
	code += 'height="' + height + '"\n';
	code += 'PLAY="true"\n';
	code += 'MENU="false"\n';
	code += 'LOOP="false"\n';
	code += 'QUALITY="best"\n';
	code += 'BGCOLOR="#ffffff"\n';
	code += 'flashvars=' + flashvars + '&chDate=' + chDate + '&statusLogin=' + statusLogin + '\n';
	code += 'type="application/x-shockwave-flash"\n';
	code += 'allowScriptAccess="always"\n';
	code +=	'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">\n';
	code += '</embed>\n</object>\n';

	if(document.all){ document.all('swfCode').innerHTML = code }
	if(document.getElementById){ document.getElementById('swfCode').innerHTML = code }
}

