(function(){
        $.extend($.fn,{
            mask: function(msg,maskDivClass,opacityValue){
                this.unmask();
                // 参数
				if (!opacityValue)
				{
					opacityValue="0.8";
				}
                var op = {
                    opacity: opacityValue,
                    z: 10000,
                    bgcolor: '#ccc'
                };
                var original=$(document.body);
                var position={top:0,left:0};
                            if(this[0] && this[0]!==window.document){
                                original=this;
                                position=original.position();
                            }
                // 创建一个 Mask 层，追加到对象中
                var maskWidth=original.outerWidth();
                if(!maskWidth){
                    maskWidth=original.width();
                }
                var maskHeight=original.outerHeight();
                if(!maskHeight){
                    maskHeight=original.height();
                }
				var maskDiv=$('<div class="maskdivgen">&nbsp;</div>');
                maskDiv.appendTo(original);
                maskDiv.css({
                    position: 'absolute',
                    top: position.top,
                    left: position.left,
                    'z-index': op.z,
                  width: maskWidth,
                    height:maskHeight,
                    'background-color': op.bgcolor,
                    opacity: 0
                });
                if(maskDivClass){
                    maskDiv.addClass(maskDivClass);
                }
                if(msg){
                    var msgDiv=$('<div style="position:absolute;border:#6593cf 1px solid; padding:2px;background:#ccca"><div style="line-height:24px;border:#a3bad9 1px solid;background:white;padding:2px 10px 2px 10px">'+msg+'</div></div>');
                    msgDiv.appendTo(maskDiv);
                    var widthspace=(maskDiv.width()-msgDiv.width());
                    var heightspace=(maskDiv.height()-msgDiv.height());
                    msgDiv.css({
                                cursor:'wait',
                                top:(heightspace/2-2),
                                left:(widthspace/2-2)
                      });
                  }
                  maskDiv.fadeIn('fast', function(){
                    // 淡入淡出效果
                    $(this).fadeTo('fast', op.opacity);
                })
                return maskDiv;
            },
         unmask: function(){
                     var original=$(document.body);
                         if(this[0] && this[0]!==window.document){
                            original=$(this[0]);
                      }
                      original.find("> div.maskdivgen").fadeOut('fast',0,function(){
                          $(this).remove();
                      });
            }
        });
    })();

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

String.prototype.Trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }
String.prototype.LTrim = function() { return this.replace(/(^\s*)/g, ""); }
String.prototype.RTrim = function() { return this.replace(/(\s*$)/g, ""); }

function addBookmark(title,url)
{
	if (window.sidebar)
	{ 
		window.sidebar.addPanel(title, url,""); 
	}
	else if( document.all )
		{
			window.external.AddFavorite( url, title);
		}
		else if( window.opera && window.print )
			{
			return true;
			}
}

function EmailAddressVerify(Email)
{
	var CheckResult=false;
	$.ajax({
		type: "POST",
		url:"/Ajax.InputValueVerify.php" + "?querytime=" + new Date().getTime(),
		dataType: "html",
		async: false,
		data: "ValueType=EmailVerify&InputValue="+Email,
		success: function(data) {
			if (data == true)
			{
				CheckResult=true;
			}
		},
		error: function(data) {
			alert("Email address verify error, Please try again later!");
		}
	});
	return CheckResult;
}

var NowMenuTagID="";
function ShowSubMenu(MenuTarget)
{
	if (NowMenuTagID=="")
	{
		$('#SubMenu_'+MenuTarget).show();
	}
	else
	{
		$('#SubMenu_'+NowMenuTagID).hide();
		$('#SubMenu_'+MenuTarget).show();
	}
	NowMenuTagID=MenuTarget;
}

function HideSubMenu(MenuTarget)
{
	NowMenuTagID="";
	$('#SubMenu_'+MenuTarget).hide();	
}

function GetFormData(theForm)
{
	var eList=new Array();
	var eList_i=0;
	var query_string='';
	var and='';
	//alert(form_obj.length);
	for (i=0;i<theForm.length ;i++ )
	{
		e=theForm[i];
		allowAdd_eItem=true;
		for (j=0;j<eList.length ;j++ )
		{
			if (e.name==eList[j].name)
			{
				allowAdd_eItem=false;
			}
		}

		if (allowAdd_eItem)
		{
			eList[eList_i]=e;
			eList_i++;
		}
	}
	for (i=0;i<eList.length ;i++ )
	{
		element_value='';
		if (eList[i].type=='select-one')
		{
			element_value=eList[i].options[eList[i].selectedIndex].value;
		}
		else
		{
			if (eList[i].type=='checkbox' || eList[i].type=='radio')
			{
				for (j=0;j<theForm.length ;j++ )
				{
					if (theForm[j].name==eList[i].name)
					{
						if (theForm[j].checked!=false)
						{
							element_value=theForm[j].value;
						}
					}
				}
			}
			else
			{
				element_value=eList[i].value;
			}
		}
		query_string+=and+eList[i].name+'='+element_value.replace(/\&/g,"%26");
		and="&";
	}
	return query_string;
}
