

 	function transToDate(y, m, d, se){
		var ys, ms, ds, dt;
		if(y!=""){
			ys = (eval(y) +1911).toString(10);
		}else{
			if(se==0){
				ys = "1911";
			}else{
				ys = "9999";
			}
		}
		if(m!=""){
			ms = new String(m);
			if(ms.length==1){
				ms = "0" + ms;
			}
		}else{
			if(se==0){
				ms = "01";
			}else{
				ms = "12";
			}
		}
		if(d!=""){
			ds = new String(d);
			if(ds.length==1){
				ds = "0"+ds;
			}
		}else{
			if(se==0){
				ds = "01";
			}else{
				ds = "31";
			}
		}
		dt = ys + "-" + ms +"-" + ds;
		return dt;
	}




 	function transToWestDate(y, m, d, se){
	var ys, ms, ds, dt;
		if(y!=""){
			ys = (eval(y) +1911).toString(10);
		}else{
			if(se==0){
				ys = "0000";
			}else{
				ys = "9999";
			}
		}
		if(m!=""){
			ms = new String(m);
			if(ms.length==1){
				ms = "0" + ms;
			}
		}else{
			if(se==0){
				ms = "00";
			}else{
				ms = "12";
			}
		}
		if(d!=""){
			ds = new String(d);
			if(ds.length==1){
				ds = "0"+ds;
			}
		}else{
			if(se==0){
				ds = "00";
			}else{
				ds = "31";
			}
		}
		dt = ys + ms + ds;
		return dt;
	}


	function transKeyword(kw){
	var kwd;
	var i;
		kwd = trim(kw);
		if(kw!=""){
			for(i=0;i<kwd.length;i++){
				kwd=kwd.replace("+","\" or \"");
				kwd=kwd.replace("&","\" and \"");				
				kwd=kwd.replace("-","\" and not \"");
			}
			kwd = '"' + kwd + '"';
		}
		return kwd;
	}


	function goto_page(p){
	var nurl = document.URL;
	var ptrn = /[pP][Aa][Gg][Ee]=[0-9]*/;
		//alert(p);
		//alert(document.URL);
		if(nurl.search(/page=/i)>0){
			//alert("find");
			nurl = nurl.replace(/[pP][Aa][Gg][Ee]=[0-9]*/, "page="+p);
		} else {
			nurl = nurl + "&page=" + p;
		}
		//alert(nurl);
		location.href = nurl;
	}	


	function hasSpecialCode(s) {
	var c;
		for(i=0;i<s.length;i++){
			c = s.charCodeAt(i);
			if (!(
			  ((c>=48)&&(c<=57))||
			  ((c>=65)&&(c<=90))||
			  ((c>=97)&&(c<=122))||
			  (c==32)||(c==33)||
			  (c==38)||(c==40)||
			  (c==41)||(c==43)||
			  (c==45)||(c==124)||(c>255)
			  )) {
				return s.charAt(i);
			}
		}
		return "";
	}
	

	function goto_page(p){
	var nurl = document.URL;
	var ptrn = /[pP][Aa][Gg][Ee]=[0-9]*/;
		//alert(p);
		//alert(document.URL);
		if(nurl.search(/page=/i)>0){
			//alert("find");
			nurl = nurl.replace(/[pP][Aa][Gg][Ee]=[0-9]*/, "page="+p);
		} else {
			nurl = nurl + "&page=" + p;
		}
		//alert(nurl);
		location.href = nurl;
	}	


	function hasNormalChar(s) {
	var c;
	var b;
		for(i=0;i<s.length;i++){
			c = s.charCodeAt(i);
			if (((c>=48)&&(c<=57)) ||
			   ((c>=65)&&(c<=90)) ||
			   ((c>=97)&&(c<=121)) ||
			   (c>127)
			   ) {
			   b = true;
			} 
		}
		return b;
	}


	function trim(strText) { 
   // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
	 return strText;
	} 


	function chkStr(s) {
		if (trim(s)!=""){
			if (hasSpecialCode(s) != "") {
				alert("檢索字詞不能含有特殊字元：" + hasSpecialCode(s) + "\n請重設查詢條件...");
				return false;
			} else if (!hasNormalChar(s)) {
				alert("沒有輸入合法的檢索字詞，請重設查詢條件...");
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}


function popup(t) {
	if (t.style.display=="none") {
		t.style.display="block";
		return true;
	} else {
		t.style.display="none";
		return false;
	}
}
