function $(id)
{
	return document.getElementById(id);
}

function Switch(objID)
{
	var obj = $(objID);
	if (obj.style.display == 'none')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.display = 'none';
	}
}

function Open(url)
{
	window.open(url);
}

function Close()
{
	window.opener = null;
	window.open('', '_self');
	window.close();
}

// 反选择
function CheckOther(obj)
{
	var object = eval("window.document." + obj);

	for (var i = 0; i < object.elements.length; i++)
	{
		var e = object.elements[i];
		if (e.type == 'checkbox')
		{
			if (e.checked == true)
			{
				e.checked = false;
			}
			else
			{
				e.checked = true
			}
		}
	}
}


function GetElementsByClassName(className)
{
	var el = [];
	var array1 = document.getElementsByTagName('*');
	for (var i = 0; i < array1.length; i++)
	{
		if (array1[i].className == className)
		{
			el[el.length] = array1[i];
		}
	}

	return el;
}





// 运行HTML代码
function RunCode(obj)
{
	var winName = window.open('', '_blank', '');
	winName.document.open('text/html', 'replace');
	winName.document.write(obj.value);
	winName.document.close();
}





// JavaScript 的 Cookies 函数库
/************************************************************
1.CookieExist(name) 检查 Cookie 是否存在
2.GetCookie(name) 读取 Cookie 的值，没有该 Cookie 返回 null
3.RemoveCookie(name, path, domain) 删除 Cookie
4.AddCookie(name, value, expires, path, domain, secure) 添加 Cookie，更新和添加都一样
5.AppendCookie(name, value) 追加值，用"|"分隔
************************************************************/

var expires = 365;
var path = "/";
var domain = "";
var secure = false;



// 1. 
function CookieExist(name)
{
  if (GetCookie(name))
      return true;
  else
      return false;
}


// 2. 
function GetCookie(name)
{
	var strCookies = document.cookie;
	var cookieName = name + "=";  // Cookie名称

	var valueBegin, valueEnd, value;
	
	// 取得值的开始位置
	valueBegin = strCookies.indexOf(cookieName);
	if (valueBegin == -1) return null;  // 没有此Cookie
	
	// 取得值的结尾位置
	valueEnd = strCookies.indexOf(";", valueBegin);
	if (valueEnd == -1)
		valueEnd = strCookies.length;// 是最后一个Cookie

	// 取得Cookie值
	value = strCookies.substring(valueBegin + cookieName.length, valueEnd);
	return value;
}



// 3. 
function RemoveCookie(name, path, domain)
{
	var strCookie;

	// 检查Cookie是否存在
	if (CookieExist(name))
	{
		// 设置Cookie的期限为己过期
		strCookie = name + "="; 
		strCookie += (path) ? "; path=" + path : "";
		strCookie += (domain) ? "; domain=" + domain : "";
		strCookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		document.cookie = strCookie;
	}
}


// 4. 
function AddCookie(name, value, expires, path, domain, secure)
{
	var strCookie = name + "=" + value;
	if (expires)
	{
		// 计算Cookie的期限, 参数为天数
		var curTime = new Date();
		curTime.setTime(curTime.getTime() + expires*24*60*60*1000);
		strCookie += "; expires=" + curTime.toGMTString();
	}

	// Cookie的路径
	strCookie +=  (path) ? "; path=" + path : "";

	// Cookie的Domain
	strCookie +=  (domain) ? "; domain=" + domain : "";

	// 是否需要保密传送,为一个布尔值
	strCookie +=  (secure) ? "; secure" : "";

	document.cookie = strCookie;
}

// 5.
function AppendCookie(name, value)
{
	var oldValue = GetCookie(name);

	if (oldValue != null)
	{
		value = oldValue + "|" + value;
	}
	
	AddCookie(name, value, expires, path, domain, secure);
}









/* ==================== XMLHttpRequest ==================== */
// CreateXMLHttpRequest()
// LoadXml(url)
// Callback()

var xmlHttp;
var xmlDoc;

CreateXMLHttpRequest();

function CreateXMLHttpRequest()
{
	if (window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
}

function LoadXml(url)
{
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = Callback;
	xmlHttp.send();
}


function Callback()
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200)
		{
			xmlDoc = xmlHttp.responseXml;
			if (typeof(ProcessXml) == "function")
			{
				ProcessXml();
			}
		}
		else
		{
			if (typeof(Err) == "function")
			{
				Err();
			}
		}
	}
}
/* ==================== XMLHttpRequest ==================== */