﻿/// <reference path="jquery-1.4.4-vsdoc.js" />



///----------  Remove CTA - Nationally Recongnised section  --------------------////
 
$(function () {
 
    var v = $('div.cL');
    var t = v.find('.shortcoursebody');
    if (t.length != '0') {
        $('#NationallyRecognised').css('display', 'none');
    }
    else {
        $('#NationallyRecognised').css('display', 'block');
    }

});


///----------  tooltip  begin --------------------////
function loadToolTips(newtarget, newTheme) {
    var target = "[title *='Coming Soon in 2012']";
    if (newtarget) target = newtarget + " " + target;

    var theme = csstheme
    if (newTheme) theme = newTheme;

    $(target).qtip({
        content: {
            text: false // Use each elements title attribute
        },
        position: {
            corner: {
                tooltip: 'topMiddle', // Use the corner...
                target: 'bottomLeft' // ...and opposite corner
            },
            adjust: { x: -50, y: 15, screen: true },
            target: 'mouse'
        },
        style: {
            border: { width: 0, radius: 6 },
            title: {
                background: '#378968',
                color: '#64D8B3'
            },
            padding: 10,
            textAlign: 'center',
            tip: true, // Give it a speech bubble tip with automatic corner detection
            name: theme
        },
        api: {
            onShow: function () {
                this.elements.tooltip.css('padding-bottom', '5px')
            }
        }
    });
}

function loadCalendarSearchHelpToolTips() {
    /// For Calendar Search Help 
    $(".searchHelp").qtip({
        content: {
            text: '<p style="color:white;text-transform:uppercase;margin:0 0 13px 0;">Course Calendar Search HELP</p>' +
                  '<p style="margin:0 0 7px 0;font-weight:normal;"><b style="color:white;">Course Departments:</b> Select a combination of up to four multiple course departments for view within the calendar.</p> ' +
                  '<p style="margin:0 0 7px 0;font-weight:normal;"><b style="color:white;">Course Types:</b> In the same way, you may also choose multiple course types.</p> ' +
                  '<p style="margin:0 0 10px 0;font-weight:normal;"><b style="color:white;">Intake Groups:</b> All students are issued with their course intake group ID upon enrolments. Select your combinations to include this course criteria within the calendar. ' +
                  'If you click on a course type by accident, just click on it again to unselect it.</p>'
        },
        position: {
            corner: {
                tooltip: 'bottomLeft', // Use the corner...
                target: 'topRight' // ...and opposite corner
            },
            adjust: { x: 0, y: -20, screen: true },
            target: 'mouse'
        },
        style: {
            width: { max: 480 },
            border: { width: 0, radius: 6 },
            title: {
                background: '#378968',
                color: '#64D8B3',
                'font-weight': 'normal'
            },
            padding: 8,
            textAlign: 'left',
            tip: true, // Give it a speech bubble tip with automatic corner detection
            name: csstheme
        },
        api: {
            onShow: function () {
                this.elements.tooltip.css('padding-bottom', '5px')
            }
        }
    });
}


///----------  tooltip   end----------------------////


///----------  wizard start ----------------------////

function WizardStepStatus() {
    this.Begain = "Unknown";
    this.Login = "Unknown";
    this.AustralianStudent = "Unknown";
    this.InternationStudent = "Unknown";
    this.Entry = "Unknown";
    this.Department = "Unknown";
    this.Program = "Unknown";
    this.Intake = "Unknown";
    this.Options = "Unknown";
    this.Course = "Unknown";
    this.Citizenship = "Unknown";
    this.Certification = "Unknown";
    this.OverseaQualifaction = "Unknown";
    this.Eligibility = "Unknown";
    this.Funding = "Unknown";
    this.Scholarship = "Unknown";
    this.Rpl = "Unknown";
    this.Rcc = "Unknown";
    this.Ct = "Unknown";
    this.Recognitions = "Unknown";
    this.Yourself = "Unknown";
    this.Enquiry = "Unknown";
    this.PaymentPlan = "Unknown";
    this.PaymentType = "Unknown";
    this.PaymentDetails = "Unknown";
    this.Registration = "Unknown";
}

