function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" )
	this.ie = (this.b=="ie" )
}
// automatically create the "is" object
is = new BrowserCheck()
var mx;
var my;
var n =0
function myHelpWindow(url) {//today
  window.open(url, 'myHelpWin' ,'height=260,width=150,screenX=598,screenY=205,left=598,top=205');
}
function myStandardsWindow(url) {
  	var xLeft = (screen.width - 520)/2;
	var yTop = (screen.height - 300)/2;
	var myFeatures = 'scrollbars,height=300,width=517,screenX='+xLeft+',screenY='+yTop+',left='+xLeft+',top='+yTop;
	window.open(url, 'myStandardsWin' ,myFeatures);
}



function setSearchOption(psize,sortOpt){
	var x=MM_findObj("resultoption");
	//var y=MM_findObj("search");
    var y= document.getElementById("searchForm");
	
	if(x){
		i=0;
		s=x.dsize.length;
		while(i<=s && x.dsize.options[i].value!=psize)
			i++
		if(i <=s) 
			x.dsize.options[i].selected=true;

	}		
	if(y)
			y.dsize.value=psize;
	
}

function setSortBy(val){
	//var x=MM_findObj("search");
	var x= document.getElementById("searchForm");
	
	if(x)
	{   
		x.sortbyStr.value=val;
	}
	//alert(x.sortbyStr.value);
}


function setPageSize(formObj){
	k = formObj.selectedIndex;
	//var x=MM_findObj("search");
	var x= document.getElementById("searchForm");
	
	if(x)
	{   
		x.dsize.value=formObj.options[k].value;
	}

	//parent.info.document.s_option.pagesize.value=formObj.options[k].value;
}


function backtoresults_bk(){
	 Murlstr= parent.info.document.resultURL.urlstr.value;
	 window.location = Murlstr;
}


function backtoresults(){
	 Murlstr= getCookie("resultURL");
	 //alert(Murlstr);
	 window.location = Murlstr;
}


function backtoresults_frBib(){
	 Murlstr= getCookie("resultURL");
     Murlstr = "../" + Murlstr;
	 window.location = Murlstr;
}

function gotopage(pageno){
	urlstr = CurPageUrl +pageno;
	window.location =urlstr;

}

function RE_windowScroll(ix,iy,sTop){
	for(i=1;i<sTop ;i++)
		window.scrollBy(ix,iy);
}


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 mouseDown(e) {
	if ((is.ns && e.which!=1) || (is.ie && event.button!=1)) return true
	mx = (is.ns)? e.pageX : event.clientX + document.body.scrollLeft;
	my = (is.ns)? e.pageY : event.clientY + document.body.scrollTop;
	return true
}

if(is.ns)
	document.addEventListener('mousedown',mouseDown,false);
else
	document.onmousedown=mouseDown;





function MM_findObj(n, d) { //v3.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); 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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function T_open(s){
 window.open(s,'standardWin','scrollbars, height=275, width=522, top=200, screenY=200, left=200, screenY=200,resizable=1');
}


function checkRequest(formObj){
	var recipient=formObj.email.value;
	var message=formObj.content.value;
	var name   =formObj.name.value;
	if(name=="" || name=="type your name here.."){
		alert("Please enter your name.");
		return false;
	}
	if(recipient=="" ||	recipient=="type your email here.."){
		alert("Please enter your email address.");
		return false;
	}
	if(recipient.search("@")==-1){
		alert("Invalid email address! Please enter your email address.");
		return false;

	}
	if(message=="" || message=="Please find some information on...and notify me at the above address when you find it."){
		alert("Please enter your message in the content box");
		return false;
	}
	window.open("", "messageWin", "width=300,height=150,screenX=250,screenY=225,top=225,left=250")
	return true;
}


