//////////////////////////////////////////////////////////////////////////////////////
// Sets a hidden input element (name="forward") in the nth form of the
// document to the value give by target.

function setSubmitTarget(target,nthForm) {
     document.forms[nthForm].forward.value=target;
};

//////////////////////////////////////////////////////////////////////////////////////

// SETUP MOUSE TRACKING for use in positioning popup windows
// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.

if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has 
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position 
        // reflects the position from the top/left of the screen the 
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no 
        // matter if the user has scrolled or not.
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard 
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    //window.status = "xMousePos=" + xMousePos + ", yMousePos=" + yMousePos + ", xMousePosMax=" + xMousePosMax + ", yMousePosMax=" + yMousePosMax;
    
}

//////////////////////////////////////////////////////////////////////////////////////

// Redirect to one of the device settings pages based on the selected item in
// the given <select> object

function doChangeSettingsWindow(obj)
{
	switch (obj.selectedIndex)
	{
		case 0:	window.location.href = "deviceSettings.do"; break;
		case 1: window.location.href = "deviceSwitches.do"; break;
		case 2: window.location.href = "deviceAlerts.do"; break;
		case 3: window.location.href = "devicePower.do"; break;
		case 4: window.location.href = "changePassword.do"; break;
	}
}

//////////////////////////////////////////////////////////////////////////////////////

// Redirect to one of the device settings pages based on the selected item in
// the given <select> object

function doChangeGamesWindow(obj)
{
	switch (obj.selectedIndex)
	{
		case 0: window.location.href = "deviceCountdowns.do"; break;
		case 1:	window.location.href = "deviceHangmanList.do"; break;
	}
}

//////////////////////////////////////////////////////////////////////////////////////

// Popup a calendar window at the current mouse position. The date picker will place
// the selected date in form element indicatd by elem. See cal1/Calendar1-901.js

function doDatePick(elem, m, y)
{
	show_calendar(elem,y, m, 'MM/DD/YY', null, 'PopupX='+(xMousePos+150)+';PopupY='+ (yMousePos+150) +';AllowWeekends=Yes;Title=Select a Date;');
}

//////////////////////////////////////////////////////////////////////////////////////

// Popup a time selection window at the current mouse position. The  time picker will place
// the selected time in the form element indicated by ob. See timepicker.htm.

function doTimePick(ob)
{
	document.timefield = ob;
	var args = "width=225, height=60, top=" + yMousePos + ", left=" + xMousePos + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no";
	w= window.open("timepicker.htm", "TimeSelector", args);
}

//////////////////////////////////////////////////////////////////////////////////////

// Check/Uncheck all of the checkboxes with the name given by control that exist in
// the given form. Toggle the state of the first checkbox found, and similarly for 
// all subsequent checkboxes.

function selAllCheckboxes(theForm,control)
{
	var formElements = theForm.elements; //EditToDoListForm.elements;
	var tog;
	var onoff;
	
	tog = 0;
	onoff = true;
	
    for (i=0; i<formElements.length; i++)
    {
 		if (formElements[i].name== control) //"selectedItems")
		{
			if (tog == 0)
			{
				if (formElements[i].checked)
					onoff = false;
				else
					onoff = true;
				tog = 1;
			}
		}
        formElements[i].checked = onoff;
    }
}

// Popup a window with help information 

 	function showHelp(name)
	{
	     showHelp(name,"fixed");
	}

 	function showHelp(name, strType)
	{
	     var helpName = "help/" + name +  ".htm";
	     var strWidth=300;
	     var strHeight=500;
 	     var args = "width=300, height=500, top=" + yMousePos + ", left=" + xMousePos + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=no";
		if (strType=="console") args="resizable,height="+strHeight+",width="+strWidth;
		if (strType=="fixed") args="status,height="+strHeight+",width="+strWidth;
		if (strType=="elastic") args="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	     w= window.open(helpName, "TicTalkHelp", args);
	     if (window.focus) {w.focus();}
	}


	function findAttachedPhone()
	{
		browserSniffer();
		if (!is_ie || !isWinOS()) // if not a WindowsOS or not IE, don't bother...our USB drivers are Win-only, and ActiveX comport is IE-only.
		{
			alert("We're sorry, but you may interact with your TicTalk over the USB at this time only with a Windows PC and Internet Explorer. (Windows NT not supported)");
			return false; 
		}
		else
		{
			
			return confirm("PHONE STATUS ICON: Blue \"COMM\" = Your phone is talking to our servers. Gray \"COMM\" = your phone is not talking to our servers.\n\nTO INTERACT WITH YOUR TICTALK OVER USB...\n\nConnect your TicTalk to your PC using the USB cable.\nThen click OK to search for your TicTalk attached to your PC via USB. If your phone is detected, this button will show a blue USB.\n\nMake sure you have downloaded and installed the TicTalk USB drivers.\n(See the \"Photos\" box on your home page for more information, or visit the HELP page for detailed step-by-step instructions.)\n\nAlso make sure that your IE security settings are set properly: \n\nIn your Internet Explorer browser:\n   * Select the Tools menu\n   * Click on Internet Options...\n   * Click Security tab\n   * Click on Trust Sites icon\n   * Click on Sites... button\n   * Add www.mytictalk.com to your trusted sites zone.\n\nYou may also need to adjust your ActiveX settings: \n   * Click Custom Level... button\n   * Set all \"ActiveX controls and Plugins\" options to \"Enable\" or \"Prompt\" ");
		}
	}
 


   