
function Application(){
	
	Application.server = "spookserver";
};


Application.cacheToObject = function(command, cache){
	return cache;
};


Application.loaded = function(loader){
	switch(loader.command){
		
	}
};



Application.start = function(){
	if(typeof ActionCondition != "undefined"){
		ActionCondition.onStart();
	}
	Application.onStart();
};

Application.destroy = function(){
	if(typeof Primrose != "undefined"){
		Primrose.clearAll();
	}
	if(typeof ActionCondition != "undefined"){
		ActionCondition.destroy();
	}
	Application.onDestroy();
};

Application.onStart = function(){};
Application.onDestroy = function(){};

Application.fireEvent = function(eventId){
	switch(eventId){
		
	}
};

new Application;

if(typeof DONOT_USE_DOCUMENT_READY == "undefined"){
	
	(function(){
		var isReady = false;
		var isopera = window.opera;
		var ismsie = navigator.userAgent.match(/MSIE/);
		var issafari = navigator.userAgent.match(/Safari/);
		var tryfunc;
		var readyfunc = function(){
			if(isReady) return;
			isReady = true;
			Application.start();
		}
		
		if ( document.addEventListener && !isopera)
			
			document.addEventListener( "DOMContentLoaded", readyfunc, false );
	
		
		
		if ( ismsie && window == top ) {
			tryfunc = function(){
				if (isReady) return;
				try {
					
					
					document.documentElement.doScroll("left");
				} catch( error ) {
					setTimeout( tryfunc, 0 );
					return;
				}
				
				readyfunc();
			};
			tryfunc();
		}

		if ( isopera ){
			tryfunc = function () {
				if (isReady) return;
				for (var i = 0; i < document.styleSheets.length; i++)
					if (document.styleSheets[i].disabled) {
						setTimeout( tryfunc, 0 );
						return;
					}
				
				readyfunc();
			}
			
			document.addEventListener( "DOMContentLoaded", tryfunc, false);
		}
		
		if ( issafari ) {
			var numStyles;
			tryfunc = function(){
				if (isReady) return;
				if ( document.readyState != "loaded" && document.readyState != "complete" ) {
					setTimeout( tryfunc, 0 );
					return;
				}
				if ( numStyles === undefined )
					numStyles = (function(){
						var es = document.getElementsByTagName("style"), ret = 0;
						ret += es.length;
						es = document.getElementsByTagName("link");
						for(var i=0; i<es.length; i++){
							if(es[i].rel == "stylesheet"){
								ret++;
							}
						}
						return ret;
					})();
				if ( document.styleSheets.length != numStyles ) {
					setTimeout( tryfunc, 0 );
					return;
				}
				
				readyfunc;
			};
		}

		
		if (typeof window != "undefined") {
			if(window.addEventListener){
				window.addEventListener("load", readyfunc, false);
				window.addEventListener("unload", Application.destroy, false);
			}else if(window.attachEvent){
				window.attachEvent("onload", readyfunc);
				window.attachEvent("onunload", Application.destroy);
			}
		}
	})();
}else{
	if (typeof window != "undefined") {
		if(window.addEventListener){
			window.addEventListener("load", Application.start, false);
			window.addEventListener("unload", Application.destroy, false);
		}else if(window.attachEvent){
			window.attachEvent("onload", Application.start);
			window.attachEvent("onunload", Application.destroy);
		}
	}
}


function undefined(val){return (typeof val == "undefined");};
function _undef(val){return (typeof val == "undefined");};

function ext(child, parent){
	var tmp = function(){};
	tmp.prototype = parent.prototype;
	child.prototype = new tmp();
};

if(undefined(Array.prototype.push)){
	Array.prototype.push = function(val){
		this[this.length] = val;
	}
}

var $emptyFunction = function(){};



function Primrose(){
	var Cache = new Object();
	var Queue = new Object();
	
	var doGet = false;
	if(navigator.userAgent.match(/MSIE/) && typeof encodeURIComponent == "function"){
		
		
		doGet = true;
	}else if(window.opera && (!(new XMLHttpRequest()).setRequestHeader)){
		
		doGet = true;
	}
	Primrose.doGet = doGet;
	var e;
	if(typeof encodeURIComponent == "function"){
		e = encodeURIComponent;
	}else{
		e = function(s){
			
			
			return (!s ? null : s.replace(/%/g, "%25").replace(/=/g, "%3D").replace(/&/g, "%26"));
		}
	}
	Primrose.encode = e;
	
	Primrose.Loader = function(command){
		var d = this;
		d.request = d.createRequest();
		d.command = command;
		d.callback = Application.loaded;
		d.cacheMapping = Application.cacheToObject;
	}
	
	
	var lp = Primrose.Loader.prototype;
	
	
	lp.load = function(params){
		if(this.request == null) return;
		if(params instanceof Array){
			
			
			
			var hash = {};
			for(var i=0, l=params.length; i<l; i++){
				var pos, p = params[i];
				if((pos = p.indexOf("=")) > -1){
					hash[p.substr(0, pos)] = p.substr(pos+1);
				}
			}
			params = hash;
		}
		params = (params || {});
		params.Command = this.command;
		params.RequestType = "PerAttribute";
		params.Protocol = "com.forcia.spook.honeybee.Primrose";
		
		this.params = params;
		var self = this;
		var isComplete = false; 
		this.request.onreadystatechange = function(){
			if(isComplete)return;
			if(self.request.readyState == 4)isComplete = true;
			if(self.isReady()){
				if(!self.isValid()){
					return;
				}
				if(self.isSuccess()){
					isComplete = true;
					self.onComplete();
				}else if(self.isHTTPError()){
					
					alert("[" + self.request.status + "]\n" + self.command + "でデータの取得に失敗しました");
				}else{
					

				}
			}
		}
		Primrose.register(this, this.command);
		this.send();
	};
	
	lp.createRequest = function(){
		if( window.XMLHttpRequest ) {
			try {
				return new XMLHttpRequest();
			} catch( e ) {
				alert(LoadErrorMessage + "(XMLHttpRequest)");
			}
		} else if( window.ActiveXObject ) {
			try {
				return new ActiveXObject( "Msxml2.XMLHTTP" );
			} catch( e0 ) {
				try {
					return new ActiveXObject( "Microsoft.XMLHTTP" );
				} catch( e1 ) {
					alert(LoadErrorMessage + "(ActiveXObject)");
				}
			}
		} else {
			alert(LoadErrorMessage + "(createRequest)");
		}
		return null;
	};

	
	lp.send = function(){
		var req = this.request;
		var query;
		if(Primrose.doGet){
			this.params.ParamEncoding = "UTF-8";
			query = this.query();
			req.open("GET", Application.server + "?" + query, true);
			req.send();
		}else{
			query = this.query();
			req.open("POST", Application.server, true);
			req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			req.send(query);
		}
	}
	
	lp.query = function(){
		var buf = [];
		var params = this.params;
		var enc = Primrose.encode;
		for(var key in params){
			buf.push(enc(key) + "=" + enc(params[key]));
		}
		
		buf.push("Date=" + (new Date()).getTime());
		return buf.join("&");
	}


	lp.isReady = function(){
		return (this.request.readyState == 4);
	};

	lp.isSuccess = function(){
		return (this.request.status == 200 || this.request.statusText == "OK");
	};
	
	lp.isHTTPError = function(){
		return (400 <= this.request.status && this.request.status < 600);
	};

	lp.isValid = function(){
		return (Primrose.validLoader(this.command) == this);
	};
	
	
	lp.onComplete = function(){
		var nodes = this.request.responseXML.documentElement.childNodes;
		var cache = new Array();
		for(var i=0, l=nodes.length; i<l; i++){
			cache[i] = {
				type: nodes.item(i).getAttribute("type"),
				data: (
					nodes.item(i).firstChild ? 
					nodes.item(i).firstChild.nodeValue.split("\n") : 
					[]
				)
			}
			if(cache[i].data[0] == "ERROR"){
				this.isError = true;
			}
		}
		Primrose.setCache(this.command, this.cacheMapping(this.command, cache));
		this.callback(this);
	};
	
	lp.destroy = function(){
		var r = this.request;
		if(r && r.readyState != 0){
			this.request.onreadystatechange = $emptyFunction;
			this.request.abort();
		}
	};
	
	Primrose.register = function(loader, command){
		if(!undefined(Queue[command]) && Queue[command] != null){
			Queue[command].destroy();
		}
		Queue[command] = loader;
	};
	
	Primrose.validLoader = function(command){
		return Queue[command];
	};
	
	Primrose.clear = function(command){
		Queue[command] = null;
	};
	
	Primrose.setCache = function(command, mappedObject){
		Cache[command] = mappedObject;
	};
	Primrose.getCache = function(command){
		return Cache[command];
	};
	
	Primrose.clearAll = function(){
		for(var com in Queue){
			if(!undefined(Queue[com]) && Queue[com] != null){
				Queue[com].destroy();
				Queue[com] = null;
			}
		}
		
		for(var com in Cache){
			delete Cache[com];
			Cache[com] = null;
		}
	};
	
	Primrose.setMethod = function(str){
		if(!str || !str.match)return;
		if(str.match(/GET/i)) Primrose.doGet = true;
		if(str.match(/POST/i)) Primrose.doGet = false;
	}
}

new Primrose();


function Client() {
	
	
	var userAgent = navigator.userAgent.toLowerCase();
	var appName = navigator.appName.toLowerCase();
	var appVersion = navigator.appVersion.toLowerCase();
	var isX11 = matchUA("x11");
	
	
	this.isWindows = matchUA("win");
	this.isWindows95 = matchUA("win95") || matchUA("windows 95");
	this.isWindows98 = matchUA("win98") || matchUA("windows 98");
	this.isWindowsMe = matchUA("win 9x 4.90");
	this.isWindows2K = matchUA("windows nt 5.0") || matchUA("windows 2000");
	this.isWindowsXP = matchUA("windows nt 5.1") || matchUA("windows xp");
	
	this.isMac = matchUA("mac");
	this.isMacOS9 = this.isMac && (matchUA("os 9") || matchUA("os9"));
	this.isMacOSX = this.isMac && (matchUA("os x") || matchUA("osx"));
	
	this.isLinux = isX11 && matchUA("linux");
	
	this.isUnix = isX11 && !this.isLinux;	
	
	if (window.opera) {
		
		this.isOpera = true;
		this.BrowserVersion = getBrowserVersion(userAgent, "opera");
	} else if (matchUA("safari")) {
		
		this.isSafari = true;
		var b = parseFloat(getBrowserVersion(userAgent, "safari"));
		if (b > 86 && b < 100) {
			this.BrowserVersion = 0.8;
		} else if (b < 120) {
			this.BrowserVersion = 1;
		} else if (b < 310) {
			this.BrowserVersion = 1.2;
		} else if (b < 410) {
			this.BrowserVersion = 1.3;
		} else if (b < 500) {			
			this.BrowserVersion = 2.;
		} else if (b < 600) {
			this.BrowserVersion = 3.;
		} else {
			this.BrowserVersion = 0;
		}
	} else if (appName && appName == "microsoft internet explorer") {
		
		this.isIE = true;
		this.BrowserVersion = getBrowserVersion(userAgent, "msie");
	} else if ((navigator.vendor && navigator.vendor.toLowerCase() == "firefox") || (navigator.userAgent && navigator.userAgent.match(/firefox/i))) {
		
		this.isFirefox = true;
		this.BrowserVersion = getBrowserVersion(userAgent, "firefox");
	} else if (appName && appName == "netscape" && matchUA("netscape")) {
		
		this.isNetscape = true;
		if (appVersion) {
			appVersion = parseFloat(appVersion);
			if (appVersion < 5) {
				this.BrowserVersion = appVersion;
			} else if (typeof navigator.vendorSub != "undefined") {
				this.BrowserVersion = parseFloat(navigator.vendorSub);
			}
		}
	} else if (getBrowserVersion(userAgent, "rv:", 0) >= 1.2) {
		
		this.isMozilla = true;
		this.BrowserVersion = getBrowserVersion(userAgent, "rv:", 0);
	}	
	
	function getBrowserVersion(ua, name, isText) {
		var pos = ua.indexOf(name);
		if (pos != -1) {
			pos += name.length;
			var buf = "", pt = 0, c;
			while (pos < ua.length) {
				c = ua.charAt(pos);
				if (" :/".indexOf(c) == -1 || buf.length > 0) {
					if (c == "-" && buf.length == 0 || c == "." && !pt++ || "0123456789".indexOf(c) != -1) {
						buf += c;
					} else if (c == ".") {
						
					} else {
						break;
					}
				}
				pos++;
			}
			if (buf.length > 0) return (isText ? buf : parseFloat(buf));
		}
		return 0;
	}
	function matchUA(txt) {
		return userAgent.indexOf(txt) != -1;
	}
}

Client.prototype.isOK = function() {
	var d = this;
	var b = d.BrowserVersion;
	return (

		(d.isWindows)
			&& (
				d.isIE && b >= 5
				|| d.isNetscape && b >= 7.
				|| d.isFirefox && b >= 0.8
				|| d.isOpera && b >= 8.
				|| d.isMozilla && b >= 1.4
				|| d.isSafari && b >= 2.
			)
		|| d.isMac
			&& (
				d.isSafari && b >= 1.2
				|| d.isNetscape && b >= 7.
				|| d.isFirefox && b >= 0.8
				|| d.isOpera && b >= 8.
				|| d.isMozilla && b >= 1.4
			)
	);
}

var client = new Client();




function Config(){
	Config.Attributes = {};
};

new Config();


Config.columnMapping = function(command, cache){
	var obj = new Object();
	var index = 0;
	var attr = this.Attributes[command];
	for(var i=0, l=attr.length; i<l; i++){
		if(index >= cache.length) break;
		if(typeof attr[i] == "object"){
			obj[attr[i].name] = new Object();
			for(var j=0, m=attr[i].attribute.length; j<m; j++){
				obj[attr[i].name][attr[i].attribute[j]] = cache[index++].data;
			}
		}else{
			obj[attr[i]] = cache[index++].data;
		}
	}
	return obj;
};



Config.rowMapping = function(command, cache){
	var obj = new Object();
	var index = 0;
	var attr = Config.Attributes[command];
	for(var i=0, l=attr.length; i<l; i++){
		if(typeof attr[i] == "object"){
			if(index + attr[i].attribute.length > cache.length) break;
			obj[attr[i].name] = new Array();
			for(var j=0, m=cache[index].data.length; j<m; j++){
				obj[attr[i].name][j] = new Object();
				for(var k=0, n=attr[i].attribute.length; k<n; k++){
					obj[attr[i].name][j][attr[i].attribute[k]] = cache[index+k].data[j];
				}
			}
			index += attr[i].attribute.length;
		}else{
			if(index >= cache.length) break;
			obj[attr[i]] = cache[index++].data;
		}
	}
	return obj;
};


Config.ConditionDelimiter = "|";
Config.CategoryDelimiter =  ">";
Config.MultiSelectDelimiter = "-";



if (typeof _undef != "function") {
	_undef = function (val){return (typeof val == "undefined");};
}

function getElement(id){return document.getElementById(id);};
var $gel = getElement;

function setElementPropertyById(id, ary_property, value) {
	setElementProperty(getElement(id), ary_property, value);
};
function setElementProperty(e, ary_property, value) {
	if (e) {
		for (var i=0; i<ary_property.length-1; i++)
			if (e[ary_property[i]]) e = e[ary_property[i]];
		var p = ary_property[ary_property.length - 1];
		if (p == 'cursor' && client.isIE && client.BrowserVersion<5.5) return;
		if (e && !_undef(e[p]))
			e[p] = value;
	}
};
function getElementPropertyById(id, ary_property) {
	return getElementProperty(getElement(id), ary_property);
};
function getElementProperty(e, ary_property) {
	if (e) {
		for (var i=0; i<ary_property.length-1; i++)
			if (e[ary_property[i]]) e = e[ary_property[i]];
		if (e && !_undef(e[ary_property[ary_property.length-1]])) {
			return e[ary_property[ary_property.length-1]];
		} else {
			return null;
		}
	} else {
		return null;
	}
};
function getParentElement(e) {
	if (e.parentElement) {
		return e.parentElement;
	} else if (e.parentNode) {
		return e.parentNode;
	} else {
		return null;
	}
};

function getElementPosition(elem) {
	var offsetTrail;
	if (typeof elem == "string") {
		offsetTrail = document.getElementById(elem);
	} else {
		offsetTrail = elem;
	}
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && 
		!_undef(document.body.leftMargin)) {
		offsetLeft += parseInt(document.body.leftMargin);
		offsetTop += parseInt(document.body.topMargin);
	}
	return {left:offsetLeft, top:offsetTop};
};


function getWindowHeight(w) {
	if (!_undef(w.innerHeight)) {
		return w.innerHeight
	} else if (!_undef(w.document.documentElement) && !_undef(w.document.documentElement.clientHeight) && w.document.documentElement.clientHeight > 0) {
		return w.document.documentElement.clientHeight
	} else if (!_undef(w.document.body)) {
		return w.document.body.clientHeight
	}
	return 0
};

function getWindowWidth(w) {
	if (!_undef(w.innerWidth)) {
		return w.innerHeight
	} else if (!_undef(w.document.documentElement) && !_undef(w.document.documentElement.clientWidth) && w.document.documentElement.clientWidth > 0) {
		return w.document.documentElement.clientWidth;
	} else if (!_undef(w.document.body)) {
		return w.document.body.clientWidth;
	}
	return 0
};


function getWindowScrollX(){

	if(navigator.userAgent.match(/MSIE/)){
		var scrollLeft  = document.body.scrollLeft;
		if (!scrollLeft) scrollLeft = document.documentElement.scrollLeft;
		return scrollLeft;
	}else{
		return window.pageXOffset;
	}
};

function getWindowScrollY(w){

	if(navigator.userAgent.match(/MSIE/)){
		var scrollTop  = document.body.scrollTop;
		if (!scrollTop) scrollTop = document.documentElement.scrollTop;
		return scrollTop;
	}else{
		return window.pageYOffset;
	}
};


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	return {width: pageWidth, height: pageHeight};
}




function createDOMElement(elementName, obj_attribute) {
	var e = document.createElement(elementName);
	var isIE = (typeof client == 'undefined' ? isInternetExplorer : client.isIE);
	if (obj_attribute) {
		for (var name in obj_attribute) {
			var value = obj_attribute[name];
			if (isIE && name == 'class') name = 'className';
			if (!isIE && name == 'innerHTML') {
				e.innerHTML = value;			
			} else {
				e.setAttribute(name, value);
			}
		}
	}
	return e
}
function removeAllChildren(elm) {
	while (elm.firstChild) {
		elm.removeChild(elm.firstChild);
	}
}
function removeSubsequentSiblings(elm) {
	var p = elm.parentNode, e, ret = new Array();
	while (e = elm.nextSibling) {
		ret.push(p.removeChild(e));
	}
	return ret;
}
function getChildElementsArray(elm, func) {
	var ary = new Array();
	for (var child = elm.firstChild; child; child = child.nextSibling) {
		extractChildElements(child, func, ary)
	}
	return ary;
}
function extractChildElements(elm, func, ary) {
	if (func(elm)) ary[ary.length] = elm;
	for (var child = elm.firstChild; child; child = child.nextSibling) {
		extractChildElements(child, func, ary)
	}
}
function _insertAfter(newElm, targetElm) {


	if (targetElm.nextSibling) {
		targetElm.parentNode.insertBefore(newElm, targetElm.nextSibling);
	} else {
		targetElm.parentNode.appendChild(newElm);
	}
	return newElm;
}

