
/* ****************************************************************************
* Copyright (C) 2004-2005 PurposeDriven.Com. All Rights Reserved.
* Unauthorized use, duplication or distribution is strictly prohibited.
*******************************************************************************
*
*	File:		pdwebauthorconsole.js
*
*	Purpose:	This file contains the javascript functions that take care
*				of managing the web author console floating bar.
*
*	Author:		Gerair D. Balian, based on code created by Microsoft Corporation.
*	Version:	1.0
**************************************************************************** */
// Copies the display name to the other field
// VERIFIED WORKING
function WBC_CopyNameToDisplayName(strNameID, strDisplayNameID)
{
	var pfrmNewChannelSaveDlg;
	pfrmNewChannelSaveDlg = document.forms["NewChannelSaveDlg"]
	pfrmNewChannelSaveDlg[strDisplayNameID].value = pfrmNewChannelSaveDlg[strNameID].value;
	return false;
}
// VERIFIED WORKING
function HandleKeyPress()
{
    // If enter key is pressed then disregard
    // otherwise it causes an annoying beep
	if( window.event ) {
		// ie code
		if( window.event.keyCode == 13 ) {
			window.event.keyCode = 0;
			return false;
		}
	}
	else if( event ) {
		// gecko engine code
		if( event.which == 13 ) {
			event.preventDefault();
			return false;
		}
	}
}
// VERIFIED WORKING
function btnClose_onclick() 
{
	window.returnValue = "Cancelled";
	window.close();
}
// VERIFIED WORKING
function btnOK_onclick()
{
	var sReturn
	sReturn = document.all( "txtName" ).value
	+ "^d"
	+ document.all( "txtDisplay" ).value;
	if ( ( document.all( "txtName" ).value == "" ) ||
		 ( document.all( "txtDisplay" ).value == "" ) )
	{
		alert("Please enter a name and display name before continuing...")
		return;	
	}
	window.returnValue = sReturn;
	window.close();
}
// Used in SortChannelItem.aspx
// VERIFIED WORKING
// Changes the order of items in the SORT CHANNEL ITEMS form
function MoveListboxItem( currentForm, bIsMoveUp, listBoxName ) {
	var lbxListboxItems = currentForm.elements[ listBoxName ]
	var selectedIndex = lbxListboxItems.selectedIndex
	if ( selectedIndex == -1) 
		alert( "Select an item to move up/down" );
	else {
		var newIndex = selectedIndex + ( bIsMoveUp ? -1 : 1);
		// Wrap around functionality
		if( newIndex < 0 ) 
			newIndex = lbxListboxItems.length - 1;
		if( newIndex >= lbxListboxItems.length ) 
			newIndex = 0;

		// Swap elements
		var oldVal = lbxListboxItems[ selectedIndex ].value;
		var oldText = lbxListboxItems[ selectedIndex ].text;
		lbxListboxItems[ selectedIndex ].value = lbxListboxItems[ newIndex ].value
		lbxListboxItems[ selectedIndex ].text = lbxListboxItems[ newIndex ].text
		lbxListboxItems[ newIndex ].value = oldVal
		lbxListboxItems[ newIndex ].text = oldText
		lbxListboxItems.selectedIndex = newIndex
	}
}
//VERIFIED WORKING
//Saves the order of items in the SORT CHANNEL ITEMS form
function btnSaveOrder( form ) {
	for( var i = 0; i < form.length; i++ ) {	
		if( form[ i ].name == "lbxChannelItems" ) {
			var strIDs = ""
			for( var j = 0; j < form[ i ].options.length; j++ )
				strIDs += form[ i ].options[ j ].value + "^"
//		    window.returnValue = strIDs.substring( 0, strIDs.length - 1 );
			var ckUtil = new CJL_CookieUtil( "newordering", "1", "/" );
			ckUtil.setSubValue( "", strIDs.substring( 0, strIDs.length - 1 ) );
			window.returnValue = "true";
			window.history.go( -1 );
			window.close();
			break;
		}
	}
}
// From CampaignResources.ascx
// These 2 functions allow the user to press ENTER after entering another
// page number in the textbox at the bottom of the campaign resources
// page. If script is not running, pressing ENTER will produce unexpected
// results.
// VERIFIED WORKING
function PageNumberTextbox_ValueChange(oEdit, oldValue, oEvent)
{	
	var bReplaced = false;
	var newSearch = UpdateOrAddURLParam( location.search, "PageNumber", oEdit.value );
	location = location.pathname + newSearch;
}
// VERIFIED WORKING
function captureEnter( oEdit )
{			
	if (window.event && window.event.keyCode == 13) 
	{
		PageNumberTextbox_ValueChange( oEdit, 0, 0 );
		event.keyCode = 0;
		return true;
	}
}
// From IndividualInformation.ascx
// Toggles the Text/Html email format options depending on whether or not the EMAIL
// checkbox is checked
// VERIFIED WORKING
function IndividualInformation_ChangeEmailCheckbox( prefix ) {
	var useEmail = document.getElementById( prefix + "_EmailCheckbox" );
	if( useEmail != null ) {
		ChangeEnabledState( prefix + "_EmailTypeList", useEmail.checked );
	}
}

