$(document).ready(function() {

    //Close button:

    $(".close").click(function() {
        $(this).parent().fadeTo(400, 0, function() {// Links with the class "close" will close parent
            $(this).slideUp(400);
        });
        return false;
    });

    $('.clearimg').click(function() {
        var id_but = $(this).attr("value");
        $(".img2clear").each(function(){
            var id_img = $(this).attr("value");
            if(id_but==id_img){
                $("#"+id_img).hide();
                $("#"+id_img+"_id").val("-1");
            }
        });
    });

    //type_id
    $('#type_id').change(function() {
        var id = $(this).val();
        document.location.href='product_list.php?id='+id;
    });

    $('.productlist_checkno').click(function() {
        $(".productlist_check").each(function(){
            //$(this).toggleClass("example");
            var tvalue = $(this).attr("value");
            if(tvalue=="0"){
                $(this).attr('checked', "checked");
            }
        });
    });

    // Check all checkboxes when the one in a table head is checked:

    $('.check-all').click(function() {
        $(this).parent().parent().parent().parent().find("input[type='checkbox']").attr('checked', $(this).is(':checked'));
    });

    $(".defaultCountdown").each(function(){
        //time_str = "2011,12,30,23,00,00";
        time_str = $(this).attr("name");
        var time_a = time_str.split(",");   
        var newYear = new Date();
        newYear = new Date(time_a[0], time_a[1]-1, time_a[2], time_a[3], time_a[4], time_a[5]); 
        //$('.defaultCountdown').countdown({until: newYear, format: 'DHM'});
        $(this).countdown({until: newYear,layout: '<table style="width: 100%"><tr><td>يوم</td><td>ساعة</td><td>دقيقة</td><td>ثانية</td></tr><tr><td>{dn}</td><td>{hn}</td><td>{mn}</td><td>{sn}</td></tr></table>'});

    });

    $(".menu_div").each(function(){
        $(this).hide();
    });

    $(".menu_li").click(function() {

        var id = $(this).attr("id");        
        if($("#mdiv_" + id).is(':visible')){
            $("#mdiv_" + id).hide();
            return false;
        }

        $(".menu_div").each(function(){
            $(this).hide();
        });

        $("#mdiv_" + id).show();
    });

    $(".like").click(function() {
        var id = $(this).attr("id");
        var sub_id = $(this).attr("name");
        var dataString = 'id=' + id + '&sub_id=' + sub_id;

        $.ajax({
            type : "GET",
            url : "ajax.php?a=comment&do=like",
            data : dataString,
            cache : false,
            success : function(html) {
                $("#luser_" + id).html(html);
            }
        });
    });

    $(".ushow").click(function() {
        var id = $(this).attr("id");
        var sub_id = $(this).attr("name");
        var dataString = 'id=' + id + '&sub_id=' + sub_id;

        $.ajax({
            type : "GET",
            url : "ajax.php?a=comment&do=ushow",
            data : dataString,
            cache : false,
            success : function(html) {
                $("#ushowd_" + id).removeClass("hide");
                $("#ushowd_" + id).addClass("ushowd");
                $("#ushowd_" + id).html(html);
            }
        });
    });

    $(".adlike").click(function() {
        var id = $(this).attr("id");
        var name = $(this).attr("name");
        var dataString = 'id=' + id + '&s=' + name;
        $("#votebox").slideDown("slow");

        $("#flash").fadeIn("slow");

        $.ajax({
            type : "GET",
            url : "ajax.php?a=rating",
            data : dataString,
            cache : false,
            success : function(html) {
                $("#flash").fadeOut("slow");
                $("#racontent").html(html);
            }
        });
    });
    // Close button action
    $(".close").click(function() {
        $("#votebox").slideUp("slow");
    });
    // Close button action
    $("#offer").change(function() {

        var price = $("#offer_check").attr("name");
        var dataString = 'code=' + this.value + "&price=" + price;

        $("#offer_check").html("جاري التحميل ..");

        if(this.value == "") {
            $("#offer_check").html("");
        } else {

            $.ajax({
                type : "GET",
                url : "ajax.php?a=offer",
                data : dataString,
                cache : false,
                success : function(html) {
                    $("#offer_check").html(html);
                }
            });

        }

    });
});
(function($) {

    var initLayout = function() {

        $('#birthdate').DatePicker({
            format : 'Y-m-d',
            date : $('#birthdate').val(),
            current : $('#birthdate').val(),
            starts : 1,
            position : 'left',
            onChange : function(formated, dates) {
                $('#birthdate').val(formated);
                $('#birthdate').DatePickerHide();
            }
        });

        $('#leave_date_m').DatePicker({
            format : 'Y-m-d',
            date : $('#leave_date_m').val(),
            current : $('#leave_date_m').val(),
            starts : 1,
            position : 'left',
            onChange : function(formated, dates) {
                $('#leave_date_m').val(formated);
                $('#leave_date_m').DatePickerHide();
            }
        });

        $('#arrival_date_m').DatePicker({
            format : 'Y-m-d',
            date : $('#arrival_date_m').val(),
            current : $('#arrival_date_m').val(),
            starts : 1,
            position : 'left',
            onChange : function(formated, dates) {
                $('#arrival_date_m').val(formated);
                $('#arrival_date_m').DatePickerHide();
            }
        });

    };

    EYE.register(initLayout, 'init');
})(jQuery)

$(function(){
    $(".spin1").NumericUpDown();
});
