self.focus(); 

// Echo-1 & MIC Functions

function KeywordSearchResultvalid(xform){
	MyObj = eval(xform);
	if (!checkString(MyObj.keyword1,"keyword2"))return false;
	else if (!CheckData1(MyObj.keyword1))	{
		MyObj.keyword1.focus();
		return false;
	}
	else return true; 
}

function KeywordSearchResult(xform){
	MyObj = eval(xform);
    if (MyObj.keyword1.value=="") {
       	MyObj.submit();
    }
    else { 
    	if (KeywordSearchResultvalid(xform))	{
        	MyObj.submit();
	    }else{
	    }
    }
} 

function KeywordSearchResult1(xform){
	MyObj = eval(xform);
    if (MyObj.keyword.value=="" && MyObj.pub_year.value=="") {
       	MyObj.submit();
    }
    else { 
    	if (KeywordSearchResultvalid(xform))	{
        	MyObj.submit();
	    }else{
	    }
    }
}     
    
function ChangePage(xform,page)	{
	MyObj = eval(xform);
  	MyObj.page.value = page;
  	MyObj.submit();
  }
  
function getall(xform){
    MyObj = eval(xform);
    if( MyObj.list_all.value == "1" ){
		MyObj.list_all.value = "0";
	}else{
		MyObj.list_all.value = "1";
	}
    MyObj.submit();
}

function field_submit(xform, queryfield) {
	MyObj = eval(xform);

    if (queryfield==MyObj.queryfield.value) {
        if (MyObj.desc.value=="desc"){  
            MyObj.desc.value="";}
        else {MyObj.desc.value="desc";}
    }
    else { MyObj.desc.value=""; }
    
    MyObj.queryfield.value = queryfield;
    MyObj.submit();
}



function SetPageSize(xform){
    MyObj = eval(xform);
    MyObj.PageSize.value = MyObj.OPPageSize.options[MyObj.OPPageSize.selectedIndex].value
    MyObj.submit();
}



function ReloadOpenerAndClose()
{
		window.opener.location.reload ();
		self.close();
}





// PI Functions

function mover(src,color)
{
//	alert(src.bgColor);
	if (!src.contains(event.fromElement))
	{ 
		src.style.cursor = 'hand'; 
		src.bgColor = color; 
	} 
	
} 
function mout(src,color)
{ 
	if (!src.contains(event.toElement))
	{ 
		src.style.cursor = 'default'; 
		src.bgColor = color; 
	} 
}
function tover(src,clr)
{ 
	if (!src.contains(event.fromElement))
	{ 
		src.style.cursor = 'hand'; 
	//	src.style.fontSize = "15pt";
		src.style.color = clr;
	} 
} 
function tout(src,clr)
{ 
	if (!src.contains(event.toElement))
	{ 
		src.style.cursor = 'default'; 
		src.style.color = clr;
	//	src.style.fontSize = "15pt";
	} 
}
function trimSpace(a)
{
	var b = a.replace(/^ */i,""); //remove heading spaces
	var c = b.replace(/ *$/i,""); //remove tailing spaces
	return c;
}


function popup_small(url) {	
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()	
	window.open(url,winname,"toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=400,height=250");
}

function popup(url) {	
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()	
	window.open(url,winname,"toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=600,height=330");
}

function popup_big(url) {
	currDate = new Date();	//use "hhmmss" as window name 
	winname=currDate.getHours().toString()+currDate.getMinutes().toString()+currDate.getSeconds().toString()	
	window.open(url,winname,"toolbar=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=750,height=700");
}


function DoPopUp(formname,fld,href)
{
	var f = eval("document."+formname);
	var n = fld=="" ? null : eval("document."+formname+"."+fld);
	
	var id;
	if(n!=null) 
	{
		id = n.value;
		href=href + "?" + fld + "=" + id;
		if(id =="" && n != null )
		{
		  alert("請至少選取一筆資料!!");
		  return;
		}
	}
	popup_big(href)
}


function DoSubmit(formname,fld,href)
{
	var f = eval("document."+formname);
	var n = fld=="" ? null : eval("document."+formname+"."+fld);
	
	var id;
	if(n!=null) 
	{
		id = n.value;
		href=href + "?" + fld + "=" + id;
		if(id =="" && n != null )
		{
		  alert("請至少選取一筆資料!!");
		  return;
		}
	}
	alert(href)
	f.action = href;
	f.submit();
}



