
function  CheckAndSelect( strCompare , slctObject )
{
	for( var i=0 ; i < slctObject.length ; i++ )
	{
		if( slctObject.options[i].value == strCompare )
		{
			slctObject.selectedIndex = i;
			break;
		}
	}
}

function GetHeaderValue(name)
{
	var header = window.location.search.substr(1,window.location.search.length);
	if( arguments.length < 1 )
		return "";
	
	var headerArray = header.split("&");
	for(var i = 0; i < headerArray.length; i++)
	{
		var pair = headerArray[i].split("=");
		if (pair[0] == name)
			return pair[1];
	}
	
	return "";
}

function GetQSExcept()
{
	var result = "";
	var header = window.location.search.substr(1,window.location.search.length);
	if( arguments.length < 1 )
		return header;
	
	var headerArray = header.split("&");
	for(var i = 0; i < headerArray.length; i++)
	{
		var isNext = false;
		for(var j = 0; j < arguments.length; j++)
		{
			if(headerArray[i].indexOf(arguments[j]) == 0)
			{
				isNext = true;
				break;
			}
		}
		
		if(isNext)continue;
		
		if(result == "")
			result = headerArray[i];
		else
			result += "&" + headerArray[i];
	}
	
	return result;
}

function Go(page)
{
	if (typeof(OnSearch) == "function")
	{
		OnSearch(page);
	}
	else
	{
		var qs = GetQSExcept("page");
		window.location = "?page=" + page + (qs == "" ? "" : "&" + qs);
	}
}

////////////////////////////////////////////////////////////////
// Start : 对CheckBox操作
function GetChecked( strName )
{
	var strResult = "";
	var colInput = document.getElementsByTagName("INPUT");
	for( var i=0; i < colInput.length; i++ )
	{
		var varItem = colInput.item(i);
		if( varItem.type == "checkbox" && varItem.name == strName && varItem.checked )
		{
			if( strResult == "" )
				strResult = varItem.value;
			else
				strResult += "|"+varItem.value;
		}
	}
	return strResult;
}

function SetCheck( strName, bCheck )
{
	var colInput = document.getElementsByTagName("INPUT");
	for( var i=0; i < colInput.length; i++ )
	{
		var varItem = colInput.item(i);
		if( varItem.type == "checkbox" && varItem.name == strName )
			varItem.checked = bCheck;
	}
}
// End : 对CheckBox操作
////////////////////////////////////////////////////////////////


function Trim(text)
{
    if (typeof(text) != "string")
		return text;

	var retValue = text;
	var ch = retValue.substring(0, 1);
    while (ch == ' ' || ch == '\r' || ch == '\n')
	{
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
    }
	
    ch = retValue.substring(retValue.length-1, retValue.length);
    while (ch == ' ' || ch == '\r' || ch == '\n')
	{
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
    }
	
    while (retValue.indexOf('  ') != -1)
	{
		retValue = retValue.substring(0, retValue.indexOf('  ')) + 
		retValue.substring(retValue.indexOf('  ')+1, retValue.length); 
    }

	return retValue; 
}

function TrimForm(form)
{
	for (var i = 0; i < form.elements.length; i++)
	{
		if (form.elements[i].tagName == "TEXTAREA" || (form.elements[i].tagName == "INPUT" && form.elements[i].type == "text"))
			form.elements[i].value = Trim(form.elements[i].value);
	}
}

//点对象
function Point(iX, iY)
{
	this.x = iX;
	this.y = iY;
}

//获得一个对象（一个Html元素对象或ID）左上角
function GetObjectXY( ob )
{
	var topLeft = new Point(0,0);
	topLeft.x	= ob.offsetLeft;
	topLeft.y	= ob.offsetTop;
	var parent	= ob.offsetParent;
	while (parent != null && parent.tagName.toUpperCase() != "BODY")
	{
		topLeft.x	+= parent.offsetLeft;
		topLeft.y	+= parent.offsetTop;
		parent = parent.offsetParent;
	}
	
	return topLeft;
}

///////////////////////////////////////////////
//START : 页面内容语言相关
function ShowLanguageFilterMenu(ob)
{
	menu = document.getElementById("LanguageFilterMenu");
	if (menu == null)
		return;
		
	var topLeft = GetObjectXY(ob);
	menu.style.left = topLeft.x + "px";
	menu.style.top = topLeft.y + ob.offsetHeight + "px";
	menu.style.display = "";
	menu.onmouseout = function(e)
	{
		HideLanguageFilterMenu(e);
	}
}

