//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oo
//oo
//oo
//oo  Program: misc.js
//oo  Author: Fred Edwards
//oo
//oo  Date: 20/02/2003 4:00PM
//oo
//oo
//oo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo


//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

function PageQuery(q) {
   if(q.length > 1)
      this.q = q.substring(1, q.length);
   else
      this.q = null;
   this.keyValuePairs = new Array();
   if(q) {
      for(var i=0; i < this.q.split("&").length; i++) {
      this.keyValuePairs[i] = this.q.split("&")[i];
      }
   }

   this.getKeyValuePairs = function() { return this.keyValuePairs; }

   this.getValue = function(s) {
      for(var j=0; j < this.keyValuePairs.length; j++) {
         if(this.keyValuePairs[j].split("=")[0] == s)
            return this.keyValuePairs[j].split("=")[1];
      }
      return false;
   }

   this.getParameters = function() {
      var a = new Array(this.getLength());
      for(var j=0; j < this.keyValuePairs.length; j++) {
         a[j] = this.keyValuePairs[j].split("=")[0];
      }
      return a;
   }
   this.getLength = function() { return this.keyValuePairs.length; }
}

function queryString(key){
   var page = new PageQuery(window.location.search);
   return unescape(page.getValue(key));
}

//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//
// Cookie Functions
//
// to get a cookie value:
//   var firstname = getCookie('firstname');
//
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}
function getCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg)
         return getCookieVal (j);
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
   }
   return null;
}
function setCookie (name, value) {
   var argv = setCookie.arguments;
   var argc = setCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain = (argc > 4) ? argv[4] : null;
   var secure = (argc > 5) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) +
      ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
      ((path == null) ? "" : ("; path=" + path)) +
      ((domain == null) ? "" : ("; domain=" + domain)) +
      ((secure == true) ? "; secure" : "");
}
function deleteCookie (name) {
   var exp = new Date();
   exp.setTime (exp.getTime() - 1);
   var cval = getCookie (name);
   document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//
// dating formats
//
function date_ddmmmyy(date)
{
  var day = date.getDate();
  var mon = date.getMonth() + 1;
  var yea = date.getYear();

  // could use splitString() here
  // but the following method is
  // more compatible
  var mmm =
    ( 1==mon)?'Jan':( 2==mon)?'Feb':(3==mon)?'Mar':
    ( 4==mon)?'Apr':( 5==mon)?'May':(6==mon)?'Jun':
    ( 7==mon)?'Jul':( 8==mon)?'Aug':(9==mon)?'Sep':
    (10==mon)?'Oct':(11==mon)?'Nov':'Dec';

  if ((yea > 100) && (yea < 2000)) { yea = (yea -100) + 2000; }


  return "" +
    (day<10?"0"+day:day) + "-" +
    mmm + "-" + (yea<10?"0"+yea:yea);




//    return (day + "/" + mon + "/" + yea);

}


//
// get last modified date of the
// current document.
//
function date_lastmodified() {
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}



//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//
//   JS EXTRACTED FROM ORIGINAL JOURNALS PAGE  &  FRONT PAGE
//
//   MAR 2009



 //   var userIP = "<!--#echo var="REMOTE_ADDR" -->";
   var onCampus = true;
   
   userIP = " " + userIP;
   
   if (userIP.match(" 140.184.") != " 140.184.") {
      onCampus = false;

   } else {
            if ((userIP.match(" 140.184.72.132") == null)) {
         onCampus = true;
      } else {
         onCampus = false;
      }
   }


function onEnterJP(e, frm){
	var keyCode = null;
	if( e.which )
	{
		keyCode = e.which;
	} 
	else if( e.keyCode )
	{
		keyCode = e.keyCode;
	}
	
	if( keyCode == 13 )
	{
		//	frm.btnSubmit.click();
		openAsinForQSearchJP();
		return false;
	}
		return true;
}

function onEnterFP(e, frm){
	var keyCode = null;
	if( e.which )
	{
		keyCode = e.which;
	} 
	else if( e.keyCode )
	{
		keyCode = e.keyCode;
	}
	
	if( keyCode == 13 )
	{
		//	frm.btnSubmit.click();
		openAsinForQSearchFP();
		return false;
	}
		return true;
}

// trying to check if user pressed enter to instantiate their search on the novanet quick search text box
function onEnterFP2(e, frm){
	//alert ("hi i'm in onEnter2");
	var keyCode = null;
	if( e.which )
	{
		keyCode = e.which;
	} 
	else if( e.keyCode )
	{
		keyCode = e.keyCode;
	}
	
	if( keyCode == 13 )
	{
		//alert ("hi i'm in onEnter2 you pressed enter");
		openNovanetSearch();
		return false;
	}
		return true;
}

function onEnterJP2(e, frm) {
	//alert ("hi i'm in onEnter2");
	var keyCode = null;
	if( e.which )
	{
		keyCode = e.which;
	} 
	else if( e.keyCode )
	{
		keyCode = e.keyCode;
	}
	
	if( keyCode == 13 )
	{
		//alert ("hi i'm in onEnter2 you pressed enter");
		openNovanetSearch();
		return false;
	}
		return true;
}
  
function openAsinForQSearchFP() {
  var myUrl = 'http://library.smu.ca:2048/login?url=http://search.ebscohost.com/login.aspx?';
  myUrl += 'direct=true&site=ehost-live&scope=site&type=1&dbgroup=10791&authtype=ip&bquery=&bquery=';
  myUrl += document.qSearch.query.value;
  var MyWindowName = '';
  //var MyWindowOptions = 'width=250,height=250';
  window.open(myUrl, null, MyWindowName);
  //alert(myUrl);
  asinQSearchFPStats();
}


// this function opens a stub page on thunder (the stub page closes itself right away) 
// we just want to keep live statistics on how many people use asin quick search 
// from library's home page. Please check "asin_QSearch_Front_Page.html" on thunder's statistics
function asinQSearchFPStats() {
  //alert ("now in function statsPage");
  var statsUrl = "http://www.smu.ca/administration/library/asin_QSearch_Front_Page.html";
  var statsWindow = '';
  window.open(statsUrl, statsWindow);
  //alert("now ending function statspage");
  //if (!popup.opener) popup.opener = self;
}


function openNovanetSearchFP() {
	var novanetSearchUrl = 'http://aleph1.novanet.ns.ca/F/?func=find-b&find_code=WRD&request=';
		novanetSearchUrl += document.novaSearch.request.value;
	//alert(novanetSearchUrl);
	var newNovanetWindow = '';
	window.open(novanetSearchUrl, newNovanetWindow);
	novanetFPStats();
}

// this function opens a stub page on thunder (the stub page closes itself right away) 
// we just want to keep live statistics on how many people use novanet quick search 
// from library's home page. Please check novanet_Search_Front_Page.html on thunder's statistics
function novanetFPStats(){
   
  var novanetStatsUrl = "http://www.smu.ca/administration/library/novanet_Search_Front_Page.html";
  var novanetStatsWindow = '';
  window.open(novanetStatsUrl, novanetStatsWindow);
  
}

function openAsinFromTab() {
  var myUrl = 'http://library2.smu.ca:2048/login?url=http://asin1.its.unb.ca:8000/muse/logon/SMU/';
  var MyWindowName = '';
  //var MyWindowOptions = 'width=250,height=250';
  window.open(myUrl, null, MyWindowName);
  //alert(myUrl);
  asinTabFromJournalsPageStats();
  
}

// this function opens a stub page on thunder (the stub page closes itself right away) 
// we just want to keep live statistics on how many people use asin quick search 
// from library's home page. Please check "asin_QSearch_Front_Page.html" on thunder's statistics
function asinTabFromJournalsPageStats() {
  //alert ("now in function statsPage");
  var statsUrl = "http://www.smu.ca/administration/library/asin_From_Tab.html";
  var statsWindow = '';
  window.open(statsUrl, statsWindow);
  //alert("now ending function statspage");
  //if (!popup.opener) popup.opener = self;
}


function openAsinForQSearchJP() {
  var myUrl = 'http://library.smu.ca:2048/login?url=http://search.ebscohost.com/login.aspx?';
  myUrl += 'direct=true&site=ehost-live&scope=site&type=1&dbgroup=10791&authtype=ip&bquery=&bquery=';
  myUrl += document.qSearch.query.value;
  var MyWindowName = '';
  //var MyWindowOptions = 'width=250,height=250';
  window.open(myUrl, null, MyWindowName);
  //alert(myUrl);
  asinQSearchJPStats();
}


// this function opens a stub page on thunder (the stub page closes itself right away) 
// we just want to keep live statistics on how many people use asin quick search 
// from library's journals page. Please check "asin_QSearch_Journals_Page.html" on thunder's statistics
function asinQSearchJPStats() {
  //alert ("now in function statsPage");
  var statsUrl = "http://www.smu.ca/administration/library/asin_QSearch_Journals_Page.html";
  var statsWindow = '';
  window.open(statsUrl, statsWindow);
  //alert("now ending function statspage");
  //if (!popup.opener) popup.opener = self;
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized

  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}
MM_reloadPage(true);



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.show(e, msg);
}

