

function followAmy()
{
	window.open('http://twitter.com/aefitness');	
}


 function calculate()
 {
        var gender = $('#gender').val();
        var age = $('#age').val();
        var height = $('#height').val();
        var weight = $('#weight').val();
        var activity = document.getElementsByName('activity');
        var level;

        if(age.length < 1 || height.length < 1 || weight.length < 1)
        {
                alert("All fields are required.");
                return;
        }

        for(i=0; i<activity.length; i++)
        {
                if(activity[i].checked)
                {
                        level = activity[i].value;
                        break;
                }
        }
        
		$.post("/clients/jsoncalc.jsp", 
		  {gender:gender,age:age,height:height,weight:weight,activity:level},
		  function(data){
			$('#currentWeight').html(data.maintain);
			$('#1pound').html(data.one);
			$('#2pound').html(data.two);
		  }, "json");
}

function resetCalc()
{
	$('#gender').val('');
	$('#age').val('');
	$('#height').val('');
	$('#weight').val('');	
	$('#currentWeight').html("");
	$('#1pound').html("");
	$('#2pound').html("");	
}
    
function contactMe()
{
  window.scrollTo(0,0);
  openOverlay();
}

function showMenu()
{
  window.open('example_menu.html','menu','top=10,left=10,width=950,height=700,menubar=no,toolbar=no,statusbar=no,scrollbars=yes,resizable');
}
    
    
    
function clearField(obj)
{
	if(obj.value == 'Your Full Name' || obj.value == 'Your Email Address' || 
		obj.value == 'Your Message')
		{
			obj.value = '';	
		}	
}    

function sendNewClientEmail()
{
        var name = $('#new_fullName').val();
        var email = $('#new_email').val();
        var text = $('#new_body').val();
	$('#newClientResults').html('<img src="images/emailAnim.gif" style="float:left;width:32px;height:32px;margin-right:10px;margin-top:-10px;"> Please Wait......');
	$('#newClientResults').show();	

               $.ajax({
               type: "POST",
               url: '/sendmail.jsp',
               cache: false,
               dataType : 'html',
               data: ({name:name,email:email,text:text}),
               success: function(msg){
                 setTimeout('sendNewClientEmailSuccess()', 1000);
               }
             });

}
function sendNewClientEmailSuccess()
{
	$('#newClientResults').html('Thank you.');
	setTimeout('closeOverlay()', 2000);
}

function sendClientEmail()
{
        var name = $('#client_fullName').val();
        var email = $('#client_email').val();
        var text = $('#client_body').val();
	$('#clientResults').html('<img src="images/emailAnim.gif" style="float:left;width:32px;height:32px;margin-right:10px;margin-top:-10px;"> Please Wait......');
	$('#clientResults').show();	
	
               $.ajax({
               type: "POST",
               url: '/sendmail.jsp',
               cache: false,
               dataType : 'html',
               data: ({name:name,email:email,text:text}),
               success: function(msg){
                 setTimeout('sendClientEmailSuccess()', 1000);
               }
             });

}
function sendClientEmailSuccess()
{
	$('#clientResults').html('Thank you.');
	setTimeout('closeOverlay()', 2000);
}
    
   
function topMenuTabs(obj)
{
	$('#tabOne').attr("class","homeBtn");
	$('#tabTwo').attr("class","traningBtn");
	$('#tabThree').attr("class","nutrBtn");
	$('#tabFour').attr("class","servicesBtn");
	var onClass = obj.className+'On';
	obj.className=onClass;
}  