function checkSuggestion(formObj){
	var recipient=formObj.email.value;
	var message=formObj.content.value;
	var name   =formObj.name.value;
	if(name=="" || name=="type your name here.." ){
		alert("Please enter your name.");
		return false;
	}
	if(recipient=="" ||	recipient=="type your email here.."){
		alert("Please enter your email address.");
		return false;
	}
	if(recipient.search("@")==-1){
		alert("Invalid email address! Please enter your email address.");
		return false;

	}
	if(message=="" || message=="Dear Library Specialists, My class and I would like some info on.."){
		alert("Please enter your message content in the content box");
		return false;
	}
	window.open("", "messageWin", "width=300,height=150,screenX=250,screenY=225,top=225,left=250")
	return true;
}


function setHpage(){
	parent.info.setHpage(document.URL);
}

function getTopicList(id){
    ArrayofTopics = id.split("\n");
    last = ArrayofTopics.length; 
	i =0;
	topicStr = "";
	dsize=10;
	for(i=0;i<last;i++){
	
		topicStr += "<a style='color:#39606B' href='topics.asp?topics=";
		topicStr += escape(ArrayofTopics[i]);
		topicStr +="&dsize=";
		topicStr +=dsize;
		topicStr +="'><nobr>";
		topicStr += ArrayofTopics[i];
		topicStr +="</nobr></a><br>";

	}
	n=i
}
function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function listTopic(Rec_id){
	getTopicList(Rec_id)
	iblock=getElemRefs("recTopics")
	oblock=getElemRefs("topicDiv")
	if(iblock){	
		iblock.innerHTML  = topicStr
		oblock.style.xpos =160 + "px";//mx
		oblock.style.ypos =my-n*10 +"px"
		oblock.style.left = oblock.style.xpos ;
		oblock.style.top  = oblock.style.ypos ;
		oblock.style.visibility = "visible"	;
				
	}
	
}

function listTopic_bk(Rec_id){
	getTopicList(Rec_id)
	iblock=getElemRefs("recTopics")
	oblock=getElemRefs("topicDiv")
	if(iblock){
			iblock.innerHTML  = topicStr
			oblock.style.xpos =mx
			oblock.style.ypos =my-n*10 
			oblock.style.left = oblock.style.xpos
			oblock.style.top  = oblock.style.ypos
			oblock.style.visibility = "visible"		
	}
	
}



function showlayer(id,x,y) {
	block=getElemRefs(id); 
	if(block){	
		block.style.xpos =x
		block.style.ypos = y 
		block.style.left = block.style.xpos
		block.style.top  = block.style.ypos
		block.style.visibility = "visible"
	}
}

function hideLayer(id) {
	block=getElemRefs(id); 
	if (block) 
		block.style.visibility = "hidden"
}
function checkSForm(formObj){
	var grades="";
	if(formObj.keyword.value.length==0){
		alert("Please enter your search argument"); 
		return false;
	}
	return true;
}

function add_delCat(obj){
	//var x=MM_findObj("search");
	var x=document.getElementById("searchForm");
	var y=MM_findObj("feature");
	var cats="";
	var i=0,j=0;
	if(x && y){
		if(obj.checked && obj.name=="all"){
			x.cats.value="";
			for (i=1;i<y.length;i++){
				y.elements[i].checked=false;
			}
		}
		else{
			for (i=1;i<y.length;i++){
				if(y.elements[i].checked){
					j++;
					cats += y.elements[i].value;
				}
			}
			if(j==y.length-1)
				x.cats.value="";
			else if(j==0)
				y.all.checked=true;
			else{
				y.all.checked=false;
				x.cats.value=cats;
			}
		}
	}
	//alert(cats);
	
}

