// =========================================
// general functions used throughout the 
// site
// =========================================


// =========================================
// image flip script (on):
// =========================================
function imgAct(imgName) {
    if (document.images) {
    document[imgName].src = eval(imgName + "on.src");
    }
}

// =========================================
// image flip script (off):
// =========================================
function imgInact(imgName) {
    if (document.images) {
    document[imgName].src = eval(imgName + "off.src");
    }
}

// =========================================
// generic window opener variables:
// mypage: url to page
// w: width
// h: height
// s: scrollbars? (yes/no)
// n: window name
// =========================================
function PopWin ( mypage, w, h, s, n ) {

	var winl = ( screen.width - w ) / 2;
	var wint = ( screen.height - h - 50 ) / 2;
	winprops = 'width='+w+',height='+h+',top='+wint+',left='+winl+',scrollbars='+s+',resize=no'
	win = window.open ( mypage, n, winprops )
	if ( parseInt(navigator.appVersion) >= 4 ) { win.window.focus(); }

}

// =========================================
// use for spam countermeasures:
// =========================================
function Email ( sUser, sDomain, sSubject ) {
	var sString;
	sString = "mailto:" + sUser + "@" + sDomain;
	if ( sSubject.length > 0 )
	{
		sString += "?subject=" + sSubject;
	}
	window.location = sString;
}

// =========================================
// does drop down box redirection for
// the "Hot Topics" box
// =========================================
function processSelectChange(){
	var list = document.hottopfrm.hottop;
	var url = list.options[list.selectedIndex].value;
	if( url != null)
	document.location = url;
}


