<!--

/* windowOpen */
function WinOpen(theURL,winName,features) {
	window.open(theURL,winName,features);
}

/* setCookie */
function setCookie(keyname,val){
	expTime = new Date( );
	expTime.setFullYear(expTime.getFullYear( ) + 1);
	expTime = expTime.toGMTString( );
	
	tmp = keyname + "=" + val + ";";
	tmp += "expires=" + expTime + ";";
	tmp += "path=/;";
	document.cookie = tmp;
}

/* getCookie */
function getCookie(keyname){
	tmp = document.cookie + ";";
	index1 = tmp.indexOf(keyname,0);
	if (index1 !=-1){
	tmp = tmp.substring(index1,tmp.length);
	index2 = tmp.indexOf("=",0) + 1;
	index3 = tmp.indexOf(";",index2);
	return(unescape(tmp.substring(index2,index3)));
	}
	return("");
}

var fontsize = getCookie("fontsize");
if (fontsize == ""){setCookie("fontsize","medium");}

/* fontsize */
function changeStyleSheet(title) {
	var i, main;
	main = document.getElementsByTagName("link");
	for(i=0; i<main.length; i++) {
		if(main[i].getAttribute("rel").indexOf("style") != -1 && main[i].getAttribute("title")) {
			main[i].disabled = true;
			if(main[i].getAttribute("title") == title){
				 main[i].disabled = false;
			}
		}
	}
	setCookie("fontsize",title);
}

var fontsize = getCookie("fontsize");
if (fontsize == ""){setCookie("fontsize","medium");}
changeStyleSheet(fontsize);


var NakazawaVillage = {
    __end__: 0
};

/**
 * HistoryGadget
 */
NakazawaVillage.HistoryGadget = new Class({
    load: function(){
        var list = $("historyGadgetList");
        if (!list){
            return;
        }
        list.addClass("loading");
        
        this.put({
            onSuccess: function(history){
                list.empty();
                history.each(function(i){
                    var a = new Element("a", {
                        "class": "arrow",
                        text: i.title,
                        href: i.url
                    });
                    var li = new Element("li");
                    li.adopt(a);
                    list.adopt(li);
                });
                list.removeClass("loading");
            }
        });
    },
    put: function(args){
        var defaultArgs = {
            onSuccess: function(){},
            onError: function(){}
        };
        args = $merge(defaultArgs, args);
        new Request.JSON({
            url: "/gadget/",
            data: {
                "class": "history",
                method: "put",
                args: {
                    title: document.title,
                    url: location.href
                }
            },
            onError: function(){
                args.onError("system_error");
            },
            onSuccess: function(reply){
                if (reply.status != "OK"){
                    args.onError(reply.error);
                    return;
                }
                args.onSuccess(reply.data);
            }
        }).send();
    }
});


window.addEvent("domready", function(){
    $("planSeekFrm").addEvent("submit", function(e){
        new Event(e).stop();
        btnSeekSubmit();
    });
    with (NakazawaVillage) {
        new HistoryGadget().load();
    }
});

//-->