/****************************************************************************/
/*																			*/
/*		 N L 2 G U I . J S													*/
/*		===================													*/
/*																			*/
/*	Routines to manipulate the entity list pages.							*/
/*	Part of the ADM - NFB's Newsline II administration sub-system.			*/
/*																			*/
/*--------------------------------------------------------------------------*/
/*																			*/
/*	Written by: Abraham Zeira.												*/
/*	Written at: Aug-05-2001.												*/
/*	Written in: Ramis Technologies, Inc., Rockville MD.						*/
/*																			*/
/*--------------------------------------------------------------------------*/
/*																			*/
/*	Last updated: Aug-05-2001	- Initial authoring.						*/
/*																			*/
/****************************************************************************/


/*---------------------------------------------------------------------------
   Initialize  -  initializes the variables for this page.
  ---------------------------------------------------------------------------*/

function Initialize()
{
	var			newImage;

	pageName	= document.title;

    if (numLines > 0)
    {
		newImage		= document.images["Line" + currLine];
        newImage.src	= "images/Selected.jpg";
		document.title	= pageName + " - " + newImage.alt;
    }

} /* end function Initialize */


/*---------------------------------------------------------------------------
   SelectLine  -  selects a line in a list.
  ---------------------------------------------------------------------------*/

function SelectLine(newLine, entityId)
{
	var			oldImage, newImage;

	if (newLine >= numLines)
		newLine	= numLines - 1;

	oldImage		= document.images["Line" + currLine];
	newImage		= document.images["Line" + newLine];
	oldImage.src	= "images/Normal.jpg";
	newImage.src	= "images/Selected.jpg";
	document.title	= pageName + " - " + newImage.alt;

	currLine		= newLine;
	currId			= entityId;

} /* end function SelectLine */


/*---------------------------------------------------------------------------
   InitPhoneEvents  -  initializes the event handlers.
  ---------------------------------------------------------------------------*/

function InitPhoneEvents()
{
	document.UserInputForm.HomePhoneEdt.onFocus	= PhoneOnFocus;
	document.UserInputForm.HomePhoneEdt.onBlur	= PhoneOnBlur;

} /* end function InitPhoneEvents */


/*---------------------------------------------------------------------------
   PhoneOnFocus  -  handles the event of the phone field receiving focus.
  ---------------------------------------------------------------------------*/

function PhoneOnFocus()
{
	oldPhoneNum		= document.UserInputForm.HomePhoneEdt.value;

} /* end function PhoneOnFocus */


/*---------------------------------------------------------------------------
   PhoneOnBlur  -  handles the event of the phone field losing focus.
  ---------------------------------------------------------------------------*/

function PhoneOnBlur()
{
	var			errorMsg;

	newPhoneNum		= document.UserInputForm.HomePhoneEdt.value;

	if (oldPhoneNum != newPhoneNum)
	{
		errorMsg	=
			"You have changed the Home Phone Number of " +
			"this Subscriber.  If the Area Code has changed " +
			"then this Subscriber will be transferred to the " +
			"Sponsor corresponding to the new Area code. " +
			"Are you sure you want to change this Subscriber's " +
			"Home Phone Number?";

		if (confirm(errorMsg) == false)
		{
			document.UserInputForm.HomePhoneEdt.value	=
				oldPhoneNum;
		}
	}

} /* end function PhoneOnBlur */


/*---------------------------------------------------------------------------
   InsertAdmin  -  calls the administrator's insert routine.
  ---------------------------------------------------------------------------*/

