﻿//tabs
$(function () {
    // TABS - START //
    //    $('.tabs_container .tab_wrapper, .tabs_container .tab_wrapper_selected').click(function () {
    //        $('.tabs_container .tab_wrapper_selected').attr('class', 'tab_wrapper');
    //        $(this).attr('class', 'tab_wrapper_selected');
    //        $('.tabs_content .t_content_show').attr('class', 't_content_hide');
    //        var tab_id = $(this).attr('id');
    //        $('.tabs_content #' + tab_id + '_content').attr('class', 't_content_show');
    //    });
    $('.tabs_container .tab_wrapper, .tabs_container .tab_wrapper_selected').live('click', function () {
        $('.tabs_container .tab_wrapper_selected').attr('class', 'tab_wrapper');
        $(this).attr('class', 'tab_wrapper_selected');
        $('.tabs_content .t_content_show').attr('class', 't_content_hide');
        var tab_id = $(this).attr('id');
        $('.tabs_content #' + tab_id + '_content').attr('class', 't_content_show');
    });

    $('.tabs_container_popup .tab_wrapper, .tabs_container .tab_wrapper_selected').live('click', function () {
        $('.tabs_container_popup .tab_wrapper_selected').attr('class', 'tab_wrapper');
        $(this).attr('class', 'tab_wrapper_selected');
        $('.tabs_content_popup .t_content_show').attr('class', 't_content_hide');
        var tab_id = $(this).attr('id');
        $('.tabs_content_popup #' + tab_id + '_content').attr('class', 't_content_show');
    });

    $('.course_wrapper').mouseenter(function () { jQuery('.course_tooltip', this).fadeIn('2000'); $(this).css('background-color', '#e9fbe3'); $(this).find('.course_name a').css('color', '#22aa19'); $(this).find('.course_name').css('padding-left', '12px') });
    $('.course_wrapper').mouseleave(function () { jQuery('.course_tooltip', this).css('display', 'none'); $(this).css('background-color', 'white'); $(this).find('.course_name a').css('color', '#666666'); $(this).find('.course_name').css('padding-left', '0px') });
    if ($('.recommended_courses').find('.course_wrapper').length == 0) {$('.recommended_courses').css('display','none')}

});

//retrieve querystring from client side
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

//function openClose(id) {
//    if ($('#' + id).css('display') == 'none')
//        $('#' + id).slideDown('slow');
//    else
//        $('#' + id).slideUp('slow');
//}

function Test()
{
alert("ok");
}


//function ShowPopUp() {
//    $('#popup').fadeIn('fast'); 
//    $('#dark_screen').fadeIn('fast');
//}

function HidePopUp() {
    $('#popup').fadeOut('fast'); 
    $('#dark_screen').fadeOut('fast');
}

(function ($) {
    // VERTICALLY ALIGN TO CENTER OF BROWSER WINDOW FUNCTION (MAKE POSITION:ABSOLUTE)
    $.fn.vAlignWin = function () {
        return this.each(function (i) {
            var ah = $(this).height();
            var ph = $(window).height();
            var mh = (ph - ah) / 2;
            mh = mh + $(window).scrollTop();
            $(this).css('top', mh);
        });
    };
})(jQuery);

(function ($) {
    // HORIZONTALLY CENTER ELEMENT OF BROWSER WINDOW FUNCTION (MAKE POSITION:ABSOLUTE)
    $.fn.hAlignWin = function () {
        return this.each(function (i) {
            var ah = $(this).width();
            var ph = $(window).width();
            var mh = (ph - ah) / 2;
            mh = mh + $(window).scrollLeft();
            $(this).css('left', mh);
        });
    };
})(jQuery);


//popup additional questions
function sNationalityChange() {
    var country = $('#sNationality option:selected').text();
    if (country != 'Australia') { $('#divStudyVisa').slideDown('slow'); }
    else { $('#divStudyVisa').slideUp('slow'); $('#divVisaHelp').slideUp('slow'); }
}

function StudyVisa() {
    var answer = $('#divStudyVisa option:selected').text();
    if (answer == 'No') { $('#divVisaHelp').slideDown('slow'); }
    else { $('#divVisaHelp').slideUp('slow'); }
}

function validateEmail(email) {
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(email);
}

function isNumber(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
}


//===================================== rating =====================================
function ClickStar(Current_star, hidden_field_id) {
    if (Current_star == null)
        return;
    var Current_star_id = $(Current_star).attr("id");
    var star_value = document.getElementById(hidden_field_id);
    star_value.value = Extract_star($(Current_star).attr("id")).substring(5, 6);

    stars_config_over(Current_star);

}


function HoverStar(Current_star, event_name, hidden_field_id) { //Current_star = this
    //alert(star);
    //var Current_star = $(star).attr("id")
    //star_value.value = $(Current_star).attr("id").substring(5, 6);
    //var Current_star_position = Current_star_id.substring(5) //star_[1]
    //var Current_star_parent = $(Current_star).parent().get(0)
    //alert($(Current_star).attr("id"));
    //alert("current_star " + Current_star + "event_name " + event_name + "hidden_field_id " + hidden_field_id);


    //debugger;
    var Current_star_id = $(Current_star).attr("id");
    var star_value = document.getElementById(hidden_field_id);
    if (event_name == 'onmouseout') {
        //alert(star_value.value);
        if (star_value.value != '0') { return; }
        stars_config_out(Current_star);
    }

    if (event_name == 'onmouseover') {
        if (star_value.value != '0') { return; }
        stars_config_over(Current_star);

    }
}