function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.hide();
}


function viewSwitch() {
   
   if (pageStatus == 0) {
      document.getElementById("Layer5").style.background = 'url(images/DatabasesAtoZ-Black.gif)';
      postResultsBySubject();
   } else {
      document.getElementById("Layer5").style.background = 'url(images/DatabasesBySubject-Black.gif)';
      postResultsByAlpha();
   }
   
}

function toggleMore() {

	el = document.getElementById("moreInfoTR");
	var display = el.style.display ? '' : 'none';
	el.style.display = display;

}

function switchDisplay() {
   var myTab = document.getElementById("layerHeight");
   var newHeight = myTab.clientHeight;
   
   if (pageState == 0) {
     newHeight += 500;
     myTab.rows[0].style.height = newHeight;
     postResultsBySubject();
     document.getElementById('titleText').innerHTML = "Databases by Subject";
     document.getElementById('sortText').innerHTML = "sort alphabetically";
     pageState = 1;
   } else {
     newHeight -= 500;
     myTab.rows[0].style.height = newHeight;                 
     postResultsByAlpha();
     document.getElementById('titleText').innerHTML = "Databases A-Z";
     document.getElementById('sortText').innerHTML = "sort by subject";
     pageState = 0;
   }    
}


function dispJPQSearchTipText() {

document.write('<table width="100%" border="0" cellpadding="3">');
document.write('	<tr>');
document.write('		<td><p>Use this search to find articles in popular databases.<strong><font size="-1"><a href=# onclick=toggleMore(); > (which databases?)</a></font></strong> </td>');
document.write('	</tr>');
document.write('	<tr name="moreInfoTR" id="moreInfoTR" style="display: none;">');
document.write('       	<td><p>This searches:<br>');
document.write('		&nbsp; &nbsp; 1. Ebsco Academic<br>');
document.write('		&nbsp; &nbsp; 2. ABI Informs<br>');
document.write('		&nbsp; &nbsp; 3. PsycInfo/Articles<br>');
document.write('		&nbsp; &nbsp; 4. Science Direct<br>');
document.write('		&nbsp; &nbsp; 5. Wiley InterScience<br>');
document.write('		&nbsp; &nbsp; 6. Springerlink<br>');
document.write('		&nbsp; &nbsp; 7. Sociological Abstracts<br>');
document.write('		&nbsp; &nbsp; 8. JSTOR journal archive</td>');
document.write('	</tr>');
document.write('</table>');

}




//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

// end