function RegistrationWizard() {
    _StaticWizard = this;
    this.progressTabs;
    this.progressBars;
    this.ui = new WizardUI(this);
    this.stepStatus = new WizardStepStatus();
    this.wizardValidation = new WizardValidation();


    this.tabClick = function (event, index) {
        var tab = $(this.getTabs()[index]);
        var pre = null;
        if (index > 0)
            pre = $(this.getTabs()[index - 1]);

        if (tab.hasClass("unknown") && pre != null && pre.hasClass("done")) {
            // allow
        } else if (tab.hasClass("unknown") && event.originalEvent != undefined) {
            return false;
        } else if (tab.hasClass("skip")) {
            return false;
        }

        var infoBoxIndex = index == 0 ? 0 : 1;
        $("ul.infoBox").data("tabs").click(infoBoxIndex);
        return true;
    }


    this.accordionClick = function (event, index) {
        //var section = this.getCurrentTab().parent().context.id;

        if (index == undefined) return true;
        
        var skip = $(this.getTabs()[index]).hasClass("skip");
        if (skip)
            return false;
        else if (index === 0)
            return true;
        else 
            return $(this.getTabs()[index - 1]).hasClass("done") || $(this.getTabs()[index - 1]).hasClass("skip");
    }

    function GetNextTab(event, index)
    {
        var x = -1;
        index = _StaticWizard.progressTabs.getIndex();
        $.each(_StaticWizard.progressTabs.getTabs(), function (i, value) {
            if (!(i > index && x === -1)) return;

            var jTab = $(value);
            var found = !jTab.hasClass("skip");

            if (found)
            {
                x = i;
            }
        });

        return x;
    }

    this.nextTabClick = function (event, index) {
        var target = $(this).attr("rel");
        var nextTab = GetNextTab(event, index);
        _StaticWizard.progressTabs.click(nextTab);

        if (target === 'eligibility') {

            if (_StaticWizard.stepStatus["Scholarship"].toLowerCase() != 'skip') {
                $(".accordion h2#scholarship").click();
            }
            else {
                _StaticWizard.nextAccordion('scholarship');
            }

        }
    }

    this.nextAccClick = function (event, index) {
        var target = $(this).attr("rel");
        //        $(".accordion h2#" + target).click();

        var valid = _StaticWizard.wizardValidation.validateBeforeMove(target);

        if (!valid) return;

        _StaticWizard.nextAccordion(target);
    }

    this.nextAccordion = function (target) {
        var stop = false;
        var accs = $(".accordion h2#" + target).nextAll("h2").each(
            function (i, value) {
                var jAcc = $(value);
                var found = !jAcc.hasClass("skip");
                if (found && !stop) {
                    stop = true;
                    jAcc.click();
                }
            });
    }

    this.checkLogin = function (sender, arguments) {
        _StaticWizard.progressTabs.next();
    }

    this.ausSelected = function (sender, arguments) {

        if (_StaticWizard.wizardValidation.state()) {

            _StaticWizard.progressTabs.next(); 
            $(".accordion h2#department").click();
        }
    }


    this.intSelected = function (sender, arguments) {

        _StaticWizard.progressTabs.next();
        $(".accordion h2#department").click();
    }


    this.departmentSelected = function (sender, arguments) {
    }


    this.programSelected = function (sender, arguments) {
    }


    this.intakeSelected = function (sender, arguments) {
    }
}

function WizardValidation() {

    this.validateBeforeMove = function (traget) {
        var valid = false

        if (traget == "department") valid = this.department();
        else if (traget == "program") valid = this.program();
        else if (traget == "intake") valid = this.intake();
        else valid = true;

        return valid;
    }
    
    this.state = function () {
        var valid = $("#ddlState").val() != "";
        if (!valid) alert("Please select a state!");
        return valid;
    }

    this.department = function () {
        var valid = _StaticWizard.stepStatus.Department == "Done";
        if (!valid) alert("Please select a Course Department!");
        return valid;
    }

    this.program = function () {
        var valid = _StaticWizard.stepStatus.Program == "Done";
        if (!valid) alert("Please select a Course!");
        return valid;
    }

    this.intake = function () {
        var valid = _StaticWizard.stepStatus.Intake == "Done";
        if (!valid) alert("Please select a intake!");
        return valid;
    }

    this.citizenship = function () {
        var valid = false;

        var rd = $('#rblCitizenship input:checked');
        if (rd.length == 0) {
            alert("Please declare your citizenship!");
            return false;
        }

        if (rd.val() == 'false' && $('#ddlResidency').val() == '') {
            alert("Please select a Residency option!");
            return false;
        }

        return true;
    }
}

