<?php
/**
 * @name          : Joomla Social Pinboard
 * @version	  : 1.5.0
 * @package       : apptha
 * @since         : Joomla 1.5
 * @author        : Apptha - http://www.apptha.com
 * @copyright     : Copyright (C) 2011 Powered by Apptha
 * @license       : http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
 * @abstract      : Social Pinboard Component Contact view
 * @Creation Date : March 2013
 * @Modified Date : March 2013
 * */
// No direct Access
defined('_JEXEC') or die('Restricted access');
$base = JURI::base();
?>
<?php
$document = JFactory::getDocument();
$document->addStyleSheet('components/com_wishlogue/css/pinit.css');
$document->addStyleSheet('components/com_wishlogue/css/reset.css');
$document->addStyleSheet('templates/wishlogue/html/com_wishlogue/css/style.css');
$document->addScript('components/com_wishlogue/javascript/chrome.js');
$document->addStyleSheet('templates/wishlogue/html/mod_wishlogue_menu/css/wishlogue_menu.css');
$document->addStyleSheet('components/com_wishlogue/css/pinboard.css');
$app = JFactory::getApplication();
$templateparams = $app->getTemplate(true)->params; // get the tempalte parameters
$logo = $templateparams->get('logo'); //get the logo

$sendMailResult = '';
if (isset($this->sendMailResult)) {
	$sendMailResult = $this->sendMailResult;
}

if ($sendMailResult == 'success') {
	echo '<div class="contact-form-success">' . JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_SUCCESS') . '</div>';
} else if ($sendMailResult == 'failed') {
	echo '<div class="contact-form-failed">' . JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_FAILED') . '</div>';
}
?>

<div class="contact-form-title"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_TITLE'); ?>
	<span class="contact-form-mandatory-fields"><font>*</font><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_MANDATORY_FIELDS'); ?></span>
</div>

<form method="POST" action="" id='ContactForm'>
	<div id="send-mail-div" >
		<ul class="send-mail">
			<li>
				<label><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_NAME'); ?><span>*</span></label>
				<input class="edit-link" type="text" name="sender_name" id="sender_name">
				<div style="display:none;" class="mail-error" id="invalid_name"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_INVALID_NAME'); ?></div>
			</li>
			<li>
				<label><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_EMAIL'); ?><span>*</span></label>
				<input type="text" name="sender_email" id="sender_email">
				<div style="display:none;" class="mail-error" id="invalid_email"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_INVALID_EMAIL'); ?></div>
			</li>
			<li>
				<label><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_SUBJECT'); ?><span>*</span></label>
				<input type="text" name="sender_subject" id="sender_subject">
				<div style="display:none;" class="mail-error" id="invalid_subject"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_INVALID_SUBJECT'); ?></div>
			</li>
			<li>
				<label><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_MESSAGE'); ?><span>*</span></label>
				<textarea name='sender_message' id='sender_message'></textarea>
				<div style="display:none;" class="mail-error" id="invalid_message"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_INVALID_MESSAGE'); ?></div>
			</li>

			<li>
				<label><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_CAPTCHA'); ?><span>*</span></label>
				<p class='captcha-description'><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_CAPTCHA_DESCRIPTION'); ?></p>
				<div class='captcha-image'>
				<div class='captcha-imagea'>
                                    <img id='captchaimg' src='<?php echo JUri::root(); ?>/index.php?option=com_wishlogue&view=contact&task=captcha_code&tmpl=component'>
                                   </div>
                                    <div class="captcha-imageb">
					<p class='cpatcha-question'><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_CAPTCHA_QUESTION'); ?></p>
					<p class='cpatcha-refresh'><a href='javascript: refreshCaptcha();' class="re-text"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_CAPTCHA_REFRESH'); ?></a></p>
                                        </div>
				</div>
				<input id="6_letters_code" name="6_letters_code" type="text" class="form-item">
				<p class='captcha-notes'><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_CAPTCHA_ENTER_THE_CHARCTERS'); ?></p>
				<div style="display:none;" class="mail-error" id="invalid_captcha"><?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_INVALID_CAPTCHA'); ?></div>
			</li>

			<li>
				<label>&nbsp;</label>
				<input onclick="validate()" class="send-mail-button" type="button" value="<?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_SUBMIT'); ?>" name="send_mail" id="send_mail">
				<input class="send-mail-reset" type="reset" value="<?php echo JTEXT::_('COM_WISHLOGUE_CONTACT_FORM_RESET'); ?>" name="reset_form" id="reset_form">
				<input type="hidden" value="mail_form_submitted" name="send_mail_form" id="send_mail_form">
			</li>
		</ul>
	</div>
</form>
<script>
					function validate() {

						var sender_message = jQuery('#sender_message').val();
						var error_flag = 0;
						jQuery('#invalid_name').css("display", "none");
						jQuery('#invalid_email').css("display", "none");
						jQuery('#invalid_subject').css("display", "none");
						jQuery('#invalid_message').css("display", "none");
						jQuery('#invalid_captcha').css("display", "none");

						if (jQuery.trim(jQuery('#sender_name').val()) === null || jQuery.trim(jQuery('#sender_name').val()) === '') {
							jQuery('#invalid_name').css("display", "block");
							error_flag = 1;
						}
						if (jQuery.trim(jQuery('#sender_email').val()) === null || jQuery.trim(jQuery('#sender_email').val()) === '' || !IsValidEmail(jQuery('#sender_email').val())) {
							jQuery('#invalid_email').css("display", "block");
							error_flag = 1;
						}
						if (jQuery.trim(jQuery('#sender_subject').val()) === null || jQuery.trim(jQuery('#sender_subject').val()) === '') {
							jQuery('#invalid_subject').css("display", "block");
							error_flag = 1;
						}
						if (sender_message === null || sender_message === '') {
							jQuery('#invalid_message').css("display", "block");
							error_flag = 1;
						}

						jQuery.get("<?php echo JUri::root(); ?>/index.php?option=com_wishlogue&view=contact&task=captcha_session&tmpl=component", function(data) {
							var dat;
							dat = data;
							var x = document.getElementById("6_letters_code").value;

							if (x === dat && x !== '' && dat !== '')
							{
								if (error_flag === 0) {
									document.getElementById("ContactForm").submit();
								}
							}
							else
							{
								jQuery('#invalid_captcha').css("display", "block");
							}
						});
					}
					function IsValidEmail(email) {
						var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						return regex.test(email);
					}

					function refreshCaptcha()
					{
						var img = document.images['captchaimg'];
						img.src = '<?php echo JUri::root(); ?>/index.php?option=com_wishlogue&view=contact&task=captcha_code&tmpl=component';
					}

</script>