$(document).ready(function(){
    
    var responseFormOptions = {  
    	beforeSubmit:  responseRequest,      
        success:       responseResponse
    } 
      
    $('#responseForm').submit(function() { 
        $(this).ajaxSubmit(responseFormOptions); 
        return false; 
    }); 
    
    $('#addResponse').click(function(){	
    	$('#responseBox .boxSuccessMessage').hide();
        $('#responseBox .boxErrorMessage').hide();
        $('#responseForm').resetForm();	                
		new Boxy($('#responseBox'), {title: Chiptop.TXT_ADD_RESPONSE }); 
		alignToCenterDialogs();       
    });
    
});


/* Events Listeners */

function responseRequest(formData, jqForm, options) {     
    $('#responseBox .boxSuccessMessage').hide();
    $('#responseBox .boxErrorMessage').hide();
    $('#responseBox .boxWaitMessage').show();    
    return true;
}

function responseResponse(responseText, statusText)  { 
    $('#responseBox .boxWaitMessage').hide();
    eval("var response = "+responseText+";");
    if(response.error == "0")
    {
        $('#responseBox .boxSuccessMessage').html(response.message).show();
        $('#responseForm').resetForm();
    }
    else
    {
        $('#responseBox .boxErrorMessage').html(response.message).show(); 
    }
}