// Since only one phone number is required, this toggle the required
// asterisk depending on what the user has entered. Basically, if one is
// full the other is not required.
// VERIFIED WORKING
function IndividualInformation_ChangePhoneRequirement_OnValueChanged( oEdit, oldValue, oEvent ) 
{
	var prefix = oEdit.ID.substring( 0, oEdit.ID.lastIndexOf( "_" ) );
	IndividualInformation_ChangePhoneRequirement( prefix );
}
// See above
// VERIFIED WORKING
function IndividualInformation_ChangePhoneRequirement( prefix ) {
	var country = document.getElementById( prefix + "_CountryList" );
	if( country != null ) {		
		var selected = country.options[ country.selectedIndex ];
		if( selected != null ) {
			var homePhone = "";
			var workPhone = "";
						
			if( selected.value == "225" ) {	// US
				var x = document.getElementById( prefix + "_USHomePhoneTextbox_t" );
				if (x == null)
				{
					x = document.getElementById( "x" + prefix + "_USHomePhoneTextbox_t" );
				}
				homePhone = x.value;
				var y = document.getElementById( prefix + "_USWorkPhoneTextbox_t" );
				if (y == null)
				{
					y = document.getElementById( "x" + prefix + "_USWorkPhoneTextbox_t" )
				}
				workPhone = y.value;				
			}
			else {
			var x = document.getElementById( prefix + "_NonUSHomePhoneTextbox_t" );
				if (x == null)
				{
					x = document.getElementById( "x" + prefix + "_NonUSHomePhoneTextbox_t" );
				}
				homePhone = x.value;
				var y = document.getElementById( prefix + "_NonUSWorkPhoneTextbox_t" );
				if (y == null)
				{
					y = document.getElementById( "x" + prefix + "_NonUSWorkPhoneTextbox_t" )
				}
				workPhone = y.value;
				}
			
			ChangeDisplayState( prefix + "_HomePhoneRequiredStar", ( workPhone.length <= 0 ) );
			ChangeDisplayState( prefix + "_WorkPhoneRequiredStar", ( homePhone.length <= 0 ) );
		}
	}
}
// From NewCustomer.ascx
// Enables the radio button for TEXT/HTML depending on the checked
// state of the Email checkbox
// VERIFIED
function NewCustomer_ChangeEmailCheckbox( prefix ) {
	var useEmail = document.getElementById( prefix + "_EmailCheckbox" );
	if( useEmail != null ) {
		ChangeEnabledState( prefix + "_EmailTypeList", useEmail.checked );
	}
}