function ContainsNS6(a, b)
{
	while (b.parentNode)
	{
		if ((b = b.parentNode) == a)
			return true;
	}
	return false;
}

function HideLanguageFilterMenu(e)
{
	menu = document.getElementById("LanguageFilterMenu");
	var browser = navigator.userAgent;
	if (browser.indexOf("Gecko") != -1)//FireFox
	{
		if (ContainsNS6(menu, e.relatedTarget))
			return;
	}
	else
	{
		if (menu.contains(event.toElement))
			return;
	}

	menu.style.display = "none";
}

function ChangeContentLang(langID)
{
	var header = GetQSExcept("Lang","page");
	if (header == "")
		window.location.href = "?Lang=" + langID;
	else
		window.location.href = "?Lang=" + langID + "&" + header;
}
//END : 页面内容语言相关
////////////////////////////////////////////////

function UrlDecode(str)
{
	str = str.replace(new RegExp('\\+','g'),' ');
	return unescape(str);
}

function UrlEncode(str)
{
	str = escape(str);
	str = str.replace(new RegExp('\\+','g'),'%2B');
	return str.replace(new RegExp('%20','g'),'+');
}

function OpenCloseLeftFrame()
{
	var frame = parent.document.getElementById("Frame");
	if (frame.cols != "0,*")
	{
		frame.cols = "0,*";
		event.srcElement.src = event.srcElement.src.replace("close", "open");
	}
	else
	{
		frame.cols = "180,*";
		event.srcElement.src = event.srcElement.src.replace("open", "close");
	}
}

function GetCookie(name)
{
	var array = document.cookie.split(";");
	for( var i=0; i < array.length; i++ )
	{
		var kvp = array[i].split("=");
		if (name == Trim(kvp[0]) && typeof(kvp[1]) != "undefined")
			return kvp[1];
	}
	return "";
}

function SetCookie(name, value, expireMinutes, path)
{
	var path = "";
	if (arguments.length == "4")
		path = ";path=" + arguments[3];
		
	var expireDate = new Date();
	expireDate.setMinutes(expireDate.getMinutes() + expireMinutes);
	document.cookie = name + "=" + value + ";expires=" + expireDate.toUTCString() + path;
}

function GetEvent()
{
	if (g_browser == "IE")
		return window.event;//如果是ie
		
	func = GetEvent.caller;
	while (func != null)
	{
		var arg0 = func.arguments[0];
		if(arg0)
		{
			if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation))
			{
				return arg0;
			}
		}
		func=func.caller;
	}
	return null;
}

function IsUyghurText(text)
{
	var uyghur = 0;
	var number = 0;
	for (var i = 0; i < text.length; i++)
	{
		var code = kw.charCodeAt(i);
		if (code >= 0x0600 && code <= 0x06FF)
			uyghur++;
		else if (code >= 0x30 && code <= 0x39)
			number++;
	}
	
	if (uyghur > (text.length - number)/2)
		return true;
	else
		return false;
}

function BuildTreeOptions(xmlDoc, parentField, idField, nameField, selectControl)
{
	var _doc = xmlDoc;
	var _parentField = parentField;
	var _idField = idField;
	var _nameField = nameField;
	var _selectControl = selectControl;
	var _nodeList = new Array();
	var _empty = "00000000-0000-0000-0000-000000000000";
	
	this.Run = function(parentID, isParentLast, layer)
	{
		var nodeList = new Array();
		var allChild = _doc.documentElement.childNodes;
		for (var i = 0; i < allChild.length; i++)
		{
			if (allChild[i].selectSingleNode(_parentField).text == parentID)
				nodeList[nodeList.length] = allChild[i];
		}
		
		for (var i = 0; i < nodeList.length; i++)
		{
			var id = nodeList[i].selectSingleNode(_idField).text;
			var nameNode = nodeList[i].selectSingleNode(_nameField);
			var name = (nameNode == null) ? "" : nameNode.text;
	
			var indent = "";
			for (var j = 0; layer > 0 && j < layer; j++)
			{
				if (j == layer - 1)
				{
					if (i == nodeList.length - 1)
						indent += "   └  ";
					else
						indent += "   ├  ";
				}
				else
				{
					indent += "   " + (isParentLast ? "" : "│");
				}
			}

			_selectControl.add(new Option(indent + name, id));
	
			if (i == nodeList.length - 1)
				Run(id, true, layer + 1);
			else
				Run(id, false, layer + 1);
		}
	}
	
	Run(_empty, false, 0);
}

var g_browser = "IE";
if (navigator.userAgent.indexOf("Gecko") != -1)//FireFox
	g_browser = "FF";
