//initialize
var winVar = null;
var activeMenus = new menuset();

document.onclick = hideMenus;
window.onload = initPage;

//initPage: initializes a page after it loads
function initPage() 
{
	activeMenus.positionTimer = setInterval("positionAllMenus()",3000);
	
	togglePage();
		
}

//preloader------------------------------------------------------
imgArray = new Array(2);

imgArray[1] = "/en_US/images/nav/myIdcOn.gif";
imgArray[2] = "/en_US/images/nav/myIdcOff.gif";
imgArray[3] = "/en_US/images/nav/loginOn.gif";
imgArray[4] = "/en_US/images/nav/loginOff.gif";
imgArray[5] = "/en_US/images/nav/logoutOn.gif";
imgArray[6] = "/en_US/images/nav/logoutOff.gif";


for (var i = 1; i <= 6; i++)
{
	imgArray[i] = new Image;
}

// string trim functions
//
String.prototype.RTrim = function() { return this.replace(/\s+$/, ""); }
String.prototype.LTrim = function() { return this.replace(/^\s+/, ""); }
String.prototype.Trim = function() { return this.RTrim().LTrim(); }

//getPhoto: returns an image tag for the photo in left nav
function getPhoto()
{
	var x = 0;
	x = Math.random();
	x = parseInt(x*10);
	if (x == 0 || isNaN(x))
	{
	   x = 1;
	}
	var imgTag = "<img src='/images/pageImg/photo_leftbar_0" + x + ".gif' border='0' width='159' alt='Photo'>";
	return imgTag;
}

//mouseOver------------------------------------------------------	
function swapImg(imgName,imgState)
{
	var imgRef = getObj(imgName); 
	imgRef.src = "/en_US/images/nav/" + imgName + imgState + ".gif";
}	

//open New Window-----------------------------------------------
function openWindow(theURL,winName,features) 
{ 
	if (!winVar || winVar.closed)
	{
		winVar =  window.open(theURL,winName,features);
	} else
	{
		winVar.focus();
	}
}

//setUserName: puts a value into the userName cookie
function setUserNameCookie(oForm, bState)
{
	var oElements = oForm.elements;
	var iNumElements = oElements.length;
	
	//iterate through each element in the form
	for (var i=0; i < iNumElements; i++)
	{
		var eElement1 = oForm.elements[i];
		
		//look for an element is named "userName"
		if (eElement1.name == "userName")
		{
			//iterate through all the elements again
			//to find the "saveUserName" element
			for (var j=0; j < iNumElements; j++)
			{
				var eElement2 = oForm.elements[j];
				if (eElement2.name == "saveUserName")
				{
					//determine whether to save
					//the username or not
					var bToSave = eElement2.checked;
					
					//set the value of the saveUserName cookie
					setCookie("saveUserName",bToSave);
					if (bToSave)
					{
						//save the username in the cookie
						setCookie("userName",eElement1.value);
					}
					else
					{
						//save an empty string to the cookie
						setCookie("userName","");
					}
					return;
				}
			}
		}
	}
}

//setSaveUserName: sets the Checked property of the saveUserName checkbox
function setSaveUserName()
{
	var iNumForms = document.forms.length;
	for (var i=0; i < iNumForms; i++)
	{
		var oForm = document.forms[i];
		var oElements = oForm.elements;		
		var iNumElements = oElements.length;
		for (var j=0; j < iNumElements; j++)
		{
			var eElement = oForm.elements[j];
			if (eElement.name == "saveUserName")
			{
				if (getCookie("saveUserName"))
				{
					//if the cookie value is true, check the check box
					eElement.checked = true;
				}
				return;
			}
		}
	}
}

//selectCheckboxes------------------------------------------------------	
//this function sets all checkboxes on the page with the specified prefix
//to the specified state
function setCheckboxes(sPrefix,bState) 
{
	var bFound = false; //indicates whether a match was found
	var iPrefixLength = sPrefix.length;
	var numForms = document.forms.length;
	
	//go through each form in the document
	for (var i=0; i < numForms; i++) 
	{
		var eForm = document.forms[i];
		var numElements = eForm.elements.length
		
		//go through each element on the form
		for (var j=0; j < numElements; j++)
		{
			var eElement = eForm.elements[j];
			
			//see if the element is a checkbox
			if (eElement.type == "checkbox")
			{
				//see if the prefix matches
				if (eElement.name.substring(0,iPrefixLength) == sPrefix)
				{
				//track that a match has been found
				bFound = true;
				
				//set the state of the checkbox
				eElement.checked = bState
				}
				else
				{
				//if a match has already been found,
				//stop looking (assumes matches are contiguous)
				if (bFound)
					{
					return;
					}
				}
			}
		}
	}
}

