﻿
//function to toggle text between maltese and english
//function toggleLanguage() {
//    $('.englishText').toggle();
//    $('.malteseText').toggle();
//};


$(function() {
    $('input.clearField1').clearDefault();
    $('input.clearField2').clearDefault();

    $().piroBox({
        my_speed: 400, //animation speed
        bg_alpha: 0.1, //background opacity
        slideShow: true, // true == slideshow on, false == slideshow off
        slideSpeed: 4, //slideshow duration in seconds(3 to 6 Recommended)
        close_all: '.piro_close,.piro_overlay'// add class .piro_overlay(with comma)if you want overlay click close piroBox

    });

    if ($.cookie('language') == '2') {
        $('.englishText').hide();
        $('.malteseText').show();
        $('input.clearField1').val('Isem / Numru tad-dar');
        $('input.clearField2').val('Isem tat-Triq');        
    } else {
        $('input.clearField1').val('House Name / No');
        $('input.clearField2').val('Street Name');        
    }



    $('.malteseButton').click(function() {
        $('.englishText').hide();
        $('.malteseText').show();
        $('input.clearField1').val('Isem / Numru tad-dar');
        $('input.clearField2').val('Isem tat-Triq');
        $.cookie('language', 2);
        tickCommsCheckboxesMaltese();
        return false;
    });

    $('.englishButton').click(function() {
        $('.englishText').show();
        $('.malteseText').hide();
        $.cookie('language', 1);
        $('input.clearField1').val('House Name / No');
        $('input.clearField2').val('Street Name');
        tickCommsCheckboxesEnglish();
        return false;

    });




    $('#chPreferedCommEng').click(function() {
        $("[id$='_hfPrefferedComm']").val("");

        $("#chPreferedCommEng input[type='checkbox']:checked").each(function() {

            $("[id$='_hfPrefferedComm']").val($("[id$='_hfPrefferedComm']").val() + '|' + $(this).val());
        });
    });

    $('#chPreferedCommMal').click(function() {
        $("[id$='_hfPrefferedComm']").val("");

        $("#chPreferedCommMal input[type='checkbox']:checked").each(function() {

            $("[id$='_hfPrefferedComm']").val($("[id$='_hfPrefferedComm']").val() + '|' + $(this).val());
        });
    });

});

//Clear form default value jQuery plugin
(function($) {
    $.fn.clearDefault = function() {
        return this.each(function() {
            var default_value2 = $(this).val();
            var valueChanged = false;
            $(this).focus(function() {
                default_value = $(this).val();
                if ($(this).val() == default_value)
                    $(this).val("");
            });
            $(this).blur(function() {
                if ($(this).val() == "") $(this).val(default_value);
            });
        });
    };
})(jQuery);

function tickCommsCheckboxesMaltese() {

    var com_array = $("[id$='_hfPrefferedComm']").val().split("|");
    var part_num = 0;
    while (part_num < com_array.length) {

        $("#chPreferedCommMal input[type='checkbox']").each(function() {

            if ($(this).val() == com_array[part_num]) {
                $(this).attr('checked', 'checked');

            }


        });
        part_num += 1;
    }
}

function tickCommsCheckboxesEnglish() {

    var com_array = $("[id$='_hfPrefferedComm']").val().split("|");
    var part_num = 0;
    while (part_num < com_array.length) {

        $("#chPreferedCommEng input[type='checkbox']").each(function() {

            if ($(this).val() == com_array[part_num]) {
                $(this).attr('checked', 'checked');
            }


        });
        part_num += 1;
    }
}

    

