var magikChar = 'e';
var magikFont = 'Symbol';
var magikSize = '+1';
var pickColor = 1;   // 1 = green  anything else = blue (the only two sharpie markers we have)
var magikColor = (pickColor == 1) ? "green" : "blue";
var wmlSloganText = new Array(
                              "Wireless Microsystems...Microsystems for Wireless",
                              "...where light speed is fast!",
                              "...where uncertainty is certain.",
                              "...where gravity is strong!",
                              "...where robots rule the sky.",
                              "...where relativity is relatively ignored.",
							  "No!"
                             );
var wmlSloganInt = 0; //Math.floor((wmlSloganText.length)*Math.random());						 

/**********************************
var absImgPath = "http://www.ece.vt.edu/WML/images/";
var EXT = ".htm";
var PEXT = ".html";

var mlink = wmlLink = 0;
var plink = publink = rlink = 1;
***********************************/
var wmlIP = 0;

var NS4 = (navigator.appName == "Netscape");

//document.write("<link rel=\"shortcut icon\" href=\"/favicon.ico\" type=\"image/x-icon\">");

function onmouseoutFunc(ee) {

  if(NS4) {
    //window.status = "id = " + ee.relatedTarget.id + " appName = " + navigator.appName;
    if(ee.relatedTarget != null && (ee.relatedTarget.id == "" || ee.relatedTarget.id == "wmlText"))
	  kickIt();
  }
  else {
    //window.status = "id = " + window.event.toElement.id + " appName = " + navigator.appName;
    if(window.event.toElement != null && (window.event.toElement.id == "" || window.event.toElement.id == "wmlText"))
      kickIt();
  }
}

