var x=0;
var y=0;
var onLink;
var overTime;
var outTime;
var objId;
var objHeight;

if(window.createPopup){
	var detailPopup = window.createPopup();
	var categoryPopup = window.createPopup();
}

function linkMouseOver(id, height){
	onLink = true;
	overTime = 0;
	flg = false;
	objId = id;
	objHeight = height;
	mouseoverTimer();
}

function linkClick(id, height){
	onLink = true;
	overTime = 0;
	flg = false;
	objId = id;
	objHeight = height;
	showDetail();
}

function linkMouseOut(){
	onLink = false;
}

function mouseoverTimer(){
	if(onLink == true){
		if(overTime < 5){
			setTimeout("mouseoverTimer()", 100);
			overTime++;
		}else{
			showDetail();
		}
	}else{
		return;
	}
}

function showDetail(){
	if(window.createPopup){
		detailPopup.document.body.style.background = '#FFFFFF';
		detailPopup.document.body.style.border = 'outset 3px';
		detailPopup.document.body.innerHTML = document.getElementById(objId).innerHTML;
		detailPopup.show(x-5,y-5,'250',objHeight,document.body);
	}else{
		window.open('event.pl?objId=' + objId , window, 'width=250px, height=' + objHeight + 'px, screenX='+x+'px, screenY='+y+'px, scrollbars=no, status=no, titlebar=no, toolbar=no');
	}
}

function showCategory(){
	if(window.createPopup){
		for(i = 1; i <= 7; i++){
			targetName = "CHIIKI" + i;
			document.f1.elements[targetName].value = document.fPopup.elements[targetName].checked;
		}
		categoryPopup.document.body.style.background = '#F9FFF9';
		categoryPopup.document.body.style.border = 'outset 3px';
		categoryPopup.document.body.innerHTML = document.getElementById("category").innerHTML;
		categoryPopup.show(265,55,'135','175',document.body);
	}else{
		for(i = 1; i <= 7; i++){
			targetName = "CHIIKI" + i;
			document.f1.elements[targetName].value = document.fPopupN.elements[targetName].checked;
		}
		window.open('category.pl', window, 'width=150px, height=180px, screenX='+x+'px, screenY='+y+'px, scrollbars=no, status=no, titlebar=no, toolbar=no');
	}
}

function windowOpen(url){
	window.open(url);
}

function popupHide(){
	if(window.createPopup){
		detailPopup.hide();
		categoryPopup.hide();
	}
}

function mSt(e){
	if(NN4||N6){
		x=e.screenX;
		y=e.screenY;
		document.routeEvent(e)
	}if(IE){
		scrollX = document.body.scrollLeft || document.documentElement.scrollLeft;
		scrollY = document.body.scrollTop  || document.documentElement.scrollTop;

		x=event.x + scrollX;
		y=event.y + scrollY;
	}
}

function initialize(flg){
	IE=window.opera||document.all;
	NN4=document.layers;
	N6=document.getElementById&&!IE;
	if(NN4||N6)document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove=mSt;
	if(flg == 1){
		setChiikiCheckbox();
	}
}

function setTabCookie(id) {

	//30日間有効
	theDay = 30;
	setDay = new Date();
	setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24));
	expDay = setDay.toGMTString();

    document.cookie = "SELECT_TAB= " + escape(id) + " ; expires="+expDay;
}


function checkboxClick(obj){
	document.f1.elements[obj.name].value = obj.checked;
}

function setChiikiCookie(){

	//30日間有効
	theDay = 30;
	setDay = new Date();
	setDay.setTime(setDay.getTime()+(theDay*1000*60*60*24));
	expDay = setDay.toGMTString();

	for(i = 1; i <= 7; i++){
		targetName = "CHIIKI" + i;
		document.cookie = targetName + "=" + escape(document.f1.elements[targetName].value) + "; expires="+expDay;
	}
	location.reload();
}

function setChiikiCheckbox(){
	var chk_cnt = 0;
	for(i = 1; i <= 7; i++){
		targetName = "CHIIKI" + i;
		val = getCookie(targetName);
		if(val == "true"){
			document.fPopup.elements[targetName].checked = true;
			document.fPopupN.elements[targetName].checked = true;
			chk_cnt++;
		}else{
			document.fPopup.elements[targetName].checked = false;
			document.fPopupN.elements[targetName].checked = false;
		}
	}
	if(chk_cnt == 0){
		for(i = 1; i <= 7; i++){
			targetName = "CHIIKI" + i;
			document.fPopup.elements[targetName].checked = true;
			document.fPopupN.elements[targetName].checked = true;
			document.f1.elements[targetName].value = "true";
		}
		setChiikiCookie();
	}
}

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("");
}
