// JavaScript Document

function selectit(keyword) {
  if (keyword.value == "關鍵字") {
    keyword.value = "";
  }
}

function disselectit(keyword) {
  if (keyword.value == "") {
    keyword.value = "關鍵字";
  }
}

function searchit() {
  keyword = document.getElementById('searchkeyword');
 // searchtype = document.getElementById(\'searchtype\');

  if (keyword.value == "" || keyword.value == "關鍵字") {
    alert("請輸入關鍵字");
    return false;
  }
 // alert(document.getElementById(\'searchtype\').options[document.getElementById(\'searchtype\').options.selectedIndex].value);
  window.location.href='tips_search.php?searchtype=' + document.getElementById('searchtype').options[document.getElementById('searchtype').options.selectedIndex].value + '&searchkeyword=' + (keyword.value);
  return true;
}

function check(event) {
  if(event.keyCode==13){
    searchit();
  }
}

function trimStr(str) {
 var re = /\s*(\S[^\0]*\S)\s*/;
 re.exec(str);
 return RegExp.$1;
}

function check2(){
		if(document.getElementById('txtMsg').value == ''){
			alert('請輸入內容！');
			document.getElementById('txtMsg').focus();
			return false;
		}
		if(document.getElementById('txtMsg').value.lenght>1024)
		{
			alert('輸入內容太長！');
			document.getElementById('txtMsg').focus();
			return false;
		}
		return true;
	}
	function checklogin()
	{
		if(document.getElementById('user_id').value == ''){
			alert('請先登入！');
			var encodeurl= document.getElementById('encodeurl').value;
			window.location.href="registration_login.php?url="+ encodeurl;
			return false;
		}
		return true;
	}
	
	function checksubmit()
	{
		if(check2())
		{
			if(checklogin())
			{
				document.frmTipsReply.submit();
			}
			
		}
	}
//	
//post page	

function doSubmit() {
		 
        var action = document.getElementById('action');
       // action.value = actionVal;

       var topic = document.getElementById('topic');

		
			if (topic.value == "") {
			  alert("知識標題必須要輸入!");
			  topic.focus();
			  return false;
			}
			var content = document.getElementById('content_s');
			if (content.value == "") {
			  alert("知識內容必須要輸入!");
			  content.focus();
			  return false;
			}
			if(topic.value.length > 60 || content.value.length>900 )
			{
			   alert("閣下的知識標題或內容字數，超出系統預設上限；請根據字數限制進行刪減。");
			   return false;
			}
		

       var selCategory = document.getElementById('selCategory');
       var selSubCategory = document.getElementById('selSubCategory');
       var nocat = document.getElementById('nocat');

        if (isNaN(selCategory.value))
          selCategory.value = 0;

        if (isNaN(selSubCategory.value))
          selSubCategory.value = 0;


        if(document.getElementById('actionvalu').value != 'preview')
		{
        if (selCategory.value == 0 && selSubCategory.value == 0 && nocat.checked == false) {
          alert("知識分類必須選擇!");
          return false;
        }
		}

		if($('#content_s').val()==''&&$('#nocat').val()=='')
		{
		  alert("知識分類必須選擇!");
          return false;
		}

		if(document.getElementById('tag') && document.getElementById('tag').value == '可輸入一個、甚至多個標籤 Tags') {
			document.getElementById('tag').value = '';
		}
       // document.formPost.submit();
	   return true;
      }
	  
  function doSubmit_post() {
		var action = document.getElementById('action');
		var topic = document.getElementById('topic');
			if (topic.value == "") {
			  alert("知識標題必須要輸入!");
			  topic.focus();
			  return false;
			}
			var content = document.getElementById('content_s');
			if (content.value == "") {
			  alert("知識內容必須要輸入!");
			  content.focus();
			  return false;
			}
			if(topic.value.length > 60 || content.value.length>900 )
			{
			   alert("閣下的知識標題或內容字數，超出系統預設上限；請根據字數限制進行刪減。");
			   return false;
			}
		
	   
	   var selCategory = document.getElementById('selCategory');
	   var selSubCategory = document.getElementById('selSubCategory');
	   var nocat = document.getElementById('nocat');

		if (isNaN(selCategory.value))
		  selCategory.value = 0;

		if (isNaN(selSubCategory.value))
		  selSubCategory.value = 0;


		if(document.getElementById('actionvalu').value != 'preview')
		{
		if (selCategory.value == 0 && selSubCategory.value == 0 && nocat.checked == false) {
		  alert("知識分類必須選擇!");
		  return false;
		}
		}


		if(document.getElementById('tag') && document.getElementById('tag').value == '可輸入一個、甚至多個標籤 Tags') {
			document.getElementById('tag').value = '';
		}
	  document.getElementById('formPost').submit();
	  //$('#sub').val('1');
	  //return true;
  }
	  
	  jQuery(document).ready(function() { 
 
        /*$('.pop_up').click(function() { 
            $.blockUI({ message: $('#postform'), css: { } }); 
        }); */
		jQuery('.pop_up').click(function() { 
			tipsWindown("e-zone.com.hk","iframe:/registration_login.php","710","460","false","","true","text");
		});

		jQuery("#forget").click(function(){
			tipsWindown("e-zone.com.hk","iframe:/registration_password.php","710","410","false","","true","text");
		});

//		jQuery(".register").click(function(){
//			tipsWindown("e-zone.com.hk","iframe:registration_landing.php","710","400","false","","true","text");
//		});
    }); 


	function logout(){
		jQuery.post('/logout.php', function(msg){
			if (msg)
			{
				jQuery('#login1').html('<p><b><a href="javascript:void(0);" onclick="showloginForm();" title="">登入</a></b> | <a href="javascript:void(0);" onclick="showregisterForm();" title="">新會員登記</a></p>');
				var docUrl = window.location.href;
				var pattern = /(tips.php|jetso.php|events_detail.php|news.php\?documentid)/;
				if (docUrl.match(pattern)){
					window.location.reload();
				}
				var pattern = /(renew.php)/;
				if (docUrl.match(pattern)){
					window.location = '/index.php';
				}
			}
		});
	}

	function showloginForm(){
		tipsWindown("e-zone.com.hk","iframe:/registration_login.php","710","460","false","","true","text");
	}

	function showregisterForm(){
		tipsWindown("e-zone.com.hk","iframe:/registration_landing.php","710","400","false","","true","text");
	}

	function showforgetForm(){
		tipsWindown("e-zone.com.hk","iframe:/registration_landing.php","710","400","false","","true","text");
	}
