﻿
$(document).ready(function() {
    $(".inf :input, .modinf").click(function(e) {
        e.preventDefault();
        $.get("/_sysutils/modalrequest.aspx?i=" + $(this).attr("id") + "&ReqOrigId=" + $("#ModalReqOrigId").val() + "&vt=" + $(this).hasClass('vt'), function(data) {
            var iFirst = data.indexOf('PnlScripts') + 12;
            var iLasr = data.length - 13;
            var strScripts = data.substring(iFirst, iLasr);
            data = data.replace(strScripts, "");
            $(data).modal({
                close: false,
                overlayId: 'modFrmOverlay',
                containerId: 'modFrmCont',
                onOpen: contact.open,
                onShow: contact.show,
                onClose: contact.close
            });
            $("#PnlScripts").html(strScripts);
        });
    });
});
        
var contact = {
	message: null,
	open: function (dialog) {
		var title = $('#modFrmCont .tit').html();
		$('#modFrmCont .tit').html('Cargando...');
		dialog.overlay.fadeIn(200, function () {
			dialog.container.fadeIn(200, function () {
				dialog.data.fadeIn(200, function () {
				    $('#modFrmCont #form').fadeIn(200, function () {
					    $('#modFrmCont .tit').html(title);
				        $('#modFrmCont #name').focus();
				    });
				});
			});
		});
	},
	show: function (dialog) {
	    $('#modFrmCont #form :input').keydown(function(e){ 	
			if (e == null) keycode = event.keyCode; // ie
			else keycode = e.which; // mozilla
			if(keycode == 27) {
			    $('#modFrmCont .sbm .modalClose').click();
			    return false;
			}
			return true;
		});
	},
	close: function (dialog) {
		$('#modFrmCont #form').fadeOut(200);
		$('#modFrmCont .ctit').fadeOut(200);
		$('#closeModal').fadeOut(200);
		$('#modFrmCont #ic_sol').animate({
			height: 40
		}, function () {
			dialog.data.fadeOut(200, function () {
				dialog.container.fadeOut(200, function () {
					dialog.overlay.fadeOut(200, function () {
						$.modal.close();
					});
				});
			});
		});
	},
	error: function (xhr) {
		alert(xhr.statusText);
	}
};