var chDate = '20100302';
var commentDate = '0812051';

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)
{
    var tmp1 = " " + document.cookie + ";";
    var xx1 = 0; var xx2 = 0;
    var len = tmp1.length;
    while (xx1 < len)
	{
	    xx2 = tmp1.indexOf(";", xx1);
	    var tmp2 = tmp1.substring(xx1 + 1, xx2);
	    var 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)
{
    var 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=.weathernews.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);
}

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+"&"+
		"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 WriteSWFTrans (swf, width, height, flashvars) {

	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=6,0,0,0">\n';
	code += '<param name="bgcolor" value="#ffffff">\n';
	code += '<param name="flashvars" value="' + flashvars + '&chDate=' + chDate + '&commentDate=' + commentDate + '">\n';
	code += '<param name="MOVIE" value="' + swf + '">\n';
	code += '<param name="wmode" value="transparent">\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 += '<embed src="' + swf + '"\n';
	code += 'width="' + width + '"\n';
	code += 'height="' + height + '"\n';
	code += 'PLAY="true"\n';
	code += 'wmode="transparent"\n';
	code += 'MENU="false"\n';
	code += 'LOOP="false"\n';
	code += 'QUALITY="best"\n';
	code += 'BGCOLOR="#ffffff"\n';
	code += 'flashvars=' + flashvars + '&chDate=' + chDate + '&commentDate=' + commentDate + '\n';
	code += 'type="application/x-shockwave-flash"\n';
	code +=	'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">\n';
	code += '</embed>\n</object>\n';
	document.write(code);
}

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

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

	var code = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width=';
	code += width + ' height=' + height;
	code += ' id="flashmovie" ';
	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 + '&commentDate=' + commentDate + '">\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 + '&commentDate=' + commentDate + '\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 }
}

// for LiveCamera Pop Up

function camWin(url,winName) {
        wx = 330;
        wy = 355;
        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,winName,options);
}

// for logout of My/Labs

function logOut(){
	 clearCookie('mdbauth');
	 location.reload();
	 return;
}

//call MyCH regist dialog
function sdecode(s)
{
    var q = s.split(".");
    s = "";
    for (var i = 0; i < q.length; ++i) s += String.fromCharCode(q[i]); // I don't think javascript supports on-the-fly array deagregation like Ruby ?
    return s;
}
function MyscrDlg(ch, vars)
{
    if (vars && (ch != "10_1"))
      vars = sdecode(vars); // This is necessary because of stupid bugs in browsers. Safari (only mac version, PC version works fine) will give out 0xFFFD char instead of anything over 127 that is
    // passed from Flash. But if the string is URL-encoded, then IE will decode it AS IF it was URL-encoded iso-latin-1 (regardless of the locale by the way, it will use
    // iso-latin-1 even if the locale is japanese) and give the (garbled, of course) result as a normal utf-8 string. Which by the way also flies in the face of standards :
    // the RFC explicitly says that anything that is URL-encoded HAS to be UTF-8. Apple, Microsoft, fix your browsers :(
    var cookie = getCookie('Id');
    var width = 0;
    var height = 0;
    var winname = 0;
    var url = 0;
    if (ch=="1_1")
	{
	    width = '300';
	    height = '225';
	    winname = "subwin0";
	    url = "/my/screen/pinpoint.html?" + vars;
	} 
    else
	{
	    width = '260';
	    height = '287';
	    winname = "subwin1";
	    url = "/my/screen/screen.html?ch=" + ch + "&" + vars;
	}
    if (' ' == cookie)
	{
	    width = '260';
	    height = '205';
	    winname = "subwin1";
	    url = "/my/screen/nocookie.html";
	}
    var x = (screen.width - width) / 2;
    var y = (screen.height - height) / 2 - 40;
    var win_popup = window.open(url, winname, "left=" + x + ",top=" + y + ",width=" + width + ",height=" + height );
    win_popup.focus();
}

var vLoad = 'finish';
