var i;
var j = 666; //which journalist is currently selected?  initial: 666 = nobody
var k,m,n,nummonas,monanum=0;
var donight=0;
var timeoutid;
social1 = new String();
social2 = new String();
age = new String();
id = new String();
pw2 = new String();
texta = new String();

monas = new Array();
monas[0] = new String("mona1.gif");
monas[1] = new String("mona2.gif");
monas[2] = new String("mona3.gif");
monas[3] = new String("mona4.gif");
monas[4] = new String("mona5.gif");
monas[5] = new String("mona6.gif");
//monas[6] = new String(".\\res\\mona7.gif");
nummonas = monas.length;

function hello()
{
   window.alert("hello(): VOTE FOR A JOURNALIST");
}
function rst()     // reset button ... all votes to 0
{
   document.myform.kitty.value = 0;
   document.myform.ibn.value = 0;
   document.myform.geller.value = 0;
}

function nighttime() {
    //window.alert("monanum = "+monanum);
    if (monanum > nummonas-1)
    {
       clearTimeout(timeoutid);
       monanum = 0;
       document.bgColor='#FFFF00';  //GO YELLOW
       document.images.show.src = "daymona.gif";
    }
    else
    {
      document.bgColor='#0F000F'; //GO DARK
      //window.alert("SHOW = "+monas[monanum]);
      document.images.show.src = monas[monanum];
      //document.images.show.src = "mona1.gif";
      monanum++;
      timeoutid = setTimeout("nighttime()",4000);
    }
}
function daytime() {
    document.bgColor='#FFFF00';  //GO YELLOW
    document.images.show.src = "daymona.gif";
}

function voter() {                  //vote button ... increase vote.
        //window.alert("CLICK");
        switch(j)    //which candidate selected?
        {
          case 0:
              i = document.myform.kitty.value;  //force numerical
              i++;
              document.myform.kitty.value = i;
              break;
          case 1:
              i = document.myform.ibn.value;
              i++;
              document.myform.ibn.value = i;
              break;
          case 2:
              i = document.myform.geller.value;
              i++;
              document.myform.geller.value = i;
              break;
        }
}

function remove1()   //FROM DUMMY
{
           k = document.myform.dummy.length;
           document.myform.dummy.options[k-1].text = "";
           window.alert(k);
}
function getselectedsource() //FROM SOURCE ... number selected from zero
{
    for (k=0;k < document.myform.selection.length;k++)
    {
        if (document.myform.selection.options[k].selected)
        {
           //window.alert(k);
           return (k);
        }
    }
}
function getselectedtarget() //FROM TARGET ... number selected from zero
{
    for (k=0;k < document.myform.dummy.length;k++)
    {
        if (document.myform.dummy.options[k].selected)
        {
           //window.alert(k);
           return (k);
        }
    }
}

function add1()
{
   m = getselectedtarget();
   //window.alert(m);
   n = getselectedsource();
   //window.alert(n);
   //document.myform.dummy.options[m].text = document.myform.selection.options[n].text;
   document.myform.dummy.options[m] = new Option(document.myform.selection.options[n].text,
                                                 document.myform.selection.options[n].value,
                                                  false, false);

  //document.myform.dummy.options[m].value = document.myform.selection.options[n].value;
}
function dummyselect()
{
   //window.alert(document.myform.dummy.value);
   //Selected picture to right-side frame:
   document.images.show.src = document.myform.dummy.value;
    //Store selected candidate for vote operation in j:
        switch(document.myform.dummy.value)
        {
          case "kitty.jpg":
              j = 0;
              break;
          case "ibn.jpg":
              j = 1;
              break;
          case "geller.jpg":
              j = 2;
              break;
          default:
             j = 666; //nobody
        }
}

//SELECT CANDIDATE:     // onchange in dropdown... new candidate
function doselect(){
        //Selected picture to right-side frame:
        document.images.show.src = document.myform.selection.value;
        //Store selected candidate for vote operation in j:
        switch(document.myform.selection.value)
        {
          case "kitty.jpg":
              j = 0;
              break;
          case "ibn.jpg":
              j = 1;
              break;
          case "geller.jpg":
              j = 2;
              break;
          default:
             j = 666; //nobody
        }
}
function AreaChange()
{
        window.alert("TEXT AREA CHANGED");
        //texta = escape(document.myform.area.value + " Brave Dude");
        //document.myform.area.value = texta;
}
function EscapeArea()
{
        texta = escape(document.myform.area.value);
        document.myform.area.value = texta;
}
function UnescapeArea()
{
        texta = unescape(document.myform.area.value);
        document.myform.area.value = texta;
}
function NameToArea()
{
       texta = texta + document.myform.name.value + "<BR>\n";
       document.myform.area.value = texta;
}
function ClearArea()
{
       texta = "";;
       document.myform.area.value = texta;
}


function submitform()
{
    window.alert("SUBMIT FORM");
    document.myform.submit();
}


//ROTATE CONTENTS OF TEXT BOXES:
function rename(){
        pw2=document.myform.pw1.value;
        document.myform.pw1.value=document.myform.output.value;
        document.myform.output.value=document.myform.fame.value;
        document.myform.fame.value=document.myform.name.value;
        document.myform.name.value=pw2;
}


function multiply(){
        age =  document.myform.name.value;
        id  =  document.myform.fame.value;
        i = age*id;
        //window.alert("MULT = "+i);
        document.myform.output.value = i;
}

function errortalk(msg,url,lineNo)
{
  window.alert("ERROR: "+msg+" AT LINE "+lineNo );
}

onerror=errortalk;