//selectRadiobuttons------------------------------------------------------	
//this function selects all radio buttons on the page with the specified prefix
//and the specified value
function setRadiobuttons(sPrefix,sValue) 
{
	var iPrefixLength = sPrefix.length;
	var numForms = document.forms.length;
	
	//go through each form in the document
	for (var i=0; i < numForms; i++) 
	{
		var eForm = document.forms[i];
		var numElements = eForm.elements.length
		
		//go through each element on the form
		for (var j=0; j < numElements; j++)
		{
			var eElement = eForm.elements[j];
			
			//see if the element matches the type
			if (eElement.type == "radio")
			{
				//see if the prefix matches
				if (eElement.name.substring(0,iPrefixLength) == sPrefix)
				{
					if (eElement.value == sValue)
					{	
						//set the state of the radio button
						eElement.checked = true;
					}
				}
			}
		}
	}
}

function countRadiobuttons(sPrefix,sValue) 
{
	var iCount = 0;
	var iPrefixLength = sPrefix.length;
	var numForms = document.forms.length;
	
	//go through each form in the document
	for (var i=0; i < numForms; i++) 
	{
		var eForm = document.forms[i];
		var numElements = eForm.elements.length
		
		//go through each element on the form
		for (var j=0; j < numElements; j++)
		{
			var eElement = eForm.elements[j];
			
			//see if the element matches the type
			if (eElement.type == "radio")
			{
				//see if the prefix matches
				if (eElement.name.substring(0,iPrefixLength) == sPrefix)
				{
					if (eElement.value == sValue)
					{	
						//set the state of the radio button
						if (eElement.checked)
						{
							iCount += 1;
						}
					}
				}
			}
		}
	}
	return iCount;
}

//***** EXPAND/COLLAPSE FUNCTIONS

//toggle: toggles an element between hidden and visible
function toggle(sBlock) 
{
	var eBlock = getObj(sBlock);
	var sCurrentState = getCookie(sBlock);
	
	if (!sCurrentState)
	{
		sCurrentState = "true";
	}
	
	if (sCurrentState == "true") 
	{
		if (!mBrowser.isNS4)
		{
			//hide the element
			getStyleObj(sBlock).display = "none";
			
			//change the image
			getObj("img" + sBlock).src = "/en_US/images/pageImg/button_shelfarrow_closed.gif";
		}
		
		//write the cookie
		setCookie(sBlock,"false");
	} 
	else 
	{
		if (!mBrowser.isNS4)
		{
			//show the element
			getStyleObj(sBlock).display = "block";
			
			//change the image
			getObj("img" + sBlock).src = "/en_US/images/pageImg/button_shelfarrow_open.gif";
		}
		
		//write the cookie
		setCookie(sBlock,"true");
	}
	
	
	//for NS, reload the page
	if (mBrowser.isNS4)
	{
		location.reload(true);
	}
}

//togglePage: iterates through the collection of DIVs on a page and determines 
//whether to hide or show each one (IE only)
function togglePage() 
{
	if (!mBrowser.isNS4)
	{	
		var aDIVs = getDIVs();
		var iNumDIVs = aDIVs.length;
		
		for (var i=0; i < iNumDIVs; i++) 
		{
			var oID = aDIVs[i].id;
			if (oID) 
			{
				if (getCookie(oID) == "false")
				{
					var iNumStylesheets = document.styleSheets.length - 1;
					var sSelector = "#" + oID;
					document.styleSheets(iNumStylesheets).addRule(sSelector,"display:none");
				}
			}
		}
	}	
}


//***** COMMERCE FUNCTIONS *****
var getReturnVar=1;
//toSubmit: determines whether to submit a form
function toSubmit()
{
	if (!document.bSubmit)
	{
		document.bSubmit==true;
		return false;
	}
	else
	{
		return true;
	}
}

//tryConfirm: determines what the user did in the confirm dialog
function tryConfirm(messg)
{
	if (confirm(messg))
		setReturn(1);
	else
		setReturn(0);
}
//checkTryConfirm: form evaluates what came from users confirm dialog, continues the form submit or stops it
function checkTryConfirm()
{
	if (getReturnVar==0)
		return false;
	else
		return true;
}

