//------------------------------------------------------------------------
// $Id: classes.js,v 1.2 2002/10/22 12:30:33 kimballr Exp kimballr $
// $Author: kimballr $
//
// Copyright 2002-2003 Kimball Software
// All rights reserved
// mailto:rick@vrmlworld.net
//------------------------------------------------------------------------

//------------------------------------------------------------------------
//-- Person Object

var defaultAV='http://vrmlworld.net/avatars/smbh.wrl';

function Person_fromString(v) {
    var keylist=v.split('&');
    var i;
    var kv;
    for ( i=0; i < keylist.length; i++ ) {
	kv = keylist[i].split('=');
	//alert(kv[i]);
	if ( kv.length == 2 ) {
	    this[kv[0]]=kv[1];
	}
    }
}

function Person_toString() {			//Added  for test Page
  var s = '';
  s += 'uniqID=' + this.uniqID;
  s += ',username=' + this.username;
  s += ',avatarURL=' + this.avatarURL;
  s += ',interests=' + this.interests;  //added
  s += ',homepage=' + this.homepage;  //added

  
  return s;
}



function Person(uniqID, username, avatarURL, interests, homepage, sex) {
    var n = parseInt(Math.random()*10000);
    this.uniqID = null;
    this.username = 'Visitor'+n;
    this.avatarURL = escape(defaultAV);
    this.interests = '';
    this.homepage = '';
    this.sex = '';							//added
    this.state = 'Online';
    this.typing = false;

    if ( uniqID    ) { this.uniqID = uniqID; }
    if ( username  ) { this.username = username; }
    if ( avatarURL ) { this.avatarURL=avatarURL;   }
    if ( interests ) { this.interests = interests; }
    if ( homepage  ) { this.homepage = homepage;   }
    if ( sex       ) { this.sex = sex;   }				//added

    this.privateid=null;
    this.ignored=0;
    this.avatarPilot=null;
    var x = parseInt(Math.random()*5);
    var z = parseInt(Math.random()*5);
    this.currP=x+" 1.75 " +z;
    this.currO="0 0 1 0";
    
    //uiUpdateUserList();									//Added  //not needed
}

Person.prototype.fromString = Person_fromString;
//Person.prototype.toString = Person_toString;				//Added  for test Page

//------------------------------------------------------------------------
//-- Dictionary Object

function Dictionary_toList() {
    var z='';
    var uid='';
    var p=null;

    for (var w in this) {
	if ( w != 'toList' && w != 'toArray' ) {
	    p=this[w];
	    if ( p != null && typeof p != 'undefined' && me != null && p.uniqID != me.uniqID ) {
		z+=unescape(p.username)+'<BR>\n';
	    }
	}
    }
    return z;
}

function Dictionary_toArray() {
    var theArray=new Array();
    var p=null;

    for (var w in this) {
	if ( w != 'toList' && w != 'toArray' ) {
	    p=this[w];
	    if ( p != null && typeof p != 'undefined' && me != null && p.uniqID != me.uniqID ) {
		theArray.push(p);
	    }
	}
    }

    return theArray;
}

function Dictionary() { }
Dictionary.prototype.toList=Dictionary_toList;
Dictionary.prototype.toArray=Dictionary_toArray;

//------------------------------------------------------------------------
//-- Fake3D Object for those without a VRML browser

function Fake3D_setNodeEventIn() { }
function Fake3D_getNodeEventOut() { return ''; }
function Fake3D_getName() { return 'fake3d'; }

function Fake3D() {}
Fake3D.prototype.setNodeEventIn=Fake3D_setNodeEventIn;
Fake3D.prototype.getNodeEventOut=Fake3D_getNodeEventOut;
Fake3D.prototype.getName=Fake3D_getName;

//--EOF-- classes.js

//New to test page

function DoConnect() {
  ABNetComm.host = hostIPorDNS.value;
  ABNetComm.username = userIDData.value;
  ABNetComm.avatarurl = avatarURL.value;
  ABNetComm.Connect();
}

function DoAttach() {
  userName = me.uniqID;
  
  //av = avatarURL.value;
  av = newAvatarURL;
  //alert('userName: '+userName+'newAvatarURL: '+newAvatarURL);
  ABNet.Attach(userName, "xyzzy", av, "1");
}

function DoDetach() {
  ABNet.Detach();
}

function DoJoin() {
  ABNetComm.Join(channelData.value);
}

function DoLeave() {
  ABNetComm.Leave(channelData.value);
}

function DoChat() {
  ABNetComm.SendToAllExcept(myID, "onChat", escape(userName + ': ' + chatData.value));
}

function DoBlock(flag) {
  var sl = document.all.userlist;
  if ( sl.selectedIndex != 0 ) {
    var key = sl.options[sl.selectedIndex].value;
    ABNetComm.Block(key,flag);
  }
  else {
    alert('select a user to block or unblock');
  }
}


//EOF --- New to test page
