
var DialogSendMessage = function( idDialog, oQ, idForm, arrFields ) {
	var _idForm = idForm;
	var _ref = this;
	var _arrFields = arrFields;
	
	var handleSubmit = function() {
  	this.sendForm();
	};
	
	var handleCancel = function() {
	  this.cancel();
	};
	
	
	DialogSendMessage.superclass.constructor.call(this, idDialog,{ width : "340px", fixedcenter : true, visible : false, constraintoviewport : true,
			buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true },
			{ text:"Cancel", handler:handleCancel } ]
		} );
	var kl_close = new YAHOO.util.KeyListener(document, {keys:27 },
												  { fn: this.hide,
														scope: this,
														correctScope:true }, "keyup" ); 
	
													
	
	this.render(document.body );
	
	this.show = function( ) {
  	hideBlock('imager');
    DialogSendMessage.superclass.show.call( _ref );
	}
	this.hide = function( ) {
		showBlock('imager');
    DialogSendMessage.superclass.hide.call( _ref );
	}
	
	this.sendForm = function() {
	  var formObject = document.getElementById( _idForm );
	  _ref.Success = function(o) {
	  	var jsonString = o.responseText;
	 		try {
	  		var obj = YAHOO.lang.JSON.parse( jsonString );
		  	if ( obj.type == 'complex' ){
					var status = 'error';
					if ( obj.status == 'error' ) { 
						status = Message.STATUS_ERR;
					}
					if ( obj.status == 'ok' ){
						status = Message.STATUS_OK;
						_ref.hide();
						formObject.reset()
					}
					oQ.add( new Message( status, obj.textMessage ) );
				}
	  	}
	  	catch( e ) {
	  		oQ.add( new Message( Message.STATUS_ERR, "Error while executing command: " + e + ';json: ' + jsonString ) );
	  	}
	    return true;
	  }
	
	  this.Failure = function(o) {
	    alert( 'Connection fail.' );
	  }
	
	  var response =
	  {
	    success: _ref.Success,
	    failure: _ref.Failure
	  }
	  
		var check = false;
	  try {
	  	aV = new FormValidator( _idForm, _arrFields );
	  	var check = aV.checkIsValid();
			if( check ) {
				var _stUrl = 'index.php?part='+part+'&subPart='+subPart+'&page='+page;
				YAHOO.util.Connect.setForm( formObject, false );
				var cObj = YAHOO.util.Connect.asyncRequest( 'POST', _stUrl, response );
			}
		}
		catch( e ) {
			 oQ.add( e );
		}	
	} 
   
}
YAHOO.lang.extend( DialogSendMessage, YAHOO.widget.Dialog );
