/*--- jquery.tooltip.js ---*/
/**
* $.tooltip
*/
(function($){

	/* extend browser detection */
	$.browser.msie6 = $.browser.msie && $.browser.version==6;
	
	/**
	 * noCache
	 * @ most browser has cache problem about ajaxed content.
	 * @ this funciton add the useless url parameter to the url.
	 * @ this will be prevent browser to cache the page.
	 */
	function noCache(url){
		return url.concat(/\?/.test(url)?"&":"?","noCache=",(new Date).getTime(),".",Math.random()*1234567)
	}
	
	$.tooltip = {
		globalConfig: {
			singleTip: true
		},
		defaultTipConfig: {
			mode: "ajax",
			behavior: "chaseHover", // chaseHover or click
			life: 3000, 
			delay: 500,
			offsetX: 5,
			offsetY: -15,
			adjustOffsetX_L: null,
			adjustOffsetX_R: null,
			adjustOffsetClass_L: "typeR",
			adjustOffsetClass_R: "typeL",
			useBottom: false,
			tipPosition: "right", // right or left
			width: "auto", // css length value
			height: "auto", // css length value
			opacity: 1, // 0 <= n <= 1
			iframeLayer: false,
			iframeSrc: "javascript:false;",
			singleTip: true,
			tipClass: null,
			tipHTML: (function(){
				var html="";
				html+= '<div class="tip-containerDiv"><table class="tip-containerTable"><tr><td class="tip-containerTd">';
				html+= '</td></tr></table></div>';
				return html;
			})(),
			speed_fadeIn: 300,
			speed_fadeOut: 300,
			disableClick: false,
			titleAsTipURL: false,
			tipLoadCallback: null
		},
		tips: [],
		register: function(s){
			var tip = new this.Tip(s);
			tip.construct();
			if(!this.tips.length){
				/* click anywhere to close tip */
				$(document.body).click(function(){
					$.tooltip.closeAllTips();
				});
			}
			this.tips.push(tip);
			return tip;
		},
		closeAllTips: function(){
			$(this.tips).each(function(){
				this.closeAllTips();
			});
		},
		getViewportInfo: function(){
			return {
				scrollLeft: $(window).scrollLeft(),
				scrollTop: $(window).scrollTop(),
				width: $(document.body).width(),
				height: $(window).height()
			};
		}
	}
	
	$.tooltip.Tip = function(s){
		this.s = s; // store received setting
		var def = $.tooltip.defaultTipConfig;
		this.config = {
			mode: s.mode ? s.mode : def.mode,
			behavior: s.behavior ? s.behavior : def.behavior,
			life: s.life ? s.life : def.life,
			delay: s.delay ? s.delay : def.delay,
			offsetX: s.offsetX ? s.offsetX : def.offsetX,
			offsetY: s.offsetY ? s.offsetY : def.offsetY,
			adjustOffsetX_L: s.adjustOffsetX_L!=undefined ? s.adjustOffsetX_L : def.adjustOffsetX_L,
			adjustOffsetX_R: s.adjustOffsetX_R ? s.adjustOffsetX_R : def.adjustOffsetX_R,
			adjustOffsetClass_L: s.adjustOffsetClass_L ? s.adjustOffsetClass_L : def.adjustOffsetClass_L,
			adjustOffsetClass_R: s.adjustOffsetClass_R ? s.adjustOffsetClass_R : def.adjustOffsetClass_R,
			useBottom: s.useBottom ? s.useBottom : def.useBottom,
			tipPosition: s.tipPosition ? s.tipPosition : def.tipPosition,
			width: s.width ? s.width : def.width,
			height: s.height ? s.height : def.height,
			opacity: s.opacity ? s.opacity : def.opacity,
			iframeLayer: s.iframeLayer ? s.iframeLayer : def.iframeLayer,
			iframeSrc: s.iframeSrc ? s.iframeSrc : def.iframeSrc,
			singleTip: s.singleTip ? s.singleTip : def.singleTip,
			tipClass: s.tipClass ? s.tipClass : def.tipClass,
			tipHTML: s.tipHTML ? s.tipHTML : def.tipHTML,
			speed_fadeIn: s.speed_fadeIn ? s.speed_fadeIn : def.speed_fadeIn,
			speed_fadeOut: s.speed_fadeOut ? s.speed_fadeOut : def.speed_fadeOut,
			special: s.special ? s.special : false,
			disableClick : s.disableClick ? s.disableClick : false,
			titleAsTipURL: s.titleAsTipURL ? s.titleAsTipURL : def.titleAsTipURL,
			tipLoadCallback: s.tipLoadCallback ? s.tipLoadCallback : def.tipLoadCallback
		};
		this.tipsets = []; // store the array of { opener: element, tip: element }
		this.currentTipset;
	}
	$.tooltip.Tip.prototype = {
		construct: function(){
			if(!this.s.opener) return;
			var opener = $(this.s.opener);
			if(!opener.size()) return;
			this.prepareBgIframe();
			this.prepareURLData(opener);
			var tipsets = this.createTipsets(opener);
			this.setOpenEvents(tipsets);
			this.tipsets = this.tipsets.concat(tipsets);
		},
		prepareURLData: function(opener){
			var self = this;
			opener.each(function(){
				var opener = $(this);
				var URL;
				if(self.config.titleAsTipURL){
					URL = opener.attr("title");
					opener.attr("title","");
				}else{
					URL = opener.attr("href");
				}
				$(this).data("ajaxURL",URL);
			});
		},
		createTipsets: function(opener){
			var tip = this;
			var tipsets = [];
			opener.each(function(){
				var opener = $(this);
				var tipElem = $(tip.config.tipHTML);
				tipsets.push({
					opener: opener,
					tipContainerDiv: tipElem,
					tipContainerTable: tipElem.find("table.tip-containerTable"),
					tipContainerTd: tipElem.find("td.tip-containerTd"),
					visible: false,
					closeTimer: null,
					showTimer: null
				});
				tipElem.css("width",tip.config.width);
				$(document.body).append(tipElem);
			});
			return tipsets;
		},
		prepareBgIframe: function(){
			/* prepare iframe for select hide */
		},
		setOpenEvents: function(tipsets){
			var tip = this;
			if(tip.config.disableClick){
				$(tipsets).each(function(){
					var tipset = this;
					tipset.opener.click(function(){
						return false;
					});
				});
			}
			$(tipsets).each(function(){
				var tipset = this;
				if(tip.config.behavior=="click"){
					tipset.opener.click(function(evt){
						tip.openTip(tipset,evt);
						return false;
					});
				}
				if(tip.config.behavior=="chaseHover"){
					tipset.opener.hover(function(evt){
						tip.openTip(tipset,evt);
					},function(){
						if(tipset.showTimer){
							tip.cancelShowTimer(tipset);
						}
					});
				}
			});
		},
		openTip: function(tipset,evt){
			var tip = this;
			if($.tooltip.globalConfig.singleTip){
				$.tooltip.closeAllTips();
			}else if(tip.config.singleTip){
				tip.closeAllTips();
			}
			tip.updateTipPos(evt,tipset);
			tipset.visible = true;
			tip.startShowTimer(tipset);
			var URL = tipset.opener.data("ajaxURL");
			tipset.tipContainerTd.load(URL, function(){
				tip.updateTipPos(evt,tipset);
				tip.setEventsInsideTip(tipset);
				if(tip.config.life) tip.startCloseTimer(tipset);
				if($.fn.rollover) tipset.tipContainerTd.rollover();
				if($.fn.addClip) tipset.tipContainerTd.find("a.addClip").addClip();
				if(tip.config.tipLoadCallback) tip.config.tipLoadCallback();
				tipset.tipContainerDiv.click(function(evt){
					evt.stopPropagation();
				});
			});
			this.currentTipset = tipset;
		},
		setEventsInsideTip: function(tipset){
			var tip = this;
			tipset.tipContainerDiv.find("a.closeTooltip").click(function(){
				if(!tipset.visible) return false;
				tip.closeTip(tipset);
				return false;
			});
			tipset.tipContainerDiv.hover(function(){
				tip.cancelCloseTimer(tipset);
			},function(){
				tip.startCloseTimer(tipset);
			});
		},
		startShowTimer: function(tipset){
			var tip = this;
			tipset.showTimer = setTimeout(function(){
				tipset.tipContainerDiv.show();
			},tip.config.delay);
		},
		cancelShowTimer: function(tipset){
			if(tipset.showTimer) clearTimeout(tipset.showTimer);
		},
		startCloseTimer: function(tipset){
			var tip = this;
			tipset.closeTimer = setTimeout(function(){
				tip.closeTip(tipset);
			},tip.config.life);
		},
		cancelCloseTimer: function(tipset){
			if(tipset.closeTimer) clearTimeout(tipset.closeTimer);
		},
		closeTip: function(tipset){
			if(!tipset.visible) return;
			tipset.visible = false;
			tipset.tipContainerDiv.hide();
		},
		closeCurrentTip: function(){
			if(this.currentTipset) this.closeTip(this.currentTipset);
		},
		closeAllTips: function(){
			var self = this;
			self.currentTipset = null;
			$(self.tipsets).each(function(){
				self.cancelShowTimer(this);
				this.tipContainerDiv.hide();
				this.visible = false;
			});
		},
		updateTipPos: function(evt,tipset){
			var tipDiv = tipset.tipContainerDiv;
			var tipTd = tipset.tipContainerTd;
			var CSSWidth = this.config.width;
			var viewport = $.tooltip.getViewportInfo();
			var mousePosX = evt.pageX;
			var mousePosY = evt.pageY;
			var offsetX = this.config.offsetX;
			var offsetY = this.config.offsetY;
			var CSSLeft,CSSRight,CSSTop,CSSBottom;
			/* 
			 * caliculate width.
			 */
			var computedTipWidth = tipDiv.innerWidth();
			var computedTipHeight = tipDiv.innerHeight();
			
			/* special: sideOfAnchor */
			if(this.config.special=="sideOfAnchor"){
				/* calc from opener pos */
				var opener = tipset.opener;
				var openerOffset = opener.offset();
				var openerWidth = opener.width();
				if(this.config.useBottom){
					CSSBottom = viewport.height-openerOffset.top+this.config.offsetY;
					CSSLeft = openerOffset.left+this.config.offsetX;
					
					/* adjust offset if adjustOffsetX_L or adjustOffsetX_R was specified */
					var typeDiv = tipTd.children("div").eq(0).children("div").eq(0);
					if(this.config.adjustOffsetX_L!=null && CSSLeft<3){
						CSSLeft = openerOffset.left+this.config.adjustOffsetX_L;
						/* add adjustOffsetClass if adjustOffsetClass_L was specified */
						if(this.config.adjustOffsetClass_L){
							typeDiv.addClass(this.config.adjustOffsetClass_L);
						}
					}else if(this.config.adjustOffsetX_R!=null && CSSLeft+computedTipWidth>viewport.width){
						CSSLeft = openerOffset.left+this.config.adjustOffsetX_R;
						/* add adjustOffsetClass if adjustOffsetClass_R was specified */
						if(this.config.adjustOffsetClass_R){
							typeDiv.addClass(this.config.adjustOffsetClass_R);
						}
					}else{
						typeDiv.removeClass(this.config.adjustOffsetClass_L);
						typeDiv.removeClass(this.config.adjustOffsetClass_R);
					}
			
				}else{
					CSSTop = openerOffset.top+this.config.offsetY;
					CSSLeft = openerOffset.left+openerWidth+this.config.offsetX;
					if(viewport.width+viewport.scrollLeft<CSSLeft+computedTipWidth+5){
						// if tip occured the overflow-x, change it to left side.
						if(CSSLeft>computedTipWidth+5){
							CSSRight = viewport.width-openerOffset.left+5;
							CSSLeft = null;
						}
					}
				}
			}else{
				/* 
				 * caliculate CSSLeft or CSSRight.
				 * invert direction of tip if the tip make the browser appear scroll-x
				 */
				var fixedWidth = true;
				switch(this.config.tipPosition){
					case "right":
						if(fixedWidth && (viewport.width+viewport.scrollLeft<mousePosX+computedTipWidth+offsetX+5)){
							// if tip occured the overflow-x, change it to left side.
							// but, if maxWidth was not set or swapped tip was too wide, ignore this.
							if(mousePosX>computedTipWidth+offsetX){
								CSSRight = viewport.width-mousePosX+offsetX;
							}else{
								CSSLeft = mousePosX+offsetX;
							}
						}else{
							CSSLeft = mousePosX+offsetX;
						}
						break;
					case "left":
						if(fixedWidth && (mousePosX<computedTipWidth+offsetX+5)){
							// if tip occured the overflow-x, change it to right side.
							// but, if maxWidth was not set or swapped tip was too wide, ignore this.
							if(viewport.width<mousePosX+computedTipWidth+offsetX){
								CSSRight = viewport.width-mousePosX+offsetX;
							}else{
								CSSLeft = mousePosX+offsetX;
							}
						}else{
							CSSRight = viewport.width-mousePosX+offsetX;
						}
						break;
					default:
						break;
				}
				/* 
				 * caliculate CSSTop.
				 * adjust cssTop if the tip was over the window
				 */
				if(offsetY<0 && mousePosY-viewport.scrollTop+offsetY<0){
					/* if top was over the window, avoid it */
					if(offsetX>0){
						CSSTop = viewport.scrollTop;
					}else{
						CSSTop = mousePosY+offsetY;
					}
				}else if(mousePosY+computedTipHeight+offsetY>viewport.scrollTop+viewport.height){
					/* if bottom was over the window, avoid it */
					if(offsetX>0){
						CSSTop = viewport.scrollTop+viewport.height-computedTipHeight;
					}else{
						CSSTop = mousePosY+offsetY;
					}
				}else{
					CSSTop = mousePosY+offsetY;
					/* if the tip content was too much and hidden, avoid it */ 
					if(CSSTop+computedTipHeight>viewport.scrollTop+viewport.height){
						CSSTop = viewport.scrollTop;
					}
				}
			}
			
			
			/* set tip position */
			if(CSSTop) tipDiv.css({ "bottom":"auto","top":CSSTop });
			if(CSSBottom) tipDiv.css({ "top":"auto","bottom":CSSBottom });
			if(CSSLeft) tipDiv.css({ "right":"auto", "left":CSSLeft });
			if(CSSRight) tipDiv.css({ "left":"auto", "right":CSSRight });
			/* bgIframe */
			/*
			if($bgIframe){
				$bgIframe.css("top",CSSTop)
				if(CSSLeft) $bgIframe.css({ "right":"auto", "left":CSSLeft });
				if(CSSRight) $bgIframe.css({ "left":"auto", "right":CSSRight });
				$bgIframe.width(tipDiv.innerWidth()+self.tipBorderWRight+self.tipBorderWLeft); // add border width
				$bgIframe.height(tipDiv.innerHeight()+self.tipBorderWTop+self.tipBorderWBottom); // add border width
			}
			*/
		},
		
		/**
		 * addExtraOpener
		 * @ receive new opener.
		 * @ receive jQuery element object
		 */
		addExtraOpener: function(opener){
			this.prepareURLData(opener);
			var tipsets = this.createTipsets(opener);
			this.setOpenEvents(tipsets);
			this.tipsets = this.tipsets.concat(tipsets);
		}
		
	}
	
	
	
})(jQuery);
/*--- jquery.tooltip.js ---*/

