<?php
$front_required = __('front_required', true);
$front_validation = __('front_validation', true);
if($tpl['status'] != 1)
{
	?>
	<div class="ml-container">
		<div class="heading"><?php __('front_label_profile');?></div>
		<div class="body">
			<form action="" method="post" name="ml_profile_form" class="ml-form">
			<?php
			if($tpl['status'] != 0)
			{
				$profile_statuses = __('profile_statuses', true);
				?><p><label class="message info"><?php echo $profile_statuses[$tpl['status']]; ?></label></p><?php
			}else{
				?>
				<input type="hidden" name="id" value="<?php echo $tpl['arr']['id']; ?>"/>
				<?php
				if (in_array($tpl['option_arr']['o_pf_include_fname'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_first_name');?> <?php if($tpl['option_arr']['o_pf_include_fname'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="first_name" class="ml-text <?php echo $tpl['option_arr']['o_pf_include_fname'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['first_name']);?>" lang="<?php echo htmlspecialchars($front_required['first_name']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_lname'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_last_name');?> <?php if($tpl['option_arr']['o_pf_include_lname'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="last_name" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_lname'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['last_name']);?>"  lang="<?php echo htmlspecialchars($front_required['last_name']); ?>"/>
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_email'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_email');?> <?php if($tpl['option_arr']['o_pf_include_email'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="email" class="ml-text email<?php echo $tpl['option_arr']['o_pf_include_email'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['email']);?>" lang="<?php echo htmlspecialchars($front_required['email']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_password'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_password');?> <?php if($tpl['option_arr']['o_pf_include_password'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="password" name="password" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_password'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['password']);?>" lang="<?php echo htmlspecialchars($front_required['password']); ?>"/>
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_phone'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_phone');?> <?php if($tpl['option_arr']['o_pf_include_phone'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="phone" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_phone'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['phone']);?>" lang="<?php echo htmlspecialchars($front_required['phone']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_website'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_website');?> <?php if($tpl['option_arr']['o_pf_include_website'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="website" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_website'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['website']);?>" lang="<?php echo htmlspecialchars($front_required['website']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_gender'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_gender');?> <?php if($tpl['option_arr']['o_pf_include_gender'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<select name="gender" class="ml-select<?php echo $tpl['option_arr']['o_pf_include_gender'] == 3 ? ' ml-required' :null;?>" lang="<?php echo htmlspecialchars($front_required['gender']); ?>" >
								<option value="">-- <?php __('front_label_choose'); ?>--</option>
								<?php
								foreach (__('genderarr', true) as $k => $v)
								{
									?><option value="<?php echo $k; ?>" <?php echo $tpl['arr']['gender'] == $k ? 'selected="selected"' : null; ?>><?php echo $v; ?></option><?php
								}
								?>
							</select>
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_age'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_age');?> <?php if($tpl['option_arr']['o_pf_include_age'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="age" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_age'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['age']);?>" lang="<?php echo htmlspecialchars($front_required['age']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_birthday'], array(2, 3)))
				{ 
					$day = $month = $year = '';
					if(!empty($tpl['arr']['birthday']))
					{
						list($year, $month, $day) = explode("-", $tpl['arr']['birthday']);
					}
					?>
					<p>
						<label class="title"><?php __('front_label_birthday');?> <?php if($tpl['option_arr']['o_pf_include_birthday'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<?php
							echo pjUtil::dateSuite($tpl['option_arr']['o_date_format'], $day, $month, $year); 
							?>
						</span>
						<input type="hidden" name="birthday" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_birthday'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['birthday']);?>" lang="<?php echo htmlspecialchars($front_required['birthday']); ?>" />
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_address'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_address');?> <?php if($tpl['option_arr']['o_pf_include_address'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="address" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_address'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['address']);?>" lang="<?php echo htmlspecialchars($front_required['address']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_city'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_city');?> <?php if($tpl['option_arr']['o_pf_include_city'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="city" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_city'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['city']);?>" lang="<?php echo htmlspecialchars($front_required['city']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_state'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_state');?> <?php if($tpl['option_arr']['o_pf_include_state'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="state" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_state'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['state']);?>" lang="<?php echo htmlspecialchars($front_required['state']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_country'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_country');?> <?php if($tpl['option_arr']['o_pf_include_country'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<select name="country_id" class="ml-select<?php echo $tpl['option_arr']['o_pf_include_country'] == 3 ? ' ml-required' :null;?>" lang="<?php echo htmlspecialchars($front_required['country']); ?>" >
								<option value="">-- <?php __('front_label_choose'); ?>--</option>
								<?php
								foreach ($tpl['country_arr'] as $k => $v)
								{
									?><option value="<?php echo $v['id']; ?>" <?php echo $tpl['arr']['country_id'] == $v['id'] ? 'selected="selected"' : null; ?>><?php echo $v['country_title']; ?></option><?php
								}
								?>
							</select>
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_zip'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_zip');?> <?php if($tpl['option_arr']['o_pf_include_zip'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="zip" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_zip'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['zip']);?>" lang="<?php echo htmlspecialchars($front_required['zip']); ?>" />
						</span>
					</p>
					<?php
				}
				if (in_array($tpl['option_arr']['o_pf_include_company'], array(2, 3)))
				{ 
					?>
					<p>
						<label class="title"><?php __('front_label_company_name');?> <?php if($tpl['option_arr']['o_pf_include_company'] == 3){?><span class="star">*</span><?php }?></label>
						<span class="form-field">
							<input type="text" name="company_name" class="ml-text<?php echo $tpl['option_arr']['o_pf_include_company'] == 3 ? ' ml-required' :null;?>" value="<?php echo stripslashes($tpl['arr']['company_name']);?>" lang="<?php echo htmlspecialchars($front_required['company_name']); ?>" />
						</span>
					</p>
					<?php
				} 
				?>
				
				<ul class="ml-error-container" style="display: none"></ul>
				<p class="ml-message-container" style="display: none"></p>
				<p>
					<label class="title empty">&nbsp;</label>
					<input type="button" value="<?php __('front_button_save'); ?>" name="ml_profile_form_save" class="ml-button" />
				</p>
				<?php
			} 
			?>
			</form>
		</div>
	</div>
	<?php
} else if(empty($tpl['option_arr']['o_login_page'])){
	?>
	<div class="ml-container">
		<div class="body">
			<?php __('front_login_needed');?>
		</div>
	</div>
	<?php
}
?>

<script type="text/javascript">
	<?php
	if($tpl['status'] == 1 && !empty($tpl['option_arr']['o_login_page']))
	{
		?>
		window.location.href = "<?php echo $tpl['option_arr']['o_login_page'];?>";
		<?php
	} 
	?>
	var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
	var getSessionId = function () {
		return sessionStorage.getItem("session_id") == null ? "" : sessionStorage.getItem("session_id");
	};
	var createSessionId = function () {
		if(getSessionId()=="") {
			sessionStorage.setItem("session_id", "<?php echo session_id(); ?>");
		}
	};
	var session_id = "";
	if (isSafari) {
		createSessionId();
		session_id = getSessionId();
	}
	var profileMLObj = new profileML({
		session_id: session_id,
		status: "<?php echo $tpl['status']; ?>",
		
		profile_form_name: "ml_profile_form",
		profile_form_save_name: "ml_profile_form_save",

		check_email_url: "<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjFront&action=pjActionCheckEmail",
		profile_url: "<?php echo PJ_INSTALL_URL; ?>index.php?controller=pjFront&action=pjActionProfileSave",

		validation: {
			error_email_invalid: "<?php echo pjSanitize::clean($front_validation['email_invalid']); ?>",
			error_email_used: "<?php echo pjSanitize::clean($front_validation['email_used']); ?>",
			error_retype_password: "<?php echo pjSanitize::clean($front_validation['retype_password']); ?>",
			error_birthday_invalid: "<?php echo pjSanitize::clean($front_validation['birthday_invalid']); ?>"
		},
		message: {
			info: "<?php echo pjSanitize::clean(__('front_label_profile_info', true, false)); ?>",
			success: "<?php echo pjSanitize::clean(__('front_label_profile_success', true, false)); ?>",
			error: "<?php echo pjSanitize::clean(__('front_label_profile_error',true, false)); ?>"
		}
	});
</script>