function showMsgBox(type, msg, w, h) {
	$("#comm_msgbox").remove();
	var html = new Array();
	if ("alert" == type) {
		html.push("<div id=\"comm_msgbox\">")
		html.push("    <div class=\"ui-widget\">");
		html.push("        <div class=\"ui-state-error ui-corner-all\" style=\"padding: 0 .7em;\">");
		html.push("            <p><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: .3em;\"></span>");
		html.push("            <strong>警告：</strong>"+msg+"</p>");
		html.push("        </div>");
		html.push("    </div>");
		html.push("</div>");
	} else {
		html.push("<div id=\"comm_msgbox\">")
		html.push("    <div class=\"ui-widget\">");
		html.push("        <div class=\"ui-state-highlight ui-corner-all\" style=\"margin-top: 20px; padding: 0 .7em;\">");
		html.push("            <p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: .3em;\"></span>");
		html.push("            <strong>提示：</strong>"+msg+"</p>");
		html.push("        </div>");
		html.push("    </div>");
		html.push("</div>");
	}
	$("body").append(html.join(''));
	var opt = {
	        autoOpen: true,
	        width: w ? w : 350,
	        buttons: {
	            "关闭": function() {
	                $(this).dialog("close"); 
	            }
	        }
	    };
	if (h) {
		opt = {
		        autoOpen: true,
		        width: w ? w : 350,
		        height: h,
		        buttons: {
		            "关闭": function() {
		                $(this).dialog("close"); 
		            }
		        }
		    }
	}
	$('#comm_msgbox').dialog(opt);
}

function showPopPage(w, h, divwin) {
	var minTop = 80;	//弹出的DIV记顶部的最小距离
	var win = divwin ? divwin : "divWindow";
	var divW = w ? w : 580;	//DIV宽度
	var divH = h ? h : 500;	//DIV高度
	var clientH = $(window).height();	//浏览器高度
	var clientW = $(window).width();	//浏览器宽度
	var div_X = (clientW - divW)/2;	//DIV横坐标
	var div_Y = (clientH - divH)/2;	//DIV纵坐标
	div_X += window.document.documentElement.scrollLeft;	//DIV显示的实际横坐标
	div_Y += window.document.documentElement.scrollTop;	//DIV显示的实际纵坐标
	if(div_Y < minTop){
		div_Y = minTop;
	}
	$("#"+win).css("position","absolute");
	$("#"+win).css("z-index","10");
	$("#"+win).css("left",(div_X + "px"));	//定位DIV的横坐标
	$("#"+win).css("top",(div_Y + "px"));	//定位DIV的纵坐标
	$("#"+win).width(divW);
	$("#"+win).height(divH);
	
	$("#divLock").remove();
	$("body").append("<div id='divLock'></div>")	//增加DIV
	//$("#divLock").height(clientH);
	//$("#divLock").width(clientW);
	$("#divLock").height("100%");
	$("#divLock").width("100%");
	$("#divLock").css("display","block");
	$("#divLock").css("background-color","#000000");
	$("#divLock").css("position","fixed");
	$("#divLock").css("z-index","5");
	$("#divLock").css("top","0px");
	$("#divLock").css("left","0px");
	$("#divLock").css("opacity","0.5");
		
	$("#"+win).show();
}

function closepop(divwin) {
	var win = divwin ? divwin : "divWindow";
	$("#"+win).hide();
	$("#divLock").hide();
}

var intervalID;
var ajaxerrorsec = 10;
$(document).ajaxError(
    function(e, xhr, settings, exception) {
      	if (xhr["status"] == 900) { //session 过期
            showMsgBox("alert", "您的操作时间过长，Session已失效，<br/><span id=\"ajaxErrorSecDiv\">10</span> 秒后，自动跳转到登录页面。");
            intervalID = window.setInterval(gotoStart, 1000);
        }
    }
);

$(document).ajaxSend(
	function() {
		showAjaxWin();
	}
);

$(document).ajaxComplete(
	function(event,request, settings){
	   hideAjaxWin();
	}
);

function showAjaxWin() {
	$("#comm_ajaxwin").remove();
	var html = new Array();
	html.push("<div id=\"comm_ajaxwin\">")
	html.push("    <div class=\"ui-widget\">");
	html.push("        <div class=\"ui-state-highlight ui-corner-all\" style=\"margin-top: 20px; padding: 0 .7em;\">");
	html.push("            <p><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: .3em;\"></span>");
	html.push("            <strong>Info：</strong><img src=\"static/img/001.gif\"/>&nbsp;数据处理中，处理结束会自动关闭此窗口，请耐心等待...</p>");
	html.push("        </div>");
	html.push("    </div>");
	html.push("</div>");

	$("body").append(html.join(''));
	$('#comm_ajaxwin').dialog({
        autoOpen: true,
        width: 550,
        modal: true
    });
}
function hideAjaxWin() {
	$('#comm_ajaxwin').dialog("close");
}

