var NGDN_1113 = {};
NGDN_1113.fun = (function(){
	var BG_value = '', oBG = null,
		oFbPop_form = $('fbPop_form'),
		oFbPop_ok = $('fbPop_ok'),
		oMessages = $('mess'),
		oCheckBox_email = $('appear_email'),
		oMail = $('footemail'),
		oHidden_mail = $('hidden_email'),
		oDicType = $('dicType'),
		oSubmit = $('feedsub'),
		oCancel = $('cancel'),
		OK = $('ok');

	// 建立半透明灰色背景
	var createBG_fadeOut = function(evt){
		evt = evt || window.event;

		oBG = document.createElement('div');
		if(oBG){
			oBG.style.left = '0px';
			oBG.style.top = '0px';
			$Dom(oBG).setStyle('width',$Dom().getDocumentWidth()+'px');
			$Dom(oBG).setStyle('height',$Dom().getDocumentHeight()+'px');
			oBG.style.zIndex = '1000';
			oBG.style.backgroundColor = '#000';
			oBG.style.position = 'absolute';
			!(window.attachEvent && !window.opera) ? oBG.style.opacity = BG_value : oBG.style.filter = 'alpha(opacity='+BG_value*100+')';
			document.body.appendChild(oBG);

			// 留言信息的位置
			oFbPop_form.style.left = setFeedback_position(oFbPop_form).left + 'px';
			oFbPop_form.style.top = setFeedback_position(oFbPop_form).top + 'px';
			oFbPop_form.style.zIndex = '1001';

			// 设置初始状态
			oMessages.value = '';
			oMessages.focus();
			oCheckBox_email.checked = true;
			$Dom(oMail).setStyle('display','block');
			$Dom(oMail).setStyle('color','#999999');

			if(oHidden_mail.value != ''){
				oMail.value = oHidden_mail.value;
			}

			if(oHidden_mail.value == ''){
				oMail.value = SPS.text('SEND_FEEDBACK_EMAIL');
			}
		}
		evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;
	};

	// 关闭背景与留言信息
	var closeBG = function(evt,elem){
		var evt = evt || window.event;
		if(oBG && elem){
			elem.style.left = '-99999px';
			elem.style.top = '-99999px';
			document.body.removeChild(oBG);
		}
		evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;
	};

	// 提交后显示提示信息的位置(AJAX)
	/**
	 *	参数说明：
	 *		url: AJAX请求地址
	 *		AJAX请求参数：
	 *			oAjax.request({
	 *				'mess': oMessages.value, // textarea中输入的信息
	 *				'email': oMail.value	//	用户输入的email内容
	 *			});
	 *		服务端返回值：
	 *			正确：true；错误：false
	 */
	var setSubmit_position = function(evt){
		var evt = evt || window.event;

		// message不能为空
		if (oMessages==null || oMessages.value =='') {
			oMessages.focus();
			alert('請填寫留言, 謝謝!');
			return false;
		}

		// mail不能为空
		if(oCheckBox_email.checked){
			if(oMail == null || oMail.value == '' || oMail.value == SPS.text('SEND_FEEDBACK_EMAIL')){
				alert('請填寫郵箱，謝謝！')
				return false;
			}
		}

		var oAjax = $Ajax('/search/submitFeedback',{
			onload: function(res){
				var info = !!(res.text());
				if(info){
					oFbPop_form.style.left = '-99999px';
					oFbPop_form.style.top = '-99999px';

					oFbPop_ok.style.left = setFeedback_position(oFbPop_ok).left + 'px';
					oFbPop_ok.style.top = setFeedback_position(oFbPop_ok).top + 'px';
					oFbPop_ok.style.zIndex = '1001';
				}else{
					alert('提交失败，请重试！');
				}
			}
		});

		if(oCheckBox_email.checked){
			oAjax.request({'message': oMessages.value,'email': oMail.value,'dicType': oDicType.value,'typeOfFeedBack': 'Main_Page'});
		}else{
			oAjax.request({ 'message': oMessages.value,'dicType': oDicType.value,'typeOfFeedBack': 'Main_Page' });
		}

		evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;
	};

	// 获取页面相关信息的坐标
	var setFeedback_position = function(elem){
		var x = document.documentElement.clientWidth || document.body.clientWidth,
			y = document.documentElement.clientHeight || document.body.clientHeight,
			scroll_y = document.documentElement.scrollTop || document.body.scrollTop;

		return{
			left: elem ? (x/2 - elem.offsetWidth/2) : -99999,
			top: elem ? (y/2 - elem.offsetHeight/2 + scroll_y) : -99999
		}
	};

	// 对于具体内容的设置
	var setEmail = function(){
		this.checked ? oMail.style.display = 'block' : oMail.style.display = 'none';
	};
	var changeEmail = function(){
		if(this.value==SPS.text('SEND_FEEDBACK_EMAIL')){
			this.value = '';
			this.style.color = '';
		}
	}
	return{
		init: function(id,vBG){
			var oFeedBack = document.getElementById(id);
			if(oMail.value==""){
				oMail.value = SPS.text('SEND_FEEDBACK_EMAIL');
			}
			BG_value = vBG;
			oFeedBack.onclick = createBG_fadeOut;
			oCheckBox_email.onclick = setEmail;
			oMail.onclick = changeEmail;
			oSubmit.onclick = setSubmit_position;

			OK.onclick = function(evt){
				closeBG(evt,oFbPop_ok);
			}

			oCancel.onclick = function(evt){
				closeBG(evt,oFbPop_form);
			}
		}
	}
})();
NGDN_1113.fun.init('last','0.5');

