/* my NEW common functions */
// <!-------------- This is the JSCOMMON.JS file --------------->
// <!-- stdbrowser refers to the standardized browser implementations: IE 5+, NS 6+, Opera 5+ -->
jsc_dbg=0;
ldbg=0;
layerref="";
styleref="";
stdbrowser=0;
firsttime=true;
asgnflg=0; // global initialization for CS205
newurl=""; //establish global name
isns=false; isns4=false; isie=false; isff=false; issafari=false;
browserbase=navigator.appName;
br="<br>";px="px";dq='"';sq="'";
ver=parseInt(navigator.appVersion.substr(0,3));
place=0;
DOM=0;
 if(jsc_dbg||ldbg)
   {
       dbgwin=window.open("","dbgwin","height=400,width=400,scrollbars=yes,resizable=yes");
       dbgwin.moveTo(550,280);
   }
var nav_user_agent = navigator.userAgent.toLowerCase();
var OS,browser,total,thestring;
var version = 0;

    if (checkstring('konqueror'))
    {
        browser = "Konqueror";
        OS = "Linux";
    }
    else if (checkstring('safari')) 
        {browser = "Safari"
         issafari=true;
        }
        else if (checkstring('omniweb')) browser = "OmniWeb";
            else if (checkstring('opera')) browser = "Opera";
                else if (checkstring('webtv')) browser = "WebTV";
                     else if (checkstring('icab')) browser = "iCab";
                          else if (pt=checkstring('firefox')) 
                                {
                                    browser = "firefox";
                                    place=pt /*76 */ ;
                                    isff=true;
                                }
                            else if (pt=checkstring('msie'))
                             { 
                                 browser = "IE";
                                 place=pt;
                                 isie=true;
                             }
                             else if (!checkstring('compatible'))
                                    {
                                        if(document.layers)
                                         {
                                            isns4=true;
                                            browser="Netscape 4";
                                         }
                                        else
                                         {
                                          browser = "Netscape Navigator"
                                          version = nav_user_agent.charAt(8);
                                          isns=true;
                                         }
                                    } 
                                  else
                                     browser = "An unknown browser";

if (!version) version = nav_user_agent.substr(place + thestring.length);
if(ldbg) 
    {   xx=window.open("","xx","height=100,width=200,scrollbars=yes,resizable=yes");
        xx.document.write("slen="+thestring.length+" version="+version+"<br>");
        xx.document.write("nav_user_agent="+nav_user_agent+", browser="+browser+
            " browserbase="+browserbase+"<br>");
            xx.document.close();
    }
if (!OS) // find out what OS we are on
{
	if (checkstring('linux')) OS = "Linux";
	else if (checkstring('x11')) OS = "Unix";
	    else if (checkstring('mac')) OS = "Mac"
            else if (checkstring('win')) OS = "Windows"
                else OS = "an unknown operating system";
}

function checkstring(string)
{   //look for the platform (win, linux, etc) or browser name
	p = nav_user_agent.indexOf(string) + 1; /* point to next character position */
	thestring = string;
    //xx=window.open("","xx", "height=100, width=200");
    //xx.document.write("string="+thestring);
    //xx.document.close();
	return p;
}

    if (document.getElementById || document.all || document.layers)
    {
        DOM=true; // If 'true' then it's a DOM browser!!!! IE7, FF, Safari
        stdbrowser=1;
    }
      
if(DOM)
    if (isns||isns4)
      {layerref=".layers";
       styleref="";
      }
    else // must be IE or Opera or Safari??
      {layerref=".all";
       styleref=".style";
      }

function proveit(who)
   {
   window.alert("reached: "+who+br);
   }
/* ----- new version -------------------------- */