/*
 * 郵便番号検索
 */
var CITYTOWN_MAX_BYTE = 40;
jQuery.fn.ajaxAddressSearch = function(config) {
	config = jQuery.extend({
		action: XY.config.pageContext.ctx + "/entry/ajax/address/search",
		zip1: "#zip1",
		zip2: "#zip2",
		prefLabel: "#addr1Label",
		pref: "#addr1Text",
		citytown: "#addr2",
		disabledColor: "#F2F2F2",
		isLvExec : false,
		isDbFlgCheck: false,
		dbFlg: "#useDbAddrFlg",
		dbFlgNotUseValue: "0"
	}, config);
	
	if($(config.zip1).val() == "" || $(config.zip2).val() == ""){
		$(config.citytown).attr("readonly", true);
		$(config.citytown).css("background-color", config.disabledColor);
	}
	
	var lvfadeOutTime;
	if(config.isLvExec) lvfadeOutTime = jQuery.lvconfig.fadeOutTime;
	var zip1Cache = config.zip1;
	var zip2Cache = config.zip2;
	$(this).bind("keyup", function() {
		if(zip1Cache == (config.zip1 + $(config.zip1).val()) && zip2Cache == (config.zip2 + $(config.zip2).val())) {
			return;
		}
		zip1Cache = config.zip1 + $(config.zip1).val();
		zip2Cache = config.zip2 + $(config.zip2).val();
		var zipno = $(config.zip1).val() + "-" + $(config.zip2).val();
		if(!zipno.match(/^[0-9０-９]{3}-[0-9０-９]{4}$/)) {
			$(config.prefLabel).text("");
			$(config.pref).val("");
			$(config.citytown).val("");
			$(config.citytown).attr("readonly", true);
			$(config.citytown).css("background-color", config.disabledColor);
			if(config.isLvExec) {
				jQuery.lvconfig = Customer.copy({}, jQuery.lvconfig, {fadeOutTime : 0});
				$(config.citytown).change();
				jQuery.lvconfig = Customer.copy({}, jQuery.lvconfig, {fadeOutTime : lvfadeOutTime});
			}
		} else {
			$.post(config.action, {zipno:zipno}, function(json) {
				if(json.addressCd == null) {
					$(config.prefLabel).text("");
					$(config.pref).val("");
					$(config.citytown).val("");
					if(config.isDbFlgCheck) {
						$(config.dbFlg).val(config.dbFlgNotUseValue);
					}
					$(config.citytown).attr("readonly", true);
					$(config.citytown).css("background-color", config.disabledColor);
					if(config.isLvExec) {
						$(config.citytown).change();
					}
				} else {
					$(config.prefLabel).text(json.pref);
					$(config.pref).val(json.pref);
					var town = json.town;
					if(town == null) town = "";
					if(!textByteCheck(json.city + town)) town = "";
					$(config.citytown).val(json.city + town);
					if(config.isDbFlgCheck) {
						$(config.dbFlg).val(config.dbFlgNotUseValue);
					}
					$(config.citytown).removeAttr("readonly");
					$(config.citytown).css("background-color", "");
					
					if(config.isLvExec) {
						$(this).bind("ajaxStop", function() {
							$(config.citytown).change();
							$(this).unbind("ajaxStop");
						});
					}
				}
			}, "json" );
		}
	});
};

