function  showModuleWindow(url,width,height){
	width = (width==undefined)?450:width;
	height= (height==undefined)?480:height; 
	var returnValue=showModalDialog(url ,window,'dialogwidth:'+width+'px;dialogheight:'+height+'px;help:0;center:yes;resizable:0;status:0;scroll:yes');
	return returnValue;	
}

//加载�?�?
function startLoad(obj){
	var t=obj==undefined?document.body:obj;
	$(t).addClass("container");
	mask = document.createElement('div');
	$(mask).addClass("mask");
	$(mask).css("height",$(t).height());
	
	///$(mask).append("<center>正在�?索中，请稍后...</center>");
	$(t).append(mask);
	$(t+" .pgRefresh").addClass("pgLoad");	
}


//加载结束
function endLoad(obj){
	var t=obj==undefined?document.body:obj;
	$(t+" .pgRefresh").removeClass("pgLoad");
	$(mask).remove();
}

function searchData(url,page){	
	startLoad();
		    $tbody = $("#mytab tbody");
 			$.ajax({
			type:"post",
			url:url.lastIndexOf('?')>-1?(url+"&page="+page):(url+"?page="+page),
			data:$('#queryform').serialize(),
			dataType:"json",
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			success:function(data){  
				fileData($tbody,data);
				$(mask).remove();
			}
		});		
 }
 
 function getXMLInfo(url,edit){
 	startLoad(edit);
 		$tbody = $("#mytab tbody");
 		$.ajax({
			type:"post",
			url:url,
			data:$('#editform').serialize(),
			dataType:"xml",
			error:function(obj,errno){
				alert('信息加载错误！');
				$("#info_loading").html(errno);
			},
			success:function(data){		   
				endLoad(edit);
				displayXMLInfo(data);
			}
		});
 }
 
  function getUpdateInfo(url,edit){
 		startLoad(edit);
 		$tbody = $("#mytab tbody");
 		$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:url,
			//参数
			data:$('#editform').serialize(),
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				alert('信息加载错误！');
				$("#info_loading").html(errno);
			},
			//载入成功时，执行下面的函�?
			success:function(data){		   
				endLoad(edit);
				fillUpdateInfo(data);
			}
		});
 }
  function addGuild(url,edit){		
 		startLoad(edit);
 		$tbody = $("#mytab tbody");
 		$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:url+"?edit="+escape(escape(edit)),
			//参数
			data:$('#editform').serialize(),
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			//载入成功时，执行下面的函�?
			success:function(data){		
				
				endLoad(edit);
				successAction(data);
			}
		});
		
 }
 
 function add(url,edit){
 		startLoad(edit);
 		$tbody = $("#mytab tbody");
 		$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:url,
			//参数
			data:$('#editform').serialize(),
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				$("#info_loading").html(errno);
				errorAction();
			},
			//载入成功时，执行下面的函�?
			success:function(data){		   
				endLoad(edit);
				successAction(data);
			}
		});
 }
 
 function addObj(url,edit){
 	try{
 		var data=$('#editform').serialize();
 		confirmBegin();
 		$.ajax({
			type:"post",
			url:url,
			data:data,
			dataType:"json",
			error:function(obj,errno){
				alert(obj.responseText);
				confirmEnd();
			},
			success:function(data){
				confirmEnd();
				successAction(data);
			}
		});
	}catch(e){
		alert('页面脚本错误:'+e.description);
	}	
 }
 /*
  * @param url 操作连接地址
  * @param edit 查询数据的formid
  */
 function update(url,edit){
 	try{
	 	var data =$('#'+edit).serialize();
	 	confirmBegin();
		$.ajax({
			type:"post",
			url:url,
			data:data,
			dataType:"json",
			error:function(obj,errno){
				$("#info_loading").html(errno);
				errorAction();
			},
			success:function(data){	  
				confirmEnd();
				successAction(data);
			}
		});
	 }catch(e){
	 	alert('页面脚本错误:'+e.description);
	 }
 }
 
 function del(url,edit){
 	if(!confirm('你将要删除信息，请再次确认！'))
 	return false;
 	edit=edit==undefined?$(document.body):edit;
	startLoad(edit);
	$.ajax({
		//type指示是get还是post
		type:"post",
		//目标文件
		url:url,
		//返回的数据类�?
		dataType:"json",
		//载入发生错误时，显示错误信息
		error:function(obj,errno){
			$("#info_loading").html(errno);
		},
		//载入成功时，执行下面的函�?
		success:function(data){		   
			endLoad(edit);
			deletSuccessAction(data);
		}
	});
 }
 
 //验证用户ID是否合法
 function checkUserName(userName){
 	startLoad($('#display'));
 			$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:'editUsers!checkUsers.action?userName='+userName,
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			//载入成功时，执行下面的函�?
			success:function(data){		   
				endLoad($('#display'));
				$('#display').html(data.message);
			}
		});
 }
 //验证公会名是否存�?
 function checkGuildName(guildName){
 	
 	
 	startLoad($('#display'));
 			$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:'editGuild!checkGuildName.action?guildName='+guildName,
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			//载入成功时，执行下面的函�?
			success:function(data){		   
				endLoad($('#display'));
				$('#display').html(data.message);
			}
		});
	
		//alert('hehe');
 }
 //推荐信息
 function commendInfo(url,param){
 	 	startLoad();
 		$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:url,
			data:param,
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			//载入成功时，执行下面的函�?
			success:function(data){		   
				endLoad();
				commendSuccess(data);
			}
		});
 }
 
 function getServerPath(){
	var serv=window.location;
	var port=serv.port==""?serv.port:":"+serv.port;
	return serv.protocol+"//"+serv.hostname+port;
 }
 
