function GetContextPath() {
	var ContextPath = window.location.pathname;
	var p = ContextPath.indexOf("/", 1);
	if (p == -1) return "";
	return ContextPath.substring(0, p);
}
var ContextPath = "";

var filesadded = "" //list of files already added
$Load=function(filename, filetype,charset) {
	checkloadjscssfile = function(filename, filetype) {
		if (filesadded.indexOf("[" + filename + "]") == -1) {
			filesadded += "[" + filename + "]" //List of files added in the form "[filename1],[filename2],etc"
			return true;
		} else {
			return false;
		}
	}
	if (!checkloadjscssfile(filename, filetype)) return false;
	var fileid="__"+filename+"__";
	switch (filename) {
		case "jquery":
			//filename=ContextPath+"/GlobaLib/js/jquery-1.3.2.min.js";
			filename="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js";
			filetype="js";
			break;
		case "jquery.form":
			filename = ContextPath + "/GlobaLib/js/jquery.form-2.18.js";
			filetype = "js";
			break;
		case "jquery.cookie":
			filename = ContextPath + "/GlobaLib/js/jquery.cookie.js";
			filetype = "js";
			break;
		case "jquery.pngFix":
			filename = ContextPath + "/GlobaLib/js/jquery.pngFix.pack.js";
			filetype = "js";
			break;
		case "jquery.autocomplete":
			filename = ContextPath + "/GlobaLib/jquery.autocomplete/jquery.autocomplete.min.js";
			filetype = "js";
			$Load(ContextPath + "/GlobaLib/js/jquery.bgiframe.min.js", "js");
			$Load(ContextPath + "/GlobaLib/jquery.autocomplete/jquery.ajaxQueue.js", "js");
			$Load(ContextPath + "/GlobaLib/jquery.autocomplete/thickbox-compressed.js", "js");
			$Load(ContextPath + "/GlobaLib/jquery.autocomplete/jquery.autocomplete.css", "css");
			$Load(ContextPath + "/GlobaLib/jquery.autocomplete/thickbox.css", "css");
			break;
		case "weebox":
			filename = ContextPath + "/GlobaLib/weebox0.3/weebox.js";
			filetype = "js";
			$Load(ContextPath + "/GlobaLib/js/jquery.bgiframe.min.js", "js");
			$Load(ContextPath + "/GlobaLib/weebox0.3/weebox.jsp", "css");
			break;
		case "jquery.pager":
			filename = ContextPath + "/GlobaLib/js/jquery.pager.js";
			filetype = "js";
			$Load(ContextPath + "/GlobaLib/css/Pager.css", "css");
			break;
		case "jquery.floatDiv":
			filename = ContextPath + "/GlobaLib/js/jquery.floatDiv.js";
			filetype = "js";
			break;
		case "My97DatePicker":
			filename = ContextPath + "/GlobaLib/My97DatePicker/WdatePicker.js";
			filetype = "js";
			break;
		case "type":
			filename = ContextPath + "/GlobaLib/js/type.js";
			filetype = "js";
			break;
		case "fckeditor":
			filename = ContextPath + "/GlobaLib/fckeditor/fckeditor.js";
			filetype = "js";
			break;
		default:
			fileid="";
	} //alert(filename);
	if(!charset)
	{
		charset="utf-8";
	}
	if (filetype == "js") { //判断文件类型 
		/*var fileref = document.createElement('script'); //创建标签 
		fileref.setAttribute("id", fileid); //文件ID
		fileref.setAttribute("type", "text/javascript"); //定义属性type的值为text/javascript 
		fileref.setAttribute("src", filename); //文件的地址 */
		document.write('<script id="'+fileid+'" type="text/javascript" src="' + filename + '" charset="'+charset+'"></s' + 'cript>');
	} else if (filetype == "css") { //判断文件类型 
		/*var fileref = document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);*/
		document.write('<link href="' + filename + '" rel="stylesheet" type="text/css">');
	} //if (typeof fileref!="undefined") 
	//document.getElementsByTagName("head")[0].appendChild(fileref) 
}//$Load End

$Ready=function(readyFunction)
{
	if(typeof($) != "function")
	{
		var js=gid("__jquery__");
		if (!/*@cc_on!@*/0) { //if not IE
			//Firefox2、Firefox3、Safari3.1+、Opera9.6+ support js.onload 
			js.onload = function () { 
				  $(document).ready(readyFunction);
			}
		} else {
			//IE6、IE7 support js.onreadystatechange 
			js.onreadystatechange = function () {
				if (js.readyState == 'complete') {
					 $(document).ready(readyFunction);
				}
			}
		}

						   
	}else{
		$(document).ready(readyFunction);
	}
}



