/* Preload the images for close i-icon button */
/*
*	Hacked to work outside of cnams by Joshua Eichorn <jeichorn@cisco.com> 9-25-2002
*/
var imgIicon_close = new Image();
imgIicon_close.src = "/images/btn_iicon_close.gif";

/*
 * Filename: global.js
 * This file contains javascript functionality that are used throughout the CNAMS site.
 * This functionality includes:
 *	- Checking the browser and linking to the appropriate css file.
 *	- Workaround for Netscape 4 window resize bug.
 *	- Function for a small popup window
 *	- Function to do a custom form action
 *	- Functions to select/deselect all checkboxes
*/


// *** Start: Code for checking which CSS file to use ***
// get platform and browser versions
var platform = navigator.platform.substr(0,3);
var browserName = navigator.appName;
var browserVer;

//for IE 5, the first number in "navigator.appVersion" is 4.0, so need to parse the string further 
if (navigator.appVersion.indexOf('MSIE 5') != -1) {
	browserVer=5;
}
else {
	browserVer = parseInt(navigator.appVersion);
}

// Platform is Windows
if (platform=="Win") {

	//Netscape 4 on Windows
	if ((browserName=="Netscape") && (browserVer <=4)) {	
		document.write('<link rel="stylesheet" type="text/css" href="/css/pc_ns_en.css" >');
	}
	//IE, NS6, (or any other browsers) on Windows 
	else {
		document.write('<link rel="stylesheet" type="text/css" href="/css/pc_ie_en.css" >');
	}
} 
	
// Platform is Macintosh
else if (platform=="Mac") {

	//IE5 or NS6 on Mac
	if (browserVer >=5) {
		document.write('<link rel="stylesheet" type="text/css" href="/css/pc_ie_en.css" >');
	}
		
	//Netscape 4, IE4, and all other browsers on Mac
	else {
		document.write('<link rel="stylesheet" type="text/css" href="/css/pc_ie_en.css" >');
	}
} 

// All other platforms
else {
	document.write('<link rel="stylesheet" type="text/css" href="/css/pc_ie_en.css" >');
}

// *** End: Code for checking which CSS file to use ***


// *** START: Code for Netscape 4 Resize bug ***
// This is a workaround for a Netscape 4 bug that causes 
// stylesheets to be corrupted when the window is resized.
if (document.layers) {
	var widthCheck = window.innerWidth;
	var heightCheck = window.innerHeight;
	window.onResize = resizeFix;
}

function resizeFix() {
	if (widthCheck != window.innerWidth || heightCheck != window.innerHeight)
	history.go(0);
}

// *** End: Code for Netscape 4 Resize bug ***


// *** START: Code for Opening a new browser popup window ***
// This function is used to open a new small browser window. 
// USAGE: 
//    <a href="javascript:openPopupWin('viewcurriculluminfo.shtml');">View Curriculum Information</a>
//
function openPopupWin(URL) {
	newPopupWin = window.open(URL,'popup','width=643,height=468,scrollbars');
	newPopupWin.focus();

}
// *** End: Code for Opening a new browser popup window ***


// *** START: Code for Opening a new browser window without browser controls that fills up the whole screen ***
// This function is used to open a new browser window which fills up the whole screen area, mostly used in the exam activation module
// USAGE: 
//    <a href="javascript:openFullScreenWin('http://www.yahoo.com');">Open Yahoo! in a new window</a>
//
function openFullScreenWin(url) {
	windowWidth = screen.width - 9;
	windowHeight = screen.height - 58;
	
	windowprops = "scrollbars,top=0,left=0,width=" + windowWidth + ",height=" + windowHeight;
	myNewWin = window.open(url, "popupPage", windowprops);
	myNewWin.focus();	
}
// *** End: Code for Opening a new browser window without browser controls that fills up the whole screen ***

// *** START: Code for Opening a new browser window for the About This Page content ***
// This function is used to open a new browser window which fills up the whole screen area, mostly used in the exam activation module
// USAGE: 
//    <a href="javascript:openAboutWin('http://www.yahoo.com');">About This Page</a>
//
function openAboutWin(url) {
	aboutWin = window.open(url, "popupPage", "scrollbars,width=460,height=500");
	aboutWin.focus();	
}
// *** End: Code for Opening a new browser window for the About This Page content ***