function ajaxFileUpload(uploadfile)
{
	$("#loading")
	.ajaxStart(function(){
		$(this).show();
	})
	.ajaxComplete(function(){
		$(this).hide();
	});
	
	$.ajaxFileUpload
	(
		{
			url:getServerPath()+'/sysUploadFile.action',
			secureuri:false,
			fileElementId:'file',
			dataType: 'json',
			success: function (data, status)
			{
				alert('success'+data);
			},
			error: function (data, status, e)
			{
				alert('error'+e);
			}
		}
	)
	
	return false;

}

 function QueryString(fieldName)
    {  
      var urlString = document.location.search;
      if(urlString != null)
      {
           var typeQu = fieldName+"=";
           var urlEnd = urlString.indexOf(typeQu);
           if(urlEnd != -1)
           {
                var paramsUrl = urlString.substring(urlEnd+typeQu.length);
                var isEnd =  paramsUrl.indexOf('&');
                if(isEnd != -1)
                {
                     return paramsUrl.substring(0, isEnd);
                }
                else
                {
                    return paramsUrl;
                }
           }
           else 
           {
                return null;
           }
      }
     else
     {
        return null;
     }
    }

 function getUserFunction(){
 	$.ajax({
			type:"post",
			url:'login!getUserFunctionXML.action',
			dataType:"xml",
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			success:function(data){
				writeFunctionHtml(data);
				successXMLAction(data);	
			}
		});
 }
 
 function selectGuild(item,value){ 	
 		startLoad($('#display'));
 			$.ajax({
			//type指示是get还是post
			type:"post",
			//目标文件
			url:'editGuild!selectGuildData.action?item='+escape(escape(item))+'&value='+escape(escape(value)),
			//参数
			data:$('#queryform').serialize(),
			//返回的数据类�?
			dataType:"json",
			//载入发生错误时，显示错误信息
			error:function(obj,errno){
				$("#info_loading").html(errno);
			},
			//载入成功时，执行下面的函�?
			success:function(data){	
				fileData($tbody,data);				
				//$(mask).remove(); 
				
			}
		});	
 }
 
 /*
  * 操作数据开始提示给你用户显示的信息
  */
