﻿/*window.scrollTo = function() { };*/

// set flash detection
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

var CCPage_Validators = new Array();
$(document).ready(function() {

    for (i = 0; i < Page_Validators.length; ++i) {
        if (Page_Validators[i].enabled == false) {
            CCPage_Validators[CCPage_Validators.length] = Page_Validators[i];
        }
    }
    //    
    //    $(document).keypress(function(e) 
    //    {    
    //            alert(e.keyCode); 
    //    
    //        if(e.keyCode == 13)     
    //        {     
    //            alert('keypress'); 
    //            //$(focussed_form).trigger('submit');     
    //        }  
    //    });
});

function toggleCCVal(blnEnable) {
    for (i = 0; i < CCPage_Validators.length; ++i) {
        CCPage_Validators[i].enabled = blnEnable;
    }
}

function showErrors(valGroup) {
    if (!Page_ClientValidate(valGroup)) {
        $('.errorpanel').show();
    }
}

function highlightError(obj, valGroup) {
    if (!Page_ClientValidate(valGroup)) {
        obj.style.border = "1px solid red";
    }
}

function cleardefault(obj, value) {
    if (obj.value == value)
        obj.value = "";
}

function checkAll(obj) {
    for (i = 0; i < document.forms[0].elements.length; i++) {
        if (document.forms[0].elements[i].type == "checkbox") {
            document.forms[0].elements[i].checked = obj.checked;
        }
    }
}

function uncheckMain(obj) {
    alert(obj.checked);
    //main.checked = false;
}

function takeQuiz(id) {
    tb_show("Quiz", "/quiz.aspx?qid=" + id + "&TB_iframe=true&height=332&width=450&modal=true", "");
}

jQuery().ready(function() {
    // simple accordion
    jQuery('#faqAccordian').accordion();

    var accordions = jQuery('#faqAccordian');

});

$(document).ready(function() {



    // Reset Font Size
    var originalFontSize = $('html').css('font-size');
    $(".resetFont").click(function() {
        $('html').css('font-size', originalFontSize);
    });
    // Increase Font Size
    $(".increaseFont").click(function() {
        var currentFontSize = $('.text-body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize);
        var newFontSize = currentFontSizeNum * 1.2;
        if (newFontSize > 12) {
            $('.text-body').css('font-size', newFontSize);
            $('.spotlight .detail').css('font-size', newFontSize);
        }
        else {
            $('.contentarea').css('font-size', newFontSize);
            $('.text-body').css('font-size', newFontSize);
            $('.spotlight .detail').css('font-size', newFontSize);
        }


        return false;
    });
    // Decrease Font Size
    $(".decreaseFont").click(function() {
        var currentFontSize = $('.text-body').css('font-size');
        var currentFontSizeNum = parseFloat(currentFontSize);
        var newFontSize = currentFontSizeNum / 1.2
        if (newFontSize > 12) {
            $('.text-body').css('font-size', newFontSize);
            $('.spotlight .detail').css('font-size', newFontSize);
        }
        else {
            $('.contentarea').css('font-size', newFontSize);
            $('.text-body').css('font-size', newFontSize);
            $('.spotlight .detail').css('font-size', newFontSize);
        }

        return false;
    });
});



/* FLV events */
var hasStarted = false;
var hasFinished = false;
var missionID = 0;
var quizID = 0;
var hasAddedTofav = false;

function flvcomplete() {
    if (quizID > 0)
        takeQuiz(quizID);
        
    if (!hasFinished && missionID > 0) {
        $.ajax({
            type: "POST",
            url: "/mission.aspx/RecordEndLesson",
            data: "{'missionID':'" + missionID + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                hasFinished = true;
            }
        });
    }
}

function flvstart() {
    if (!hasStarted && missionID > 0) {
        $.ajax({
            type: "POST",
            url: "/mission.aspx/RecordStartLesson",
            data: "{'missionID':'" + missionID + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                hasStarted = true;
            }
        });
    }
}

function AddToFavorite() {
    if (!hasAddedTofav && missionID > 0) {
        $.ajax({
            type: "POST",
            url: "/mission.aspx/AddToFavorite",
            data: "{'missionID':'" + missionID + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {
                // setting buttons to be disabled
                hasAddedTofav = true;
            }
        });
    }
}

function showLoginForm() {
    $(document).ready(function() {
        $(document.body).click(function() {
            $(".login-panel").toggle("slow");
        });
    });
}

$(document).ready(function() {
    $('.login-open').click(function() {
        $(".login-panel:hidden").show("slow", function() { $(".text-142:first").focus(); });
        return false;
    });
});