function getFirstChildElement(elm, func) {
	for (var child = elm.firstChild; child; child = child.nextSibling) {
		if (func(child)) return child;
	}
	return null;
}

function getFirstParentElement(elm, func) {
	elm = elm.parentNode;
	while (elm) {
		if (func(elm)) return elm;
		elm = elm.parentNode;
	}
	return null;
}

function hasClassName(elm, className) {
	if (elm == null || elm.className == null) return false;
	var c = elm.className.split(" ");
	for (var i=0, l=c.length; i<l; i++) {
		if (c[i] == className) return true
	}
	return false
}

function getScrollTop() {
	var scrollTop  = document.body.scrollTop;
	if (!scrollTop) scrollTop = -1 * document.documentElement.scrollTop;	
	return scrollTop;
}
function setScrollTop(scrollTop) {
	if (scrollTop) {
		if (scrollTop < 0) {
			
			document.documentElement.scrollTop = -1 * scrollTop;
		} else {
			document.body.scrollTop = scrollTop;
		}
	}
}

function getEventObject(evt) {
	return (evt ? evt : (window.event ? event : null));
};
function getSourceElement(evt) {
	return (evt.srcElement ? evt.srcElement : (evt.target ? evt.target : null));
};
function getToElement(evt) {
	return (evt.relatedTarget ? evt.relatedTarget: (evt.toElement ? evt.toElement : null));
};
function getFromElement(evt) {
	return (evt.relatedTarget ? evt.relatedTarget: (evt.fromElement ? evt.fromElement : null));
};
function getMousePositionX(evt) {
	if (typeof evt.clientX != "undefined") {
		return evt.clientX + getWindowScrollX();
	} else if (typeof evt.pageX != "undefined") {
		return evt.pageX;
	} else {
		return null;
	}
};
function getMousePositionY(evt) {
	if (typeof evt.clientY != "undefined") {
		return evt.clientY + getWindowScrollY();
	} else if (typeof evt.pageY != "undefined") {
		return evt.pageY;
	} else {
		return null;
	}
};
function _addEventListener(targetElement, eventType, listener, useCapture) {
	try {
		if (targetElement.addEventListener) {
			targetElement.addEventListener(eventType, listener, useCapture);
			if (eventType == "click") targetElement.onclick = function() {return false}
		} else if (targetElement.attachEvent) {
			var func = function(evt) {
				listener(evt);
				return false
			};
			targetElement.attachEvent("on" + eventType, func)
		}
		return true;
	} catch(e) {return false}
};


function HTMLTable(attr){
	this.attr = (attr || "");
	this.tbody_attr = null;
	this.cells = new Array();
	this.rattr = new Array();
	this.h = -1;
	this.w = -1;
	this.emptyCell = {content:"&nbsp;", attr:null};
	this.hasHeader = false;
};

HTMLTable.prototype.TableCell = function(content, attr, isHeader){
	this.content = content;
	this.attr = (attr || "");
	this.isHeader = isHeader
};

HTMLTable.prototype.fillCells = function(r, c) {
	var x = this.cells;
	if(this.h < r){
		for(var i=this.h; i<r; i++){
			x[i+1] = new Array();
			for(var j=-1; j<this.w; j++){
				x[i+1][j+1] = new this.TableCell(this.emptyCell.content, this.emptyCell.attr);
			}
		}
		this.h = r;
	}
	if(this.w < c){
		for(var i=this.w; i<c; i++){
			for(var j=-1; j<this.h; j++){
				x[j+1][i+1] = new this.TableCell(this.emptyCell.content, this.emptyCell.attr);
			}
		}
		this.w = c;
	}
}

HTMLTable.prototype.setCell = function(r, c, content, attr, isHeader){			
	this.fillCells(r, c);
	var x = this.cells;
	if (undefined(content)) content = this.emptyCell.content;
	if (undefined(attr)) attr = this.emptyCell.attr;
	x[r][c] = new this.TableCell(content, attr, isHeader);
};

HTMLTable.prototype.getCell = function(r, c){
	if (c <= this.w && r <= this.h) {
		return this.cells[r][c];
	} else {
		return null;
	}
};

HTMLTable.prototype.collapseC = function(r, c, num){
	this.fillCells(r, c+num-1);
	var x = this.cells;
	x[r][c].attr += " colspan='" + num + "'";
	for(var i=1; i<num; i++){
		x[r][c+i].collapsed = true;
	}
}

HTMLTable.prototype.collapseR = function(r, c, num){
	this.fillCells(r+num-1, c);
	var x = this.cells;
	x[r][c].attr += " rowspan='" + num + "'";
	for(var i=1; i<num; i++){
		x[r+i][c].collapsed = true;
	}
}

HTMLTable.prototype.collapseRC = function(r, c, rnum, cnum){
	this.fillCells(r+rnum, c+cnum);
	var x = this.cells;
	x[r][c].attr += " rowspan='" + rnum + "' colspan='" + cnum + "'";
	for(var i=1; i<rnum; i++){
		for (var j=1; j<cnum; j++) {
			x[r+i][c+j].collapsed = true;
		}
	}
}

HTMLTable.prototype.setRowAttr = function(r, attr){
	this.rattr[r] = attr;
};

HTMLTable.prototype.setTBodyAttr = function(attr){
	this.tbody_attr = attr;
};

HTMLTable.prototype.toHTML = function(){
	var x = this.cells;
	var ra = this.rattr;
	var buf = new Array(this.w*this.h);
	buf[0] = "<table " + this.attr + ">";
	var idx = 1;
	if (this.tbody_attr) buf[idx++] = "<tbody " + this.tbody_attr + ">";

	var tagName;
	for (var r=-1, h=this.h; r<h; r++){
		buf[idx++] = "<tr" + (undefined(ra[r+1]) ? "" : " " + ra[r+1]) + ">";
		tagName = (this.hasHeader && r == -1 ? "th" : "td");
		for(var c=-1, w=this.w; c<w; c++){
			if(!x[r+1][c+1].collapsed) {
				buf[idx++] = "<" + (x[r+1][c+1].isHeader ? "th" : tagName) + " " + x[r+1][c+1].attr + ">" + x[r+1][c+1].content + "</" + (x[r+1][c+1].isHeader ? "th" : tagName) + ">";
			}
		}
		buf[idx++] = "</tr>";
	}
	if (this.tbody_attr)buf[idx++] = "</tbody>";
	buf[idx++] = "</table>";
	return buf.join("");
};



function ActionCondition(){
	ActionCondition.groups = new Object();
	ActionCondition.started = false;
	ActionCondition.history = new Array();
};
new ActionCondition();

ActionCondition.switchLoader = function(loader){
	this.Loader = loader;
};

ActionCondition.register = function(group){
	this.groups[group.id] = group;
	if(this.started){
		group.onStart();
	}
};

ActionCondition.onStart = function(){
	var gs = this.groups;
	for(i in gs){
		gs[i].onStart();
	}
	this.started = true;
};

ActionCondition.getConditionString = function(){
	var buf = new Array();
	for(var i in this.groups){
		var str = this.groups[i].getConditionString();
		if(str != null) buf[buf.length] = str;
	}
	return (buf.length == 0 ? "" : "Condition=" + buf.join(Config.ConditionDelimiter));
};

ActionCondition.update = function(command, ex_param){
	if(undefined(this.Loader)){
		this.Loader = Primrose.Loader;
	}
	var loader = new this.Loader(command);
	ex_param = (ex_param || []);
	loader.load([ActionCondition.getConditionString()].concat(ex_param));
};

ActionCondition.getGroup = function(id){
	return this.groups[id];
};

ActionCondition.removeCondition = function(group_id, item_id){
	this.groups[group_id].remove(item_id);
};

ActionCondition.removeAll = function(){
	var gs = this.groups;
	for(var i in gs){
		gs[i].removeAll();
	}
};

ActionCondition.destroy = function(){
	var gs = this.groups;
	for(var i in gs){
		gs[i].onDestroy();
		gs[i] = null;
	}
};

ActionCondition.pushHistory = function(group_id, item_id){
	var h  = this.history;
	if(h.length == 10){
		for(var i=0; i<9; i++){
			h[i] = h[i+1];
		}
		h.length--;
	}
	h.push({group: group_id, item: item_id});
};

ActionCondition.popHistory = function(){
	var h = this.history;
	if(h.length > 0){
		var o = h[h.length-1];
		h.length--;
		return o;
	}else{
		return null;
	}
};





function isArray(ary) {
	if (!ary) return false;
	if (ary.constructor == Array) return true;
	if (typeof ary != typeof new Array()) return false;
	if (typeof ary.length != typeof 1 || !ary.sort) return false;
	return true;
}

function array_pop(ary, num) {
	var ret = new Array();
	if (num <= 0) return ret;
	var len = ary.length;
	if (num > len) num = len;
	for (var i=len-num; i<len; i++) {
		ret[ret.length] = ary[i];
	}
	ary.length = len - num;
	return ret;
}

function array_push(ary, item) {
	var a = new Array();
	if (isArray(item)) {
		a = item;
	} else {
		a[0] = item;
	}
	var aryLen = ary.length;
	var len = aryLen + a.length;
	for (var i=aryLen; i<len; i++) {
		ary[i] = a[i - aryLen];
	}
	return ary;
}

function array_shift(ary, num) {
	var ret = new Array();
	if (num <= 0) return ret;
	var len = ary.length;
	if (num > len) num = len;
	for (var i=0; i<len; i++) {
		if (i < num) {
			ret[i] = ary[i];
		} else {
			ary[i-num] = ary[i];
		}
	}
	ary.length = len - num;
	return ret;
}

function array_unshift(ary, item) {
	var a = new Array();
	if (isArray(item)) {
		a = item;
	} else {
		a[0] = item;
	}
	var len = a.length;
	ary.length = ary.length + len;
	for (var i=ary.length - 1; i>=0; i--) {
		if (i < len) {
			ary[i] = a[i];
		} else {
			ary[i] = ary[i-len];
		}
	}
	return ary;
}


function array_removeItem(ary, item) {
	var rmv = 0;
	var len = ary.length;
	for (var i=0; i<len; i++) {
		if (ary[i] == item) {
			rmv++
		} else {
			ary[i-rmv] = ary[i];
		}
	}
	ary.length = len - rmv;
	return rmv;
}


function array_findItem(ary, item) {
	for (var i=0; i<ary.length; i++) if (ary[i] == item) return i;
	return -1;
}


function array_sub(ary, from, count) {
	var ret = new Array();
	for (var i=from; i<from + count && i<ary.length; i++) {
		ret[ret.length] = ary[i];
	}
	return ret;
}


function array_insert(ary, ary_in, from){
	var ret = new Array();
	var offset = ary_in.length;
	for(var i=0, l=ary.length; i<l; i++){
		if(from <= i){
			ret[offset+i] = ary[i]
		}else{
			ret[i] = ary[i];
		}
	}
	for(var i=0; i<offset; i++){
		ret[from+i] = ary_in[i];
	}
	return ret;
}


function array_remove(ary, from, count){
	var ret = new Array(ary.length - count);
	var i=0;
	for(; i<from; i++){
		ret[i] = ary[i];
	}
	var j=i;
	i += count;
	for(var l=ary.length; i<l; i++){
		ret[j++] = ary[i];
	}
	return ret;
}


function array_insertx(ary, ary_in, from){
	var l = ary_in.length;
	ary.length = ary.length + l;
	for (var i=ary.length-1; i>=from; i--) {
		if (i-from < l) {
			ary[i] = ary_in[i-from];
		} else {
			ary[i] = ary[i-l];
		}
	}
	return ary;
}


function array_removex(ary, from, count){
	var l = ary.length;
	for (var i=from; i<l-count; i++) {
		ary[i] = ary[i+count];
	}
	ary.length = l - count;
	return ary;
}

Array.prototype.map = function(func){
	var ret = new Array();
	for (var i=0; i<this.length; i++) {
		ret.push(func(this[i], i));
	}
	return ret;
}

Array.prototype.grep = function(func){
	var ret = new Array();
	for (var i=0; i<this.length; i++) {
		if (func(this[i], i)) ret.push(this[i]);
	}
	return ret;
}





function sprintf(format) {
	var args = new Array();
	for (var i=1; i<sprintf.arguments.length; i++) args[i-1] = sprintf.arguments[i];
	var argIndex = 0;
	var ret = "";
	var formatPosition = 0;
	var chr, isFormat, fmtChar, alignLeft, headPositive, padZero, fieldSize, precisionSize, isPrecision, value, directiveSize;
	while (formatPosition < format.length) {
		chr = format.substr(formatPosition++, 1);
		if (chr != "%" || formatPosition == format.length) {
			ret += chr;
		} else {
			alignLeft = padZero = isPrecision = false;
			fieldSize = directiveSize = 0;
			precisionSize = -1;
			headPositive = "";
			isFormat = true;
			while (isFormat) {
				fmtChar = format.substr(formatPosition++, 1);
				directiveSize++;
				switch (fmtChar) {
					
					case " ":
						if (headPositive != "+") headPositive = " ";
						continue;
					case "+":
						headPositive = "+";
						continue;
					case "-":
						alignLeft = true;
						padZero = false;
						continue;
					case "0":
						if (fieldSize == 0 && precisionSize == -1) {
							if (!alignLeft) padZero = true;
							continue;
						}
					
					case "1": case "2": case "3": case "4": case "5":
					case "6": case "7": case "8": case "9":
						if (isPrecision) {
							precisionSize = (precisionSize<0 ? 0 : precisionSize) * 10 + parseInt(fmtChar);
						} else {
							fieldSize = fieldSize * 10 + parseInt(fmtChar);
						}
						continue;
					case ".":
						isPrecision = true;
						continue;
					case "*":
						if (isPrecision) {
							precisionSize = (argIndex < args.length ? parseInt(args[argIndex++]) : 0);
						} else {
							fieldSize = (argIndex < args.length ? parseInt(args[argIndex++]) : 0);
							if (fieldSize < 0) {
								alignLeft = true;
								fieldSize = -fieldSize;
							}
						}
						continue;
					
					case "c":
						value = (argIndex < args.length ? parseInt(args[argIndex++]) : 0);
						ret += String.fromCharCode(value);
						break;
					case "s":
						value = (argIndex < args.length ? args[argIndex++] : "");
						value = (value ? new String(value) : "");
						ret += formatString(value, alignLeft, fieldSize, precisionSize);
						break;
					case "d":
						value = (argIndex < args.length ? parseInt(args[argIndex++]) : 0);
						ret += formatNumber(value, 10, false, alignLeft, fieldSize, precisionSize, padZero, headPositive);
						break;
					case "o":
						value = (argIndex < args.length ? parseInt(args[argIndex++]) : 0);
						ret += formatNumber(value, 8, false, alignLeft, fieldSize, precisionSize, padZero, "");
						break;
					case "x": case "X":
						value = (argIndex < args.length ? parseInt(args[argIndex++]) : 0);
						ret += formatNumber(value, 16, (fmtChar == "X"), alignLeft, fieldSize, precisionSize, padZero, "");
						break;
					case "f":
						value = (argIndex < args.length ? parseFloat(args[argIndex++]) : 0);
						ret += formatFloat(value, alignLeft, fieldSize, precisionSize, padZero, headPositive);
						break;
					case "%":
						ret += fmtChar;
						break;
					default:
						if (directiveSize == 1) {
							ret += "%" + fmtChar;
						} else {
							
						}
						break;
				}
				isFormat = false;
			}
		}
		
		
		
	}
	return ret;
	
	function formatString(value, alignLeft, fieldSize, precisionSize) {
		var ret;
		var padString = "";
		
		if (precisionSize > 0 && value.length > precisionSize) {
			ret = value.substr(0, precisionSize);
		} else {
			ret = value;
		}
		for (var i=0; i<fieldSize - value.length; i++) padString += " ";
		if (alignLeft) {
			return ret + padString;
		} else {
			return padString + ret;
		}
	}
	function formatNumber(value, base, caps, alignLeft, fieldSize, precisionSize, padZero, headPositive) {
		var sign, unSigned, digitCount = 0, ret = "", padString = "";
		if (value == 0) {
			sign = "";
			unSigned = 0;
			ret = "0";
			digitCount = 1;
		} else if (value < 0) {
			sign = "-";
			unSigned = -value;
		} else {
			sign = headPositive;
			unSigned = value;
		}
		while (unSigned) {
			ret = ("0123456789" + (caps ? "ABCDEF" : "abcdef")).substr(unSigned % base, 1) + ret;
			unSigned = parseInt(unSigned / base);
			digitCount++;
		}
		while (digitCount < precisionSize) {
			ret = '0' + ret;
			digitCount++;
		}
		var padSize = fieldSize - digitCount - sign.length;
		for (var i=0; i<padSize; i++) padString += (padZero ? "0" : " ");
		if (alignLeft) {
			return sign + ret + padString;
		} else {
			return padString + sign + ret;
		}
	}
	function formatFloat(value, alignLeft, fieldSize, precisionSize, padZero, headPositive) {
		var sign, unSigned, digitCount = 0, ret = "", padString = "";
		if (value == 0) {
			sign = "";
			unSigned = 0;
		} else if (value < 0) {
			sign = "-";
			unSigned = -value;
		} else {
			sign = headPositive;
			unSigned = value;
		}
		var wholeNumber = parseInt(unSigned);
		var decimalNumber = getDecimalNumber(unSigned, 0);
		if (precisionSize == 0) {
			if (decimalNumber >= 0.5) wholeNumber++;
			decimalNumber = 0;
		}
		if (wholeNumber == 0) {
			ret = '0';
			digitCount = 1;
		} else {
			while (wholeNumber) {
				ret = new String(parseInt(wholeNumber) % 10) + ret;
				wholeNumber = parseInt(wholeNumber / 10);
				digitCount++;
			}
		}
		if (precisionSize > 0) {
			var p = Math.pow(10, precisionSize);
			decimalNumber = Math.round(decimalNumber * p) / p;
		}
		if (decimalNumber > 0) {
			ret += ".";
			digitCount++;
			var digitBase = digitCount;
			while (decimalNumber) {
				ret += new String(parseInt(decimalNumber * 10));
				decimalNumber = getDecimalNumber(decimalNumber, 1);
				digitCount++;
			}
			while (digitCount - digitBase < precisionSize) {
				ret += '0';
				digitCount++;
			}
		}
		var padSize = fieldSize - digitCount - sign.length;
		for (var i=0; i<padSize; i++) padString += (padZero ? "0" : " ");
		if (alignLeft) {
			return sign + ret + padString;
		} else {
			return padString + sign + ret;
		}
	}
	function getDecimalNumber(value, shift) {
		var str = new String(value);
		var idx = str.indexOf(".");
		var decimalString = str.substr(idx + 1 + shift);
		if (decimalString != "") {
			return "0." + decimalString;
		} else {
			return 0;
		}
	}
}
 