function setReturn(returnVar)
{
	getReturnVar=returnVar;
}


//toSubmitForm: determines whether to submit a form
function toSubmitForm()
{
	if (document.toSubmit)
	{
		return true;
	}
	return false;
}

//deleteConfirm: sets a variable based on the user's response to a confirmation dialog
function deleteConfirm(message)
{	
	document.bSubmit = confirm(message);
}

//clearPaymentFormValues: used by payment.jsp to set form values not related to the 
//selected payment type to null before submitting the form
function clearPaymentFormValues(bShowResults) 
{
	var oForm = document.forms["payment"];
	var oPaymentType = getObj("paymentType");
	var oPaymentRadio;
	var sPaymentType;
	var oElement;
	var sFormValues = "";
	var bPaymentType = false;
	var bIdMatch = false;
	var bImage = false;
	
	//determine which radio button was clicked
	for (var i=0; i < oPaymentType.length; i++)
	{
		oPaymentRadio = oPaymentType(i);
		if (oPaymentRadio.checked)
		{
			//get the value of the checked radio button
			sPaymentType = oPaymentRadio.value;
		}
	}
	for (var j=0;j < oForm.elements.length; j++)
	{
		oElement = oForm.elements[j];
		
		//If these are all true, set the element's value to null
		//1. The element's id includes the value of the selected radio button
		bIdMatch = (oElement.id.indexOf(sPaymentType)<0);
		//2. The element isn't a radio button
		bPaymentType = (oElement.id != "paymentType");
		//3. The element isn't an image
		bImage = (oElement.type != "image");
		
		if (bIdMatch && bPaymentType && bImage)
		{
			//set the element's value to null
			oElement.value = null;
		}
		sFormValues += "<tr><td>" + oElement.id + "</td><td>" + oElement.value + "</td></tr>";
	}
	if (bShowResults)
	{	
		sFormValues += "<table class='message'>" + sFormValues + "</table>";
		oForm.insertAdjacentHTML("beforeEnd",sFormValues);
	}
}

//utilizationFormHandler: manipulates form values and the Action, and validates dates, for the utilization report form
function utilizationFormHandler(oForm)
{
	var startDate = new Date(2001,5,30);
	
	//set the form's action to the value of the "actionURL" drop-down list
	var eElement = getFormElement(oForm,"actionURL");	
	oForm.action = eElement.options[eElement.selectedIndex].value;

	//set the From date
	var eFromDate = getFormElement(oForm,"dFr");
	var eFromMonth = getFormElement(oForm,"monthFrom");
	var sFromMonth = eFromMonth.options[eFromMonth.selectedIndex].value;
	var sFromYear = getFormElement(oForm,"yearFrom").value;
	var sFromDay = getFormElement(oForm,"dayFrom").value;
	var dFromDate = new Date(sFromYear,sFromMonth,sFromDay);
	eFromDate.value = (dFromDate.getMonth()+1) + "-" + dFromDate.getDate() + "-" + dFromDate.getFullYear();
	
	//set the To date
	var eToDate = getFormElement(oForm,"dTo");
	var eToMonth = getFormElement(oForm,"monthTo");
	var sToMonth = eToMonth.options[eToMonth.selectedIndex].value;
	var sToYear = getFormElement(oForm,"yearTo").value;
	var sToDay = getFormElement(oForm,"dayTo").value;
	var dToDate = new Date(sToYear,sToMonth,sToDay);
	eToDate.value = (dToDate.getMonth()+1) + "-" + dToDate.getDate() + "-" + dToDate.getFullYear();
	
	//check that the FROM date is valid
	if (!isValidDate(dFromDate,"'From' date"))
	{
		return false;
	}
	//check that the TO date is valid
	if (!isValidDate(dToDate,"'To' date"))
	{
		return false;
	}
	
	/* un-comment this when we go live!
	if (dFromDate.getTime() - startDate.getTime() < 0)
	{
		alert("Utilization date is not available before 1 Jul 2001");
		eFromMonth.options[6].selected = true;
		getFormElement(oForm,"dayFrom").value = 1;
		getFormElement(oForm,"yearFrom").value = 2001;
		return false;
	}
	*/
	
	//make sure the TO date is after the FROM date
	if (dToDate.getTime() - dFromDate.getTime() < 0)
	{
		alert("The TO date must be equal to or after the FROM date");
		return false;
	}
	return true;
}