// 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
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "");
  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 dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function loadPage () {
  var stuff = new String();
  
  parent.document.title = pageName;
  bootyCount();
  
  if(stuff = getCookie("wmlCookie")) {
    if(NS4)
	  document.getElementId('wmlBG').innerHTML = stuff;
	else
      wmlBG.innerHTML = stuff;
  }
  else {
    var expire = new Date();
	expire.setTime(expire.getTime() + 6000);  //24*60*60*1000);

    stuff =
    "<map name=\"wmlMenuMapTop\">" +
    "<area shape=rect href=\"" + linkArray[mlink++][0] + "\" onmouseover=\"expandMenu(1)\" onmouseout=\"\" coords=\"0,0,72,20\">" +
    // Nikhil - Remove seperate Publications Links 
    //"<area shape=rect href=\"" + linkArray[mlink++][0] + "\" onmouseover=\"expandMenu(2)\" onmouseout=\"\" coords=\"72,0,188,20\">" +
    "<area shape=rect href=\"" + linkArray[mlink++][0] + "\" onmouseover=\"expandMenu(3)\" onmouseout=\"\" coords=\"82,0,280,20\">" +
    "</map>" +
    "<map name=\"wmlPeoMenuMap\">" +
    // Edited by Nikhil - fixing mouse over co ordinate regions
      "<area shape=rect id=\"wmlPeoSubMenu\" href=\"" + linkArray[people][plink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"0,0,72,20\">" +
      "<area shape=rect id=\"wmlPeoSubMenu\" href=\"" + linkArray[people][plink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"72,0,195,20\">" +
      "<area shape=rect id=\"wmlPeoSubMenu\" href=\"" + linkArray[people][plink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"195,0,280,20\">" +
      "<area shape=rect id=\"wmlPeoSubMenu\" href=\"" + linkArray[people][plink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"0,0,72,20\">" +
      "<area shape=rect id=\"wmlPeoSubMenu\" href=\"" + linkArray[people][plink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"72,0,195,20\">" +
      "<area shape=rect id=\"wmlPeoSubMenu\" href=\"" + linkArray[people][plink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"195,0,280,20\">" +
    "</map>" +
    // Edited by Nikhil - To remove links for publications and journals on mouse over
    //"<map name=\"wmlPubMenuMap\">" +
    //"<area shape=rect id=\"wmlPubSubMenu\" href=\"" + linkArray[publish][publink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"0,0,80,20\">" +
    //"<area shape=rect id=\"wmlPubSubMenu\" href=\"" + linkArray[publish][publink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"80,0,162,20\">" +
    //"<area shape=rect id=\"wmlPubSubMenu\" href=\"" + linkArray[publish][publink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"162,0,280,20\">" +
    //"</map>" +
    "<map name=\"wmlResMenuMap\">" +
    "<area shape=rect id=\"wmlResSubMenu\" href=\"" + linkArray[researc][rlink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"0,0,84,20\">" +
    "<area shape=rect id=\"wmlResSubMenu\" href=\"" + linkArray[researc][rlink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"84,0,163,20\">" +
    "<area shape=rect id=\"wmlResSubMenu\" href=\"" + linkArray[researc][rlink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"163,0,280,20\">" +
    "<area shape=rect id=\"wmlResSubMenu\" href=\"" + linkArray[researc][rlink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"0,20,130,35\">" +
    "<area shape=rect id=\"wmlResSubMenu\" href=\"" + linkArray[researc][rlink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"130,20,209,35\">" +
    "<area shape=rect id=\"wmlResSubMenu\" href=\"" + linkArray[researc][rlink++] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"209,20,280,35\">" +
    "</map>" +
    "<map name=\"wmlMenuMapBot\">" +
    "<area shape=rect href=\"" + linkArray[mlink++][0] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"0,0,85,20\">" +
    "<area shape=rect href=\"" + linkArray[mlink++][0] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"85,0,175,20\">" +
  //  "<area shape=rect href=\"" + linkArray[mlink++][0] + "\" onmouseover=\"\" onmouseout=\"\" coords=\"175,0,280,20\">" +
    "</map>" +
    "<table width=700 height=620 border=0 align=center cellpadding=0 cellspacing=0 bgcolor=#FFFFFF>" +
    "  <tr>" +
    "    <td align=left valign=top><img src=\"" + absImgPath + "chamfer-topleft.gif\"></td>" +
    "    <td>" +
    "      <table width=700 height=620 border=0 align=center cellpadding=0 cellspacing=0 bgcolor=\"#FFFFFF\">" +
    "        <tr height=15><td colspan=4></td></tr>" +
    "        <tr height=95>" +
    "          <td valign=top width=100 align=center><a href=\"" + wmlLinks[wmlLink++] + "\" target=\"_top\"><img border=0 src=\"" + absImgPath + "logo-letter.gif\"></a></td>" +
    "          <td width=10 colspan=1>&nbsp;</td>" +
    "          <td width=1 colspan=1><img src=\"" + absImgPath + "v-spacer.gif\" width=1 height=105 border=0 vspace=0></td>" +
    "          <td valign=top align=center width=40% height=20>" +
    "            <table border=0 cellspacing=0 cellpadding=0>" +
    "               <tr>" +
    "                 <td valign=bottom>" +
    "                   <div id=\"wmlTopMenu\"><img usemap=\"#wmlMenuMapTop\" src=\"" + absImgPath + "menus/top-menu.gif\" id=\"topMenuRobot\" border=0 vspace=0></div>" +
    "                 </td>" +
    "               </tr>" +
//    "               <tr height=1>" +
//    "                 <td valign=middle height=1>" +
//    "                   <img src=\"" + absImgPath + "h-spacer.gif\" width=100% height=1 border=0 vspace=0 hspace=0>" +
//    "                 </td>" +
//    "               </tr>" +
    "               <tr>" +
    "                 <td valign=top>" +
    "                   <div id=\"wmlMidMenu\"><img usemap=\"#wmlMenuMapBot\" src=\"" + absImgPath + "menus/bot-menu.gif\" id=\"midMenuRobot\" border=0 vspace=0></div>" +
    "                 </td>" +
    "               </tr>" +
    "               <tr>" +
    "                 <td valign=top>" +
    "                   <div id=\"wmlBotMenu\"><img usemap=\"#wmlMenuMapBot\" src=\"" + absImgPath + "menus/bot-menu.gif\" id=\"botMenuRobot\" border=0 vspace=0></div>" +
    "                 </td>" +
    "               </tr>" +
    "              <tr height=11>" +
    "                <td colspan=1 align=center valign=middle><div id=\"wmlSlogan\">\"" + wmlSloganText[wmlSloganInt] +"\"</div></td>" +
    "              </tr>" +
    "            </table>"+
    "          </td>" +
	"          <td width=1><img src=\"" + absImgPath + "v-spacer.gif\" width=1 height=105 border=0 vspace=0></td>" +
    "          <td valign=top align=center><a href=\"" + wmlLinks[wmlLink++] + "\" alt=\"VT Home\" target=\"_top\"><img border=0 src=\"" + absImgPath + "VTblue-i.jpg\"></a>" +
	"          <div id=\"wmlAddressOld\"><a href=\"" + wmlLinks[wmlLink++] + "\" alt=\"VT ECE Home\" class=wmlAddressOldLink target=\"_top\">Bradley Dept. of Electrical<br>" +
    "            and Computer Engineering</a></div> " +
    "          </td>" +
    "        </tr>" +
    "        <tr height=438>" +
//    "          <td width=1><img src=\"" + absImgPath + "v-spacer.gif\" width=1 height=100% border=0 vspace=0></td>" +
    "          <td colspan=8>" +
    "            <table width=100% cellpadding=0 cellspacing=0 border=0>" +
    "              <tr>" +
    "                <td align=left><img src=\"" + absImgPath + "h-spacer.gif\" width=100% height=1 border=0 vspace=0 hspace=0></td>" +
    "              </tr>" +
	//"              <tr height=2>" +
    //"                <td>&nbsp;</td>" +
    //"              </tr>" +
    "              <tr rowspan=3>" +
    "                <td align=center height=456>" +
    "                  <div id=wmlText></div>" +
    "                </td>" +
    "              </tr>" +
    "              <tr>" +
    "                <td align=left><img src=\"" + absImgPath + "h-spacer.gif\" width=100% height=1 border=0 vspace=0 hspace=0></td>" +
    "              </tr>" +
    "            </table>" +
    "          </td>" +
    "        </tr>" +
    "        <tr>";
    if (pageName == "Tina's 30th Birthday!!!!" || pageName == "Tina's 30th Birthday!!!! (page 2)")
      stuff +=
               "<td align=center class=wmlReference>" +
               "  Check out <br><a class=\"sslinkII\" href=\"http://www.ece.vt.edu/wml/steph.html\" target=\"_top\">Steph's 21st Birthday</a>!"+
               "</td>";
    else if (pageName == "Steph's 21st Birthday!!!!")
      stuff +=
               "<td align=center class=wmlReference>" +
               "  Check out <br><a class=\"sslinkII\" href=\"http://www.ece.vt.edu/wml/tina.html\" target=\"_top\">Tina's 30th Birthday</a>!"+
               "</td>";
    else if (pageName != "The Wireless Microsystems Laboratory")
	  stuff +=
               "          <td class=wmlSearchlink><form action=\"http://www.google.com/u/virginiatech\">Search VT Web<br>" +
               "            <input name=\"domains\" type=\"hidden\" value=\"vt.edu\"><input name=\"sitesearch\" type=\"hidden\" value=\"vt.edu\">" +
               "            <input id=\"websearchquery\" name=\"q\" type=\"text\" style=\"width: 130px;font-size:10px\" value=\"Enter search keywords\" size=\"15\" maxlength=\"50\">" +
               "            <input type=\"submit\" value=\"Go\">" +
               "          </form></td>";
	else
      stuff +=
               "<td align=center class=wmlReference>" +
               "  <a class=\"sslinkII\" href=\"" + linkArray[announc][annpage]+ "\">Announcements</a> <br>concerning the WML"+
               "</td>";
	stuff += 		   
    "          <td>&nbsp;</td>" +
    "          <td valign=top width=1><img src=\"" + absImgPath + "v-spacer.gif\" width=1 height=50 border=0 vspace=0></td>" +
    "          <td class=wmlWebMaz> Webmasters: <b>Nikhil</b> and <b>Krishna</b>. <br>" +
    "            Send comments to: <a class=wmlWebMaz href=\"mailto:rfic@ee.vt.edu\">kvummidi@vt.edu</a><br>" +
	"            This week is sponsored by the character: <font face=" + magikFont + " size=" + magikSize + " color=" + magikColor + ">" + magikChar + "</font>" +
    "          </td>" +
    "          <td valign=top width=1><img src=\"" + absImgPath + "v-spacer.gif\" width=1 height=50 border=0 vspace=0></td>" +
    "          <td colspan=1>" +
    "            <div id=\"wmlAddress\">" + 
    "            433/477 Whittemore Hall <br>" +
    "            (Mail Code 0111)<br>" +
    "            Blacksburg, VA 24061<br>" +
    "            Phone: (540) 231-3411</div>" +
    "        </td>" +
    "        </tr>" +
    "      </table>" +
    "    </td>" +
    "    <td align=right valign=top><img src=\"" + absImgPath + "chamfer-topright.gif\"></td>" +
    "  </tr>" +
    "  <tr>" +
    "    <td align=right valign=top><img src=\"" + absImgPath + "chamfer-botleft.gif\"></td>" +
    "    <td></td>" +
    "    <td align=right valign=top><img src=\"" + absImgPath + "chamfer-botright.gif\"></td>" +
    "  </tr>" +
    "</table>";

    //alert("No cookie");			
    setCookie("wmlCookie", stuff, expire);
	//alert("Cookie has been baked");
	if (NS4)
	  document.getElementById('wmlBG').innerHTML=stuff;
	else
	  wmlBG.innerHTML = stuff;
  }
   loadText();
   //window.status = "wmlIP = " + wmlIP;
}

function loadText() {
  var IMG_HEIGHT_ADJ = 0.295;
  var IMG_WIDTH_ADJ = 0.2;
  var PIC_WIDTH_ADJ = 0.61;
  var PIC_MARGIN_ADJ = 0.36;
 
  if (NS4) {
    document.getElementById('wmlText').innerHTML += docText;
  }
  else {
    wmlText.innerHTML += docText;
  }
  
}

function rollIn(el)
{
    el.initstyle=el.style.cssText;
	el.style.cssText="color: #3366FF";
}

function rollOut(el)
{
	el.style.cssText=el.initstyle
}

function expandMenu(id)
{
  document.onmouseout=onmouseoutFunc;
  
  if (NS4) {
    wmlTopMenu = document.getElementById('wmlTopMenu');
    wmlMidMenu = document.getElementById('wmlMidMenu');
    wmlBotMenu = document.getElementById('wmlBotMenu');
    wmlSlogan = document.getElementById('wmlSlogan');
  }
  
  switch (id) {
    case 1:
      wmlMidMenu.style.height = "20px";
      wmlMidMenu.innerHTML = "<img usemap=\"#wmlPeoMenuMap\" src=\"" + absImgPath + "menus/peo-menu.gif\" id=\"midMenuRobot\" border=0 vspace=0>";
	  break;
    case 2:
	  wmlMidMenu.style.height = "20px";
      wmlMidMenu.innerHTML = "<img usemap=\"#wmlPubMenuMap\" src=\"" + absImgPath + "menus/pub-menu.gif\" id=\"midMenuRobot\" border=0 vspace=0>";
      break;
    case 3:
      wmlMidMenu.style.height = "40px";
      wmlMidMenu.innerHTML = "<img usemap=\"#wmlResMenuMap\" src=\"" + absImgPath + "menus/res-menu.gif\" id=\"midMenuRobot\" border=0 vspace=0>";
      break;
  }
//  wmlMidMenu.style.paddingTop = "0px";
  wmlSlogan.style.display = "none";
  wmlBotMenu.style.display = "block";	 
}

function kickIt()
{
  if (NS4) {
    wmlTopMenu = document.getElementById('wmlTopMenu');
    wmlMidMenu = document.getElementById('wmlMidMenu');
    wmlBotMenu = document.getElementById('wmlBotMenu');
    wmlSlogan = document.getElementById('wmlSlogan');
  }

  wmlBotMenu.style.display = "none";
  wmlSlogan.style.display = "block";
  wmlSlogan.style.paddingTop = "5px";
  wmlMidMenu.style.height = "20px";
  wmlMidMenu.innerHTML = "<img usemap=\"#wmlMenuMapBot\" src=\"" + absImgPath + "menus/bot-menu.gif\" id=\"midMenuRobot\" border=0 vspace=0></div>";

  document.onmouseout="";
}

function bootyCount() 
{
  wmlIP = 0;
  var url = "http://www.ee.vt.edu/~rs/counter.cgi?pagename=" + pageName; //http://batfish.ece.vt.edu/cgi-bin/trapped.cgi";
  
  parent.left.location.href = url; //"http://www.ee.vt.edu/~rs/counter.cgi?pagename=" + pageName;
/******************************************************************
*******************************************************************
******  Old popup window method for counting...
******  However, the Google toolbar forced Chris to come up
******  with a new way to count:  das frame! (previous 
******  line o' code)
*******************************************************************
*******************************************************************
  if (NS4) {
      var win = window.open (url, "trap", "screenX=" + (this.screenX+document.body.clientWidth-100) + ",screenY="+ (this.screenY+document.body.clientHeight) + ",height=1,width=1,alwaysLowered=yes");
      //window.ontop = true;
      //win.blur();
	  //win.creator = self;
  }
  else {
    var win = window.open (url, "trap", "top=" + (window.event.screenY+window.event.clientY)  + ",left=" + (window.event.screenX+window.event.clientX) + ",height=1,width=1");
    window.focus();
	//win.creator = self;
  }	
	
  window.focus();
  //win.close();	
******************************************************************/
}

function assClown() {
  wmlIP = 69;
}