// Script for NASA Knights
//This script check to see if a browser supports the Document Object Model and MSIE Object Model
function browserCheck() {
	ua = navigator.userAgent.toLowerCase();
	this.dom = (document.getElementById && document.getElementsByTagName && document.getElementsByName) ? true : false;
	this.ie = (this.dom && document.all) ? true : false;
	this.ns = (!this.dom && document.layers) ? true : false;
	this.opera = (ua.indexOf("opera") != -1) ? true : false;
	this.msnTV = ((ua.indexOf('webtv') != -1) || (ua.indexOf('msntv') != -1)) ? true : false;
	this.other = (!this.dom && !this.ie && !this.ns) ? true : false;
	this.bad = (this.ns || this.other) ? true : false;
	this.moz = (this.dom && !this.ie) ? true : false;
	this.apple = ((ua.indexOf("apple") != -1) || (ua.indexOf("mac") != -1)) ? true : false;
	this.current = !this.bad;
}
browserIs = new browserCheck();

//There are some browsers that do not completely support these object models, they are consider bad
//and are directed to another webpage
if (browserIs.bad) {
	//location.href = "index02.html";
}
function setVis(objId,t) {
//setVis(id name, boolean true or false)
	if (t == null || t) {
		v = (browserIs.ns) ? "show" : "visible";
	} else {
		v = "hidden";
	}
	if (browserIs.dom) {
		a = document.getElementById(objId);
//	alert(objId + " | " + v);
		a.style.visibility = v;
	} else if (browserIs.ns) {
		document.layers[objId].visibility = v;
	}	
}
//--COOKIES---------------------------------------------------------
//--NS4, MSIE, DOM--
function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null || hours != undefined)  // if hours is null then cookie is a session cookie - stays as long as browser is working
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function readCookie(name) {
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0) { 
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
				if (end == -1) end = document.cookie.length;
					cookieValue = unescape(document.cookie.substring(offset, end)) 
			}
	}  
	return cookieValue;
}
//--------MAILTO DECODER--------------------------------
function makemail(mTo,mtDm,mType, ccTo,ccDm, cType, subJct, txTs) {
  if (mTo.length > 0) {
	  mTo = dCode(mTo);
	  mtDm = dCode(mtDm);
	  toType = addType(mType);
    mtoAdr = mTo + "@" + mtDm + toType;
		mailAdr = "mailto:" + mtoAdr;
	}

  if (ccTo != null && ccTo.length > 1) {
	  ccTo = dCode(ccTo);
	  ccDm = dCode(ccDm);
	  toType = addType(cType);
		cctoAdr = "?cc=" + ccTo + "@" + ccDm + toType;
		mailAdr += cctoAdr;
  }
  if (subJct != null ) {
	  if (ccTo == null || ccTo == "") {
		  mailAdr += ("?subject=" + subJct);
		} else {
  	  mailAdr += ("&subject=" + subJct);
		}
	}
	if ((subJct != "" && (!(txTs == null || txTs == "")))) {
	  mailAdr += "&body=" + txTs;
	}
	
  window.location = unescape(mailAdr);
//alert(unescape(mailAdr));
  return;
}

function dCode(eCode) {
	xCode = new String;
	if (eCode.indexOf("%") == -1 && (eCode.charAt(0)>=0 && eCode.charAt(0)<=9)) {
		aCode = new String();
		xLngth = eCode.length;
		for (i=0; i<=xLngth-1 ;i=i+2) {
				aCode = "%" + eCode.charAt(i) + eCode.charAt(i+1);
				xCode += aCode;
		} // End For
	} else {
		xCode = eCode;
	} //End If
	return xCode;
//return (typeof xCode != "undefined") ? xCode : eCode;
}// End Function

function addType(i) {
  switch (i) {
    case "1" :
	    tyPe = ".com"
  		break;
  	case "2" :
  	  tyPe = ".net"
  		break;
  	case "3" :
  	  tyPe = ".edu"
  		break;
    case "4" :
      tyPe = ".mil"
        break;
    case "5" :
      tyPe = ".org"
        break;
    case "6" :
      tyPe = ".biz"
        break;
	case "7" :
		tyPe = ".us"
		break;
	case "8" :
		tyPe = ".gov"
		break;
	default :
		tyPe = ""
		break;
  }
return tyPe;
}
//--NEW WINDOW-------------------------------------------------------------
//--NS4, MSIE, DOM--
function newWindow() { //v2.0 (url, window name [, width, height])
	aL = arguments.length;
	aA = arguments;
	theURL = aA[0];
	winName = aA[1];
	if (isNaN(aA[2]) == false && isNaN(aA[3]) == false) {
 		var newFeatures = "location=yes,status=yes,menubar=yes,toolbar=yes,directories=yes,scrollbars=yes,resizable=yes,width=" + aA[2] + ",height=" + aA[3] + ",left=20,right=20";
	} else {
		if (document.compatMode && document.compatMode != "BackCompat") {
		   aWidth = document.documentElement.offsetWidth;
		   aHeight = document.documentElement.offsetHeight;
		} else {
		   aWidth = document.body.offsetWidth;
		   aHeight = document.body.offsetHeight;
		}
		var newFeatures = "location=yes,status=yes,menubar=yes,toolbar=yes,directories=yes,scrollbars=yes,resizable=yes, width=" + aWidth + ",height=" + aHeight + ",left=20,right=20";
//		var newFeatures = "location=yes,status=yes,menubar=yes,toolbar=yes,directories=yes,scrollbars=yes,resizable=yes";
	}
	miniwindi = window.open(theURL,winName,newFeatures);
	miniwindi.focus();
	return false;
}
//--STATUS BAR MESSAGE-------------------------------------------------
//--NS4, MSIE, DOM--
function setStatusBar(msgStr) { self.status = msgStr; }