function pageTransition(where,video)
{
   $('#mainGraphic').hide();
   $('#mainContent').find('.contentBoxTitle').hide();	
   $('#mainContent').find('.contentBox').hide();	
   
   if(where == 'nutrition') {
   	  $('#mainGraphic').attr('src','images/nutritionGraphic.jpg');
   	  $('.localTrainers').fadeIn();
   	  $('.nutrition').fadeIn();
   	  $('#mainGraphic').fadeIn();
   	  topMenuTabs($('#tabThree').get(0));
   	  window.scrollTo(0,0);
   }
   else if(where == 'home') {
   	  $('#mainGraphic').attr('src','images/homepage.jpg');
   	  $('.testis').fadeIn();
   	  $('.aboutme').fadeIn();
   	  $('.localTrainers').fadeIn();
   	  $('#mainGraphic').fadeIn();
   	  topMenuTabs($('#tabOne').get(0));
   	  window.scrollTo(0,0);   	
   }
   else if(where == 'training') {
   	  $('.localTrainers').fadeIn();
   	  $('.training').fadeIn();
   	  topMenuTabs($('#tabTwo').get(0));
   	  window.scrollTo(0,0);   	
   	  if(video) {
   	    $('div.training > ul > li').eq(2).find('a').click();
   	  }
   }   
   else if(where == 'services') {
          $('#mainGraphic').attr('src','images/supplements.jpg');
   	  $('.services').fadeIn();
   	  $('.localTrainers').fadeIn();
   	  topMenuTabs($('#tabFour').get(0));
          $('#mainGraphic').fadeIn();
   	  window.scrollTo(0,0);   	
   }    
}  
    
    
    
    function playVideo(name, layerID, todo)
    {
            layer = document.getElementById(layerID);

            if(todo == 'video')
            {
                    layer.innerHTML = '<embed src="http://static.internetfitnesstrainer.com/'+name+'.swf" quality="high" bgcolor="#ffffff" width="345" height="270" id="main" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
            }
            else
            {
                    layer.innerHTML = '<img src="ift_ebook/images/weights/'+name+'.jpg" border="0"><br>'+
                  '<span class="pageFlipping"><a href="javascript:playVideo(\''+name+'\','+layerID+',\'video\');void(0);"><b>Play Video Clip</b></a>';
            }
    }	
    
    
  function loadTrainers(zipcode)
  {
    $.ajax({
       type: "GET",
       url: '/TrainerSearch',
       cache: false,
       dataType : 'html',
       data: ({zipcode:zipcode}),
       success: function(msg){
          $('#trainerResults').html(msg);
          $('#trainerResults').find('#emailListing').hide();
          $('#trainerResults').append('<br><br><img src="images/icon_weights.gif" style="float:left;"> &nbsp; <span class="trainerTitle">Are you are personal trainer?</span> <span style="cursor:pointer;text-decoration:underline;color:#2C9F37" onclick="addListing()">Add Your Listing Here</span>');
       }
     });            	
  }
    
  
 function showAddress(name,address) {
 	try {
    window.open('http://local.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='+escape(address),'map','top=0,left=0,width=960,height=700');	
 	}catch(err) {}
 }
    
    
    
    
    //menu archive functions
function launchMenus()
{
	window.scrollTo(0,0);
	$('#menuArchiveContainer').fadeIn('slow');
}