function add_delGrade(obj){
	//var x=MM_findObj("search");
	var x= document.getElementById("searchForm");
	var y =MM_findObj("gradelevel");
	var grades="";
	var i=0,j=0;
	
	if(x && y){
		if(obj.checked && obj.name=="grade_all"){
			x.grades.value="";
			for (i=1;i<y.length;i++){
				y.elements[i].checked=false;
			}
		}
		else{
			for (i=1;i<y.length;i++){
				if(y.elements[i].checked){
					j++;
					grades += y.elements[i].value;					
				}
			}
			
			if(j==y.length-1)
				x.grades.value="";
			else if(j==0)
				y.grade_all.checked=true;
			else{
				y.grade_all.checked=false;
				x.grades.value=grades;
			}
		}
	}
	
}



function toggle(id){
	obj1=document.getElementById("x"+id);
	obj2=document.getElementById("y"+id);
	if(obj1){
		if(obj2.style.display=="none"){
			obj1.innerHTML="<a href=# onclick='toggle(\"" + id + "\");return false'>Collapse all</a>";
			obj2.style.display="block";
		}
		else{
			obj1.innerHTML="<a href=# onclick='toggle(\"" + id + "\");return false'>Expand all</a>";
			obj2.style.display="none";
		}
	}
}
var opalsWindow;
function srchDewey(dStr){
	var url="http://demo.scoolaid.net/bin/search/standard?sf0=13&kw0=" + dStr;
	if(typeof(keyword) != "undefined" && keyword!="")
		url += "&sf1=21&kw1=" + keyword + "&boolop1=or"

    opalsWindow=window.open(url, 'Opals' ,'scrollbars=yes,resizable=yes,height=600,width=800,screenX=40,screenY=40,left=40,top=40');
	if (window.focus) {opalsWindow.focus()}

}

/////////////////////////////////////////////////////
// 
// Thai  for bibliography
//
/////////////////////////////////////////////////////

function addDelBib(obj,ifChecked){

	var recId=obj.value;
    var recIdList= getCookie("recIdList");
    var newRecIdList='';
	var recCount=0;
    var recIdArr=recIdList.split(',');
    for(var i=0; i< recIdArr.length; i++){
       if( recIdArr[i]!='' && recIdArr[i]!=recId){
            newRecIdList += recIdArr[i] + ",";
			recCount++;
		}
    }
	if(obj.checked==ifChecked){
		newRecIdList += recId+ ",";
		recCount++;
	}

    setCookie("recIdList",newRecIdList); 
	updateBibCount(recCount);
    
}
////////////////////////////////
// 
//  This function is the oposite ot the addDelBib() function
//  used in the bibliography where 
//      
//        checkbox.checked =true   : remove from list
//        checkbox.checked =false  : add to the list
//
///////////////////////////////

function delAddBib(obj){

	var recId=obj.value;
    var recIdList= getCookie("recIdList");
    var newRecIdList='';
	var recCount=0;
    var recIdArr=recIdList.split(',');
    for(var i=0; i< recIdArr.length; i++){
       if( recIdArr[i]!='' && recIdArr[i]!=recId){
            newRecIdList += recIdArr[i] + ",";
			recCount++;
		}
    }
	if(!obj.checked){
		newRecIdList += recId+ ",";
		recCount++;
	}

    setCookie("recIdList",newRecIdList); 
	updateBibCount(recCount);
    
}


function updateBibCount(n){
	block=document.getElementById("bibCount");
	var str ="<b>" + n + "</b> items in bibliography";
	if(block)
		block.innerHTML=str;
}


function clearBib(ifChecked){
    var recIdList= getCookie("recIdList");
    var recIdArr=recIdList.split(',');
    for(var i=0; i< recIdArr.length; i++){
       if( recIdArr[i]!=''){
			var obj=document.getElementById("bib" + recIdArr[i])
			if(obj) obj.checked=ifChecked;
	   }
    }
    setCookie("recIdList",""); 
	updateBibCount(0);

}


