function log(){
	document.write('<iframe src="/access?ref='+document.referrer+'" width="200" height="200" frameborder="0" scrolling="no"></iframe>');
}

function reloadPage(){
	location.reload();
}

function stringLength(value, maxLength, countID){
	strLength = value.length;
	document.getElementById(countID).innerHTML = strLength + '/' + maxLength;
	document.getElementById('submit').disabled = (strLength > maxLength)? true : false;
	if(document.getElementById('submit').disabled){
		document.getElementById('submit').className = 'disabled';
	}else{
		document.getElementById('submit').className = '';
	}
}

function initSearchForm(target, q){
	classes = target.className.split(' ');
	c = '';
	for(i = 0; i < classes.length; i++){
		/*
		if(classes[i] == 'default'){
			classes.splice(i,1);
		}else{
			class+= classes[i] + ' ';
		}
		*/
		if(classes[i] != 'default'){
			c = c + ' ' + classes[i];
		}
	}
	if(target.value == q){
		target.className = c;
		target.value = '';
	}
}

function addTag(){
	tags = document.getElementById('ItemTags').value;
	tagAry = tags.split(',');// 配列化
	tagAry = uniqueArray(tagAry);// 重複したタグの削除
	
	// カテゴリを削除
	if(arguments.length > 1){
		for(n = 1; n < arguments.length; n++){
			for(i = 0; i < tagAry.length; i++){
				if(tagAry[i] == arguments[n]){
					tagAry.splice(i,1);
				}
			}
		}
	}
	/*
	tags.push(arguments[0]);// カテゴリの追加
	tagAry = uniqueArray(tagAry);// 重複したタグの削除
	*/
	tags = tagAry.toString();// 文字列に変換
	document.getElementById('ItemTags').value = arguments[0] + ',' + tags;// インプットフォームに戻す
}

function uniqueArray(array) {
    var storage = {};
    var uniqueArray = [];
 
    var i, value;
    for (i = 0; i < array.length; i++) {
        value = array[i];
        if (!(value in storage)) {
            storage[value] = true;
            uniqueArray.push(value);
        }
    }
 
    return uniqueArray;
}

document.observe('dom:loaded',function(){
	
	var relative = new Control.Window($(document.body).down('[href=#open]'),{
		position: 'relative',
		className: 'menu',
		closeOnClick: true,
		offsetTop: 25
	});
	relative.container.insert($('menu'));
	
	var areaSetupWindow = new Control.Window($(document.body).down('[href=#location]'),{
		className    : 'normal-window',
		closeOnClick : 'area-close',
		closeOnClick : 'layout',
		beforeOpen   : showAreaWindow
	});
});

function showAreaWindow(){
	$("area-response").hide();
	$("area-indicator").show();
	new Ajax.Updater('area-response','/local/area_setup', {
		asynchronous:true,
		evalScripts:true,
		onComplete:function(request, json) {
			$("area-response").show();
			$("area-indicator").hide()
		}, 
		method:'get',
		requestHeaders:['X-Update', 'area-response']
	})
}