function DragElementObject2(
	containerId
	,dragHandleId
	,engageListener			
	,dragListener			
	,releaseListener		
	,cursor
) {
	this.setLimits = function(minDragX, maxDragX, minDragY, maxDragY) {	
		if (minDragX != null) MinDragX = InitialX + minDragX;
		if (maxDragX != null) MaxDragX = InitialX + maxDragX;
		if (minDragY != null) MinDragY = InitialY + minDragY;
		if (maxDragY != null) MaxDragY = InitialY + maxDragY;
	}
	this.setPosition = function(x, y) {
		if (ContainerElement && (IsInit || !(DragX == InitialX + x && DragY == InitialY + y))) {
			DragX = InitialX + x;
			DragY = InitialY + y;
			setElementProperty(ContainerElement, ["style", "left"], x + "px");
			setElementProperty(ContainerElement, ["style", "top"], y + "px");
			IsInit = false;
		}
	}
	
	var DragHandleElement = getElement(dragHandleId);
	DragHandleElement.onmousedown = engage;
	if(cursor)setElementProperty(DragHandleElement, ["style", "cursor"], cursor);
	var ContainerElement = getElement(containerId);
	var InitialX = 0, InitialY = 0, ContainerId;
	if (ContainerElement) {
		InitialX = parseInt(getElementProperty(ContainerElement, ["style", "left"]));
		if (isNaN(InitialX)) InitialX = 0;
		InitialY = parseInt(getElementProperty(ContainerElement, ["style", "top"]));
		if (isNaN(InitialY)) InitialY = 0;
		ContainerId = ContainerElement.id;
	}
	var Engaged = false;
	var MinDragX, MaxDragX, MinDragY, MaxDragY;
	var OffsetX, OffsetY, BaseX = 0, BaseY = 0;
	var DragX = 0, DragY = 0;
	var EngageListener = engageListener;
	var DragListener = dragListener;
	var ReleaseListener = releaseListener;
	var IsInit = true;
	
	function engage(evt) {
		evt = getEventObject(evt);
		if (!evt) return;

		if (ContainerElement) {
			BaseX = parseInt(getElementProperty(ContainerElement, ["style", "left"]));
			BaseY = parseInt(getElementProperty(ContainerElement, ["style", "top"]));
		}
		document.onmousemove = dragIt;
		document.onmouseup = release;
		if (document.body && document.body.setCapture) {
			document.body.setCapture();
		} else {
			document.onmouseout = release;
			if (window.opera) document.onmouseover = release;
		}
		OffsetX = getMousePositionX(evt);
		OffsetY = getMousePositionY(evt);
		Engaged = true;
		if (EngageListener) EngageListener(ContainerId, BaseX, BaseY, OffsetX, OffsetY);
		return false;
	}
	function dragIt(evt) {
		evt = getEventObject(evt);
		if (!evt) return;
		if (Engaged) {
			DragX = BaseX + (getMousePositionX(evt) - OffsetX);
			DragY = BaseY + (getMousePositionY(evt) - OffsetY);
			DragX = (typeof MinDragX != "undefined" && DragX < MinDragX ? MinDragX : (typeof MaxDragX != "undefined" && DragX > MaxDragX ? MaxDragX : DragX));
			DragY = (typeof MinDragY != "undefined" && DragY < MinDragY ? MinDragY : (typeof MaxDragY != "undefined" && DragY > MaxDragY ? MaxDragY : DragY));
			if (ContainerElement) {
				setElementProperty(ContainerElement, ["style", "left"], DragX + "px");
				setElementProperty(ContainerElement, ["style", "top"], DragY + "px");
			}
			evt.cancelBubble = true;
			if (DragListener) DragListener(ContainerId, DragX - InitialX, DragY - InitialY);
			return false;
		}
	}
	function release(evt) {
		evt = getEventObject(evt);
		if (!evt) return;
		if (Engaged && !getFromElement(evt)) {

			if (document.body && document.body.releaseCapture) {
				document.body.releaseCapture();
			} else {
				document.onmouseout = "";
			}
			document.onmousemove = "";
			document.onmouseup = "";
			Engaged = false;
			if (ReleaseListener) ReleaseListener(ContainerId, DragX - InitialX, DragY - InitialY);
		}
	}

}

var Debug = new Debug3Object();

function $T(t){
	var tt = new Object();
	tt.value = t;
	tt._is_tag_ = 1;
	return tt;
}

function Debug3Object() {
	this.setTextMode = function(mode) {
		TextMode = mode;
	}
	this.setStreamMode = function(mode) {
		StreamMode = mode;
	}
	this.setWindowTitle = function(title) {
		setElementPropertyById("DebugWindowTitle", ["innerHTML"], title);
	}
	this.setPosition = function(top, left, width, height) {
		if (top) Table_top = top;
		if (left) Table_left = left;
		if (width) Table_width = width;
		if (height) Table_height = height;
		var e = getElement('debugWrap');
		if (e) {
			e.style.top = Table_top + "px";
			e.style.left = Table_left + "px";
			e = getElement('debugContainer');
			e.style.width = Table_left + "px";
			e.style.height = Table_height + "px";
			e = getElement('changeCS');
			e.style.width = Table_width + "px";
			e.style.height = (Table_height + 20) + "px";
		}
	}
	this.write = function() {
		var ttt = new Object();
		ttt = Debug.write.arguments;
		_waitDebugWriteT(50,ttt);
	}
	this.writeT = function() {
		var ttt = new Object();
		ttt = Debug.writeT.arguments;
		_waitDebugWriteT(50,ttt);
	}
	this.writeW = function() {
		var l = Debug.writeW.arguments.length-1;
		if(Debug.writeW.arguments[l]._is_tag_){
			tempLiveW = Debug.writeW.arguments[l].value;
			ArgsShelterW= new Array();
			ArgsShelterW[0] = tempLiveW;
			for(var e=1;e<=l;e++){
				ArgsShelterW[e] = Debug.writeW.arguments[e-1];
			}
		}else{
			tempLiveW = LiveCount;
			LiveCount++;
			ArgsShelterW = Debug.writeW.arguments;
		}
		var td = openDebugWindow(tempLiveW); 
		ObjectModel = DebugWindow.document;
		if(!DebugStop){
			Writing(td, ArgsShelterW, false);
		}
	}
	this.startWriteT = function(arg) {
		var l = arg.length-1;
		if(arg[l] && arg[l]._is_tag_){
			tempLive = arg[l].value;
			DebugArgsShelter= new Array();
			DebugArgsShelter[0] = tempLive;
			for(var e=1;e<=l;e++){
				DebugArgsShelter[e] = arg[e-1];
				
			}
		}else{
			tempLive = LiveCount;
			LiveCount++;
			DebugArgsShelter = arg;
		}
		var td = openDebugTable(tempLive);
		ObjectModelT = document;
		if(!DebugStop) {
			Writing(td, DebugArgsShelter, true);
		}
	}
	function Writing(td, args, isT){
		var now = new Date();
		StartTime = (new Date()).getTime();
		var CurrentTimeStamp = now.getTime();
		var timeStamp = sprintf("%04d/%02d/%02d %02d:%02d:%-.3f",
			now.getFullYear(),
			(now.getMonth() + 1),
			now.getDate(),
			now.getHours(),
			now.getMinutes(),
			now.getSeconds() + now.getMilliseconds()/1000
		);
		var timer = "   " + (PreviousTimeStamp ? "Lap:" + commify(CurrentTimeStamp - PreviousTimeStamp) + ", Ttl:" + commify(CurrentTimeStamp - StartTimeStamp) : "START");
		var e, tempLiveLocal;
		if(isT){
			e = ObjectModelT.getElementById("debug_outertable");
			tempLiveLocal = tempLive;
		}else{
			e = ObjectModel.getElementById("debug_outertable");
			tempLiveLocal = tempLiveW;
		}
		var scrollTop = e.offsetHeight;
		ObjectStartCount = 0;
		
		if(!ObjectArray[tempLiveLocal]){
			ObjectArray[tempLiveLocal] = new Array();
			ObjectState[tempLiveLocal] = new Array();
			ObjectCount[tempLiveLocal] = new Array();
			for(var i=0; i<MaximumDebugLevel+2; i++){
				ObjectArray[tempLiveLocal][i] = new Array();
				ObjectState[tempLiveLocal][i] = new Array();
				ObjectCount[tempLiveLocal][i] = new Array();
			}
		}
		var html = (TextMode || StreamMode ? "" : "[" + timeStamp + "]" + timer + "------------------")
			+ "<table id='table"+tempLiveLocal+"' border=0 cellpadding=0 cellspacing=0 style='font-size:12px;width:100%;height:100%;' >";
		for(var i=0; i<args.length; i++){
			html += "<tr><td valign='top' nowrap>" + (StreamMode ? "" : "<pre>") + getDebugString(args[i],tempLiveLocal,0,i,isT) + (StreamMode ? "" : "</pre>") + "</td></tr>";
		}
		html += "</table>";
		td.innerHTML = html;
		if(isT){
		
		
		}else{
			if((NN||Fx)&& DebugWindow)ObjectModel.body.scrollTop = scrollTop;
			ObjectModel.getElementById("debugContainer").scrollTop = scrollTop;
		}
		if (!PreviousTimeStamp) StartTimeStamp = CurrentTimeStamp;
		PreviousTimeStamp = CurrentTimeStamp;
	}
				
	this.openNextObject = function(ObjectKind, tempLive, level, index, isT){
		StartTime = (new Date()).getTime();
		var ef, es;
		if(isT){
			ef = ObjectModelT.getElementById(ObjectKind + "font_" + tempLive + "_" + level + "_" + index);
			es = ObjectModelT.getElementById(ObjectKind + "_" + tempLive + "_" + level + "_" + index);
		}else{
			ef = ObjectModel.getElementById(ObjectKind + "font_" + tempLive + "_" + level + "_" + index);
			es = ObjectModel.getElementById(ObjectKind + "_" + tempLive + "_" + level + "_" + index);
		}
		var ary_properties = new Array();
		var o = ObjectArray[tempLive][level][index];
		if (o instanceof Array) {
			for (var i=0; i<o.length; i++) ary_properties[ary_properties.length] = i;
		} else {
			for (var x in o) ary_properties[ary_properties.length] = x;
		}
		ObjectStartCount=0;
		if(index>0){for(var i=0;i<index;i++)ObjectStartCount+=(ObjectCount[tempLive][level+1][i]? ObjectCount[tempLive][level+1][i]:0);ObjectStartCount++;}
		if(!ObjectState[tempLive][level][index]){
			ef.innerHTML = (ObjectKind=="array"? "ARRAY[":"OBJECT{");
			var html = "<table id='table_" + tempLive + "_" + level + "_" + index +"' style='border:solid 0px;font-size:12px;'>" ;
			if(ObjectKind=="array") ary_properties.sort(function (a,b){return a - b});
			else ary_properties.sort();
			for (var i=0; i<ary_properties.length; i++) {
				try{
					html += "<tr><td valign='top' nowrap>"
						+ "&nbsp;&nbsp;&nbsp;" + ((ObjectKind=="array")? "["+i+"]" :  ary_properties[i]) + ":"
						+ "</td><td valign='top'>"
						+ getDebugString(ObjectArray[tempLive][level][index][ary_properties[i]], tempLive, level+1, "", isT)
						+ "</td></tr>";
				}catch(e){}
			}
			html += "<tr><td>"+ ((ObjectKind=="array")? "]":"}") +"</td></tr></table>";
			es.innerHTML = html;
			ObjectState[tempLive][level][index] = true;
		}else{
			if(ObjectKind=="array") ef.innerHTML = "ARRAY[" + ary_properties.length + "]" ;
			if(ObjectKind=="object") ef.innerHTML = "OBJECT{" + ary_properties.length + "}" ;
			es.innerHTML = "";
			ObjectState[tempLive][level][index] = false;
			ObjectStartCount=0;
		}
	}
	
	var Fx = (window.navigator.userAgent.match(/firefox/i)) ? true:false;
	var NN = (window.navigator.userAgent.match(/Netscape/i)) ? true:false;
	var MaximumDebugLevel = 10;
	var DebugWindow;
	var DebugTable = false;
	var Drag;	
	var TimeLimit = 10;		
	var ObjectModel; 
	var ObjectModelT; 
	var ObjectStartCount;
	var StartTime = null;
	var StartTimeStamp = null;
	var PreviousTimeStamp = null;
	var DebugStop = false;
	var tempLive = 0;
	var ObjectArray = new Array();
	var ObjectState = new Array();
	var ObjectCount = new Array();
	var Table_top = 10;
	var Table_left = 300;
	var Table_width = 300;
	var Table_height = 300;
	var Table_bar = 50;
	var isVisibleContainer = true;
	var Table_BgColor = "#000099";
	var Window_width = 400;
	var Window_height = 300;
	var changeCS_color = "#999999";
	
	var tempLive;
	var tempLiveW;
	var LiveCount=1;
	var LiveCountW =1;
	var DebugArgsShelter;
	var ArgsShelterW;
	
	var Shim;			
	
	
	
	this.setTableDesign = function(height, width, top, left, bgcolor, change_bg){
		if(height) Table_height = height;
		if(width) Table_width = width;
		if(top) Table_top = top;
		if(left) Table_left = left;
		if(bgcolor) Table_BgColor = bgcolor;
		if(change_bg) changeCS_color = change_bg;
	}
	this.setWindowDesign = function(height, width){
		if(height) Window_width = height;
		if(width) Window_width = width;
	}
	function openDebugTable(tempLive) {
		if (!DebugTable ) {
			DebugTable = true;
			constructDebugTable();
			Drag = new DragElementObject2(
				"debugWrap", 			
				"debugMV"	
			
			
			
				,null
				,synchShim
				,null
			);
		
			_waitDebugWriteT2(500,'change');
		}
		var eTD = getElement("TD"+tempLive);
		if(eTD){
			return eTD;
		}
		setElementPropertyById("debugWrap",["style","visibility"],"visible");
		var tagTr, nLoop, tagTd;
		var e = getElement("debug_outertable");
		tagTr = document.createElement("TR");
		if(document.all && !window.opera) {
			e.childNodes[0].appendChild(tagTr);
		} else {
			e.appendChild(tagTr);
		}
		tagTd = document.createElement("TD");
		tagTd.setAttribute('id',"TD"+tempLive);
		tagTr.appendChild(tagTd);
		return tagTd;
	}
	function constructDebugTable() {
		var scrollTop = document.body.scrollTop;
		if (!scrollTop) scrollTop = 0;
		var scrollLeft = document.body.scrollLeft;
		if (scrollLeft) Table_left += scrollLeft;
		var html ="<div id='debugWrap' style='position:absolute;top:" + (Table_top + scrollTop) + "px;left:" + Table_left + "px;z-index:1000;visibility:visible;'>"
			+ "<table id='changeCS' cellpadding='0' cellspacing='2' style='border:solid 0px; width:" + Table_width + "px;height:" + Table_height + ";'>"
			+ "<tr><td colspan=2>"
			+ "<div id='change' style='width:100%;height:20px;position:relative;top:0px;left:0px;visibility:visible;'></div>"
			+ "</td></tr><tr>"
			+ "<td id='debugMV' style='height:20px;background-color:" + Table_BgColor + "'>"
				+ "<table border=0 cellpadding=0 cellspacing=0 width='100%' height='100%'>"
				+ "<tr>"
				+ "<td id='DebugWindowTitle' style='padding-left:5px;font-size:12px;font-weight:bold;;color:white;'></td>"
				+ "<td align='right' class='debug'>"
			
				+ (TextMode ? "" : "<input type='button' value='CLEAR' style='font-size:10px;' onClick='Debug.Refresh(1,true)'>")
				+ (TextMode ? "" : "<input type='button' id='changeSmall' value='　↑　' style='font-size:10px;' onClick='Debug.changeTableState(this)'>")
				+ "<input type='button' value='　×　' style='font-size:10px;' onClick='Debug.changeTableclose()'>"
			+ "</td></tr></table>"
				+ "</td>"
			+ "<td id='changeUR'  style='width:20px;background-color:" + Table_BgColor + ";position:relative;top:0px;left:0px;visibility:visible;'>"
			+ "</td></tr>"
			+ "<tr><td id='DebugTableTd' colspan=2 style='border:1px solid #333333;visibility:visible;background-color:#FFFFFF;'>"
			+ "<div id='debugContainer' style='padding:0px;overflow:scroll;width:" + Table_width + "px;height:" + (Table_height - 20) + "px'>"
			+ "<table id='debug_outertable' style='font-size:11px;border:solid 0px'></table>"
			+ "</div>"
			+ "</td></tr>"
			+ "<tr><td id='change_base' colspan=2 style='height:20px; visibility:visible; background-color:" + changeCS_color+ ";'>"
			+ "</td></tr>"
			+ "</table></div>";
		var container = document.createElement("DIV");
		container.innerHTML = html;
		document.body.appendChild(container);
		
		if (client && client.isIE && client.BrowserVersion >= 5.5) {
			Shim = document.createElement(
				"<iframe scrolling='no' frameborder='0' "
				+"style='background-color:#FF0000; position:absolute; top:0px; left:0px; display:none;filter:Alpha(Opacity=0);'>"
				+ "</iframe>"
			);
			document.body.appendChild(Shim);
			synchShim();
		}
	}
	function synchShim() {
		if (Shim) {
			var pos = getElementPosition("debugMV");
			if (pos) {
				Shim.style.top = pos.top + "px";
				Shim.style.left = pos.left + "px";
				Shim.style.width = (ContainerElement2 ? ContainerElement2 : getElement("debugContainer")).offsetWidth + 2 + "px";
				Shim.style.height = (ContainerElement ? ContainerElement : getElement("changeCS")).offsetHeight - 26 + "px";
				Shim.style.display = "block";
			}
		}
	}
	function openDebugWindow(tempLiveW) {
		var rtn;
		if (!DebugWindow || DebugWindow.closed) {
			DebugWindow = window.open("", "Debug", "width=" + Window_width + ",height=" + Window_height+ ",resizable=yes");
			constructDebugWindow();
		}
		var tagTr, nLoop, tagTd;
		var eTD = DebugWindow.document.getElementById("TD"+tempLiveW);
		if(eTD){
			return eTD;
		}
		var e = DebugWindow.document.getElementById("debug_outertable");
		tagTr = DebugWindow.document.createElement("TR");
		if(document.all && !window.opera){
			e.childNodes[0].appendChild(tagTr);
		}else{
			e.appendChild(tagTr);
		}
		tagTd = DebugWindow.document.createElement("TD");
		tagTd.setAttribute('id',"TD"+tempLiveW);
		tagTr.appendChild(tagTd);
		DebugWindow.focus();
		return tagTd;
	}
	function constructDebugWindow() {
			var html = ["<html><head><title>DEBUG</title>"
			, "<script language='javaScript' type='text/JavaScript'>"
			, "function polling() {"
			, "if (window.opener == null) {"
			, "		window.opener = true;"
			, "		window.close();"
			, "	} else {"
			, "		if (window.opener.closed) window.close();"
			, "	}"
			, "	setTimeout('polling()', 1000);"
			, "}"
			, "</script>"
			, "</head>"
			, "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 style='font-size:12px;' onLoad='polling()'>"
			, "<table cellpadding='0' cellspacing='10' style='border:solid 0px;width:100%;height:100%;'><pre>"
			, "<tr><td style='height:20px'>"
			, "<input type='button' value='CLEAR' style='font-size:12px;' onClick='opener.Debug.Refresh()'>"
			, "</td></tr>"
			, "<tr><td style='border:1px solid #333333;background-color:#FFFFFF;'>"
				, ((NN)? "<div style='width:100%;height:100%;'>":"")		
			, "<div id='debugContainer' style='padding:0px;width:100%;height:100%;overflow:scroll;'>"
			, "<table id='debug_outertable' style='font-size:12px;border:solid 0px;' ></table>"
			, "</div>"
			, ((NN)?"</div>":"")
			, "</td></tr>"
			, "</pre></table>"
			, "</body>"
			, "</html>"].join("\n");
		DebugWindow.document.write(html);
		DebugWindow.document.close();
	}
	
	function getDebugString(o, tempLive, level, index, isT) {
		var ret;
		if (typeof level == 'undefined') level = 0;
		if (typeof index == 'undefined') index = 0;
		if (typeof tempLive == 'undefined') tempLive = tempLive;
		var CurrentTime = (new Date()).getTime();
		if (o == null) return "NULL";
		switch (typeof o) {
			case "string":
				o=o.replace(/</g,"&lt;");
				o=o.replace(/>/g,"&gt;");
				return (TextMode ? o : "\"" + o + "\"");
				break;
			case "number":
			case "boolean":
				return  o;
				break;
			case "object":
				var JadgementOfObject=0,LocalCount=0;
				if(!ObjectCount[tempLive][level+1][ObjectStartCount])ObjectCount[tempLive][level+1][ObjectStartCount]=0;
				for (var x in o){ 
					if (typeof x=="String") JadgementOfObject++;
					LocalCount++;
					try{
						if( typeof o[x] == "object" ) ObjectCount[tempLive][level+1][ObjectStartCount]++;
					}catch(e){}
				}
				if (o instanceof Array) LocalCount = o.length;
				if (o.length && JadgementOfObject!=LocalCount) {		
					if (level >= MaximumDebugLevel) return "ARRAY[...]";
					if (CurrentTime - StartTime > TimeLimit * 1000) return "TIMEOUT::ARRAY[...]";
			
						ObjectArray[tempLive][level][ObjectStartCount] = o;
					ObjectState[tempLive][level][ObjectStartCount] = false;
					if(isT){
						var ary = "<a href=\"javascript:" + (ObjectModelT==document? "":"") + "Debug.openNextObject('array','"+ tempLive +"'," + level + "," + ObjectStartCount + "," + "true" + ");\"><font id='arrayfont_" + tempLive + "_" + level + "_" + ObjectStartCount + "'>ARRAY[" + LocalCount + "]</font></a><span id='array_" + tempLive + "_" + level + "_" + (ObjectStartCount++) + "'></span>";
						return ary;
					}else{
						var ary = "<a href=\"javascript:" + (ObjectModel==document? "":"opener.") + "Debug.openNextObject('array','"+ tempLive +"'," + level + "," + ObjectStartCount + "," + "false" + ");\"><font id='arrayfont_" + tempLive + "_" + level + "_" + ObjectStartCount + "'>ARRAY[" + LocalCount + "]</font></a><span id='array_" + tempLive + "_" + level + "_" + (ObjectStartCount++) + "'></span>";
						return ary;
					}
				} else {			
					if (level >= MaximumDebugLevel) return "OBJECT{...}";
					if (CurrentTime - StartTime > TimeLimit * 1000) return "TIMEOUT::OBJECT[...]";
			
						ObjectArray[tempLive][level][ObjectStartCount] = o;
					ObjectState[tempLive][level][ObjectStartCount] = false;
					if(isT){
						var ary = "<a href=\"javascript:" + (ObjectModelT==document? "":"") + "Debug.openNextObject('object','"+ tempLive +"'," + level + "," + ObjectStartCount + "," + "true"+ ");\"><font id='objectfont_" + tempLive + "_" + level + "_" + ObjectStartCount + "'>OBJECT{" + LocalCount + "}</font></a><span id='object_" + tempLive + "_" + level + "_" + (ObjectStartCount++) + "'></span>";
						return ary;
					}else{
						var ary = "<a href=\"javascript:" + (ObjectModel==document? "":"opener.") + "Debug.openNextObject('object','"+ tempLive +"'," + level + "," + ObjectStartCount + "," + "false" +");\"><font id='objectfont_" + tempLive + "_" + level + "_" + ObjectStartCount + "'>OBJECT{" + LocalCount + "}</font></a><span id='object_" + tempLive + "_" + level + "_" + (ObjectStartCount++) + "'></span>";
						return ary;
					}
				}
				break;
			case "function":
				return o.toString();
				break;
			default:
				return "UNDEFINED TYPE:" + typeof o;
		}
	}
	this.changeTableclose = function(){
		getElement('debugWrap').outerHTML = "";
		if(Fx){ 
			getElement('debugWrap').innerHTML = "";
		}
		if (Shim) Shim.style.display = "none";
		DebugTable = false;
	}
	var preChangeTop , preChangeY , preChangeY2;
	this.changeTableState = function(e){
		if(isVisibleContainer){
			isVisibleContainer = false;
			e.value = "　↓　";
			preChangeY = getElementProperty(ContainerElement, ["style", "height"]);
			preChange2Y = getElementProperty(ContainerElement2, ["style", "height"]);
			preChangeTop = parseInt(getElementPropertyById("change", ["style", "top"]));
			setElementProperty(ContainerElement, ["style", "height"], "20px");
			setElementProperty(ContainerElement2, ["style", "height"], (Fx? "0px":"2px"));
			DragCS.setPosition(0,MinDragCSY);
			synchShim();
		}else{
			isVisibleContainer = true;
			e.value = "　↑　";
			setElementProperty(ContainerElement, ["style", "height"], preChangeY);
			setElementProperty(ContainerElement2, ["style", "height"], preChange2Y);
			DragCS.setPosition(0,preChangeTop);
			synchShim();
		}
	}
	function cancelTabelState(){
		if(isVisibleContainer == false){
			isVisibleContainer = true;
			var cs = getElement('changeSmall');
			cs.value = "　↑　";
			setElementPropertyById("change", ["style", "height"], "20px");
		}
	}
	this.Refresh = function(n,isT) {
		var r = (n? document : DebugWindow.document);
		r.getElementById("debugContainer").innerHTML="<table id='debug_outertable' style='font-size:12px;border:solid 0px;' ></table>";
		if(isT){
			LiveCount=1;
		}else{
			LiveCountW =1;
		}
	}
	function commify(num) {
		if (num) {
			var re = /(-?\d+)(\d{3})/;
			var str = num.toString();
			while (str.match(re)) str = str.replace(re, "$1,$2");
			return str;
		}
		return num;
	}


	
	var InitialCSX,InitialCSY;
	var MinDragCSX=195, MaxDragCSX, MinDragCSY=50, MaxDragCSY;
	var OffsetCSX, OffsetCSY, BaseCSX, BaseCSY;
	var DragCSX = 0, DragCSY = 0;
	var EngagedCS = false;
	var ContainerElement,ChangeSizeHandleElement;
	var ContainerElement2;
	var TextMode = false;
	var StreamMode = false;
	var DragCS;
	if(!Fx){
		MinDragCSY = MinDragCSY  + 2;
	}
	
	this.initChange2=function (Id) {
		DragCS = new DragElementObject2(
											"change"
											,"change"
											,this.engage			
											,this.dragIt			
											,this.release		
										   );
		DragCS.setPosition(0,Table_height+30);
		DragCS.setLimits(0, MaxDragCSX, MinDragCSY, MaxDragCSY);
		ContainerElement = getElement(Id + "CS");
		setElementPropertyById("change", ["style", "cursor"], "se-resize");
		DragUR = new DragElementObject2(
											"changeUR"
											,"changeUR"
											,this.engageUR			
											,this.dragUR			
											,this.releaseUR		
										   );
		setElementPropertyById("changeUR", ["style", "cursor"], "ne-resize");
		ContainerElement = getElement("changeCS");
		ContainerElement2 = getElement("debugContainer");
	}
	
	this.engage = function(a, x, y) {
		cancelTabelState();
		BaseCSX = x;
		BaseCSY = y;
		Table_width = parseInt(getElementProperty(ContainerElement, ["style", "width"]));
		Table_left = parseInt(getElementPropertyById("debugWrap", ["style", "left"]));
		DragCS.setLimits(MinDragCSX-Table_width-BaseCSX, MaxDragCSX, MinDragCSY, MaxDragCSY);
		EngagedCS = true;
		setElementPropertyById(a, ["style", "width"], 0);
		return false;
	}
	this.dragIt= function(a, x, y) {
		if (EngagedCS) {
			DragCSX = parseInt(x) + Table_width;
			DragCSY = parseInt(y) - MinDragCSY + (Fx? 0 : 2);
			setElementProperty(ContainerElement, ["style", "width"], DragCSX);
			setElementProperty(ContainerElement, ["style", "height"], DragCSY);
			setElementProperty(ContainerElement2, ["style", "width"], DragCSX);
			setElementProperty(ContainerElement2, ["style", "height"], DragCSY);
			synchShim();
			return false;
		}
	}
	this.release = function(a, x, y) {
		if (EngagedCS) {
			setElementPropertyById(a, ["style", "width"], "100%");
			EngagedCS = false;
			DragCS.setPosition(0,y);
		}
	}
	
	this.engageUR = function(a, x, y) {
		cancelTabelState();
		BaseCSX = x;
		BaseCSY = y;
		var ContainerElement4 = getElement("debugWrap");
		
		Table_height = parseInt(getElementProperty(ContainerElement, ["style", "height"]));
		Table_width = parseInt(getElementProperty(ContainerElement2, ["style", "width"]));
		Table_left = parseInt(getElementProperty(ContainerElement4, ["style", "left"]));
		Table_top = parseInt(getElementProperty(ContainerElement4, ["style", "top"]));
		
		DragUR.setLimits(MinDragCSX-Table_width+BaseCSX, MaxDragCSX, -Table_top-20, Table_height+BaseCSY);
		EngagedCS = true;
		return false;
	}
	this.dragUR= function(a, x, y) {
		if (EngagedCS) {
			DragCSY = Table_height + BaseCSY - parseInt(y) + (Fx? 0 : 2);
			DragCSX = parseInt(x) + Table_width - BaseCSX;
			setContainerElement(DragCSX,DragCSY);
			if(!Fx) DragUR.setPosition(0,0);
			Drag.setPosition(Table_left , Table_top + parseInt(y) - BaseCSY);
			synchShim();
			return false;
		}
	}
	this.releaseUR = function(a, x, y) {
		if (EngagedCS) {
			Table_height = parseInt(getElementProperty(ContainerElement, ["style", "height"])) +50+ (Fx? 0 : 2);
			DragCS.setPosition(0,Table_height);
			EngagedCS = false;
		}
	}
	function setContainerElement(DragCSX,DragCSY){
		setElementProperty(ContainerElement, ["style", "width"], DragCSX);
		setElementProperty(ContainerElement, ["style", "height"], DragCSY);
		setElementProperty(ContainerElement2, ["style", "width"], DragCSX);
		setElementProperty(ContainerElement2, ["style", "height"], DragCSY);
		return true;
	}
}
function _waitDebugWriteT(cnt,arg) {
	if (typeof cnt == "undefined") cnt = 50;
	if (document && document.body) {
		Debug.startWriteT(arg);
	} else if (cnt-- > 0) {
		setTimeout("_waitDebugWriteT(" + cnt + ","+arg+")", 100);
	} else {
		alert("Debug.writeT() Failed.");
	}
}
function _waitDebugWriteT2(cnt,Id) {
	if (typeof cnt == "undefined") cnt = 50;
	if (document && document.body) {
		Debug.initChange2(Id);
	} else if (cnt-- > 0) {
		setTimeout("_waitDebugWriteT2(" + cnt +","+ Id+")", 100);
	} else {
		alert("Debug.writeT() Failed.");
	}
}