function DoSubmitWithConfirm(formname,fld,href,prompt)
{
	var f = eval("document."+formname);
	var n = fld=="" ? null : eval("document."+formname+"."+fld);
	var id = GetCheck(f);
	if(id =="" && n != null )
	{
		alert("請至少選取一筆資料!!");
		return;
	}
	if(n!=null) n.value = id;
	f.action = href;
	if (confirm(prompt))
		f.submit();
}


function GetCheck(f)
{
	var TotalOn = 0;
	var id ="";
	for (var i=0;i<f.elements.length;i++)
	{
        var e = f.elements[i];
        if(e.type=='checkbox')
        {
			if (e.checked)
			{
				id = e.value;
				TotalOn++;
			}
        }
	}
	if(TotalOn != 1) return "";
	return id ;
}

function CheckCheck(btn)
{
	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<btn.form.elements.length;i++)
	{
        var e = btn.form.elements[i];
        if ((e.name != btn.name ) && (e.type=='checkbox'))
        {
			e.checked =false;

        }
	}
}

function CheckCheckAll(xform,allbox,txtbox)
{
	var OnOff ;
	OnOff = eval("xform."+allbox+".checked");

	for (var i=0;i<xform.elements.length;i++)
	{
          var e = xform.elements[i];
          if ((e.name != allbox) && (e.type=='checkbox'))
          {
		e.checked = OnOff;
          }
	}
	SetCheck(xform,allbox,txtbox)
}

function SetCheck(xform,allbox,txtbox)
{
	var txtvalue="" ;
	var txt_box ;
	
	for (var i=0;i<xform.elements.length;i++)
	{
          var e = xform.elements[i];
          if ((e.name != allbox) && (e.type=='checkbox') && e.checked )
          {
          	if (txtvalue != "")
          	  txtvalue = txtvalue + ";";
		txtvalue = txtvalue + e.value;
          }
	}
	txt_box=eval("xform."+txtbox);
	txt_box.value=txtvalue;
}

function getUC(str)
{
	var rtn="";
	var code=0;
	var i;
	for (i=0; i<str.length; i++)
	{
		code=str.charCodeAt(i);
		if (code>255)
			rtn+="&#"+code+";";
		else
			rtn+=str.charAt(i);
	}
	return rtn;
}

function parseUC(fld)
{
	fld.value=getUC(fld.value);
//	return true;
}

function parseUCAll(formobj)
{
	for (var i=0;i<formobj.elements.length;i++)
	{
        var e = formobj.elements[i];
       	if( (e.type=='hidden') || (e.type=='text') || (e.type=='textarea'))
       	{
      		//alert(e.value);
       		e.value = getUC(e.value);
       		//alert(e.value);
       	}
	}
}

/****************** the following methods used by asoc page**********************/
function addToSelectList(formname,selname,avlname)
{
	var f = eval('document.'+formname);
	var s = eval('document.'+formname+'.'+selname);
	var a = eval('document.'+formname+'.'+avlname);
	s.options[0].selected =false;
	a.options[0].selected =false;
	for (var i=1; i<a.options.length; i++)
	{
		if (a.options[i].selected)
		{
			var opt= new Option(a.options[i].text, a.options[i].value);
			s.options[s.options.length]=opt;
			a.options[i]=null;
			i--;
		}	
	}
	//if("a"  "b")
	//	alert("a <b");
	
	sortList(s);
}

function removeFromSelectList(formname,selname,avlname)
{
	var f = eval('document.'+formname);
	var s = eval('document.'+formname+'.'+selname);
	var a = eval('document.'+formname+'.'+avlname);
	s.options[0].selected =false;
	a.options[0].selected =false;
	for (var i=1; i<s.options.length; i++)
	{
		if (s.options[i].selected)
		{
			var opt= new Option(s.options[i].text, s.options[i].value);
			a.options[a.options.length]=opt;
			s.options[i]=null;
			i--;
		}	
	}
//	sortList(a);
	pm_array_qsort(a.options,1,a.options.length-1,_pm_array_selectioncmp)
}