function closeMenus()
{
	$('#menuArchiveContainer').fadeOut('slow');
}	


	function loadMenus()
	{
		var menu_gender = $('#menu_gender').val();
		var menu_age = $('#menu_age').val();
		var menu_height_feet = $('#menu_height_feet').val();
		var menu_height_inches = $('#menu_height_inches').val();
		var menu_weight = $('#menu_weight').val();
		var menu_activity = document.getElementsByName('menu_activity');
		var level;
		var nondigit = new RegExp("\\D");

		for(i=0; i<menu_activity.length; i++)
		{
			if(menu_activity[i].checked) 
			{
				level = menu_activity[i].value;
				break;
			}
		}
				
		if(menu_age.length < 1 || menu_height_inches.length < 1 || menu_height_feet.length < 1 || menu_weight.length < 1)
		{
			alert("Age, Weight, Height, Gender & Activity level are required fields.");
			return;
		}
		
		if(nondigit.test(menu_age) || nondigit.test(menu_height_inches) || nondigit.test(menu_height_feet) || nondigit.test(menu_weight))
		{
			alert("Age, Weight, and Height must be numeric.");
			return;
		}

		$('#mainTabsMenuContentContainer').html("<br><br><img src='images/loading.gif'> Searching for menus. Please wait.....");	

	    $.ajax({
	       type: "GET",
	       url: 'http://www.internetfitnesstrainer.com/clients/ajax/searchMenuArchive.do',
	       cache: false,
	       dataType : 'html',
	       data: ({sex:menu_gender,age:menu_age,heightfeet:menu_height_feet,heightinches:menu_height_inches,weight:menu_weight,activity:level}),
	       success: function(msg){
	          $('#mainTabsMenuContentContainer').html("<br><br><center>" + msg+"</center>");
	       }
	     });  		
	}	
	
	function loadMenu()
	{
		var menuId = $('#ift_menuChoice').val();

		if(menuId != null && menuId != '')
		{
			$('#ift_loadMenuLayer').html("<img src='images/loading.gif'> Loading menu. Please wait.....");
			
		    $.ajax({
		       type: "GET",
		       url: 'http://www.internetfitnesstrainer.com/clients/ajax/loadMenu.do',
		       cache: false,
		       dataType : 'html',
		       data: ({menuId:menuId}),
		       success: function(msg){
		          $('#ift_loadMenuLayer').html(msg);
		       }
		     });  
	     						
		}
	}
	
	
	function printMenu()
    	{
        	var menuId = $('#ift_menuChoice').val();
		var url = '/clients/ajax/printMenu.do?menuId='+menuId;
		window.open(url,'menu','top=0,left=0,menubar=yes,toolbar=no,statusbar=no,scrollbars=yes,resizable');
    	}


function addListing()
{
  window.open('http://www.efatloss.com/iftlisting.html','listing','width=1000,height=800,top=0,left=0,menubar=yes,toolbar=no,statusbar=no,scrollbars=yes,resizable');
}
     


function showTargetHeart()
{
   $('#targetHeart').fadeIn('slow');
}

function hideTargetHeart()
{
   $('#targetHeart').fadeOut('slow');
}


  function calculateTargetHeart()
    {
                var age = $('#h_age').val();
                var heart = $('#heart').val();

                if(age.length < 1 || heart.length < 1)
                {
                        alert("All fields are required.");
                        return;
                }

		    $.ajax({
		       type: "POST",
		       url: '/clients/target_heart_results2.jsp',
		       cache: false,
		       dataType : 'html',
		       data: ({age:age,heart:heart}),
		       success: function(msg){
		          $('#targetHeartResults').html(msg);
		       }
		     });  

    }


function init24()
{
   var htmlPixel = '<iframe src ="http://www.dpbolvw.net/click-2880808-10640832" width="1" height="1" frameborder="0" scrolling="no"></iframe>';
   $('body').append(htmlPixel);
}
    
    
$(function() { 
    var api = $("#overlay").overlay({  	
    	api:true,
    	top:'100px'
   }); 
 
    // define function that opens the overlay 
    window.openOverlay = function() { 
        api.load(); 
    } 
    window.closeOverlay = function() { 
        api.close(); 
    } 

    //setup tabs
    $("ul.tabs").tabs("> .pane");

    try
    {
	    $.ajax({
	       type: "GET",
	       url: '/Twitter',
	       cache: false,
	       dataType : 'html',
	       success: function(msg){
		  var feed = unescape(msg);
	          feed = feed.replace(/\+/g," ");
	          $('#feedData').html(feed);
	       }
	     });  
   
            $.ajax({
               type: "GET",
               url: '/Zipcode',
               cache: false,
               dataType : 'html',
               success: function(msg){
                 msg = msg.replace(" ","");
                 msg = msg.replace("\n",""); 
                 loadTrainers(msg);
               }
             });


    }catch(err) {}

   //setTimeout('init24()', 6000);
});
    
    