// Changes the field validation for Day Phone and Evening phone.
// VERIFIED
function NewCustomer_ChangePhoneRequirement_OnValueChanged( oEdit, oldValue, oEvent ) 
{
	var prefix = oEdit.ID.substring( 0, oEdit.ID.lastIndexOf( "_" ) );
	NewCustomer_ChangePhoneRequirement( prefix );
}
// VERIFIED
function NewCustomer_ChangePhoneRequirement( prefix ) {
	var country = document.getElementById( prefix + "_CountryList" );
	if( country != null ) {		
		var selected = country.options[ country.selectedIndex ];
		if( selected != null ) {
			var homePhone = "";
			var workPhone = "";
						
			if( selected.value == "225" ) {	// US
				var x = document.getElementById( prefix + "_USHomePhoneTextbox_t" );
				if (x == null)
				{
					x = document.getElementById( "x" + prefix + "_USHomePhoneTextbox_t" );
				}
				homePhone = x.value;
				var y = document.getElementById( prefix + "_USWorkPhoneTextbox_t" );
				if (y == null)
				{
					y = document.getElementById( "x" + prefix + "_USWorkPhoneTextbox_t" )
				}
				workPhone = y.value;				
			}
			else {
			var x = document.getElementById( prefix + "_NonUSHomePhoneTextbox_t" );
				if (x == null)
				{
					x = document.getElementById( "x" + prefix + "_NonUSHomePhoneTextbox_t" );
				}
				homePhone = x.value;
				var y = document.getElementById( prefix + "_NonUSWorkPhoneTextbox_t" );
				if (y == null)
				{
					y = document.getElementById( "x" + prefix + "_NonUSWorkPhoneTextbox_t" )
				}
				workPhone = y.value;
			}
			
			ChangeDisplayState( prefix + "_HomePhoneRequiredStar", ( workPhone.length <= 0 ) );
			ChangeDisplayState( prefix + "_WorkPhoneRequiredStar", ( homePhone.length <= 0 ) );
		}
	}
}
// From PaymentMethod.ascx
// All verified
function ChangeToExistingCreditPayment( prefix, canInvoice, allInvoice ) {
	ChangeCheckedState( prefix + "_CheckButton", false );
	ChangeCheckedState( prefix + "_NewCreditCardButton", false );
	ChangeCheckedState( prefix + "_InvoicePaymentButton", false );
	ChangePaymentType( prefix, "CC", canInvoice, allInvoice );
}
function ChangeToCheckPayment( prefix, canInvoice, allInvoice ) {
	ChangeCheckedState( prefix + "_CreditCardButton", false );
	ChangeCheckedState( prefix + "_NewCreditCardButton", false );		
	ChangeCheckedState( prefix + "_InvoicePaymentButton", false );
	ChangePaymentType( prefix, "CHECK", canInvoice, allInvoice );
}
function ChangeToNewCreditPayment( prefix, canInvoice, allInvoice ) {
	ChangeCheckedState( prefix + "_CreditCardButton", false );
	ChangeCheckedState( prefix + "_CheckButton", false );		
	ChangeCheckedState( prefix + "_InvoicePaymentButton", false );
	ChangePaymentType( prefix, "NEWCC", canInvoice, allInvoice );
}
function ChangeToInvoicePayment( prefix, canInvoice, allInvoice ) {
	ChangeCheckedState( prefix + "_CheckButton", false );
	ChangeCheckedState( prefix + "_NewCreditCardButton", false );
	ChangeCheckedState( prefix + "_CreditCardButton", false );
	ChangePaymentType( prefix, "INVOICE", canInvoice, allInvoice );
}
function ChangePaymentType( prefix, type, canInvoice, allInvoice ) {
	// CHECK is default
	var isExistingCC = false;
	var isCheck = true;
	var isNewCC = false;
	var isInvoicePayment = false;
			
	if( type == "CC" ) {
		isExistingCC = true;
		isCheck = false;
		isNewCC = false;
		isInvoicePayment = false;
	}
	else if( type == "NEWCC" ) {
		isExistingCC = false;
		isCheck = false;
		isNewCC = true;
		isInvoicePayment = false;
	}
	else if( type == "INVOICE" ) {
		isExistingCC = false;
		isCheck = false;
		isNewCC = false;
		isInvoicePayment = true;			
	}
	var showInvoiceResourcePanel = canInvoice && isExistingCC && !allInvoice;
	ChangeDisplayState( prefix + "_InvoiceResourcePanel", showInvoiceResourcePanel );
	ChangeEnabledState( prefix + "_CreditCardList", isExistingCC );		
	ChangeDisplayState( prefix + "_BillAddressPanel", isExistingCC );
	ChangeEnabledState( prefix + "_EditCreditCardButton", isExistingCC );				
//		ChangeEnabledState( prefix + "_CheckNumberTextbox", isCheck );	
	ChangeEnabledState( prefix + "_ExpirationDateMonthList", false );
	ChangeEnabledState( prefix + "_ExpirationDateYearList", false );			

	var isInvoice = false;
	var invoiced = document.getElementById( prefix + "_InvoiceResourceList_0" );
	if ( ( invoiced != null ) && ( !showInvoiceResourcePanel ) )
		invoiced.checked = false;
	if ( canInvoice )
	{
		if ( invoiced != null )
		{
			isInvoice = (invoiced.checked && isExistingCC) || isInvoicePayment;
		}
	}
	ChangeDisplayState( prefix + "_InvoiceAddressPanel", isInvoice );
}	
function AllowCreditCardEdit( prefix ) {
	ChangeEnabledState( prefix + "_ExpirationDateMonthList", true );
	ChangeEnabledState( prefix + "_ExpirationDateYearList", true );
}
// From MakePayment.ascx
function MakePayment_changePanelVisibility( prefix )
{
	// set the visibility of the panels based on whether the user has any credit card
	var creditCardList = document.getElementById( prefix + "_CreditCardList" );
	ChangeVisibleState( prefix + "_ExistingCreditCardPanel", (creditCardList.length > 0 ) );
	MakePayment_changeBillingAddressPanelVisibility( prefix );
}