function WizardUI(wiz) {
    var wizard = wiz;
    var allStatus = 'unknown ready done skip update';
    this.returnUrl;

    this.update = function () {
        $.each(_StaticWizard.progressTabs.getTabs(), function (index, value) {
            var tab = value.id.replace('tab', '')
            var status = wizard.stepStatus[tab].toLowerCase();

            var jTab = $(value);
            jTab.removeClass(allStatus).addClass(status);

            var step = $($(".progressBar .step").get(index));
            step.removeClass(allStatus).addClass(status);

            if (jTab.hasClass('skip')) {
                jTab.find('.tabTitle').fadeTo(0, 0.3);
            }
            else {
                jTab.find('.tabTitle').fadeTo(0, 1);
            }
        });

        $.each($(".accordion > h2"), function (index, value) {
            var tab = value.id;
            tab = tab.charAt(0).toUpperCase() + tab.slice(1);
            var status = wizard.stepStatus[tab].toLowerCase();

            var jTab = $(value);
            jTab.removeClass('unknown done skip update').addClass(status);

            if (jTab.hasClass('skip')) {
                jTab.find('a').fadeTo(0, 0.3);
            } else {
                jTab.find('a').fadeTo(0, 1);
            }
        });

        this.visaTypeDisplay();

//        if (wizard.stepStatus["Scholarship"].toLowerCase() === 'skip') {
//            $(".accordion h2#scholarship + .pane").hide();
//            $(".accordion h2#rpl").click();
//        }
    }

    this.setCalendar = function () {
        $("input.calendar").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: '1930:2011'
        });

      
        if ($("input#rblJobNetwork_0").attr("checked")) {

            $("#btnPayment").css("display", "none");


            $("#txbNetwork").attr("disabled", false);
            $("#txbNetwork").removeClass();
            $("#txbNetwork").addClass("inputbox1");
        }
        else {

            $("#btnPayment").css("display", "block");

            $("#txbNetwork").val("Please specify the Network. E.g. Max Employment");
            $("#txbNetwork").attr("disabled", true);
            $("#txbNetwork").removeClass();
            $("#txbNetwork").addClass("inputbox1_disable");
        }
    }

    this.courseUnavailable = function(){
        alert("Sorry, this intake is unavailable at the moment, please come back later or choose another intake, thank you.");
    }

    this.visaTypeDisplay = function () {
        var rd = $('#rblCitizenship input:checked');
        if (rd.length == 0 || rd.val() == 'true') {
            $('#ddlResidency').attr('disabled', 'disabled');
        } else {
            $('#ddlResidency').removeAttr('disabled');
        }
    }

    this.close = function () {
        if (this.returnUrl != null) {
            window.parent.location = this.returnUrl;
        } else if (window.parent.overlayClose != undefined) {
            window.parent.overlayClose();
        }
    }
}

///----------  wizard end ----------------------////



function inputtextbox(obj, txt) {
    if (obj.value == txt)
        obj.value = "";
}

function textboxblur(obj, txt) {
    var t = $.trim(obj.value);

    if (t == "")
        obj.value = txt;
}

function inputpswbox(obj,target) {
    var obj2 = "#" + target;
    $(obj).css("display", "none");
    $(obj2).val("");
    $(obj2).css("display", "block");
    $(obj2).focus();
}

function pswboxblur(obj, target, txt) {
    var obj2 = "#" + target;
    if ($(obj).val() == txt || $(obj).val() == "") {
        $(obj).css("display", "none");
        $(obj2).css("display", "block");
    }
}

