<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
set_magic_quotes_runtime(0);
include("include/dbcommon.php");
include("include/##@TABLE.strShortTableName##_variables.php");
##if @BUILDER.bCaptcha##
if((!isset($_SESSION["count_captcha"])) or ($_SESSION["count_captcha"]>4)) $_SESSION["count_captcha"]=0;
##endif##
$registered=false;
//event for onsubmit
$onsubmit="";
$strMessage="";
$allow_registration=true;
$strUsername="";
$strPassword="";
$strEmail="";
$values=array();

include('include/xtempl.php');
$xt = new Xtempl();


//	Before Process event
if(function_exists("BeforeProcessRegister"))
	BeforeProcessRegister($conn);

##if @BUILDER.bSendActivationLink##
if(@$_GET["a"]=="activate")
{
	$username=base64_decode(@$_GET["u"]);
	$code = @$_GET["code"];
	$strUsername = make_db_value("##@BUILDER.strUserNameField s##",$username);
	$sql = "select ##@BUILDER.strPasswordField ws## from ##@BUILDER.strLoginTable ts## where ##@BUILDER.strUserNameField ws##=".$strUsername;
	$rs = db_query($sql,$conn);
	$verified=false;
	if(!$rs)
	{
		echo ##message SEC_INVALID_REG_CODE##;
		return;
	}
	$data = db_fetch_numarray($rs);
	if(!$data)
	{
		echo ##message SEC_INVALID_REG_CODE##;
		return;
	}
##if @BUILDER.bEncryptPasswords##
	$usercode = $username.$data[0];
##else##
	$usercode = $username.md5($data[0]);
##endif##
	if($code!=md5($usercode))
	{
		echo ##message SEC_INVALID_REG_CODE##;
		return;
	}
	$sql = "update ##@BUILDER.strLoginTable ts## set ##@BUILDER.strActivationField ws##=1 where ##@BUILDER.strUserNameField ws##=".$strUsername;
	db_exec($sql,$conn);

	$body=array();
	$body["begin"]="<form method=\"POST\" action=\"login.##@ext##\" name=\"loginform\">
	<input type=\"Hidden\" name=username value=\"".htmlspecialchars($username)."\">";
##if !@BUILDER.bEncryptPasswords##
	$body["begin"].="<input type=\"Hidden\" name=password value=\"".htmlspecialchars($data[0])."\">";
##endif##
	$body["begin"].="</form>";
	$xt->assign("body",$body);
	$xt->assign("registered_block",true);
	$xt->assign("loginlink_attrs","onclick=\"document.forms.loginform.submit();return false;\"");
	$xt->display("register_success.htm");
	return;
}
##endif##

