HFLibrary = {
	toolTipValue: '',
	
	toolTip: function(o,v)
	{
		HFLibrary.toolTipValue=v;
		o.mousemove(function (obj) {
			HFLibrary.toolTipShow(obj,HFLibrary.toolTipValue);
		});
		
		o.mouseout(function (obj) {
			HFLibrary.toolTipHide();
		});
	},
	toolTipShow: function(o,v)
	{
		$('body').append("<div class='HFtooltip'>"+v+"</div>");
		$('div.HFtooltip').css('position','absolute');
		$('div.HFtooltip').css('left',o.pageX+10);
		$('div.HFtooltip').css('top',o.pageY+10);
		$('div.HFtooltip').addClass('HFtooltip');
		$('div.HFtooltip').show();
	},
	toolTipHide: function()
	{
		$('div.HFtooltip').remove();
	},
	
	applyGridEditors: function() {
		$('.GridTextEditor').unbind();
		HFLibrary.toolTip($('.GridTextEditor'),'برای تغییر اطلاعات، کلیک کنید.');
		$('.GridTextEditor').click(function (obj) {
			if ((this.id.substring(0,6)!="INEDIT") && (this.id.substring(0,10)!="CANCELEDIT"))
			{
				var data=this.innerHTML;
				data=data.substring(6);
				this.innerHTML="<form method='post' action=''><input type='text' name='data' id='"+this.id+"' value='"+data+"'><br /><input type='submit' value='تایید' style='width: 50px'><input type='button' value='انصراف'  style='width: 50px' onclick=\"document.getElementById('INEDIT"+this.id+"').innerHTML='&nbsp;"+data+"';document.getElementById('INEDIT"+this.id+"').id='CANCELEDIT"+this.id+"'\"><input type='hidden' name='gridact' value='updatefield'><input type='hidden' name='olddata' value='"+data+"'><input type='hidden' name='field' value='"+this.id+"'></form>";
				this.id="INEDIT"+this.id;
			}else if(this.id.substring(0,10)=="CANCELEDIT") {
				this.id=this.id.substring(10);
			}
		});
		
		for (var i=0;i<$('.GridBooleanEditor').length;i++)
		{
			var data=$($('.GridBooleanEditor')[i]).html();
			if (data=="false") {
				$($('.GridBooleanEditor')[i]).addClass('HFGridBooleanFalse');
			}else if (data=="true") {
				$($('.GridBooleanEditor')[i]).addClass('HFGridBooleanTrue');
			}
			$($('.GridBooleanEditor')[i]).empty();
		}
		$('.GridBooleanEditor').unbind();
		$('.GridBooleanEditor').mouseup(function (obj) {
			var oldData="";
			var newData="";
			if ($(this).hasClass('HFGridBooleanFalse')) {
				oldData="false";
				newData="true";
			}else if ($(this).hasClass('HFGridBooleanTrue')) {
				oldData="true";
				newData="false";
			}
			var params="gridact=updatefield&olddata="+oldData+"&data="+newData+"&field="+this.id;
			$(this).removeClass('HFGridBooleanTrue');
			$(this).removeClass('HFGridBooleanFalse');
			$(this).addClass('HFLoading');
			PROGRAM.serverCall("","",params,function (r) {
				$('div.app').empty();
				$('div.app').append(r);
			});
		});
	}
}