function MakePayment_changeBillingAddressPanelVisibility( prefix )
{
	var creditCardPanel = document.getElementById( prefix + "_ExistingCreditCardPanel" );
	if ( creditCardPanel.style.visible == "hidden" )
	{
		ChangeVisibleState( prefix + "_BillingAddressPanel", false );
	}
	else
	{
		var existingCreditCardRadioButton = document.getElementById( prefix + "_CreditCardButton" );
		ChangeVisibleState( prefix + "_BillingAddressPanel", existingCreditCardRadioButton.checked );
	}	
}

function MakePayment_existingCreditCardType( prefix )
{
	var newCreditCardRadioButton = document.getElementById( prefix + "_NewCreditCardButton" );
	newCreditCardRadioButton.checked = false;
	ChangeEnabledState( prefix + "_CreditCardList", true );
	ChangeEnabledState( prefix + "_EditCreditCardButton", true );
	MakePayment_editCreditCardExpirationDate( prefix, false );
}

function MakePayment_newCreditCardType( prefix )
{
	var creditCardRadioButton = document.getElementById( prefix + "_CreditCardButton" );
	creditCardRadioButton.checked = false;
	ChangeEnabledState( prefix + "_CreditCardList", false );
	ChangeEnabledState( prefix + "_EditCreditCardButton", false );
	MakePayment_editCreditCardExpirationDate( prefix, false );
	MakePayment_changeBillingAddressPanelVisibility( prefix );
}

