//*********************************************************
// Purpose:  Left trim a string
// Inputs:   as_value - string to left trim
// Returns:  The left trimmed string.
//           
// Change History: 
//	Do not include author, visible to client, 08/30/99
//		Created
//*********************************************************

function ltrim(as_value) 
{
	while (1) 
	{
		if (as_value.substring(0, 1) != " ")
			break;
		as_value = as_value.substring(1, as_value.length);
	}
	return as_value;
} 

//*********************************************************
// Purpose:  Right trim a string
// Inputs:   as_value - string to right trim
// Returns:  The right trimmed string.
//           
// Change History: 
//	Do not include author, visible to client, 08/30/99
//		Created
//*********************************************************

//function rtrim(as_value) 
//{
//	while (1) 
//	{
//		if (as_value.substring(as_value.length - 1, as_value.length) != " ")
//			break;
//		as_value = as_value.substring(0, as_value.length - 1);
//	}
//	return as_value;
//} 

function RTrim(str)
{
	// We don't want to trip JUST spaces, but also tabs,
	// line feeds, etc.  Add anything else you want to
	// "trim" here in Whitespace
	var whitespace = new String(" \t\n\r");

	var s = new String(str);

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		// We have a string with trailing blank(s)...

		var i = s.length - 1;       // Get length of string

		// Iterate from the far right of string until we
		// don't have any more whitespace...
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;

			// Get the substring from the front of the string to
			// where the last non-whitespace character is...
			s = s.substring(0, i+1);
		}
	return s;
}



//*********************************************************
// Purpose:  Trim a string (both right and left sides
// Inputs:   as_value - string to trim
// Returns:  The trimmed string.
//           
// Change History: 
//	Do not include author, visible to client, 08/30/99
//		Created
//*********************************************************

function trim(as_value)
{
	return RTrim(ltrim(as_value));
} 

//*********************************************************
// Purpose:  creates a comma delimited string of values
//           based on what checkboxes are selected
// Inputs:   n/a
// Returns:  The comma delimited string
//           
// Change History: 
//	Do not include author, visible to client, 03/24/2000
//		03-24-2000	Created
//		07-13-2000	Added VerifyInstall function call to form
//*********************************************************