function Item(id, group_def, group){
	this.init(id, group_def, group);
}

Item.prototype = {
	init: function(id, group_def, group){
		for(var i in group_def.actions){
			this[i] = group_def.actions[i];
		}
	
		this.isDown = false;
		this.isDisabled = false;
		for(var i in group_def.members[id]){
			this[i] = group_def.members[id][i];
		}
		this.id = id;
		this.group = group;
	},

	_onDown: function(){
		this.isDown = true;
		try{
			this.onDown(this);
		}catch(e){}
	},

	_onOver: function(){
		try{
			if(!this.isDisabled) this.isDown ? this.onDownOver(this) : this.onUpOver(this);
		}catch(e){}
	},
	
	_onUp: function(){
		this.isDown = false;
		try{
			this.onUp(this);
		}catch(e){}
	},
	
	_onOut: function(){
		try{
			if(!this.isDisabled) this.isDown ? this.onDownOut(this) : this.onUpOut(this);
		}catch(e){}
	},
	
	_onDisabled: function(){
		if(this.isDisabled) return;
		try{
			var e = this.element;
			this.isDisabled = true;
			this.onDisabled(this);
			e.style.cursor = "default";
		}catch(e){}
	},
	
	_onEnabled: function(){
		if(!this.isDisabled) return;
		try{
			var e = this.element;
			this.isDisabled = false;
			this.onEnabled(this);
			e.style.cursor = "pointer";
		}catch(e){}
	},
	
	_onStart: function(){
		try{
			var e = this.element = getElement(this.id);
			var self = this;
			var group = this.group;
			e.onclick = function(){group.onClickItem(self);};
			e.onmouseover = function(){group.onOverItem(self);};
			e.onmouseout = function(){group.onOutItem(self);};

			e.style.cursor = "pointer";
		}catch(ex){}
		try{
			return this.onStart(this);
		}catch(ex){}
	},
	
	_onDestroy: function(){
		var e = this.element;
		if(e){
			if(client && client.isIE && client.BrowserVersion < 5.5)return;
			e.onclick = e.onmouseover = e.onmouseout = $emptyFunction;

		}
		try{
			return this.onDestroy(this);
		}catch(e){}
	},
	
	_onRemove: function(){
		return this.onRemove(this);
	}
};

var virtual = ["onDown", "onUp", "onUpOver", "onDownOver", "onUpOut", "onDownOut", "onDisabled", "onEnabled", "onStart", "onDestroy", "onRemove"];
for(var i=0, l=virtual.length, ip=Item.prototype; i<l; i++){
	ip[virtual[i]] = function(){return true};
}


function Group(){};

Group.prototype = {
	init: function(group_def, item_object){
		this.id = group_def.id;
		this.members = new Object();
		for(var i in group_def.members){
			this.members[i] = new item_object(i, group_def, this);
		}
		this.group_def = group_def
	},
	onClickItem: function(item){
	},
	
	onOverItem: function(item){
		item._onOver();
	},
	
	onOutItem: function(item){
		item._onOut();
	},

	onStart: function(){
		for(var i in this.members){
			this.members[i]._onStart();
		}
	},
	
	onDestroy: function(){
		for(var i in this.members){
			this.members[i]._onDestroy();
		}
	},
	
	setDisabled: function(id){
		this.members[id]._onDisabled();
	},
	
	setEnabled: function(id){
		this.members[id]._onEnabled();
	},
	
	deleteMembers: function(){
		this.onDestroy();
		this.members = new Object();
	},
	
	each: function(block){
		for(var i in this.members){
			block(this.members[i]);
		}
	}
};


function MultipleGroup(group_def){
	this.init(group_def, Item);
	this.selectedItems = new Object();
};

ext(MultipleGroup, Group);

var g_proto = MultipleGroup.prototype;

g_proto.onClickItem = function(item){
	if(item.isDisabled) return;
	for(var i in this.members){
		var member = this.members[i];
		if(member.id == item.id){
			if(item.isDown){
				item._onUp();
				this.selectedItems[item.id] = null;
			}else{
				item._onDown();
				this.selectedItems[item.id] = item;
			}
		}
	}
	
	Application.fireEvent(this.id, item);
};

g_proto.getConditionString = function(){
	var buf = new Array();
	for(var i in this.selectedItems){
		if(this.selectedItems[i] != null && !undefined(this.selectedItems[i].value)) 
			buf[buf.length] = this.selectedItems[i].value;
	}
	return (buf.length != 0 ? this.id + "," + buf.join(Config.MultiSelectDelimiter) : null);
};

g_proto.remove = function(id){
	if(!id){
		this.removeAll();
	}
	if(this.selectedItems[id] != null && this.selectedItems[id].onRemove()){
		var item = this.selectedItems[id];
		item._onUp();
		this.selectedItems[id] = null;
	}
};

g_proto.removeAll = function(){
	for(var id in this.selectedItems){
		this.remove(id);
	}
};



function ToggleGroup(group_def){
	this.init(group_def, Item);
	this.selectedItem = null;
};

ext(ToggleGroup, Group);

var g_proto = ToggleGroup.prototype;
g_proto.onClickItem = function(item){
	if(item.isDisabled) return;
	
	if(item.isDown && this.group_def.noSelection) return;
	for(var i in this.members){
		var member = this.members[i];
		if(member.id == item.id){
			if(item.isDown){
				item._onUp();
				this.selectedItem = null;
			}else{
				item._onDown();
				this.selectedItem = item;
			}
		}else{
			member._onUp();
		}
	}
	
	Application.fireEvent(this.id, item)
};

g_proto.refresh = function(group_def){
	this.onDestroy();
	this.init(group_def, Item);
	this.selectedItem = null;
	this.onStart();
};

g_proto.getConditionString = function(){
	return (this.selectedItem && !undefined(this.selectedItem.value) ? this.id + "," + this.selectedItem.value : null);
};

g_proto.remove = function(id){
	if(this.selectedItem != null){
		var item = this.selectedItem;
		if(!this.group_def.noSelection && item._onRemove()){
			item._onUp();
			this.selectedItem = null;
		}
	}
};

g_proto.removeAll = g_proto.remove;

var NORMAL_SEARCH = "normalSearch";
var KODAWARI_SEARCH = "kodawariSearch";
var OMOSHIRO_SEARCH = "omoshiroSearch";


Config.Attributes = {
	Decoder: [
		{
			name: "Local",
			attribute: [
			"localCd",
			"originalLocalCd",
			"localName"
			]
		},
		{
			name: "Pref",
			attribute: [
			"prefCd",
			"originalPrefCd",
			"prefName",
			"localCd"
			]
		},
		{
			name: "Type",
			attribute: [
			"typeCd",
			"typeName"
			]
		},
		{
			name: "Company",
			attribute: [
			"companyCd",
			"companyName",
			"prefName"
			]
		},
		{
			name: "Brand",
			attribute: [
			"brandCd",
			"brandName",
			"companyName"
			]
		},
		{
			name: "Kodawari",
			attribute: [
			"kodawariCd",
			"kodawariName",
			"columnName",
			"columnValue"
			]
		},
		{
			name: "Tpo",
			attribute: [
			"tpoCd",
			"tpoName",
			"categoryCd"
			]
		},
		{
			name: "TpoCategory",
			attribute: [
			"categoryCd",
			"categoryName"
			]
		},
		{
			name: "Img",
			attribute: [
			"imgCd",
			"imgName",
			"categoryCd"
			]
		},
		{
			name: "ImgCategory",
			attribute: [
			"categoryCd",
			"categoryName"
			]
		},
		{
			name: "PriceCategory",
			attribute: [
			"categoryGroup",
			"categoryIndex",
			"lowPrice",
			"highPrice",
			"priceCategory"
			]
		},
		{
			name: "Length",
			attribute: [
			"local",
			"pref",
			"company",
			"type",
			"brand",
			"kodawari",
			"tpo",
			"img",
			"price"
			]	
		}
	],
	ConditionState: [
		"LocalKuraCount",
		"PrefKuraCount",
		"LocalCount",
		"PrefCount",
		"TypeCount",
		"KodawariCount",
		"TpoCount",
		"ImgCount",
		"PriceCount",
		"Pref",
		"Company",
		"Brand",
		"GoodsCount"
	],
	List: [
		{
			name: "Item",
			attribute: [
			"companyName", 
			"brandName",
			"commodityName",
			"capacity",
			"price",
			"kakemaiName",
			"kakemaiPer",
			"gentei",
			"sakeDig",
			"acidDig",
			"alcFrecFrom",
			"alcFrecTo"
			]
		}
	]
};

