
function action_login(done, host){
	var form = Ecnavi.Form.build((host||"")+"/config/login", "get", {"done":done||location.href});
	document.body.appendChild(form);
	form.submit();
}

function action_logout(done, host){
	var form = Ecnavi.Form.build((host||"")+"/config/logout", "get", {"done":done||location.href});
	document.body.appendChild(form);
	form.submit();
}

function action_plus_login(done, host){
	var form = Ecnavi.Form.build((host||"")+"/config/pluslogin", "get", {"done":done||location.href});
	document.body.appendChild(form);
	form.submit();
}
function action_plus_logout(done, host){
	var form = Ecnavi.Form.build((host||"")+"/config/pluslogout", "get", {"done":done||location.href});
	document.body.appendChild(form);
	form.submit();
}

function action_join(done,caption,host){
	var json = {
		"done":done||location.href
		,"caption":caption||"見ていたページに戻る"
	};
	var form = Ecnavi.Form.build((host||"")+"/config/register/prepare", "get", json);
	document.body.appendChild(form);
	form.submit();
}

function change_search_mode(mode) {
	var fix = function(val, key) {
		if (mode == val.getAttribute("rel")) {
			Element.addClassName(val, "select");
		} else {
			Element.removeClassName(val, "select");
		}
	};
	function element(name){
		return {
			show	: function(){ if($(name)) $(name).style.visibility = "visible" }
			,hide	: function(){ if($(name)) $(name).style.visibility = "hidden" }
		};
	}
	mode = (mode) ? mode : $F('search_mode');
	var tabs = document.getElementsByClassName('search_tab', 'search_box');
	tabs.each(fix);
	var sf = $('search_form');
	switch (mode) {
		case 'web':
			sf.action = '/search/';
			$('search_word').name = 'keyword';
			$('search_mode').value = 'web';
			element('powered_by_y').show();
			break;
		case 'news':
			sf.action = '/api/tag/suggest/test/';
			$('search_word').name = 'query';
			$('search_mode').value = 'news';
			element('powered_by_y').hide();
			break;
		case 'tag':
			sf.action = '/tag/';
			$('search_word').name = 'tag';
			$('search_mode').value = 'tag';
			element('powered_by_y').hide();
			break;
		case 'entry':
			sf.action = '/entrylist';
			$('search_word').name = 'url';
			$('search_mode').value = 'entry';
			element('powered_by_y').hide();
			break;
		case 'video':
			sf.action = '/video';
			$('search_word').name = 'query';
			$('search_mode').value = 'video';
			element('powered_by_y').hide();
			break;
		case 'home':
			$('search_mode').value = 'home';
			element('powered_by_y').hide();
			var keyword = $F('search_word');
			var home = $F('search_home');
			if(home && keyword){
				window.location = '/user/'+home+'/keyword/'+encodeURIComponent(keyword);
				return;
			}
			break;
	}
	$('search_word').focus();
	if ($F('search_word')){
		element('submit_loader').show();
		sf.submit();
	}
}

function action_reader(favorite, thumbprint){
	var json = {
		"favorite" : favorite
		,"done" : location.href
		,"thumbprint" : thumbprint
	};
	if(confirm("このユーザの読者になりますか？")){
		var form = Ecnavi.Form.build("/config/favorite/add", "post", json);
		document.body.appendChild(form);
		form.submit();
	}
}

// *** disable double click
var DCButton;
function disableDC(buttonObject){
	buttonObject.disabled = true;
	DCButton = buttonObject;
	setTimeout('DCButton.disabled = false;', 60 * 1000);
	return true;
}

Array.prototype.shuffle = function() {
    var i = this.length;
    while(i){
        var j = Math.floor(Math.random()*i);
        var t = this[--i];
        this[i] = this[j];
        this[j] = t;
    }
    return this;
}

function action_delete(entry_id, thumbprint){
	var json = {
		"entry_id" : entry_id
		,"done" : location.href
		,"thumbprint" : thumbprint
	};
	if(confirm("削除しますか？")){
		var form = Ecnavi.Form.build("/config/delete/execute", "post", json);
		document.body.appendChild(form);
		form.submit();
	}
}
