
// global variable definitions
var is = new Is();


// this function is a browser sniffer.	based on the return values it can
// determine what functions are available based on the DOM model and browser
function Is() {
    var agent	= navigator.userAgent.toLowerCase();
    this.major	= parseInt(navigator.appVersion);
    this.minor	= parseFloat(navigator.appVersion);

    this.opera	= ((agent.indexOf("opera") != -1)  && (this.major >= 5));

    this.ns	= ((agent.indexOf("mozilla")   != -1) &&
		  (agent.indexOf("spoofer")    == -1) &&
		  (agent.indexOf("compatible") == -1) &&
		  (agent.indexOf("webtv")      == -1) &&
		  (agent.indexOf("opera")      == -1));
    this.webtv	= (agent.indexOf("webtv")      != -1);
    this.ns4	= (this.ns && (this.major      ==  4));
    this.ns6	= (this.ns && (this.major      ==  5));
    this.ns6up	= (this.ns && (this.major      >=  5));

    this.ie	= (agent.indexOf("msie")       != -1);
    this.ie3	= (this.ie && (this.major      <   4));
    this.ie4	= (this.ie && (this.major >= 4));
    this.ie5	= (this.ie && (this.major == 4) && (agent.indexOf("msie 5.") != -1));
    this.ie6	= (this.ie && (this.major == 4) && (agent.indexOf("msie 6.") != -1));
    this.ie5up	= (this.ie && (this.major >= 4));

    this.gecko	= (agent.indexOf("gecko") != -1);
    this.modern = (this.ie5up || this.ns6up || this.opera );
    this.old	= !(this.modern);
}



// simple function to return the current date in the format MMM DD, YYYY
function CurrentDate() {
     var mydate = new Date();
     return MakeDateStr(mydate);
}


function MakeDateStr(date) {
 var months = new Array("January", "February", "March",     "April",
			"May",	   "June",     "July",	    "August",
			"September","October", "November", "December");
 return months[date.getMonth()] + " " +
	 date.getDate() + ", " +
	 date.getFullYear();
}

function locateObject(n, d) { //v3.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=locateObject(n,d.layers[i].document);
  return x;
}

function InitializePanel(ptitle)
{
       if (ptitle == "*dynamic*") {
	    ptitle = GetCookie('title');
	    document.title = "Ross's Chip Collection - "+ ptitle;
       }

       if (is.modern)	 locateObject('PanelTitle').innerText = ptitle;
       else if (is.ns4) {
	    document.lyr1.layers["nsTitleBox"].document.open();
	    document.lyr1.layers["nsTitleBox"].document.write(ptitle);
	    document.lyr1.layers["nsTitleBox"].document.close();
       }

       MakeMargin();

}

// this figures out the page width and can set the margin to center a page.
function MakeMargin()
{
  var PageWidth = 800;
  var StartMargin = 0;
  var BrowserWidth = 0;

  if (is.ie5up)   BrowserWidth = document.body.clientWidth;
  else if (is.ns4 || is.ns6)   BrowserWidth = window.innerWidth;
  else if (is.opera)	       BrowserWidth = window.innerWidth;
  else			       BrowserWidth = PageWidth;

  if (BrowserWidth > PageWidth)
     StartMargin = (BrowserWidth-PageWidth)/2;

  if (is.modern)   document.body.style.marginLeft = StartMargin;
  else if (is.ns4)	  { /* not supported right now */ }
  else			  { /* not supported right now */ }
}

function resize()
{
    if(is.ns4 ||is.modern ) {
		history.go(0);
	}
}

function over_effect(e,state)
{
	 if (is.ie4||is.ns6||is.ie5up)	 source4=event.srcElement
	 else if (document.getElementById)
	      source4=e.target;

	 if (source4.className=="menulines")
	    source4.style.borderStyle=state
	 else{
	      while(source4.tagName!="TABLE"){
		 source4=document.getElementById? source4.parentNode : source4.parentElement
		 if (source4.className=="menulines")
		    source4.style.borderStyle=state
	      }
	 }
}

function AddNSTitle(ptitle) {
       if (is.ns4) {
	    document.lyr1.layers["nsTitleBox"].document.open();
	    document.lyr1.layers["nsTitleBox"].document.write("<strong><span style='background-color: #C0C0C0; width: 200; letter-spacing: 2pt'>"+ptitle+"</span></strong>");
	    document.lyr1.layers["nsTitleBox"].document.close();
       }
}

function MakePage(ptitle, pmenu, plegend)
{
     // set a cookie on the user's machine to store this temporarily
     // var mydate = new Date();
     // var pathname = location.pathname;
     // var domain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';

     // mydate.setTime(mydate.getTime() + (36000));
     SetCookie('title',ptitle);
     SetCookie('menu',pmenu);
     SetCookie('legend',plegend);

     // now load the page into the browser _top
     window.top.location.href = "chippage.shtml";
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = "/";     // (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" +
			  expires.toGMTString())) +

		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}

function getCookieVal (offset)
{
 var endstr = document.cookie.indexOf (";", offset);
 if (endstr == -1)
    endstr = document.cookie.length;
 return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 while (i < clen) {
       var j = i + alen;
       if (document.cookie.substring(i, j) == arg)
	  return getCookieVal (j);
       i = document.cookie.indexOf(" ", i) + 1;
       if (i == 0) break;
 }
 return null;
}

