//Função para validacao do conteudo do fckEditor
//Recebe em args.Value o o id da instÂncia do fckEditor
function ValidatetbTexto(source,args){
    var fckBody = FCKeditorAPI.GetInstance(args.Value);
    if (fckBody){
        args.IsValid = (fckBody.GetXHTML(true) != null && fckBody.GetXHTML(true) != "");
        return;
    }
    args.IsValid = false;
}

/*Método auxiliar para realizar um pedido ajax*/
function DoAjaxRequest(url, data, funcaoSucesso) {
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        contentType: "application/json",
        dataType: "json",
        async: false,
        cache: false,
        success: funcaoSucesso
    })
}

/* Função que faz um pedido ajax e obtem um obecto javascript da resposta (.NET Framework 2 onde a resposta vem em xml e os parametros devem ter o formato 'p1=0&p2=9'). */
function GetObjectFromAJAX (url, data) {

    var ret = null;
    
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        async: false,
        cache: false,
        success: function (response) {
            try {
                ret = jQuery.parseJSON($(response).children().eq(0).text());                        
            } catch(err) {
            
            }
        }
    });

    return ret;
};

var KeyPressHandler = new Object();
(function ($) {

	var keyCodes = {
		Enter: 13,
		Escape: 27
	};

	var enterKeyEventHandler = null;
	var escapeKeyEventHandler = null;

	var eventAttached = false;

	function AttachEvent() {

		$(document).keydown(function (e) {

			if (e.keyCode == keyCodes.Enter) {
				if (enterKeyEventHandler) {
					enterKeyEventHandler(e);
				}
				return false;
			}
			if (e.keyCode == keyCodes.Escape) {
				if (escapeKeyEventHandler) {
					escapeKeyEventHandler();
				}
				return false;
			}
		});
	}

	KeyPressHandler.SetEnterEventHandler = function (handler) {
		enterKeyEventHandler = handler;
		if (!eventAttached) {
			AttachEvent();
			eventAttached = true;
		}
	};

	KeyPressHandler.SetEscapeEventHandler = function (handler) {
		escapeKeyEventHandler = handler;
		if (!eventAttached) {
			AttachEvent();
			eventAttached = true;
		}
	};

})(jQuery);