function MakePayment_editCreditCardExpirationDate( prefix, isEnabled )
{
	ChangeEnabledState( prefix + "_ExpirationDateMonthList", isEnabled );
	ChangeEnabledState( prefix + "_ExpirationDateYearList", isEnabled );
	return false;
}
// From NewOrganization.ascx
// VERIFIED
function NewOrganization_ChangeEmailCheckbox( prefix ) {
	var noEmail = document.getElementById( prefix + "_NoEmailCheckbox" );
	if( noEmail != null ) {
		ChangeEnabledState( prefix + "_EmailTextbox", !noEmail.checked );
		ChangeVisibleState( "EmailRequiredStar", !noEmail.checked );			
	}
}
function NewOrganization_ChangeURLCheckbox( prefix ) {
	var noURL = document.getElementById( prefix + "_cbNoURL" );
	if( noURL != null ) {
		ChangeEnabledState( prefix + "_txtURL", !noURL.checked );
		ChangeVisibleState( "reqValURL", !noURL.checked );			
	}
}
// VERIFIED
function NewOrganization_ChangeOrgType( prefix ) {
	var orgType = document.getElementById( prefix + "_OrganizationTypeList" );
	if( orgType != null ) {
		var selected = orgType.options[ orgType.selectedIndex ];
		var enabledState = false;			
		if( ( selected != null ) && ( selected.value == "1" ) )	// 1 is church
			enabledState = true;
			
		var oAttendanceRow = document.getElementById( prefix + "__attendanceRow" );
		if ( oAttendanceRow != null )
		{
			if ( enabledState == true )
				oAttendanceRow.style.display = "block";
			else
				oAttendanceRow.style.display = "none";
		}
		
		ChangeEnabledState( prefix + "_DenominationList", enabledState );
		ChangeEnabledState( prefix + "_LanguagesList", enabledState );
		ChangeVisibleState( prefix + "_AddLanguageButton", enabledState );
		
		ChangeVisibleState( prefix + "_DenominationRequiredStar", enabledState );
		ChangeVisibleState( prefix + "_AttendanceRequiredStar", enabledState );
		ChangeVisibleState( prefix + "_LanguageRequiredStar", enabledState );
	}
}
// VERIFIED
function NewOrganization_ChangeOtherPostalCode( prefix ) {
	var noPostalCode = document.getElementById( prefix + "_Other_NoPostalCodeCheckbox" );
	if( noPostalCode != null ) {
		ChangeEnabledState( prefix + "_Other_PostalCodeTextbox", !noPostalCode.checked );
		ChangeVisibleState( "Other_PostalCodeRequiredStar", !noPostalCode.checked );
//			ChangeEnabledState( prefix + "_Other_PostalCodeRequired", noPostalCode.checked );
	}
}
//VERIFIED
function NewOrganization_ChangeProvince( prefix ) {
	var noProvince = document.getElementById( prefix + "_Other_NoProvinceCheckbox" );
	if( noProvince != null ) {
		ChangeEnabledState( prefix + "_Other_ProvinceTextbox", !noProvince.checked );
		ChangeVisibleState( "Other_ProvinceRequiredStar", !noProvince.checked );
	}
}
// VERIFIED
function NewOrganization_ChangeCountry( prefix ) {
	var country = document.getElementById( prefix + "_CountryList" );
	if( country != null ) {
		var isUS = false;
		var isCA = false;	
		
		var selected = country.options[ country.selectedIndex ];
		if( selected != null ) {
			if( selected.value == "225" )	// US
				isUS = true;
			else if( selected.value == "38" )	// Canada
				isCA = true;									
		}
		ChangeDisplayState( prefix + "_US_Panel", isUS );
		ChangeDisplayState( prefix + "_CA_Panel", isCA );
		ChangeDisplayState( prefix + "_Other_Panel", !( isUS | isCA ) );	


		ChangeDisplayState(prefix + "_pnlNonUSPhone", !isUS );	
		ChangeDisplayState(prefix + "_pnlNonUSFax", !isUS );	

		ChangeDisplayState( prefix + "_pnlUSPhone", isUS );		
		ChangeDisplayState( prefix + "_pnlUSFax", isUS );		
	}
}
// From RegistrationInformation.ascx
function createAttendanceTable( prefix, first, last, email, action, remove, edit, cancelled )
{
	var html = "<table cellspacing='0' cellpadding='3' rules='all' bordercolor='Gray' border='1' style='border-color:Gray;border-width:1px;border-style:Solid;width:100%;border-collapse:collapse;'>";
	var attendeeString = document.getElementById( prefix + "_AttendeesTextbox" ).value;
	if ( attendeeString.length > 0 )
		html += createHeader( first, last, email, action );

	var attendees = attendeeString.split( ";" );
	var attendeeCount = 0;
	for ( var i = 0; i < attendees.length; i ++ )
	{
		if ( attendees[i].length > 0 )
		{
			var attendee = attendees[i].split( ":" );
			
			html += "<tr>";
			html += "<td>" + attendee[0] + "</td><td>" + attendee[1] + "</td><td>" + attendee[2] + "</td>";
			html += "<td>";
			html += "<table cellspacing='3' cellpadding='0' border='0' style='border-width:0px;'>";
			html += "<tr>";
			if ( attendee[3] == "1" )
			{
				html += "<td>" + cancelled + "</td>";
			}
			else
			{
				html += "<td><a class='LinkUnderline' href='javascript:editAttendee(\"" + prefix + "\", " + i.toString() + " )';>" + edit + "</a></td>";
				html += "<td><a class='LinkUnderline' href='javascript:removeAttendee(\"" + prefix + "\", " + i.toString() + ", \"" + first + "\", \"" + last + "\", \"" + email + "\", \"" + action + "\", \"" + remove + "\", \"" + edit + "\" )';>" + remove + "</a></td>";
				attendeeCount ++;
			}
			html += "</tr>";
			html += "</table>";
			html += "</td>";
			html += "</tr>\n";
		}
	}
	
	html += "</table>";
	createQuantityMessage( prefix, attendeeCount );	

	var panel = document.getElementById( "AttendeeListing" );
	panel.innerHTML = html;			
}

function createHeader( first, last, email, action )
{
	var header = "<tr style='background-color:Gray;'>";
	header += "<td class='blueButtonText'>" + first + "</td>";
	header += "<td class='blueButtonText'>" + last + "</td>";
	header += "<td class='blueButtonText'>" + email + "</td>";
	header += "<td class='blueButtonText'>" + action + "</td>";
	header += "</tr>\n";
	
	return header;
}

