/**
	 * BBcode editor
	 *
	 * @uses $this->pbconfig->EnableRating, $this->pbconfig->ShowTitle, $this->pbconfig->ShowName, $this->pbconfig->ShowEmail, $this->pbconfig->UseLocation, $this->pbconfig->LocationField, $this->pbconfig->UseWebAddress, $this->pbconfig->WebField, $this->pbconfig->AllowBBCode, $this->pbconfig->AllowSmiles, $this->pbconfig->Captcha
	 *
	 * @param  pbProfileBookEntry  $item
	 * @param  string              $idTag
	 * @param  string              $htmlAreaLabel
	 * @param  string              $txtSubmit
	 * @param  UserTable           $curruser
	 * @param  boolean             $required
	 * @return string
	 */
	function _bbeditor( $item, $idTag, $htmlAreaLabel, $txtSubmit, $curruser, $required )
	{
		global $_CB_framework, $ueConfig;

		$myId			=	Application::MyUser()->getUserId();

		$newOrMe		=	( ( $item->posterid == -1 ) || ( $item->posterid == $myId ) );

		$htmltext		=	'<div class="cbpbEditorContainer" id="div' . $idTag . '">';
		
		//get the CB initiatied form action path this is used for all forms
		$base_url		=	$this->_getAbsURLwithParam( array() );
		$htmltext		.=	'<form name="admin' . $idTag . '" id="admin' . $idTag . '" method="post" onsubmit="javascript: return pb_submitForm(this);" action="' . $base_url . "\">\n";
		$htmltext		.=	'<input type="hidden" name="' . $this->_getPagingParamName( 'formaction' .  $this->pbconfig->MainMode[0] ) . '" value="' . ( $item->_pbid ? 'edit' : 'new' ) . "\" />\n";
		if ( $item->_pbid ) {
			$htmltext	.=	'<input type="hidden" name="' . $this->_getPagingParamName( 'id' ) . '" value="' . $item->_pbid . "\" />\n";
		}
		if ( $this->pbconfig->AllowBBCode ) {
			$editor		=	$this->getEditor( $idTag );
		} else {
			$editor		=	null;
		}
		$htmltext		.=	"<table width=\"100%\">\n";
		$locationField	=	null;
		//Check to see if the Location field should be used
		if ( $this->pbconfig->UseLocation ) {
			//Check to see if a registered user is logged in and if the admin has defined a a value for the location field
			if ( $myId && ( $this->pbconfig->LocationField != 0 ) && $newOrMe ) {
				$locationField		=	new FieldTable();
				$locationField->load( $this->pbconfig->LocationField );
				$naLocationField	=	$locationField->name;
				//if they true then display the location value from the users cb profile in read only
				$locationField		=	'<td class="titleCell">' . CBTxt::th( "Location" ) . ':<br /><input type="hidden" name="' . $this->_getPagingParamName( 'posterlocation' ) . '" value="' . htmlspecialchars( $curruser->$naLocationField ) . '" />' . htmlspecialchars( $curruser->$naLocationField ) . '</td>';
			} else {
				//else display an entry field to capture the location
				$locationField		=	'<td class="titleCell">' . CBTxt::th( "Location" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'posterlocation' ) . '" value="' . htmlspecialchars( $item->posterlocation ) . '" /></td>';
			}
		}
		
		$webField					=	null;
		if ( $this->pbconfig->UseWebAddress ) {
			if ( $myId && ( $this->pbconfig->WebField != 0 ) && $newOrMe  ) {
				$webfield			=	new FieldTable();
				$webfield->load( $this->pbconfig->WebField );
				$naWebField			=	$webfield->name;
				$webField			=	'<td class="titleCell">' . CBTxt::th( "Web Address" ) . ':<br /><input type="hidden" name="' . $this->_getPagingParamName( 'posterurl' ) . '" value="' . $curruser->$naWebField . '" />' . $this->_displayWebAddress( $curruser->$naWebField ) . '</td>';
			} else {
				$webField			=	'<td class="titleCell">' . CBTxt::th( "Web Address" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'posterurl' ) . '" value="' . htmlspecialchars( $item->posterurl ) . '" /></td>';
			}
		}
		
		$htmltext				.=	"\n<tr>";
		if ( ! $myId ) {
			$htmltext			.=	'<td class="titleCell">' . CBTxt::th( "Name" )  . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'postername' ) . '" value="' . htmlspecialchars( $item->postername ) . '" /></td>';
			$htmltext			.=	'<td class="titleCell">' . CBTxt::th( "Email" ) . ':<br /><input class="inputbox" type="text" name="' . $this->_getPagingParamName( 'posteremail' ) . '" value="' . htmlspecialchars( $item->posteremail ) . '" /></td>';
		} else {
			$htmlName	=	( $item->postername ? htmlspecialchars( $item->postername ) : getNameFormat( $curruser->name, $curruser->username, $ueConfig['name_format'] ) );
			if ( $this->pbconfig->ShowName ) {
				$htmltext		.=	'<td class="titleCell">' . CBTxt::th( "Name" ) . ':<br /><input type="hidden" name="' . $this->_getPagingParamName( 'postername' ) . '" value="' . $htmlName . '" />' . $htmlName . '</td>';
			} else {
				$htmltext		.=	'<td><input type="hidden" name="' . $this->_getPagingParamName( 'postername' ) . '" value="' . $htmlName . '" /></td>';
			}
			if ( $this->pbconfig->ShowEmail ) {
				$htmltext		.=	'<td class="titleCell">' . CBTxt::th( "Email" ) . ':<br />';
				if ( ! $item->posteremail || $myId == $item->posterid || Application::MyUser()->isAuthorizedToPerformActionOnAsset( 'core.manage', 'com_users' ) ) {
					$htmltext	.=	'<input type="hidden" name="' . $this->_getPagingParamName( 'posteremail' ) . '" value="' . ( $item->posteremail ? htmlspecialchars( $item->posteremail ) : htmlspecialchars( $curruser->email ) ) . '" />' . ( $item->posteremail ? htmlspecialchars( $item->posteremail ) : htmlspecialchars( $curruser->email ) );
				} else {
					$htmltext	.=	CBTxt::th( "Hidden" );
				}
			} else {
				if ( ! $item->posteremail || $myId == $item->posterid || Application::MyUser()->isAuthorizedToPerformActionOnAsset( 'core.manage', 'com_users' ) ) {
					$htmltext	.=	'<td><input type="hidden" name="' . $this->_getPagingParamName( 'posteremail' ) . '" value="' . ( $item->posteremail ? htmlspecialchars( $item->posteremail ) : htmlspecialchars( $curruser->email ) ) . '" /></td>';
				}
			}
		}
		$htmltext				.=	'</tr>';
		
		//Check to see if we are displaying the web address or location field. If we are then add a row for them
		if ( $webField != null || $locationField != null ) {
			$htmltext		.=	"\n<tr>" . $locationField . $webField . '</tr>';
		}
		$htmltext			.=	'<tr><td colspan="2">';
		
		//Check to see if the admin has enabled rating for profile entries
		if ( $this->pbconfig->EnableRating && ( $myId != $item->userid ) ) {
			//Yep its enabled so get the ratings HTML/Code
			$htmltext		.=	'<div class="titleCell">' . CBTxt::Th( "User Rating" ) . ':</div>'
							.	'<div class="fieldCell">' . pbcbRatings::getRatingForm( $item->postervote, 'admin' . $idTag, $this->_getPagingParamName( 'postervote' ), ( $this->pbconfig->EnableRating == 3 ) ) . '</div>'
							;
		}

		// Title line:
		if ( $this->pbconfig->ShowTitle ) {
			$htmltext		.=	'<div class="pbTitleInput">'
							.	'<span class="titleCell">' . CBTxt::Th( "Title" ) . ':</span> '
							.	'<span class="fieldCell">'
							.	'<input class="form-control pbTitleBox" type="text" name="' . $this->_getPagingParamName( 'postertitle' ) . '" value="' . htmlspecialchars( $item->postertitle ) . '" maxlength="128" />'
							.	'</span>'
							.	'</div>'
							;
		}
		// Comment editor:
		$htmltext			.=	'<div class="pbCommentInput">'
							.	'<span class="titleCell">' . $htmlAreaLabel . ':</span>'
							.	'<span class="fieldCell">'
							.	$editor
							.	'<table class="cbpbEditorTexts"><tr>';
		if ( $this->pbconfig->AllowSmiles ) {
			$htmltext		.=	"<td width=\"73%\">\n";
		} else {
			$htmltext		.=	"<td width=\"100%\">\n";
		}
		$htmltext			.=	'<textarea class="inputbox cbpbEditor" name="' . $this->_getPagingParamName( 'postercomments' )
							.	'" rows="7" cols ="40" style="width: 95%; overflow:auto;" >'
							.	htmlspecialchars( $item->postercomment ) . "</textarea>\n</td>\n";
		if ( $this->pbconfig->AllowSmiles ) {
			$htmltext		.=	"<td>\n" . $this->getSmilies( $idTag ) . "</td>\n";
		}
		$htmltext			.=	"</tr>\n</table>\n"
							.	'</span>'
							.	'</div>'
							.	'</td></tr>';
		
		// Captcha integration:
		if ( ( $this->pbconfig->Captcha == 2 ) || ( ( $this->pbconfig->Captcha == 1 ) && ( $curruser === null ) ) ) {
			global $_PLUGINS;
			
			$_PLUGINS->loadPluginGroup( 'user' );
			$pluginsResults	=	$_PLUGINS->trigger( 'onGetCaptchaHtmlElements', array( true ) ); // onCheckCaptchaHtmlElements
			if ( implode( $pluginsResults ) != '' ) {
				$htmltext	.=	'<tr><td colspan="2">' . implode( '</td></tr><tr><td colspan="2">', $pluginsResults ) . '</td></tr>';
			}
		}
		
		$htmltext			.=	'<tr><td colspan="2"><span class="fieldCell"><input class="button" name="submitentry" type="submit" value="' . $txtSubmit . "\" /></span></td></tr>\n";
		$htmltext			.=	"</table>\n";
		$htmltext			.=	"</form>\n";
		$htmltext			.=	"</div>\n";
		
		//Add the localized Javascript parameters so that error messages are properly translated
		$validateArray		=	array();
		if ( $required ) {
			$validateArray[]	=	array( 'field' => 'postername', 'confirm' => null, 'error' => CBTxt::T( "Name is Required!" ) );
			$validateArray[]	=	array( 'field' => 'posteremail', 'confirm' => null, 'error' => CBTxt::T( "Email Address is Required!" ) );
		}
		if ( $myId != $item->userid ) {
			if ( $this->pbconfig->EnableRating == 3 ) {
				$validateArray[]	=	array( 'field' => 'postervote', 'confirm' => null, 'error' => CBTxt::T( "User Rating is Required!" ) );
			} elseif ( $this->pbconfig->EnableRating == 2 ) {
				$validateArray[]	=	array( 'field' => 'postervote', 'confirm' => CBTxt::T( "You have not selected a User Rating. Do you really want to provide an Entry without User Rating ?" ), 'error' => null );
			}
		}
		if ( $this->pbconfig->ShowTitle ) {
			$validateArray[]	=	array( 'field' => 'postertitle', 'confirm' => null, 'error' => CBTxt::T( "Title is Required!" ) );
		}
		$validateArray[]		=	array( 'field' => 'postercomments', 'confirm' => null, 'error' => CBTxt::T( "Comment is Required!" ) );
		
		$res				=	array();
		foreach ( $validateArray as $validateField ) {
			$res[]			=	"Array('" . addslashes( $this->_getPagingParamName( $validateField['field'] ) ) . "',"
							.	"'" . addslashes( $validateField['confirm'] ) . "',"
							.	"'" . addslashes( $validateField['error'] ) . "')";
		}
		$_CB_framework->document->addHeadScriptDeclaration(
			  'var _admin' . $idTag . '_validations = Array( ' . implode( ',', $res ) . ");\n"
			. 'var _admin' . $idTag . "_bbcodestack = Array();\n"
		);
		return $htmltext;
	}