//reportFormHandler: manipulates form values and the Action, and validates dates, for the report form
//for order summary, successful cc transactions, failed cc transactions
function reportFormHandler(oForm)
{
	var eRadio = oForm.actionURL;
	for (var i=0; i < eRadio.length; i++)
	{
		//find the checked radio button
		if (eRadio[i].checked)
		{
			//set the action to the URL specified in the actionURL value
			oForm.action = eRadio[i].value;
		}
	}

	//set the From date
	var eFromDate = getFormElement(oForm,"dFr");
	var eFromMonth = getFormElement(oForm,"monthFrom");
	var sFromMonth = eFromMonth.options[eFromMonth.selectedIndex].value;
	var sFromYear = getFormElement(oForm,"yearFrom").value;
	var sFromDay = getFormElement(oForm,"dayFrom").value;
	var dFromDate = new Date(sFromYear,sFromMonth,sFromDay);
	eFromDate.value = dFromDate.getMonth()+1 + "/" + dFromDate.getDate() + "/" + dFromDate.getFullYear();
	
	//set the To date
	var eToDate = getFormElement(oForm,"dTo");
	var eToMonth = getFormElement(oForm,"monthTo");
	var sToMonth = eToMonth.options[eToMonth.selectedIndex].value;
	var sToYear = getFormElement(oForm,"yearTo").value;
	var sToDay = getFormElement(oForm,"dayTo").value;
	var dToDate = new Date(sToYear,sToMonth,sToDay);
	eToDate.value = dToDate.getMonth()+1 + "/" + dToDate.getDate() + "/" + dToDate.getFullYear();
	
	//check that the FROM date is valid
	if (!isValidDate(dFromDate,"'From' date"))
	{
		return false;
	}
	//check that the TO date is valid
	if (!isValidDate(dToDate,"'To' date"))
	{
		return false;
	}
	
	return compareDates(dFromDate,dToDate);
}

//addGroupProductsFormHandler: validates dates on the Add Group Products form
function addGroupProductsFormHandler(oForm)
{
	//set the From date
	var eFromMonth = getFormElement(oForm,"monthFrom");
	var sFromMonth = eFromMonth.options[eFromMonth.selectedIndex].value;
	var sFromYear = getFormElement(oForm,"yearFrom").value;
	var sFromDay = getFormElement(oForm,"dayFrom").value;
	var dFromDate = new Date(sFromYear,sFromMonth-1,sFromDay);
	
	//set the To date
	var eToMonth = getFormElement(oForm,"monthTo");
	var sToMonth = eToMonth.options[eToMonth.selectedIndex].value;
	var sToYear = getFormElement(oForm,"yearTo").value;
	var sToDay = getFormElement(oForm,"dayTo").value;
	var dToDate = new Date(sToYear,sToMonth-1,sToDay);
	
	//check that the FROM date is valid
	if (!isValidDate(dFromDate,"'From' date"))
	{
		return false;
	}
	//check that the TO date is valid
	if (!isValidDate(dToDate,"'To' date"))
	{
		return false;
	}
	
	return compareDates(dFromDate,dToDate);
}

//validatePendingRequests: validates the pending request queue form
function validatePendingRequests()
{
	var bToSubmit = false;
	var iNumAccepted = countRadiobuttons("pendingRequest","accept");
	var iNumVacant = document.numVacant;
	var iGap = iNumVacant - iNumAccepted;
	
	if (document.accountType == 2)
	{
		//if this is a limited user account, check that the number of users doesn't exceed the number of available seats
		if (iGap >= 0)
		{
			bToSubmit = true;
		}
		else
		{
			alert("You have accepted " + Math.abs(iGap) + " more people than the number of available seats. Please reduce the number of people you accept into this group.");
			bToSubmit = false;
		}
	}
	else
	{
		bToSubmit = true;
	}
	return bToSubmit;
}

//viewAccountFormHandler: validates dates on the Add Group Products form
function viewAccountFormHandler(oForm)
{
	//set the date
	var eMonth = getFormElement(oForm,"limitExpMonth");
	var sMonth = eMonth.options[eMonth.selectedIndex].value;
	var sYear = getFormElement(oForm,"limitExpYear").value;
	var sDay = getFormElement(oForm,"limitExpDay").value;
	var dDate = new Date(sYear,sMonth-1,sDay);
	
	//check that the date is valid
	if (!isValidDate(dDate,"'Reset Balance On' date"))
	{
		return false;
	}
	return true;
}