function gid(id) {
	return document.getElementById ? document.getElementById(id) : null;
} //去掉空格 
function Trim(str) {
	if (str.charAt(0) == " ") {
		str = str.slice(1);
		str = Trim(str);
	}
	return str;
} //截取左边num个字符串
function Left(str, len) {
	if (str.length * 2 < len) return str;
	var strlen = 0;
	for (var i = 0; i < str.length; i++) {
		if (str.charCodeAt(i) > 128) {
			strlen = strlen + 2;
		} else {
			strlen = strlen + 1;
		}
		if (strlen > len) {
			return str.substring(0, i) + "...";
		}
	}
	return str;
} //LowerCase 区分大小写
function EndWith(str, end, LowerCase) {
	if (end == null || end == "" || str.length == 0 || end.length > str.length) {
		return false;
	}
	if (!LowerCase) str = str.toLowerCase();
	if (str.substring(str.length - end.length) == end) {
		return true;
	} else {
		return false;
	}
	return true;
}
//判断是否是空 
function isEmpty(value) {
	if (value == null || Trim(value) == "") {
		return true;
	}
	return false;
}
function isDate(str) {
	if (str == null || str == '') return false;
	re = /\d{4}-{1}\d{2}-{1}\d{2}$/;
	return str.match(re);
}
//判断是否是数字 
function isNumber(s) {
	strRef = "1234567890";
	if (s == "") return false;
	for (i = 0; i < s.length; i++) {
		tempChar = s.substring(i, i + 1);
		if (strRef.indexOf(tempChar, 0) == -1) {
			return false;
		}
	}
	return true;
}
//判断是否是非负浮点数 
function isFloat(s) {
	var re = /^[0-9]+.?[0-9]*$/; 
	return re.test(s);
}
function unhtmlcode(str) {
	var s;
	s = str.replace(/&amp;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, " ");
	s = s.replace(/&#39;/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	s = s.replace(/<br\/>/g, "\n");
	return s;
}
function Now() {
	var now = "";
	var time = new Date();
	var month = time.getMonth() + 1;
	var date = time.getDate();
	var year = time.getFullYear();
	if (month < 10) month = "0" + month;
	if (date < 10) date = "0" + date;
	now = year + "-" + month + "-" + date;
	return now;
} //  获取当前文件名
function getFileName(url) {
	var pos = url.lastIndexOf("/");
	if (pos == -1) pos = url.lastIndexOf("\\");
	var filename = url.substr(pos + 1);
	return filename;
}
function select(id, value) {
	if (value==null||value=='') return;
	$("#" + id + " option").each(function() {
		var t = $(this);
		if (t.val() == value) {
			t.attr("selected", true);
			return;
		}
	});
} ////////////
function Confirm(url, msg) {
	if (QuestionBox(msg, "确认")) {
		window.location.href = url;
	}
}
function fixPNG(myImage) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var imgID = (myImage.id) ? "id='" + myImage.id + "' ": "";
		var imgClass = (myImage.className) ? " ": "";
		var imgTitle = (myImage.title) ? "title='" + myImage.title + "' ": "title='" + myImage.alt + "' ";
		var imgStyle = "display:inline-block;" + myImage.style.cssText;
		var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
		myImage.outerHTML = strNewHTML; //alert(strNewHTML);
	}
} //////////////////
function GlobaAjax() {
	defaults = {
		form: null,
		type: 'post',
		url: null,
		dataType: 'json',
		LoadingLayer: null,
		button: null,
		successFunction: null,
		errorFunction: null,
		haveResult: true //是否符返回操作结果?json.success='='true'?
	};
	this.GetOptions = function(opt) {
		var options = $.extend({},
		defaults, opt);
		return ajax_options = {
			type: options.type,
			url: options.url,
			dataType: options.dataType,
			beforeSend: function() {
				if (options.button != null) options.button.disabled = true;
				if (options.LoadingLayer != null) $(options.LoadingLayer).css("display", "block");
			},
			success: function(json) {
				if (options.LoadingLayer != null) $(options.LoadingLayer).fadeOut(100);
				if (options.haveResult) {
					if (json.success == 'true') {
						if (typeof(options.successFunction) == "function") options.successFunction(json);
						if (options.button != null) options.button.disabled = false;
						return false;
					} else { //1确定
						WarnBox(json.msg, "失败");
						if (typeof(options.erroFunction) == "function") options.errorFunction(json);
						if (options.button != null) options.button.disabled = false; 
					}
				} else { //load 操作,不含操作结果
					if (typeof(options.successFunction) == "function") options.successFunction(json);
				}
			},
			error: function(json) {
				if (options.LoadingLayer != null) $(options.LoadingLayer).fadeOut(100);
				if (options.button != null) options.button.disabled = false;
				WarnBox("处理失败!", "处理失败");
			}
		}; //ajax_options end
	}
	this.Submit = function(opt) {
		var o = $(opt.form);
		if (opt.url == null) {
			opt.url = o.attr("action"); //alert(opt.url);
		}
		o.ajaxSubmit(this.GetOptions(opt));
	} //Submit end
	this.Get = function(opt) {
		opt.type = "get";
		$.ajax(this.GetOptions(opt));
	} //Get end
	this.Load = function(opt) {
		opt.type = "get";
		opt.dataType="html";
		opt.haveResult=false;
		$.ajax(this.GetOptions(opt));
	} //Load end	;
} ////WinForm Function
function WarnBox(msg, title) {
	alert(msg);
	return true; //$.weeboxs.open(msg, {boxid:'warn',title:title,draggable:false, type:'alert'});
}
function QuestionBox(msg, title) {
	return confirm(msg);
}