function textByteCheck(str) {
	var count=0;
	for(i=0;i<str.length;i++) {
		(str.charAt(i).match(/[ｱ-ﾝ]/) || escape(str.charAt(i)).length< 4) ? count++ : count+=2;
	}
	if(count <= CITYTOWN_MAX_BYTE) {
		return true
	}
	return false;
}

/*
 * zexy会員JavaScript Library
 * 
 */
var Customer = {
	//static isFunction(any value) : boolean
	isFunction: function(value){
		return typeof value === "function" || $.isFunction(value);
	},
	//static copy(object base[, object value...]) : object
	copy: function(base){
		if(base){
			for(var a=arguments,i=1,m=a.length; i<m; i++){
				var v = a[i];
				for(var p in v){
					base[p] = v[p];
				}
			}
		}
		return base;
	},
	//static copyStr(object base[, string value...])
	copyStr: function(base){
		if(base){
			for(var a=arguments,i=1,m=a.length; i<m; i++){
				var v = a[i], j=0;
				for(var p in base){
					if(j < v.length) {
						base[p] = v[j++];
					}
				}
			}
		}
		return base;
	},
	//static interceptor(function fn, object advices) : function
	interceptor : function(fn, advices){
		var contextClass = function(){};
		Customer.copy(contextClass.prototype, {
			fn : fn,
			proceed : function(){
				return this.fn.apply(this.scope, this.args);
			}
		});
		return function(){
			var context = new contextClass();
			context.scope = this;
			context.args = arguments;
			if(Customer.isFunction(advices.before)){
				advices.before.apply(context, arguments);
			}
			var r = Customer.isFunction(advices.around)
					?advices.around.apply(context, arguments)
					:fn.apply(this, arguments)
			if(Customer.isFunction(advices.after)){
				advices.after.apply(context, arguments);
			}
			return r;
		};
	},
	//static format(string str[, object value...])
	format: function(str){
		if(str){
			for(var a=arguments,i=1,m=a.length; i<m; i++){
				var v = a[i];
				for(var p in v){
					str = str.replace("${"+p+"}",v[p]);
				}
			}
		}
		return str;
	}
}