//checkrequired: checks required fields in form, set in "name" property of field, for input.
function checkrequired(formName,sMessage)
{
	whichForm = formName;
	var pass=true;
	
	//set error message
	if (sMessage)
	{
		var errorMessage = sMessage;
	}
	else
	{
		var errorMessage = "Please complete all of the required fields, marked by an *.";
	}
	//check fields for "reqd" in name property
	if (document.images) 
	{
		for (i=0;i<whichForm.length;i++) 
		{
		var tempobj=whichForm.elements[i];
		if (tempobj.type == "text" || tempobj.type == "textarea" || tempobj.type == "password")
		{
			if (tempobj.name.toLowerCase().indexOf('reqd')>=0) 
				{
				if (tempobj.value=="")
					{
    					pass=false;
                        if (tempobj.type == "password")
                        {
                            errorMessage = "Please enter a password." ;
                        }
                        break;
					}
	    		} //if reqd
			}
		}
 	 }	//if javascript

	//display error if false or submit form if true
	if (!pass) 
	{
		alert(errorMessage);
		return false;
		
	}
	else
	{
		return true;
	}
}//function

//setSelect: sets the value of a select element
function setSelect(sForm,sElement,sValue)
{
	var oForm = getForm(sForm);
	var eElement = getFormElement(oForm,sElement);
	var iNumOptions = eElement.options.length;

	for (var i=0; i < iNumOptions; i++)
	{
		if (eElement.options[i].value == sValue.toString())
		{
			eElement.options[i].selected = true;
		}
	}	
}

function setDates(sForm)
{						
	var oForm = getForm(sForm);			
	var dDate = new Date();
	var iDay = dDate.getDate();
	var iMonth = dDate.getMonth();
	var iYear = dDate.getFullYear();
	var oForm = getObj("addProductsForm");
	
	//set the From dates
	getFormElement(oForm,"utilizationStartDay").value = iDay;
	setSelect("addProductsForm","utilizationStartMonth",iMonth);
	getFormElement(oForm,"utilizationStartYear").value = iYear;
	
	//set the To dates
	getFormElement(oForm,"utilizationEndDay").value = iDay;
	setSelect("addProductsForm","utilizationEndMonth",iMonth);
	getFormElement(oForm,"utilizationEndYear").value = iYear + 1;
}

//resolveAction: used by bookcase to copy, move, delete, or email a link
function resolveAction(oForm,urlVar) 
{
	switch (oForm.selAction.options[oForm.selAction.selectedIndex].value)
	{
		case "copy":
			urlString = "/en_US/my/copyBookcaseItem.jsp?shelfItemId=" + oForm.shelfId.value;
			window.open(urlString,'_blank','HEIGHT=440,WIDTH=450,scrollbars=true');
			break;
		case "move":
			urlString = "/en_US/my/moveBookcaseItem.jsp?shelfItemId=" + oForm.shelfId.value;
			window.open(urlString,'_blank','HEIGHT=440,WIDTH=450,scrollbars=true');
			break;
		case "delete":
			blnConfirm = confirm("Are you sure you want to remove this item from this bookshelf?");
			if (blnConfirm == true)
			{
				urlString = "/en_US/my/deleteLink.jsp?shelfItemId=" + oForm.shelfId.value;
				urlString += "&url=" + urlVar;
				window.location.href = urlString;
				return false;
			}
			break;
		case "email":
			//urlString = "/en_US/my/emailForm.jsp?body=" + oForm.body.value + "&redirectTo=" + oForm.redirectTo.value;
			//window.location.href = urlString;
            oForm.action="/en_US/my/emailForm.jsp";
            oForm.method="post";
            oForm.submit();
			return false;
			break;
		default:
			//tmpString = "mailto:?body=http://www.idc.com" + oForm.selAction.value;
			//tmpValue = window.open(tmpString,"tmpWindow");
			//tmpValue.close();
			window.location.href = oForm.selAction.value;
			break;
	}
	return false;
}

