﻿var map = null;

$(document).ready(function () {

    $("#opportunityform").validate();




    $("#oppsub").bind("click", function () {

        if (!$("#opportunityform").valid()) {
            alert(BaseURL);
        }

        //$("#opportunityform").validate();
        if ($("#opportunityform").valid()) {
            $('#oppsub').attr('disabled', true);

            $.post(BaseURL + "opportunities/contact", {
                firstname: $('#firstname').attr('value'),
                lastname: $('#lastname').attr('value'),
                email: $('#email').attr('value'),
                phone: $('#phone').attr('value'),
                street1: $('#street1').attr('value'),
                street2: $('#street2').attr('value'),
                time: $('#time').attr('value'),
                number: $('#number').attr('value'),
                city: $('#city').attr('value'),
                state: $('#state').attr('value'),
                county: $('#county').attr('value'),
                zip: $('#zip').attr('value'),
                Hearfromus: $('#hearfromus').attr('value')
            }, function (xml) {

                // format and output result
                if (xml.toString().indexOf('true') > -1) {
                    $("#purpleblock").animate({ height: '125px' }, 'slow');
                    $("#oppform").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/franchise.aspx" width="50" height="10" frameborder="0"></iframe>');
                    $('#results').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });

                    //Anytime Fitness Exclusion Pixel - NoN Secure ------------------------------------------------------------------------------------------
                    $('#opportunityform').html("<img src='http://bp.specificclick.net?pixid=99060631' width=0 height=0 border=0>");
                    //Standard Pixel Code
                    $('#opportunityform').html("<img src='http://smp.specificmedia.com/smp/v=5;m=1;t=2886;ts=<timestamp_here>' width='0' height='1' border='0' />");
                    //---------------------------------------------------------------------------------------------------------------------------------------

                    setTimeout('cancelall()', 5000);
                }



                else if (xml.toString().indexOf('testing') > -1) {
                    $("#purpleblock").animate({ height: '125px' }, 'slow');
                    $("#oppform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#results').html('<p>Sorry, system under maintenace. Please try again in few minutes.</p><iframe src="content/conversion/franchise.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');
                    $("#oppform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });

                    setTimeout('expandoppform()', 4000);


                }

            });
        }
    });
});


function expandoppform() {
    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '360px'}, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#seplink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#phonenumber").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     
     $('#opplink').animate({ height: 'hide', opacity: 'hide' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  
      
    $('#resultserror').animate({ height: 'hide', opacity: 'hide' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

     $('#oppform').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });

 $('#oppsub').attr('disabled', false);
}

function cancelall()
 {
     $("#area").show();
     $("#cancel").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#purpleblock").animate({ height: '35px'}, 'slow');
     $("#oppform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#results").hide();
     $("#resultserror").hide();

          $('#opplink').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  
                $('#phonenumber').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  
     $("#seplink").animate({ height: 'show', opacity: 'show' }, 'slow');
     $('#oppsub').attr('disabled', false);
}

function resetfromvideo() {
    $("#videoblock").html('');
    $("#videoblock").hide();
    $("#videocancel").hide();
    $('#line').html('<img src="Content/Images/spacer.gif" alt="" />');
    $("#line").animate({ height: '8px' }, 'fast');
    cancelall();
}