Customer.copy(Customer, {
	//static confirm([object options]) : void
	confirm: function(){
		var impl = $.modal.impl;
		impl.open = Customer.interceptor(impl.open, {
			after: function(){
				Customer.rollover();
			}
		});
		return function(options) {
			Customer.modal(options, "confirm");
		};
	}(),
	//static dialog([object options]) : void
	dialog: function(){
		var impl = $.modal.impl;
		impl.open = Customer.interceptor(impl.open, {
			before: function(){
				var o = Customer.config.dialog.options;
				if(Customer.isFunction(o.onopen)){
					o.onopen.apply(null, [options]);
				}
				var options = impl.opts;
				if(options.overlayClose){
					$("#" + options.overlayId).click(function(){
						Customer.closeDialog();
					});
				}
				$(document.body).attr("scroll","no");
				$("div#simplemodal-overlay").css("height",2000);
			},
			after: function(){
				Customer.config.dialog.resize();
			}
		});
		impl.close = Customer.interceptor(impl.close, {
			after: function(){
				var o = Customer.config.dialog.options;
				if(Customer.isFunction(o.onclose)){
					o.onclose.apply(null, [options]);
				}
				$(document.body).attr("scroll","auto");
			}
		});
		return function(options) {
			Customer.modal(options, "dialog");
		};
	}(),
	//static pallet([object options]) : void
	pallet: function(){
		return function(options) {
			Customer.modal(options, "pallet");
		};
	}(),
	//static modal([object options,[string configName]]) : void
	modal: function(){
		return function(options, configName) {
			var config = Customer.config[configName];
			options = Customer.copy({}, config.options, options);
			options.attrs = Customer.copy({}, config.options.attrs, options.attrs);
			
			var html = options.html ? options.html:options.el ? $(options.el).html():null;
			if( ! html && Customer.isFunction(options.creator)){
				html = options.creator.apply(null, [options]);
			}
			else if(html) {
				html = $("<div />").attr("id", "lbContents").append(html);
			}
			$.modal(html, options);
		};
	}(), 
	//static modalResize(string height) : void
	modalResize: function() {
		return function(height, width) {
			if($("div#simplemodal-data").children("iframe:first").length) {
				$("div#simplemodal-data").children("iframe:first").attr("height", height).attr("width", width);
			}
		};
	}(),
	//static closeConfirm() : void
	closeConfirm: function(){
		$("div#lbContents .hover").unbind("hover");
		Customer.closeModal($.modal.impl.dialog);
	},
	//static closeDialog() : void
	closeDialog: function(){
		Customer.closeModal($.modal.impl.dialog);
	},
	//static closePallet() : void
	closePallet: function(){
		Customer.closeModal($.modal.impl.dialog);
	},
	//static closeModal() : void
	closeModal: function(dialog) {
		dialog.data.fadeOut(200, function() {
			dialog.container.slideUp(200, function() {
				dialog.overlay.fadeOut(200, function() {
					$.modal.close();
				});
			});
		});
	},
	//static disabledCheck()
	disabledCheck: function() {
		return function() {
			var selected = $("input:checkbox[@name^='selectedChk']");
			if ($("input:checkbox[@name^='selectedChk']:checked").length >= 1) {
				var gyoshu = $("input:checkbox[@name^='selectedChk']:checked").attr("class");
				selected.attr("disabled", "disabled");
				$("input:checkbox[class=" + gyoshu + "]").removeAttr("disabled");
			} else {
				selected.removeAttr("disabled");
			}
			selected.click(function(){
				if ($("input:checkbox[@name^='selectedChk']:checked").length >= 1) {
					var gyoshu = $("input:checkbox[@name^='selectedChk']:checked").attr("class");
					selected.attr("disabled", "disabled");
					$("input:checkbox[class=" + gyoshu + "]").removeAttr("disabled");
				} else {
					selected.removeAttr("disabled");
				}
			});
		};
	}(),
	//static sendToList([object options])
	sendToList: function() {
		return function(options) {
			var options = Customer.copy({}, Customer.config.sendToList.options, options);
			if(!$("#sendToName .sendTrg" + options.memberId).length) {
				$("#sendToName").append(
					$("<span />").attr("class", "target sendTrg" + options.memberId).append(
						$("<span />").text(options.memberName + " ")
					).append(
						$("<a />").attr("href", "javascript:void(0)").attr("class", "deleteSendTo").append(
							$("<img />").attr("class", "hover").attr("src", "/images/common/btn_close_02.gif")
							.attr("width", "19").attr("height", "19")
						).append(
							$("<input type='hidden' />").attr("name", "sendToId").val(options.memberId)
						)
					)
				);
			}
		}
	}(),
	//static anniversaryToList([object options])
	anniversaryToList: function() {
		return function(options) {
			var options = Customer.copy({}, Customer.config.anniversary.options, options)
			var toNameStyleId = "#toName" + options.toList.anivId + "_"
				+ options.toList.configKbn + "_"
				+ options.toList.elementNamePrefix + "_"
				+ options.toList.listIndex;
			if(!$(toNameStyleId + " .trg" + options.setToList.memberId).length) {
				$(toNameStyleId).append(
					$("<span />").attr("class", "target trg" + options.setToList.memberId).text(options.setToList.memberName + " ").append(
						$("<a />").attr("href", "javascript:void(0)").attr("class", "deleteSendTo").append(
							$("<img />").attr("class", "hover").attr("src", "/images/common/btn_close_02.gif")
							.attr("width", "19").attr("height", "19")
						).append(
							$("<input type='hidden' />")
								.attr("name", options.toList.elementNamePrefix 
									+ "[" + options.toList.listIndex + "]"
									+ "." 
									+ options.toList.configKbn 
									+ "MemberId").val(options.setToList.memberId)
						)
					)
				);
			}
		}
	}(),
	//static popup(string path, string name, object options) : void
	popup: function popup(path, options){
		var o = Customer.copy({}, Customer.config.popup.options, options);
		var optionsArray = [];
		var name = o.name;
		delete o.name;
		for(var n in o){
			optionsArray.push(n + "=" + o[n]);
		}
		var sw = window.open(path, name, optionsArray.join(","));
		sw.focus();
	},
	//static tooltip(object e, [object options,[object info]])
	tooltip: function (){
		return function(e, options, info) {
			var o = Customer.copy({}, Customer.config.tooltip.options, options);
			var i = Customer.copy({}, Customer.config.tooltip.info, info);
			var tip;
			Customer.closeTooltip();
			if($("div.tip-containerDiv").length) {$("div.tip-containerDiv").remove();}
			$.tooltip.tips = [];
			tip = new $.tooltip.Tip(o);
			tip.prepareBgIframe();
			tip.tipsets = tip.createTipsets($(o.opener));
			$.tooltip.tips.push(tip);
			$(tip.tipsets).each(function(){
				var tipset = this;
				if(tipset.opener.css("display") == "none") {
					tipset.opener.css("display", "block");
				}
				if(tipset.opener.css("position") == "absolute" && 
					$("div#" + Customer.config.dialog.options.containerId).length) {
					tipset.opener.css({
						top: (parseInt($("div#" + Customer.config.dialog.options.containerId).offset().top) 
								+ parseInt(i.dispBaseOffset.top)),
						left: (parseInt($("div#" + Customer.config.dialog.options.containerId).offset().left) 
								+ parseInt(i.dispBaseOffset.left))
					});
				} else if (tipset.opener.css("position") == "absolute"){
					tipset.opener.css({
						top: parseInt(i.dispBaseOffset.top),
						left: parseInt(i.dispBaseOffset.left)
					});
				}
				tipset.visible = false;
				tipset.opener.data("ajaxURL", i.url);
				tip.openTip(tipset, e);
			});
		}
	}(),
	//static tooltipRegister([object options])
	tooltipRegister: function tooltip(){
		return function(options) {
			var o = Customer.copy({}, Customer.config.tooltipRegister.options, options);
			$.tooltip.register(o);
		}
	}(),
	//static closeTooltip()
	closeTooltip: function(){
		if($.tooltip.globalConfig.singleTip){
			$($.tooltip.tips).each(function(){
				tip = this;
				tip.closeAllTips();
			}); 
		}
	},
	//static parentLocationChange(string url)
	parentLocationChange: function(){
		return function(url) {
			if(parent) {
				parent.location.href = url;
			}
			else {
				Customer.closeTooltip();
				location.href = url;
			}
		}
	}(),
	//static rollover()
	rollover: function(){
		return function() {
			$("div#lbContents .hover").not("img[src*='_on.'],img[src*='_cr.']").hover(
				function () { $(this).attr( 'src', RLO.rollover.newimage($(this).attr('src')) ); },
				function () { $(this).attr( 'src', RLO.rollover.oldimage($(this).attr('src')) ); }
			);
		}
	}(),
	//static listeners : object
	listeners: {
		resizeModal: function(){
			//lightboxリサイズリスナ
			if($("#lbContents").length && parent){
				$("div.popWrapperSecond").each(function(){
					if($(this).height() > 500){
						$("div.popM").addClass("scrollM");
						$("div.popL").addClass("scrollL");
					}
				});
				parent.Customer.modalResize(
					$(document.body).outerHeight() < 520 ? $(document.body).outerHeight() : 520,
					$("div.popM,div.popL,div.popS").css("width").replace("px", ""));
				parent.Customer.config.dialog.resize();
				parent.Customer.closeTooltip();
				parent.$("div#simplemodal-data").children("iframe:first").css("visibility","visible");
			}
		},
		beforeResizeHidden: function(){
			//lightboxリサイズ前非表示リスナ
			if($("#lbContents").length && parent){
				$(window).unload(function(){
					parent.Customer.closeTooltip();
					parent.$("div#simplemodal-data").children("iframe:first").css("visibility","hidden");
				});
			}
		},
		openToList: function(){
			//宛先選択リスナの登録
			$("#openSendToListDialog, #openSubSendToListDialog").click(function(e){
				e.preventDefault();
				e.stopPropagation();
				var url = $(this).attr("id") == "openSendToListDialog" ?
					 Customer.config.sendToList.options.normalMemberUrl :
					 	Customer.config.sendToList.options.subMemberUrl;
				url += "?authRedirectPath=" + $(this).attr("class")
					.replace(
						"authRedirectPath ", ""
					).replace(
						XY.config.pageContext.ctx, ""
					);
				Customer.dialog({
					attrs:{
						src: url,
						height: 183,
						style: null
					}
				});
				return false;
			});
		},
		deleteTo: function(){
			//宛先削除リスナの登録
			var deleteSendToList = function (){
				$("a.deleteSendTo").click(function(e){
					e.preventDefault();
					e.stopPropagation();
					$(this).parent("span:first").remove();
					return false;
				});
			}();
		},
		closeModal: function(){
			//modalクローズリスナ
			$("a.closeModal").click(function(e){
				e.preventDefault();
				e.stopPropagation();
				parent.Customer.closeDialog();
			});
		},
		popupWindow: function(){
			//ポップアップウインドウリスナ
			$(".popupWindow").click(function(e){
				var href = $(this).attr("href");
				Customer.popup(href);
				e.preventDefault();
				e.stopPropagation();
				return false;
			});
		},
		parentLocationChange: function(){
			//親画面遷移リスナ
			$(".parentLocationChange").click(function(e){
				var href = $(this).attr("href");
				Customer.parentLocationChange(href);
				e.preventDefault();
				e.stopPropagation();
				return false;
			});
		},
		setAuthRedirectPath: function(){
			//ログイン画面遷移前画面登録リスナ
			if($("a.authRedirectPath").length) {
				$("a.authRedirectPath").addClass(location.pathname);
			}
		},
		logout: function(){
			// ログアウトボタンオンクリックリスナ
			$("a.logout").click(function(e) {
				e.preventDefault();
				e.stopPropagation();
				location.href = $(this).attr("href");
				$(this).unbind("click");
				$(this).bind("click", function(e) {
					e.preventDefault();
					e.stopPropagation();
  					return false;
				});
				return false;
			});
		}
	}
});