//checkPositive: validates that a field is at least zero
 function checkPositive(eFormElement)
 {
 	if (eFormElement.value.length != 0)
	{
		if (isPositive(eFormElement.value) == false)
		{
			alert("This field must be at least zero.");
			eFormElement.value = "";
		}
	}
 }
 
 //validateEmailAddress: validates the user's email address
 function validateEmailAddress(eFormElement)
 {
 	var sValue = eFormElement.value;
 	if (sValue.length != 0)
	{
		if (sValue.lastIndexOf("@") == -1)
		{
			alert("Please enter a valid email address.");
			eFormElement.value = "";
			eFormElement.focus();
		}
	}
 }
 
 //validatePassword: validates the user's password
 function validatePassword(eFormElement)
 {
 	var sValue = eFormElement.value;
	var bError = false;

 	if (sValue.length != 0)
	{
		//check that the password doesn't contain spaces
		if (sValue.lastIndexOf(" ") != -1)
		{
			bError = true;
		}
		
		//check that the password is long enough
		if (sValue.length < 7)
		{
			bError = true;
		}
		//display an alert if there is an error
		if (bError)
		{
			alert("Please enter a valid password. Passwords must be at least 7 characters long and cannot contain any spaces.");
			eFormElement.value = "";
			eFormElement.focus();
		}
	}
 }

//initSearch: initializes dates on advanced search pages
function initSearch(bDefaultDatesFuture)
{	var oForm = getObj("AdvancedSearchForm");
		
	var sD1 = document.searchD1;
	
	//determine the FROM date
	if (sD1 == "")
	{
		var dFromDate = new Date();
		var iFromMonth = dFromDate.getMonth() + 1;
		//set the From dates to be 1 year ago
		if (bDefaultDatesFuture)
		{
			//set the FROM year to this year
			var iFromYear = dFromDate.getFullYear();
		}
		else
		{
			//set the FROM year to last year
			var iFromYear = dFromDate.getFullYear() - 1;
		}
	}
	else
	{
		var dFromDate = new Date(sD1);
		var iFromMonth = dFromDate.getMonth() + 1;
		var iFromYear = dFromDate.getFullYear();
	}
	//set the From dates
	getFormElement(oForm,"dayFrom").value = 1;
	setSelect("AdvancedSearchForm","monthFrom",iFromMonth);
	setSelect("AdvancedSearchForm","yearFrom",iFromYear);
	

	//determine the TO date
	var sD2 = document.searchD2;
	if (sD2 == "")
	{
		var dToDate = new Date();
		var dLastDateOfMonth = getLastDateOfMonth(dToDate);
		var iToDay = dLastDateOfMonth.getDate();
		var iToMonth = dToDate.getMonth() + 1;
		if (bDefaultDatesFuture)
		{
			//set the To year 1 year in future
			var iToYear = dToDate.getFullYear() + 1;
		}
		else
		{
			//set the To year to this year
			var iToYear = dToDate.getFullYear();
		}
	}
	else
	{
		var dToDate = new Date(sD2);
		var iToDay = dToDate.getDate();
		var iToMonth = dToDate.getMonth() + 1;
		var iToYear = dToDate.getFullYear();
	}
	//set the To dates to today
	getFormElement(oForm,"dayTo").value = iToDay;
	setSelect("AdvancedSearchForm","monthTo",iToMonth);
	setSelect("AdvancedSearchForm","yearTo",iToYear);
}

//validateSearch: checks dates and checkboxes on advanced search pages
function validateSearch(oForm,sMessage)
{	
	//set the From date
	var oFromMonth = getFormElement(oForm,"monthFrom");
	var sFromMonth = oFromMonth.options[oFromMonth.selectedIndex].value;
	var oFromYear = getFormElement(oForm,"yearFrom");
	var sFromYear = oFromYear.options[oFromYear.selectedIndex].value;
	var sFromDay = 1;
	var dFromDate = new Date(sFromYear,sFromMonth-1,sFromDay);

	//set the To date
	var oToMonth = getFormElement(oForm,"monthTo");
	var sToMonth = oToMonth.options[oToMonth.selectedIndex].value;
	var oToYear = getFormElement(oForm,"yearTo");
	var sToYear = oToYear.options[oToYear.selectedIndex].value;
	oToDay = getFormElement(oForm,"dayTo");
	var sToDay = 1;
	var dToDate = new Date(sToYear,sToMonth-1,sToDay);
	
	var dToDate = getLastDateOfMonth(dToDate);
	sToDay = dToDate.getDate();
	oToDay.value = sToDay;
	
	//check that the FROM date is valid
	if (!isValidDate(dFromDate,"'From' date"))
	{
		return false;
	}

	//check that the TO date is valid
	if (!isValidDate(dToDate,"'To' date"))
	{
		return false;
	}
	
	//make sure the TO date is after the FROM date
	if (!compareDates(dFromDate,dToDate))
	{
		return false;
	}
	
	if (sMessage)
	{
		if (!isOneSelected(oForm,'contentType',sMessage))
		{
			return false;
		}	
	}
	
	var oD1 = getFormElement(oForm,"d1");
	oD1.value = sFromMonth + "/" + sFromDay + "/" + sFromYear;
	
	var oD2 = getFormElement(oForm,"d2");
	oD2.value = sToMonth + "/" + sToDay + "/" + sToYear;
	
	return true;
}

 //checkAccountPurchases: checks/unchecks the P.O. required checkboxes
 //based on the checked state of the Account Purchase checkbox
 function checkAccountPurchases(eAccountPurchasesAllowed,sPORequired)
 {
 	var oForm = eAccountPurchasesAllowed.form;
 	var ePORequired = getFormElement(oForm,sPORequired);
	
	//if account purchases are not allowed, uncheck PO required
	if (eAccountPurchasesAllowed.checked == false)
	{
		ePORequired.checked = false;
	}
	else
	{
		if (ePORequired.defaultChecked == true)
		{
			ePORequired.checked = true;
		}
	}
 }
 
  //checkPORequired: checks the Account Purchase checkbox if the P.O. required checkbox is checked
