

// popup window open for Hal Crook Page //////////////////////////////////////////////////////////////////////////////////// 
var halCrookWin;
function openHalCrookWin(link)
{
	if(halCrookWin && !halCrookWin.closed)
	{
		halCrookWin.focus();			
	}
	else
	{
		halCrookWin = window.open(link,'halCrookWin','width=1124,height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// End popup window open for Catalog Page ////////////////////////////////////////////////////////////////////////////////////
// popup window open for Catalog Page //////////////////////////////////////////////////////////////////////////////////// 
var catalogWin;
function openCatalogWin(link)
{
	if(catalogWin && !catalogWin.closed)
	{
		catalogWin.focus();			
	}
	else
	{
		catalogWin = window.open(link,'catalogWindow','width=1124,height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// End popup window open for Catalog Page ////////////////////////////////////////////////////////////////////////////////////

// popup window open for Class Reserves Page //////////////////////////////////////////////////////////////////////////////////// 
var classReservesWin;
function openClassReservesWin(link)
{
	if(classReservesWin && !classReservesWin.closed)
	{
		classReservesWin.focus();			
	}
	else
	{
		classReservesWin = window.open(link,'classReservesWindow','width=1124, height=750,  directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// popup window open for Class Reserves Page //////////////////////////////////////////////////////////////////////////////////// 
var homeWin;
function goToHomeWin(link, openerWin)
{
	if(openerWin && !openerWin.closed)
	{
		openerWin.focus();	
		openerWin.location.href = link;		
	}
	else
	{
		homeWin = window.open(link,'homeWindow','width=1124,height=650,  directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
}
// end popup window open for Class Reserves Page //////////////////////////////////////////////////////////////////////////////////// 



// popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 
var articlesWin;
  

function openArticlesWin(link)
{      
  //---------------------------
  //display articles browser warning if neccessary
  if( berkleeBrowserTest() )
  {
    return false;
  }  
  //---------------------------  
  
	if(articlesWin && !articlesWin.closed)
	{
		articlesWin.focus();			
	}
	else
	{
		articlesWin = window.open(link,'articlesWindow','width=1124, height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
	                     
}
// end popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 


// popup window open for A-Z Page //////////////////////////////////////////////////////////////////////////////////// 
var azWin;
  

function openAZWin(link)
{      
	if(azWin && !azWin.closed)
	{
		azWin.focus();			
	}
	else
	{
		azWin = window.open(link,'azWindow','width=1124, height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
	                     
}
// end popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 


// popup window open for A-Z Page //////////////////////////////////////////////////////////////////////////////////// 
var subjectWin;
  

function openSubjectWin(link)
{      
	if(subjectWin && !subjectWin.closed)
	{
		subjectWin.focus();			
	}
	else
	{
		subjectWin = window.open(link,'subjectWindow','width=1124, height=650, directories=yes,location=yes, menubar=yes, scrollbars=yes, status=yes, toolbar=yes, resizable=yes');
	}
	                     
}
// end popup window open for Articles Page //////////////////////////////////////////////////////////////////////////////////// 




function berkleeBrowserTest()
{     
 
  //alert("berkleeBrowserTest()");     
   var show_upgrade_info = false;
  
  if ( berkleeBrowserCheck() == false )
  {
     if( displayWarning() )
     {
       show_upgrade_info = true;
     } 
  } 
  else
  {
    //alert('passed');
  }     
   
   return show_upgrade_info;
}

    
                         
//--------------------------------
function displayWarning()
{

  //alert user of issues; give them a choice 
  var show_info_bool = false;
  var msg = 'You are using an older Safari web browser that does not work with the Berklee library\'s Article site.\n\nPlease click "OK" for information on how to upgrade your browser.\n\nClick "Cancel" to ignore this warning';
  if( confirm(msg) )
  {
  	  window.location = "http://lr-test.berklee.edu/articles_upgrade";
  	  show_info_bool = true;
  }
  else
  {
    //do nothing, they ignored warning 
    //alert("confirm ignored");
  }
  return show_info_bool;
}

function berkleeBrowserCheck()
{                             
  
  var browser_check_bool = false;
  
   //  see http://developer.apple.com/internet/safari/uamatrix.html
  var minimun_safari_build_ver = 523; //corresponds to safari version 3.x
  
  var ua_text = navigator.userAgent;
  //alert('ua: ' + ua_text);
  var pattern_safari = new RegExp("safari/\\d*", "i");   //example "Safari/312.26"  
  //this "[0-9\.]*" pattern did not work!!! had to use the folowing pattern                                                                                    
  var pattern_safari_version = new RegExp("\\d{2,3}");   //example "312.26"
  
  var safari_ua = pattern_safari.exec(ua_text);
  
  if( safari_ua != null) //if this is a Safari  browser
  {
    var safari_build_version = pattern_safari_version.exec(safari_ua[0]); //are the brackets "[0]" neccessary???

    if ( safari_build_version != null && safari_build_version >= minimun_safari_build_ver)
    {
      browser_check_bool= true;
    }
  }      
  else
  {
    //this is not a Safari browser
    browser_check_bool = true;
  }                           
  
  return browser_check_bool;
   
}                                        
/*
//http://www.dustindiaz.com/getelementsbyclass/
function getElementsByClassName(classname, node)  
{
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}            
    */





/*  // ------ what are all these functions????   -------------
var cX = 0; var cY = 0;
function UpdateCursorPosition(e)
{ 
	cX = e.pageX; cY = e.pageY;
}
function UpdateCursorPositionDocAll(e)
{ 
	cX = event.clientX; cY = event.clientY;
}
if(document.all) 
{ 
	document.onmousemove = UpdateCursorPositionDocAll; 
}
else 
{ 
	document.onmousemove = UpdateCursorPosition; 
}
function AssignPosition(d) 
{
	d.style.left = (cX-20) + "px";
	d.style.top = (cY+20) + "px";
}
function HideContent(d) 
{
	if(d.length < 1) 
	{ 
		return; 
	}
	document.getElementById(d).style.display = "none";
	//shiftOpacity(d, 500);
}
function ShowContent(d) 
{
	if(d.length < 1) 
	{ 
		return; 
	}
	var dd = document.getElementById(d);
	//shiftOpacity(d, 2000);
	//opacity(d, 0, 100, 2000);
	time = new time();
	
	AssignPosition(dd);
	dd.style.display = "block";
	//currentDescription(d);
}
function ReverseContentDisplay(d) 
{
	if(d.length < 1) 
	{ 
		return; 
	}
	var dd = document.getElementById(d);
	AssignPosition(dd);
	if(dd.style.display == "none") 
	{ 
		dd.style.display = "block"; 
	}
	else 
	{ 
		dd.style.display = "none"; 
	}
}

// fade In and Out /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) 
	{
		for(i = opacStart; i >= opacEnd; i--)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		
		}
	} 
	else if(opacStart < opacEnd) 
	{
		for(i = opacStart; i <= opacEnd; i++)
		{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}        

*/


// End popup window open for Class Reserves Page ////////////////////////////////////////////////////////////////////////////////////

// mouse tracer //////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
var currentID = '';
function currentDescription(divID)
{
	currentID = divID;
}

var isIE = document.all?true:false;
if (!isIE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
function getMousePosition(mp) 
{
	var _x;
	var _y;
	if (!isIE) 
	{
		_x = mp.pageX;
		_y = mp.pageY;
	}
	if (isIE) 
	{
		_x = event.clientX + document.body.scrollLeft;
		_y = event.clientY + document.body.scrollTop;
	}
	if (currentID != '')
	{
	  document.thisform.x.value=_x;
	  document.thisform.y.value=_y;
	} 
	 return true;
}
*/
// END mouse tracer //////////////////////////////////////////////////////////////////////////////////////////////////////////////




/*
Copyright (c) 2009 Yamil Suarez (www.yamil.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

// This code requires at least Firefox version 1 or IE version 5.5

function proxy(reference)
{
	var proxy_server = "http://catalog.berklee.edu:2048/login?url="; 
	
	var proxy_urls = new Array();
	
	//add URLS that need proxy
	proxy_urls.push("http://site.ebrary.com");
	proxy_urls.push("http://netlibrary.com");
	proxy_urls.push("http://library.berklee.edu");

	for( x in proxy_urls)
	{
		pattern = new RegExp(  proxy_urls[x] , "i" ); //i == case insensitive search
		//if URL matches pattern
		if(pattern.test(  reference.href  ) )
		{
			if( reference.href.match(proxy_server)  == null ) // avoid adding proxy_server again
			{
				reference.href = proxy_server + reference.href;
			}	

		}
	}
} //proxy() function END













