/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * @author naved
 * @date  27 Jul, 2010
 */
$(document).ready(function(){ 
    $(document).bind('click', function(e) {
        var $clicked = $(e.target);
        if (! $clicked.parents().hasClass("FeedbackBox") && $('#FeedbackBox > .boxTitle').hasClass("active")){
            $("#FeedbackBox > .boxContent").toggle("fast");
            $('#FeedbackBox > .boxTitle').toggleClass("active");
        }
    });

    $('#FeedbackBox > .boxTitle').click(function(){
    	$('#formFeedback')[0].reset();
       $('#feedbackSuccess').html('');    	
        $("#FeedbackBox > .boxContent").toggle("fast");
        $(this).toggleClass("active");
        return false;

    });

    lzFormOptions = {
        success:       responseHandle,
        url:       AJAX_URL,
        type:      'post',
        dataType:  'json'
    };

    $('#formFeedback').ajaxForm(lzFormOptions);


    function responseHandle(response, status, form, xhr){
        var successCode = response.action;

        var targetString = '#'+form.attr("data-parent")

        if (successCode == 3) {
            $("#FeedbackBox > .boxContent").delay(900).toggle("fast");
            $('#FeedbackBox > .boxTitle').toggleClass("active");
            $(targetString).html(response.html);
        }
        if (successCode == 2) {
            $(targetString).html(response.html);
        }
        return false;
    }

});

