<?php
/*
Template Name: Contact
*/
	$contact = false;
    function ContactError($fieldName)
    {
        wp_die(__('Error: please fill the Field "'.$fieldName.'"!','hybrid_lang' ) .
            __('<a onclick="history.go(-1)"><p style="cursor: hand; cursor: pointer;">Back</p></a>'));
    }
    if(isset($_POST["hybrid_contactForm"]) && $_POST["hybrid_contactForm"])
    {
        if(empty($_POST["contactName"]))            ContactError('Name');
        else if(empty($_POST["contactEmail"]))      ContactError('Email');
        else if(empty($_POST["contactMessage"]))    ContactError('Message');
        else
        {
            $name = $_POST["contactName"];
            $email = $_POST["contactEmail"];
            $comments = $_POST["contactMessage"];
			$tel = $_POST["contactTel"];
			
            $body = "Name: $name Email: $email Comments: $comments";
			if(!empty($_POST["contactTel"]))
				$body .=" Tel: $tel";
            $emailTo = get_option('admin_email');
            $subject = 'Contact Form Submission from '.$name;
            $headers = 'From: My Site <'.$emailTo.'>' . "rn" . 'Reply-To: ' . $email;
            mail($emailTo, $subject, $body, $headers);		
            $contact = true;
        }
    }
	
?>
<?php get_header(); ?>
<?php if(get_field('map_grayscale')):
	echo '<style type="text/css">
		#map-container{ 
		  -webkit-filter: grayscale(100%);
		  -moz-filter: grayscale(100%);
		  -ms-filter: grayscale(100%);
		  -o-filter: grayscale(100%);
		  filter: grayscale(100%);
		  filter: url(grayscale.svg); /* Firefox 4+ */
		  filter: gray; /* IE 6-9 */
		}
	</style>'; endif; ?>
<?php  
$latLng = get_field('map');
$zoomLevel = get_field('map_zoom');
 ?>	
<script>
        jQuery(document).ready(function ($) {
            var myCenter = new google.maps.LatLng(<?php echo $latLng['coordinates']; ?>);
            function initialize()
            {
                var mapProp = {
                    center:myCenter,
                    zoom: <?php echo $zoomLevel; ?>,
                    mapTypeId:google.maps.MapTypeId.ROADMAP
                };
                var map=new google.maps.Map(document.getElementById("map-container"),mapProp);
                var marker=new google.maps.Marker({
                    position:myCenter
                });
                marker.setMap(map);
            }            google.maps.event.addDomListener(window, 'load', initialize);
        });
    </script>
    <div class="content-wrapper">
    	<div class="container">
    		<div class="row-fluid">
    			<div class="span6">
    				<h3><?php get_field('contact_title') ? the_field('contact_title') : the_title(); ?></h3>
				 	<?php if(!$contact):?>
    				<form method="post" action="">
					 <input type="hidden" name="hybrid_contactForm" value="true">
	    				<div id="contact-container">
	    					<div class="row-fluid">
	    						<div class="field span4">
	    							<p class="post-categoty color-black capitalize"><?php echo _e('name:','hybrid_lang');?></p>
	    							<input type="text" class="contact-txtbox" name="contactName">
	    						</div>
	    						<div class="field span4">
	    							<p class="post-categoty color-black capitalize"><?php echo _e('email:','hybrid_lang');?></p>
	    							<input type="text" class="contact-txtbox" name="contactEmail">
	    						</div>
	    						<div class="field span4">
	    							<p class="post-categoty color-black capitalize"><?php echo _e('phone:','hybrid_lang');?></p>
	    							<input type="text" class="contact-txtbox" name="contactTel">
	    						</div>
	    					</div>
	    					<div class="row-fluid">
	    						<div class="field span12">
	    							<textarea class="contact-txtarea" rows="5" placeholder="<?php echo _e('your message goes here...','hybrid_lang');?>" name="contactMessage"></textarea>	    						
	    						</div>
	    					</div>
	    					<div class="pull-right">
		    					<input type="reset" class="btn capitalize" value="reset">
		    					<input type="submit" class="btn capitalize" value="send messsage">
		    				</div>
	    				</div>
    				</form>
					  <?php else: ?>
							<div class="alert alert-info"><button type="button" class="close" data-dismiss="alert">&times;</button>		
								<h4><?php _e('Info','hybrid_lang');?></h4>
								<p class="post-title"><?php _e('Your message has been send','hybrid_lang');?></p>							
							</div>
					<?php endif; ?>
    			</div>		
				<?php if(!get_field('disable_map')):?>
					<div class="span6">
						<h3><?php the_field('map_title') ;?></h3>
						<div id="map-container">
						</div>
					</div>		
				<?php endif;?>
    		</div>
            <div class="row-fluid">
    			<div id="css-table" class="lg-contact-i">
                    <div class="col">
                        <div class="contact-info-container">
                            <div class="elem"><p class="post-title"><?php the_field("address_title");?></p></div>
                            <div class="elem"><?php the_field("address_description");?></div>
                        </div>
                    </div>
                    <div class="col">
                        <div class="contact-info-container">
                            <div class="elem"><p class="post-title"><?php the_field("e-mail_adress");?></p></div>
                            <div class="elem"><?php the_field("e-mails");?></div>
                        </div>
                    </div>
                    <div class="col">
                        <div class="contact-info-container">
                            <div class="elem"><p class="post-title"><?php the_field("telephones_title");?></p></div>
                            <div class="elem"><?php the_field("telephones_numbers");?></div>
                        </div>
                    </div>
                    <div class="col">
                        <div class="contact-info-container">
                            <div class="elem"><p class="post-title"><?php the_field("schedule");?></p></div>
                            <div class="elem"><?php the_field("schedule_description");?></div>
                        </div>
                    </div>
                </div>
                <div class="tablet-contact-info">
                    <div id="css-table">
                        <div class="col">
                            <div class="contact-info-container">
                                <div class="elem"><p class="post-title"><?php the_field("address_title");?></p></div>
                                <div class="elem"><?php the_field("address_description");?></div>
                            </div>
                        </div>
                        <div class="col">
                            <div class="contact-info-container">
                                <div class="elem"><p class="post-title"><?php the_field("e-mail_adress");?></p></div>
                                <div class="elem"><?php the_field("e-mails");?></div>
                            </div>
                        </div>
                    </div>
                    <div id="css-table">
                        <div class="col">
                            <div class="contact-info-container">
                                <div class="elem"><p class="post-title"><?php the_field("telephones_title");?></p></div>
                                <div class="elem"><?php the_field("telephones_numbers");?></div>
                            </div>
                        </div>
                        <div class="col">
                            <div class="contact-info-container">
                                <div class="elem"><p class="post-title"><?php the_field("schedule");?></p></div>
                                <div class="elem"><?php the_field("schedule_description");?></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>    		
    	</div><!--container-->
    </div><!--.content-wrapper-->
<?php get_footer(); ?>