function pdflink_2009( auname)
{
  bName = navigator.appName;
  bVer = parseInt(navigator.appVersion);
  
	var newwin = window.open("/twdaoapp/servlet/ShowService?path=pdf&title="+auname,
	               + "chk_window",
	    "toolbar=no,menubar=no,resizable=1,scrollbars=yes,status=yes,width=600,height=350");
        if (newwin != null && newwin.opener == null)
        {
           newwin.opener = self;
        }
}



function pdflink( auname, ordernum )
{
  bName = navigator.appName;
  bVer = parseInt(navigator.appVersion);
  
//  var ttt='/twdaoapp/servlet/statusProgress?nocache='+new Date();
//  window.open(ttt,'UploadStatus','scrollbars=no,status=no,width=360,height=90');

/*
  if (bName == "Microsoft Internet Explorer") {
	var newwin = window.open("/twdaoapp/servlet/waitingfor?path=pdf&title="+auname,
	+ "chk_window",
	"toolbar=no,menubar=no,resizable=1,scrollbars=yes,status=yes,width=600,height=350");
      if (newwin != null && newwin.opener == null)
         {
           newwin.opener = self;
          }
   }
   else{
*/
		var newwin = window.open("/twdaoapp/servlet/ShowService?path=pdf&title="+auname+"&ordernum="+ordernum,
	               + "chk_window",
	    "toolbar=no,menubar=no,resizable=1,scrollbars=yes,status=yes,width=600,height=350");
        if (newwin != null && newwin.opener == null)
        {
           newwin.opener = self;
        }
//   }
}

function popUp(nameOfpage)
{
    var newwin = window.open("/twdaoapp/"+nameOfpage + ".html",
	nameOfpage + "_window",
	"toolbar=no,menubar=no,resizable=1,scrollbars=yes,status=no,width=450,height=400");
    if (newwin != null && newwin.opener == null)
    {
        newwin.opener = self;
    }
}

