﻿var map = null;
var vMediaUID = "";
var vProvider = "";


$(document).ready(function () {

    $("#sevenpassform").validate();
    $("#tellfriendform").validate();

    if (document.URL.indexOf('ShowForm') > 1) {
        expandsevenpass();
    }


    var PassResult = "";
    var PassResultsError = "";
    var TellResult = "";
    var TellResultsError = "";


    if (BaseCulture == "fd44ff6c-34e8-3849-8ce7-51330685f1cf")//Netherlands
    {
        PassResult = '<p>Dank u voor uw interesse in Anytime Fitness!<br /><b>Gelieve uw e-mail, </ b> uw 7 dagen pas zal binnenkort aankomt!</p><iframe src="content/conversion/pass.aspx" width="50" height="10" frameborder="0"></iframe>';
        TellResult = '<p>Dank u voor het vertellen van je vrienden over Anytime Fitness!</p>';
    }
    else if (BaseCulture == "fc954581-1399-40f0-8cae-33a65ebfcb1f")//Mexico
    {
        PassResult = '<p>Gracias por su interés en Anytime Fitness! <b> <br /> Por favor, revise su correo electrónico, </ b> su pase por siete días debe llegar en breve!</p><iframe src="content/conversion/pass.aspx" width="50" height="10" frameborder="0"></iframe>';
        TellResult = '<p>Muchas gracias por avisarle a tus amigos acerca de Anytime Fitness!<br /></p>';
    }
    else {
        PassResult = '<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>';
        TellResult = '<p>Thank you for telling your friends about Anytime Fitness!<br /></p>';
    }



    $("#passsubmit").bind("click", function () {
        debugger;
        $("#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,
                MediaUID: vMediaUID,
                MediaProvider: vProvider

            }, 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(PassResult + '<iframe src="content/conversion/pass.aspx" width="1" height="1" frameborder="0"></iframe>');
                    $('#results').animate({ height: 'show', opacity: 'show' }, 'slow', 'linear', function () {
                        if ($.browser.msie)
                            this.style.removeAttribute('filter');
                    });

                    setTimeout('cancelall()', 5000);
                }
                else if (xml.toString().indexOf('FromGigya') > -1) {
                    var conf = {
                        APIKey: "2_V5Zpvp3qqUMz4BSwWVvT39XYC8129rcV5ESUlKswSgKvi3hdyvHVgmTjJoEGd714",
                        enabledProviders: "facebook,twitter,yahoo,messenger,google,linkedin,myspace,aol,blogger,wordpress,livejournal,openid"
                    };
                    // Constructing a UserAction Object   
                    var act = new gigya.services.socialize.UserAction();

                    act.setTitle("FREE 14-Day Pass to Anytime Fitness");  // Setting the Title   
                    act.setUserMessage("Cool, I just got a free 14-day pass to Anytime Fitness! Wanna join me? Click the link to get yours.");   // Setting the User Message   
                    act.setLinkBack("http://www.anytimefitness.com/en-us/membership/#ShowForm");  // Setting the Link Back   
                    act.setDescription("Ready for fitness? Click to get your free gym pass today!");   // Setting Description   
                    act.addActionLink("Read More", "http://www.anytimefitness.com");  // Adding Action Link   
                    // Adding a Media (image)   
                    act.addMediaItem({ type: 'image', src: 'http://www.anytimefitness.com/en-us/content/images/email/Running_Man.png', href: 'http://www.anytimefitness.com/en-us/membership/#ShowForm' });

                    var params =
                    {
                        userAction: act
                    };


                    // Publishing the User Action              
                    gigya.services.socialize.publishUserAction(conf, params);
                    PassResult = '<p>"Thank you for your interest in Anytime Fitness!<br /><b>Please check your email,</b> your 14 day pass should arrive shortly!"</p>';

                    $("#purpleblock").animate({ height: '125px' }, 'slow');
                    $("#passform").animate({ height: 'hide', opacity: 'hide' }, 'slow');
                    $('#results').html(PassResult + '<iframe src="content/conversion/pass.aspx" width="1" height="1" 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(TellResult);
                    $('#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() {
    if (document.URL.toLowerCase().indexOf('joemauer') > 1) {
        $('html, body').animate({ scrollTop: 500 }, 400);
    }
    else {
        $('html, body').animate({ scrollTop: 0 }, 400);
    }



    $("#purpleblock").animate({ height: '390px' }, 'slow');
    $('#purpleblock').css("background-image", "url(../../content/Images/purple-block_B.jpg)");  
     $("#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');
     $('#purpleblock').css("background-image", "url(../../content/Images/purple-block.jpg)");
     $("#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);
    //debugger;
    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 {
         var vVal = document.getElementById('zipcodefield').value;
         map.Find(null, vVal + BaseCountry, null, null, 0, 1, false, false, true, true, LoadResults);
     }
     catch(e)         
     { alert(e.message); }

}

function LoadResults(layer, resultsArray, places, hasMore, veErrorMessage) {
//debugger;
     $("#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: '390px'}, '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'); 
      });  
}

