/*
 * 检查字符串是否全为数字
 *
 * @param str 要检查的字符串
 * @return 是返回true,否返回false
 */
function IsInt(str) {
	var int_string = "0123456789";

	var boole_flag = true;

	for (i = 0; i < str.length; i++) {
		if (int_string.indexOf(str.charAt(i)) == -1) {
			boole_flag = false;
			break;
		}
	}

	return boole_flag;
}

/*
 * 去除字符串前后空白
 *
 * @param str 要修正的字符串
 * @return 修正后的字符串
 */
function Trim(str) {
    if (str == null) {
        return str;
    }

    var i;
    var beginIndex = 0;
    var endIndex = str.length - 1;

    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == ' ' || str.charAt(i) == '　') {
            beginIndex++;
        } else {
            break;
        }
    }

    for (i = str.length - 1; i >= 0; i--) {
        if (str.charAt(i) == ' ' || str.charAt(i) == '　') {
            endIndex--;
        } else {
            break;
        }
    }

    if (endIndex < beginIndex) {
        return "";
    }

    return str.substring(beginIndex, endIndex + 1);
}

/*
 * 通过接口URL跟参数获得完整的URL
 *
 * @param interface 接口URL
 * @param parameterArray 参数数组
 * @return 完整的URL
 */
function GetURL(interface, parameterArray) {
	var url = interface;

	if (interface.substring(interface.length-1, interface.length) != "?") {
		url += "?";
	}

	for (var key in parameterArray) {
		var value = parameterArray[key];

		if (value.constructor == window.Array) {
			for (var key2 in value) {
				url += key2 + "=" + escape(Trim(value[key2])) + "&";
			}
		} else {
			url += key + "=" + escape(value) + "&";
		}
	}

	return url;
}

/*
 * 将数组转换成完整的Post内容字符串
 *
 * @param parameterArray 参数数组,至多是二维数组
 * @return Post内容字符串
 */
function GetPostContentFromArray(parameterArray) {
	var content = "";

	for (var key in parameterArray) {
		var value = Trim(parameterArray[key]);

		if (value.constructor == window.Array) {
			for (var key2 in value) {
				content += key2 + "=" + encodeURIComponent(Trim(value[key2])) + "&";
			}
		} else {
			content += key + "=" + encodeURIComponent(value) + "&";
		}
	}

	return content;
}

/*
 * 取得当前页面宽度,高度,窗口宽度,高度
 *
 * @return 数组
 */
function getPageSize() {
	var xScroll, yScroll;//页面内容的宽度,高度

	xScroll = document.body.scrollWidth;
	yScroll = document.body.scrollHeight;

	var windowWidth, windowHeight;//当前窗口的宽度,高度

	windowWidth = document.body.clientWidth;
	windowHeight = document.body.clientHeight;

	if(yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

var IsShowTransparentBackground = false;//是否显示透明背景DIV的标志

/*
 * 显示一个透明的背景DIV
 *
 * @param color 颜色编码
 */
function showTransparentBackground(color) {
	var arrayPageSize = getPageSize();
	var sWidth = arrayPageSize[0];
	var sHeight = arrayPageSize[1];

	var BgDiv = false;
	BgDiv = document.getElementById("TransparentBgDiv");

	//原先已存在这个div,且样式可用
	if (BgDiv && BgDiv.style) {
		BgDiv.style.background = color;
		BgDiv.style.top =  "0px";
		BgDiv.style.left = "0px";
		BgDiv.style.width = sWidth + "px";
		BgDiv.style.height = sHeight + "px";
		BgDiv.style.visibility = "visible";
		BgDiv.style.display = "";

		IsShowTransparentBackground = true;

		return;
	} else if (BgDiv && !BgDiv.style) {
		document.body.removeChild(BgDiv);//原先存在这个div,但样式不可用
	}

	//新建一个div对象
	BgDiv = document.createElement("div");
	BgDiv.setAttribute("id", "TransparentBgDiv");
	BgDiv.style.position = "absolute";
	BgDiv.style.background = color;
	BgDiv.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=80,finishOpacity=75)";
	BgDiv.style.opacity = "0.8";
	BgDiv.style.top =  "0px";
	BgDiv.style.left = "0px";
	BgDiv.style.width = sWidth + "px";
	BgDiv.style.height = sHeight + "px";
	document.body.appendChild(BgDiv);

	IsShowTransparentBackground = true;
}

/*
 * 隐藏透明的背景DIV
 *
 */
function hiddenTransparentBackground() {
	if (IsShowTransparentBackground) {
		var BgDiv = document.getElementById("TransparentBgDiv");

		//原先已存在这个div
		if (BgDiv) {
			document.body.removeChild(BgDiv);
		}

		IsShowTransparentBackground = false;
	}
}

var IsShowPopup = false;//是否显示弹出窗口的标志

/*
 * 显示一个弹出窗口DIV
 *
 * @param popupDivId DIV的ID
 * @param sTop DIV的上坐标
 * @param sLeft DIV的左坐标
 */
function showPopupById(popupDivId, sTop, sLeft) {
	var popupDiv = document.getElementById(popupDivId);
	if (popupDiv && popupDiv.style) {
		popupDiv.style.position = "absolute";
		popupDiv.style.top = sTop + "px";
		popupDiv.style.left = sLeft + "px";
		popupDiv.style.visibility = "visible";
		popupDiv.style.zIndex = 10001;
		popupDiv.style.display = "";
		document.body.appendChild(popupDiv);

		IsShowPopup = true;
	}
}

/*
 * 隐藏一个弹出窗口DIV
 *
 * @param popupDivId DIV的ID
 */
function hiddenPopupById(popupDivId) {
	var popupDiv = document.getElementById(popupDivId);
	if (popupDiv && popupDiv.style) {
		popupDiv.style.display = "none";

		IsShowPopup = false;
	}
}

/*
 * 移动弹出窗口DIV
 *
 * @param popupDivId DIV的ID
 * @param sTop DIV的上坐标
 * @param sLeft DIV的左坐标
 */
function movePopupById(popupDivId, sTop, sLeft) {
	if (IsShowPopup) {
		var popupDiv = document.getElementById(popupDivId);
		if (popupDiv && popupDiv.style) {
			popupDiv.style.top = sTop + "px";
			popupDiv.style.left = sLeft + "px";
			popupDiv.style.visibility = "visible";
			popupDiv.style.zIndex = 10001;
			popupDiv.style.display = "";
		}
	}
}