<?php /* Template Name: Contact Form */ 

get_header();

$get_meta = get_post_custom($post->ID);
$weblusive_sidebar_pos = isset( $get_meta['_weblusive_sidebar_pos'][0]) ? $get_meta["_weblusive_sidebar_pos"][0] : 'full';
get_template_part( 'library/includes/page-head' ); 
$options = array(
		weblusive_get_option('contact_error'), 
		weblusive_get_option('contact_success'),
		weblusive_get_option('contact_subject'), 
		weblusive_get_option('contact_email'), 		
	);
$address = weblusive_get_option('contact_address'); 
if (!empty($address)):?>
<script type="text/javascript">   
jQuery(function(){
	jQuery('#map').gmap3({
		action: 'addMarker',
		address: "<?php echo htmlspecialchars($address)?>",
		
		marker:{
			options:{
				icon : new google.maps.MarkerImage('<?php echo get_template_directory_uri()?>/images/mapmarker.png')
			}
		},
		
		map:{
			center: true,
			zoom: 14,
			},
		},
		{action: 'setOptions', args:[{scrollwheel:false}]}		
		);	  
	});
</script> 
<?php endif?> 
<div class="banner">
    <div class="inner-banner">
        <?php if (!weblusive_get_option('hide_titles')):?>
            <div class="note"><?php the_title(); ?></div>
       <?php endif?>
       <?php if (!weblusive_get_option('hide_breadcrumbs')):?>
            <div class="site-map">
                <?php _e('You are here:', 'Wecare');?>
                <?php if(class_exists('the_breadcrumb')){ $albc = new the_breadcrumb; } ?>
            </div>
        <?php endif?>
	<div class="clear"></div>
    </div>
</div>
<?php if (!empty($address)):?>
    <div id="map" class="gmap3 map_location map1"></div>
<?php endif?>
<div class="wrapper">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="contact-row dark">
    <div class="contact2 column4">
        <?php the_content(); ?>
    </div>
    <div class="msg-form column8">
        <h4><?php _e('Send us a message', 'Wecare'); ?></h4>
        <div class="border"></div>
        <form method="POST" class="contactForm" id="contact-form">
            <div id="status"></div>
			<div class="row-fluid">
				<div class="column4">
					<input type="text" placeholder="<?php _e('Name', 'Wecare')?>" name="contactname" id="contactname" />
					<?php if(isset($nameError) && $nameError != ''): ?><span class="errorarr"><?php echo $nameError;?></span><?php endif;?>
				</div>
				<div class="column4">	
					<input type="text" placeholder="<?php _e('E-mail', 'Wecare')?>" name="contactemail" id="contactemail" />
					<?php if(isset($emailError) && $emailError != ''): ?><span class="errorarr"><?php echo $emailError;?></span><?php endif;?>
				</div>
				<div class="column4">
					<input type="text" placeholder="<?php _e('Website', 'Wecare')?>" name="contactwebsite" id="contactwebsite" />
				</div>
			</div>
			<div class="row-fluid">
				<div class="column12">
					<textarea cols="10" rows="15" name="contactmessage" id="contactmessage"  placeholder="<?php _e('Message', 'Wecare')?>" ></textarea>
					<?php if(isset($messageError) && $messageError != ''): ?><span class="errorarr"><?php echo $messageError;?></span><?php endif;?>
				</div>
			</div>
			<div class="row-fluid">
				<div class="column12">
					<input type="submit" id="submit_contact" value="<?php _e('Send message', 'Wecare')?>" name="send"  />
					<input type="hidden" name = "options" value="<?php echo implode('|', $options) ?>" />
				</div>
			</div>
        </form>
    </div>
    <div class="clear"></div>
</div>
<?php endwhile; ?>
</div>

<script type="text/javascript">
<!-- Contact form validation
jQuery(document).ready(function(){

  jQuery(".contactForm").validate({
	submitHandler: function() {
	
		var postvalues =  jQuery(".contactForm").serialize();
		
		jQuery.ajax
		 ({
		   type: "POST",
		  url: "<?php echo get_template_directory_uri()  ?>/contact-form.php",
		   data: postvalues,
		   success: function(response)
		   {
		 	 jQuery("#status").html(response).show('normal');
		     jQuery('#contactmessage, #contactemail, #contactname, #contactwebsite').val("");
		   }
		 });
		return false;
		
    },
	focusInvalid: true,
	focusCleanup: false,
	//errorLabelContainer: jQuery("#registerErrors"),
  	rules: 
	{
		contactname: {required: true},
		contactemail: {required: true, minlength: 6,maxlength: 50, email:true},
		contactmessage: {required: true, minlength: 6}
	},
	
	messages: 
	{
		contactname: {required: "<?php _e( 'Name is required', 'Wecare' ); ?>"},
		contactemail: {required: "<?php _e( 'E-mail is required', 'Wecare' ); ?>", email: "<?php _e( 'Please provide a valid e-mail', 'Wecare' ); ?>", minlength:"<?php _e( 'E-mail address should contain at least 6 characters', 'Wecare' ); ?>"},
		contactmessage: {required: "<?php _e( 'Message is required', 'Wecare' ); ?>"}
	},
	
	errorPlacement: function(error, element) 
	{
		error.insertBefore(element);
		jQuery('<span class="errorarr"></span>').insertAfter(element);
	},
	invalidHandler: function()
	{
		//jQuery("body").animate({ scrollTop: 0 }, "slow");
	}
	
});
});
-->
</script>


<?php get_footer(); ?>