//THIS ARRAY AND FUNCTION SET IS FOR THE ROLLOVERS FOR ALL OF THE NAVIGATION SECTIONS

ver4 = (document.layers || document.all) ? 1 : 0;
 
 if (document.images) {
  navImageSrc = new Array (
		"gs_leftnav_professionaldevelopment_off.gif",
		"gs_leftnav_professionaldevelopment_on.gif",
		"gs_leftnav_research_off.gif",
		"gs_leftnav_research_on.gif",
		"gs_leftnav_grants_off.gif",
		"gs_leftnav_grants_on.gif",
		"gs_topnav_about_off.gif",
		"gs_topnav_about_on.gif",
		"gs_topnav_customer_off.gif",
		"gs_topnav_customer_on.gif",
		"gs_topnav_home_off.gif",
		"gs_topnav_home_on.gif",
		"gs_topnav_products_off.gif",
		"gs_topnav_products_on.gif"
		)
  navImageList = new Array ();
  for (counter in navImageSrc) {
   navImageList[counter] = new Image();
   navImageList[counter].src = "/GreatSource/images/" + navImageSrc[counter];
  }
 }
 
 function navRollOver(imName,over) {
  if (!document.images) {
   return
  }
  
  whichIm = document.images[imName];
  
  if (over) {
   whichIm.src = "/GreatSource/images/gs_topnav_" + imName + "_on.gif"
  } else {
   whichIm.src = "/GreatSource/images/gs_topnav_" + imName + "_off.gif"
  }
 }

 
 function leftnavRollOver(imName,over) {
  if (!document.images) {
   return
  }
  
  whichIm = document.images[imName];
  
  if (over) {
   whichIm.src = "/GreatSource/images/gs_leftnav_" + imName + "_on.gif"
  } else {
   whichIm.src = "/GreatSource/images/gs_leftnav_" + imName + "_off.gif"
  }
 }

 function tabRollOver(imName,over) {
  if (!document.images) {
   return
  }
  
  whichIm = document.images[imName];
  
  if (over) {
   whichIm.src = "/GreatSource/images/tabs/" + imName + "_over.gif"
  } else {
   whichIm.src = "/GreatSource/images/tabs/" + imName + "_off.gif"
  }
 }

// FUNCTION TO WRITE YEAR
function writeYear() {
var time=new Date();
var year=time.getYear();
if (year < 2000)    
year = year + 1900; 
document.write(year);
}

// FUNCTION TO DELETE COOKIES WRITTEN AT LOGIN - NEEDS TO HAVE cookies.js LOADED
// created by Tom Flaherty 11/09/2007
function submitLogout() {
	var Cookie1 = "ERIGHTS"  
	var Cookie2 = "ERIGHTSUSER"  
	if (!getCookieValue (Cookie1) && !getCookieValue (Cookie2)) {
		alert ('Cookie does not exist')
	}
	else {
		deleteCookie (Cookie1);
		deleteCookie (Cookie2);
		alert ("You have been logged out.");
    }
}
// FUNCTION TO SHOW EITHER LOGIN OR LOGOUT LINKS WITHIN STATIC HTML PAGES - NEEDS TO HAVE cookies.js LOADED
// created by Tom Flaherty 11/09/2007
function loginLogout() {
	var myCookieName = "ERIGHTS"
	if (getCookieValue (myCookieName)) {
		document.write ("<a href=\"/emeta/LogoutController?targeturl=/store/ProductCatalog/webdocs/GreatSource/logoff.jsp&amp;errorurl=/store/CustomerProfileController?cmd=LP&amp;nextPage=GreatSource/MyAccount.jsp&d&amp;ivision=G01\"><img src=\"/GreatSource/images/midbar_logout.gif\" alt=\"Logout\" border=\"0\"><\/a>")
	}
	else {
		document.write  ("<a href=\"/store/CustomerProfileController?cmd=LP&nextPage=GreatSource/MyAccount.jsp&amp;division=G01\" class=\"gstopblack11text\"><img src=\"/GreatSource/images/midbar_login.gif\" alt=\"Login/Register\" border=\"0\"><\/a>");
	}
}


// JAVASCRIPT TO SHOW AND HIDE LAYERS
// IF LAYER IS TO BE HIDDEN ON LOAD THEN THE DIV'S ATTRIBUTE NEEDS TO BE  
// STYLE="DISPLAY: NONE"
// DIV MUST ALSO HAVE A UNIQUE ID

function HideContent(d) {
	document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
	document.getElementById(d).style.display = "inline";
}
function ReverseContentDisplay(d) {
	if(document.getElementById(d).style.display == "none") { 
		document.getElementById(d).style.display = ""; 
		}
	else { 
		document.getElementById(d).style.display = "none"; 
		}
}

// FUNCTION FOR POP-UP WINDOWS
function openPopup(url,w,h) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
	if(url.indexOf('/GreatSource') != -1) {
		popupwin=window.open(url, 'Popup', 'width='+w+',height='+h+',scrollbars=yes,toolbar=no,menubar=no,location=no,titlebar=no,left='+winl+',top='+wint+',screenX='+winl+',screenY='+wint+',resizable=yes,alwaysRaised=yes');
  	} 
  	else if(url.indexOf('/professionaldevelopment') != -1) {
		popupwin=window.open(url, 'Popup', 'width='+w+',height='+h+',scrollbars=yes,toolbar=no,menubar=no,location=no,titlebar=no,left='+winl+',top='+wint+',screenX='+winl+',screenY='+wint+',resizable=yes,alwaysRaised=yes');
  	} 
  	else 
  	{
		popupwin=window.open(url, 'Popup', 'width='+w+',height='+h+',scrollbars=yes,toolbar=yes,menubar=yes,location=yes,titlebar=yes,left='+winl+',top='+wint+',screenX='+winl+',screenY='+wint+',resizable=yes,alwaysRaised=yes');
  	}
  popupwin.focus();
}