function confirmBegin(){
	$('<div id="wrapper" style="display:none"><div id="mid"><div id="box" class="boxstyle"></div></div></div>').appendTo(document.body);
	$('#wrapper').fadeIn('slow');
	$(':input').each(function(){
		$(this).attr('disabled','disabled');
	});	
	$(document.body).attr('disabled','disabled');
} 

function confirmEnd(){
	$('#wrapper').fadeOut('slow');
	$(':input').each(function(){
		$(this).attr('disabled','');
	});	
	$(document.body).attr('disabled','');
}

function deletSuccessAction(data){
	alert(data.message);
}

function successAction(data){
	alert(data.message);
}

function successXMLAction(data){
}

function writeFunctionHtml(data){
	$(data).find("USERFUNCTION").find("FUNCTION").each(function(){
		for(var i=0;i<functionids.length;i++){
			if($(this).find("FUNCTIONCODE").text()===functionids[i]){
				$($(this).find("FUNCTIONHTML").text()).appendTo('#funbut');
			}
		}
	});	
}

(function($){
   	$.openWindow = function(options){    			
	        var defaults = {
	                title:"信息提示",                           //标题
	                content:"",                       //显示内容
	                loadUrl:"",                              //调用url
	                bColor:"#777",                           //背景色
	                bWidth:document.body.clientWidth+"px",   //背景宽度
	                bHeight:document.body.clientHeight+"px", //背景高度
	                oColor:"#FFF",                           //弹出窗口颜色
	                oWidth:400,                              //弹出窗口宽度
	                oHeight:250                              //弹出窗口高度
	        };
	        $.extend(defaults,options);
	
	        //绑定div到body
	        var cbtn = "<div id='cbtn'><img src='http://mobile.qq.com:8080/web_mobile/images/close_x.gif'/>"+defaults.title+"</div><div>";
	        var odiv = "<div id='odiv'>"+cbtn+"<div id='content'>loading...</div></div>";
	        var bdiv = "<div id='bdiv'></div>";
	        if(!($("#bdiv").length))$("body").append(bdiv);
	        if(!($("#odiv").length))$("body").append(odiv);
	        defaults.loadUrl ? $("#content").load(defaults.loadUrl) : $("#content").html(defaults.content);
	
	        //CSS
	        $("#cbtn>img").css({"cursor":"pointer","float":"right"}).click(function(){$("#bdiv").remove();$("#odiv").remove();});
	        $("#cbtn").css({"font-size":"12px","background":"#F2F3F7","color":"#777","padding":"5px 5px"});
	        $("#content").css({"font-size":"14px","padding":"10px 10px","overflow-x":"hidden","overflow-y":"auto","width":defaults.oWidth+"px","height":defaults.oHeight+"px"});
	        $("#odiv").css({"background":defaults.oColor,"width":defaults.oWidth+"px","border":"1px black solid","z-index":"9999","position":"absolute","top":"150px","left":(document.body.clientWidth-defaults.oWidth)/2+"px"});
	        $("#bdiv").css({"background":defaults.bColor,"width":defaults.bWidth,"height":defaults.bHeight,"z-index":"9998","position":"absolute","filter":"alpha(opacity:90)","left":0,"top":0});
	};
})(jQuery);

Date.prototype.format = function(format) //author: meizz 
{ 
		var o = { 
		"M+" : this.getMonth()+1, //month 
		"d+" : this.getDate(), //day 
		"h+" : this.getHours(), //hour 
		"m+" : this.getMinutes(), //minute 
		"s+" : this.getSeconds(), //second 
		"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
		"S" : this.getMilliseconds() //millisecond 
		} 
		if(/(y+)/.test(format)) format=format.replace(RegExp.$1, 
		(this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
		for(var k in o)if(new RegExp("("+ k +")").test(format)) 
		format = format.replace(RegExp.$1, 
		RegExp.$1.length==1 ? o[k] : 
		("00"+ o[k]).substr((""+ o[k]).length)); 
		return format; 
 } 
