function loadEnote()
{
	var enoteObj = document.getElementById( 'enote' );
	var enoteText = opener.document.getElementById( 'enoteText' ).value;
	var newText = '';
	
	//swap out spaces with space character so they show up
	//while ( enoteText.indexOf( ' ' ) > 0 )
	//{
	//	enoteText = enoteText.replace( ' ', '\u00a0' );	
	//}
	var onSpace = false;
	var currentChar = '';
	
	for ( var i = 0; i < enoteText.length; i++ )
	{
		currentChar = enoteText.substring( i, i + 1 );
	
		if ( onSpace )
		{
			//on a space
			if ( currentChar == ' ' )
			{
				//two spaces in succession, append the '\u00a0' character
				//(this is so that the HTML won't collapse all the spaces
				//on display)
				newText = newText + '\u00a0';
			}
			else
			{
				//next character is not a space, print it and flip flag off
				newText = newText + currentChar;
				
				onSpace = false;
			}
		}
		else
		{
			//not on a space
			//print the character
			newText = newText + currentChar;
			
			if ( currentChar == ' ' )
			{
				//current char is a space, set flag for next iteration
				onSpace = true;
			}
		}
	}
	
	enoteText = newText;
	
	var newLine = enoteText.indexOf( '\n' );
	
	var start = 0;
	
	while ( newLine > 0 )
	{
		//append everything up until the new line
		enoteObj.appendChild( document.createTextNode( enoteText.substring( start, newLine ) ) );
			
		//add a <br> for the new line
		enoteObj.appendChild( document.createElement( 'br' ) );	
		
		//move the parsing of the string
		start = newLine;
		newLine = enoteText.indexOf( '\n', start + 1 );
	}

	//append what's left (or all of it, if there is no newline)
	enoteObj.appendChild( document.createTextNode( enoteText.substring( start, enoteText.length ) ) );
}

function isSearchValid()
{
	var elements = document.getElementById( 'searchSection' ).getElementsByTagName( 'input' );
	var valid = false;
	
	for ( var i=0; i < elements.length; i++ )
	{
		if ( elements[i].value != '' )
		{
			//entered something
			valid = true;
		}
	}
	
	if ( !valid )
	{
		alert( document.getElementById('invalidSearchMessage').value );
		return false;
	}
	
	return true;
}

function canSubmitAfterSearch()
{
	//must pick a recipient before continuing
	var recipients = document.getElementsByName( document.getElementById( 'jsRecipientFormName' ).value );
	for ( i = 0; i < recipients.length; i++ )
	{
		if ( recipients[i].checked )
		{
			//one picked
			return true;
		}
	}
	
	alert( document.getElementById( 'jsNoSubmitMessage' ).value );
	return false;
}

function handleTime( year, month, day )
{
	var nextBusinessDay = new Date();
	
	//make sure the date is using the server's time, not the client's time
	nextBusinessDay.setTime( document.getElementById( 'today' ).value );
	
	var shiftDays = 1;
	
	if ( nextBusinessDay.getDay() == 5 || nextBusinessDay.getDay() == 6 )
	{
		//friday, next business day will be Monday, so shift three days
		//OR saturday, next business day will be Tuesday, so shift three days
		shiftDays = 3;
	}
	else if ( nextBusinessDay.getDay() == 0 )
	{
		//sunday, next business day will be Tuesday, so shift two days
		shiftDays = 2;
	}
	
	nextBusinessDay.setDate( nextBusinessDay.getDate() + shiftDays );
	nextBusinessDay.setHours( 0, 0, 0, 0 );	
	
	var pickedDate = new Date();
	var dateToDisplay = 'needByDateDate';
	pickedDate.setDate( day );
	pickedDate.setMonth( month - 1 );
	pickedDate.setYear( year );
	pickedDate.setHours( 0, 0, 0, 0 );
	
	//hide standard shipping message 
	document.getElementById( 'standardShipping' ).style.display = 'none';
	
	if ( pickedDate.getTime() == nextBusinessDay.getTime() )
	{
		//only when date is tomorrow do they get to pick a need by date time
		//showTime();
		//use the next day date for displaying the date they picked
		dateToDisplay = 'nextDayDate';
		//hide the need by date delivery section
		document.getElementById( 'needByDateDelivery' ).style.display = 'none';
		//and show the next day delivery section
		document.getElementById( 'nextDayDelivery' ).style.display = 'block';
	}
	else
	{
		//else hide the need by date time
		//hideTime();
		//hide the next day delivery section
		document.getElementById( 'nextDayDelivery' ).style.display = 'none';
		//and show the need by date delivery section
		document.getElementById( 'needByDateDelivery' ).style.display = 'block';		
	}	
	
	//and set date picked in top of section
	if ( document.getElementById( dateToDisplay ).childNodes.length > 0 )
	{
		document.getElementById( dateToDisplay ).removeChild( document.getElementById( dateToDisplay ).childNodes[0] );
	}
	
	//and allow them to revert back to standard shipping
	document.getElementById( 'backToShipping' ).style.visibility = 'visible';
	
	document.getElementById( dateToDisplay ).appendChild( document.createTextNode( formatDate( pickedDate, window.CP_dateFormat ) ) );
	
	//call the default date function to set the date
	CP_tmpReturnFunction( year, month, day );
}

function standardShipping( needByDateField )
{
	//hide the next day and need by date sections
	document.getElementById( 'needByDateDelivery' ).style.display = 'none';
	document.getElementById( 'nextDayDelivery' ).style.display = 'none';
	
	//and show the standard shipping section
	document.getElementById( 'standardShipping' ).style.display = 'block';
	
	//hide the link that allows to revert back to standard shipping
	document.getElementById( 'backToShipping' ).style.visibility = 'hidden';
	
	//and clear out the field with the date
	document.getElementById( needByDateField ).value = '';
}