// FUNCTION FOR DISPLAYING THE CORRECT VERSION OF THE VIRTUAL CATALOG BASED ON SCREEN RESOLUTION
function launchVirtualCatalog(theURL,winName) { //v2.0

if (screen.width <= 800) {
	theURL ="/GreatSource/virtual/flipbook800.html" 
	} 
else
	{
		theURL = "/GreatSource/virtual/flipbook1024.html"
	}
	window.open(theURL,winName,"width=1004,height=670,resizable=no scrollbars=no status=no ");
}


// LOAD PAGE INTO PARENT WINDOW
// Version 1.0
// Last Updated: May 18, 2000
// Code maintained at: http://www.moock.org/webdesign/javascript/
// Copy permission granted any use provided this notice is unaltered.
// Written by Colin Moock.


function loadinparent(url, closeSelf){
	self.opener.location = url;
	if(closeSelf) self.close();
	}


function goToSelectedLocation(dropDownName) {
	var formDropDown = eval("document.statesMenu." + dropDownName);
	var formValue = formDropDown.options[formDropDown.selectedIndex].value;
	var locationValue = formValue;
	var islocationvalueok=locationValue.indexOf("http://");
	if(dropDownName=="state" && islocationvalueok != -1){
		window.open(locationValue,"_blank","resizable=no,scrollbars=no,status=no");
	} else {
		document.location.href="http://www.greatsource.com" + locationValue;
	}
}

function writeDate() {
	var months=new Array(13);
	months[1]="1";
	months[2]="2";
	months[3]="3";
	months[4]="4";
	months[5]="5";
	months[6]="6";
	months[7]="7";
	months[8]="8";
	months[9]="9";
	months[10]="10";
	months[11]="11";
	months[12]="12";
	var time=new Date();
	var lmonth=months[time.getMonth() + 1];
	var date=time.getDate();
	var year=time.getYear();
	if (year < 2000)    
	year = year + 1900; 
	document.write(lmonth + "/" + date + "/" + year);
}

function writeYear() {
	var time=new Date();
	var year=time.getYear();
	if (year < 2000)    
	year = year + 1900; 
	document.write(year);
}

function formHandler(formName){
	var url = document.stateForm.state.options[document.stateForm.state.selectedIndex].value;
	if (url != ""){
		window.location.href = url;
	}
}


function openCatalog(theURL,winName) { //v2.0
	if (screen.width <= 800)
		{
			theURL = "/GreatSource/virtualpages/catalog/flipbook800.html" 
		}
	else {
			theURL = "/GreatSource/virtualpages/catalog/flipbook1024.html"
		}
	window.open(theURL,winName,"width=1004,height=670,resizable=no,scrollbars=no,status=no ");
}

// get a random number to display random images for non flash users
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
/* begin test for Flash 6 or greater*/
var showFlash;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

showFlash = false;

// begin Non-IE Test for Flash
if (plugin) {
	whichPlugin = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));
	if (whichPlugin >= 6) {
  		showFlash = true;
	} else {
  		showFlash = false;
	}
}
// end Non-IE Test for Flash

/* end test for Flash 6 or greater */

function homepageFlash() { //v2.0
	var flashSWF = "/GreatSource/flash/swf/gs_home_";
	var flashFileURL = flashSWF + getRandomNum(1,6) + ".swf";
	//alert(flashFileURL);
	if (showFlash) {
		document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"184\" height=\"248\"><param name=\"movie\" value=" + flashFileURL + "><param name=\"quality\" value=\"high\"><embed src=" + flashFileURL + " quality=\"high\" width=\"184\" height=\"248\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"><\/embed><\/object>");
	} else {
		document.write("<img src=\"/GreatSource/flash/jpg/gs_home_");
		document.write(getRandomNum(1,6));
		document.write(".jpg\" width=\"194\" height=\"248\" alt=\"Effective Affortable Student-friendly Research-based Materials\" />");
	}
}


// SEARCH 

function setFocus(formName,inputFieldName) {
	if(document.layers) {
		var inputField = eval("document." + formName + "." + inputFieldName);
		inputField.focus();
	} else if (document.all) {
		var inputField = eval("document.all['" + formName + "']." + inputFieldName);
		inputField.focus();
	} else {
		var inputField = eval("document.getElementById('" + formName + "')." + inputFieldName);
		inputField.focus();
	}

}

function clearForm() {
	document.topForm.txtTitle.value="";
}
								
function clearOrderForm(formName,inputFieldName) {
	if(document.layers) {
		var inputField = eval("document." + formName + "." + inputFieldName);
	} else if (document.all) {
		var inputField = eval("document.all['" + formName + "']." + inputFieldName);
	} else {
		var inputField = eval("document.getElementById('" + formName + "')." + inputFieldName);
	}
  	var i;
  	for (i = 0; i < inputField.length; i++) {
    	inputField[i].value = "";
    }
}