function registKodawari(kodawariMaster){
	var membersObj = new Object();
	for(var i = 0; i < kodawariMaster.length; i++){
		for(var n = 0; n < kodawariMaster[i].rows.length; n++){
			var row = kodawariMaster[i].rows[n];
			for(var t = 0; t < row.rows.length; t++){
				membersObj[[row.rows[t].columnName, "Button", row.rows[t].columnValue].join("")] =
				{
					value:row.rows[t].kodawariCd,
					name:row.rows[t].kodawariName,
					count:0,
					title:"こだわり",
					category:KODAWARI_SEARCH
				};
			}
		}
	}
	var actionsObj = {
		onDown: function(self){
			self.element.className = getButtonClass(self.element.className, 1);
			var groupElements = getElementsByClassName(self.element.className, self.element.parentNode);
			for(var i = 0; i < groupElements.length; i++){
				if(groupElements[i] != self.element){
					groupElements[i].onUp(groupElements[i]);
				}
			}
		},
		onUp: function(self){
			self.element.className = getButtonClass(self.element.className, 0);
		},		
		onEnabled: function(self){
			self.element.className = "button down";
		},
		onDisabled: function(self){
			self.element.className = "button up";
		}
	};
	resistMultiple("kodawari", membersObj, actionsObj);
};

function registPrice(priceMaster){
	var membersObj = new Object();
	for(var i = 0; i < priceMaster.length; i++){
		for(n = 0; n < priceMaster[i].rows.length; n++){
			var row = priceMaster[i].rows[n];
			var lowPrice = row.lowPrice != MIN_PRICE ? ["\\", addFigure(row.lowPrice)].join("") : "";
			var highPrice = row.highPrice != MAX_PRICE ? ["\\", addFigure(row.highPrice)].join("") : "";
			membersObj[["priceButton", row.categoryGroup, "-", row.categoryIndex].join("")] =
			{
				value:row.priceCategory,
				name:[lowPrice, "～", highPrice],
				count:0,
				title:"価格",
				category:NORMAL_SEARCH,
				valueGroup:row.categoryGroup,
				min:(n == 0),
				max:(n == priceMaster[i].rows.length - 1),
				first:(i == 0),
				last:(i == priceMaster.length - 1)
			};
		}		
	}
	var actionsObj = {
		onDown: function(self){
			self.element.className = getButtonClass(self.element.className, 1);
		},
		onUp: function(self){
			self.element.className = getButtonClass(self.element.className, 0);
		},		
		onEnabled: function(self){
			self.element.className = "button down";
		},
		onDisabled: function(self){
			self.element.className = "button up";
		}
	};
	resistToggle("price", membersObj, actionsObj);
};

function resistToggle(idName, membersObj, actionsObj){
	ActionCondition.register(new ToggleGroup({
		id:idName,
		members:membersObj,
		actions:actionsObj
	}));
};

function resistMultiple(idName, membersObj, actionsObj){
	ActionCondition.register(new MultipleGroup({
		id:idName,
		members:membersObj,
		actions:actionsObj
	}));
};

function getButtonClass(className, upDown){
	var classArray = className.split(" ");
	classArray = classArray.slice(0,2);
	if(upDown == 0){
		classArray.push("buttonUp");
	} else {
		classArray.push("buttonDown");
	}	
	return classArray.join(" ");
};



function preLoadImage(files){
	document.preload = new Array(files.length);

	setTimeout(function(){
		for(var i=0, l=files.length; i<l; i++){
			document.preload[i] = new Image();
			document.preload[i].src = files[i];
		}
	}, 500);
};


function hasChildNode(parent, child){
	if(parent.hasChildNodes()){
		var nodes = parent.childNodes;
		for(var i=0, l=nodes.length; i<l; i++){
			if(nodes[i] == child) return true;
		}
	}
	return false;
}

function comma3(str){
	var signed = false;
	if(str-0<0) {
		signed = true;
		str = (str + "").substr(1);
	}else{
		str += "";
	}
	var buf = new Array();
	var l = str.length;
	var s = (3 - l % 3); s = (s == 3 ? 0 : s);
	str = (s == 1 ? "0" : (s == 2 ? "00" : "")) + str;
	for(var i=j=s; i<l+s; i++){
		buf[buf.length] = str.charAt(i) + (j == 2 && i != l+s-1 ? "," : "");
		j = (j == 2 ? 0 : j+1);
	}
	return (signed ? "-" : "") + buf.join("");
}

function commify(num) {
	if (num) {
		var str = num.toString();
		var pos = str.indexOf(".");
		if (pos < 0) {
			for (var i=str.length-1; i>=0; i--) {		
				if (!isNaN(str.substring(i, i+1))) {
					pos = i + 1;
					break;
				}
			}
		}
		var figure = -1;
		while (--pos >= 0 && !isNaN(str.substring(pos, pos+1)))
			if (++figure > 0 && figure % 3 == 0)
				str = str.substring(0, pos+1) + "," + str.substring(pos+1, str.length);
		return str;
	} else {
		return num;
	}
}

function zero_bar(str){
	return (str == 0 ? "-" : str);
}

function parseDataVersion(dataVersion){
	return new Date(dataVersion.substr(0, 4)-0, dataVersion.substr(5, 2)-1, dataVersion.substr(8, 2)-0, dataVersion.substr(11, 2)-0, dataVersion.substr(14, 2)-0, 0);
}

var KODAWARI = "kodawari";
var PRICE ="price";

var PRICE_CATEGORY = "priceCategory";

var MIN_PRICE = 0;
var MAX_PRICE = 2147483647;

var LIMIT = 20;

var IMAGE_MAP_GUIDE_ALL_LINK = "imageMapGuideAllLink";


function _switchDisplay(array, maxLength, buttonName){
	for(var i = 0; i < maxLength; i++){
		var elm = getElement(buttonName + (i + 1));
		if(array_findItem(array, i + 1) >= 0){
			elm.style.display = "block";
		} else {
			elm.style.display = "none";
		}
	}
};


function _drawCount(array, key){
	for(var i = 0; i < array.length; i++){
		var elm = getElement(key.concat(i + 1));
		if(elm){
			elm.innerHTML = array[i];
		}	
	}
};


function _setImgAttr(src, useMap){
	var imgElm = getElement("imageMapImg");
	imgElm.src = "img/map/".concat(src);
	imgElm.useMap = "#".concat(useMap);
};


function _getAreaHTML(mapCoords, idTitle){
	var text = "";
	for(var i in mapCoords){
		var prefCoords = mapCoords[i];
		if(prefCoords[MapCoordsIndex]){
			for(var n = 0; n < prefCoords[MapCoordsIndex].length; n++){
				text = text.concat("<area id=\""+(idTitle.concat(i))+"\" href=\"javascript:void(0)\" alt=\""+(prefCoords[MapTitleIndex])+"\" coords=\""+(prefCoords[MapCoordsIndex][n].join(','))+"\" shape=\""+(prefCoords[MapCoordsIndex][n].length == 3 ? "circle" : "poly")+"\"/>");
			}
		}
	}
	return text;
};


function _getGuideHTML(item, id){
	return ("&nbsp;>&nbsp;<a id=\""+(id)+"\">"+(item[MapTitleIndex])+"</a>");
};


function _removeLinkMapGuideAll(localGroup){
	if(localGroup && !localGroup.selectedItem){
		getElement(IMAGE_MAP_GUIDE_ALL_LINK).removeAttribute("href");
	}
};


function _addLinkMapGuideAll(localGroup, mapCoords){
	if(mapCoords[localGroup.selectedItem.code][MapChildIndex]){
		getElement(IMAGE_MAP_GUIDE_ALL_LINK).href = "javascript:clearLocalMapSelect()";	
	}
};


function Local(masterArray, maxSeq){
	var BUTTON_AREA_ID = "local";
	var BUTTON_ID_TITLE = "localMap";
	var GROUP_ID = "local";
	var GROUP_NAME = "地域";
	var CODE_COLUMN = "localCd";
	var NAME_COLUMN = "localName";
	var ORIGINAL_CODE_COLUMN = "originalLocalCd";
	var COUNT_ID = "local";
	var KURA_COUNT_ID = "localKura";
	var IMAGE_MAP_GUIDE = "imageMapGuideLocal";
	var IMAGE_MAP_MAP = "imageMapLocalMap";
	var IMAGE_MAP_GUIDE_LINK = "imageMapGuideLocalLink";
	var IMAGE_MAP_RUBY = "imageMapRuby";
	var _masterArray = masterArray;
	var _maxSeq = maxSeq;
	var _count = new Array();
	var _kuraCount = new Array();
	
	
	this.drawMap = function(localGroup, mapCoords){		
		_setImgAttr(mapCoords[MapSrc], BUTTON_ID_TITLE);
		getElement(IMAGE_MAP_MAP).innerHTML = _getAreaHTML(mapCoords[MapChildIndex], BUTTON_ID_TITLE);
		getElement(IMAGE_MAP_RUBY).innerHTML = getRubyHTML(mapCoords[MapChildIndex], _masterArray);
		registButton(_masterArray, mapCoords[MapChildIndex]);
	}
	
	this.addMapGuide = function(localGroup, mapCoords){
		getElement(IMAGE_MAP_GUIDE).innerHTML = _getGuideHTML(mapCoords[localGroup.selectedItem.code], IMAGE_MAP_GUIDE_LINK);
	}
	
	this.removeMapGuide = function(){
		getElement(IMAGE_MAP_GUIDE).innerHTML = "";
	}
	
	
	this.drawItemCount = function(text){
		_drawCount(complementArray(text.split(",") , _maxSeq), COUNT_ID);
	}
	
	this.saveKuraCount = function(text){
		Debug.write(complementArray(text.split(",") , _maxSeq));
	};
	
	
	this.drawKuraCount = function(text) {
		_drawCount(complementArray(text.split(",") , _maxSeq), KURA_COUNT_ID);
	}
	
	
	this.clickRuby = function(elm, localCd){
		ActionCondition.getGroup(GROUP_ID).onClickItem(ActionCondition.getGroup(GROUP_ID).members[BUTTON_ID_TITLE.concat(localCd)]);
	};
	
	
	function registButton(_masterArray, mapCoords){
		ActionCondition.register(new ToggleGroup({
			id:GROUP_ID,
			members:getMembers(_masterArray, mapCoords),
			actions:getAction()
		}));
	};
	
	
	function getRubyHTML(mapCoords, master){
		var text = "";
		for(var i in mapCoords){
			var prefCoords = mapCoords[i];
			var localCd = master[array_findItem_by_attribute(master, i, ORIGINAL_CODE_COLUMN)][CODE_COLUMN];
			text = text.concat("<div id=\""+(IMAGE_MAP_RUBY + i)+"\" class=\"imageMapRuby\" style=\"left:"+(prefCoords[MapTextIndex][0])+"px; top:"+(prefCoords[MapTextIndex][1])+"px; cursor:pointer;\" onclick=\"javascript:local.clickRuby(this, '"+(i)+"')\">"+(prefCoords[MapTitleIndex])+"(<span id=\""+(KURA_COUNT_ID.concat(localCd))+"\"></span>蔵)(<span id=\""+(COUNT_ID.concat(localCd))+"\"></span>)</div>");
		}
		return text;
	};
	
	function getMembers(master, mapCoords){
		var membersObj = new Object();
		for(var i in mapCoords){
			prefCoords = mapCoords[i];
			membersObj["localMap".concat(i)] = 
			{
				value:master[array_findItem_by_attribute(master, i, ORIGINAL_CODE_COLUMN)][CODE_COLUMN],
				name:prefCoords[MapTitleIndex],
				count:0,
				kuraCount:0,
				title:GROUP_NAME,
				category:NORMAL_SEARCH,
				code:i
			};	
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				getElement(IMAGE_MAP_RUBY.concat(self.code)).style.backgroundColor = "lightGreen";
			},
			onUp: function(self){
				getElement(IMAGE_MAP_RUBY.concat(self.code)).style.backgroundColor = "white";
			},
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
};


function Pref(masterArray, maxSeq){
	var BUTTON_AREA_ID = "pref";
	var BUTTON_ID_TITLE = "prefMap";
	var GROUP_ID = "pref";
	var GROUP_NAME = "都道府県";
	var CODE_COLUMN = "prefCd";
	var NAME_COLUMN = "prefName";
	var ORIGINAL_CODE_COLUMN = "originalPrefCd";
	var COUNT_ID = "pref";
	var KURA_COUNT_ID = "prefKura";
	var IMAGE_MAP_GUIDE_LINK = "imageMapGuidePrefLink";
	var IMAGE_MAP_GUIDE = "imageMapGuidePref";
	var IMAGE_MAP_MAP = "imageMapPrefMap";
	var IMAGE_MAP_RUBY = "imageMapRuby";
	var _masterArray = masterArray;
	var _maxSeq = maxSeq;
	
	
	this.drawMap = function(localGroup, mapCoords){
		if(!mapCoords[localGroup.selectedItem.code][MapChildIndex]){
			return;	
		}
		_setImgAttr(mapCoords[localGroup.selectedItem.code][MapSrc], BUTTON_ID_TITLE);
		getElement(IMAGE_MAP_MAP).innerHTML = _getAreaHTML(mapCoords[localGroup.selectedItem.code][MapChildIndex], BUTTON_ID_TITLE);
		getElement(IMAGE_MAP_RUBY).innerHTML = getRubyHTML(mapCoords[localGroup.selectedItem.code][MapChildIndex], _masterArray);
		registButton(_masterArray, mapCoords[localGroup.selectedItem.code][MapChildIndex]);
	};
	
	this.addMapGuide = function(localGroup, prefGroup, mapCoords){
		getElement(IMAGE_MAP_GUIDE).innerHTML = _getGuideHTML(mapCoords[localGroup.selectedItem.code][MapChildIndex][prefGroup.selectedItem.code], IMAGE_MAP_GUIDE_LINK);
	};
	
	this.removeMapGuide = function(){
		getElement(IMAGE_MAP_GUIDE).innerHTML = "";
	};
	
	
	this.drawKuraCount = function(text){
		_drawCount(complementArray(text.split(",") , _maxSeq), KURA_COUNT_ID);
	};
	
	
	this.drawItemCount = function(text){
		_drawCount(complementArray(text.split(",") , _maxSeq), COUNT_ID);
	};
	
	this.clickRuby = function(elm, prefCd){
		ActionCondition.getGroup(GROUP_ID).onClickItem(ActionCondition.getGroup(GROUP_ID).members[BUTTON_ID_TITLE.concat(prefCd)]);
	};
	
	function getRubyHTML(mapCoords, prefMaster){
		var text = "";
		for(var i in mapCoords){
			var prefCoords = mapCoords[i];
			var prefCd = prefMaster[array_findItem_by_attribute(prefMaster, i, "originalPrefCd")][CODE_COLUMN];
			text = text.concat(
				"<div id=\""+(IMAGE_MAP_RUBY.concat(i))+"\" class=\"imageMapRuby\" style=\"left:"+(prefCoords[MapTextIndex][0])+"px; top:"+(prefCoords[MapTextIndex][1])+"px; cursor:pointer;\" onclick=\"javascript:pref.clickRuby(this, '"+(i)+"')\"> "+(prefCoords[MapTitleIndex])+"(<span id='"+(KURA_COUNT_ID.concat(prefCd))+"'></span>蔵)(<span id='"+(COUNT_ID.concat(prefCd))+"'></span>) </div> "
			);
		}
		return text;
	};
	
	
	
	function registButton(masterArray, mapCoords){
		ActionCondition.register(new ToggleGroup({
			id:GROUP_ID,
			members:getMembers(masterArray, mapCoords),
			actions:getAction()
		}));
	};
	
	function getMembers(masterArray, mapCoords){
		var membersObj = new Object();
		for(var i in mapCoords){
			prefCoords = mapCoords[i];
			membersObj[BUTTON_ID_TITLE.concat(i)] = 
			{
				value:masterArray[array_findItem_by_attribute(masterArray, i, ORIGINAL_CODE_COLUMN)][CODE_COLUMN],
				name:prefCoords[MapTitleIndex],
				count:0,
				kuraCount:0,
				title:GROUP_NAME,
				category:NORMAL_SEARCH,
				code:i
			};	
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				getElement(IMAGE_MAP_RUBY.concat(self.code)).style.backgroundColor = "lightGreen";
			},
			onUp: function(self){
				getElement(IMAGE_MAP_RUBY.concat(self.code)).style.backgroundColor = "white";
			},
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
};


function Company(masterArray, maxSeq){
	var BUTTON_AREA_ID = "company";
	var BUTTON_ID_TITLE = "companyButton";
	var GROUP_ID = "company";
	var GROUP_NAME = "蔵元";
	var CODE_COLUMN = "companyCd";
	var NAME_COLUMN = "companyName";
	var CLASS_NAME = "button companyButton";
	var _masterArray = masterArray;
	var _maxSeq = maxSeq;
	
	
	this.drawButton = function(){
		getElement(BUTTON_AREA_ID).innerHTML = getHTML(_masterArray);
		registButton();
	};
	
	
	this.switchButtonDisplay = function(array){
		_switchDisplay(array, _maxSeq, BUTTON_ID_TITLE);
	};

	
	function registButton(){
		ActionCondition.register(new ToggleGroup({
			id:GROUP_ID,
			members:getMembers(_masterArray),
			actions:getAction()
		}));
	};
	
	function getMembers(master){
		var membersObj = new Object();	
		for(var i = 0; i < master.length; i++){
			membersObj[BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN])] =
			{
				value:master[i][CODE_COLUMN],
				name:master[i][NAME_COLUMN],
				count:0,
				title:GROUP_NAME,
				category:NORMAL_SEARCH
			};
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				self.element.className = getButtonClass(self.element.className, 1);
			},
			onUp: function(self){
				self.element.className = getButtonClass(self.element.className, 0);
			},		
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
	
	function getHTML(master){
		var text = "";
		for(var i = 0; i < master.length; i++){
			text = text.concat(
				"<li id=\""+(BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN]))+"\" class=\""+(CLASS_NAME)+"\"> <ul> <li>"+(master[i][NAME_COLUMN])+"</li> </ul> </li> "
			);
		}
		return text;
	};
};


function Type(masterArray, maxSeq){
	var BUTTON_AREA_ID = "type";
	var BUTTON_ID_TITLE = "typeButton";
	var GROUP_ID = "type";
	var GROUP_NAME = "種類";
	var CODE_COLUMN = "typeCd";
	var NAME_COLUMN = "typeName";
	var CLASS_NAME = "button typeButton";
	var COUNT_ID = "type";
	var _masterArray = masterArray;
	var _maxSeq = maxSeq;
	
	
	this.drawButton = function(){
		getElement(BUTTON_AREA_ID).innerHTML = getHTML(_masterArray);
		registButton();
	};
	
	
	this.drawItemCount = function(text){
		_drawCount(complementArray(text.split(",") , _maxSeq), COUNT_ID);
	};
	
	function registButton(){
		ActionCondition.register(new ToggleGroup({
			id:GROUP_ID,
			members:getMembers(_masterArray),
			actions:getAction()
		}));
	};
	
	function getMembers(master){
		var membersObj = new Object();	
		for(var i = 0; i < master.length; i++){
			membersObj[BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN])] =
			{
				value:master[i][CODE_COLUMN],
				name:master[i][NAME_COLUMN],
				count:0,
				title:GROUP_NAME,
				category:NORMAL_SEARCH
			};
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				self.element.className = getButtonClass(self.element.className, 1);
			},
			onUp: function(self){
				self.element.className = getButtonClass(self.element.className, 0);
			},		
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
	
	function getHTML(master, maxSeq){
		var text = "";
		for(var i = 0; i < master.length; i++){
			text = text.concat(
				"<li id=\""+(BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN]))+"\" class=\""+(CLASS_NAME)+"\"> <ul> <li> "+(master[i][NAME_COLUMN])+"(<span id=\""+(COUNT_ID.concat(master[i][CODE_COLUMN]))+"\">()</span>) </li> </ul> </li> "
			);
		}
		return text;
	};
};