if(@$_POST["btnSubmit"] == "Register")
{
##if @BUILDER.bCaptcha##
	if(($_SESSION["count_captcha"]==0) or ($_SESSION["count_captcha"]>4))
	{
		if(@strtolower(@$_POST["captcha"])!=strtolower(@$_SESSION["captcha"]))
		{
			$xt->assign("captcha_msg",##message SEC_INVALID_CAPTCHA_CODE##);
			$allow_registration=false;
			$captcha_passed=0;
		}
		else
		 	$captcha_passed=1;
	}
    else 
		$captcha_passed=1;
##endif##

	$filename_values=array();
	$blobfields=array();
	$files_move=array();
	$files_save=array();
	$inlineedit=ADD_SIMPLE;

##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach Fields as @f filter @f.strName==@uf##
//	processing ##@f.strName## - start

	$value = postvalue("value_##@f.strName g##");
	$type=postvalue("type_##@f.strName g##");
	if (FieldSubmitted("##@f.strName s##"))
	{
##if @f.strEditFormat==EDIT_FORMAT_DATABASE_FILE && @f.ListFormatObj.strFilename##
		$value=prepare_for_db("##@f.strName s##",$value,$type,postvalue("filename_##@f.strName g##"));
##else##
		$value=prepare_for_db("##@f.strName s##",$value,$type);
##endif##
	}
	else
		$value=false;
	if(!($value===false))
	{
##if (@f.bResizeOnUpload || @f.bCreateThumbnail) && @f.strEditFormat==EDIT_FORMAT_FILE##
		if($value)
			$contents = GetUploadedFileContents("file_##@f.strName g##");
##endif##

##if @f.bCreateThumbnail && (@f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE || @f.strEditFormat==EDIT_FORMAT_FILE)##
//	create thumbnail
		if($value)
		{
	##if @f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE##
			$ext = CheckImageExtension(GetUploadedFileName("file_##@f.strName g##"));
			$thumb = CreateThumbnail($value,##@f.nThumbnailSize##,$ext);
			$blobfields[]="##@f.strThumbnail s##";
			$values["##@f.strThumbnail s##"]=$thumb;
	##else##
			$ext = CheckImageExtension(GetUploadedFileName("file_##@f.strName g##"));
			$thumb = CreateThumbnail($contents,##@f.nThumbnailSize##,$ext);
			$file = GetUploadFolder("##@f.strName s##")."##@f.strThumbnail s##".$value;
			$files_save[] = array("file"=>$thumb,"filename"=>$file);
	##endif##
		}
##endif##

##if @f.bResizeOnUpload && (@f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE || @f.strEditFormat==EDIT_FORMAT_FILE)##
//	resize
		if($value)
		{
	##if @f.strEditFormat==EDIT_FORMAT_DATABASE_IMAGE##
			$ext = CheckImageExtension(GetUploadedFileName("value_##@f.strName g##"));
			$thumb = CreateThumbnail($value,##@f.nNewSize##,$ext);
			$blobfields[]="##@f.strName s##";
	##endif##
		}
##endif##
		$blobfields[]="##@f.strName s##";
		$values["##@f.strName s##"]=$value;
	}
##if @f.strEditFormat==EDIT_FORMAT_DATABASE_FILE && @f.ListFormatObj.strFilename##
	if($filename)
		$afilename_values["##@f.ListFormatObj.strFilename s##"]=$filename;
##endif##
//	processibng ##@f.strName## - end
##endfor##
##endfor##

	$strUsername = $values["##@BUILDER.strUserNameField s##"];
	$strPassword = $values["##@BUILDER.strPasswordField s##"];
##if @BUILDER.strUserEmailField##
	$strEmail = $values["##@BUILDER.strUserEmailField s##"];
##endif##


//	add filenames to values
	foreach($filename_values as $key=>$value)
		$values[$key]=$value;

//	check if entered username already exists
	if(!strlen($strUsername))
	{
		$xt->assign("user_msg",##message USER_NOEMPTY##);
		$allow_registration=false;
	}	
	else
	{
		$strSQL="select count(*) from ##@BUILDER.strLoginTable ts## where ##@BUILDER.strUserNameField ws##=".add_db_quotes("##@BUILDER.strUserNameField s##",$strUsername);
	   	$rs=db_query($strSQL,$conn);
		$data=db_fetch_numarray($rs);
		if($data[0]>0)
		{
			$xt->assign("user_msg",##message USERNAME_EXISTS1##." <i>".$strUsername."</i> ".##message USERNAME_EXISTS2##);
			$allow_registration=false;
		}
	}

##if @BUILDER.bRemindPwdPage##
//	check if entered email already exists
	
	if(!strlen($strEmail))
	{
		$xt->assign("email_msg",##message VALID_EMAIL##);
		$allow_registration=false;
	}
	else
	{
		$strSQL="select count(*) from ##@BUILDER.strLoginTable ts## where ##@BUILDER.strUserEmailField ws##=".add_db_quotes("##@BUILDER.strUserEmailField s##",$strEmail);
	   	$rs=db_query($strSQL,$conn);
		$data=db_fetch_numarray($rs);
		if($data[0]>0)
		{
			$xt->assign("email_msg",##message EMAIL_ALREADY1##." <i>".$strEmail."</i> ".##message EMAIL_ALREADY2##);
			$allow_registration=false;
		}
	}
##endif##
##if @BUILDER.bSendActivationLink##
	$values["##@BUILDER.strActivationField s##"]=0;
##endif##

##if @BUILDER.bStrongPassword##
	if(!checkpassword($values["##@BUILDER.strPasswordField s##"]))
	{
		$msg="";
##if @BUILDER.nPwdLen##
		$fmt=##message SEC_PWD_LEN##;
		$fmt=str_replace("%%","##@BUILDER.nPwdLen##",$fmt);
		$msg.="<br>".$fmt;
##endif##
##if @BUILDER.nPwdUnique##
		$fmt=##message SEC_PWD_UNIQUE##;
		$fmt=str_replace("%%","##@BUILDER.nPwdUnique##",$fmt);
		$msg.="<br>".$fmt;
##endif##
##if @BUILDER.nPwdDigits##
		$fmt=##message SEC_PWD_DIGIT##;
		$fmt=str_replace("%%","##@BUILDER.nPwdDigits##",$fmt);
		$msg.="<br>".$fmt;
##endif##
##if @BUILDER.bPwdUpperLower##
		$fmt=##message SEC_PWD_CASE##;
		$msg.="<br>".$fmt;
##endif##
		if($msg)
			$msg=substr($msg,4);
		$xt->assign("password_msg",$msg);
		$allow_registration=false;
	}
		
##endif##	
	$retval=true;
	
	if($allow_registration)
	{
		if(function_exists("BeforeRegister"))
			$retval = BeforeRegister($values,$strMessage);
	}
	else
		$retval=false;

	if($retval)
	{
##if @BUILDER.bEncryptPasswords##
//	encrypt password
		$originalpassword=$values["##@BUILDER.strPasswordField s##"];
		$values["##@BUILDER.strPasswordField s##"]=md5($values["##@BUILDER.strPasswordField s##"]);
##endif##
		$retval=DoInsertRecord("##@BUILDER.strLoginTable s##",$values,$blobfields);
##if @BUILDER.bEncryptPasswords##
		$values["##@BUILDER.strPasswordField s##"]=$originalpassword;
##endif##
	}
	else
		$retval=false;
	if($retval)
	{
		if(function_exists("AfterSuccessfulRegistration"))
			AfterSuccessfulRegistration($values);
		$url = GetSiteUrl();
		$url.=$_SERVER["SCRIPT_NAME"];
##if @BUILDER.bNotifyUser##
//	send email to user
		$message=##message REGMAIL_USER1##." ".$url."\r\n\r\n";
##if @BUILDER.bSendActivationLink##
		$message.= ##message REGMAIL_USER2##.":\r\n";
		$message.= $url."?a=activate&u=".rawurlencode(base64_encode($values["##@BUILDER.strUsernameField s##"]))."&code=";
		$message.=rawurlencode(md5($values["##@BUILDER.strUsernameField s##"].md5($values["##@BUILDER.strPasswordField s##"])));
		$message.="\r\n(".##message REGMAIL_USER3##.")\r\n\r\n";
##endif##
##foreach @BUILDER.Registration.arrUserFields as @f##
		$strLabel = ##label @TABLE.strDataSourceTable @f##;
		$message.=$strLabel.": ".$values["##@f s##"]."\r\n";
##endfor##
		if(($pos=strpos($strEmail,"\r"))!==FALSE || ($pos=strpos($strEmail,"\n"))!==FALSE)
			$strEmail=substr($strEmail,0,$pos);
		runner_mail(array('to' => $strEmail, 'subject' => ##message REGMAIL_USER4##, 'body' => $message));
##endif##

##if @BUILDER.bNotifyAdmin##
//	send letter to admin
		$message=##message REGMAIL_ADMIN1##." ".$url."\r\n";
##foreach @BUILDER.Registration.arrUserFields as @f filter @f!=@BUILDER.strPasswordField || @BUILDER.strPasswordField==@BUILDER.strUserNameField##
//		$strLabel = "##Fields[strName==@f].strLabel s##";
		$strLabel = ##label @TABLE.strDataSourceTable @f##;

		$message.=$strLabel.": ".$values["##@f s##"]."\r\n";
##endfor##
		runner_mail(array('to' => "##@BUILDER.strAdminEmail s##", 'subject' => ##message REGMAIL_USER4##, 'body' => $message));
##endif##

//	show Registartion successful message
		$body=array();
##if @BUILDER.bSendActivationLink##
		$xt->assign("email",$strEmail);
		$xt->assign("activation_block",true);
##else##
		$body["begin"]="<form method=\"POST\" action=\"login.##@ext##\" name=\"loginform\">
		<input type=\"Hidden\" name=username value=\"".htmlspecialchars($strUsername)."\">".
		"<input type=\"Hidden\" name=password value=\"".htmlspecialchars($strPassword)."\">".
		"</form>";
		$xt->assign("registered_block",true);
##endif##
		$xt->assign("body",$body);
		$xt->assign("loginlink_attrs","onclick=\"document.forms.loginform.submit();return false;\"");
##if @BUILDER.bCaptcha##
		$_SESSION["count_captcha"]=$_SESSION["count_captcha"]+1;
 ##endif##

		$xt->display("register_success.htm");
		return;
	}
	else
	{
		if(function_exists("AfterUnsuccessfulRegistration"))
			AfterUnsuccessfulRegistration($values,$strMessage);
	}
	if(!$retval)
	{
		if($strMessage!="")
		{
			$xt->assign("message",$strMessage);
			$xt->assign("message_block",true);
		}
##if @BUILDER.bCaptcha##
		if($captcha_passed==1) $_SESSION["count_captcha"]=$_SESSION["count_captcha"]+1;
##endif##
	}
}
//////////////////////////////////////////////////////////////////	
//	validation stuff
$bodyonload="";
//Basic includes js files
$includes="";
//javascript code
$jscode="";
//	Begin Add validation params for Regester	
	$regex='';
	$regexmessage='';
	$func="";
	$regextype = '';
	$arrValidate = array();
//	for inlineEdit
	$regValidateTypes = array();
	$regValidateFields = array();
	$regValidateUseRTE = array();
	$regValidateCBList = array();
	$regValidateRegex = array();
	$regValidateRegexmes = array();	
	$regValidateRegexmestype = array();	
//	Begin Edit validation	
//if use InnovaEditor or RTE on page add when useRTE will be with  -  "_FLY"
//if use InnovaEditor or RTE on page InineEdit when useRTE will be with out  -  "_FLY"
	AddJSFile("validate");
	
	if(@$_REQUEST["language"])
		$language = $_REQUEST["language"];
	// may be elseif ?
	if(@$_SESSION["language"])
		$language = $_SESSION["language"];
	else
		$language = 'English';
	
	$jscode.="window.current_language='".jsreplace($language)."';\r\n";
	
	$jscode.="regValid = new validation();\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_REQUIRED='".jsreplace(##message INLINE_FIELD_REQUIRED##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_ZIPCODE='".jsreplace(##message INLINE_FIELD_ZIPCODE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_EMAIL='".jsreplace(##message INLINE_FIELD_EMAIL##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_NUMBER='".jsreplace(##message INLINE_FIELD_NUMBER##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_CURRENCY='".jsreplace(##message INLINE_FIELD_CURRENCY##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_PHONE='".jsreplace(##message INLINE_FIELD_PHONE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_PASSWORD1='".jsreplace(##message INLINE_FIELD_PASSWORD1##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_PASSWORD2='".jsreplace(##message INLINE_FIELD_PASSWORD2##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_STATE='".jsreplace(##message INLINE_FIELD_STATE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_SSN='".jsreplace(##message INLINE_FIELD_SSN##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_DATE='".jsreplace(##message INLINE_FIELD_DATE##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_TIME='".jsreplace(##message INLINE_FIELD_TIME##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_CC='".jsreplace(##message INLINE_FIELD_CC##)."';\r\n";
	$jscode.="window.TEXT_INLINE_FIELD_SSN='".jsreplace(##message INLINE_FIELD_SSN##)."';\r\n";
	$jscode.="window.TEXT_INLINE_MATCH_PASSWORDS='".jsreplace(##message DONT_MATCH##)."';\r\n";	
##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach Fields as @f filter @f.strName==@uf && NeedValidation(@f)##
//	validate field - ##@f.strName g##
##if @f.strEditFormat!=EDIT_FORMAT_TEXT_FIELD && @f.strEditFormat!=EDIT_FORMAT_TIME##
	$validatetype="";
##else##
##if @f.EditFormatObj.strValidateAs==VALIDATE_AS_NUMBER##
	$validatetype="IsNumeric";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_PASSWORD##
	$validatetype="IsPassword";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_EMAIL##
	$validatetype="IsEmail";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_CURRENCY##
	$validatetype="IsMoney";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_ZIPCODE##
	$validatetype="IsZipCode";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_PHONENUMBER##
	$validatetype="IsPhoneNumber";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_STATE##
	$validatetype="IsState";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_SSN##
	$validatetype="IsSSN";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_CC##
	$validatetype="IsCC";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_TIME##
	$validatetype="IsTime";
##elseif @f.EditFormatObj.strValidateAs==VALIDATE_AS_REGEXP##
	$validatetype="Regular expression";
	$regex = "##@f.strRegex##";
	$regexmessage = "##@f.strRegexMessage.text s##";
	$regextype = "##@f.strRegexMessage.nameType s##";
##else##
	$validatetype="##@f.EditFormatObj.strValidateAs##";
	##if @f.EditFormatObj.strValidateAs##
	AddJSFile("validate/".$validatetype,"validate");
	##endif##	
##endif##
##endif##
##if @f.EditFormatObj.bRequired && @f.strEditFormat!=EDIT_FORMAT_CHECKBOX && @f.strEditFormat!=EDIT_FORMAT_READONLY##
	$second_validatetype="IsRequired";
##else##
	$second_validatetype="";
##endif##
##if UseRTEFCK(@f)##
	$strRTE='FCK';
##elseif UseRTEINNOVA(@f)##
	$strRTE='INNOVA_FLY';
##elseif  UseRTEBASIC(@f)##
	$strRTE='RTE_FLY';	
##else##
	$strRTE='';
##endif##
##if @f.nControlType==LCT_CBLIST##
	$lookup='CBList';
##elseif @f.nControlType==LCT_LIST || @f.nControlType==LCT_AJAX##
	$lookup='disp';
##elseif @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && @f.nLookupType!=LT_LOOKUPTABLE && @f.nSelectSize>1##	
	$lookup='list';
##else##
	$lookup='';	
##endif##
	$arrValidate[] = array(0 => "##@f.strName g##", 1 => $validatetype, 2 => $second_validatetype, 3 => $strRTE,
						   4 => $lookup, 5 => $regex, 6 => $regexmessage, 7 => $regextype);
##endfor##
##endfor##
$bodyonload.="regValid.add(document.editform['value_##@BUILDER.strUserNameField##'],'IsRequired','','');\r\n";	
$bodyonload.="regValid.add(document.editform['value_##@BUILDER.strPasswordField##'],'IsRequired','','');\r\n";	
$bodyonload.="regValid.add(document.editform['value1_##@BUILDER.strPasswordField##'],'IsMatchPasswords','','');\r\n";
$bodyonload.="regValid.add(document.editform['value1_##@BUILDER.strPasswordField##'],'IsRequired','','');\r\n";
for($i=0;$i<count($arrValidate);$i++)
{
	if($arrValidate[$i][1])
	{
		if ($arrValidate[$i][1]=="Regular expression")
			$bodyonload.="regValid.addRegex(document.editform['value_".$arrValidate[$i][0]."'],'".$arrValidate[$i][1]."','".
				jsreplace($arrValidate[$i][5])."','".jsreplace($arrValidate[$i][6])."','".jsreplace($arrValidate[$i][7])."');\r\n";
		else
			$bodyonload.="regValid.add(document.editform['value_".$arrValidate[$i][0]."'],'".$arrValidate[$i][1]."','".$arrValidate[$i][3]."','".$arrValidate[$i][4]."');\r\n";
	}
	if($arrValidate[$i][2])
	{
		if($arrValidate[$i][3]=='INNOVA_FLY' || $arrValidate[$i][3]=='RTE_FLY')
		{
			$bodyonload.='$("table:last td").each(function(){';
			$bodyonload.='if($("iframe[@name=\'value_'.$arrValidate[$i][0].'\']",this).length)';
			$bodyonload.='regValid.add($("iframe[@name=\'value_'.$arrValidate[$i][0].'\']",this),"'.$arrValidate[$i][2].'","'.$arrValidate[$i][3].'","'.$arrValidate[$i][4].'");});';
			$func.='getDataFromRTEInnova($(\'#value_'.$arrValidate[$i][0].'\'),\''.$arrValidate[$i][3].'\',$(\'#editform\'),\'value_'.$arrValidate[$i][0].'\');'; 
		}
		else
			$bodyonload.="regValid.add(document.editform['".($arrValidate[$i][4]=='disp' ? "display_" : "")."value_".$arrValidate[$i][0].($arrValidate[$i][4]=='CBList' || $arrValidate[$i][4]=='list' ? "[]" : "")."'],'".$arrValidate[$i][2]."','".$arrValidate[$i][3]."','".$arrValidate[$i][4]."');\r\n";
	}		
}
##if @BUILDER.bCaptcha##
if(($_SESSION["count_captcha"]==0) or ($_SESSION["count_captcha"]>4))
	$bodyonload.="regValid.add(document.editform['captcha'],'IsRequired','','');\r\n";	
##endif##
##if @BUILDER.strUserEmailField##
$bodyonload.="regValid.add(document.editform['value_##@BUILDER.strUserEmailField##'],'IsEmail','','');\r\n";	
##endif##
//	End Add validation params for InlineEdit or Edit
//////////////////////////////////////////////////////////////
##foreach Fields as @f filter @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && (@f.nControlType==LCT_LIST || @f.bAllowToAdd)##
##if @first##
AddJSFile("ui");
AddJSFile("ui.core","ui");
AddJSFile('ui.resizable','ui.core');
AddJSFile("onthefly");
##endif##
##endfor##
////////////////////// time picker
##foreach Fields as @f filter @f.useTimePicker##
##if @first##
	AddJSFile("ui");
	AddJSFile("jquery.utils","ui");
	AddJSFile("ui.dropslide","jquery.utils");
	AddJSFile("ui.timepickr","ui.dropslide");
	AddCSSFile("ui.dropslide");
##endif##
##endfor##
//////////////////////
##if UseRTEINNOVA(@f) || UseRTEBASIC(@f)##
		$onsubmit.="if(regValid.validate()){".$func."return true;}else return false;";
##else##	
		$onsubmit.="return regValid.validate();";
##endif##
$includes.="<script language=\"JavaScript\" src=\"include/jquery.js\"></script>\r\n";
	AddJSFile("ajaxsuggest");
	$includes.="<script language=\"JavaScript\" src=\"include/customlabels.js\"></script>\r\n";
	$includes.="<script language=\"JavaScript\" src=\"include/jsfunctions.js\"></script>\r\n";
	$jscode.= "window.locale_dateformat = ".$locale_info["LOCALE_IDATE"].";\r\n".
	"window.locale_datedelimiter = \"".$locale_info["LOCALE_SDATE"]."\";\r\n".
	"bLoading=false;\r\n".
	"window.TEXT_PLEASE_SELECT='".jsreplace(##message PLEASE_SELECT##)."';\r\n";
	$jscode.="SUGGEST_TABLE='##@TABLE.strShortTableName##_searchsuggest.php';\r\n";
	$includes.="<div id=\"search_suggest\"></div>\r\n";

##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach Fields as @f filter @f.strName==@uf && UseCalendar(@f)##
	##if @first##
//	include datepicker files

	$jscode.="window.TEXT_MONTH_JAN='".jsreplace(##message MONTH_JAN##)."';\r\n";
	$jscode.="window.TEXT_MONTH_FEB='".jsreplace(##message MONTH_FEB##)."';\r\n";
	$jscode.="window.TEXT_MONTH_MAR='".jsreplace(##message MONTH_MAR##)."';\r\n";
	$jscode.="window.TEXT_MONTH_APR='".jsreplace(##message MONTH_APR##)."';\r\n";
	$jscode.="window.TEXT_MONTH_MAY='".jsreplace(##message MONTH_MAY##)."';\r\n";
	$jscode.="window.TEXT_MONTH_JUN='".jsreplace(##message MONTH_JUN##)."';\r\n";
	$jscode.="window.TEXT_MONTH_JUL='".jsreplace(##message MONTH_JUL##)."';\r\n";
	$jscode.="window.TEXT_MONTH_AUG='".jsreplace(##message MONTH_AUG##)."';\r\n";
	$jscode.="window.TEXT_MONTH_SEP='".jsreplace(##message MONTH_SEP##)."';\r\n";
	$jscode.="window.TEXT_MONTH_OCT='".jsreplace(##message MONTH_OCT##)."';\r\n";
	$jscode.="window.TEXT_MONTH_NOV='".jsreplace(##message MONTH_NOV##)."';\r\n";
	$jscode.="window.TEXT_MONTH_DEC='".jsreplace(##message MONTH_DEC##)."';\r\n";
	
	$jscode.="window.TEXT_DAY_SU='".jsreplace(##message DAY_SU##)."';\r\n";
	$jscode.="window.TEXT_DAY_MO='".jsreplace(##message DAY_MO##)."';\r\n";
	$jscode.="window.TEXT_DAY_TU='".jsreplace(##message DAY_TU##)."';\r\n";
	$jscode.="window.TEXT_DAY_WE='".jsreplace(##message DAY_WE##)."';\r\n";
	$jscode.="window.TEXT_DAY_TH='".jsreplace(##message DAY_TH##)."';\r\n";
	$jscode.="window.TEXT_DAY_FR='".jsreplace(##message DAY_FR##)."';\r\n";
	$jscode.="window.TEXT_DAY_SA='".jsreplace(##message DAY_SA##)."';\r\n";
	
	$jscode.="window.TEXT_TODAY='".jsreplace(##message TODAY##)."';\r\n";	
	
	AddJSFile("calendar");
	##endif##
##endfor##
##endfor##

##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach Fields as @f filter @f.strName==@uf && UseRTEFCK(@f)##
##if @first##
include("plugins/fckeditor/fckeditor.php");
##endif##
##endfor##
##endfor##
$xt->assign("bodyonload",$bodyonload);

if(strlen($onsubmit))
	$onsubmit="onSubmit=\"".$onsubmit."\"";



//	assign values to the controls

if(!count($values))
{
##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach Fields as @f filter @f.strName==@uf && @f.strDefaultValue.len order @f.nAddPageOrder##
	$values["##@f.strName s##"]=##@f.strDefaultValue##;
##endfor##
##endfor##
}

##foreach @BUILDER.Registration.arrUserFields as @uf filter @uf!=@BUILDER.strPasswordField##
##foreach Fields as @f filter @f.strName==@uf && !IsBinaryField(@f) order @f.nAddPageOrder##
//$xt->assign("value_##@f.strName g##",@$values["##@f.strName s##"]);
$control_##@f.strName g##=array();
$control_##@f.strName g##["func"]="xt_buildeditcontrol";
$control_##@f.strName g##["params"] = array();
$control_##@f.strName g##["params"]["field"]="##@f.strName s##";
$control_##@f.strName g##["params"]["value"]=@$values["##@f.strName s##"];
$control_##@f.strName g##["params"]["mode"]="add";
$xt->assignbyref("##@f.strName g##_editcontrol",$control_##@f.strName g##);
$xt->assign("##@f.strName g##_fieldblock",true);
##endfor##
##endfor##

##if @BUILDER.strUserNameField!=@BUILDER.strPasswordField##
$xt->assign("password_attrs","name=\"value_##@BUILDER.strPasswordField s##\" value=\"".htmlspecialchars(@$values["##@BUILDER.strPasswordField s##"])."\"");
$xt->assign("confirm_attrs","name=\"value1_##@BUILDER.strPasswordField s##\" value=\"".htmlspecialchars(@$values["##@BUILDER.strPasswordField s##"])."\"");
$xt->assign("password_block",true);
$xt->assign("confirm_block",true);
##endif##
$xt->assign("username_block",true);
$xt->assign("buttons_block",true);

$readonlyfields=array();

//	show readonly fields
##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach Fields as @f filter @f.strName==@uf && @f.strEditFormat==EDIT_FORMAT_READONLY##
##if @f.strViewFormat==FORMAT_HTML || @f.strViewFormat==FORMAT_FILE_IMAGE || @f.strViewFormat==FORMAT_FILE || @f.strViewFormat==FORMAT_HYPERLINK || @f.strViewFormat==FORMAT_EMAILHYPERLINK || @f.strViewFormat==FORMAT_CHECKBOX##
	$readonlyfields["##@f.strName s##"] = GetData($values,"##@f.strName s##", "##@f.strViewFormat##");
##else##
	$readonlyfields["##@f.strName s##"] = htmlspecialchars(GetData($values,"##@f.strName s##", "##@f.strViewFormat##"));
##endif##
##endfor##
##endfor##

if ($useAJAX) {
##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach @TABLE.arrFieldObj as @f filter @f.strName==@uf && @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && @f.bUseCategory##
		$output = loadSelectContent("##@f.strName s##",@$values["##@f.strCategoryControlField s##"],@$values["##@f.strName s##"]);
		$txt = ""; 
		foreach( $output as $value ) {
			$txt .= jsreplace($value)."\\n";
		}
		$jscode .= "preloadSelectContent('".$txt."', 'value_##@f.strName g##', '".jsreplace(@$values["##@f.strName s##"])."','');\r\n";
##endfor##
##endfor##
}
else
{
##foreach @BUILDER.Registration.arrUserFields as @uf##
##foreach @TABLE.arrFieldObj as @f filter @f.strName==@uf && @f.strEditFormat==EDIT_FORMAT_LOOKUP_WIZARD && @f.bUseCategory##
	//	##@f.strName## - ##@f.strCategoryControlField##
	$jscode.="bLoading = true;";
	$jscode.="SetSelection('value_##@f.strCategoryControlField g##', 'value_##@f.strName g##', '".jsreplace(@@$values["##@f.strCategoryControlField s##"])."', '".jsreplace(@$values["##@f.strName s##"])."', arr_##@f.strName g##);";
	$jscode.="bLoading = false;";
##endfor##
##endfor##
}

##if @BUILDER.bCaptcha##
if(($_SESSION["count_captcha"]==0) or ($_SESSION["count_captcha"]>4))
{
 $xt->assign("captcha_block",true);
 $xt->assign("captcha",
 "<object type=\"application/x-shockwave-flash\" data=\"securitycode.swf?ext=##@ext##\" width=\"210\" height=\"65\">
	<param name=\"movie\" value=\"securitycode.swf?ext=##@ext##\" />
	<param name=\"wmode\" value=\"opaque\" />
	<a href=\"http://www.macromedia.com/go/getflashplayer\"><img src=\"\" alt=\"Download Flash\" /></a>
  </object>");
}
else $xt->assign("captcha_block",false);
##endif##

$body=array();
$body["begin"]=$includes.
	"<form encType=\"multipart/form-data\" method=\"POST\" action=\"register.##@ext##\" id=\"editform\" name=\"editform\" ".$onsubmit.">
	<input type=hidden name=btnSubmit value=\"Register\">";
$jscode.= "flag_but=0; ".$bodyonload."\r\n SetToFirstControl('editform');\r\n";
	PrepareJSCode($jscode,'');
$body["end"]="</form><script>".$jscode."</script>";	
	$xt->assignbyref("body",$body);
$templatefile="register.htm";
if(function_exists("BeforeShowRegister"))
	BeforeShowRegister($xt,$templatefile);

$xt->display($templatefile);

?>