// =========================================
// function to get user browser and system
// information (some are IE only)
// portions from 
//		http://www.gemal.dk/browserspy/
// =========================================
var acrobatVersion = 0;
var b_vbcookies = false;
var iPlace;
var bString;
function getBrowserInfo ( usrFormFields, usrValues ) {

	var usrValArry = new Array();
	var usrFrmArry = new Array();
	var i,j, contents='', retVal='', tmpVal='', bwin = false;
	var sOS, plugin='', agent='', tmpBrowser='', tmpVersion='', rv='';
	usrFrmArry = usrFormFields.split(",");
	usrValArry = usrValues.split(",");

	if ( usrFrmArry.length == usrValArry.length ) {
		// lengths match, so go for it
		for (i=0; i<usrValArry.length; ++i ) {
			if (usrValArry[i]) {
				switch(usrValArry[i].toLowerCase()) {
					case "bname": (typeof(navigator.appName) != "undefined") ? retVal = navigator.appName : retVal = "not supported or blank";  break;
					case "bver": (typeof(navigator.appVersion) != "undefined") ? retVal = navigator.appVersion : retVal = "not supported or blank";  break;
					case "bminver": (typeof(navigator.appMinorVersion) != "undefined") ? retVal = navigator.appMinorVersion : retVal = "not supported or blank";  break;
					case "advbname":
						tmpBrowser = '';
						tmpVal = navigator.userAgent.toLowerCase();
						if (checkVal("konqueror",tmpVal)) {
							tmpBrowser = "Konqueror";
							sOS = "Linux";
						}
						else if (checkVal('safari',tmpVal)) tmpBrowser = "Safari";
						else if (checkVal('omniweb',tmpVal)) tmpBrowser = "OmniWeb";
						else if (checkVal('opera',tmpVal)) tmpBrowser = "Opera";
						else if (checkVal('webtv',tmpVal)) tmpBrowser = "WebTV";
						else if (checkVal('icab',tmpVal)) tmpBrowser = "iCab";
						else if (checkVal('msie',tmpVal)) tmpBrowser = "Internet Explorer";
						else if (checkVal('k-meleon',tmpVal)) {
							tmpBrowser = "K-Meleon";
							rv = tmpVal.match(/k-meleon ([\w.]+)/)[0];
							if (rv) { tmpVersion = rv.substr(9); }
						}
						else if (!checkVal('compatible',tmpVal)) {
							tmpBrowser = "Netscape Navigator";
							tmpVersion = tmpVal.charAt(8);
							if (typeof(navigator.product) != "undefined" && navigator.product && typeof(navigator.vendor) != "undefined" && navigator.vendor == "") {
								tmpBrowser = "Mozilla";
								rv = navigator.userAgent.match(/rv:([\w.]+)/)[0];
								tmpVersion = rv.substr(3);
							}
						}
						else tmpBrowser = "unknown browser";

						if (!tmpVersion) { tmpVersion = tmpVal.charAt(iPlace + bString.length); }
						if (tmpBrowser) { retVal = tmpBrowser; }
						if (tmpVersion) { retVal += " " + tmpVersion; }						
						if (!retVal) { retVal = "unable to detect"; }
						break;

					case "os":
						tmpVal = navigator.userAgent.toLowerCase();
						if (tmpVal.indexOf("win")!=-1 || tmpVal.indexOf("16bit")!=-1) {
							bwin = true;
						}
						if (bwin) {
							if (tmpVal.indexOf("win95")!=-1 || tmpVal.indexOf("windows 95")!=-1)
								retVal = "Windows 95";
							if (tmpVal.indexOf("win 9x 4.90")!=-1)
								retVal = "Windows ME";
							if (tmpVal.indexOf("winnt")!=-1 || tmpVal.indexOf("windows nt")!=-1)
								retVal = "Windows NT";
							if (tmpVal.indexOf("windows nt 5.0")!=-1)
								retVal = "Windows 2000";
							if (tmpVal.indexOf("windows nt 5.1")!=-1)
								retVal = "Windows XP";
							if (tmpVal.indexOf("win98")!=-1 || tmpVal.indexOf("windows 98")!=-1)
								retVal = "Windows 98";
							if (!retVal)
								retVal = "Unknown Windows";
						} else {
							retVal = "Unknown Windows";
						}
						break;
					case "cpu":
						tmpVal = navigator.cpuClass;
						switch (tmpVal) {
							case "x86" : retVal = tmpVal + ' - x86 Compatible processor (Intel, Cyrix, AMD, etc...)'; break;
							case "68K" : retVal = tmpVal + ' - Motorola processor'; break;
							case "Alpha" : retVal = tmpVal + ' - Digital processor'; break;
							case "PPC" : retVal = tmpVal + ' - Motorola processor'; break;
							case "Other" : retVal = tmpVal + ' - Other CPU classes, including Sun SPARC'; break;
						}
						break;
					case "acrobat":
						agent = navigator.userAgent.toLowerCase(); 
						// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Acrobat plugin in plugin array
						if (navigator.plugins != null && navigator.plugins.length > 0) {
							for (j=0; j < navigator.plugins.length; j++ ) {
								var plugin = navigator.plugins[j];
								if (plugin.name.indexOf("Adobe Acrobat") > -1) {
									acrobatVersion = parseFloat(plugin.description.substring(30));
								}
							}
						}
						// IE4+ Win32:  attempt to create an ActiveX object using VBScript
						else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
							document.write('<scr' + 'ipt language="VBScript"\> \n');
							document.write('on error resume next \n');
							document.write('dim obAcrobat \n');
							document.write('set obAcrobat = CreateObject("PDF.PdfCtrl.5") \n');
							document.write('if IsObject(obAcrobat) then \n');
							document.write('acrobatVersion = 5 \n');
							document.write('else set obAcrobat = CreateObject("PDF.PdfCtrl.1") end if \n');
							document.write('if acrobatVersion < 5 and IsObject(obAcrobat) then \n');
							document.write('acrobatVersion = 4 \n');
							document.write('end if');
							document.write('</scr' + 'ipt\> \n');
						}
						// Can't detect in all other cases
						else {
							acrobatVersion = "undetected or not installed";
						}
						retVal = acrobatVersion;
						break;
					case "cookies":
						var isCookies;
						var b_jscookies;
						agent = navigator.userAgent.toLowerCase();
						var cookiename = "js_detect_cookie_test";
						isCookies = navigator.cookieEnabled;
						document.cookie = cookiename;
						if (document.cookie.indexOf(cookiename) >= 0)
							b_jscookies = true;
						document.cookie = "";

						// check for session cookies with vbscript (IE4+):
						if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
							document.write('<scr' + 'ipt language="VBScript"\> \n');
							document.write('on error resume next \n');
							document.write('response.cookies("testcookie") = "test"\n');
							document.write('if response.cookies("testcookie") = "test" then \n');
							document.write('b_vbcookies = true \n');
							document.write('else b_vbcookies = false end if \n');
							document.write('response.cookies("testcookie").Expires = dateAdd("d",-1000,Date()) \n');
							document.write('</scr' + 'ipt\> \n');
						}
						retVal = "cookies enabled: " + isCookies + "; js cookies: " + b_jscookies + "; vbscript (non-server) cookies: " + b_vbcookies + "";
						break;
					case "resolution":
						retVal = screen.width + 'x' + screen.height;
						break;
					case "colordepth":
						retVal = screen.colorDepth;
						break;
					case "css":
						if (document.styleSheets) {
							retVal = "supported";
						}
						break;
					default: retVal = "undefined"; break;
				}
				contents += '<input type="hidden" name="'+ usrFrmArry[i] +'" value="' + retVal + '">';
			}			
		}
	}
	return contents;
}

function checkVal ( sString, sDetect ) {
	bString = sString;
	iPlace = sDetect.indexOf(sString) + 1;
	return iPlace;
}


function obj(o,ot) {
	if (ot) {
		if (typeof(o) == t) {
			return 1;
		} else {
			return 0;
		}
	} else {
		if (typeof(o) != "undefined") {
			return 1;
		} else {
			return 0;
		}
	}
}