function pswboxchange(obj,target) {

    var obj2 = "#" + target;
    $(obj).css("display", "none");
    $(obj2).val("");
    $(obj2).css("display", "block");
    $(obj2).focus();
}


/*
------- clipboard  -----------------
*/
function closewebpartbyId(obj)
{
    $(obj).hide();
}

function accordianheadercontrol(obj, target) {
    var gap = target + "_gap";
    if ($(obj).attr("title") == "hide") {
        $(obj).attr("title", "show");
        $(obj).removeClass();
        $(obj).addClass("headerbtn_Show");
        $(target).slideUp("normal");
        $(gap).css("display", "block");
    }
    else {
        $(obj).attr("title", "hide");
        $(obj).removeClass();
        $(obj).addClass("headerbtn_Hide");
        $(target).slideDown("normal");
        $(gap).css("display", "none");
    }
}


/*
---------------- text box place holder labels -----------------------
*/

function RegisterInPlaceLabels()
{
    $('input[type="text"][data-placeholder]')
    .focus(function () {
        if (this.value == $(this).attr('data-placeholder')) {
            this.value = '';
        }
    })
    .blur(function () {
        if ($.trim(this.value) == '') {
            this.value = $(this).attr('data-placeholder') || '';
        }
    });
}


function LoadVideo(selector,videoHolder,url,dlgHeight,dlgWidth) {


    $(selector).delegate('a.ctaImg', 'click', function () {
        // $(selector).live('click', function () {

        var placeholder = $(videoHolder);
        placeholder.load(url, function () {
            placeholder.dialog({
                height: dlgHeight,
                width: dlgWidth,
                position: 'center',
                modal: true,
                closeText: '',
              //  dialogClass: 'transparent',
                open: function (event, ui) {
                    $(this).parent().children(".ui-widget-header").css('border', 'none');
                    $(this).parent().children(".ui-widget-header").css('background-color', 'transparent');
                    $(this).parent().children(".ui-widget-header").css('background-image', 'none');

                    //$(this).parent().find(".ui-dialog-titlebar-close").css('background-color', 'red');
                    $(this).parent().find(".ui-dialog-titlebar-close").css('border', 'none');
                    //  $(this).parent().find(".ui-dialog-titlebar-close").css('width', '30px');
                    //  $(this).parent().find(".ui-dialog-titlebar-close").css('height', '30px');
                    $(this).parent().find(".ui-dialog-titlebar-close").css('top', '18px');
                    $(this).parent().find(".ui-dialog-titlebar-close").css('right', '6px');
                    $(this).parent().find(".ui-dialog-titlebar-close").css('z-index', '300');
                    $(this).parent().find(".ui-dialog-titlebar-close").addClass("dialog-close");

                    //$(this).parent().find(".ui-dialog-titlebar-close").children(".ui-icon").css('background-color', 'green');

                    $(this).parent().find(".ui-dialog-titlebar-close").css('margin', '0px');
                    $(this).parent().find(".ui-dialog-titlebar-close").css('padding', '0px');
                    $(this).parent().find(".ui-dialog-titlebar-close").css('margin', '0px');


                    $(this).parent().find(".ui-dialog-titlebar-close span").removeClass("ui-icon-closethick");
                    $(this).parent().find(".ui-dialog-titlebar-close span").removeClass("ui-icon");
                    $(this).parent().find(".ui-dialog-titlebar-close span").children("ui-icon").css('background', 'none');
                    //$(this).parent().find(".ui-dialog-titlebar-close span").val("");
                    $(this).parent().find(".ui-dialog-titlebar-close span").addClass("dialog-close-icon");
                    //$(this).parent().find(".ui-dialog-titlebar-close span").css("display", "none");

                    //$(this).parent().find(".ui-dialog-titlebar-close").removeClass(".ui-icon").addClass(".ctaImg");

                    $(this).parent(".ui-widget-content").css('background', 'transparent');
                    $(this).parent(".ui-widget-content").css('border', 'none');

                }

            });
        });

    });

    // Close Video Dilaog if Clicked Outside
    $('.ui-widget-overlay').live('click', function (event) {
        $(this).prev().find('div:nth-child(2)').dialog('close');
    });

}





