var curSelectedRole;
var isDirty = false;

$(document).ready(function () {
    $("ul.sf-menu").supersubs({ minWidth: 12, maxWidth: 27, extraWidth: 1 }).superfish({ speed: 'fast', autoArrows: true, animation: { height: 'show'} }).find('ul').bgIframe({ opacity: false });
    $("span.validator").wrapInner($("<span class='wrapper'></span>"));
    //$(".formerror").corner("round 5px cc:#fff");
    $(".login").keypress(function (event) { if (event.keyCode == '13') { window.location = $(".login a").attr('href'); return false; } });
    $(".smallsearch").keypress(function (event) { if (event.keyCode == '13') { window.location = $(".smallsearch a").attr('href'); return false; } });
    //$('.field').bind('focus', function () { $(this).addClass('focus'); $(this).css("color", "#000000"); });
    //$('.field').bind('blur', function () { $(this).removeClass('focus'); $(this).css("color", "#666666"); });
    //$('.ui-autocomplete-input').bind('focus', function () { $(this).addClass('focus'); $(this).css("color", "#000000"); });
    //$('.ui-autocomplete-input').bind('blur', function () { $(this).removeClass('focus'); $(this).css("color", "#666666"); });
    $('.pleaseWaitMsg').center(); $(window).bind('resize', function () { $('.pleaseWaitMsg').center(); });
    initPopups();
    enablePegText();
});

function initPopups() {
    $(".yt-video1").colorbox({ iframe: true, innerWidth: 425, innerHeight: 344 });
    $(".yti01").colorbox({ inline: true, width: "475px", href: "#yti01" });
    $(".yti02").colorbox({ inline: true, width: "475px", href: "#yti02" });
    $(".yti03").colorbox({ inline: true, width: "475px", href: "#yti03" });
    $(".yti04").colorbox({ inline: true, width: "475px", href: "#yti04" });
    $(".yti05").colorbox({ inline: true, width: "475px", href: "#yti05" });
    $("#yti01 a").youtubin(); $("#yti02 a").youtubin(); $("#yti03 a").youtubin(); $("#yti04 a").youtubin(); $("#yti05 a").youtubin();
    $(".inline-link1").colorbox({ width: "50%", inline: true, href: "#inline-html1" });
    $(".ifrm-normal").colorbox({ iframe: true, innerWidth: 750, innerHeight: 455 });
    $(".ifrm-results").colorbox({ iframe: true, innerWidth: 900, innerHeight: 455 });
    $(".ifrm-forgot").colorbox({ iframe: true, innerWidth: 420, innerHeight: 220 });
    $("#link-debugsession").colorbox({ width: "350px", inline: true, href: "#inline-debugsession" });
    $(".tbl-question").css("position", "relative");$(".tbl-test").css("position", "relative");
    //$(".gelbtn26b").blend(); $(".gelbtn56g").blend(); $(".gelbtn100r").blend(); $(".gelbtn114").blend(); $(".gelbtn114b").blend(); $(".gelbtn275").blend(); $(".gelbtn275r").blend();
}

function enablePegText() {
    $('input').not(".star").checkBox(); $(".date").datepicker();
    //$(".autocmp").combobox();
    //$("input.peg").each(function () { title = $(this).attr('title'); if (title != "") { id = $(this).attr('id'); required = $(this).attr('Required'); lbl = "<label for='" + id + "'>" + title + "</label>"; if (required == "true") lbl = "<label for='" + id + "'>" + title + "<span class='req'>*</span></label>"; if ($(this).parent().find("label").length == 0) { $(this).after(lbl); } } });
    //$("input.peg").focus(function () { $(this).addClass("focus"); });
    //$("input.peg").blur(function () { $(this).removeClass("focus"); });

    //$("select.peg").each(function () { title = $(this).attr('title'); if (title != "") { id = $(this).attr('id'); required = $(this).attr('Required'); lbl = "<label for='" + id + "'>" + title + "</label>"; if (required == "true") lbl = "<label for='" + id + "'>" + title + "<span class='req'>*</span></label>"; if ($(this).parent().find("label").length == 0) { $(this).next().next().after(lbl); } } });
    //$("textarea.peg").each(function () { title = $(this).attr('title'); if (title != "") { id = $(this).attr('id'); required = $(this).attr('Required'); lbl = "<label for='" + id + "'>" + title + "</label>"; if (required == "true") lbl = "<label for='" + id + "'>" + title + "<span class='req'>*</span></label>"; if ($(this).parent().find("label").length == 0) { $(this).after(lbl); } } });
    $(".phone").mask("(999) 999-9999");
    $(".zipcode").mask("99999");
    $('textarea.autosize').elastic();
    $("textarea.autosize").live("focus", function () {
        $(this).elastic().die("focus");
    });
    //$('select.autocmp').each(function () { $(this).siblings(".ui-autocomplete-input").val($(this).find('option:selected').text()); });
}

function tabSelect(x) { $("#dr0").hide(); $("#dr1").hide(); $("#dr2").hide(); $("#dr3").hide(); $("#dr4").hide(); $("#dr5").hide(); $("#dr6").hide(); $(".tab").removeClass('sel'); if (x == "dr0") { $("#dr0").show(); $("#lr0").addClass('sel'); } if (x == "dr1") { $("#dr1").show(); $("#lr1").addClass('sel'); } if (x == "dr2") { $("#dr2").show(); $("#lr2").addClass('sel'); } if (x == "dr3") { $("#dr3").show(); $("#lr3").addClass('sel'); } if (x == "dr4") { $("#dr4").show(); $("#lr4").addClass('sel'); } if (x == "dr5") { $("#dr5").show(); $("#lr5").addClass('sel'); } if (x == "dr6") { $("#dr6").show(); $("#lr6").addClass('sel'); } return void (0); };
function ddlclicked(list, btn) {if ($(list).is(':visible')) {$(btn).removeClass('active');$(list).hide();}else {$(".ddl_hm").removeClass("active");$(".divDropDownList").hide();$(btn).addClass('active');$(list).show();}}
function enableDnD() {if ($('#divRoleSelection').length > 0) {$('#divRoleSelection').html($('#divRoleSelection').html().replace("javascript:", "javascript:$('.tile-student').draggable('destroy'); $('.tile-drop-user').droppable('destroy');")); $('.tile-student').draggable('destroy'); $('.tile-drop-user').droppable('destroy'); $('.tile-student').draggable({ helper: 'clone' }); $('.tile-drop-user').droppable({ drop: function (event, ui) { $("input", this).val($("input", ui.helper).val()); document.location = $("a", this).attr("href"); } });}}
//function fixFieldSets() {if ($.support.borderRadius && document.body.style['MozBorderRadius'] == undefined) {$("fieldset").not(".fieldsetFix fieldset").each(function () {if ($(this).find('#recaptcha_widget_div').length > 0) { $(this).parent('div').addClass('fieldsetFix') } else $(this).wrap("<div class='fieldsetFix' />");});}}
function showMessage() { $.fn.colorbox({ width: "50%", inline: true, open: true, href: "#message-box" }); }

function enableQuestionDnD() {
    $("#ulResults").sortable({
        handle: '.tile-question', axis: 'y', delay: 200, update: function (event, ui) {
            var i = 1; $(".liTile:visible").find(".qOrder").each(function () { $(this).html(String(i)); i++; });
            ReorderQuestion($(".qID", ui.item).val(), $(".qOrder", ui.item).text());
        }
    }); 
}
