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: "475x", href: "#yti01" });
    $(".yti02").colorbox({ inline: true, width: "475x", href: "#yti02" });
    $(".yti03").colorbox({ inline: true, width: "475x", href: "#yti03" });
    $(".yti04").colorbox({ inline: true, width: "475x", href: "#yti04" });
    $(".yti05").colorbox({ inline: true, width: "475x", 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();$(".autocmp").combobox();$(".date").datepicker();
    var pegThemeEnabled = false;
    if ($("td select.peg + input").length > 0) {pegThemeEnabled = true;$("td select.peg + input").addClass("peg");$("td select.peg + input").each(function () {$(this).attr('title', $(this).prev().attr("title"));$(this).attr('required', $(this).prev().attr("required"));$(this).attr('tabIndex', $(this).prev().attr("tabIndex"));});}
    if ($("td input.peg").length > 0) {pegThemeEnabled = true; $(".dds").wrap("<div style=\"position:relative;\" />"); $("td input.peg").each(function () {if ($(this).parent(".pti").length == 0) {$(this).wrap("<div class='pto' />");$(this).wrap("<div class='ptc' />");$(this).wrap("<div class='pti' />");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>"; $(this).parents(".pto").after(lbl);$(this).focus(function () { $(this).parent().parent().addClass("focus"); });$(this).blur(function () { $(this).parent().parent().removeClass("focus"); });}}});}
    if ($("td textarea.peg").length > 0) {pegThemeEnabled = true;$("td textarea.peg").each(function () { if ($(this).parent(".pti").length == 0) { $(this).wrap("<div class='pto' />"); $(this).wrap("<div class='ptc' />"); $(this).wrap("<div class='pti' />"); 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>"; $(this).parents(".pto").after(lbl); $(this).focus(function () { $(this).parent().parent().addClass("focus"); }); $(this).blur(function () { $(this).parent().parent().removeClass("focus"); }); } } });}
    if ($("div.pto + label + button").length > 0) {$("div.pto + label + button").each(function () {$(this).prev().prev().find(".pti").after($(this));});}
    if (pegThemeEnabled) {$(".ptc").uncorner().parent().uncorner();$(".ptc").corner("round 5px").parent().css('padding', '1px').corner("cc:#fff round 6px");}
    $(".phone").mask("(999) 999-9999");$(".zipcode").mask("99999");
    $('textarea.autosize').elastic();
    $("textarea.autosize").live("focus", function () {
        $(this).elastic().die("focus");
    });
    fixFieldSets();
    $('.clicky').uncorner().corner("round 5px");
    if (!Modernizr.input.placeholder) { $.updnWatermark.attachAll(); }
}

function tabSelect(x) {$("#dr1").hide(); $("#dr2").hide(); $("#dr3").hide(); $("#dr4").hide(); $("#dr5").hide(); $("#dr6").hide();$(".tab").removeClass('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++; });
            $(".txtNewOrder").val($(".qOrder", ui.item).text());
            $(".txtQuestionIdSwap").val($(".qID", ui.item).val());
            document.location = $(".lnkReorderQuestions").attr("href"); 
        } 
    }); 
}