/**************** bubble sort ***********************/
function sortList(s)
{
	for (var i=1; i<s.options.length-1; i++)
	{
		for(var j=i+1;j<s.options.length;j++)
		{
			if(s.options[i].text.toLowerCase() >s.options[j].text.toLowerCase())
			{
				var o1 = s.options[i];
				var o2 = s.options[j];
				var t = o1.text ;
				o1.text =o2.text;
				o2.text = t;
				
				t = o1.value ;
				o1.value =o2.value;
				o2.value = t;		
				
				t = o1.selected ;
				o1.selected =o2.selected;
				o2.selected = t;						
			}
		}
	}
}

/**************** qsort ***********************/
function _pm_array_qsort(vec,lo,up,cmp_fun)
{
//	alert(vec[1].text);
	var i, j;
	t = new Object ;
	while(up > lo)
	{
		i = lo;
		j = up;
		//t = vec[lo];
		assign(t,vec[lo]);
		while(i < j)
		{
			while(cmp_fun(vec[j],t) > 0)
				j -= 1;
			//vec[i] = vec[j];
			assign(vec[i],vec[j]);
			while((i < j) && (cmp_fun(vec[i],t) <= 0))
				i++;
			//vec[j] = vec[i];
			assign(vec[j],vec[i]);
		}
		//vec[i] = t;
		assign(vec[i],t);
		if(i - lo < up - i)
		{
			_pm_array_qsort(vec,lo,i-1,cmp_fun); lo = i+1;
		} 
		else 
		{
			_pm_array_qsort(vec,i+1,up,cmp_fun); up = i-1;
		}
	}
}
function _pm_array_defcmp(a,b)
{
	return (a == b) ? 0 : (a > b) ? 1 : -1;
}
function _pm_array_selectioncmp(a,b)
{
//	alert(a.text);
	var t1 = a.text.toLowerCase() 
	var t2 =  b.text.toLowerCase()
	return (t1 == t2 ) ? 0 : (t1 > t2) ? 1: -1;
}
function assign(o1,o2)
{
//	var t = o1.text ;
	o1.text =o2.text;
//	o2.text = t;
	
//	t = o1.value ;
	o1.value =o2.value;
//	o2.value = t;		
	
//	t = o1.selected ;
	o1.selected =o2.selected;
//	o2.selected = t;		
}

function pm_array_qsort(vec,lo,hi,cmp_fun)
{
	if(vec == null)
	{
		return;
	} 
	else if(cmp_fun == null)
	{
		_pm_array_qsort(vec,lo,hi,_pm_array_defcmp);
	}
	else
	{
		_pm_array_qsort(vec,lo,hi,cmp_fun);
	}
}

function hiliteList(formname,listname)
{
	var s = eval('document.'+formname+'.'+listname);
	s.options[0].selected=false;//label
	for (i=1; i<s.options.length; i++)
		s.options[i].selected=true;
}


/************ the following methods used by tree page********************/
function getCurIndex(label) 
{
	return getCurCookie(label);
}
function setCurIndex(label,n) 
{
	var expire = new Date();
	expire.setTime(expire.getTime() + ( 7*24*60*60*1000 ) ); // expire in 1 week
	document.cookie = label+"="+n ;//+ "; expires=" + expire.toGMTString(); 
}
function getCurState(label) 
{
	return getCurCookie(label);
}
function getCurId(label) 
{
	return getCurCookie(label);
}
function getCurCookie(label)
{	
	//getCurIndex() 
	label = label+"="
	var labelLen = label.length
	var cLen = document.cookie.length
//alert(document.cookie)
	var i = 0
	while (i < cLen) 
	{
		//alert(document.cookie)
		var j = i + labelLen
		if (document.cookie.substring(i,j) == label) 
		{
			var cEnd = document.cookie.indexOf(";",j)
			if (cEnd == -1) 
			{ 
				cEnd = document.cookie.length 
			}
			var s = unescape(document.cookie.substring(j,cEnd))
		//	alert(s)
			return s
		}
		i++
	}
	return ""
}
// Record current settings in cookie
function setCurState(label,setting) 
{
	var expire = new Date();
	expire.setTime(expire.getTime() + ( 7*24*60*60*1000 ) ); // expire in 1 week
	document.cookie = label+"=" + escape(setting) +"; expires=" + expire.toGMTString();
}
function setCurId(label,id) 
{
	var expire = new Date();
//	expire.setTime(expire.getTime() + ( 7*24*60*60*1000 ) ); // expire in 1 week
	document.cookie = label+"=" + escape(id) ;//+ "; expires=" + expire.toGMTString();
}
// Add an entry to the database
function dbAdd(mother,id,display,URL,indent,top,newitem)
{
	db[total] = new Object;
	db[total].mother = mother
	db[total].id = id
	db[total].display = display
	db[total].URL = URL
	db[total].indent = indent
	db[total].top = top
	db[total].newitem = newitem
	db[total].selected = false
	db[total].leaf = true
	if(total >1)	
	db[total-1].leaf = db[total-1].indent >= indent ? true : false

	total++
}