function initSelBib(){
	var checkVal=true;
	var url ="";
	url =this.location.href;
    var recIdList= getCookie("recIdList");
    var recIdArr=recIdList.split(',');
	var bibCount=0;
		
	if(url.indexOf('biblio.asp')!=-1){
		checkVal=false;

	}

    var checkBoxes=document.getElementsByTagName("input");
	for(var i=0; i< checkBoxes.length; i++){
		if(checkBoxes[i].type=="checkbox" && checkBoxes[i].id.indexOf("bib")==0){
			checkBoxes[i].checked=false;
		}
	}


    for(var i=0; i< recIdArr.length; i++){
       if( recIdArr[i]!=''){
			bibCount++;
			var obj=document.getElementById("bib" + recIdArr[i])
			if(obj) obj.checked=checkVal;
	   }
    }
	updateBibCount(bibCount);
   
   //Bibliography format cookie
    var bibformat= getCookie("bibformat");
	var fradios = document.getElementById ('bibFradios');
	if (fradios) {
	  var inputs = fradios.getElementsByTagName ('input');
	  if (inputs) {
		if (bibformat !=""){
			for (var i = 0; i < inputs.length; ++i) {
			  if (inputs[i].type == 'radio' && inputs[i].name == 'bibformat'&& inputs[i].value == bibformat)
				inputs[i].checked = true;
			  else 
				inputs[i].checked = false;
			}
		}
		else{
			inputs[0].checked = true;
			setCookie("bibformat", "mla");
		}
	  }
	}

   //Summary Bibliography format cookie
    var sumformat= getCookie("sumformat");
	var sradios = document.getElementById ('sumFradios');
	if (sradios) {
	  var inputs = sradios.getElementsByTagName ('input');
	  if (inputs) {
		if (sumformat !=""){
			for (var i = 0; i < inputs.length; ++i) {
			  if (inputs[i].type == 'radio' && inputs[i].name == 'sumformat'&& inputs[i].value == sumformat)
				inputs[i].checked = true;
			  else 
				inputs[i].checked = false;
			}
		}
		else{
			inputs[0].checked = true;
			setCookie("sumformat", "0");
		}
	  }
	}

   
   //Sort Bibliography format cookie
    var bibsortby= getCookie("bibsortby");
	var sbyradios = document.getElementById ('sortradios');
	if (sbyradios) {
	  var inputs = sbyradios.getElementsByTagName ('input');
	  if (inputs) {
		if (bibsortby !=""){
			for (var i = 0; i < inputs.length; ++i) {
			  if (inputs[i].type == 'radio' && inputs[i].name == 'bibsortby'&& inputs[i].value == bibsortby)
				inputs[i].checked = true;
			  else 
				inputs[i].checked = false;
			}
		}
		else{
			inputs[0].checked = true;
			setCookie("bibsortby", "title");
		}
	  }
	}


}


function genBibliography(orderBy){
    var recIdList= getCookie("recIdList");
	if(recIdList=="")
		alert("It appears that you haven't selected any record.");
	else{
		//Ha urlstr = "../script/biblio.asp?biblist=" + recIdList +"&orderby=" +orderBy;
		urlstr = "../biblio.asp?biblist=" + recIdList +"&orderby=" +orderBy;
		window.location =urlstr;
	}
}
/////////////////////////////////////////////////////
//  Thai : Cookie functions
/////////////////////////////////////////////////////

function setCookie(name, value, path, domain, secure) {
  var curCookie = name + '=' + escape(value) +
//                  ((path) ? '; path=' + path : '') +
                  '; path=/' +
                  ((domain) ? '; domain=' + domain : '') +
                  ((secure) ? '; secure' : '');
  document.cookie = curCookie;
}

/**
 * Get cookie
*/
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + '=';
  var begin = dc.indexOf('; ' + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0)
      return '';//null;
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(';', begin);
  if (end == -1)
    end = dc.length;
  
  return unescape(dc.substring(begin + prefix.length, end));
}

///////////////////////////////////////////////////////
function delTopic(t){
	topicFrame.delTopic(t);
 
}