// *** START: Custom form action function ***
// This function is used to change the action URL ('theUrl') for 'theForm'. 
// It is used on pages where there is one form, but different buttons trigger different actions. 
// Arguments: 'theForm' is the name of the form containing the buttons.
//			  'the Url' is the URL of the action template associated with the button.
// USAGE: 
//    <input type="button" name="cancel2" value="Cancel" class="button" onClick="doFormAction('contactFrm','contacts.jhtml');" />
//
function doFormAction(theForm, theUrl) {
	eval('document.' + theForm + '.action=\"' + theUrl + '\"');
	eval('document.' + theForm + '.submit()');
	}
// *** END: Custom form action function ***

// *** START: Functions to select/deselect all checkboxes ***
// This function is used to check or uncheck all the checkboxes names of which are provided in an array
// Arguments: 'formname' is the name of the form containing the buttons.
//	      
// USAGE: 
//    
//

function SelectAll(formName,getArr,whattodo) {
	getArr = eval(getArr);
	
	if (whattodo == "check") {
		for (var i=0;i<getArr.length;i++) {
		myBox = getArr[i];
		var e = eval("document." + formName + "." + myBox);
		e.checked = true;
		}
	}
	else {
		for (var i=0;i<getArr.length;i++) {
		myBox = getArr[i];
		var e = eval("document." + formName + "." + myBox);
		e.checked = false;
	}			
}
}
// *** END: Functions to select/deselect all checkboxes ***

// *** START: Second set of functions to select/deselect all checkboxes ***
// This function is used to check or uncheck all the checkboxes having the same name but diff values
// Arguments:'formname' is the name of the form containing the buttons.
//		'chkset' is the name of the checkboxes you want to modify the state of
//		'whattodo' tells the function whether to check or uncheck the set of checkboxes
// USAGE: 
//    <a href="javascript:SelectAllSame('myform1','chk1','check');">Select All</a><img src="/cnamsassets/images/common/spacer.gif" width="10" height="1" alt="" border="0" /><a href="javascript:SelectAllSame('myform1','chk1','uncheck');">Deselect All</a>
//

function SelectAllSame(formName,chkset,whattodo) {
	count = 0;
	if(eval("document." + formName + "." + chkset)) {
	if(eval("document." + formName + "." + chkset + ".length"))
	{
		count = eval("document." + formName + "." + chkset + ".length");
		}
	else		
	{
	if (whattodo == "check") {
		eval("document." + formName + "." + chkset + ".checked = true");
		return;
	}
	else
	{
		eval("document." + formName + "." + chkset + ".checked = false");
		return;	
	}
	}	
	}
	if (whattodo == "check") {
		for (var i=0;i<count;i++) {
		var e = eval("document." + formName + "." + chkset + "[" + i + "]");
		e.checked = true;
		}
	}
	else {
		for (var i=0;i<count;i++) {
		var e = eval("document." + formName + "." + chkset + "[" + i + "]");
		e.checked = false;
	}
}
}
// *** END: Functions to select/deselect all checkboxes ***


// Stuff from cisco.netacad.net on 9/30/2002

// Area drop-down redirection
var areanav_current = 0;
function set_areanav_current( index ) {
	// xsl position starts at 1, array index starts at 0
	areanav_current = index-1;
}
function areanav_redirect(select_name) {	
  var theselect=eval(select_name);
  var tmp=theselect.selectedIndex;
  if(theselect.options[tmp].value != "") {
	 theselect.options[areanav_current].selected=true;
	 location.href=get_baseTag()+theselect.options[tmp].value;
  }
}

// Rollover Images
function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Get the BaseTag, if specified in the current page
function get_baseTag() {
	var baseTag = "";
	if ( document.all ) {	
		var baseTagsCol = document.all.tags("BASE");
		if (baseTagsCol.length!=0){
			baseTag = baseTagsCol[0].href;
		}
	} else if (window.opera) {
		var baseTag
		if (document.getElementById('basehref')){
			baseTag = document.getElementById('basehref').href;
			baseTag = baseTag.substring(0, baseTag.length-1);
		}
	}
	return baseTag;
}

