
<!--
//**************************************************/
//  © 1997-2002  Nortia Technologies.   All rights reserved.
//
//	File:			incCOP.js		
//	Author(s):		ks
//  Created:		9/17/2003	
//	Description:	Common Community of Practice javascript functions
//	Dependencies:
//	Functions:		
//	Notes:
//	TODO:		
//	History:		07/19/2004 - Moved functions with language specific strings out, and non language functions in
//		
//**************************************************/

/* InvalidTextField(objField, strMsg)
		Alert the user of the invalid text field value.
		Set the focus to the text field.
*/
function InvalidTextField(objField, strMsg)
{
	if (strMsg != "") alert(strMsg);		
	objField.focus();
}

/* initPhoto(frm, index)
		Resize the photo being displayed on the page
		Must provide a handle to the photo to resize
*/


function initPhoto(objPhoto){
		
	if(objPhoto.width > objPhoto.height)
	{	
		if(objPhoto.width > 80) objPhoto.width = 80;
	}	
	else
	{
		if(objPhoto.height > 80) objPhoto.height = 80;
	}
	
}	

/*--------------------------------------------------------------------
SelectAddRemoveMeetingUsers()
Usage:	Add and remove options to and from the Meeting User select boxes.
		Updates the Moderator list

Input:  blnIsAdd - true for adding, false for removing

--------------------------------------------------------------------*/
function SelectAddRemoveMeetingUsers(blnIsAdd)
{
    var i = 0;
	
	// form elements
	var objForm = document.frmLMEdit;
	var selRemove = objForm.selRemoveUser;
	var selAdd = objForm.selAddUser;
	
	var objSource = selAdd;
	var objDest = selRemove;
	
	if (blnIsAdd)
	{
		objSource = selRemove;
		objDest = selAdd;
	}
	
	// copy the option from the source list to the destination list
	for (i=0; i<objSource.length; i++)
	{
		if (objSource.options[i].selected)
		{
			if (blnIsAdd && objDest.length == MAX_PARTICIPANTS)
			{
				alert(maxParticipantsMsg);
				return;
			}
			objDest.options[objDest.length] = new Option(objSource.options[i].text, objSource.options[i].value);
			objSource.options[i] = null;
			i--;
		}
	}
}
/*--------------------------------------------------------------------
function EnableSeats()
Usage:	Enable / Disable the input box for private seats for meeting edits
		
Input:  blnPrivate - true if the meeting is private, false if not

--------------------------------------------------------------------*/
function EnableSeats(blnPrivate)
{
    
    var objInput = document.frmLMEdit.txtSeats;
    
    blnPrivate? objInput.disabled=true : objInput.disabled=false;
    
}

/*--------------------------------------------------------------------
function ValidateNumeric()
Usage:	Checks an input box for a numeric value, removes non-digits
		
Input:  objField - the text field to check

--------------------------------------------------------------------*/
function ValidateNumeric(objField)
{
	var str = objField.value;
		
	str = str.replace(/\D/gi, '') // remove non-digits
	
	objField.value = str;
			
}

/*--------------------------------------------------------------------
function initTime()
Usage:	Sets the starting time of a meeting based on the client's current time
		and then adjusts the hours to one in advance
		
Input:  none;

--------------------------------------------------------------------*/	
function initTime()
{
	var objForm = document.frmLMEdit;
		
	// set the default dates and times
	with (objForm)
	{
		SetTimeAndZone(selTimeStartHour, selTimeEndHour, selYear, selMonth, selDay, selTimeZone);
			
		// increment the starting hour by one
		if (selTimeStartHour.selectedIndex < selTimeStartHour.length-1)
		{
			selTimeStartHour.selectedIndex += 1;
			selTimeEndHour.selectedIndex = selTimeStartHour.selectedIndex + 1;
		} else{			
			selTimeStartHour.selectedIndex = 0;
			selTimeEndHour.selectedIndex = 1;
		}	
	}	
}

