// Software Technology, Inc.

/*
	Most of these functions control the operations of the STI Library web site,
 	however, some functions may be added later which may be useful	elsewhere 
	and can be used by including the following line in the head of an
   html document:
 		<script language="javascript" src="scripts.js"></script>
*/

function loadArticleID(id) {
   top.frmTopic.location = id + ".htm"
}

// load page into frmApplet frame if necessary & change tab images
function loadFrmApplet(desc, page) {
	// do not change applet frame if already displaying correct page
	if (top.frmApplet.location.pathname.indexOf(page)  <  0)
		top.frmApplet.location = page

	if ((desc == "Content") && (top.frmTab.document.images[0].src != "content1.gif")) {
		setTimeout('top.frmTab.document.images[0].src = "content1.gif"',100)
		setTimeout('top.frmTab.document.images[1].src = "content2.gif"',100)
		setTimeout('top.frmTab.document.images[2].src = "content3.gif"',100)
	}
	else if ((desc == "Index") && (top.frmTab.document.images[1].src != "index2.gif")){
		setTimeout('top.frmTab.document.images[1].src = "index2.gif"',100)
		setTimeout('top.frmTab.document.images[0].src = "index1.gif"',100)
		setTimeout('top.frmTab.document.images[2].src = "index3.gif"',100)
	}
	else if ((desc == "Search") && (top.frmTab.document.images[2].src != "search3.gif")){
		setTimeout('top.frmTab.document.images[2].src = "search3.gif"',100)
		setTimeout('top.frmTab.document.images[0].src = "search1.gif"',100)
		setTimeout('top.frmTab.document.images[1].src = "search2.gif"',100)
	}
   return true
}


// syncronize frmTab with frmApplet frame
function syncTabs(tab, page) {
	loadFrmApplet(tab, page)
}


// cannot resize the java applet in Netscape, must reload
function resizeApplet()
{
	top.frmTab.location.reload()
	top.frmApplet.location.reload()
	return true
}


// reset tabs if resizing search page in Netscape
function resetSearch()
{
	if (!msieversion()){
 		top.frmTab.location.reload()
   	setTimeout('top.frmTab.document.images[2].src = "search3.gif"',250)
		setTimeout('top.frmTab.document.images[0].src = "search1.gif"',100)
		setTimeout('top.frmTab.document.images[1].src = "search2.gif"',100)
   }
}


// return version of IE or zero if not IE
function msieversion()
{
	ua = window.navigator.userAgent
	msie = ua.indexOf("MSIE ")
	if (msie > 0) {
		// is Microsoft Internet Explorer; return version number
		return(parseInt(ua.substring(msie+5,ua.indexOf(".", msie))))
	}
	// is other browser
	return(0)
}


// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// bracketed items need not be specified if using defaults
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	 		((expires) ? "; expires=" + expires.toGMTString() : "") +
         ((path) ? "; path=" + path : "") +
         ((domain) ? "; domain=" + domain : "") +
         ((secure) ? "; secure" : "")
	if ((name + "=" + escape(value)).length <= 4000)
      document.cookie = curCookie
   else if (confirm("Cookie exceeds 4KB and will be cut!"))
      document.cookie = curCookie
}


// name - name of the desired cookie
// return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
	var prefix = name + "="
   var cookieStartIndex = document.cookie.indexOf(prefix)
   if (cookieStartIndex == -1)
		return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}


// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
   	document.cookie = name + "=" +
   		   ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}


// load page into browser window
function redirect(page) {
	window.location = page;
}


// change to url in time (milliseconds)
function delayToPage(url,time) {
	page = url
	timer = setTimeout('redirect(page)', time);
}
