// /////////////////////////////////////////////////////////////////////////////////////////////
//
//      SCRIPT NAME:	global-scripts.js
//    SCRIPT AUTHOR:	Web Services
//      SCRIPT DATE:	May 2009
//  SCRIPT LOCATION:	pitcairn://target1s3/Web2/htdocs/www/scripts/
//  SCRIPT FUNCTION:		
//     SCRIPT NOTES:	    
// OTHER FILES USED:	
//    LAST MODIFIED:	
//	                       
// /////////////////////////////////////////////////////////////////////////////////////////////
//

//
// FUNCTION TO COLLECT TAGS BY CLASS NAME
//
document.getElementsByClass=function(tag, classname){
var tagcollect=document.all? document.all.tags(tag): document.getElementsByTagName(tag); //IE5 workaround
var filteredcollect=new Array();
var inc=0;
for (i=0;i<tagcollect.length;i++){
if (tagcollect[i].className==classname)
filteredcollect[inc++]=tagcollect[i];
}
return filteredcollect;
} // end - function()

//
// FUNCTION TO EXPAND GLOBAL NAV MENU
//
function expandMenu(divName){
contractMenus();
document.getElementById(divName).style.left = 'auto';
} // end - function expandMenu()

//
// FUNCTION TO CONTRACT GLOBAL NAV MENUS
//
function contractMenus(){
var divElements=new Array();
divElements=document.getElementsByClass('div','menuList');
var inc=0;
while (divElements[inc]){
divElements[inc].style.position = 'absolute';
divElements[inc].style.left = '-999em';
inc++;
}
} // end - function contractMenus()

//
// FUNCTION TO EXPAND SELECTED TAB
//
function expand(divname, tabname){
contract();
document.getElementById(divname).style.display = 'inline-block';
document.getElementById(tabname).className = 'activetabstyle';
} // end - function expand()

//
// FUNCTION TO CONTRACT UNSELECTED TABS
//
function contract(){
var divElements=new Array();
divElements=document.getElementsByClass('div','tabcontent');
if(divElements.length == 0){
divElements=document.getElementsByClass('div','tabcontent_index');
}
tabelements=document.getElementsByClass('div', 'activetabstyle');
var inc=0;
while (divElements[inc]){
divElements[inc].style.display = 'none';
inc++;
}
var tabinc=0;
while(tabelements[tabinc]){
tabelements[tabinc].className= 'tabstyle';
tabinc++;
}
} // end - function contract()

//
// FUNCTION TO SWITCH OUT FORM BUTTON ON MOUSEOVER/MOUSEOUT
//
// when passed button element id, determines if current button state is on 
// or off and changes button src accordingly. requires button naming scheme
// of 'button-buttonname-off' and 'button-buttonname-on'.
//
function switchButton(elemid) {
var buttonElem = document.getElementById(elemid);
var buttonImg = buttonElem.src;
if (buttonImg.match(/-off./)) {
buttonImg = buttonImg.replace('-off.','-on.');
} else {
buttonImg = buttonImg.replace('-on.','-off.');
}
buttonElem.src = buttonImg;
return;
} // end - function switchButton()


function goBtnOff(){
// document.getElementById('quicksearch_go').src = 'http://' + window.location.host + '/images/button-go-off.gif';
document.getElementById('quicksearch_go').src = 'http://www.lib.uci.edu/images/button-go-off.gif';
}

// This is for testing ways to link to a tab.
function changeURL(tabname) {
	parent.location.hash = tabname;
	displayCorrectTab();
}

function displayCorrectTab(){
	var thisURL = window.location.href.split('#');
	if(thisURL[1] != null){
		contract();
		var urlname = thisURL[1].replace(/%20/g, " ");
		document.getElementById(urlname + ' content').style.display = 'inline-block';
		document.getElementById(urlname).className = 'activetabstyle';
	}
}

