$(document).ready (function() {
    web20_init();
    //$(this).ajaxStop(function() {
        //web20_init();
    //});
});
function web20_init() {

    $(document).click(function() {
        $('.Web20_select_popup_js').slideUp();
    });
    $('.Web20_select_popup_2_js a').click(function() {
        $(this).parents('.Web20_select_inner_js').children('input').val($(this).attr('value'));
        $(this).parents('.Web20_select_inner_js').children('div[id^=select_visual]').text($(this).attr('showvalue') ? $(this).attr('value') : $(this).text());
    });
    $('.Web20_select_left_js').click(function(event) {
        event.stopPropagation();
        if ($(this).find('.Web20_select_popup_js').css('display') == 'block') {
            $(this).find('.Web20_select_popup_js').slideUp();
        } else {
            $(this).find('.Web20_select_popup_js').slideDown();
        }
    });


    if (navigator && navigator.platform && !navigator.platform.match(/^(iPad|iPod|iPhone)$/)) {

        $(".js_dropdown").each( function(){

            var select_replace_options = "";

            $(this).children('option').each(function(){
                select_replace_options += "<a value='" + $(this).attr('value') + "' href='javascript:;'>" + $(this).text() + "</a> ";
            });

            var select_replace_by = "<div class='select_replaced_js'><div style=\"" + $(this).attr('style') + "\" class=\"Web20_select_alpha_left Web20_select_alpha_left_js\">\n\
                                <div class=\"Web20_select_alpha_right Web20_select_alpha_right_js\"></div>\n\
                                    <div class=\"Web20_select_alpha_inner Web20_select_alpha_inner_js\">\n\
                                    <div class=\"Web20_select_alpha_visual Web20_select_alpha_visual_js\" id=\"select_alpha_visual_cmb_country\">"+ $(this).children("option:selected").text() +"</div>\n\
                                        </div>\n\
                                                    <div id=\"select_levelList\"  style=\"" + $(this).attr('style') + "\" class=\"Web20_select_alpha_popup Web20_select_alpha_popup_js\"><div class=\"Web20_select_alpha_popup_1 Web20_select_alpha_popup_1_js\"><div class=\"Web20_select_alpha_popup_2 Web20_select_alpha_popup_2_js\">\n\
                                                    " + select_replace_options + "</div></div>\n\
                                                     <div class=\"Web20_select_popup_footer_left Web20_select_popup_footer_left_js\"><div class=\"Web20_select_popup_footer_right Web20_select_popup_footer_right_js\"><div class=\"Web20_select_popup_footer_inner Web20_select_popup_footer_inner_js\"></div></div></div>\n\
                                               </div>\n\
                                            </div>\n\
                                    </div>\n\
                                ";

            $(this).hide();
            $(this).after(select_replace_by);
        });
    }

    $(document).click(function() {
        $('.Web20_select_alpha_popup_js').slideUp('fast');
    });
    $('.Web20_select_alpha_popup_2_js a').click(function() {
        $(this).parents('.select_replaced_js').parent().children('select').val($(this).attr('value'));
        $(this).parents('.select_replaced_js').find('div[id^=select_alpha_visual]').text($(this).text());
    });
    $('.Web20_select_alpha_left_js').click(function(event) {
        event.stopPropagation();
        if ($(this).find('.Web20_select_alpha_popup_js').css('display') == 'block') {
            $(this).find('.Web20_select_alpha_popup_js').slideUp('fast');
        } else {
            $(this).find('.Web20_select_alpha_popup_js').slideDown('fast');
        }
    });
    $('.Web20_input_right input.visual4password').focus(function() {
        $(this).hide();
        $(this).parent().children('input.password').show().focus();
    });
    $('.Web20_input_right input.password').blur(function() {
        if ($(this).val() == '') {
            $(this).hide();
            $(this).parent().children('input.visual4password').show();
        }
    });
    $('.Web20_input_right_v1 input.visual4password').focus(function() {
        $(this).hide();
        $(this).parent().children('input.password').show().focus();
    });
    $('.Web20_input_right_v1 input.password').blur(function() {
        if ($(this).val() == '') {
            $(this).hide();
            $(this).parent().children('input.visual4password').show();
        }
    });
}