function getobj(name) // good for non-nested layers - formerly named getObj
  {if(ldbg)dbgwin.document.write("getobj: lname="+lname);// getobj: compliments of Peter-Paul Koch at www.quirksmode.org, with mods by D. J. Foreman
   if(!document.getElementById(name))return null;	  
    if (document.getElementById)
      {// NN6-8 AND IE 6
       this.obj = document.getElementById(name);
       this.style = document.getElementById(name).style;
       this.obj.name=name;
       this.height=document.getElementById(name).offsetHeight;
       this.width=document.getElementById(name).width;
       if(ldbg) dbgwin.document.write("getobj: got it from document.getElementById("+name+")<br>");
       if(ldbg) dbgwin.document.write("getobj: reversit:"+getobjname(this)+"<br>");
      }
    else
      if (document.all)
        {// ie 4/5 
         this.obj = document.all[name];
         this.style = document.all[name].style;
         this.obj.name=name;
         if(ldbg) dbgwin.document.write("getobj: got it from document.all[name]<br>");
        }
       else
         if (document.layers)
           { // NN4
             this.obj = getobjNN4(document,name);
             this.style = this.obj;
             isns=false;isns4=true;
             this.id=name;
             if(firsttime)
             {
                 firsttime=false;
                 if(!ldbg)
                 window.alert("Netscape 4.xx does not support full CSS and Javascript together. "  
             +"You may need a different browser to see all the effects on this page.")
             if(ldbg) dbgwin.document.write("is NS4<br>");
             }
           }
    return this;  
  }