function selectRows(URL,CallingFunction)
	{	
	//define variables
	var vstrSelectedFields;
	var uu;
	var rr;
	var checkedCount;
	var arrSelectedFields;
	var strParmValues;
	var strMessage;
	var booDelete;
	
	//define 'constants'
	var NUM_OF_ELEMENTS;
	var ELEMENT;
	var FOLDERID;
	var PASSBACKORIGINPAGE;
	var PASSEDINFO;
	
	//initialize variables	
	vstrSelectedFields = "";
	strParmValues = "";
	checkedCount = 0;
	strMessage = "";
	
	//initialize constants
	NUM_OF_ELEMENTS = 8;
	FOLDERID = 7;
			
	//initialize according to calling page and calling function
	if (document.forms['frmSelections'].txtPageMinor.value == "Folders")	//get folder id's
		{
		ELEMENT = FOLDERID;
		PASSEDINFO = "FOLDERID";
		if (CallingFunction == "Delete")
			{
			booDelete = confirm("Are you sure you want to delete the selected folder(s)? Click 'OK' to continue.");
			if (booDelete == false)
				{
				strMessage = "Delete cancelled.";
				}
			}
		}
	else
		{
		if (CallingFunction == "Voicemail" || CallingFunction == "BuddyChat")	//get member id's
			{
			ELEMENT = 2;
			PASSEDINFO = "MEMBERID";
			//Verify user has the recorder software installed ONLY for Voicemail!
			//	if (CallingFunction == "Voicemail")
			//	{
			//		if (VerifyInstall() == "1")
			//		{
			//			document.forms['frmSelections'].SoftwareVerified.value = "1"
			//		}
			//	}
			}
		else
			{
			if (CallingFunction == "AddContact")	//get pcn's
				{
				ELEMENT = 3;
				PASSEDINFO = "PCN";
				}
			else
				{
				if (CallingFunction == "NotifyOnline")   //get contact id's
					{
					ELEMENT = 6;
					PASSEDINFO = "CONTACTID";
					}
				else
					{
					if (CallingFunction == "Delete")
						{
						if (document.forms['frmSelections'].txtPageMinor.value == "Incoming Log" || document.forms['frmSelections'].txtPageMinor.value == "Outgoing Log")	//get call id's
							{
							ELEMENT = 6;
							PASSEDINFO = "CALLID";
							}
						else
							{
							if (document.forms['frmSelections'].txtPageMajor.value == "Mailbox")	//get voicemail id's
								{
								ELEMENT = 5;
								PASSEDINFO = "VOICEMAILID";
								}
							else
								{
								if (document.forms['frmSelections'].txtPageMinor.value == "Contacts" || document.forms['frmSelections'].txtPageMinor.value == "Folder Contents")	//get contact id's
									{
									ELEMENT = 6;
									PASSEDINFO = "CONTACTID";
									} 
								if (document.forms['frmSelections'].txtPageMinor.value == "Contacts")
									{
									booDelete = confirm("This will delete all record of this contact. Click 'OK' to continue.");
									if (booDelete == false)
										{
										strMessage = "Delete cancelled.";
										}
									}
								}
							}
						}
					else
						{
						if (CallingFunction == "AddToFolder")
							{
							if (document.forms['frmSelections'].txtPageMinor.value == "Contacts") //get contact id's
								{
								ELEMENT = 6;
								PASSEDINFO = "CONTACTID";
								PASSBACKORIGINPAGE = "/commsite/contacts/contacts.asp"
								}
							else
								{
								if (document.forms['frmSelections'].txtPageMinor.value == "Folder Contents") //get contact id's
									{
									ELEMENT = 6;
									PASSEDINFO = "CONTACTID";
									PASSBACKORIGINPAGE = "/commsite/contacts/contactfolders.asp"
									}
								}
							}
						}
					}
				}
			}
		}
	
	//loop thru check boxes and determine which ones are checked
	for (uu = 0; uu < document.forms['frmTableAction'].length; uu++)
		{			
		if ( (document.forms['frmTableAction'].elements[uu].type) == "checkbox")
			{
			if (document.forms['frmTableAction'].elements[uu].checked == true)
				{	
				checkedCount = checkedCount + 1;				
				vstrSelectedFields = vstrSelectedFields + document.forms['frmTableAction'].elements[uu].value;
				}
			}
		}
	
	//if some are checked, create the appropriate parm string to send to next page
	if (vstrSelectedFields != "")
		{
		document.forms['frmSelections'].action = URL;
		//split string into an array
		arrSelectedFields = vstrSelectedFields.split("|");
		//if coming from delete function on contacts page, get folder id
		if (CallingFunction == "Delete" && document.forms['frmSelections'].txtPageMajor.value == "Contacts")
			{
			document.forms['frmSelections'].txtFolderID.value = arrSelectedFields[FOLDERID];
			}
		//loop thru array to grab the info needed
		for (rr = ELEMENT; rr < arrSelectedFields.length; rr=rr + NUM_OF_ELEMENTS)
			{
			//do not include non-members in 'NotifyWhenOnline', 'MultipleRecipientVoicemail', or 'InviteToBuddyChat' functions
			if (CallingFunction != "Delete" && CallingFunction != "AddToFolder" && document.forms['frmSelections'].txtPageMajor.value == "Contacts" && arrSelectedFields[rr] == "")
				{
				strMessage = "Non-members are not eligible for this function.";
				}
			else
				{
				if (strParmValues == "")
					{
					strParmValues = arrSelectedFields[rr];
					}
				else
					{
					strParmValues = strParmValues + "," + arrSelectedFields[rr];
					}
				}
			}
		if (strMessage != "")
			{
			alert(strMessage);
			}
		else
			{
			document.forms['frmSelections'].txtSelected.value = strParmValues;
			document.forms['frmSelections'].txtPassBackOriginPage.value = PASSBACKORIGINPAGE;
			document.forms['frmSelections'].txtPassedInfo.value = PASSEDINFO;
			document.forms['frmSelections'].txtCallingFunction.value = CallingFunction;
			
			document.forms['frmSelections'].submit();
			}
		}
	else  //if no boxes are checked, put up message
		{
		alert("Please make your selections.")
		}
	}
	
	function LaunchRecorder(sMode, sParamList) {
	var winHeight = 650		//ActiveRecorder.Height;
	var winWidth = 513		//ActiveRecorder.Width;
	var leftX = ((screen.width / 2) - (winWidth / 2)) ;
	var topY = ((screen.height / 2) - (winHeight / 2));

	var sURL =  "/CommSite/Secure/Recorder.asp?";
	
	var sLoc = ",width=" + winWidth + ",height=" + winHeight;		
	sLoc = sLoc + ",screenX=" +  leftX  + ",screenY=" + topY + ",left=" + leftX + ",top=" +  topY;

	if (sMode == "") {
		alert('You have not specified a Mode for the recorder/player, this is a required parameter.')
		return false;
	}
	
	if (sParamList == "") {
		alert('You have not specified a ParamList for the recorder/player, this is a required parameter.')
		return false;
	}
	
	sURL =  sURL + "Mode=" + sMode + sParamList;
	
	window.open(sURL, "Recorder", sLoc);
	return true;
}
