﻿/// <reference path="jquery-1.3.2-vsdoc2.js"/>

function SetPhoneNumber() {
//    var location = window.location + "";
//    location = location.toLowerCase();
//    var index = location.indexOf("drnickweightloss.com");
//    if (index > -1) {
//        var newNumber = "972-535-8269";
//        $("#phoneNumber").html(newNumber);
//        $("#headerHumber").html(newNumber);
//    }
}

function cal_bmi(lbs, ins) {
    h2 = ins * ins;
    bmi = lbs / h2 * 703
    f_bmi = Math.floor(bmi);
    diff = bmi - f_bmi;
    diff = diff * 10;
    diff = Math.round(diff);
    if (diff == 10) {
        // Need to bump up the whole thing instead
        f_bmi += 1;
        diff = 0;
    }
    bmi = f_bmi + "." + diff;
    return bmi;
}

function CheckInt(w) {
    if (isNaN(parseInt(w))) {
        return false;
    } else if (w < 0) {
        return false;
    } else {
        return true;
    }
}

function ShowBMI() {
    SetPositionToCenter("BMICalcHolder", 150, 250);
    $("#BMICalcHolder").fadeIn("normal", function() {
        $("#outerHolder").fadeTo("slow", 0.25);
    });
}

function CloseBMI() {
    $("#BMICalcHolder").fadeOut("normal", function() {
        $("#outerHolder").fadeTo("slow", 1);
    });
}

function ValidateBMIInput() {
    var returnValue = true;
    if(!CheckInt( $("#bmiHeightFeet").val() ))
        returnValue = false;
    if (!CheckInt($("#bmiHeightInches").val()))
        returnValue = false;
    if (!CheckInt($("#bmiWeight").val()))
        returnValue = false;        
    return returnValue;
    
}

function CalculateBMI() {
    if (ValidateBMIInput()) {
        var heightFeet = parseInt($("#bmiHeightFeet").val());
        var heightInches = parseInt($("#bmiHeightInches").val());
        var weight = parseInt($("#bmiWeight").val());
        var inches = (heightFeet * 12) + heightInches;
        var BMI = cal_bmi(weight, inches);
        $("#bmiTitle").html("Your BMI:");
        $("#bmiResult").html(BMI);
    }
    else {
        alert("Please enter your height and weight.");
    }
}

function SetPositionToCenter(objectId, objectWidth, objectHeight) {
    var topPosition = ($(window).scrollTop() + ($(window).height() / 2) | 0) - objectHeight;
    var leftPosition = ($(window).scrollLeft() + ($(window).width() / 2) | 0) - objectWidth;
    document.getElementById(objectId).style.top = topPosition + "px";
    document.getElementById(objectId).style.left = leftPosition + "px";
}

function ShowMovie(movieName, movieTitle) {
    SetPositionToCenter("movieOuterHolder", 150, 250);
    $("#movieTitleHolder").html(movieTitle);

    $("#outerHolder").fadeTo("slow", 0.25, function() {
        $("#movieOuterHolder").fadeIn("slow", function() {
            $("#movieHolder").show();
            flowplayer("movieHolder", "../images/swf/flowplayer-3.1.0.swf", movieName);
        });    
    });
}

function CloseMovie() {
    $("#movieHolder").hide();
    $("#movieOuterHolder").fadeOut("slow", function() {
    $("#outerHolder").fadeTo("slow", 1, function() { }); 
    });
}

function ClearField(object, text) {
    if (document.getElementById(object.id).value == text) {
        document.getElementById(object.id).style.color = "black";
        document.getElementById(object.id).value = "";
    }
}

function RestoreField(object, text) {
    if (document.getElementById(object.id).value == "") {
        document.getElementById(object.id).style.color = "gray";
        document.getElementById(object.id).value = text;
    }
}

function SetTwoColumn() {
    $(document).ready(function() {
        $("#rightColumn").css("width", "0px");
        $("#middleColumn").css("width", "660px");
    });
}

function ToggleSeminarList(seminarCheckBox) {
    var checked = $("#" + seminarCheckBox).attr("checked");
    if (checked) {
        $("#seminarDropdownHolder").slideDown("normal");
    }
    else {
        $("#seminarDropdownHolder").slideUp("normal");
    }
}

function SetSeminarList(checked) {

    $(document).ready(function() {
        if(checked == "True") {
            $("#seminarDropdownHolder").show();
        }
        else {
            $("#seminarDropdownHolder").hide();
        }
    });
}

//menuitems---------------------------------------------------------------
var currentlyVisibleMenu = "";
var timeOut = null;
function ShowMenu(menuId, object) {
    CancelHide();
    if (currentlyVisibleMenu != "")
        $("#" + currentlyVisibleMenu).hide();
    $("#" + menuId).show();
    currentlyVisibleMenu = menuId;
}

function HideSubmenu() {
    if (currentlyVisibleMenu != "") {
        $("#" + currentlyVisibleMenu).fadeOut("slow", function() {

        });
        currentlyVisibleMenu = "";
    }
}

function StartHide() {
    if (timeOut == null)
        timeOut = setTimeout("HideSubmenu();", 1500);
}

function CancelHide() {
    if (timeOut != null) {
        clearTimeout(timeOut);
        timeOut = null;
    }
}

//----------------------------------------------------------------

function ToggleInsurance(paymentID, insuranceID) {
    var value = document.getElementById(paymentID).value;
    if (value.indexOf("Insurance") > -1) {
        $("#insuranceHolder").slideDown("fast");
        ValidatorEnable(document.getElementById(insuranceID), true);
    }
    else {
        $("#insuranceHolder").slideUp("fast");
        ValidatorEnable(document.getElementById(insuranceID), false);
    }
}

//marketingOther
function ToggleMarketingOther(value) {
    if (value.indexOf("Other") > -1) {
        $("#marketingOther").slideDown("fast");
    }
    else {
        $("#marketingOther").slideUp("fast");
    }
}

//thanks dr. nick video callout
function ShowTV3() {
    SetPositionToCenter("TV3YoutubeHolder", 150, 200);
    $("#outerHolder").fadeTo("slow", 0.25, function() {
        $("#TV3YoutubeHolder").fadeIn("fast");
    });
}

function HideTV3() {
    $("#TV3YoutubeHolder").fadeOut("fast", function() {
        $("#outerHolder").fadeTo("slow", 1);
    });
}

$(document).ready(function() {
    $.localScroll();
    SetPhoneNumber();
});