function addAttendee( prefix, first, last, email, action, remove, edit, mode, cancelled )
{

	var firstName = document.getElementById( prefix + "_FirstNameTextbox" );
	var lastName = document.getElementById( prefix + "_LastNameTextbox" );	
	var emailAddr = document.getElementById( prefix + "_EmailTextbox" );
	if ( firstName.value.length <= 0 )
		return;
	if ( lastName.value.length <= 0 )
		return;
	var val = firstName.value + ":" + lastName.value + ":" + emailAddr.value;
	var attendees = document.getElementById( prefix + "_AttendeesTextbox" );
	var index = document.getElementById( prefix + "_IdTextbox" ).value;
	if ( index.length <= 0 )
	{
		if ( mode == 0 )	// update only mode so don't add.
			return;
		else
		{
			attendees.value += ";" + val;
		}
	}
	else
	{
		var attendee = attendees.value.split( ";" );
		var att = attendee[index];
		att = att.substr( att.lastIndexOf( ":" ) );
		attendee[index] = val + ":" + att;
		attendees.value = attendee.join( ";" );
	}
	createAttendanceTable( prefix, first, last, email, action, remove, edit, cancelled );	
	firstName.value = "";
	lastName.value = "";
	emailAddr.value = "";
	document.getElementById( prefix + "_IdTextbox" ).value = "";
	trimAttendees( prefix );

}

function removeAttendee( prefix, index, first, last, email, action, remove, edit, cancelled )
{
	var attendees = document.getElementById( prefix + "_AttendeesTextbox" );
	var attendee = attendees.value.split( ";" );
	attendee[index] = "";
	
	var attendeeString = attendee.join( ";" );
	attendees.value = attendeeString;
	trimAttendees( prefix );
	
	createAttendanceTable( prefix, first, last, email, action, remove, edit, cancelled );					
}

function trimAttendees( prefix )
{
	var attendees = document.getElementById( prefix + "_AttendeesTextbox" );
	var attendeeString = attendees.value;
	
	attendeeString = attendeeString.replace( ";;", ";" );
	if ( attendeeString.charAt(0) == ';' )
		attendeeString = attendeeString.substr( 1 );
	if ( attendeeString.charAt( attendeeString.length - 1 ) == ';' )
		attendeeString = attendeeString.substring( 0, attendeeString.length - 1 );
	attendees.value = attendeeString;
}

function editAttendee( prefix, index )
{
	var attendees = document.getElementById( prefix + "_AttendeesTextbox" ).value;
	var attendee = attendees.split( ";" );
	var splitString = attendee[index].split( ":" );
	document.getElementById( prefix + "_FirstNameTextbox" ).value = splitString[0];
	document.getElementById( prefix + "_LastNameTextbox" ).value = splitString[1];
	document.getElementById( prefix + "_EmailTextbox" ).value = splitString[2];
	document.getElementById( prefix + "_IdTextbox" ).value = index;
}