function Brand(masterArray, maxSeq){
	var BUTTON_AREA_ID = "brand";
	var BUTTON_ID_TITLE = "brandButton";
	var GROUP_ID = "brand";
	var GROUP_NAME = "銘柄";
	var CODE_COLUMN = "brandCd";
	var NAME_COLUMN = "brandName";
	var COMPANY_NAME_COLUMN = "companyName";
	var CLASS_NAME = "button brandButton";
	var _masterArray = masterArray;
	var _maxSeq = maxSeq;
	
	
	this.drawButton = function(){
		getElement(BUTTON_AREA_ID).innerHTML = getHTML(_masterArray);
		registButton();
	};
	
	
	this.switchButtonDisplay = function(array){
		_switchDisplay(array, _maxSeq, BUTTON_ID_TITLE);
	};
	
	function registButton(){
		ActionCondition.register(new ToggleGroup({
			id:GROUP_ID,
			members:getMembers(_masterArray),
			actions:getAction()
		}));
	};
	
	function getMembers(master){
		var membersObj = new Object();	
		for(var i = 0; i < master.length; i++){
			membersObj[BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN])] =
			{
				value:master[i][CODE_COLUMN],
				name:master[i][NAME_COLUMN],
				count:0,
				title:GROUP_NAME,
				category:NORMAL_SEARCH
			};
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				self.element.className = getButtonClass(self.element.className, 1);
			},
			onUp: function(self){
				self.element.className = getButtonClass(self.element.className, 0);
			},		
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
	
	function getHTML(master){
		var text = "";
		for(var i = 0; i < master.length; i++){
			text = text.concat(
				"<li id=\""+(BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN]))+"\" class=\""+(CLASS_NAME)+"\"> <dl> <dt>"+(master[i][NAME_COLUMN])+"</dt> <dd>"+(master[i][COMPANY_NAME_COLUMN])+"</dd> </dl> </li> "
			);
		}
		return text;
	};
};


function Tpo(masterArray, categoryMasterArray, maxSeq){
	var BUTTON_AREA_ID = "tpo";
	var BUTTON_ID_TITLE = "tpoButton";
	var CATRGOTY_BUTTON_TITLE = "tpoCategory";
	var GROUP_ID = "tpo";
	var GROUP_NAME = "TPO";
	var CODE_COLUMN = "tpoCd";
	var NAME_COLUMN = "tpoName";
	var CATEGORY_COLUMN = "categoryCd";
	var CATEGORY_NAME = "categoryName";
	var CLASS_NAME = "button tpoButton";
	var CATEGORY_CLASS_NAME = "button";
	var COUNT_ID = "tpo";
	var CATEGORY_AREA_TITLE = "tpoCategoryArea";
	var CATEGORY_AREA_CLASS_NAME = "categoryArea";
	var _masterArray = masterArray;
	var _categoryMasterArray = categoryMasterArray;
	var _maxSeq = maxSeq;
	
	this.drawButton = function(){
		getElement(BUTTON_AREA_ID).innerHTML = getHTML(_masterArray, _categoryMasterArray);
		registButton(_masterArray);
	};
	
	
	this.drawItemCount = function(text){
		_drawCount(complementArray(text.split(",") , _maxSeq), COUNT_ID);
	};
	
	this.switchArea = function(elm){
		var childs = elm.parentNode.getElementsByTagName("UL");
		for(var i = 0; i < childs.length; i++){
			if(childs[i].style.display == "block"){
				displayDisable(childs[i]);
			} else {
				displayEnable(childs[i]);
			}	
		}
	};
	
	function registButton(master){
		resistMultiple(GROUP_ID, getMembers(master), getAction());
	};

	function getMembers(master){
		var membersObj = new Object();	
		for(var i = 0; i < master.length; i++){
			membersObj[BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN])] =
			{
				value:master[i][CODE_COLUMN],
				name:master[i][NAME_COLUMN],
				count:0,
				title:GROUP_NAME,
				category:OMOSHIRO_SEARCH
			};
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				self.element.className = getButtonClass(self.element.className, 1);
			},
			onUp: function(self){
				self.element.className = getButtonClass(self.element.className, 0);
			},		
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
	
	function getHTML(master, categoryMaster){
		return getCategoryHTML(master, categoryMaster);
	}
	
	function getCategoryHTML(master, categoryMaster){
		var text = "";
		for(var i = 0; i < categoryMaster.length; i++){
			text = text.concat(
				"<li id=\""+(CATRGOTY_BUTTON_TITLE.concat(categoryMaster[i][CATEGORY_COLUMN]))+"\" class=\""+(CATEGORY_CLASS_NAME)+"\"> <h4 onclick=\"javascript:tpo.switchArea(this)\" style=\"cursor:pointer\">"+(categoryMaster[i][CATEGORY_NAME])+"</h4> <ul class=\""+(CATEGORY_AREA_CLASS_NAME)+"\"> "+(getInnerCategoryHTML(selectByKey(master, categoryMaster[i][CATEGORY_COLUMN], CATEGORY_COLUMN)))+" </ul> </li> "
			)
		}
		return text;
	};
	
	function getInnerCategoryHTML(master){
		var text = "";
		for(var i = 0; i < master.length; i++){
			text = text.concat(
				"<li id=\""+(BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN]))+"\" class=\""+(CLASS_NAME)+"\"> "+(master[i][NAME_COLUMN])+"(<span id=\""+(COUNT_ID.concat(master[i][CODE_COLUMN]))+"\">()</span>) </li> "
			)
		}
		return text;
	}
};



function Img(masterArray, categoryMasterArray, maxSeq){
	var BUTTON_AREA_ID = "img";
	var BUTTON_ID_TITLE = "imgButton";
	var CATRGOTY_BUTTON_TITLE = "imgCategory";
	var GROUP_ID = "img";
	var GROUP_NAME = "イメージ";
	var CODE_COLUMN = "imgCd";
	var NAME_COLUMN = "imgName";
	var CATEGORY_COLUMN = "categoryCd";
	var CATEGORY_NAME = "categoryName";
	var CLASS_NAME = "button imgButton";
	var CATEGORY_CLASS_NAME = "button";
	var COUNT_ID = "img";
	var CATEGORY_AREA_TITLE = "imgCategoryArea";
	var CATEGORY_AREA_CLASS_NAME = "categoryArea";
	var _masterArray = masterArray;
	var _categoryMasterArray = categoryMasterArray;
	var _maxSeq = maxSeq;
	
	this.drawButton = function(){
		getElement(BUTTON_AREA_ID).innerHTML = getHTML(_masterArray, _categoryMasterArray);
		registButton(_masterArray);
	};
	
	
	this.drawItemCount = function(text){
		_drawCount(complementArray(text.split(",") , _maxSeq), COUNT_ID);
	};
	
	this.switchArea = function(elm){
		var childs = elm.parentNode.getElementsByTagName("UL");
		for(var i = 0; i < childs.length; i++){
			if(childs[i].style.display == "block"){
				displayDisable(childs[i]);
			} else {
				displayEnable(childs[i]);
			}	
		}
	};
	
	function registButton(master){
		resistMultiple(GROUP_ID, getMembers(master), getAction());
	};

	function getMembers(master){
		var membersObj = new Object();	
		for(var i = 0; i < master.length; i++){
			membersObj[BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN])] =
			{
				value:master[i][CODE_COLUMN],
				name:master[i][NAME_COLUMN],
				count:0,
				title:GROUP_NAME,
				category:OMOSHIRO_SEARCH
			};
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				self.element.className = getButtonClass(self.element.className, 1);
			},
			onUp: function(self){
				self.element.className = getButtonClass(self.element.className, 0);
			},		
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
	
	function getHTML(master, categoryMaster){
		var text = "";
		for(var i = 0; i < categoryMaster.length; i++){
			text = text.concat(
				"<li id=\""+(CATRGOTY_BUTTON_TITLE.concat(categoryMaster[i][CATEGORY_COLUMN]))+"\" class=\""+(CATEGORY_CLASS_NAME)+"\"> <h4 onclick=\"javascript:img.switchArea(this)\" style=\"cursor:pointer\">"+(categoryMaster[i][CATEGORY_NAME])+"</h4> <ul class=\""+(CATEGORY_AREA_CLASS_NAME)+"\"> "+(getInnerCategoryHTML(selectByKey(master, categoryMaster[i][CATEGORY_COLUMN], CATEGORY_COLUMN)))+" </ul> </li> "
			)
		}
		return text;
	};
	
	function getInnerCategoryHTML(master){
		var text = "";
		for(var i = 0; i < master.length; i++){
			text = text.concat(
				"<li id=\""+(BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN]))+"\" class=\""+(CLASS_NAME)+"\"> "+(master[i][NAME_COLUMN])+"(<span id=\""+(COUNT_ID.concat(master[i][CODE_COLUMN]))+"\">()</span>) </li> "
			)
		}
		return text;
	};
};


function Kodawari(kodawariArray, maxSeq) {
	var BUTTON_ID_TITLE = "kodawariButton";
	var GROUP_ID = "kodawari";
	var GROUP_NAME = "こだわり";
	var CODE_COLUMN = "kodawariCd";
	var NAME_COLUMN = "kodawariName";
	var AREA_ID = "kodawariSearch";
	var COUNT_ID = "kodawari";
	var HORIZONTAL_CLASSNAME = "stackHorizontal";
	var VERTICAL_CALSSNAME = "stackVertical";
	var TAB_CLASSNAME = "tab";
	var _masterObj = decodeToKodawariMaster(kodawariArray, KodawariCategory);
	var _maxSeq = maxSeq;
	
	this.drawContents = function(){
		getElement(AREA_ID).innerHTML = getKodawariListHTML(_masterObj);
		registButton(kodawariArray);
	};
	
	
	this.drawCount = function(array, maxSeq){
		_drawCount(complementArray(array.split(",") , maxSeq), KODAWARI);
	};
	
	function getKodawariListHTML(masterObj, parentPanel){
		var text = "";
		for(var i in masterObj){
			var id = masterObj[i][KodawariArray.ChildIndex] ? "" : ["id=",  BUTTON_ID_TITLE, i].join("");
			var classNameArray = new Array();
			var tab = "";
			var countText = masterObj[i][KodawariArray.ChildIndex] ? "" : "(<span id=\""+(COUNT_ID.concat(i))+"\"></span>)";
			var display = "";
			if(!masterObj[i][KodawariArray.ChildIndex]){
				classNameArray.push("kodawariButton");
			}
			if(parentPanel == Panel.Tab){
				if(indexOf(masterObj, i) > 0){
					display = "style=\"display:none\"";
				}
				id = "id=\""+(masterObj[i][KodawariArray.KodawariCdIndex])+"\"";
			}
			switch(masterObj[i][KodawariArray.PanelIndex]){
				case Panel.StackHorizontal:
					classNameArray.push(HORIZONTAL_CLASSNAME);
				break;
				case Panel.StackVertical:
					classNameArray.push(VERTICAL_CALSSNAME);
				break;
				case Panel.Tab:
					classNameArray.push(TAB_CLASSNAME);
					tab = getTabHTML(masterObj[i]);
					id = "id=\""+(masterObj[i][KodawariArray.KodawariCdIndex])+"\"";
				break;
			}
			text = text.concat(
				"<div "+(id)+" class=\""+(classNameArray.join(" "))+"\" "+(display)+"> "+(tab)+" "+([getTitleHTML(masterObj[i]), getKodawariListHTML(masterObj[i][KodawariArray.ChildIndex], masterObj[i][KodawariArray.PanelIndex]), countText].join(""))+" </div> "
			);
			
		}
		return text;
	};
	
	function indexOf(obj, item){
		var count = 0;
		for(var i in obj){
			if(i == item){
				return count;
			} else {
				count++;
			}
		}
		return -1;
	}
	
	function getTabHTML(obj){
		var htmlArray = new Array();
		htmlArray.push("<div class=\""+(["tabArea"].join(" "))+"\">");
		for(var i in obj[KodawariArray.ChildIndex]){
			htmlArray.push("<div onclick=\"javascript:changeTab(this, '"+(obj[KodawariArray.ChildIndex][i][KodawariArray.KodawariCdIndex])+"')\">"+(obj[KodawariArray.ChildIndex][i][KodawariArray.CategoryNameIndex])+"</div>");
		}
		htmlArray.push("</div>");
		return htmlArray.join("");
	};
	
	function getTitleHTML(obj){
		var titleTagName = getTitleTagName(obj);
		if(obj[KodawariArray.CategoryNameIndex]){
			return "<"+(titleTagName)+">"+(obj[KodawariArray.CategoryNameIndex])+"</"+(titleTagName)+">";
		} else {
			return "";
		}
	};
	
	function getTitleTagName(obj){
		switch(searchChildLevel(obj)){
			case 1:
				return "h4";
			case 2:
				return "h3";
			case 3:
				return "h2";
			default:
				return null;		
		}
	};
	
	
	function searchChildLevel(obj){
		var level = 0;
		for(var i in obj[KodawariArray.ChildIndex]){
			var childLevel = searchChildLevel(obj[KodawariArray.ChildIndex][i]);
			if(childLevel > level){
				level = childLevel;
			}
		}
		level++;
		return level;
	};
	
	function haveChild(){
		for(var i in obj[KodawariArray.ChildIndex]){
			if(obj[KodawariArray.ChildIndex][i][KodawariArray.ChildIndex]){
				return true;
			}	
		}
		return false;
	}
	
	
	function decodeToKodawariMaster(kodawariArray, kodawariMaster){
		for(var i = 0; i < kodawariArray.length; i++){
			pushItemToMaster(kodawariArray[i], kodawariMaster);
		}
		return kodawariMaster;
	};
	
	
	function pushItemToMaster(item, kodawariCategory){
		for(var i in kodawariCategory){
			if(kodawariCategory[i][KodawariArray.KodawariCdIndex] == item.columnName){
				kodawariCategory[i][KodawariArray.ChildIndex][item.kodawariCd] = [
					item.columnValue
					,item.kodawariName
				];
			} else {
				pushItemToMaster(item, kodawariCategory[i][KodawariArray.ChildIndex]);
			}
		}
		return kodawariCategory;
	};
	
	
	function registButton(master){
		resistMultiple(GROUP_ID, getMembers(master), getAction());
	};

	function getMembers(master){
		var membersObj = new Object();
		for(var i = 0; i < master.length; i++){
			membersObj[BUTTON_ID_TITLE.concat(master[i][CODE_COLUMN])] =
			{
				value:master[i][CODE_COLUMN],
				name:master[i][NAME_COLUMN],
				count:0,
				title:GROUP_NAME,
				category:KODAWARI_SEARCH
			};
		}
		return membersObj;
	};
	
	function getAction(){
		return {
			onDown: function(self){
				self.element.style.backgroundColor = "lightgreen";
			},
			onUp: function(self){
				self.element.style.backgroundColor = "white";
			},		
			onEnabled: function(self){
				self.element.className = "button down";
			},
			onDisabled: function(self){
				self.element.className = "button up";
			}
		};
	};
};

function drawPrice(priceArray){
	var text = "";
	for(var i = 0; i < priceArray.length; i++){
		text = text.concat("<div id=\""+(PRICE_CATEGORY.concat(priceArray[i].category))+"\" "+(i > 0 ? "style=\"display:none\"" : "")+" >");
		for(var n = 0; n < priceArray[i].rows.length; n++){
			var priceArrayRow = priceArray[i].rows[n];
			var lowPrice = priceArrayRow.lowPrice != MIN_PRICE ? "\\".concat(addFigure(priceArrayRow.lowPrice)) : "";
			var highPrice = priceArrayRow.highPrice != MAX_PRICE ? "\\".concat(addFigure(priceArrayRow.highPrice)) : "";
			text = text.concat(
				"<li id=\"priceButton"+(priceArrayRow.categoryGroup)+"-"+(priceArrayRow.categoryIndex)+"\" class=\"button priceButton\"> "+([lowPrice, "～", highPrice].join(""))+" (<span id=\""+(PRICE.concat(priceArrayRow.priceCategory))+"\">()</span>) </li> "
			);	
		}
		text = text.concat("</div>");
	}
	getElement("price").innerHTML = text;
};


function drawPriceCount(array, maxSeq){
	_drawCount(complementArray(array.split(",") , maxSeq), PRICE);
};


function drawSearchCondition(groups){
	var normalSearchConditionAry = new Array();
	var kodawariSearchConditionAry = new Array();
	var omoshiroSearchConditionAry = new Array();
	
	for(var i in groups){
		if(groups[i].selectedItem){
			var selectedItem = groups[i].selectedItem;
			switch(selectedItem.category){
				case NORMAL_SEARCH:
					normalSearchConditionAry.push("<li>"+([selectedItem.title, "：", selectedItem.name].join(""))+"(<a href=\"javascript:removeCondition('"+(i)+"')\">削除</a>)</li>");
					break;
				case KODAWARI_SEARCH:
					kodawariSearchConditionAry.push("<li>"+([selectedItem.title, "：", selectedItem.name].join(""))+"(<a href=\"javascript:removeCondition('"+(i)+"')\">削除</a>)</li>");
					break;
				case OMOSHIRO_SEARCH:
					omoshiroSearchConditionAry.push("<li>"+([selectedItem.title, "：", selectedItem.name].join(""))+"(<a href=\"javascript:removeCondition('"+(i)+"')\">削除</a>)</li>");
					break;
			}
		} else if(groups[i].selectedItems){
			for(var n in groups[i].selectedItems){
				var selectedItem = groups[i].selectedItems[n];
				if(selectedItem){
					switch(selectedItem.category){
						case NORMAL_SEARCH:
							normalSearchConditionAry.push("<li>"+([selectedItem.title, "：", selectedItem.name].join(""))+"(<a href=\"javascript:removeCondition('"+(i)+"', '"+(n)+"')\">削除</a>)</li>");
							break;
						case KODAWARI_SEARCH:
							kodawariSearchConditionAry.push("<li>"+([selectedItem.title, "：", selectedItem.name].join(""))+"(<a href=\"javascript:removeCondition('"+(i)+"', '"+(n)+"')\">削除</a>)</li>");
							break;
						case OMOSHIRO_SEARCH:
							omoshiroSearchConditionAry.push("<li>"+([selectedItem.title, "：", selectedItem.name].join(""))+"(<a href=\"javascript:removeCondition('"+(i)+"', '"+(n)+"')\">削除</a>)</li>");
							break;
					}	
				}
			}
		}
	}
	getElement("normalSearchCondition").innerHTML = normalSearchConditionAry.join("");
	getElement("kodawariSearchCondition").innerHTML = kodawariSearchConditionAry.join("");
	getElement("omoshiroSearchCondition").innerHTML = omoshiroSearchConditionAry.join("");
};


function drawGoodsCount(count){
	getElement("goodsCount").innerHTML = count;
};


