﻿var map = null;



  $(document).ready(function(){
    $("#sevenpassform").validate();
    $("#tellfriendform").validate();
    $("#telllouieform").validate();
    
         if(document.URL.indexOf('ShowForm') > 1)
         {
            expandsevenpass();
         }
    
    
    $("#passsubmit").bind("click", function(){
          $("#sevenpassform").validate().form();
         if($("#sevenpassform").valid())
         {
             $.post(BaseURL + "/membership/getpass", { firstname: $('#firstname').attr('value'),
                                            lastname: $('#lastname').attr('value'),
                                            email: $('#email').attr('value'),
                                            phone: $('#phone').attr('value'),
                                            street1: $('#street1').attr('value'),
                                            street2: $('#street2').attr('value'),
                                            city: $('#city').attr('value'),
                                            state: $('#state').attr('value'),
                                            zip: $('#zip').attr('value'),
                                            club: club }, function(xml) {
               // format and output result
               if(xml.toString().indexOf('true') > -1)
               {
                     $("#purpleblock").animate({ height: '125px'}, 'slow');
                     $("#passform").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 7 day pass should arrive shortly!</p><iframe src="content/conversion/pass.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');
                    $("#passform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
                     if ($.browser.msie) 
                         this.style.removeAttribute('filter'); 
                      });  
                      
                      setTimeout('showpassform()', 4000);
                      
                      
               }
               
             });
         }
         
 

    });
    
        $("#tellsubmit").bind("click", function(){
          $("#tellfriendform").validate().form();
         if($("#tellfriendform").valid())
         {
             $.post(BaseURL + "/membership/tellfriend", { firstname: $('#firstnametell').attr('value'),
                                                email1: $('#email1').attr('value'),
                                                email2: $('#email2').attr('value'),
                                                email3: $('#email3').attr('value'),
                                                email4: $('#email4').attr('value'),
                                                comments: $('#comments').attr('value')
                                              }, function(xml) {
               // format and output result
               if(xml.toString().indexOf('true') > -1)
               {
                     $("#purpleblock").animate({ height: '125px'}, 'slow');
                     $("#tellfriend").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                     $('#results').html('<p>Thank you for telling your friends about Anytime Fitness!<br /></p>');
                     $('#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');
                    $("#tellfriend").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
                     if ($.browser.msie) 
                         this.style.removeAttribute('filter'); 
                      });  
                      
                      setTimeout('showtellform()', 4000);
                      
                      
               }
               
             });
         }
    });

$("#tellsubmitlouie").bind("click", function(){
          $("#telllouieform").validate().form();
         if($("#telllouieform").valid())
         {
             $.post(BaseURL + "/membership/telllouie", { firstname: $('#firstnametelllouie').attr('value'),
                                                email: $('#emaillouie').attr('value'),
                                                message: $('#commentslouie').attr('value')
                                              }, function(xml) {
               // format and output result
               if(xml.toString().indexOf('true') > -1)
               {
                     $("#purpleblock").animate({ height: '125px'}, 'slow');
                     $("#telllouie").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                     $('#results').html('<p>Thank you for telling Louie your story!<br /></p>');
                     $('#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');
                    $("#telllouie").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#resultserror').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
                     if ($.browser.msie) 
                         this.style.removeAttribute('filter'); 
                      });  
                      
                      setTimeout('showtellform()', 4000);
                      
                      
               }
               
             });
         }
    });
    
    $('#zipcodefield').keyup(function(e) {	
        if(e.keyCode == 13) 
        {	
            getlocations();            	
        }        
    }); 
  
  });


function expandsevenpass() {

    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '340px'}, 'slow');
     $("#telllink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#louielink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#seplink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#step1").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locationstitle").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locations").hide();
     $("#passform").hide();
     $("#tellfriend").hide();

     $('#sevenpass').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  
     $('#step1').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  

}

function expandtellfriend() {
    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '340px'}, 'slow');     
     $("#passlink").hide('slow');
     $("#louielink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#seplink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#step1").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locationstitle").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locations").hide();
     $("#passform").hide();

     $('#tellfriend').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  
}


function expandtelllouie() {
    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '340px'}, 'slow');     
     $("#passlink").hide('slow');
     $("#telllink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#louielink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#seplink").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#step1").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locationstitle").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locations").hide();
     $("#passform").hide();

     $('#telllouie').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');
     $("#sevenpass").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#locations").hide();
     $("#step1").hide();
     $("#results").hide();
     $("#resultserror").hide();
     $("#passform").hide();
     $("#locationstitle").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#passform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#tellfriend").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#telllouie").animate({ height: 'hide', opacity: 'hide' }, 'slow');

     $("#passlink").show('slow'); //animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#seplink").show('slow'); //.animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#telllink").show('slow'); //.animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#louielink").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();
}

function getlocations()
{
     map = new VEMap('hiddenmap');
     map.LoadMap(StartLat);
     try  
     {       
          map.Find(null, document.getElementById('zipcodefield').value + BaseCountry, null, null, 0, 1, false, false, true, true, LoadResults);
     }
     catch(e)         
     { alert(e.message); }

}

function LoadResults(layer, resultsArray, places, hasMore, veErrorMessage)
{
     $("#locations").children("div").remove();
   $("#locations").load(BaseURL + "/locate/nearby/" + places[0].LatLong.Latitude.toString().replace(".", "p") + "/" + places[0].LatLong.Longitude.toString().replace(".", "p") + "/" + "selectclub", addClickHandlers );

     $("#sevenpass").animate({ height: 'hide', opacity: 'hide' }, 'slow');
 
}

function addClickHandlers()
{
   $("#locations").children("div").hover(function() {
         $(this).removeClass("hoveroptionoff");         
         $(this).addClass("hoveroption");
       },function(){
         $(this).removeClass("hoveroption");        
         $(this).addClass("hoveroptionoff"); 
       });

    $("#locations").children("div").bind("click", function(){
	var s = $(this).attr("id");
	selectclub(s);
});


$('#locationstitle').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
     if ($.browser.msie) 
         this.style.removeAttribute('filter'); 
      });  
      $("#locations").show();
}
function testing()
{

}

var club;

function selectclub(clubid)
{
     club = clubid.replace("club", "");
     $("#clubnumber").value = club;

     $("#locations").hide();
     $("#locationstitle").animate({ height: 'hide', opacity: 'hide' }, 'slow');
     $("#step1").animate({ height: 'hide', opacity: 'hide' }, 'slow');

     $('#passform').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
          if ($.browser.msie) 
              this.style.removeAttribute('filter'); 
      });  

	
}

function showpassform()
{   
    $("#resultserror").animate({ height: 'hide', opacity: 'hide' }, 'slow');
    $("#purpleblock").animate({ height: '340px'}, 'slow');
    $('#passform').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
          if ($.browser.msie) 
              this.style.removeAttribute('filter'); 
      });  
}

function showtellform()
{   
    $("#resultserror").animate({ height: 'hide', opacity: 'hide' }, 'slow');
    $("#purpleblock").animate({ height: '340px'}, 'slow');
    $('#tellfriend').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
          if ($.browser.msie) 
              this.style.removeAttribute('filter'); 
      });  
}

function showtelllouieform()
{   
    $("#resultserror").animate({ height: 'hide', opacity: 'hide' }, 'slow');
    $("#purpleblock").animate({ height: '340px'}, 'slow');
    $('#telllouie').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function() { 
          if ($.browser.msie) 
              this.style.removeAttribute('filter'); 
      });  
}