function createQuantityMessage( prefix, attendeeCount )
{
	var qtyMsg = document.getElementById( prefix + "_MaxQuantityTextbox" ).value;
	var maxQty = qtyMsg.substr( qtyMsg.lastIndexOf( " " ) );
	qtyMsg = qtyMsg.replace( "##", attendeeCount.toString() );
	
	document.getElementById( prefix + "_AttendeeCountLabel" ).innerHTML = qtyMsg;

	if ( maxQty < attendeeCount )
	{
		ChangeDisplayState( prefix + "_DecrementAttendeeLabel", true );
		ChangeDisplayState( prefix + "_IncrementAttendeeLabel", false );
	}
	else if ( maxQty > attendeeCount )
	{
		ChangeDisplayState( prefix + "_DecrementAttendeeLabel", false );
		ChangeDisplayState( prefix + "_IncrementAttendeeLabel", true );
	}
	else
	{
		ChangeDisplayState( prefix + "_DecrementAttendeeLabel", false );
		ChangeDisplayState( prefix + "_IncrementAttendeeLabel", false );		
	}
}
// from PaginationControl.ascx
function RequestPage( page )
{
	var ARGS_BEGIN_CHAR = '?';
	var ARGS_SEPARATOR_CHAR = '&';
	var ARGS_EQUALS_OP_CHAR = '=';
	var PAGE_PARAM_NAME = 'page';
		
	if ( ( location.search != null ) && ( location.search.length > 0 ) )
	{
		var sQueryStr = '';
		var vQueries;
		var sSearch = location.search;
		
		var nQueryBegin = sSearch.indexOf( ARGS_BEGIN_CHAR );
		if ( nQueryBegin > -1 )
			sSearch = sSearch.substring( nQueryBegin + 1, sSearch.length );
		
		var vQueries = sSearch.split( ARGS_SEPARATOR_CHAR );
		var bPageParamFound = false;
		
		for ( var query = 0; query < vQueries.length; query++ )
		{
			var sQueryName = vQueries[ query ].split( ARGS_EQUALS_OP_CHAR );
			if ( sQueryName[ 0 ].indexOf( PAGE_PARAM_NAME ) > -1 )
			{
				var sPageParam = sQueryName[ 0 ] + ARGS_EQUALS_OP_CHAR + ( ( page == null ) ? 1 : ( page == 0 ) ? 1 : page );
				if ( vQueries.length > 1 )
					sQueryStr = sQueryStr + ARGS_SEPARATOR_CHAR + sPageParam;
				else
					sQueryStr = sQueryStr + sPageParam;
				bPageParamFound = true;
			}
			else
			{
				if ( sQueryStr.length > 0 )
					sQueryStr = sQueryStr + ARGS_SEPARATOR_CHAR + vQueries[ query ];
				else
					sQueryStr = vQueries[ query ];
			}
		}
		if ( !bPageParamFound )
		{
			var sPageParam = PAGE_PARAM_NAME + ARGS_EQUALS_OP_CHAR + ( ( page == null ) ? 1 : ( page == 0 ) ? 1 : page );
			sQueryStr = sQueryStr + ARGS_SEPARATOR_CHAR + sPageParam;
		}
		location.assign( location.pathname + ARGS_BEGIN_CHAR + sQueryStr );
	}
	else
	{
		var sPageParam = ARGS_BEGIN_CHAR + PAGE_PARAM_NAME + ARGS_EQUALS_OP_CHAR + ( ( page == null ) ? 1 : ( page == 0 ) ? 1 : page );
		location.assign( location.pathname + sPageParam );
	}
}
//From SearchResultsTemplate.aspx
function NextPage( newIndex ) {
	var query = document.location.search;
	var searchPage;
	if( query.length <= 0 )
		query = "?index=" + newIndex;
	else {
		if( query.indexOf( "index" ) >= 0 )
			query = query.replace( /index=[0-9]*/gi, "index=" + newIndex );
		else {
			query += "&index=" + newIndex;
		}
	}
	document.location.assign( document.location.pathname + query );
}
// From PDHeaderControl.ascx
// Hide the logout button if the user has not logged in
function HideLogoutButtonIfNotLoggedIn() {
	var ShowButton = false;		
	var Cookie = getCookie( "PurposeDriven" );	
	if( Cookie != null ) {
		var userGuidValue = getCookieCrumbValue( Cookie, "UserGuid" );
		ShowButton = ( userGuidValue != null ) ? true : false;
	}
	ChangeDisplayState( "logoutBtnTable", ShowButton );	

	ShowButton = false;
	Cookie = getCookie( "PD" );
	if( Cookie != null ) {
		var itemValue = getCookieCrumbValue( Cookie, "CartItems" );
		var priceValue = getCookieCrumbValue( Cookie, "CartPrice" );
		if( ( itemValue != null ) && ( priceValue != null ) )
			ShowButton = true;
	}
	ChangeDisplayState( "cartBtnTable", ShowButton );
	return true;	
}
//From SearchPDFinder.aspx
function setCookieCrumbValue( Cookie, CrumbName, newValue ) {
	var cookieCrumbs = Cookie.split( '&' );
	for( i = 0; i < cookieCrumbs.length; i++ ) {
		var crumb = cookieCrumbs[ i ].split( '=' );
		if( crumb[ 0 ] == CrumbName ) {
			if( ( crumb[ 1 ].length > 0 ) && ( crumb[ 1 ] != '0' ) )
				crumb[ 1 ] = newValue;
		}
	}
}
function setCookieCrumbValue()
{
	var query = location.search;
	if( query == null )  {
		var Cookie = getCookie( "PurposeDriven" );	
		if( Cookie != null ) {
			setCookieCrumbValue( Cookie, "PDFinder", "" );			
		}
	}
}