/**
 *  Sitewide Tools Rollover Functions
 *  sitewide_tools.js
 *
 */
 
// Window opening script for Sitewide Toolkit only
function sitewide_toolkit_window(url,winName) {
	if(!winName) { winName = "swtwin"; }
	var swtwin = window.open(url, winName, 'width=614,height=400,top=50,left=50,resizable=1,scrollbars=1,toolbar=0,menubar=1,status=1');
	swtwin.focus();
	}

var Imgs = new Array();

function precache_imgs( theimgs ) {

	for(var i=0; i<theimgs.length; i++) {
		var j = Imgs.length;
		var tmp = { id: theimgs[i], on:null,off:null,text:null }
		tmp.on = new Image(); tmp.on.src = "/images/sitewide_"+theimgs[i]+"_on.gif";
		tmp.off = new Image(); tmp.off.src = "/images/sitewide_"+theimgs[i]+"_off.gif";
		tmp.text = new Image(); tmp.text.src = "/images/sitewide_"+theimgs[i]+"_text.gif";
		Imgs[j] = tmp;
	}
}

// called on mouseover, swaps icon and site_wide_text.gif images 
function img_over( name ) {

	var img = null;
	for(var i=0; i<Imgs.length; i++) {
		if( Imgs[i].id == name ) {
			img = Imgs[i]
		}
	}
	if( img != null ) {
		document.images[ name+"img" ].src = img.on.src;
		document.images[ "sitewide_text" ].src = img.text.src;
	}
}

// called on mouseout, Replaces icon and site_wide_text.gif images 
function img_out( name ) {
	var img = null;
	for(var i=0; i<Imgs.length; i++) {
		if( Imgs[i].id == name ) {
			img = Imgs[i]
		}
	}
	if( img != null ) {
		document.images[ name+"img" ].src = img.off.src;
		document.images[ "sitewide_text" ].src = "/images/sitewide_text_start.gif"; 
	}
}

// Print Function

function printit(){  
if (window.print) {
    window.print() ;  
} else {
    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
    WebBrowser1.ExecWB(6, 2);
// Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
}
}

// POP UP A PREFORMATTED EMAIL MESSAGE WINDOW
function sitewide_email_this_page() {
  // SET MESSAGE VALUES
  var to = "";
//  var cc = "";
//  var bcc = "";
//  var subject = "";
  var body = document.location.href
  // BUILD MAIL MESSAGE COMPONENTS 
  var doc = "mailto:" + to + "?" +
 //     "cc=" + cc + "&" +
 //     "bcc=" + bcc + "&" +
 //     "subject=" + escape(subject) + "&" +
      "body=" + escape(body); 
  // POP UP EMAIL MESSAGE WINDOW
  window.location.href = doc;
}

function openLargePopup( url, windowname ) {
	var popup = window.open( url , windowname, "toolbar=yes,status=yes,scrollbars=yes,menubar=yes,locationbar=no,top=50,left=70,outerWidth=643,outerHeight=468,width=643,height=468,resizable=yes");
	popup.focus();
}

function openMediumPopup( url, windowname ) {
	var popup = window.open( url , windowname, "toolbar=no,status=yes,scrollbars=yes,menubar=no,locationbar=no,top=90,left=170,outerWidth=445,outerHeight=390,width=445,height=390,resizable=yes");
	popup.focus();
}

function openSmallPopup( popupurl, windowname ) {
	var popup = window.open( url , windowname, "toolbar=no,status=yes,scrollbars=yes,menubar=no,locationbar=no,top=90,left=290,outerWidth=220,outerHeight=390,width=220,height=390,resizable=yes");
	popup.focus();
}




var tmp = new Array(
            "bookmark", "email",  "print",  "glossary", "download"
          );
precache_imgs( tmp );

function confirmLink(theLink, message)
{
	var is_confirmed = confirm(message);
        if (is_confirmed) {
		theLink.href += '&is_js_confirmed=1';
	}

	return is_confirmed;
} // end of the 'confirmLink()' function