function checkPORequired(ePORequired,sAccountPurchasesAllowed)
 {
 	var oForm = ePORequired.form;
 	var eAccountPurchasesAllowed = getFormElement(oForm,sAccountPurchasesAllowed);
	
	//if P.O. Required is checked, check Account Purchases
	if (ePORequired.checked)
	{
		eAccountPurchasesAllowed.checked = true;
	}
 }

 //isOneSelected: checks whether one checkbox in a group is selected
 function isOneSelected(oForm,sCheckboxName,sMessage)
 {
 	//if the item is checked, return
	var iNumChecked = 0;
	
	var iNumElements = oForm.elements.length;
	
	//go through each element on the form
	for (var i=0; i < iNumElements; i++)
	{
		var eElement = oForm.elements[i];
		
		//see if the element is a checkbox
		if (eElement.type == "checkbox")
		{
			//see if the name matches
			if (eElement.name == sCheckboxName)
			{
				//increment the counter if the checkbox is checked
				if (eElement.checked)
				{
					iNumChecked += 1;
				}
			}
		}
	}
	//if none are checked, pop up an alert and
	//check the checkbox
	if (iNumChecked == 0)
	{
		if (sMessage)
		{
			alert(sMessage);
		}
		else
		{
			alert("At least one checkbox must be checked.");
		}
		return false;
	}
	return true;
}


/* ***** COUNTRY/STATE FUNCTIONS ***** */

document.setStates = setStates;
document.aCountrySelect = new Array();
document.aStateSelect = new Array();

function getStates(oCountrySelect)
{
	//get the currently selected country
	var sCurrCountry = escape(oCountrySelect.options[oCountrySelect.selectedIndex].value);
	
	document.oStateForm = oCountrySelect.form;
	
	//get a reference to the state element
	//reference created by /en_US/includes/stateListGenFrag.jsp
	var sCountrySelectName = oCountrySelect.name;
	var iNumCountrySelects = document.aCountrySelect.length;
	var iStateSelect;
	for (var i=0; i < iNumCountrySelects; i++) 
	{
		if (sCountrySelectName == document.aCountrySelect[i])
		{
			iStateSelect = i;
		}
	}
	
	var sStateSelect = document.aStateSelect[iStateSelect];
	if (sStateSelect == "null" || sStateSelect == null)
	{
		//return if a reference can't be determined
		return;
	}
	var oStateSelect = getFormElement(document.oStateForm,sStateSelect);
	document.oStateSelect = oStateSelect;
	
	//get a reference to the iFrame or layer to post the request	
	if (mBrowser.isNS4)
	{
		var oFrame = getObj("childLayer");
	}
	else
	{
		var oFrame = getObj("childIFrame");
	}
	
	//post the request for a state list	
	if (oFrame)
	{
		oFrame.src = "/includes/getstates.jsp?currCountry=" + sCurrCountry;
	}
	else
	{
		alert("Can't get state list");
	}
	
	//initialize the options collection on the state element
	var iNumOptions = oStateSelect.length;
	for (var i=0; i < iNumOptions; i++) 
	{
		if (mBrowser.isNS4)
		{
			oStateSelect.options[0] = null;
		}
		else
		{
			oStateSelect.options.remove(0);
		}
	}
}

//setStates: populates a drop-down list box with a set of values
function setStates(oOptions)
{
	//get a reference to the state drop-down list
	var oSelect = document.oStateSelect;
	
	//put the options in the list
	setOptions(oSelect,oOptions);
	
	//select the first value	
	oSelect.options[0].selected = true;
}

