﻿$(document).ready(function() {

    /* INFO REQUEST */
    var a = $('#infoRequest').children();
    $('#infoRequest').children().remove();
    $('#ctl00_ctl00_column_thirdColumn_sitefinity_controltemplates_isalon_inforequest_ascx1_btnSubmit').hide();

    $('.button').click(function() {
        $(a).appendTo('#infoRequest');
        $('#infoRequest').children().css('visibility', 'visible');
        $('#ctl00_ctl00_column_thirdColumn_sitefinity_controltemplates_isalon_inforequest_ascx1_btnSubmit').show();
        $('.button').hide();
    });



    /* POST IT */
    if ($('#ctl00_ctl00_column_thirdColumn_sitefinity_controltemplates_isalon_postit_ascx1_hfBackGround').attr('value') == 'red')
        $('.postit').addClass('postitRed');
    if ($('#ctl00_ctl00_column_thirdColumn_sitefinity_controltemplates_isalon_postit_ascx1_hfBackGround').attr('value') == 'green')
        $('.postit').addClass('postitGreen');
    if ($('#ctl00_ctl00_column_thirdColumn_sitefinity_controltemplates_isalon_postit_ascx1_hfBackGround').attr('value') == 'yellow')
        $('.postit').addClass('postitYellow');
    if ($('#ctl00_ctl00_column_thirdColumn_sitefinity_controltemplates_isalon_postit_ascx1_hfBackGround').attr('value') == 'custom')
        $('.postit').addClass('postitCustom');


    /* READ MORE */
    $('.bottom').hide();

    $('.blah').click(function() {
        if ($(this).parent('.top').parent('.parent').children('.bottom').css('display') == 'none') {
            $(this).parent('.top').parent('.parent').children('.bottom').slideToggle();
        }
        else {
            $(this).parent('.top').parent('.parent').children('.bottom').slideToggle();
        }
    });

    /* CALL BACK */
    $('#ctl00_ctl00_column_thirdColumn_ctl00_txtRequest').focus(function() {
        if ($(this).text() == $(this).val())
            $(this).val('');
    });

    /* SOCIAL NETWORK */
    if ($('.media').height() > ($('.twitter').height() + $('.others').height())) {
        $('.media').css('padding-top', '20px');
        var hght = $('.media').height();
        $('.media').height(hght + 30);
    }

    /* LOGIN */
    $('#ctl00_ctl00_column_left_ctl00_txtPassword').keydown(function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if (code == 13) {
            __doPostBack('ctl00$ctl00$column$left$ctl00$btnLogin', '')
        }
    });

    $('#ctl00_ctl00_column_left_ctl00_btnLogin').click(function() {
        if ($('#ctl00_ctl00_column_left_ctl00_txtPassword').val() == "" ||
        $('#ctl00_ctl00_column_left_ctl00_txtPassword').val() == null ||
        $('#ctl00_ctl00_column_left_ctl00_txtUsername').val() == "" ||
        $('#ctl00_ctl00_column_left_ctl00_txtUsername').val() == null) {
            $('#ctl00_ctl00_column_left_ctl00_lblError').hide();
            $('#ctl00_ctl00_column_left_ctl00_lblError').fadeIn();
            $('#ctl00_ctl00_column_left_ctl00_lblError').text('please complete user name and password fields.');
            return false;
        }
    });

    /* YOUR TEAM */
    $("tr.tableItem").click(function() {
        $("tr.tableItem").removeClass("selected");
        $(this).addClass("selected");
    });

    $('span.rbDeputy').click(function() {
        $('span.rbDeputy').children().attr("checked", NaN);
        $(this).children().attr("checked", 'checked');
    });

    /* INDUSTRY LINKS */
    $(".industryLink").click(function() {
        $(this).parent().find("input.btnLog").click();
    });

    /* REGISTER */
    if ($("#divMaster") != undefined && $("#divMaster") != null && $("#divMaster") != NaN) {
        $('#ctl00_ctl00_column_left_sitefinity_controltemplates_isalon_register_ascx1_rdbNoManager').click(function() {
            $('#ctl00_ctl00_column_left_sitefinity_controltemplates_isalon_register_ascx1_lblError').hide();
            $('#ctl00_ctl00_column_left_sitefinity_controltemplates_isalon_register_ascx1_lblError').fadeIn();
            $('#ctl00_ctl00_column_left_sitefinity_controltemplates_isalon_register_ascx1_lblError').text('You must be the salon manager to proceed with the registration.');
        });
        $('#ctl00_ctl00_column_left_ctl00_rdbYesManager').click(function() {
            $('#ctl00_ctl00_column_left_sitefinity_controltemplates_isalon_register_ascx1_lblError').hide();
        });
    }

    /* PROFILE */
    mandatory = false;
    $(document).keyup(function(e) {
        if (!mandatory) {
            filled = false;
            fields = $('input.confirmPass');
            for (i = 0; i < fields.length; i++) {
                if ($(fields[i]).val() != '') {
                    filled = true;
                }
            }
            if (filled) {
                mandatory = true;
                labels = $('label.confirmPass');
                for (i = 0; i < labels.length; i++) {
                    $(labels[i]).text('*' + $(labels[i]).text().trim());
                }
            }
        }
        else {
            notFilled = true;
            fields = $('input.confirmPass');
            for (i = 0; i < fields.length; i++) {
                if ($(fields[i]).val() != '') {
                    notFilled = false;
                }
            }
            if (notFilled) {
                mandatory = false;
                labels = $('label.confirmPass');
                for (i = 0; i < labels.length; i++) {
                    $(labels[i]).text($(labels[i]).text().replace('*',''));
                }
            }
        }
    });
});