function InsertAdmin()
{
	self.location	=
		"ADMAdminInput.jsp?AdminIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function InsertAdmin */


/*---------------------------------------------------------------------------
   UpdateAdmin  -  calls the administrator's update routine.
  ---------------------------------------------------------------------------*/

function UpdateAdmin()
{
	if (numLines < 1)
	{
		alert("There are no Administrator to update!");
		return;
	}

	self.location	=
		"ADMAdminInput.jsp?AdminIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function UpdateAdmin */


/*---------------------------------------------------------------------------
   DeleteAdmin  -  calls the administrator's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteAdmin()
{
	if (numLines < 1)
	{
		alert("There are no Administrator to delete!");
		return;
	}

	parent.location	=
		"ADMAdminDelete.jsp?AdminIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteAdmin */


/*---------------------------------------------------------------------------
   ViewADMAgentsList  -  calls the agents list's view routine.
  ---------------------------------------------------------------------------*/

function ViewADMAgentsList()
{
	if (numLines < 1)
	{
		alert("There are no Sponsors to view their Agents!");
		return;
	}

	parent.location	=
		"ADMAgentsList.jsp?CurrentSponsor=" + currId +
		"&LineIdParam=" + currLine;

} /* end function ViewADMAgentsList */


/*---------------------------------------------------------------------------
   ViewADMPapersList  -  calls the agents list's view routine.
  ---------------------------------------------------------------------------*/

function ViewADMPapersList()
{
	if (numLines < 1)
	{
		alert("There are no Sponsors to view their Agents!");
		return;
	}

	parent.location	=
		"ADMSpnPapersList.jsp?CurrentSponsor=" + currId +
		"&LineIdParam=" + currLine;

} /* end function ViewADMPapersList */


/*---------------------------------------------------------------------------
   InsertADMAgent  -  calls the agent's insert routine.
  ---------------------------------------------------------------------------*/

function InsertADMAgent()
{
	self.location	=
		"ADMAgentInput.jsp?AgentIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function InsertADMAgent */


/*---------------------------------------------------------------------------
   UpdateADMAgent  -  calls the agent's update routine.
  ---------------------------------------------------------------------------*/

function UpdateADMAgent()
{
	if (numLines < 1)
	{
		alert("There are no Agents to update!");
		return;
	}

	self.location	=
		"ADMAgentInput.jsp?AgentIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function UpdateAgent */


/*---------------------------------------------------------------------------
   DeleteADMAgent  -  calls the agent's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteADMAgent()
{
	if (numLines < 1)
	{
		alert("There are no Agents to delete!");
		return;
	}

	parent.location	=
		"ADMAgentDelete.jsp?AgentIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteADMAgent */


/*---------------------------------------------------------------------------
   ViewADMUsersList  -  calls the users list's view routine.
  ---------------------------------------------------------------------------*/

function ViewADMUsersList()
{
	if (numLines < 1)
	{
		alert("There are no Sponsors to view their Subscribers!");
		return;
	}

	parent.location	=
		"ADMUsersList.jsp?CurrentSponsor=" + currId +
		"&LineIdParam=" + currLine;

} /* end function ViewADMUsersList */


/*---------------------------------------------------------------------------
   ViewADMUsersReports  -  calls the users reports' view routine.
  ---------------------------------------------------------------------------*/

function ViewADMUserReport()
{
	if (numLines < 1)
	{
		alert("There are no Sponsors to view their Subscribers Reports!");
		return;
	}

	parent.location	=
		"ADMSubssReport.jsp?CurrentSponsor=" + currId +
		"&LineIdParam=" + currLine;

} /* end function ViewADMUsersList */


/*---------------------------------------------------------------------------
   InsertADMSubs  -  calls the subscriber's insert routine.
  ---------------------------------------------------------------------------*/

function InsertADMSubs()
{
	self.location	=
		"ADMSubsInput.jsp?UserIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function InsertADMSubs */


/*---------------------------------------------------------------------------
   UpdateADMSubs  -  calls the subscriber's update routine.
  ---------------------------------------------------------------------------*/

function UpdateADMSubs()
{
	if (numLines < 1)
	{
		alert("There are no Subscriber to update!");
		return;
	}

	self.location	=
		"ADMSubsInput.jsp?UserIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function UpdateADMSubs */


/*---------------------------------------------------------------------------
   DeleteADMSubs  -  calls the subscriber's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteADMSubs()
{
	if (numLines < 1)
	{
		alert("There are no Subscriber to delete!");
		return;
	}

	parent.location	=
		"ADMSubsDelete.jsp?UserIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteADMSubs */


/*---------------------------------------------------------------------------
   InsertADMUser  -  calls the user's insert routine.
  ---------------------------------------------------------------------------*/

function InsertADMUser()
{
	self.location	=
		"ADMUserInput.jsp?UserIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function InsertADMUser */


/*---------------------------------------------------------------------------
   UpdateADMUser  -  calls the user's update routine.
  ---------------------------------------------------------------------------*/

function UpdateADMUser()
{
	if (numLines < 1)
	{
		alert("There are no Users to update!");
		return;
	}

	self.location	=
		"ADMUserInput.jsp?UserIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function UpdateADMUser */


/*---------------------------------------------------------------------------
   DeleteADMUser  -  calls the user's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteADMUser()
{
	if (numLines < 1)
	{
		alert("There are no Users to delete!");
		return;
	}

	parent.location	=
		"ADMUserDelete.jsp?UserIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteADMUser */


/*---------------------------------------------------------------------------
   InsertSPNAgent  -  calls the agent's insert routine.
  ---------------------------------------------------------------------------*/

function InsertSPNAgent()
{
	self.location	=
		"SPNAgentInput.jsp?AgentIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function InsertSPNAgent */


/*---------------------------------------------------------------------------
   UpdateSPNAgent  -  calls the agent's update routine.
  ---------------------------------------------------------------------------*/

function UpdateSPNAgent()
{
	if (numLines < 1)
	{
		alert("There are no Agents to update!");
		return;
	}

	self.location	=
		"SPNAgentInput.jsp?AgentIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function UpdateSPNAgent */


/*---------------------------------------------------------------------------
   DeleteSPNAgent  -  calls the agent's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteSPNAgent()
{
	if (numLines < 1)
	{
		alert("There are no Agents to delete!");
		return;
	}

	parent.location	=
		"SPNAgentDelete.jsp?AgentIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteSPNAgent */


/*---------------------------------------------------------------------------
   InsertSPNUser  -  calls the user's insert routine.
  ---------------------------------------------------------------------------*/

function InsertSPNUser()
{
	self.location	=
		"SPNUserInput.jsp?UserIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function InsertSPNUser */


/*---------------------------------------------------------------------------
   UpdateSPNUser  -  calls the user's update routine.
  ---------------------------------------------------------------------------*/

function UpdateSPNUser()
{
	if (numLines < 1)
	{
		alert("There are no Users to update!");
		return;
	}

	self.location	=
		"SPNUserInput.jsp?UserIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=UserInp";

} /* end function UpdateSPNUser */


/*---------------------------------------------------------------------------
   DeleteSPNUser  -  calls the user's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteSPNUser()
{
	if (numLines < 1)
	{
		alert("There are no Users to delete!");
		return;
	}

	parent.location	=
		"SPNUserDelete.jsp?UserIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteSPNUser */


/*---------------------------------------------------------------------------
   InsertChannel  -  calls the channel's insert routine.
  ---------------------------------------------------------------------------*/

function InsertChannel()
{
	self.location	=
		"SPNChannelInput.jsp?ChannelIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=ChannelInp";

} /* end function InsertChannel */


/*---------------------------------------------------------------------------
   UpdateChannel  -  calls the channel's update routine.
  ---------------------------------------------------------------------------*/

function UpdateChannel()
{
	if (numLines < 1)
	{
		alert("There are no Channels to update!");
		return;
	}

	self.location	=
		"SPNChannelInput.jsp?ChannelIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=ChannelInp";

} /* end function UpdateChannel */


/*---------------------------------------------------------------------------
   DeleteChannel  -  calls the channel's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteChannel()
{
	if (numLines < 1)
	{
		alert("There are no Channels to delete!");
		return;
	}

	parent.location	=
		"SPNChannelDelete.jsp?ChannelIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteChannel */


/*---------------------------------------------------------------------------
   ViewSectionsList  -  calls the sections list's view routine.
  ---------------------------------------------------------------------------*/

function ViewSectionsList()
{
	if (numLines < 1)
	{
		alert("There are no Channels to view their sections!");
		return;
	}

	parent.location	=
		"SPNChanSecsList.jsp?CurrentChannel=" + currId +
		"&LineIdParam=" + currLine;

} /* end function ViewSectionsList */


/*---------------------------------------------------------------------------
   InsertSection  -  calls the section's insert routine.
  ---------------------------------------------------------------------------*/

function InsertSection()
{
	self.location	=
		"SPNChanSecInput.jsp?SectionIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=ChanSecInp";

} /* end function InsertSection */


/*---------------------------------------------------------------------------
   UpdateSection  -  calls the section's update routine.
  ---------------------------------------------------------------------------*/

function UpdateSection()
{
	if (numLines < 1)
	{
		alert("There are no Sections to update!");
		return;
	}

	self.location	=
		"SPNChanSecInput.jsp?SectionIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=ChanSecInp";

} /* end function UpdateSection */


/*---------------------------------------------------------------------------
   DeleteSection  -  calls the section's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteSection()
{
	if (numLines < 1)
	{
		alert("There are no Sections to delete!");
		return;
	}

	parent.location	=
		"SPNChanSecDelete.jsp?SectionIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteSection */


/*---------------------------------------------------------------------------
   ViewArticlesList  -  calls the articles list's view routine.
  ---------------------------------------------------------------------------*/

function ViewArticlesList()
{
	if (numLines < 1)
	{
		alert("There are no Sections to view!");
		return;
	}

	parent.location	=
		"SPNChanArtsList.jsp?CurrentSection=" + currId +
		"&LineIdParam=" + currLine;

} /* end function ViewArticlesList */


/*---------------------------------------------------------------------------
   InsertArticle  -  calls the article's insert routine.
  ---------------------------------------------------------------------------*/

function InsertArticle()
{
	self.location	=
		"SPNChanArtInput.jsp?ArticleIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=ChanArtInp";

} /* end function InsertArticle */


/*---------------------------------------------------------------------------
   UpdateArticle  -  calls the article's update routine.
  ---------------------------------------------------------------------------*/

function UpdateArticle()
{
	if (numLines < 1)
	{
		alert("There are no Articles to update!");
		return;
	}

	self.location	=
		"SPNChanArtInput.jsp?ArticleIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=ChanArtInp";

} /* end function UpdateArticle */


/*---------------------------------------------------------------------------
   DeleteArticle  -  calls the article's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteArticle()
{
	if (numLines < 1)
	{
		alert("There are no Articles to delete!");
		return;
	}

	parent.location	=
		"SPNChanArtDelete.jsp?ArticleIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteArticle */


/*---------------------------------------------------------------------------
   InsertPaper  -  calls the paper's insert routine.
  ---------------------------------------------------------------------------*/

function InsertPaper()
{
	self.location	=
		"ADMPaperInput.jsp?PaperIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=PaperInp";

} /* end function InsertPaper */


/*---------------------------------------------------------------------------
   UpdatePaper  -  calls the paper's update routine.
  ---------------------------------------------------------------------------*/

function UpdatePaper()
{
	if (numLines < 1)
	{
		alert("There are no Newspapers to update!");
		return;
	}

	self.location	=
		"ADMPaperInput.jsp?PaperIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=PaperInp";

} /* end function UpdatePaper */


/*---------------------------------------------------------------------------
   DeletePaper  -  calls the paper's delete routine.
  ---------------------------------------------------------------------------*/

function DeletePaper()
{
	if (numLines < 1)
	{
		alert("There are no Newspapers to delete!");
		return;
	}

	parent.location	=
		"ADMPaperDelete.jsp?PaperIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeletePaper */


/*---------------------------------------------------------------------------
   InsertSponsor  -  calls the sponsor's insert routine.
  ---------------------------------------------------------------------------*/

function InsertSponsor()
{
	self.location	=
		"ADMSponsorInput.jsp?SponsorIdParam=-1" +
		"&LineIdParam=" + currLine + "&FormIdParam=SponsorInp";

} /* end function InsertSponsor */


/*---------------------------------------------------------------------------
   UpdateSponsor  -  calls the sponsor's update routine.
  ---------------------------------------------------------------------------*/

function UpdateSponsor()
{
	if (numLines < 1)
	{
		alert("There are no Sponsors to update!");
		return;
	}

	self.location	=
		"ADMSponsorInput.jsp?SponsorIdParam=" + currId +
		"&LineIdParam=" + currLine + "&FormIdParam=SponsorInp";

} /* end function UpdateSponsor */


/*---------------------------------------------------------------------------
   DeleteSponsor  -  calls the sponsor's delete routine.
  ---------------------------------------------------------------------------*/

function DeleteSponsor()
{
	if (numLines < 1)
	{
		alert("There are no Sponsors to delete!");
		return;
	}

	parent.location	=
		"ADMSponsorDelete.jsp?SponsorIdParam=" + currId +
		"&LineIdParam=" + currLine;

} /* end function DeleteSponsor */


/*---------------------------------------------------------------------------
   Retrace  -  retraces back to a previous page.
  ---------------------------------------------------------------------------*/

function Retrace(level)
{
	switch (level)
	{
		case 1:
			self.location	= retracePage1;
			break;

		case 2:
			self.location	= retracePage2;
			break;
	}

} /* end function InsertSponsor */


/*===========================================================================*/
/* Rollover Functions and preloading images in top right of page.			 */
/*===========================================================================*/

/*---------------------------------------------------------------------------
   newImage  -  loads a new image and returns a reference to it.
  ---------------------------------------------------------------------------*/

function newImage(imageUrl)
{
	var		imagePtr;

	if (document.images != null)
	{
		imagePtr		= new Image();
		imagePtr.src	= imageUrl;
	}
	else
		imagePtr		= null;

	return (imagePtr);

} /* end function changeImages */


/*---------------------------------------------------------------------------
   changeImages  -  changes images when the mouse is over this place.
  ---------------------------------------------------------------------------*/

function changeImages()
{
	var			argInx, numArgs, imgInx;

	if ((document.images != null) && (isPreload == true))
	{
		numArgs	= changeImages.arguments.length;

		for (argInx = 0; argInx < numArgs; argInx += 2)
		{
			imgInx					=
				changeImages.arguments[argInx];
			document[imgInx].src	=
				changeImages.arguments[argInx + 1];
		}
	}

} /* end function changeImages */


/*---------------------------------------------------------------------------
   preloadImages  -  preloades images that are needed for the image change.
  ---------------------------------------------------------------------------*/

function preloadImages()
{
	if (document.images != null)
	{
		contactus_01over	=
			newImage("images/contactus_01over.gif");
		nfbhome_01over		=
			newImage("images/nfbhome_01over.gif");
		isPreloadFlag		= true;
	}

} /* end function preloadImages */


/****************************************************************************
/*---------------------------------------------------------------------------
   reportChkBox  -  reports the status of a checkbox.
  ---------------------------------------------------------------------------*/

function clickFunc(clkdButton)
{
	var				request;

//    alert("In clickFun.");
	if (httpReq == null)
		return;

	request			=
		"NOLTVSched.jsp?action=" + clkdButton.name;

//    alert("sending this request: " + request);
    httpReq.onreadystatechange = state_change;
	httpReq.open("GET", request, true);
	httpReq.send(null);

	}

    function state_change()
    {
        if (httpReq.readyState==4)
        {
            if (httpReq.status==200)
            {
                result  = httpReq.responseText.split("-*-");
                document.getElementById('sched').value = result[1];
                window.location = "#tvlisting";
                document.getElementById('sched').focus();
                loadHttpRequest();
            }
            else
            {
                alert("Communication error, please try your request again.");
                loadHttpRequest();
            }
    }
} /* end function reportChkBox */


/*---------------------------------------------------------------------------
   loadHttpRequest  -  reports the status of a checkbox.
  ---------------------------------------------------------------------------*/

function loadHttpRequest()
{
	httpReq			= null;

	if (window.XMLHttpRequest)
	{
		httpReq		= new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		httpReq		= new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (httpReq == null)
	{
		alert("Your browser does not support XMLHTTP.");
	}

} /* end function loadHttpRequest */

/*
   Global variables for this environment.
  ****************************************************************************/

currLine		= 0;
currId			= 0;
numLines		= 0;
isPreload		= false;
retracePage1	= "";
retracePage2	= "";
pageName		= "";
oldPhoneNum		= "";
newPhoneNum		= "";
httpReq         = null;

/* ------------------------- e n d   o f   f i l e ------------------------- */
