﻿var map = null;



  $(document).ready(function(){
    $("#sevenpassform").validate();
    $("#tellfriendform").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);
                      
                      
               }
               
             });
         }
    });
    
    $('#zipcodefield').keyup(function(e) {	
        if(e.keyCode == 13) 
        {	
            getlocations();            	
        }        
    }); 
  
  });


function expandsevenpass() {

    $('html, body').animate({ scrollTop: 0 }, 400);
     $("#purpleblock").animate({ height: '340px'}, 'slow');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#telllink").animate({ height: 'hide', opacity: 'hide' }, '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');
     $("#cancel").animate({ height: 'show', opacity: 'show' }, 'slow');
     $("#passlink").hide('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').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');

     $("#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');

}

function resetfromvideo()
{
  	$("#videoblock").html('');
  	$("#videoblock").hide();
  	$('#line').html('<img src="Content/Images/spacer.gif" alt="" />');
  	$("#line").animate({ height: '8px'}, 'fast');
  	cancelall();
}

function getlocations() {
    //alert(BaseCountry);
    map = new VEMap('hiddenmap');



    if (BaseCulture == "f4a61736-70e9-455d-a210-dc01c42ca723")//USA
        StartLat = new VELatLong(37.020098, -93.779297);
    else if (BaseCulture == "dbfa3d0b-67c2-43f8-9955-cd6526c947ad")//Australia
        StartLat = new VELatLong(-24.441317, 135.253542);
    else if (BaseCulture == "04fc34bd-779f-4be0-b7bf-acbb7d178392")//New Zealand
        StartLat = new VELatLong(-40.298346, 172.440435);  
     
     
     
     
     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'); 
      });  
}
