<div id="my_agency">

    <div class="container start-freemium" id="inner_my_agency">

        <h1><?= $this->input('title') ?></h1>

        <div class="intro">
            <p><?= $this->input('text')?></p>
        </div>

        <form id="freemium_subscribe" action="" method="post" enctype="application/x-www-form-urlencoded">

            <div id="name" class="step">

                <div class="heading">
                    <span><?= $this->input('inscription')?></span>
                </div>

                <div class="content">
                    <div>
                        <div>
                            <span id="contact_name-label"><label for=""><?= $this->input('contact-name')?></label></span>
                            <span><input type="text" value="" id="contact_name" name="contact_name"></span>
                        </div>
                        <div>
                            <span id="contact_email-label"><label for=""><?= $this->input('contact-email')?></label></span>
                            <span><input type="text" value="" id="contact_email" name="contact_email"></span>
                        </div>

                        <div>
                            <span id="agency_name-label"><label for=""><?= $this->input('agency_name')?></label></span>
                            <span><input type="text" value="" id="agency_name" name="agency_name"></span>
                        </div>

                        <div>
                            <span id="software_name-label"><label for=""><?= $this->input('software_name')?></label></span>
                            <span><input type="text" value="" id="software_name" name="software_name"></span>
                        </div>



                    </div>
                </div>
            </div>




                <?php if ($this->editmode) {

                    echo 'acceptation des cgu <br>';
                    echo $this->wysiwyg('cgu-accept');
                    echo 'bouton submit <br>';
                    echo $this->input('submit');

                } else {?>
                    <div style="text-align:center;color:#495762" class="cb">
                        <input type="checkbox" name="agreed" id="agreed" style="height:auto;width: auto;" class="required" value=""/>
                        <span><?= $this->wysiwyg('cgu-accept')->text ?></span>
                    </div>
                    <input style="display: block;margin: 30px auto 0;" type="submit" value="<?= $this->input('submit') ?>" />';
                <?php } ?>



    </form>

    <div id="press">
        <div id="inner_press" class="container">
            <?= $this->inc('/snippets/press2') ?>
        </div>
    </div>

    <div id="clients">
        <div id="inner_clients" class="container">
            <?= $this->inc('/snippets/clients2') ?>
        </div>
    </div>

</div>

</div>


<script>
    $( "form#freemium_subscribe" ).submit(function( event ) {

        var hasError = false;
        if(!isValid('#contact_name')) hasError = true;
        if(!isValid('#contact_email')) hasError = true;
        if(!isValid('#agency_name')) hasError = true;
        if(!isValid('#software_name')) hasError = true;
        if(!isValid('#agreed')) hasError = true;

        if (hasError) event.preventDefault();
    });

    function isValid(id){
    	console.log(id + ' : ' + $(id).val());
    	var is_ok;

    	if ($(id).attr('type') == "checkbox"){
	 		if($('#agreed').is(':checked')){
	            $(id).removeClass('has-error');
	            return true;
        	}else{
	            $(id).addClass('has-error');
	            $(id).parents('.content').addClass('has-error');
	            return false;
        	}
    	}

    	

        if($(id).val() == ''){
            $(id).addClass('has-error');
            $(id).parents('.content').addClass('has-error');
            return false;
        }else{
            $(id).removeClass('has-error');
            return true;
        }
    }
</script>