// For Google maps.

    
    	//append driving "To here" form to a current extra div (curr_div)
    	//long, lat - longtitude and latitude of a marker required.
    	//JL 2/4/2008
    	function to_here(curr_div, long, lat)
    	{
	    	window.status='';
	    	
	    	var me = document.getElementById(curr_div);
	    	
			me.innerHTML = "<b>Driving Directions:</b>";
			me.innerHTML += '&nbsp;&nbsp;<b>To here</b>&nbsp;&nbsp;&nbsp;<a class="maplink" href="javascript:from_here(' + curr_div + ',' + long + ',' + lat + ');">From here</a>';						    	
	    	
         me.innerHTML +=  '<p><b>Start address:</b><form action="http://maps.google.com/maps" method="get" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=60 name="saddr" id="saddr" value="" /><br>' +
           '<input class="button" value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="daddr" value="' + long + ',' + lat + '"/></p>';       
           
         //myclick(curr_div);                     
    	}
    	
    	//append driving "From here" form to a current extra div (curr_div)
    	//long, lat - longtitude and latitude of a marker required.
    	//JL 2/4/2008    	
    	function from_here(curr_div, long, lat)
    	{
	    	//alert(long + " " + lat);
	    	window.status='';
	    	
	    	var me = document.getElementById(curr_div);
	    	
			me.innerHTML = "<b>Driving Directions:</b>";
			me.innerHTML += '&nbsp;&nbsp;<a class="maplink" href="javascript:to_here(' + curr_div + ',' + long + ',' + lat + ');">To here</a> &nbsp;&nbsp;&nbsp;<b>From here</b>';					
	    		    	
         me.innerHTML +=  '<p><b>End address:</b><form action="http://maps.google.com/maps" method="get"" target="_blank">' +
           '<input type="text" SIZE=40 MAXLENGTH=60 name="daddr" id="daddr" value="" /><br>' +
           '<input class="button" value="Get Directions" TYPE="SUBMIT">' +
           '<input type="hidden" name="saddr" value="' + long + ',' + lat + '"/></p>';
 		    		    	
         //myclick(curr_div);  
    	}
    	
    	
      //JL 2/4/2008
      // curr_div - current div that holds the "to here - from here" form.
      // div_count - number of markers of the map.
      // long, lat - longtitude and latitude of a marker.
		function toggle_div(curr_div, div_count, long, lat){
			
			//alert(div_count);
			//alert(long + " " + lat);			
			
			var me = document.getElementById(curr_div);
			
			if (me.style.display=="inline-block")
			{
				me.style.display="none";
			}
			else 
			{
				if (me.style.display=="none"){
					me.style.display="inline-block";
						
					//Add inner html stuff here.
					me.innerHTML = "<b>Driving Directions:</b>";
					me.innerHTML += '&nbsp;&nbsp;<a class="maplink" href="javascript:to_here(' + curr_div + ',' + long + ',' + lat + ');">To here</a> &nbsp;&nbsp;&nbsp;<a class="maplink" href="javascript:from_here(' + curr_div + ',' + long + ',' + lat + ');">From here</a>';					
				}
					
					//Close other divs and make only the current div active.
				for(i = 0; i < div_count; i++)
				{
					if(i != curr_div)
						document.getElementById(i).style.display="none";
				}															
			}
		}    



/* This is code for the hmong-textile page */
	PositionX = 100;
	PositionY = 100;
	
	// Set these value approximately 20 pixels greater than the
	// size of the largest image to be used (needed for Netscape)
	
	defaultWidth  = 500;
	defaultHeight = 500;
	
	// Set autoclose true to have the window close automatically
	// Set autoclose false to allow multiple popup windows
	
	var AutoClose = true;
	
	// Do not edit below this line...
	// ================================
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=yes,width=150,height=100,left='+PositionX+',top='+PositionY;
	function popImage(imageURL,imageTitle){
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
	writeln('width=100-(document.body.clientWidth-document.images[0].width);');
	writeln('height=100-(document.body.clientHeight-document.images[0].height);');
	writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
	writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
	writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
	if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="yes" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body bgcolor=000000 scroll="yes" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
	writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
	close();		
	}}
/* End of code for hmong-texile page */

/* For SCA collections pages */
function openDiv(divName) {	
	document.getElementById("spotlight-on").style.display = "none";	
	var divElements=new Array();
	divElements=document.getElementsByClass('div','collections-info-div');
	var inc=0;
	while (divElements[inc]){
		divElements[inc].style.display = 'none';
		inc++;
	}
	document.getElementById(divName).style.display = "block";
}
