﻿var map = null;

$(document).ready(function () {
   // debugger;
    $("#wellnessform").validate();
    $("#referform").validate();

    $("#wellsub").bind("click", function () {
        $("#wellnessform").validate().form();
        if ($("#wellnessform").valid()) {
            $.post(BaseURL + "wellness/contact", {
                firstname: $('#firstname').attr('value'),
                company: $('#company').attr('value'),
                title: $('#title').attr('value'),
                email: $('#email').attr('value'),
                phone: $('#phone').attr('value'),
                street1: $('#street1').attr('value'),
                street2: $('#street2').attr('value'),
                comments: $('#comments').attr('value'),
                employees: $('#employees').attr('value'),
                worksites: $('#worksites').attr('value'),
                city: $('#city').attr('value'),
                state: $('#state').attr('value'),
                zip: $('#zip').attr('value')
            }, function (xml) {

                // format and output result
                if (xml.toString().indexOf('true') > -1) {
                    $("#purpleblock").animate({ height: '125px' }, 'slow');
                    $("#wellform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#results').html('<p>Thank you for your interest in Anytime Fitness!<br /><b>Please check your email,</b> your confirmation should arrive shortly!</p><iframe src="content/conversion/wellness.aspx" width="50" height="10" frameborder="0"></iframe>');
                    $('#results').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });

                    setTimeout('cancelall()', 5000);
                }
                else {
                    $("#purpleblock").animate({ height: '100px' }, 'slow');
                    $("#wellform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });

                    setTimeout('expandwellform()', 4000);


                }

            });
        }
    });

    $("#refsub").bind("click", function () {
        $("#referform").validate().form();
        if ($("#referform").valid()) {
            $.post("wellness/refer", { firstname: $('#firstname2').attr('value'),
                lastname: $('#lastname2').attr('value'),
                email: $('#email2').attr('value'),
                phone: $('#phone2').attr('value'),
                street1: $('#street12').attr('value'),
                street2: $('#street22').attr('value'),
                employees: $('#employees2').attr('value'),
                city: $('#city2').attr('value'),
                state: $('#state2').attr('value'),
                zip: $('#zip2').attr('value')
            }, function (xml) {

                // format and output result
                if (xml.toString().indexOf('true') > -1) {
                    $("#purpleblock").animate({ height: '125px' }, 'slow');
                    $("#refform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#results').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });

                    setTimeout('cancelall()', 5000);
                }
                else {
                    $("#purpleblock").animate({ height: '100px' }, 'slow');
                    $("#refform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });


                    setTimeout('expandreferform()', 4000);


                }

            });
        }
    });
});


function expandwellform() {
    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '340px'}, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#referlink").hide('slow'); //animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#seplink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     
    $('#resultserror').animate({ height: 'hide', opacity: 'hide' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

     $('#wellform').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

}

function expandreferform() {
    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '340px'}, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#welllink").hide('slow'); //animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#seplink").animate({ height: 'hide', opacity: 'hide' }, 'slow');

    $('#resultserror').animate({ height: 'hide', opacity: 'hide' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

     $('#refform').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

}
function cancelall()
 {
     $("#area").show();
     $("#cancel").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#purpleblock").animate({ height: '35px'}, 'slow');
     $("#wellform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#refform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#results").hide();
     $("#resultserror").hide();

     $("#welllink").show('slow'); //animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#seplink").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#referlink").show('slow'); //.animate({ height: 'show', opacity: 'show' }, 'slow');

}

function resetfromvideo()
{
  	$("#videoblock").html('');
  	$("#videoblock").hide();
  	$('#line').html('<img src="Content/Images/spacer.gif" alt="" />');
  	$("#line").animate({ height: '8px'}, 'fast');
  	cancelall();
}
