var Util = new function() {
	this.checkTextCharA=function(text){
		  // 字数超出,返回负数
		  var iLen=0;
          var v = text;
          var maxNum = 140;
          var lv= maxNum;
     
          for (i = 0; i < v.length; i++){
              iLen += /[^\x00-\xff]/g.test(v.charAt(i)) ? 1 : 1;
              lv=(maxNum - Math.floor(iLen));
         } 
          
          lv = ((lv>0)?lv:-1*(Math.floor(iLen)-maxNum));
          
			return lv;
	},
	
	this.GA = function(callback, url) {
		$.ajax( {
			url : url,
			dataType : 'html',
			cache : false,
			success : function(data) {
				callback(data);
			},
			error : function(xhr, statusText, err) {
				alert(decodeURI(xhr.statusText));
			}
		});
	}
	this.load = function(divName, url) {
		$.ajax( {
			url : url,
			dataType : 'html',
			cache : false,
			success : function(data) {
				
				if (divName) {
					$('#' + divName).html(data);
				}
			},
			error : function(xhr, statusText, err) {
			}
		});
	}
	this.searchTest = function(form, divName, url) {
		url += "?" + $("#" + form).formSerialize();
		$.ajax( {
			url : url,
			dataType : 'html',
			cache : false,
			success : function(data) {
				if (divName) {
					$('#' + divName).html(data);
				}
			},
			error : function(xhr, statusText, err) {
				alert(decodeURI(xhr.statusText));
			}
		});
	}
	this.submit = function(form, url) {
		url += "?" + $("#" + form).formSerialize();
		$.ajax( {
			url : url,
			dataType : 'html',
			cache : false,
			success : function(data) {
				alert("操作成功");
			},
			error : function(xhr, statusText, err) {
				alert(decodeURI(xhr.statusText));
			}
		});
	}
	this.funcSubmit = function(callback, form, url) {
		url += "?" + $("#" + form).formSerialize();
		$.ajax( {
			url : url,
			dataType : 'html',
			cache : false,
			success : function(data) {
				alert("操作成功");
				callback();
				Util.closeEdit();
			},
			error : function(xhr, statusText, err) {
				alert(decodeURI(xhr.statusText));
			}
		});
	}
	this.funcLoad = function(callback, divName, url) {
		$.ajax( {
			type : 'POST',
			url : url,
			contentType : "application/html; charset=utf-8",
			dataType : "html",
			cache : false,
			success : function(data) {
				alert(data);
				callback(divName, data);
				var Htop = $("#" + divName).offset().top;
				$(document).scrollTop(Htop - 100);
			},
			error : function(xhr, statusText, err) {
				alert(decodeURI(xhr.statusText));
			}
		});
	}
	this.funcLoadByMsg = function(callback, divName, url) {
		$.ajax( {
			url : url,
			dataType : 'html',
			cache : false,
			success : function(data) {
				Dialog.alert("操作成功", callback(divName, data));
			},
			error : function(xhr, statusText, err) {
				Dialog.alert("操作失败", alert(decodeURI(xhr.statusText)));
			}
		});
	}
	this.sumbitAndLoad = function(div, url, form, show) {
		url += "?" + $("#" + form).formSerialize();
		Util.funcLoad(Util.divInfoList, div, url);
		if (show)
			alert("发布成功！");
		Util.closeEdit();
	}
	this.pageSumbit = function(url, form, page) {
		if (form) {
			if (url.indexOf("?") != -1) {
				url += "&" + $("#" + form).formSerialize() + "&pageNumber="
						+ page;
			} else {
				url += "?" + $("#" + form).formSerialize() + "&pageNumber="
						+ page;
			}
		} else {
			if (url.indexOf("?") != -1) {
				url += "&pageNumber=" + page;
			} else {
				url += "?pageNumber=" + page;
			}
		}
		location.href = url;
	}
	this.pageJumpSumbit = function(url, form) {
		var jumpPage = $("#num").val();
		Util.pageSumbit(url, form, jumpPage);
	}
	this.pageSumbitAndLoad = function(div, url, form, page) {
		if (form) {
			if (url.indexOf("?") != -1) {
				url += "&" + $("#" + form).formSerialize() + "&pageNumber="
						+ page;
			} else {
				
				url += "?" + $("#" + form).formSerialize() + "&pageNumber="
						+ page;
				
			}
		} else {
			if (url.indexOf("?") != -1) {
				url += "&pageNumber=" + page;
			} else {
				url += "?pageNumber=" + page;
			}
		}
		Util.funcLoad(Util.divInfoList, div, encodeURI(url));
	}
	this.pageSumbitAndLoadByMsg = function(div, url, form, page) {
		if (form) {
			if (url.indexOf("?") != -1) {
				url += "&" + $("#" + form).formSerialize() + "&pageNumber="
						+ page;
			} else {
				
				
				url += "?" + $("#" + form).formSerialize() + "&pageNumber="
						+ page;
				
				
			}
		} else {
			if (url.indexOf("?") != -1) {
				url += "&pageNumber=" + page;
			} else {
				url += "?pageNumber=" + page;
			}
		}
		Util.funcLoadByMsg(Util.divInfoList, div, url);
	}
	this.pageJumpSumbitAndLoad = function(div, url, form) {
		var jumpPage = $("#num").val();
		if (form) {
			if (url.indexOf("?") != -1) {
				url += "&" + $("#" + form).formSerialize() + "&pageNumber="
						+ jumpPage;
			} else {
				url += "?" + $("#" + form).formSerialize() + "&pageNumber="
						+ jumpPage;
			}
		} else {
			if (url.indexOf("?") != -1) {
				url += "&pageNumber=" + jumpPage;
			} else {
				url += "?pageNumber=" + jumpPage;
			}
		}
		Util.funcLoad(Util.divInfoList, div, url);
	}
	this.divInfoList = function(divName, data) {
		if (divName) {
			$('#' + divName).html(data);
		}
	}
	this.openEdit = function(url) {
		$('body').append('<div id="editDiv" class="white_content"></div>');
		$('body').append('<div id="editFade" class="black_overlay"></div>');
		var mybg = document.getElementById('editFade'), fullScreenH = document.documentElement.clientHeight;
		fullScreenW = document.documentElement.clientWidth;
		mybg.style.display = 'block';
		mybg.style.height = fullScreenH + "px";
		mybg.style.width = fullScreenW + "px";
		Util.load("editDiv", url);
		$("#editFade").show();
		$("#editDiv").show();
	}
	this.closeEdit = function() {
		$("#editDiv").remove();
		$("#editFade").remove();
	}
	this.dialogResultDiv = function(dialogResult) {
		if (dialogResult != null && dialogResult != '') {
			$("#drDiv").fadeOut(3000);
		}
	}
	this.dialogResultTimeout = function() {
		$("#drDiv").attr("style", 'display: none');
	}
	this.divInfoList = function(divName, data) {
		if (divName) {
			$('#' + divName).html(data);
		}
	}

	this.share = function(uid, title, url, webid) {
		if(webid=='sina'){
			var openUrl = 'http://v.t.sina.com.cn/share/share.php?title='+ title +'&url='+url+'&appkey=3086495442';
			window.open(openUrl);			
		}else{
			var openUrl = 'http://v.t.qq.com/share/share.php?title='+title+'&url='+url;
			window.open(openUrl);
		}
	}
	
	this.sendMail = function(url, email) {
		$.dialog( {
			content : "<input type='text' id='input_email' value='" + email
					+ "'/>",
			lock : true,
			title : "输入邮箱",
			button : [ {
				name : "发送",
				callback : function() {
					$("#email").val($("#input_email").val());
					Util.send(url + '&email=' + $("#email").val());
				}
			}, {
				name : "取消",
				callback : function() {
					Util.closeEdit();
				}
			} ]
		});
	}
	this.send = function(url) {
		if ($("#email").val() != '') {
			jQuery.post(url, function(data) {
				var obj = eval('(' + data + ')');
				if (obj['code'] == 'true') {
					alert('发送成功！');
				} else {
					alert('发送失败！');
				}
			}, "html");
		} else {
			alert('请输入邮箱地址!');
		}
		Util.closeEdit();
	}
	this.downloadmap = function(url, id, sn) {
		var newwin = window.open(url + "/mapdownload/" + sn);
	}
	this.smapd = function(url, id, sn) {
	}
}
function templateSetFlash() {
	thisMovie("weyooMap").setFlashRootURL("http://www.weyoo.cn/");
}

function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return document.getElementsByName(movieName)[0];
	 } else {
		 return document.getElementsByName("weyooMap")[0];
	 }
}