// JavaScript Document
//Functions used in DMS website

//This is the script for the rotating imgs on the top level page
// NO LONGER USED - REPLACED BY FLASH VERSION
numImages = 26;
imgPath = "assets/rotating_assets/";
rand = Math.floor(Math.random()*numImages) + 1;

//run the showImg() function onLoad
function showImg() {
  window.document.getElementById("randImg").src = imgPath + rand + ".jpg"; //images[rand];
}


// open popup window
function openPopup(URL, name, ww, hh) {
	var xcoord, ycoord, popWidth, popHeight, popName;
	
	xcoord = 0;
	ycoord = 0;
	
	if(name != null) {
		popName = name;
	}
	else {
		popName = "popup";
	}
	
	if(ww != null) {
		popWidth = ww;
	}
	else {
		popWidth = 460;
	}
	
	if(hh != null) {
		popHeight = hh;
	}
	else {
		popHeight = 580;
	}
	
	if(document.getElementById) {
		xcoord = Math.round((screen.availWidth - popWidth) / 2);
		ycoord = Math.round((screen.availHeight - popHeight) / 2);
	}
	
  myPopup = window.open(URL,popName,'width=' + popWidth + ',height=' + popHeight + ',left=' + xcoord + ',top=' + ycoord + ',directories=no,menubar=yesn,status=no,resizable=1,scrollbars=yes');
  if (!myPopup.opener) {
		myPopup.opener = self;
	}
	
	myPopup.focus();
}


// The following two functions are used to create mailto links in an effort to thwart 
//email harvesting spam-bots.

function generate_envelope_link( username, domain ) {
	//var domain = ".berkeley.edu";
	var atsign = "&#64;";
	var addr = username + atsign + domain;
	document.write( 
		"<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
		"<img src='assets/letter.gif' width='21' height='13' border='0' align='absmiddle' alt='click to send an email'>" +
		"<\/a>");
}

function generate_mailto_link( username, domain ) {
	//var domain = ".berkeley.edu";
	var atsign = "&#64;";
	var addr = username + atsign + domain;
	document.write( 
		"<" + "a" + " " + "href=" + "mail" + "to:" + addr + ">" +
		addr +
		"<\/a>");
}


function generate_comments_link( username, domain ) {
	//var domain = ".berkeley.edu";
	var atsign = "&#64;";
	var display = "Comments"
	var addr = username + atsign + domain;
	//alert (addr);
	document.write( 
		"<" + "a" + " " + "class='comments'" + " " + "href=" + "mail" + "to:" + addr + ">" +
		display + "<\/a>");
}


// Show/Hide bio text div on staff page
function showBio(name) {
	var theDivId;
	var theLinkId;
	theDivId = document.getElementById("bio-" + name);
	theLinkId = document.getElementById("show-hide-" + name);
	//alert(theDivId);
	
	if(theDivId.style.display == 'none') {
		theDivId.style.display = 'block';
		theLinkId.innerHTML = "<img src='../assets/arrow_up.gif' alt='show bio' width='9' height='9' /> hide bio";
	} else if(theDivId.style.display == 'block') {
		theDivId.style.display = 'none';
		theLinkId.innerHTML = "<img src='../assets/arrow_down.gif' alt='show bio' width='9' height='9' /> show bio";
	}
		

}

// used to snap window to image size
function PopupPic(sPicURL,sAudURL) {
     window.open( "../snaptoimage.html?"+sPicURL+"?"+sAudURL, "",  
     "resizable=1,HEIGHT=200,WIDTH=200");
   } 
	 

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}


//MACROMEDIA FUNCTIONS////////////////////////////////////////////////////////////////////////////////////////
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