//onloadタイミングのリスナー実行
$(function(){
	$.each(Customer.config.listeners.ready, function(){
		this.apply();
	});
});

Customer.config = {
	confirm: {
		options: {
			attrs: {
				id: null,
				"class": null,
				style: null,
				title: "",
				longdesc: "",
				name: "shared",
				src: null,
				width: 460,
				height: 160,
				scrolling: "no",
				frameborder: "0",
				marginwidth: "0",
				marginheight: "0",
				allowtransparency: "true"
			},
			html:null,
			el:null,
			form:"#mainForm",
			action:null,
			okBtnClass:".okBtn",
			creator: function(options){
				return $("<div />")
					.append($("<iframe />").attr(options.attrs))
					.html();
			},
			appendTo: "body",
			focus: true,
			overlayId: "simplemodal-overlay",
			overlayCss: {},
			containerId: "simplemodal-container",
			containerCss: {},
			dataId: "simplemodal-data",
			dataCss: {},
			minHeight: null,
			minWidth: null,
			maxHeight: null,
			maxWidth: null,
			autoResize: false,
			zIndex: 1000,
			close: true,
			closeClass: "closeModal",
			escClose: true,
			overlayClose: true,
			position: "fixed",
			persist: false,
			onOpen: null,
			onShow: function(dialog){
				$(Customer.config.confirm.options.okBtnClass).click(function() {
					Customer.closeConfirm(dialog);
					var form = $(Customer.config.confirm.options.form); 
					var action = Customer.config.confirm.options.action ? 
						$(Customer.config.confirm.options.action) : $(form).attr("action");
					form.attr("action", action).submit();
					$(this).unbind("click");
				});
			},
			onClose: Customer.closeConfirm
		}
	},
	dialog: {
		options: {
			attrs: {
				id: null,
				"class": null,
				"style": null,
				title: "",
				longdesc: "",
				name: "shared",
				src: null,
				width: 1,
				height: 0,
				scrolling: "no",
				frameborder: "0",
				marginwidth: "0",
				marginheight: "0",
				allowtransparency: "true"
			},
			html:null,
			creator: function(options){
				var now = new Date();
				options.attrs.name = "shared" + now.getTime();
				return $("<div />")
					.append($("<iframe />").attr(options.attrs))
					.html();
			},
			appendTo: "body",
			focus: true,
			opacity: 80,
			overlayId: "simplemodal-overlay",
			overlayCss: {
				backgroundColor: "#000000",
				position: "fixed",
				width: 2000,
				height: 2000
			},
			containerId: "simplemodal-container",
			containerCss: {
				padding: 0,
				margin: 0
			},
			dataId: "simplemodal-data",
			dataCss: {},
			minHeight: null,
			minWidth: null,
			maxHeight: null,
			maxWidth: null,
			autoResize: false,
			zIndex: 1000,
			close: true,
			closeClass: "closeModal",
			escClose: false,
			overlayClose: true,
			persist: false,
			onOpen: null,
			onShow: null,
			onClose: Customer.closeDialog
		},
		resize: function(){
			var impl = $.modal.impl;
			for(var n in impl.dialog){
				var container = $("#" + impl.opts.containerId),
					w = $(window);
				var top = parseInt((w.height() / 2) - (container.height() / 2));
				var left = parseInt((w.width() / 2) - (container.width() / 2));
				container
					.css({
						top: top < 0 ? 0 : top,
						left: left < 0 ? 0 : left
					});
				return;
			}
		}
	},
	pallet: {
		options: {
			attrs: {
				id: null,
				"class": null,
				style: null,
				title: "",
				longdesc: "",
				name: "shared",
				src: null,
				width: 460,
				height: 160,
				scrolling: "no",
				frameborder: "0",
				marginwidth: "0",
				marginheight: "0",
				allowtransparency: "true"
			},
			html:null,
			el:null,
			form:"#mainForm",
			action:null,
			okBtnClass:".okBtn",
			creator: function(options){
				return $("<div />")
					.append($("<iframe />").attr(options.attrs))
					.html();
			},
			appendTo: "body",
			focus: true,
			overlayId: "simplemodal-overlay",
			overlayCss: {},
			containerId: "simplemodal-container",
			containerCss: {},
			dataId: "simplemodal-data",
			dataCss: {},
			minHeight: 240,
			minWidth: 450,
			maxHeight: null,
			maxWidth: null,
			autoResize: false,
			zIndex: 1000,
			close: true,
			closeClass: "closeModal",
			escClose: true,
			overlayClose: false,
			position: "fixed",
			persist: false,
			onOpen: null,
			onShow: function(dialog){
				$(Customer.config.confirm.options.okBtnClass).click(function() {
					Customer.closeConfirm(dialog);
					var form = $(Customer.config.confirm.options.form); 
					var action = Customer.config.confirm.options.action ? 
						$(Customer.config.confirm.options.action) : $(form).attr("action");
					form.attr("action", action).submit();
				});
			},
			onClose: Customer.closePallet
		}
	},
	sendToList: {
		options: {
			normalMemberUrl: XY.config.pageContext.ctx + "/entry/sendToList",
			subMemberUrl: XY.config.pageContext.ctx + "/entry/sendToList/sub",
			memberId: null,
			memberName: null
		}
	},
	anniversary: {
		options: {
			toList: {
				anivId: null,
				configKbn: null,
				elementNamePrefix: null,
				listIndex:null
			},
			setToList: {
				memberId: null,
				memberName: null
			}
		}
	},
	popup: {
		name: "_sub",
		width: 800,
		menubar: "yes",
		toolbar: "yes",
		location: "yes",
		status: "yes",
		resizable: "yes",
		scrollbars: "yes"
	},
	tooltip: {
		options: {
			opener: "div.openTip",
			width: "450px",
			special: "sideOfAnchor",
			disableClick: true,
			useBottom: true,
			offsetX: -185,
			offsetY: 5,
			adjustOffsetX_L:-3,
			adjustOffsetX_R:-365,
			life: null,
			delay: null,
			tipLoadCallback: null,
			tipContainerDivClass: "tip-containerDiv",
			tipHTML: (function(){
				var html="";
				html+= '<div class="tip-containerDiv"><table class="tip-containerTable"><tr><td class="tip-containerTd">';
				html+= '</td></tr></table></div>';
				return html;
			})()
		},
		info: {
			url: null,
			dispBaseOffset: null
		}
	},
	tooltipRegister: {
		options: {
			opener: null,
			width: "450px",
			special: "sideOfAnchor",
			disableClick: true,
			useBottom: true,
			offsetX: -195,
			offsetY: 5,
			adjustOffsetX_L:-18,
			adjustOffsetX_R:-375,
			life: 3000000,
			delay: null,
			tipLoadCallback : null
		}
	},
	listeners: {
		ready: [
			Customer.listeners.beforeResizeHidden,
			Customer.listeners.resizeModal,
			Customer.listeners.openToList,
			Customer.listeners.deleteTo,
			Customer.listeners.closeModal,
			Customer.listeners.popupWindow,
			Customer.listeners.parentLocationChange,
			Customer.listeners.setAuthRedirectPath,
			Customer.listeners.logout
		]
	}
};