function ItemList(count){
	
	var LOW_LIMIT_ID = "lowLimit";
	var HIGH_LIMIT_ID = "highLimit";
	var ITEM_AREA_ID = "item";
	
	var LIMIT = 20;
	
	var _count = count;
	
	this.pageCondition = {
		list:0,
		max:Math.ceil(count / LIMIT)
	};
	
	this.drawListMenu = function(){
		drawListLimit(this.pageCondition);
		drawListPages(this.pageCondition);
	};
	
	
	this.drawListItem = function(itemArray){
		var text = "";
		for(var i = 0; i < itemArray.length; i++) {
			text = text.concat(
				"<li class=\"item\"> <div class=\"itemImg\"> <img width=\"100px\" height=\"100px\" alt=\"商品画像\" /> </div> <div class=\"itemInfo\"> <ul> <li>"+(itemArray[i].companyName)+"</li> <li>"+(itemArray[i].brandName)+"</li> <li>"+(itemArray[i].commodityName)+"</li> <li>"+(itemArray[i].capacity)+" ml</li> <li>\\"+(addFigure(itemArray[i].price))+"(税込)</li> <li>掛米："+(itemArray[i].kakemaiName)+"</li> <li>精米歩合："+(itemArray[i].kakemaiPer)+"%</li> <li>日本酒度："+(itemArray[i].sakeDig)+"</li> <li>酸度"+(itemArray[i].acidDig)+"</li> <li>アルコール度"+(itemArray[i].alcFrecFrom)+""+(itemArray[i].alcFrecFrom && itemArray[i].alcFrecTo?"～" :"")+""+(itemArray[i].alcFrecTo)+"</li> </ul> </div> </li> "
			);
		}
		getElement(ITEM_AREA_ID).innerHTML = text;
	};
	
	function drawListLimit(pageCondition){
		var offset = pageCondition.list * 20;
		getElement(LOW_LIMIT_ID).innerHTML = offset + 1;
		getElement(HIGH_LIMIT_ID).innerHTML = Math.min(offset + 20, _count) == _count ? _count : offset + 20 ;
	};
	
	
	function drawListPages(pageCondition){
		var first = 0 < pageCondition.list - 2 ? pageCondition.list - 2 : 0;
		var last = pageCondition.max > first + 5 ? first + 5 : pageCondition.max;
		getElement("listPageArray").innerHTML = getHTML(pageCondition, first, last);
	};
	
	function getHTML(pageCondition, first,last){
		var text = "";
		text = text.concat(getPageForwardHTML(pageCondition));
		for(var i = first; i < last; i++){
			text = text.concat(getPageNumberHTML(i, pageCondition));
		}
		text = text.concat(getPageBackwardHTML(pageCondition));
		return text;
	}
	
	
	function getPageForwardHTML(pageCondition){
		if(pageCondition.list - 1 >= 0){
			return "<a href=javascript:listPageChange("+(pageCondition.list - 1)+")>前</a>&nbsp;";
		} else {
			return "<a>前</a>&nbsp;"
		}
	}
	
	
	function getPageBackwardHTML(pageCondition){
		if(pageCondition.list + 1 < pageCondition.max){
			return "<a href=javascript:listPageChange("+(pageCondition.list + 1)+")>次</a>&nbsp;";
		} else {
			return "<a>次</a>&nbsp;"
		}
	}
	
	
	function getPageNumberHTML(count, pageCondition){
		if(count == pageCondition.list){
			return "<a>"+(count + 1)+"</a>&nbsp;";
		} else {
			return "<a href=javascript:listPageChange("+(count)+")>"+(count + 1)+"</a>&nbsp;";
		}
	}
};


function switchPriceCategory(priceGroup){
	if(!priceGroup.selectedItem){
		return;
	}
	if(priceGroup.selectedItem.min && !priceGroup.selectedItem.first){
		var group = parseInt(priceGroup.selectedItem.valueGroup);
		getElement(PRICE_CATEGORY.concat(group)).style.display = "none";
		getElement(PRICE_CATEGORY.concat(group - 1)).style.display = "block";
	}
	if(priceGroup.selectedItem.max && !priceGroup.selectedItem.last){
		var group = parseInt(priceGroup.selectedItem.valueGroup);
		getElement(PRICE_CATEGORY.concat(group)).style.display = "none";
		getElement(PRICE_CATEGORY.concat(group + 1)).style.display = "block";
	}
};

function complementArray(array, maxLength){
	for(var i = 0; i < array.length; i++){
		if(array[i] == null || array[i] == ""){
			array[i] = "0";
		}
	}
	while(array.length < maxLength){
		array.push("0");
	}
	return array;
};

function getElementsByClassName(target, elm){
	var ary = new Array();
	if(!elm){
		elm = document;
	}
	var childs = elm.childNodes;
	for(var i = 0; i < childs.length; i++){
		if(childs[i].className == target){
			ary.push(childs[i]);
		}
		if(childs[i].hasChildNodes()){
			ary.push(getElementsByClassName(target, childs[i]));
		}
	}
	return ary;
};

function decodeToPriceMaster(priceArray){
	var ary = new Array();
	var categoryArray = getAllHash(priceArray, "categoryGroup");
	for(var i = 0; i < categoryArray.length; i++){
		var rows = selectByKey(priceArray, categoryArray[i], "categoryGroup");
		ary[i] = {
			rows: rows,
			category: categoryArray[i]
		}
	}
	return ary;
};


function getAllHash(ary, hashName){
	if(!hashName){
		hashName = 0;
	}
	var returnAry = new Array();
	for(var i = 0; i < ary.length; i++){
		if(array_findItem(returnAry, ary[i][hashName]) < 0){
			returnAry.push(ary[i][hashName]);
		}
	}
	return 	returnAry;
};

function selectByKey(ary, key, column){
	var returnAry = new Array();
	for(var i = 0; i < ary.length; i++){
		if(ary[i][column] == key){
			returnAry.push(ary[i]);
		}
	}
	return returnAry;
};

function array_findItem_by_attribute(array, item, attribute){
	for(var i = 0; i < array.length; i++){
		if(array[i][attribute] == item){
			return i;
		}
	}
	return -1;
};


function format(text) {
  for (i = 1; i < arguments.length; i++) {
    var reg = new RegExp("\\{" + (i - 1) + "\\}", "g");
    text = text.replace(reg,arguments[i]);
  }
  return text;
};


function getSequenceFromCount(i){
	return i + 1;
};

function addFigure(text) {
	var num = new String(text).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
};
var MapBaseObj = '01';
var MapTitleIndex = 0;
var MapTextIndex = 1;
var MapCoordsIndex = 2;
var MapSrc = 3;
var MapChildIndex = 4;
var MapCoords = {
	'01':[
		'日本'
		,null
		,null
		,'japan_all.gif'
		,{
			'01':[
				'北海道'
				,[79,20]		
				,[[162,57,160,53,154,51,156,46,160,48,168,46,187,53,190,45,196,40,203,39,212,35,205,29,208,20,199,25,190,23,168,2,170,20,164,38,154,35,156,42,148,47,148,54,153,56,151,62,156,63]]		
			]
			,'02':[
				'東北'
				,[124,75]		
				,[[164,111,174,91,167,72,166,63,163,62,155,66,154,72,149,75,150,88,148,100,150,109,142,126,144,128,151,126,162,129]]		
				,'touhoku.gif'
				,{
					'02':[
						'青森県 '
						,[121,29]		
						,[[103,20,112,20,114,37,121,30,127,35,132,22,129,19,127,22,117,22,119,7,127,9,131,16,139,12,135,26,138,45,144,49,141,56,121,60,120,54,91,52,89,45,93,39,101,38,103,29]]		
					]
					,'03':[
						'秋田県 '
						,[54,70]		
						,[[114,92,122,70,123,62,121,62,119,55,93,52,90,69,86,72,81,72,83,77,91,77,93,89,87,108,106,113,110,119,117,114]]		
					]
					,'04':[
						'岩手県 '
						,[154,80]		
						,[[123,60,141,56,145,52,152,70,156,86,153,105,147,115,140,113,139,120,131,121,116,113,116,104,114,94,120,76]]		
					]
					,'05':[
						'山形県 '
						,[50,118]		
						,[[110,138,110,121,106,114,87,109,87,117,78,131,88,142,83,146,79,159,98,164,101,154]]		
					]
					,'06':[
						'宮城県 '
						,[139,134]		
						,[[147,116,141,114,139,120,132,122,117,114,110,118,111,136,102,155,116,163,122,159,126,141,133,137,141,142,140,127]]		
					]
					,'07':[
						'福島県 '
						,[120,179]		
						,[[122,159,115,163,102,156,98,164,83,162,75,174,68,177,64,186,69,199,88,189,94,190,106,201,124,196,127,176]]		
					]
				}
			]
			,'03':[
				'関東'
				,[127,135]		
				,[[141,125,144,127,150,126,159,129,157,136,161,143,152,157,138,150,140,145,133,134]]		
				,'kantou.gif'
				,{
					'08':[
						'群馬県 '
						,[0,54]		
						,[[108,88,107,83,94,82,86,74,92,54,84,48,88,27,76,22,68,15,66,19,60,21,59,28,54,30,55,34,50,35,50,41,46,41,29,45,22,54,19,67,25,72,35,71,38,76,32,84,34,100,40,107,63,94,70,81,95,91]]		
					]
					,'09':[
						'栃木県 '
						,[124,10]		
						,[[150,25,148,36,146,45,149,61,144,69,125,76,108,90,107,83,93,82,86,73,93,54,84,49,87,27,120,7,132,7,147,15]]		
					]
					,'10':[
						'茨城県 '
						,[164,77]		
						,[[188,32,171,25,173,29,164,36,150,25,147,47,149,61,144,70,125,77,109,90,118,104,143,119,168,113,192,130,179,107,170,85,170,80,175,76,173,65,183,47]]		
					]
					,'11':[
						'千葉県 '
						,[153,148]		
						,[[118,105,143,120,167,114,193,130,174,135,160,152,159,160,162,171,160,176,146,185,142,184,131,194,129,202,119,203,114,196,118,194,118,177,121,173,116,166,118,161,125,159,139,143,131,137,127,142,122,141,126,132,124,123,127,117]]		
					]
					,'12':[
						'埼玉県 '
						,[22,106]		
						,[[126,118,108,89,95,92,70,82,64,94,40,107,44,114,55,119,59,116,91,127,123,123]]		
					]
					,'13':[
						'東京都 '
						,[39,125]		
						,[[117,145,114,141,122,140,126,132,124,124,92,128,59,117,57,118,62,130,78,143,88,143,94,151,94,141,100,139,110,147]]		
					]
					,'14':[
						'神奈川県 '
						,[26,170]		
						,[[69,137,77,143,88,144,95,150,94,142,100,139,109,148,113,146,117,149,107,158,107,167,112,173,103,185,99,169,83,167,70,173,70,184,63,179,58,172,61,166,62,159,55,159,56,154,69,147]]		
					]
				}
			]
			,'04':[
				'甲信越'
				,[89,99]		
				,[[148,102,150,108,142,125,133,134,140,146,138,151,125,152,122,144,124,126,136,118],[133,113,4]]		
				,'koushinetsu.gif'
				,{
					'15':[
						'新潟県 '
						,[98,53]		
						,[[120,111,127,109,134,100,139,96,140,94,147,99,148,84,143,82,152,71,163,66,163,59,170,46,165,42,169,25,174,25,180,18,162,3,155,15,155,26,146,36,127,46,116,67,106,78,95,85,78,91,69,95,74,98,77,109,84,102,88,107,102,104,112,98,118,103],[98,47,99,32,113,16,116,32,110,47],[145,7,3]]		
					]
					,'16':[
						'長野県 '
						,[33,126]		
						,[[120,111,119,105,112,98,103,104,90,107,85,102,77,109,69,130,68,153,59,159,55,163,63,174,63,181,69,182,63,200,76,200,93,191,93,181,97,176,95,167,105,158,125,160,116,144,118,129,107,128,109,118,115,113]]		
					]
					,'17':[
						'山梨県 '
						,[123,168]		
						,[[115,187,119,193,131,191,140,183,143,174,132,163,122,160,104,158,96,169,99,183,98,195,112,204]]		
					]
				}
			]
			,'05':[
				'東海'
				,[111,155]		
				,[[138,161,141,157,138,152,126,152,122,145,123,136,115,136,113,142,109,145,110,156,105,158,107,165,103,172,116,164,124,160]]		
				,'toukai.gif'
				,{
					'21':[
						'静岡県 '
						,[173,138]		
						,[[169,141,153,135,145,136,127,134,126,123,137,117,147,96,162,85,165,82,165,74,170,66,172,73,169,87,172,90,176,89,179,98,187,99,187,97,189,84,190,80,197,87,214,83,216,88,212,95,216,103,223,103,220,107,221,115,224,118,212,135,203,141,199,135,202,110,208,111,207,108,202,103,193,104,187,108,188,112,178,118,176,123,176,126,171,129,168,135]]		
					]
					,'22':[
						'愛知県 '
						,[66,81]		
						,[[126,134,126,123,137,117,142,107,146,97,139,93,132,96,129,90,124,95,115,89,109,93,103,89,97,81,85,83,78,92,77,100,87,106,90,104,87,113,88,119,86,125,94,132,96,130,93,123,98,126,114,125,114,129,103,136,100,134,97,141,114,138]]		
					]
					,'23':[
						'岐阜県 '
						,[126,26]		
						,[[63,93,69,91,77,100,77,93,82,88,85,83,97,81,104,89,109,94,116,90,124,95,129,91,134,88,134,76,129,71,130,63,124,54,118,53,121,45,126,47,136,35,132,31,135,26,133,23,139,16,126,7,109,7,96,19,94,12,88,17,89,23,83,36,88,45,85,50,70,54,62,52,57,60,59,70,63,72,65,83]]		
					]
					,'30':[
						'三重県 '
						,[58,171]		
						,[[84,105,77,100,70,92,63,94,64,100,63,107,60,115,53,118,47,117,39,122,41,131,39,137,48,144,48,147,42,150,44,159,41,177,37,177,33,184,27,191,35,200,40,190,50,182,53,170,81,161,82,166,89,162,93,149,91,142,83,145,71,136,69,128,80,109]]		
					]
				}
			]
			,'06':[
				'北陸'
				,[62,117]		
				,[[124,127,123,135,115,136,113,142,110,146,100,150,96,146,102,146,105,138,113,131,113,122,120,120]]		
				,'hokuriku.gif'
				,{
					'18':[
						'富山県 '
						,[171,116]		
						,[[197,57,204,63,206,91,194,111,177,104,164,107,159,107,149,123,148,118,143,114,138,114,136,118,134,117,136,95,136,79,145,60,156,58,150,68,161,76,175,76,180,71,180,63,183,60]]		
					]
					,'19':[
						'石川県 '
						,[60,76]		
						,[[156,58,144,60,136,78,136,100,135,111,134,117,138,122,132,133,132,137,126,139,117,131,109,131,99,127,99,122,94,117,102,110,121,87,128,75,134,64,133,60,134,56,130,48,132,40,126,38,132,28,132,22,144,16,147,17,159,12,163,8,167,8,173,5,177,9,178,14,171,17,173,23,171,28,162,26,155,35,155,44]]		
					]
					,'20':[
						'福井県 '
						,[20,146]		
						,[[94,118,99,122,99,127,103,129,108,131,117,131,126,139,132,139,128,145,135,157,133,162,110,166,101,164,98,164,98,171,95,175,85,172,84,173,85,182,73,191,69,188,63,198,52,202,38,199,32,191,33,184,39,187,52,184,60,177,72,168,79,163,73,154,75,149,70,145,74,140,76,133,85,125,85,119,88,120]]		
					]
				}
			]
			,'07':[
				'近畿'
				,[104,176]		
				,[[93,144,100,150,109,147,110,156,105,158,107,164,103,171,99,177,91,170,86,159,86,146,86,146]]		
				,'kinki.gif'
				,{
					'24':[
						'滋賀県 '
						,[179,28]		
						,[[158,92,152,84,147,84,147,78,144,73,147,52,140,42,147,40,155,32,160,30,170,26,170,16,173,18,180,26,180,30,184,31,186,42,183,55,186,62,184,77,179,84,172,86,165,85]]		
					]
					,'25':[
						'京都府 '
						,[89,41]		
						,[[158,92,153,84,148,84,148,79,144,73,147,51,142,45,134,45,126,42,126,36,121,24,111,30,107,28,109,19,112,14,107,9,97,9,87,15,82,16,82,22,86,27,92,27,94,37,85,37,85,45,93,50,98,50,116,63,113,69,125,79,132,79,139,91,138,96,148,98,160,99]]		
					]
					,'26':[
						'大阪府 '
						,[83,112]		
						,[[138,96,140,91,133,80,126,80,113,69,111,72,112,77,117,77,118,94,111,99,114,105,114,110,99,127,92,128,91,133,132,125,133,100]]		
					]
					,'27':[
						'兵庫県 '
						,[20,66]		
						,[[111,99,118,95,118,77,114,78,111,72,116,64,99,50,93,50,85,44,86,38,95,38,93,28,87,28,82,23,82,17,71,14,62,14,49,18,57,45,54,49,46,49,49,55,38,68,37,82,41,89,49,89,68,89,89,103,103,100,106,97,111,97],[89,106,86,104,72,116,66,126,61,127,68,138,82,131,76,125]]		
					]
					,'28':[
						'和歌山県 '
						,[104,172]		
						,[[142,165,127,167,128,159,119,150,131,137,131,125,91,134,96,140,89,147,96,152,90,156,87,164,91,165,110,179,105,181,109,189,136,202,148,192,151,181,141,171],[154,158,149,158,144,165,149,164]]		
					]
					,'29':[
						'奈良県 '
						,[158,126]		
						,[[132,124,133,101,138,95,160,99,157,108,170,117,168,121,164,121,159,126,162,129,159,156,153,159,148,159,142,165,127,167,127,159,119,151,130,137]]		
					]
				}
			]
			,'08':[
				'中国'
				,[12,137]		
				,[[44,164,58,167,86,160,86,146,71,145,62,149,43,160]]		
				,'chugoku.gif'
				,{
					'31':[
						'岡山県 '
						,[179,107]		
						,[[239,74,237,65,234,69,223,72,223,67,209,58,199,64,183,56,170,74,158,77,163,82,159,90,165,100,168,131,184,125,193,131,202,130,219,119,230,107,227,100,227,94,228,84,234,77]]		
					]
					,'32':[
						'広島県 '
						,[104,131]		
						,[[167,132,164,98,159,91,164,83,159,77,131,74,115,87,119,94,87,95,77,101,77,106,70,122,72,131,76,140,81,147,80,141,92,133,99,135,103,146,115,144,122,139,141,139,141,134,153,132,161,138]]		
					]
					,'33':[
						'鳥取県 '
						,[152,22]		
						,[[245,57,246,64,242,68,235,66,232,69,222,71,222,65,209,57,199,63,183,55,170,73,159,77,149,76,155,68,149,62,160,61,164,48,157,38,154,33,164,33,163,38,166,45,175,39,182,39,187,41,210,41,212,39,217,42,225,41,232,38,233,36,239,38]]		
					]
					,'34':[
						'島根県 '
						,[30,59]		
						,[[149,30,154,33,164,47,161,59,149,62,155,67,148,76,131,74,115,86,118,94,87,95,77,102,77,107,63,133,53,133,49,128,50,123,46,123,43,116,47,109,43,102,57,97,74,83,85,74,93,71,100,61,113,56,116,53,118,49,117,43,129,37,143,36]]		
					]
					,'35':[
						'山口県 '
						,[0,124]		
						,[[63,133,54,133,49,128,50,123,46,123,43,116,46,109,43,102,36,107,22,121,17,123,13,119,0,119,0,129,-10,136,0,141,0,159,0,152,2,153,4,160,15,162,18,161,21,153,23,159,45,154,49,157,48,163,51,165,57,163,65,168,69,173,64,179,71,176,82,182,75,176,72,169,76,174,84,174,89,172,96,167,86,169,78,164,79,156,81,146,75,136,71,130,71,121]]		
					]
				}
			]
			,'09':[
				'四国'
				,[66,196]		
				,[[64,185,72,177,76,177,80,180,91,171,87,160,59,168,58,180]]		
				,'shikoku.gif'
				,{
					'36':[
						'香川県 '
						,[153,41]		
						,[[209,55,205,59,184,59,180,64,172,65,168,68,166,64,157,64,146,72,139,67,143,56,137,47,146,51,154,43,158,41,166,37,176,42,183,36,184,44,189,40,193,43,192,47],[183,26,187,26,201,20,201,35,195,31,190,36],[204,28,3],[180,37,4]]		
					]
					,'37':[
						'徳島県 '
						,[188,96]		
						,[[193,118,184,118,180,112,183,108,173,104,173,97,167,89,162,94,156,88,148,88,143,84,146,72,157,64,165,64,169,67,176,64,180,64,184,59,204,59,210,55,216,55,221,59,216,72,217,78,220,77,225,84,220,92,229,94,217,97,205,107,199,108,196,114]]		
					]
					,'38':[
						'高知県 '
						,[90,141]		
						,[[57,169,59,154,55,147,62,151,67,146,67,139,80,134,72,119,87,121,104,92,108,92,112,89,121,89,122,88,130,88,135,84,143,84,146,89,157,89,161,93,168,89,173,96,173,104,184,108,179,111,184,117,194,117,184,130,180,146,170,133,167,129,162,123,150,119,142,117,126,123,123,127,113,132,108,131,105,144,103,149,94,158,94,163,89,161,84,171,84,176,80,177,80,183,82,184,84,192,79,190,78,185,72,184,68,188,62,186,61,182,52,186,57,177]]		
					]
					,'39':[
						'愛媛県 '
						,[28,79]		
						,[[139,67,146,73,142,84,134,84,131,87,112,88,109,92,104,92,92,112,87,121,72,120,80,134,67,140,67,145,61,150,55,147,58,154,57,164,57,169,51,170,46,170,45,172,40,167,43,159,33,159,37,154,42,151,36,143,49,141,45,137,43,132,35,130,38,116,16,124,12,123,21,116,43,109,45,102,62,95,66,87,65,82,62,75,71,77,73,65,85,61,86,55,94,62,100,77,109,74,113,71,120,71,132,74,137,69],[85,70,4],[93,59,93,52,86,50,92,47,92,41,96,40,106,49,99,57]]		
					]			
				}
			]
			,'10':[
				'九州'
				,[2,178]		
				,[[59,167,58,181,47,201,37,208,30,202,24,174,44,165]]		
				,'kyusyu.gif'
				,{
					'40':[
						'福岡県 '
						,[152,19]		
						,[[149,65,141,61,139,64,136,63,131,67,131,70,126,70,126,65,122,59,124,55,134,46,135,41,131,41,128,44,122,37,107,37,111,33,113,26,117,27,123,25,127,24,132,22,132,18,138,11,141,12,146,10,153,12,159,9,163,9,164,13,163,17,160,20,166,30,171,34,170,39,159,39,150,48,150,57,152,60],[132,11,3]]		
					]
					,'41':[
						'佐賀県 '
						,[49,28]		
						,[[122,59,123,55,134,47,136,42,131,41,128,43,122,37,108,37,104,38,102,35,102,31,90,37,96,39,95,44,91,47,94,55,99,55,101,58,98,61,108,70,115,71,111,63,117,57],[92,14,5]]		
					]
					,'42':[
						'長崎県 '
						,[31,65]		
						,[[115,71,108,71,98,61,101,58,100,55,94,55,91,48,95,44,96,39,92,38,91,44,87,40,80,38,76,42,71,37,73,45,67,51,75,51,80,50,84,56,80,62,79,69,85,75,91,84,91,87,86,91,86,94,99,85,106,82,111,82,114,86,107,90,108,94,114,93,120,89,123,83,121,76,116,75],[81,31,3],[57,44,4],[52,49,4],[24,84,33,86,40,83,37,78,49,71,52,75,51,70,58,66,56,62,56,53,48,67,42,69,38,74,31,76,27,73,27,79]]		
					]
					,'43':[
						'熊本県 '
						,[79,103]		
						,[[126,70,131,70,131,67,137,64,139,65,141,62,148,64,156,70,160,68,158,64,160,61,166,62,172,75,173,84,160,100,155,108,160,118,155,121,158,130,136,130,132,124,121,128,117,124,130,107,129,101,137,96,124,99,122,96,133,90,135,84,127,77],[97,120,97,111,101,99,109,98,110,103,119,100,124,101,122,108,115,114]]		
					]
					,'44':[
						'大分県 '
						,[193,64]		
						,[[216,82,203,95,204,90,199,87,196,91,183,91,183,86,179,89,173,85,173,75,168,63,161,61,158,62,160,67,157,70,150,65,153,60,151,58,151,48,160,39,170,39,172,35,185,36,190,31,198,31,202,37,202,46,199,50,194,52,188,52,188,56,190,59,197,59,204,61,207,60,215,73]]		
					]
					,'45':[
						'宮崎県 '
						,[181,120]		
						,[[136,130,158,130,154,123,161,119,156,108,172,85,178,90,183,84,183,90,197,91,199,88,204,91,204,94,194,104,190,114,175,149,177,154,176,164,169,171,169,178,165,179,156,173,160,166,156,164,152,163,149,153,144,150,144,142,138,140]]		
					]
					,'46':[
						'鹿児島県 '
						,[72,170]		
						,[[126,202,144,194,154,186,153,182,148,179,151,175,157,173,162,166,152,163,149,154,144,152,144,143,139,140,136,133,136,128,133,123,122,128,118,123,115,126,110,126,108,117,101,121,108,130,106,132,109,135,109,141,104,147,106,153,111,160,110,169,105,174,99,171,104,183,112,185,118,184,122,191,127,186,123,181,121,171,125,164,131,156,141,160,135,165,131,169,134,178,135,182,133,191,127,196],[132,165,5],[75,153,77,157,83,148,92,143,87,140,80,147]]		
					]
				}
			]
		}
	]
};
var TAB_BUTTON_CLASS_NAME = "searchTabButton";
var NORMAL_SEARCH_AREA_ID = "normalSearch";
var KODAWARI_SEARCH_AREA_ID = "kodawariSearch";
var OMOSHIRO_SEARCH_AREA_ID = "omoshiroSearch";
var NORMAL_SEARCH_BUTTON = "normalSearchButton";
var KODAWARI_SEARCH_BUTTON = "kodawariSearchButton";
var OMOSHIRO_SEARCH_BUTTON = "omoshiroSearchButton";

