var MeikanSearch = function () {};/*@cc_on _d=document;eval('var document=_d')@*/MeikanSearch.prototype = {	requestUrl: '/search/sc-{ceo_enterprise_name}/fw-{free_word}/',	ajaxRequestUrl: '/search/ajax/',	actionName: 'action_main_search_result',	errorMessage: {		'length': 'length error...'	},	init: function (themeList, resultTotal, pageItemLimit, tooltip) {		this.ui.init(this, tooltip.freeword, tooltip.ceoEnterprise);		this.theme.init(this, themeList);		this.pager.init(this, this.ajaxRequestUrl, this.ui.resultEndId, resultTotal, pageItemLimit);	},	submitForm: function (windowCheck) {		if (windowCheck == null) {			windowCheck = true;		}		if (windowCheck == true && ($('#' + this.ui.enterpriseCondId).css('display') != 'none' || $('#' + this.ui.ceoCondId).css('display') != 'none')) {			return false;		}		var free_word = $('#' + this.ui.freeWordId);		var ceo_enterprise_name = $('#' + this.ui.ceoEnterpriseNameId);		var form = $('#' + this.ui.formId);		var actionName = $("input[@name^='" + this.actionName + "']", form);		actionName.attr('disabled', true);		ceo_enterprise_name.attr('disabled', true);		free_word.attr('disabled', true);		if (free_word.attr('class').match(/show_tooltip/)) {			free_word.val('');		}		if (ceo_enterprise_name.attr('class').match(/show_tooltip/)) {			ceo_enterprise_name.val('');		}		if (free_word.val().length > 100 || ceo_enterprise_name.val().length > 100) {			alert(this.errorMessage.length);			return false;		}		var requestUrl = this.requestUrl.replace('{free_word}', encodeURIComponent(free_word.val())).replace('{ceo_enterprise_name}', encodeURIComponent(ceo_enterprise_name.val())).replace(/%2F/g, '%252F');		form.attr('action', requestUrl);		form.submit();	}}MeikanSearch.prototype.ui = {	parent: null,	formId: 'main_search_box',	defaultPosition: {		x: 100,		y: 300	},	ceoCondId: 'search_ceo_cond',	ceo: null,	enterpriseCondId: 'search_enterprise_cond',	enterprise: null,	freeWordId: 'main_search_free_word',	ceoEnterpriseNameId: 'main_search_ceo_enterprise_name',	condPrefix: 'main_search_cond_',	groupParentPrefix: 'main_search_group_parent_',	groupChildPrefix: 'main_search_group_child_',	groupParentClass: 'main_search_parent',	groupChildClass: 'main_search_child',	condChildClass: 'main_search_cond_child',	nowCondLabelClass: 'main_search_now_cond_label',	nowCondInputClass: 'main_search_now_cond_input',	resultEndId: 'main_search_result_end',	dragHandleClass: 'draggable_handle',	clearFlag: false,	init: function (parent, freeWord, ceoEnterpriseName) {		this.parent = parent;		var self = this;		$('#' + this.freeWordId).keypress(function (e) {			if (self.getKeyCode(e) == 13) {				self.parent.submitForm();			}		});		$('#' + this.ceoEnterpriseNameId).keypress(function (e) {			if (self.getKeyCode(e) == 13) {				self.parent.submitForm();			}		});		this.ceo = $('#' + this.ceoCondId);		this.enterprise = $('#' + this.enterpriseCondId);	},	getKeyCode: function (e) {		if (e.keyCode != 0) {			return e.keyCode;		} else {			return e.charCode;		}	},	setTextboxTooltip: function (id, text) {		var tooltip = text;		var textBox = $('#' + id);		textBox.focus(function () {			if ($(this).attr('class').match(/show_tooltip/)) {				$(this).css('color', '#000000');				$(this).removeClass('show_tooltip');				$(this).val('');			}		});		textBox.blur(function () {			if ($(this).val() == '') {				$(this).addClass('show_tooltip');				$(this).css('color', '#999999');				$(this).val(tooltip);			}		});		if (textBox.val() == '') {			textBox.addClass('show_tooltip');			textBox.val(tooltip);		} else {			textBox.css('color', '#000000');		}	},	change: function (elm, name) {		var inputElm = $('#main_search_' + name);		var orderElm = $('#main_search_order');		if (elm.value != '') {			inputElm.attr('disabled', false);			inputElm.val(elm.value);		} else {			inputElm.attr('disabled', true);			inputElm.val(null);		}		orderElm.val(name + '::asc');		this.parent.submitForm(false);	},	changeCheckbox: function (elm, name) {		var inputElm = $('#main_search_' + name);		if (elm.checked) {			inputElm.attr('disabled', false);			inputElm.val(1);		} else {			inputElm.attr('disabled', true);			inputElm.val(null);		}		this.parent.submitForm(false);	},	changePref: function (elm, name) {		if (elm.value) {			this.change(elm, name);		}		this.parent.submitForm(false);	},	changeYear: function (name) {		var month = this.getDateElement(name, 'month').get(0);		var day = this.getDateElement(name, 'day').get(0);		month.style.display = 'block';		day.style.display = 'none';	},	changeMonth: function (name) {		var day = this.getDateElement(name, 'day').get(0);		day.style.display = 'block';	},	changeDay: function (name) {		var year = $('#form_' + this.condPrefix + name + '_year');		var month = $('#form_' + this.condPrefix + name + '_month');		var day = $('#form_' + this.condPrefix + name + '_day');		var inputYearElm = $('#main_search_' + name + '_year');		var inputMonthElm = $('#main_search_' + name + '_month');		var inputDayElm = $('#main_search_' + name + '_day');		inputYearElm.attr('disabled', false);		inputYearElm.val(year.val());		inputMonthElm.attr('disabled', false);		inputMonthElm.val(month.val());		if (day.val() != null) {			inputDayElm.attr('disabled', false);			inputDayElm.val(day.val());		} else {			inputDayElm.attr('disabled', true);			inputDayElm.val(null);		}		this.parent.submitForm(false);	},	getDateElement: function (name, type) {		var windowElm = $('#main_search_cond_' + name);		return $('.main_search_' + type, windowElm);	},	changeGroup: function (elm, groupName) {		var windowElm = $('#' + this.condPrefix + 'group_' + groupName);		var parentElmAll = $('.' + this.groupParentClass, windowElm);		var childElmAll = $('.' + this.groupChildClass, windowElm);		var parentElm = $('#' + this.groupParentPrefix + elm.value);		parentElmAll.each(function () {			this.style.display = 'none';		});		childElmAll.each(function () {			this.style.display = 'none';		});		parentElm.css('display', 'block');	},	changeGroupParent: function (elm, groupName, name) {		this.filterOptions('form_' + this.condPrefix + name, elm);		var childElm = $('#' + this.groupChildPrefix + name);		childElm.css('display', 'block');	},	changeGroupMini: function (elm, groupName) {		var windowElm = $('#' + this.condPrefix + 'group_' + groupName);		var childElmAll = $('.' + this.groupChildClass, windowElm);		var childElm = $('#' + this.groupChildPrefix + elm.value);		childElmAll.each(function () {			this.style.display = 'none';		});		childElm.css('display', 'block');	},	filterOptions: function (id, selectedElm) {		var optionsResource = $('#' + id + '__resource/option');		var values = selectedElm.value.split(',');		var startIdx = parseInt(values[0]);		var endIdx = parseInt(values[1]);		var clearFlag = this.clearFlag;		if (!endIdx) {			$('#' + id).css('display', 'none');			$('#' + id + '_label').empty();			return false;		}		$('#' + id).empty();		$('#' + id).css('display', 'block');		$('#' + id + '_label').html(selectedElm.options[selectedElm.selectedIndex].text);		optionsResource.each(function () {			var value = this.value;			if (startIdx <= value && value <= endIdx) {				$(this).clone().appendTo('#' + id);			}		});		if (clearFlag) {			$('#' + id + ' option').each(function () {				this.selected = null;			});		}	},	open: function (id, draggable, xadjust, yadjust) {		if (draggable == null) {			draggable = true;		}		if (xadjust == null) {			xadjust = 0;		}		if (yadjust == null) {			yadjust = 0;		}		var elm = $('#' + id);		if (elm.css('display') != 'none') {			return false;		}		elm.css('display', 'block');		elm.css('position', 'absolute');		elm.css('left', this.defaultPosition.x + xadjust + 'px');		elm.css('top', this.defaultPosition.y + yadjust + 'px');		if (draggable) {			elm.Draggable({				handle: '.' + this.dragHandleClass			});			var handleElm = $('.' + this.dragHandleClass, elm);			handleElm.css('cursor', 'move');		}	},	close: function (id) {		var elm = $('#' + id);		elm.css('display', 'none');	},	openCeoCond: function () {		this.closeEnterpriseCond();		this.open(this.ceoCondId);	},	closeCeoCond: function () {		this.closeChildAll();		this.close(this.ceoCondId);	},	openEnterpriseCond: function () {		this.closeCeoCond();		this.open(this.enterpriseCondId);	},	closeEnterpriseCond: function () {		this.closeChildAll();		this.close(this.enterpriseCondId);	},	openChild: function (name) {		this.closeChildAll();		var elmId = this.condPrefix + name;		this.open(elmId, true, 50, 50);		$('#form_' + elmId + '_label').html('');		$('#form_' + elmId).css('display', 'none');		var childWin = $('#' + elmId);		childWin.addClass(this.condChildClass);	},	openChildGroup: function (name) {		this.closeChildAll();		var elmId = this.condPrefix + 'group_' + name;		this.open(elmId, true, 50, 50);		var childWin = $('#' + elmId);		childWin.addClass(this.condChildClass);	},	openChildDate: function (name) {		this.closeChildAll();		var elmId = this.condPrefix + name;		this.open(elmId, true, 50, 50);		var year = this.getDateElement(name, 'year').get(0);		var month = this.getDateElement(name, 'month').get(0);		var day = this.getDateElement(name, 'day').get(0);		month.style.display = 'none';		day.style.display = 'none';	},	closeChild: function (name) {		var elmId = this.condPrefix + name;		this.close(elmId);	},	closeChildGroup: function (name) {		var elmId = this.condPrefix + 'group_' + name;		this.close(elmId);	},	closeChildAll: function () {		var childWindowsElms = $('.' + this.condChildClass);		childWindowsElms.css('display', 'none');	},	clear: function () {		var inputElms = $('.' + this.nowCondInputClass);		var labelElms = $('.' + this.nowCondLabelClass);		var selectTags = $('select');		selectTags.each(function () {			for (i = 0; i < this.length; i++) {				this.options[i].selected = false;			}		});		inputElms.each(function () {			this.value = null;			this.disabled = true;		});		this.clearFlag = true;		labelElms.remove();	}}MeikanSearch.prototype.pager = {	parent: null,	resultTotal: 0,	pageItemLimit: 0,	page: 2,	request: false,	requestUrl: null,	ajaxTimeout: 2000,	resultEndId: null,	listenInterval: 300,	itv: null,	windowHeight: 800,	hasNextResult: true,	loadingMessage: 'Loading...',	searchEndMessage: '',	init: function (parent, requestUrl, resultEndId, resultTotal, pageItemLimit) {		this.parent = parent;		this.requestUrl = requestUrl;		this.resultEndId = resultEndId;		this.resultTotal = resultTotal;		this.pageItemLimit = pageItemLimit;		var resultEnd = $('#' + this.resultEndId);		if (resultEnd.size() < 1) {			return false;		}		var self = this;		this.itv = setInterval(function () {			if (self.positionIsBottom() && self.hasNextResult && !self.request) {				self.loadNextPage();			}		},		self.listenInterval);	},	positionIsBottom: function () {		// Updated on 2009-09-07		return (this.getPageHeight() - this.getPageScrollY() < 300);		/*		var resultBottomPos = this.getResultBottomPos();		var currentPos = this.getCurrentPos();		if (resultBottomPos <= currentPos + this.windowHeight) {			return true;		} else {			return false;		}		*/	},	loadNextPage: function () {		if (this.resultTotal <= this.pageItemLimit * (this.page - 1)) {			return false;		}		var loadingNow = '<div id="main_search_loading" style="margin:bottom: 1em;">' + '<img src="/images/loading.gif" />' + '<strong>{message}</strong>' + '</div>';		loadingNow = loadingNow.replace('{message}', this.loadingMessage);		$('#' + this.resultEndId).before(loadingNow);		$.ajaxTimeout(this.ajaxTimeout);		this.request = true;		var self = this;		var host = location.host;		var params = this.getRequestParams();		params['page'] = this.page;		params['referrer'] = host;		$.post('/search/ajax/', params, function (res, status) {			$('#main_search_loading').remove();			if (status == 'success' && res.length > 0) {				self.page++;				$('#' + self.resultEndId).before(res);				self.request = false;			} else {				$('#' + self.resultEndId).before(self.searchEndMessage);				self.hasNextResult = false;			}		});	},	ajaxTimeout: function () {		$('#main_search_loading').remove();	},	getRequestParams: function () {		var params = new Object();		var f = $('#' + this.parent.ui.formId).get(0);		for (var i = 0; i < f.elements.length; i++) {			if (f.elements[i].value && f.elements[i].disabled == false && !(f.elements[i].className.match(/show_tooltip/))) {				params[f.elements[i].name] = f.elements[i].value;			}		}		return params;	},	getCurrentPos: function () {		var pos = document.documentElement.scrollTop;		return pos;	},	getResultBottomPos: function () {		return this.getElmPosition(this.resultEndId).top;	},	getElmPosition: function (id) {		var elm = document.getElementById(id);		var top = 0;		var left = 0;		while (elm) {			top += elm.offsetTop;			left += elm.offsetLeft;			elm = elm.offsetParent;		}		return {			left: left,			top: top		};		//---------- Add start 2009-09-07 ----------	},		getPageScrollY : function(){		if(window.pageYOffset){			return window.pageYOffset;		}else if(document.documentElement && document.documentElement.scrollTop){			return document.documentElement.scrollTop;		}else if(document.body){			return document.body.scrollTop;		}	},	getInnerHeight : function(){		if(window.innerHeight && window.scrollMaxY){			return window.innerHeight + window.scrollMaxY;		}else if (document.body.scrollHeight > document.body.offsetHeight){			return document.body.scrollHeight;		}else{			return document.body.offsetHeight;		}	},	getWindowHeight : function(){		var windowHeight = 0;		if(window.innerHeight){		  return window.innerHeight;		}else if(document.documentElement && document.documentElement.clientHeight){		  return document.documentElement.clientHeight;		}else if(document.body){		  return document.body.clientHeight;		}	},	getPageHeight : function(){		var i = this.getInnerHeight();		var w = this.getWindowHeight();		return ((i < w) ? w : i) - w;//---------- Add end 2009-09-07 ----------		}}MeikanSearch.prototype.theme = {	parent: null,	id: 'main_search_box_theme',	offset: null,	limit: 4,	reflesh_time: 9000,	item: [],	liTemplate: '<li><a href="/search/?t_theme_id={t_theme_id}">{title} ({count})</a></li>',	init: function (parent, themeList) {		this.parent = parent;		this.item = themeList;		this.offset = this.limit;		if (this.item.length <= this.limit) {			void(0);		}		var self = this;		this.itv = setInterval(function () {			var elm = $('#' + self.id);			var themeHtml = '';			self.shuffle(themeList);			elm.empty();			for (var i = 0; i < self.limit; i++) {				if (self.offset >= self.item.length) {					self.offset = 0;				}				themeHtml = themeHtml + self.liTemplate.replace('{t_theme_id}', self.item[self.offset].id).replace('{title}', self.item[self.offset].title).replace('{count}', self.item[self.offset].count);				self.offset++;			}			elm.html(themeHtml);		},		this.reflesh_time);	},	shuffle: function (list) {		var i = list.length;		while (--i) {			var j = Math.floor(Math.random() * (i + 1));			if (i == j) continue;			var k = list[i];			list[i] = list[j];			list[j] = k;		}		return list;	}}var searchMgr = new MeikanSearch();