/*--------------------------------------------------------------------
function ValidateTime()
Usage:	Ensures that a meeting is scheduled for at least 10 mins into the future
		
Input:  None

Output: A code representing the status of the time of the meeting compared to the current system time:
		0 - Meeting is ahead of the grace period
		1 - Meeting has not started, but within the grace period
		2 - Meeting has started
		3 - Meeting has expired

Notes:  This function gets the values for the meeting date from select boxes or hidden input
        boxes only
        A date object: dtSysTime must be created before using
        2 arrays : arrZoneID and arrZoneOffSet must be created
			These are parallel arrays that represent the time zone ids and offsets for those time zones
--------------------------------------------------------------------*/
function ValidateTime(grace)
{
	
	return true;
	var objForm = document.frmLMEdit;
	var offsetMins = 0;
	var year;
	var month;
	var day;
	var hour;
	var minute;
	var zoneID;
	var hourend;
	var minuteend;
		
	if (objForm.selYear.tagName=="SELECT")
	{
		year = objForm.selYear[objForm.selYear.selectedIndex].value;
		month = objForm.selMonth[objForm.selMonth.selectedIndex].value - 1;
		day = objForm.selDay[objForm.selDay.selectedIndex].value;
		hour = objForm.selTimeStartHour[objForm.selTimeStartHour.selectedIndex].value;
		minute = objForm.selTimeStartMinute[objForm.selTimeStartMinute.selectedIndex].value;
		zoneID = objForm.selTimeZone[objForm.selTimeZone.selectedIndex].value;
		hourend = objForm.selTimeEndHour[objForm.selTimeEndHour.selectedIndex].value;
		minuteend = objForm.selTimeEndMinute[objForm.selTimeEndMinute.selectedIndex].value;
	} else {
		year = objForm.selYear.value;
		month = objForm.selMonth.value - 1;
		day = objForm.selDay.value;
		hour = objForm.selTimeStartHour.value;
		minute = objForm.selTimeStartMinute.value;
		zoneID = objForm.selTimeZone.value;
		hourend = objForm.selTimeEndHour.value;
		minuteend = objForm.selEndHour.value;
	}
		
	var dtMeeting = new Date(year, month, day, hour, minute);
	
	for (var i=0; i<arrZoneID.length; i++)
	{
		if (arrZoneID[i]==zoneID)
		{
			offsetMins = (arrZoneOffSet[i] * 60); // convert the hour offset to mins
			break;
		}
	}
		
	dtMeeting.setMinutes(dtMeeting.getMinutes() + offsetMins); // convert the minutes to the time zone given
	
	var dtMeetingEnd = newDate(dtMeeting); // make a copy of the meeting date
	
	
	dtMeeting.setMinutes(dtMeeting.getMinutes() - grace); // adjust the meeting time with the grace period
	
		
	//alert (dtMeetingEnd + " " + dtMeeting);
	//alert(dtMeeting.getTime());
	return false;
	
	return (dtMeeting > dtSysTime);
}

/*--------------------------------------------------------------------
function COPIsEmailValid()
Usage:	Checks an e-mail address to see if it's valid.  Returns true if it is
		
		
Input:  the address to validate

--------------------------------------------------------------------*/	
function COPIsEmailValid(address)
{
	// regular expression to validate the e-mail address
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
			
	return re.test(address);
}

/*--------------------------------------------------------------------
function COPCheckKey(e)
Usage:	Submits a form if the user presses enter on a text field
		
Input:  e - the key pressed
		
Return: true if the enter key was pressed
--------------------------------------------------------------------*/	
function COPCheckKey(e)
{
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;
	
	return false;
}

/*--------------------------------------------------------------------
function COPCheckAll()
Usage:	Checks / unchecks all the boxes in checkbox collection
		
Input:  e - the key pressed
		
Return: nothing
--------------------------------------------------------------------*/	
function COPCheckAll(blnCheck, name)
{

	var arrCheck = document.getElementsByName(name);
	var i;
	
	if (blnCheck)
	{
		for (i=0; i<arrCheck.length; i++) {arrCheck[i].checked=true}
	} else {
		for (i=0; i<arrCheck.length; i++) {arrCheck[i].checked=false}
	}
	
	return;
		
}

/*--------------------------------------------------------------------
function COPValidateCC()
Usage:	Validates the CC field when sending Live Meeting e-mail notifications
		
Input: None
		
Return: true if valid, false if not
--------------------------------------------------------------------*/	
function COPValidateCC()
{
	var strAddress = document.frmLMEdit.txtCC.value.replace(/ /gi, ";"); // add semicolons where necessary
			
	var arrAddress = strAddress.split(";");
	var blnValid = true;
			
	strAddress = ""; // reset the address holder
	
	// loop through and test each e-mail address
	for (var i=0; i<arrAddress.length; i++)
	{
		arrAddress[i]=trim(arrAddress[i]);
		if (arrAddress[i]!="")
		{
			if (COPIsEmailValid(arrAddress[i]))
			{
				strAddress+=arrAddress[i] + " " // rebuild the address list with valid addresses
			} else {
				blnValid = false;  // flag it false
			}
		}
	} 
			
	strAddress = trim(strAddress);
	strAddress = strAddress.replace(/ /gi, ";");
			
	document.frmLMEdit.txtCC.value = strAddress;
			
	return blnValid;
}

/*--------------------------------------------------------------------
function COPOrderForm()
Usage:	Orders a form on the field given
		
Input:	strField - the name of the field to order on
		
Return: Nothing
--------------------------------------------------------------------*/	
function COPOrderForm(strField)
{
	var oForm = document.frmCOPSearch;
	var oField = oForm.txtCOPOrderField;
	
	oField.value = strField;
								
	oForm.submit();
	
}

/*--------------------------------------------------------------------
function SearchCOP()
Usage:	Validates the search field and submits the search form
		
Input:	blnUseSearchText - true to use the value entered in the search field, false to reset
		
Return: Nothing
--------------------------------------------------------------------*/	
function SearchCOP(blnUseSearchText)
{
	var oSearch = document.frmCOPSearch.txtCOPSearchField;
	
	if (blnUseSearchText && trim(oSearch.value)=="")
	{
		return; // do nothing if no search text was entered
	} 
	else
	{
		if (!blnUseSearchText) document.frmCOPSearch.txtCOPSearchField.value = "";
	}
	
	document.frmCOPSearch.submit();
	
}