//----------
String.prototype.endsWith = function (str) {
    var lastIndex = this.lastIndexOf(str);
    //return (lastIndex != -1) && (lastIndex + str.length == this.length);
    return (this.match(str + "$") == str)
}

function Extract_star(star_id) {
    if (star_id.endsWith("star_1")) return "star_1";
    if (star_id.endsWith("star_2")) return "star_2";
    if (star_id.endsWith("star_3")) return "star_3";
    if (star_id.endsWith("star_4")) return "star_4";
    if (star_id.endsWith("star_5")) return "star_5";

}
//---------

function stars_config_out(Current_star) {

    switch (Extract_star($(Current_star).attr("id"))) {
        case "star_1":
            $(Current_star).attr("class", "grey_star");
            $(Current_star).next().attr("class", "grey_star");
            $(Current_star).next().next().attr("class", "grey_star");
            $(Current_star).next().next().next().attr("class", "grey_star");
            $(Current_star).next().next().next().next().attr("class", "grey_star");

            $(Current_star).next().next().next().next().next().next().html("No rating");
            break;
        case "star_2":
            $(Current_star).prev().attr("class", "grey_star");
            $(Current_star).attr("class", "grey_star");
            $(Current_star).next().attr("class", "grey_star");
            $(Current_star).next().next().attr("class", "grey_star");
            $(Current_star).next().next().next().attr("class", "grey_star");

            $(Current_star).next().next().next().next().next().html("No rating");
            break;
        case "star_3":
            $(Current_star).prev().prev().attr("class", "grey_star");
            $(Current_star).prev().attr("class", "grey_star");
            $(Current_star).attr("class", "grey_star");
            $(Current_star).next().attr("class", "grey_star");
            $(Current_star).next().next().attr("class", "grey_star");

            $(Current_star).next().next().next().next().html("No rating");
            break;
        case "star_4":
            $(Current_star).prev().prev().prev().attr("class", "grey_star");
            $(Current_star).prev().prev().attr("class", "grey_star");
            $(Current_star).prev().attr("class", "grey_star");
            $(Current_star).attr("class", "grey_star");
            $(Current_star).next().attr("class", "grey_star");

            $(Current_star).next().next().next().html("No rating");
            break;
        case "star_5":
            $(Current_star).prev().prev().prev().prev().attr("class", "grey_star");
            $(Current_star).prev().prev().prev().attr("class", "grey_star");
            $(Current_star).prev().prev().attr("class", "grey_star");
            $(Current_star).prev().attr("class", "grey_star");
            $(Current_star).attr("class", "grey_star");

            $(Current_star).next().next().html("No rating");
            break;
    }

}



function stars_config_over(Current_star) { //this(parent), this(hovered star)

    //$(parent).children().each(function() {
    //var child = $(this);
    //var child_id = $(child).attr("id");
    //switch (child_id) {
    //alert($(Current_star).next().attr("id"));
    //alert($(Current_star).attr("id"));

    //alert (Extract_star($(Current_star).attr("id")));
    switch (Extract_star($(Current_star).attr("id"))) {
        case "star_1":
            $(Current_star).attr("class", "orange_star");
            $(Current_star).next().attr("class", "silver_star");
            $(Current_star).next().next().attr("class", "silver_star");
            $(Current_star).next().next().next().attr("class", "silver_star");
            $(Current_star).next().next().next().next().attr("class", "silver_star");

            $(Current_star).next().next().next().next().next().next().html("Unacceptable");
            break;
        case "star_2":
            $(Current_star).prev().attr("class", "orange_star");
            $(Current_star).attr("class", "orange_star");

            $(Current_star).next().attr("class", "silver_star");
            $(Current_star).next().next().attr("class", "silver_star");
            $(Current_star).next().next().next().attr("class", "silver_star");

            $(Current_star).next().next().next().next().next().html("poor");
            break;
        case "star_3":
            $(Current_star).prev().prev().attr("class", "orange_star");
            $(Current_star).prev().attr("class", "orange_star");
            $(Current_star).attr("class", "orange_star");

            $(Current_star).next().attr("class", "silver_star");
            $(Current_star).next().next().attr("class", "silver_star");

            $(Current_star).next().next().next().next().html("fair");
            break;
        case "star_4":
            $(Current_star).prev().prev().prev().attr("class", "orange_star");
            $(Current_star).prev().prev().attr("class", "orange_star");
            $(Current_star).prev().attr("class", "orange_star");
            $(Current_star).attr("class", "orange_star");

            $(Current_star).next().attr("class", "silver_star");

            $(Current_star).next().next().next().html("Good");
            break;
        case "star_5":
            $(Current_star).prev().prev().prev().prev().attr("class", "orange_star");
            $(Current_star).prev().prev().prev().attr("class", "orange_star");
            $(Current_star).prev().prev().attr("class", "orange_star");
            $(Current_star).prev().attr("class", "orange_star");
            $(Current_star).attr("class", "orange_star");

            $(Current_star).next().next().html("Excellent");
            break;
    }
}
//==================================================================================