/* ------------------------------- */
function getobjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for (var i=0;i<x.length;i++)
	{//document.write("i="+i+", lname="+x[i].id+"<br>");
		if (x[i].id == name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getobjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function getobjname(objhandle)
{if (isns4)
    return objhandle.id;
 else
    return objhandle.obj.name;
}

/* from looks like:   http://machine/~dj/205pages/assgns/assignments-v0.html */
function bldref205a(from)
  {
    // home205a=from;
  }

function lshow(lname)
    {if(ldbg) dbgwin.document.write("show div name=/"+lname+"/<br>");
     if(!isns4) // get obj from name
      var  obj=getobj(lname);
     else
        obj=lname;
      if (isns4)
          eval("document."+obj+".visibility='visible';");
      else
        obj.style.visibility="visible";
    }
function lhide(lname)
    {if(ldbg) dbgwin.document.write("hide lname=/"+lname+"/<br>");
     if(!isns4)
      var  obj=getobj(lname);
     else
      var  obj=lname;
      if (isns4)
         eval("document."+lname+".visibility='hide';");
      else
          obj.style.visibility="hidden";  // "hidden" in Firefox, Netscape 8 and in IE
    }
// following is sample code only. Not used in any of my web pages
/*
function nav4_resizer(init) 
{  // allows pages to be resized in nav4
  if (init==true) 
      with (navigator) 
        {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
            {
                document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
            }
        }
  else 
      if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) history.go(0);
}
MM_reloadPage(true);
*/

// Function to put a layer in a specific place on the screen
// and give it specific width and height.
// need to re-write to eliminate incoming "px" requirement
function setpos (lname,topv,rightv,bottomv,leftv)
    {if (!isns4)
         var id=getobj(lname);
     else
         var id=lname;
    //if(ldbg) dbgwin.document.write("reached setpos<br>");
     if((topv!=-1) && (topv!=""))
        if(isns)id.style.top=topv+px;
        else 
            if (isns4) id.top=topv;
        else
        {
            id.obj.pixelTop=topv;
            id.style.top=topv+px;
        }
     if((rightv!=-1) && (rightv!=""))
        if(isns)id.style.right=rightv+px;
     else 
            if (isns4) id.right=rightv;
        else 
          {
              id.obj.pixelRight=rightv;
              id.style.right=rightv+px;
          }
     if((bottomv!=-1) && (bottomv!=""))
        if(isns)id.style.bottom=bottomv+px;
     else 
            if (isns4) id.bottom=bottomv;
        else 
          {
              id.obj.pixelBottom=bottomv;
              id.style.bottom=bottomv+px;
          }
     if((leftv!=-1) && (leftv!=""))
        if(isns)id.style.left=leftv+px;
     else 
            if (isns4) id.left=leftv;   
     else 
          {
              id.obj.pixelLeft=leftv;
              id.style.left=leftv+px;
          }
     //id.style.overflow="auto";
    }

function placeit(lname,x,y) // input is actual layer (ie; div) name
  {   
      if(ldbg)
          dbgwin.document.write("placeit: "+lname+",  xpos="+x+",  ypos="+y+"<br>");
      if (!isns4)
         var id=getobj(lname);
      else
          var id=lname;
      if (isns) // NS4 uses no units, NS uses "px"
         {
           id.style.left=x+px;
           id.style.top=y+px;
         }
      else
          if (isns4) 
               eval("document."+lname+".moveTo(x,y);");
          else /* for ff & ie */
          {
           id.obj.pixelLeft=x;
           id.obj.pixelTop=y; 
           id.style.left=x+px;
           id.style.top=y+px;
          }
  }
function setcolor(lname,clr)
    {if (!isns4)
        {var id=getobj(lname);
        id.style.color=clr;
        }
     else
         ; // ignored in NS4
    }

function setsize(lname,sz)
    {if (!isns4)
        {
         var id=getobj(lname);
         id.style.fontSize=sz;
        }
     else
         ;     // cannot do this in NS4 with normal JavaScript
    }
    
function tstpos(lname)
  {
      if(ldbg)
      {if (!isns4)
         var id=getobj(lname);
       else
           var id=lname;
       dbgwin.document.write("top, pixelTop="+id.style.top+","+id.obj.pixelTop+"<br>");
       dbgwin.document.write("left, pixelLeft="+id.style.left+","+id.obj.pixelLeft+"<br>"); 
       dbgwin.document.write("right, pixelRight="+id.style.right+","+id.obj.pixelRight+"<br>");
       dbgwin.document.write("id="+getobjname(id)+",  isie="+isie+",  isns="+isns+",  isff="+isff+"<br>");
      }
  }

  function gethw(lname,hw)
  {   if (!isns4)
      {zz=getobj(lname);
      var h=zz.height;
      var w=zz.width;
      }
      else
          {
              var h=eval("document."+lname+".document.height");
              var w=eval("document."+lname+".document.width");
          }
   if (hw=="h")
   {//alert("returning "+h);  
       return (h);
   }
   else return (w);
  }
function sethw(lname,h,w)
    {
      if (!isns4)
      {zz=document.getElementById(lname);
      zz.height=h+"px";
      zz.width=w+"px";
      }
      else
          {
              lname.height=h;
              lname.width=w;
          }
    }
  
function hideit(id)
  {
    lhide(id);
  }

function showit(id)
  {
    lshow(id);
  }
// move a layer left, right, up or down
function shift(id,x,y) // input is a number w/o the "px" at the end
  {if (!isns4)
         var id=getobj(id);
   var oldleft, oldtop, newleft,newtop;  
	 if (x!=0)
         // must convert the oldvalue to a true number after chopping-off the "px"
         {  
          if (isns)
          {
              oldleft=id.style.left;
              newleft=parseInt(oldleft)+parseInt(x);
              id.style.left=newleft+px;
          }
              else if (isns4)
                {
                    oldleft=id.style.pageX;
                    newleft=parseInt(oldleft)+parseInt(x);
                    id.obj.moveBy(x,0);
                }
          else
              {// isie or isff       must set BOTH fields
                  oldleft=id.obj.pixelLeft;
                  newleft=parseInt(oldleft)+parseInt(x);
                  id.obj.pixelLeft=newleft;
                  id.style.left=newleft+px;
              }
          if (ldbg) dbgwin.document.write("shift: id="+getobjname(id)+",  oldleft="+oldleft+",  newleft="+newleft+"<br>");
         }
	 if (y!=0)
         {      
              if (isns)
              {
                oldtop=id.style.top;
                newtop=parseInt(oldtop)+parseInt(y);
                id.style.top=newtop+px;
              }
              else if (isns4)
                {
                    oldtop=id.style.pageY;
                    newtop=parseInt(oldtop)+parseInt(y);
                    id.obj.moveBy(0,y);
                }
              else // must be ie or firefox
              {
                 oldtop=id.obj.pixelTop;
                 newtop=parseInt(oldtop)+parseInt(y);
                 id.obj.pixelTop=newtop;
                 id.style.top=newtop+px;
              }
          if (ldbg) dbgwin.document.write("shift: id="+getobjname(id)+",  oldtop="+oldtop+",  newtop="+newtop+"<br>");
         }// end if y!=0
  }

function getx(id)
  {   if (!isns4)
         var id=getobj(id);
      //if (ldbg) dbgwin.document.write("getx<br>");
      if(isns) xx=id.style.left;  // returns a STRING like "10px"
      else if (isns4)
          xx=id.style.pageX;
          else xx=id.obj.pixelLeft;
      if (ldbg) dbgwin.document.write("getx: id="+getobjname(id)+", found:"+xx+"<br>");
      x=parseInt(xx);  // chop off the "px" before returning the number part
      if (ldbg) dbgwin.document.write("getx returning:"+x+"<br>");
      return x;
  }
function gety(id)
  { if (!isns4)
         var id=getobj(id);
   //if (ldbg) dbgwin.document.write("gety<br>");
    if(isns)  
      yy=id.style.top;
    else if (isns4)
        yy=id.style.pageY;
        else
          yy=id.obj.pixelTop;
          y=parseInt(yy); // chop off the "px" before returning the number part
       if (ldbg) dbgwin.document.write("gety returning:"+yy+"<br>");
   return y;
  }
  function chkdate(a,b)
  {// this function returns a -1, 0 or +1 based on a compare of a:b
  ayr=a.getFullYear();
  byr=b.getFullYear();
  amo=a.getMonth();
  bmo=b.getMonth();
  ady=a.getDate();
  bdy=b.getDate();
  dbg=0;
  if (ayr<byr)
     {  if (dbg) document.write("ayr &lt;byr<br>");
      return -1;            // a<b
     }
  if (ayr>byr)
     {  if (dbg) document.write("ayr &gt;byr<br>");
      return 1;             // a>b
     }
  if (ayr==byr)
     {/* now compare months */
        if (dbg) document.write("ayr=byr<br>");
      if (amo<bmo)
          {
           if (dbg) document.write("amo&lt;bmo<br>");
           return -1;                // yrs are same, a<b
          }
      if (amo>bmo)
          {
           if (dbg) document.write("amo&gt;bmo<br>");
           return  1;                // yrs are same, a>b
          }
      if (amo==bmo)                  // yrs are same, months are same
         {// now compare days
           if (dbg) document.write("amo==bmo<br>");
          if (ady<bdy) return -1;    //a<b
          if (ady>bdy) return 1;     //a>b
          return 0;                  //a=b
         }
     }
  }
function season() // returns either "spring" or "fall"
{var today=new Date();
    month=today.getMonth();
    if (month<6) return "spring";
    else return "fall";
}
function hwversion()  
{ if (season=="fall") return 1;
  else return 2;
}
function bakecookie(name,value,days) 
    {var expdate = ""; // initilly set to expire at close of browser
	    if (days) 
        {
		    var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000)); 
            // if days<0, then the date setting will delete the cookie
            var expdate="expires="+date.toGMTString();
        }
        else var expdate = "";
	var nvpair = name+"="+value+"; "+expdate+"; path=/"; // ONE space after ";"
	document.cookie = nvpair;
    }

function getcookie(name) 
    {
	var head = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) 
       	    {
	     var c = ca[i];
	     while (c.charAt(0)==' ') 
                 c = c.substring(1,c.length);
	     if (c.indexOf(head) == 0) 
		     return c.substring(head.length,c.length);
            }
	return null; // cookie not found or expired
    }

function delcookie(name) 
    {
	 bakecookie(name,"",-1); // change expdate to before today
    }  
  
/*if(document.all){
document.all.contents.style.left=xpos;
}
if(!document.all && document.getElementById){
document.getElementById("contents").style.left=xpos+"px";
}
if (xpos<=-200 || xpos>=0){
window.clearTimeout(Id);Id=0;}
else{
Id = window.setTimeout("movemenu();",100);
*/