function gotoStart() {
	ajaxerrorsec = ajaxerrorsec - 1;
	$("#ajaxErrorSecDiv").html(ajaxerrorsec);
	if (ajaxerrorsec == 0) {
		clearInterval(intervalID);
		ajaxerrorsec = 10;
		top.location.href = "login";
	}
}

function switchdiv(id1, id2) {
	$("#"+id2).hide();
	$("#"+id1).show();
}

function editMapVer(hardcode) {
	$.post("mapup",
			{"atn":"getmapverlist", "hardcode":hardcode},
            function(json) {
                if ("1" == json.result) {
                	openEditMapVerWin(json.verlist, hardcode);
                } else {
                    showMsgBox("alert", json.msg);
                }
            }, "json"
    );
}

function openEditMapVerWin(verlist, hardcode) {
	$("#comm_editmapverwin").remove();
	var html = new Array();
	html.push("<div id=\"comm_editmapverwin\">")
	html.push("    <table>");
	html.push("        <tr>");
	html.push("            <td>选择当前地图版本：</td>");
	html.push("            <td><select id=\"mapVerWinSel\">");
	for (var i=0; i<verlist.length;i++) {
		map = verlist[i];
		html.push("            <option value=\""+map.mapid+"\">"+map.mapver+"</option>");
	}
	html.push("			   </select></td>");
	html.push("        </tr>");
	html.push("    </table>");
	html.push("</div>");

	$("body").append(html.join(''));
	$('#comm_editmapverwin').dialog({
        autoOpen: true,
        width: 350,
        buttons: [
                   {
                	   text:"确定",
                	   click: function() { 
                		   	      var mapid = $("#mapVerWinSel").val();
                		   	      var ver = $("#mapVerWinSel option:selected").text();
                		   	      $.post("mapup",
                		   	              {"atn":"editmapver", "hardcode":hardcode, "mapid":mapid, "curmapver":ver},
                		   	              function(json) {
                		   	            	  if ("1" == json.result) {
                		   	            		  $("#curmapver_span").html(ver);
                		   	            	  } else {
                		   	            		  showMsgBox("alert", json.msg);
                		   	            	  }
                		   	            	$("#comm_editmapverwin").dialog("close");
                		               }, "json"
                		   	      );
                		   		  
                		   	  }
                   },
                   {
                	   text:"取消",
                	   click: function() { $(this).dialog("close"); }
                   }
                 ]
    });
}

function showDeliver(path, deliverid) {
	$.post(path+"/mapup",
            {"atn":"getdiliverinfo", "deliverid":deliverid},
            function(json) {
                if ("1" == json.result) {
                	var info = json.info;
                    var html = new Array();
                    html.push("<tr bgcolor=\"#FFFFFF\">");
                    html.push("<td id=\"tt03\">");
                    html.push("    <table width=\"100%\" bgcolor=\"#94c2ef\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
                    html.push("        <tr bgcolor=\"#FFFFFF\">");
                    html.push("            <td height=\"25\" bgcolor=\"#d4e9f7\" id=\"tt02\">申请时间</td>");
                    html.push("            <td id=\"tt02\" bgcolor=\"#d4e9f7\">当前状态</td>");
                    html.push("            <td id=\"tt02\" bgcolor=\"#d4e9f7\">最后处理时间</td>");
                    html.push("        </tr>");
                    html.push("        <tr bgcolor=\"#FFFFFF\">");
                    html.push("            <td width=\"150\" id=\"tt02\">"+info.getmapdate+"</td>");
                    html.push("            <td width=\"190\" id=\"tt02\">"+info.type+"</td>");
                    html.push("            <td width=\"180\" id=\"tt02\">"+info.rupd+"</td>");
                    html.push("        </tr>");
                    html.push("        <tr bgcolor=\"#FFFFFF\">");
                    html.push("            <td bgcolor=\"#d4e9f7\" id=\"tt02\">收件地址</td>");
                    html.push("            <td colspan=\"2\" id=\"tt02\">"+info.address+"</td>");
                    html.push("        </tr>");
                    html.push("    </table>");
                    html.push("</td>");
                    html.push("</tr>");
                	    
                    $("#getmaptable").append(html.join(''));
                    $("#showdeliverspan").html("");              
                } else {
                    showMsgBox("alert", json.msg);
                }
            }, "json"
    );
}

function getValue(value, def) {
	if (value == null || value == undefined) {
		return def;
	}
	return value;
}
