

$(document).ready(function(){
    
    $('.ankboot_contact_form_display').attr('href','#').click(function(){
        
        display_ankboot_form();
        return false;
    });
    
    
    $('#submit_ankboot_contact_form').live('submit',function(){
        
        var name = $('#ankboot_contact_form [name=name]').val();
        var email = $('#ankboot_contact_form [name=email]').val();
        var comments = $('#ankboot_contact_form [name=comments]').val();
        var subject = $('#ankboot_contact_form [name=subject]').val();
        
        var reEmail = new RegExp(/^[a-zA-Z0-9_\.\-]+\@([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/);
        
        
        if (!email || !name || !subject || !comments){
            
            $('#ankboot_contact_msg').html('جميع الحقول مطلوبة').fadeIn();
            return false;
        }
        
        if (!reEmail.test(email)) {
            $('#ankboot_contact_msg').html('الرجاء ادخال ايميل صحيح').fadeIn();
            return false;
        }
        
        
        else {
            $.post('http://aljarallah.net/wp-content/plugins/ank_contact/js/../contactForm.php',
                {
                    'name': name,
                    'email': email,
                    'comments': comments,
                    'subject': subject
                },
                function(data){
                    
                    var xml = $(data);
                    var status = xml.find('status').text();
                    
                    if (status == 'success'){
                        $('#ankboot_contact_msg').addClass('ankboot_green').html('تم الارسال بنجاح').fadeIn('slow',function(){
                            //close_ankboot_contact();
                        });
                        
                    }
                    
                },
            'xml');
        }
        
        return false;
        
    });
    
    $('#ankboot_close').live('click',function(){
        close_ankboot_contact ();
        return false;
    });
    

});


function ankboot_form_html (){
    
    var html = '<div id="ankboot_conatct_overlay"></div>';
    html += '<div id="ankboot_contact_form" class="ankboot_rounded"  style="display:none;background:#ffffff">';
    html += '<div id="ankboot_close"><img src="http://aljarallah.net/wp-content/plugins/ank_contact/js/../images/close.png"></div>';
    html += '<span id="ankboot_contact_msg" style="display:none;"></span>';
    html += '<form id="submit_ankboot_contact_form" action="" method="post">';
    html += '<div><label>الاسم:</label><input type="text"  name="name" id="name"></div>';
    html += '<div><label>الايميل:</label><input type="text" name="email" value=""></div>';
    html += '<div><label>الموضوع:</label><input type="text" name="subject"></div>';
    html += '<div><label>الرسالة:</label><textarea name="comments"></textarea></div>';
    html += '';
    //html += '<div><label>ما هو مجموع 1+1:</label><input type="text"></div>';
    html += '<div><button type="submit">أرسل</button></div>';
    html += '</fom>';
    html += '</div>';
    html += '';
    
    return html;
    
    
}

function display_ankboot_form(){
    
    
    $('body').append(ankboot_form_html());
    
    //alert($('#ankboot_contact_overlay').html());
    
    
    $('#ankboot_conatct_overlay').ankboot_overlay();
    
    //animate form contact
    
    
    //animate one
    $('#ankboot_contact_form').ankboot_contact_center().animate({
    height: 'toggle'
    }, 500, function() {
      $('#ankboot_close').fadeIn();
    });

    

    
    //end animation
    
    $('#ankboot_conatct_overlay').click(function(){
        close_ankboot_contact();
    });
    
    ankboot_ini_css();
    

}


function ankboot_ini_css (){
    $('#ankboot_contact_form').css('backgroundColor', '#ffffff');
    $('#ankboot_contact_form').css('borderColor', '#cccccc');
    $('#ankboot_contact_form button').css('backgroundColor', '#cccccc');
    $('#ankboot_contact_form label').css('color', '#000000');
}


function close_ankboot_contact (){
    
    var $this = $('#ankboot_conatct_overlay');
        $('#ankboot_contact_form').fadeOut(function(){
            $this.fadeOut('fast',function(){
                $(this).remove();
            });
            
            $(this).remove();
        });
    
}

jQuery.fn.ankboot_contact_center = function () {
    this.css("position","absolute");
    //this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("top",'75px');
    
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    
    this.css("position","fixed");
    
    return this;
}


jQuery.fn.ankboot_overlay = function () {
    
    
    this.css({
        top: '0px',
        left: '0px',
        height: $(document).height() + 'px',
        width: $(document).width() + 'px',
        background: '#000',
        position:'absolute'
    });
    
    return this;
}








