/*
 Most Important Javascript Functions
 Written By Charbel Al Batal: http://www.charbelbatal.com
 Copyright W8: http://www.wondereight.com
*/
function addValidators(form)
{
	var $inputs = $('#'+form+' :input[type="text"]');
	var $textarea = $('#'+form+' textarea');
	$inputs.each(function() {
       $(this).blur(function(){
			if(!$(this).validateNumber()){$(this).addClass("fieldError");$(this).val($(this).attr("id"));}
			else{ $(this).removeClass("fieldError");}
		}).focus(function(){
			if($(this).val()==$(this).attr("id")){
				$(this).val("");
			}
		});
    });
}

calcNeeds = function (v_weight,v_height,v_age,v_activity,v_genre){
	var weight = (isNaN(v_weight)) ? 0 : v_weight;
	//if (weight == 0) alert("Results will be inaccurate.  Weight is not a valid number.");
	var height = (isNaN(v_height)) ? 0 : v_height;
	//if (height == 0) alert("Results will be inaccurate.  Height is not a valid number.");
	var age = (isNaN(v_age)) ? 0 : v_age;
	//if (age == 0) alert("Results will be inaccurate.  Age is not a valid number.");
	var activity = (isNaN(v_activity)) ? 0 : v_activity;
	//var wmult = (document.wcbubba.units.value == "pounds") ? 2.204 : 1;
	var wmult = 1;var hmult=1;
	//var hmult = (document.wcbubba.hunits.value == "inches") ? 2.54 : 1;
	var genvar = (v_genre == "male") ? 5 : -161;
	var BMR = Math.round((((weight / wmult) * 9.99) + ((height * hmult) * 6.25) - (age * 4.92) + genvar) * 1);
	var calburn = Math.round((((weight / wmult) * 9.99) + ((height * hmult) * 6.25) - (age * 4.92) + genvar) * activity);
	return "Your Basal Metabolic Rate is: <strong>" + BMR + " calories</strong>.<br>Your Average Daily Calorie Need Is: <strong>" + calburn + " calories</strong>.";
}

function calculateCalories(form){
	var valid = 0;
	var $inputs = $('#'+form+' :input[type="text"]');
	$inputs.each(function() {
		if(!$(this).validateNumber()){$(this).addClass("fieldError");valid++;$(this).val($(this).attr("id"));}
		else{ $(this).removeClass("fieldError");}
    });
	if(valid==0){		
		var weight = $("#Weight").val();var height = $("#Height").val();var age = $("#Age").val();
		var activity = $("#activity").val();var genre = $('input:radio[name=rdGender]:checked').val();
		abc =  calcNeeds(weight,height,age,activity,genre);
		return abc;
	}
	else{
		return false;
	}	
}

function animateFooter(){
	if($("#click-here").is(".expanded")){
		$("#widgets-wrapper .widgets").slideToggle(500,'easeOutQuart');
		$("#home-footer #copyright").stop().animate({marginTop:"85px"},500,'easeOutQuart');		
		$("#click-here").removeClass("expanded");
	}else{
		$("#widgets-wrapper .widgets").slideToggle(500,'easeOutQuart');
		$("#home-footer #copyright").stop().animate({marginTop:"30px"},500,'easeOutQuart');		
		$("#click-here").addClass("expanded");
	}
}

function modifyFooterHeight(){	
	var windowHeight;
	var mainDocumentBodyHeight = $("#wrapper").height() +23 ;
	$("#home-footer").css("height","255px")
	if (document.documentElement){
		if(document.documentElement.offsetHeight>document.documentElement.clientHeight)  windowHeight = document.documentElement.offsetHeight
		else windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body){
		if(document.body.offsetHeight>document.body.clientHeight)  windowHeight = document.body.offsetHeight
		else windowHeight  = document.body.clientHeight;
	}	
	if(windowHeight>mainDocumentBodyHeight){
		height = windowHeight - mainDocumentBodyHeight;
		$("#home-footer").css("height",height +"px");
	}
}
modifyFooterHeight();