//sendStates: called from the iframe/layer. Calls a method on the parent to populate a state drop-down list
function sendStates()
{
	//call the setStates method in the parent document
	if (!mBrowser.isNS4)
	{
		if (mBrowser.isIE55)
		{
			var oDocument = window.frameElement.document;
		}
		else
		{
			var oDocument = document.parentWindow.parent.document;
		}
	}
	else
	{
		var oDocument = window.parent.document;
	}
	
	if (oDocument)
	{
		oDocument.setStates(document.forms[0].elements[0].options);
	}
	else
	{
		alert("Can't reference parent document");
	}
}

//beanSubmit:
function beanSubmit(sButton)
{
	document.toSubmit = false;
	if (!mBrowser.isNS4)
	{
		var oButton = getObj(sButton);
		if (isEnterKey())
		{
			if (oButton)
			{
				//oButton.click();
			}
		}
	}
}


//validateFTPEditGroup: validates that ftp username and passwords are ok from the edit group form
//
function validateFTPEditGroup(oForm)
{
	
	var oFtpGroupSw = getObj("ftpGroupSw");
	var oFtpTechSupportSw = getObj("ftpTechSupportSw");
	var bToSubmit = true;
		
	if (((oFtpGroupSw != null) && (oFtpTechSupportSw != null)) && ((oFtpGroupSw.value == "Y") && (oFtpTechSupportSw.value == "Y")))
	{
	    var oFTPUserName = getObj("ftpUserName");
	    var oFTPPassword = getObj("ftpPassword");
	    
	    var sMessage;
	
	    if ((oFTPUserName == null) || (oFTPUserName.value.Trim().length == 0)) 
	    {
	        alert("FtpIntranet Username cannot be empty");
	        bToSubmit = false;
	    }
	    else if ((oFTPPassword == null) || (oFTPPassword.value.Trim().length == 0))
	    {	              	
	        alert("FtpIntranet Password cannot be empty");
	        bToSubmit = false;	    	
	    }            
	}
	
	return bToSubmit;
		
}

//validateFTPGroup: validates that ftp username and passwords are ok
//
function validateFTPGroup(oForm)
{
	
	var oFtpGroup = getObj("ftpGroup");	
	
	if (oFtpGroup.checked) 
	{			
		
	    var oFTPUserName = getObj("ftpUserName");
	    var oFTPConfirmUserName = getObj("ftpConfirmUserName");
	    var oFTPPassword = getObj("ftpPassword");
	    var oFTPConfirmPassword = getObj("ftpConfirmPassword");
	    
	    var bToSubmit = true;
	    var sMessage;
	
	    if ((oFTPUserName == null) || (oFTPUserName.value.Trim().length == 0)) 
	    {
	        sMessage = "FtpIntranet Username cannot be empty";
	        bToSubmit = false;
	    }
	    else if ((oFTPPassword == null) || (oFTPPassword.value.Trim().length == 0))
	    {	              	
	        sMessage = "FtpIntranet Password cannot be empty";
	        bToSubmit = false;	    	
	    }		
	    else 
	    {	
	        if (oFTPUserName.value != oFTPConfirmUserName.value)
	        {
		    bToSubmit = false;
		    sMessage = "The Intranet Usernames";	
	        }
	        if (oFTPPassword.value != oFTPConfirmPassword.value)
	        {
		    bToSubmit = false;
		    if (sMessage == null)
		    {
			sMessage = "The Intranet Passwords";
		    }
		    else
		    {
			sMessage += " and Passwords";
		    }
	        }
	        
	        sMessage += " don't match.";
	        
	    }    
	        
	    if (bToSubmit == false)
	    {
		alert(sMessage);
	    }
	    return bToSubmit;
	}
	
	return true;	
}

//renameShelf: opens a dialog box so that the user can change a shelf name
function renameShelf(shelfID)
{
	newWin = "/en_US/my/renameShelf.jsp?bookshelfId=" + shelfID;
	window.open(newWin,'_blank','HEIGHT=440,WIDTH=450,scrollbars=true');
}


//savePrefs: saves prefs before enabling the user to select subscriptions or analysts
function savePrefs(sActionURL)
{
	var oForm = getObj("editProfile");
	var eSuccessURL = getFormElement(oForm,"successURL");
	eSuccessURL.value = sActionURL;	
	//oForm.action = sActionURL;
	oForm.submit();
}

