

function updateTwitter(data)
{
	var feed = unescape(data);
	feed = feed.replace(/\+/g," ");
	$('#feedData').html(feed);	
}

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("/jsoncalc.php", 
		  {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");
		  
		 try
         {
	   	$.get('/registerimp.php', function(data) {});
   } catch(err) {}
}

function resetCalc()
{
	$('#gender').val('');
	$('#age').val('');
	$('#height').val('');
	$('#weight').val('');	
	$('#currentWeight').html("");
	$('#1pound').html("");
	$('#2pound').html("");	
}
    
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()
{
	$('#newClientResults').html('<img src="images/emailAnim.gif" style="float:left;width:32px;height:32px;margin-right:10px;margin-top:-10px;"> Please Wait......');
	$('#newClientResults').show();	
	setTimeout('sendNewClientEmailSuccess()', 2000);
}
function sendNewClientEmailSuccess()
{
	$('#newClientResults').html('Thank you.');
	setTimeout('closeOverlay()', 2000);
}

function sendClientEmail()
{
	$('#clientResults').html('<img src="images/emailAnim.gif" style="float:left;width:32px;height:32px;margin-right:10px;margin-top:-10px;"> Please Wait......');
	$('#clientResults').show();	
	setTimeout('sendClientEmailSuccess()', 2000);
}
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();
   	  }
   }
   
   try
   {
	   	$.get('/registerimp.php', function(data) {});
   } catch(err) {}
}  
    
    
    
    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: 'searchTrainers.php',
       cache: false,
       dataType : 'html',
       data: ({zipcode:zipcode}),
       success: function(msg){
          $('#trainerResults').html(msg);
          $('#trainerResults').find('#emailListing').hide();
          $('#trainerResults').append('<br><br>Are you are personal trainer? <a href="#">Add Your Listing Here</a>');
       }
     });            	
  }
    
  
 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: '/searchmenus.php',
	       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>" + msg);
	       }
	     });  		
	}	
	
	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: '/showmenu.php',
		       cache: false,
		       dataType : 'html',
		       data: ({menuId:menuId}),
		       success: function(msg){
		          $('#ift_loadMenuLayer').html(msg);
		          
		       }
		     });  
	     						
		}
	}
	
	
	function printMenu()
    	{
        	var menuId = $('#ift_menuChoice').val();
		var url = '/printMenu.php?menuId='+menuId;
		window.open(url,'menu','top=0,left=0,menubar=yes,toolbar=no,statusbar=no,scrollbars=yes,resizable');
    	}
    
    

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

