var SysPet = $.fn.extend({
	
	evtSubmitForm: function(paramForm) 
	{
	
		$('#' + paramForm).submit();
	},
	
	evtChangeBackGroundColor: function(paramObject, paramColor)
	{		
		$(paramObject).attr('bgcolor-before', $(paramObject).css('background-color'));
		$(paramObject).css('background-color', paramColor);
	},
	
	redirect : function (url)
	{
		window.location = url;
	},
	
	GetAppendRegisterSelect: function(paramObject, paramText, paramValue)
	{
		var options = $(paramObject).attr('options');
		options[options.length] = new Option(paramText, paramValue, true, true);
	},
	
	confirmation : function(paramTitle, paramMessage, paramUrl)
	{
		Ext.MessageBox.show({
		   title: paramTitle,
		   msg: paramMessage,
		   width: 300,
		   buttons: Ext.MessageBox.OKCANCEL,
		   icon: Ext.MessageBox.QUESTION,
		   fn: function(paramButton)
		   { 
				if (paramButton == 'ok')
				{
					SysPet.redirect(paramUrl);
				}
		   }
		});
	},
	
	tooltip : function(divName,divHtml){
		
		
		Ext.QuickTips.init();
		
		new Ext.ToolTip({
			 target: divName,
			 html: divHtml,
			 trackMouse: true
			 });
		
	},
	
	window : function(paramInstance, paramUrl, paramWidth, paramHeight)
	{
		var winPanel = Ext.getCmp(paramInstance);
		
		if(!winPanel)
		{
			winPanel = new Ext.Window({
				title: '', 
				id: paramInstance,
				autoHeight: false,
				autoWidth: false,
				height: paramHeight, //540
				width: paramWidth, //865
				resizable: true,
				closable: true,
				modal: true,
				html: '<iframe class=" " style="width: '+ (paramWidth - 15) +'px; height: '+ (paramHeight - 10) +'px;" src="'+ paramUrl +'"></iframe>'
			});
		}

		winPanel.show();
	}	
});

jQuery.fn.limitMaxlength = function(options) {

	var settings = jQuery.extend({
		attribute: "maxlength",
		onLimit: function() {},
		onEdit: function() {}
	}, options);

	// Event handler to limit the textarea
	var onEdit = function() {
		var textarea = jQuery(this);
		var maxlength = parseInt(textarea.attr(settings.attribute));

		if(textarea.val().length > maxlength){
			textarea.val(textarea.val().substr(0, maxlength));

			// Call the onlimit handler within the scope of the textarea
			jQuery.proxy(settings.onLimit, this)();
		}

		// Call the onEdit handler within the scope of the textarea
		jQuery.proxy(settings.onEdit, this)(maxlength - textarea.val().length);
	}

	this.each(onEdit);

	return this.keyup(onEdit)
				.keydown(onEdit)
				.focus(onEdit)
				.live('input paste', onEdit);
};