function libweblink(auname)
{
    var newwin = window.open("/twdaoapp/chkopac.jsp?au="+auname,
	+ "chk_window",
	"toolbar=no,menubar=no,scrollbars=yes,status=no,width=600,height=350");
    if (newwin != null && newwin.opener == null)
    {
        newwin.opener = self;
    }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
    x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;
  if (d.images) {
    if (!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for (i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0) {
        d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
      }
    }
}

function popUpExamples()
{
    var newwin = window.open(
	"help.html#quick",
	"help_window",
	"toolbar=no,menubar=no,scrollbars=yes,status=no,width=450,height=400");
    if (newwin != null && newwin.opener == null)
    {
        newwin.opener = self;
    }

}

function MM_findObj(n, d) { //v4.0
  var p,i,x;
  if (!d)
    d=document;
  if ((p=n.indexOf("?"))> 0 && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if (!(x=d[n]) && d.all)
    x=d.all[n];
  for (i=0; !x && i< d.forms.length; i++)
    x=d.forms[i][n];
  for(i=0; !x && d.layers && i< d.layers.length; i++)
    x=MM_findObj(n,d.layers[i].document);
  if (!x && document.getElementById)
    x=document.getElementById(n);
  return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for (i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null) {
     document.MM_sr[j++]=x;
     if(!x.oSrc)
       x.oSrc=x.src;
     x.src=a[i+2];
   }
}

function addHistoryTerm(searchTermNumber, joiner) {
  var oldQuery = document.searchForm.query.value;
  var searchTerm = eval("document.tools.historyItem" + searchTermNumber + ".value");
  if (oldQuery) {
    document.searchForm.query.value = oldQuery + ' ' + joiner + ' ' + searchTerm;
  } else {
    document.searchForm.query.value = searchTerm;
  }
}

function clearSearchHistory() {
  document.searchForm.submitFlag.value = "clearhistory";
  switchTab('history');
}

function doSchoolSearch(substring) {
  var oldaction = document.searchForm.action;
  var newaction = oldaction.substring(0,oldaction.indexOf('search'));
  newaction = newaction + 'search/advanced/school';
  document.searchForm.action = newaction;
  document.searchForm.school.value = substring;
  document.searchForm.submit();
}

function addSchoolTerm(code, joiner) {
  var oldQuery = document.searchForm.query.value;
  var searchTerm = '學校代號(' + code + ')';
  if (oldQuery) {
    document.searchForm.query.value = oldQuery + ' ' + joiner + ' ' + searchTerm;
  } else {
    document.searchForm.query.value = searchTerm;
  }
}

function gotoTreePath(id) {
  var Oldquery = document.searchForm.query.value;
  document.tools.action = '/twdaoapp/servlet/readnodes';
  if (Oldquery)
      document.tools.query.value = Oldquery;
  document.tools.page.value  = id;
  document.tools.submit();
}

function addSubjectTerm(code, joiner) {
  var oldQuery = document.searchForm.query.value;
  var searchTerm = '主題分類(' + code + ')';
  if (oldQuery) {
    document.searchForm.query.value = oldQuery + ' ' + joiner + ' ' + searchTerm;
  } else {
    document.searchForm.query.value = searchTerm;
  }
}

// Other stuff we need on all advanced pages
function switchTab(newPane) {
  var oldaction = document.searchForm.action;
  var newaction = oldaction.substring(0,oldaction.indexOf('search'));
  newaction = newaction + newPane+".jsp";
  document.searchForm.action = newaction;
  document.searchForm.submit();
}

function submitSearch() {
  document.searchForm.submitFlag.value = "search";
  document.searchForm.submit();
}

function clearSearch() {
  document.searchForm.query.value = "";
}

function addMultipleOptions(selectObj, field) {
  var i;
  for (i = 0; i < selectObj.length; i++) {
    if (selectObj.options[i].selected) {
      addTerm(field, selectObj.options[i].value, 'and');
      selectObj.options[i].selected = false;
    }
  }
}

function addTerm(field,value,joiner,modifier) {
  // define term
  var term;

  // stop here unless we have a value to use
  if (value == "") {
    return;
  }

  // quote any values that might have "problem" characters
  if (value.indexOf('(') != -1) {
    value = '"' + value + '"';
  }

  if (!modifier) {
    modifier = 'EQ';
  }

  if (!joiner) {
    joiner = "and";
  }

  if (modifier == "EQ") {
    term = field + '(' + value + ')';
  }
  else if (modifier == "LT") {
    term = field + '(<' + value + ')';
  }
  else if (modifier == "LE") {
    term = field + '(<=' + value + ')';
  }
  else if (modifier == "GT") {
    term = field + '(>' + value + ')';
  }
  else if (modifier == "GE") {
    term = field + '(>=' + value + ')';
  }

  // rebuild expression
  buildExpr(term, joiner);
}

function buildExpr(term, joiner) {
  var expression;
  expression = document.searchForm.query.value;
  if (expression) {
    expression = expression + " " + joiner + " " + term;
  }
  else {
    expression = term;
  }
  document.searchForm.query.value = expression;
}

function addAllTerms() {
  // gather our data
  var indexSel, addedTerm;

  with(document.tools) { 
    fieldSel="";
    if (textfield1!=null && textfield1.value) {
      addTerm(".all", textfield1.value);
      addedTerm = 1;
    }

    indexSel = andtext2.selectedIndex;
    fieldSel = andtext2.options[indexSel].value
	if (fieldSel && textfield2.value) {
      // add the second term
      joinerVal = andfield2.options[andfield2.selectedIndex].value;
      if (joinerVal) {
        addTerm(fieldSel, textfield2.value, joinerVal);
      } else {
        addTerm(fieldSel, textfield2.value);
      }
      addedTerm = 1;
    }

    indexSel = andtext3.selectedIndex;
    fieldSel = andtext3.options[indexSel].value
    if (fieldSel && textfield3.value) {
      // add the second term
      joinerVal = andfield3.options[andfield3.selectedIndex].value;
      if (joinerVal) {
        addTerm(fieldSel, textfield3.value, joinerVal);
      } else {
        addTerm(fieldSel, textfield3.value);
      }
      addedTerm = 1;
    }

    joinerVal = andfield4.options[andfield4.selectedIndex].value;

    if (yearfrom.value) {
      addTerm("date", yearfrom.value, joinerVal, "GE");
      addedTerm = 1;
    }

    if (yearto.value) {
      addTerm("date", yearto.value, joinerVal, "LE");
      addedTerm = 1;
    }

    // now reset everything
//    andtext1.selectedIndex = 0;
    andtext2.selectedIndex = 0;
    andtext3.selectedIndex = 0;

    andfield2.selectedIndex=0;
    andfield3.selectedIndex=0;
    andfield4.selectedIndex=0;
    textfield1.value = "";
    textfield2.value = "";
    textfield3.value = "";
    yearfrom.value = "";
    yearto.value = "";
  }
}

 //var newwin = window.open("/twdaoapp/servlet/ShowService?path=pdf&title="+auname,

 function pdflink_org(auname)
{
  bName = navigator.appName;
  bVer = parseInt(navigator.appVersion);
  
  var ttt='/twdaoapp/servlet/statusProgress?nocache='+new Date();
  window.open(ttt,'UploadStatus','scrollbars=no,status=no,width=360,height=90');

  if (bName == "Microsoft Internet Explorer") {
	var newwin = window.open("/twdaoapp/servlet/waitingfor?path=pdf&title="+auname,
	+ "chk_window",
	"toolbar=no,menubar=no,resizable=1,scrollbars=yes,status=yes,width=600,height=350");
      if (newwin != null && newwin.opener == null)
         {
           newwin.opener = self;
          }
   }
   else{
		var newwin = window.open("/twdaoapp/servlet/ShowService?path=pdf&title="+auname,
	               + "chk_window",
	    "toolbar=no,menubar=no,resizable=1,scrollbars=yes,status=yes,width=600,height=350");
        if (newwin != null && newwin.opener == null)
        {
           newwin.opener = self;
        }
   }
}