// toggles an outline mother entry, storing new value in the cookie
function toggle(n) 
{
	if (n != 0) 
	{
		var newString = ""
		var expanded = current.substring(n-1,n) // of clicked item
		newString += current.substring(0,n-1)
		newString += expanded ^ 1 // Bitwise XOR clicked item
		newString += current.substring(n,current.length)
		setCurState(CURSTATE,newString) // write new state back to cookie
//		setCurIndex(n) // write new state back to cookie
	}
}

// returns padded spaces (in mulTIPles of 2) for indenting
function pad(n)
{
	var result = ""
	for (var i = 1; i <= n; i++)
		result += "&nbsp;&nbsp;&nbsp;&nbsp;" 
	return result
}

// Expand everything
function explode()
{
	current = "";
	initState="";
	for (var i = 1; i < db.length; i++)
	{ 
		initState += "1"
		current += "1"
	}
	setCurState(CURSTATE,initState);
	history.go(0);
}

// Collapse everything
function contract() 
{
	current = "";
	initState="";
	for (var i = 1; i < db.length; i++) 
	{ 
		initState += "0"
		current += "0"
	}
	setCurState(CURSTATE,initState);
	history.go(0);
}

function tree_close() 
{
	window.parent.location = window.parent.content.location;
}
//function setHiliteIndex(top,url,display,idx)
function setSeletion(id,idx)
{
/*	alert(top)
	alert(url)
	alert(display)
	alert(idx)
	alert(id);
*/	setCurIndex(CURINDEX,idx);
	setCurId(CURID,id);
	var p = eval("parent.parent");
	p.location = "plsa_categoryexpr.asp";
}
/******************************************************************************

FUNCTION:		checkDate
ARGUMENTS:
DESCRIPTION:
SYNTAX:	
AUTHOR:	
DATE:
	
******************************************************************************/
var CutOff1900s = 1912  // Setting used by CheckDate
function checkDate (This) {
	
	if (This.value.length==0) return false;

// If the field contains only blanks, empty it and return false.  Else, we know the position of 
// the first nonblank character.
	var FirstNonblank = -1
	var i = 0
	for (i = 0; i <= This.value.length - 1; i++) {
		if (This.value.charAt(i) != " ") {
			FirstNonblank = i;
			break
			}
		}
	if (FirstNonblank == -1) {
		This.value = "";
		return false;
		}

// Find the start positions of up to three numerical values
	var SearchFor = "Number"
	StartPos = new Array(-1,-1,-1)
	var StringNum = 0
	for (i = FirstNonblank; i <= This.value.length - 1; i++) {
		if (StringNum >= 3) break;
		if (SearchFor == "Number") {
			if (!isNaN(parseInt(This.value.charAt(i),10))) {
				StartPos[StringNum] = i;
				StringNum = StringNum + 1;
				SearchFor = "Nonnumber"
				}
			}
		else {
			if (isNaN(parseInt(This.value.charAt(i),10))) SearchFor = "Number"
				
		}
	}

// Extract the first number and see if it is 6 or 8 digits.  If so, set (or reset) the second and
// third start positions to appropriate locations within the first-number string.

	if (StartPos[0] != -1) {
		var FirstNumLength = parseInt(This.value.substring(StartPos[0], This.value.length),10).toString().length
		if (This.value.charAt(StartPos[0]) == "0") FirstNumLength++;
		if (FirstNumLength == 6 || FirstNumLength == 8) {
			StartPos[1] = StartPos[0] + 2;
			StartPos[2] = StartPos[1] + 2
		}
	}

// Verify that we have three numbers
	if (StartPos[2] == -1) {
		//alert ('Please enter the date as three separate numbers, or as 6 or 8 contiguous digits.\n  For example, to enter January 3, 1999, you could type "1-3-99", "01/03/99", "1  3  1999", "010399", or "01031999".');
		alert ('Please enter the date as three separate numbers,\n  For example, to enter January 3, 2001, you could type "01/03/2001"');
		
		This.focus();
		return false
		}

// Extract the three numbers and check them for obvious errors.
	var Month = parseInt(This.value.substring(StartPos[0], StartPos[1]),  10)
	var Day =   parseInt(This.value.substring(StartPos[1], StartPos[2]),  10)
	var Year=	parseInt(This.value.substring(StartPos[2], This.value.length), 10)
	
	if ( Month > 12 || Month < 1 ) {
	 	alert ("The month you entered was " + Month + ", but the acceptable range is 1 to 12, where 1 is January and 12 is December.\n  For example, January 4, 1998, could be entered as 1-4-98.");
		This.focus();
	 	return false
		}
	if ( Day > 31 || Day < 1 ) {
	 	alert ("The day you entered was " + Day + ", but the acceptable range is 1 to 31.");
		This.focus();
	 	return false
	   }

// Convert one- or two-digit years into four digit years
	var CutOff = 1910
	if ( Year < 100 ) {
		Year = Year + 1900;
		if ( typeof( CutOff1900s ) == "number" ) CutOff = CutOff1900s;
		if ( Year < CutOff ) Year = Year + 100;
	 	}
	else { 
		if (Year < 1900 || Year > 2100) {
			if (Year < 1000 || Year > 9999){
				alert("The year entered is incorrect, please revise.");
				This.focus();
				return false;
			}
			alert ("Caution:  The year may be incorrect.  Please check it for accuracy.")
		 }
	}

// One final date verification:  If the day changes when JavaScript builds a
// date string, then the day must be invalid for the month specified.  (For this
// crazy date constructer, the month range is 0 to 11.)
	var MyDate = new Date ( Year, Month - 1, Day)
	if ( MyDate.getDate() != Day ) {
	   alert ("The day you entered was " + Day + ", but the month you specified does not contain " + Day + " days.  Please specify a valid date.");
		This.focus();
	 	return false
	}
	
// Construct an output string
/*	var MyString = MyDate.toLocaleString().substring(0,6) + Year
	var Delimiter = "/"
	if ( typeof(DateDelimiter) == "string" ) Delimiter = DateDelimiter;
	if ( Delimiter == "/" ) {
		This.value = MyString
		}
	else {
		This.value = MyString.substring(0,2) + Delimiter + MyString.substring(3,5) + Delimiter + MyString.substring(6,10)
		}
*/	return true
}
// ********************* CheckDate ends here ********************************** 



/******************************************************************************

		checkNum

******************************************************************************/

function checkNum (This) 
{

	var num=This.value;
	var checkNumber=parseInt(num,10);

	if (checkNumber !=0 && isNaN(checkNumber)== false)
	{
		
	return true
	
	}

	else
	{
	alert ("The number you entered was not valid.");
	 return false
	}


}
function stampURL(url)
{
	var d = new Date()
	var ms = d.getTime() 
	var lastchar = new String(url.charAt(url.length-1))
	if(lastchar =="?" || lastchar =="&") 
		return url+"ts="+ms
	else if(url.indexOf('?') > 0 )
		return url+"&ts="+ms
	else	
		return url+"?ts="+ms
}
function findReservedChar(str,rev)
{
//	alert("fdsa");
	if(typeof(rev)=='undefined' || rev.length == 0)
		rev = "<>";
	for(var i=0;i<rev.length;i++)
	{
		var thechar = new String(rev.charAt(i));
		if(str.indexOf(thechar) > -1)
			return true
	}	
	return false
}



function clearDate(obj)
{
	obj.value= '';
}