function seeDOM() {
  var range = document.body.createTextRange();
  if (range!=null) {
    alert(range.htmlText);
  }
}

function setLanguageCookie(the_language)
{
   var user_language = "userlanguage="+escape(the_language);
   var exp_date = new Date();
   var exp_dateInMSecs = exp_date.getTime();
   exp_dateInMSecs = exp_dateInMSecs + (1000*60*60*24*90); // 90 days
   exp_date.setTime(exp_dateInMSecs);
   user_language = user_language+";path:/;expires="+exp_date.toGMTString();
   document.cookie = user_language;
}

function WM_readCookie(name)
{
   if (document.cookie == "")  {
       return false;
   }
   else  {
       var firstChar, lastChar;
       var theBigCookie = document.cookie;
       firstChar = theBigCookie.indexOf(name);

      if (firstChar != -1)    {
          firstChar = firstChar + name.length + 1;
            lastChar = theBigCookie.indexOf(";",firstChar);
            if (lastChar == -1) {lastChar = theBigCookie.length;}
          return unescape(theBigCookie.substring(firstChar,lastChar));
        }
        else {
             return false;
       }
    }
}

function setPrevLanguage()
{
    var prevLanguage = WM_readCookie("userlanguage");

    if (prevLanguage != false)  {
      for (var i = 0; i < document.pick_language.the_language.length; i++)
      {
          if (prevLanguage == document.pick_language.the_language[i].value) {
              document.pick_language.the_language[i].checked = true;
              setALanguage(prevLanguage);
          }
      }
    }
    else {setALanguage("Spanish")};
}

function buildDivArrays()
{
   English_texts = new Array();
   Spanish_texts = new Array();
   English_lines = new Array();
   Spanish_lines = new Array();

   var allDivs = window.document.getElementsByTagName("DIV");
   var j;

   for (var i=0; i < allDivs.length; i++)
   {
       j = Spanish_texts.length;
       if (allDivs[i].id.substring(0,8)=="Spanish_") {Spanish_texts[j] = allDivs[i].id;}
       j = English_texts.length;
       if (allDivs[i].id.substring(0,8)=="English_") {English_texts[j] = allDivs[i].id;}
   }

   
}

function browserVars()
{
   isNS4 = (document.layers) ? true : false;
   isIE4 = (document.all && !document.getElementById) ? true : false;
   isIE5 = (document.all && document.getElementById) ? true : false;
   isNS6 = (!document.all && document.getElementById) ? true : false;

   // alert("NS4 = "+isNS4+"; IE4 = "+isIE4+"; IE5 = "+isIE5+"; NS6 = "+isNS6);

   browser_name=navigator.appName;
   browser_platform=navigator.platform;
   browser_version=parseFloat(navigator.appVersion);
}

function setBackground()   // Avoids "feature" in NS, Opera
{
   if (isIE5)
   {
      window.document.body.bgcolor = "#e8e8e8";
   }
}

function startupProcedures()
{
   browserVars();
   buildDivArrays();
   setPrevLanguage();
   setBackground();
   var def_list = window.document.getElementsByTagName("DD");

   // seeDOM();
   // alert(def_list[0].firstChild.nodeValue);
}

function setALanguage(thisLanguage)

{
   setLanguageCookie(thisLanguage);

   if (!(isNS6 || isIE5))  {
      var theHomeURL = thisLanguage+"Home.htm";
      window.location = theHomeURL;
   }

   else {

      if (thisLanguage=="Spanish")
      {
          var whatsSpanish="visible";
          var whatsEnglish="hidden";
          var posSpanish="relative";
          var posEnglish="absolute";
      }
      else
      { 
           var whatsSpanish="hidden";
           var whatsEnglish="visible";
           var posSpanish="absolute";
           var posEnglish="relative";
      }

      for (var i=0; i<English_texts.length; i++)
      {
        if (isNS6)
        {
         window.document.getElementById(Spanish_texts[i]).style.position=posSpanish;
         window.document.getElementById(English_texts[i]).style.position=posEnglish;
         window.document.getElementById(Spanish_texts[i]).style.visibility=whatsSpanish;
         window.document.getElementById(English_texts[i]).style.visibility=whatsEnglish;
        }
        else if (isIE4 || isIE5)
        {
         window.document.all[Spanish_texts[i]].style.position=posSpanish;
         window.document.all[English_texts[i]].style.position=posEnglish;
         window.document.all[Spanish_texts[i]].style.visibility=whatsSpanish;
         window.document.all[English_texts[i]].style.visibility=whatsEnglish;
        }
      }

     }
}

function writeTitleOverlay()   // Not currently in use

{
    browserVars();
    if (isIE5)
    {
    window.document.write("<DIV id=\"redCLVU\" style=\"position:absolute;left=-2;top=2;z-index=5\"><H1 class=\"bigredhead\">City Life/Vida Urbana</H1></DIV>");
     }
}