var NHN = {};
NHN.search = (function(){
	var $ = function(elem){
			if(typeof elem == 'obj'){
				return elem;
			}else if(typeof elem == 'string'){
				return document.getElementById(elem);
			}
	};

	var hasClass = function(elem,classN){
			var regClass = new RegExp('^'+classN+'$');
			return	regClass.test(elem.className) ? true : false;
	};

	var doKeySearch = function(event){
		var evt = event || window.event,
				oInputBox = $('de_searchboxQuery'),
				oSearchButton = $('cm_searchLink'),
				sValue = oInputBox.value,
				oSearchButton_href = oSearchButton.getAttribute('href');

		if(hasClass(oInputBox,'regard_null')){
			sValue = '';
		}
		if(!hasClass(oInputBox,'skip_nullcheck') && sValue.length == 0){
			alert(SPS.text('FILL_SEARCHQUERY'));
			oInputBox.focus();
			return;
		}

		if(oSearchButton_href.match('detailpageEn.nhn')){
			document.location.href = oSearchButton_href+"/" + encodeURIComponent(sValue);
		}else{
			var sRange = "";
			var elRadios = document.getElementsByName("search_range");
			for(var i = 0; i < elRadios.length; i++){
				var elRadio = elRadios[i];
				if(elRadio.checked){
					sRange = elRadio.value == "" ? "" : "/" + elRadio.value;
					break;
				}
			}
			document.location.href = oSearchButton_href + sRange + "/" + encodeURIComponent(sValue);
		}
		evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;	// 取消默认表单的提交动作。当js不起作用时，执行表单提交也可以正常搜索单词
	};

	var doBottomSearch = function(event){
		var evt = event || window.event,
				oInputBox = $('querybottom'),
				oSearchButton = $('cm_searchLinkBottom'),
				sValue = oInputBox.value,
				oSearchButton_href = oSearchButton.getAttribute('href');

		if(hasClass(oInputBox,'regard_null')){
			sValue = '';
		}
		if(!hasClass(oInputBox,'skip_nullcheck') && sValue.length == 0){
			alert(SPS.text('FILL_SEARCHQUERY'));
			oInputBox.focus();
			return;
		}
		if(oSearchButton_href.match('detailpageEn.nhn')){
			document.location.href = oSearchButton_href+"/" + encodeURIComponent(sValue);
		}else{
			document.location.href = oSearchButton_href  + "/" + encodeURIComponent(sValue);
		}
		evt.preventDefault ? evt.preventDefault() : evt.returnValue = false;	// 取消默认表单的提交动作。当js不起作用时，执行表单提交也可以正常搜索单词
	};


	return{
		requestKeySearch: function(event){
			doKeySearch(event);
		},
		requestBottomSearch: function(event){
			doBottomSearch(event);
		}
	}
})();