function changeSearchTab(elm){
	var buttonAry = getElementsByClassName(TAB_BUTTON_CLASS_NAME, elm.parentNode);
	for(var i = 0; i < buttonAry.length; i++){
		if(buttonAry[i] == elm){
			buttonAry[i].style.backgroundColor = "lightblue";
			switch(buttonAry[i].id){
				case NORMAL_SEARCH_BUTTON:
					displayEnable(getElement(NORMAL_SEARCH_AREA_ID));
				break;
				case KODAWARI_SEARCH_BUTTON:
					displayEnable(getElement(KODAWARI_SEARCH_AREA_ID));
				break;
				case OMOSHIRO_SEARCH_BUTTON:
					displayEnable(getElement(OMOSHIRO_SEARCH_AREA_ID));
				break;
			}
		} else if(buttonAry[i].style){
			buttonAry[i].style.backgroundColor = "white";
			switch(buttonAry[i].id){
				case NORMAL_SEARCH_BUTTON:
					displayDisable(getElement(NORMAL_SEARCH_AREA_ID));
				break;
				case KODAWARI_SEARCH_BUTTON:
					displayDisable(getElement(KODAWARI_SEARCH_AREA_ID));
				break;
				case OMOSHIRO_SEARCH_BUTTON:
					displayDisable(getElement(OMOSHIRO_SEARCH_AREA_ID));
				break;
			}
		}
	}
};

function changeTab(elm, buttonId){
	var nodes = elm.parentNode.childNodes;
	for(var i = 0; i < nodes.length; i++){
		if(nodes[i] == elm){
			nodes[i].style.backgroundColor = "lightblue";
		} else {
			nodes[i].style.backgroundColor = "white";
		}
	}
	
	var area = elm.parentNode.parentNode;
	for(var i = 0; i < area.childNodes.length; i++){
		var obj = getElement(area.childNodes[i].id);
		if(!(obj && obj.style)){
			continue;
		}
		if(obj.id == buttonId){
			obj.style.display = "block";
		} else {
			obj.style.display = "none";
		}
	}
};

function Tab() {
	var _groupItems = new Object();
	
	this.addObject = function(buttonId, targetId){
		_groupItems[buttonId] = targetId;
	};
	
	this.removeObject = function(buttonId){
		delete _groupItems[buttonId];
	};
	
	this.click = function(buttonId){
		for(var i in _groupItems){
			var obj = getElement(_groupItems[i]);
			if(i = buttonId){
				obj.style.backgroundColor = "lightBlue";
				obj.style.display = "block";
			} else {
				obj.style.backgroundColor = "white";
				obj.style.display = "none";
			}
		}
	};
};

function displayEnable(elm){
	elm.style.display = "block";
};

function displayDisable(elm){
	elm.style.display = "none";
};
KodawariArray = {
	KodawariCdIndex: 0,
	CategoryNameIndex: 1,
	PanelIndex: 2,
	ChildIndex: 3
};

Panel = {
	StackHorizontal: 1, 
	StackVertical: 2, 
	Tab: 3 
};

KodawariCategory = {
	'01':[
		null
		,''
		,Panel.StackVertical
		,{
			'01':[
				null
				,''
				,Panel.StackVertical
				,{
					'01':[
						'spec'
						,''
						,Panel.StackHorizontal
						,{
							'01':[
								'orig_sake'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'02':[
								'sanpai'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'03':[
								'kimotokei'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'04':[
								'no_filtration_sake'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'05':[
								'siboritate'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'06':[
								'hiyaoroshi'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'07':[
								'fukuroduri'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'08':[
								'funesibori'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'09':[
								'arasibari'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'10':[
								'nakatori'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'11':[
								'tobindori'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'12':[
								'nigorizake'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'13':[
								'usunigori'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'14':[
								'orizake'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'15':[
								'sparkring'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'16':[
								'lowalcohol'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'17':[
								'highacidity'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'18':[
								'taruzake'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'19':[
								'kanpiyoukai'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'20':[
								'touji_name'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'21':[
								'old_sake'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'22':[
								'season_gentei'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'23':[
								'region_gentei'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'24':[
								'route_gentei'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'25':[
								'no_chemical_rice'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'26':[
								'organic_rice'
								,''
								,Panel.StackHorizontal
								,{}
							]
						}
					]
					,'02':[
						'syori_chozo'
						,''
						,Panel.StackVertical
						,{
							'01':[
								'proc_method_01'
								,'処理方法'
								,Panel.StackHorizontal
								,{}
							]
							,'02':[
								'proc_method_02'
								,'貯蔵方法-1'
								,Panel.StackHorizontal
								,{}
							]
							,'03':[
								'proc_method_03'
								,'貯蔵方法-2'
								,Panel.StackHorizontal
								,{}
							]
						}
					]
				}
			]
			,'02':[
				null
				,''
				,Panel.StackVertical
				,{
					'01':[
						'nomikata'
						,'お勧めの飲み方'
						,Panel.StackVertical
						,{
							'01':[
								'drink_cold'
								,'冷やして'
								,Panel.StackHorizontal
								,{}
							]
							,'02':[
								'drink_normal'
								,'常温'
								,Panel.StackHorizontal
								,{}
							]
							,'03':[
								'drink_nurukan'
								,'ぬる燗'
								,Panel.StackHorizontal
								,{}
							]
							,'04':[
								'drink_atsukan'
								,'熱燗'
								,Panel.StackHorizontal
								,{}
							]
							,'05':[
								'drink_rock'
								,'オンザロック'
								,Panel.StackHorizontal
								,{}
							]
						}
					]
				}
			]
			,'03':[
				'kodawariTab'
				,''
				,Panel.Tab
				,{
					'01':[
						'ajiwai'
						,'味わい'
						,Panel.StackVertical
						,{
							'01':[
								't_noutan'
								,'濃淡'
								,Panel.StackVertical
								,{}
							]
							,'02':[
								't_amakara'
								,'甘口・辛口'
								,Panel.StackHorizontal
								,{}
							]
							,'03':[
								't_sannmi'
								,'酸味'
								,Panel.StackHorizontal
								,{}
							]
							,'04':[
								't_shibumi'
								,'渋味'
								,Panel.StackHorizontal
								,{}
							]
							,'05':[
								't_umami'
								,'旨み'
								,Panel.StackHorizontal
								,{}
							]
							,'06':[
								't_kire'
								,'キレ・余韻'
								,Panel.StackVertical
								,{}
							]
							,'07':[
								't_type'
								,'タイプ'
								,Panel.StackVertical
								,{}
							]
							
						}
					]
					,'02':[
						'kaoriSoftHard'
						,'香りの強弱'
						,Panel.StackVertical
						,{
							'01':[
								'f_01'
								,''
								,Panel.StackHorizontal
								,{}
							]
						}
					]
					,'03':[
						'kaoriPoint'
						,'香りの特徴'
						,Panel.StackHorizontal
						,{
							'01':[
								'f_11'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'02':[
								'f_12'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'03':[
								'f_13'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'04':[
								'f_14'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'05':[
								'f_15'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'06':[
								'f_16'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'07':[
								'f_17'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'08':[
								'f_18'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'09':[
								'f_19'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'10':[
								'f_20'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'11':[
								'f_21'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'12':[
								'f_22'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'13':[
								'f_23'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'14':[
								'f_24'
								,''
								,Panel.StackHorizontal
								,{}
							]
							,'15':[
								'f_25'
								,''
								,Panel.StackHorizontal
								,{}
							]
						}
					]
					,'04':[
						'aisyo'
						,'料理との相性'
						,Panel.StackVertical
						,{
							'01':[
								'dish01'
								,''
								,Panel.StackVertical
								,{}
							]
							,'02':[
								'dish02'
								,''
								,Panel.StackVertical
								,{}
							]
							,'03':[
								'dish03'
								,''
								,Panel.StackVertical
								,{}
							]
							,'04':[
								'dish04'
								,''
								,Panel.StackVertical
								,{}
							]
							,'05':[
								'dish05'
								,''
								,Panel.StackVertical
								,{}
							]
						}
					]
				}
			]
		}
	]
};

var local;
var pref;
var company;
var type;
var brand;
var tpo;
var img;
var kodawari;

var kodawariLength;
var priceLength;

var itemList;


Application.server = "spookserver";
Application.cacheToObject = Config.rowMapping;

Application.loadedHandler = {
	"Decoder": function(loader, cache) {
		localMaster = cache.Local;
		prefMaster = cache.Pref;
		
		local = new Local(cache.Local, cache.Length[0].local);
		
		pref = new Pref(cache.Pref, cache.Length[0].pref);
		
		company = new Company(cache.Company, cache.Length[0].company);
		company.drawButton();
		
		type = new Type(cache.Type, cache.Length[0].type);
		type.drawButton();
		
		brand = new Brand(cache.Brand, cache.Length[0].brand);
		brand.drawButton();
		
		tpo = new Tpo(cache.Tpo, cache.TpoCategory, cache.Length[0].tpo);
		tpo.drawButton();
		
		img = new Img(cache.Img, cache.ImgCategory, cache.Length[0].img);
		img.drawButton();
		
		kodawari = new Kodawari(cache.Kodawari, cache.Length[0].kodawari);
		kodawari.drawContents();
		
		var priceMaster = decodeToPriceMaster(cache.PriceCategory);
		
		priceLength = cache.Length[0].price;

		drawPrice(priceMaster);
		
		registPrice(priceMaster);
		
		ActionCondition.update("ConditionState");
	},
	"ConditionState": function(loader, cache) {		
		
		switchPriceCategory(ActionCondition.getGroup("price"));
		
		var localGroup = ActionCondition.getGroup("local");
		var prefGroup = ActionCondition.getGroup("pref");

		if(!localGroup || (localGroup && !localGroup.selectedItem)){
			_removeLinkMapGuideAll(localGroup);
			local.removeMapGuide();
			local.drawMap(localGroup, MapCoords[MapBaseObj]);
			pref.removeMapGuide();
		}
		
		if((localGroup && localGroup.selectedItem) && (!prefGroup || !prefGroup.selectedItem)){
			_addLinkMapGuideAll(localGroup, MapCoords[MapBaseObj][MapChildIndex]);
			local.addMapGuide(localGroup, MapCoords[MapBaseObj][MapChildIndex]);
			pref.drawMap(localGroup, MapCoords[MapBaseObj][MapChildIndex]);
			pref.removeMapGuide();
		}
		
		if((localGroup && localGroup.selectedItem) && (prefGroup && prefGroup.selectedItem)){
			pref.addMapGuide(localGroup, prefGroup, MapCoords[MapBaseObj][MapChildIndex]);
		}
		
		local.saveKuraCount(cache.LocalKuraCount[0]);
		local.drawKuraCount(cache.LocalKuraCount[0]);
		pref.drawKuraCount(cache.PrefKuraCount[0]);
		local.drawItemCount(cache.LocalCount[0]);
		pref.drawItemCount(cache.PrefCount[0]);		
		type.drawItemCount(cache.TypeCount[0]);

		kodawari.drawCount(cache.KodawariCount[0]);
		tpo.drawItemCount(cache.TpoCount[0]);
		img.drawItemCount(cache.ImgCount[0]);
		drawPriceCount(cache.PriceCount[0], priceLength);
		
		company.switchButtonDisplay(cache.Company);
		brand.switchButtonDisplay(cache.Brand);
		drawGoodsCount(cache.GoodsCount[0]);
		
		drawSearchCondition(ActionCondition.groups); 
		
		ActionCondition.update("List");
		
		itemList = new ItemList(cache.GoodsCount[0]);
	},
	"List": function(locader, cache) {
		itemList.drawListMenu();
		itemList.drawListItem(cache.Item);
	}
};

Application.loaded = function(loader){
	return Application.loadedHandler[loader.command](loader, Primrose.getCache(loader.command));
};

Application.fireEvent = function(eventId){
	switch(eventId){
		case "local":
		case "pref":
		case "company":
		case "type":
		case "brand":
		case "kodawari":
		case "tpo":
		case "img":
		case "price":
		case "reload":
			ActionCondition.update("ConditionState");
			break;
		case "list":
			ActionCondition.update("List", ["Page=", itemList.pageCondition.list * 20].join(""));
		default:
			break;
	}
};

Application.onStart = function(){
	ActionCondition.update("Decoder");
};

Application.onDestroy = function(){
};

function listPageChange(arg){
	itemList.pageCondition.list = arg;
	Application.fireEvent("list");
};

function clearLocalMapSelect() {
	var localGroup = ActionCondition.getGroup("local");
	var prefGroup = ActionCondition.getGroup("pref");
	if(localGroup.selectedItem){
		localGroup.remove(localGroup.selectedItem);
	}
	if(prefGroup.selectedItem){
		prefGroup.remove(prefGroup.selectedItem);
	}
	Application.fireEvent("reload");
};

function removeCondition(groupName, selectedItemName){
	var group = ActionCondition.getGroup(groupName);
	if(selectedItemName){
		group.remove(group.selectedItems[selectedItemName]);
	} else {
		group.remove(group.selectedItem);		
	}
	
	if(groupName == "local"){
		var prefGroup = ActionCondition.getGroup("pref");
		if(prefGroup && prefGroup.selectedItem){
			prefGroup.removeAll();
		}
	}
	Application.fireEvent("reload");	
};

function clearCondition(){
	ActionCondition.removeAll();
	Application.fireEvent("reload");
};
