//zmg, 03.01.01
//this file needs a better description!
//
//





// Utility functions




// FIle: actions_misc.txt
// Description: Miscellenous functions


// utility_hideAll()
// IN : None
// DO : Hide all unutilized movie clips
// OUT: None
function utility_hideAll() {
	_root.Instructions._visible = false;
	_root.Topology._visible = false;
	_root.Done._visible = false;
}




// utility_updateText()
// IN : None
// DO : Updates text for Menu buttons (i.e. hide/show instructions, toplogy, done)
// OUT: None
function utility_updateText() {


	tellTarget("Menu") {

		instructiontext = "Show Instructions";
		topologytext = "Show Topology";
		donetext = "Show Done";
	}
}




// utility_setVisible(b)
// IN : The router object that is to be set
// DO : Sets visibility of buttons for Routers and the screen
// OUT: None
function utility_setVisible(b) {

	// set the visibility of the router's menu button to true
	with(eval("_root.Menu.m" + b)) {
		_visible = true;
	}

	// set the visibility of the router's hyperterminal to false
	with(eval("_root.HyperTerminal.s" + b)) {
		_visible = false;
	}
}




// ***** utility_randomMAC() *****
// IN : None
// DO : Calculates a random 12-digit MAC address in the following hex format:
//		0060.5cf4.c677
// OUT:	Returns the random address generated
function utility_randomMAC() {


	// an array of possible hex numerals
	var hex = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");

	var mac = ""; // container for the random address

	// pull 12 random elements out of the hex array
	// put a '.' seperator between each group of four
	for (var i=0; i<12; i++)
	{
		mac += hex[Math.round(Math.random()*15)];

		// adding the '.' seperator after the 4th and 8th numerals
		if(i == 3 || i == 7)
			mac += ".";
	}

	return mac;
}



function utility_switchToNewRouter() {

	//the visible router isnt telnetted anywhere,
	//switch over to this new router like normal

	// turning on the correct router
	if (BUTTONROUTER == "RouterA") {

		// turn visibility to nil
		_root.Menu.mRouterA._visible = false;
		_root.HyperTerminal.sRouterA._visible = true;
		_root.utility_setVisible(_root.VISIBLE_ROUTER);

 		_root.active_router = "RouterA";
		_root.VISIBLE_ROUTER = "RouterA";
		_root.utility_hideAll();
		_root.utility_updateText();

		_root.router_startup_checkStartUp();
		_root.output_setCursor();

	} else if (BUTTONROUTER == "RouterB") {
		// turn visibility to nil
		_root.Menu.mRouterB._visible = false;
		_root.HyperTerminal.sRouterB._visible = true;
		_root.utility_setVisible(_root.VISIBLE_ROUTER);

		_root.active_router = "RouterB";
		_root.VISIBLE_ROUTER = "RouterB";
		_root.utility_hideAll();
		_root.utility_updateText();

		_root.router_startup_checkStartUp();
		_root.output_setCursor();

	} else if (BUTTONROUTER == "RouterC") {
		// turn visibility to nil
		_root.Menu.mRouterC._visible = false;
		_root.HyperTerminal.sRouterC._visible = true;
		_root.utility_setVisible(_root.VISIBLE_ROUTER);

		_root.active_router = "RouterC";
		_root.VISIBLE_ROUTER = "RouterC";
		_root.utility_hideAll();
		_root.utility_updateText();

		_root.router_startup_checkStartUp();
		_root.output_setCursor();

	} else if (BUTTONROUTER == "RouterD") {
		// turn visibility to nil
		_root.Menu.mRouterD._visible = false;
		_root.HyperTerminal.sRouterD._visible = true;
		_root.utility_setVisible(_root.VISIBLE_ROUTER);

		_root.active_router = "RouterD";
		_root.VISIBLE_ROUTER = "RouterD";
		_root.utility_hideAll();
		_root.utility_updateText();

		_root.router_startup_checkStartUp();
		_root.output_setCursor();

	} else if (BUTTONROUTER == "RouterE") {
		// turn visibility to nil
		_root.Menu.mRouterE._visible = false;
		_root.HyperTerminal.sRouterE._visible = true;
		_root.utility_setVisible(_root.VISIBLE_ROUTER);

		_root.active_router = "RouterE";
		_root.VISIBLE_ROUTER = "RouterE";
		_root.utility_hideAll();
		_root.utility_updateText();

		_root.router_startup_checkStartUp();
		_root.output_setCursor();
	}

}

