/* ==============================
 定数の宣言
============================== */
var PROJECT_NAME = "KIDS_PATROL";


/* ==============================
 環境変数の取得（GET['key'], COOKIES['key']）
============================== */
var GET = new Object;
if ( document.location.href.indexOf('?') != -1 ) {
	var GETsStr = (document.location.href.substr( document.location.href.indexOf("?")+1, document.location.href.length ) ).split("&");
	for ( var count=0; count < GETsStr.length; count++ ) {
		var temp = GETsStr[count].split('=');
		GET[temp[0]] = temp[1];
	}
}

var COOKIES = new Object;
checkCookies();
function checkCookies(){
	if( document.cookie ){
		var COOKIEsStr = document.cookie.split(";");
		for ( var count=0; count < COOKIEsStr.length; count++ ) {
			var temp = COOKIEsStr[count].split("=");
			COOKIES[temp[0].replace( /^ *| *$/g, "" )] = temp[1].replace( /^ *| *$/g, "" );
		}
	}
}
function setCookie( key, value ){
	var expiresDateObj = new Date();
	if( arguments.length == 3 ){
		expiresDateObj = arguments[2];
	} else {
		expiresDateObj = new Date();
		expiresDateObj.setYear( expiresDateObj.getFullYear() + 1 );
	}
	var expiresDate = expiresDateObj.toGMTString().replace(/UTC/, "GTM");
	var tempStr = key + "=" + value + "; ";
	tempStr +="expires=" + expiresDate + "; ";
	document.cookie=tempStr;

	checkCookies();
}


/* ==============================
 関数：openWindow
============================== */
function openWindow( targetRef, popWidth, popHeight ){
	var popLeft = (screen.width - popWidth) / 2;
	var popTop = (screen.height - popHeight) / 2;

	var refPopWin;
	if( (arguments.length == 4) && (arguments[3] == 'scroll') ) {
		refPopWin = window.open( targetRef, PROJECT_NAME + "_Pop" + popWidth + "x" + popHeight + "SB", "toolbar=0,location=0,directories=0,scrollbars=1,status=1,resizable=0,width=" + popWidth + ",height=" + popHeight + ",top=" + popTop + ",left=" + popLeft);
	}
	else {
		refPopWin = window.open( targetRef, PROJECT_NAME + "_Pop" + popWidth + "x" + popHeight + "", "toolbar=0,location=0,directories=0,scrollbars=0,status=1,resizable=0,width=" + popWidth + ",height=" + popHeight + ",top=" + popTop + ",left=" + popLeft);
	}
	refPopWin.focus();
	return refPopWin;
}


/* ==============================
 関数：changeImage
============================== */
var imgObj = new Array();
var imgReady = false;

function initImage(targetname, stat, src) {
	if(document.images) {
		if(typeof imgObj[targetname] == "undefined") imgObj[targetname] = new Array();
		imgObj[targetname][stat] = new Image();

		if(src != "" && src != null) imgObj[targetname][stat].src = src;
		else return false;

		return true;
	}
	return false;
}
function changeImage(imgname,stat) {
	if(document.images && imgReady) {
		var targetImg;
		if( arguments.length == 3 ) {
			targetImg = imgname + arguments[1];
			stat = arguments[2];
		}
		else targetImg = imgname;

		if(document.images[targetImg]) document.images[targetImg].src = imgObj[imgname][stat].src;
		return true;
	}
	return false;
}


