/*
	获取xmlhttprequest数据
*/
function getTransport() {
  return Try.these(
    function() { return new XMLHttpRequest() },
    function() { return new ActiveXObject('MSXML2.DOMDocument.5.0') },
    function() { return new ActiveXObject('MSXML2.DOMDocument.4.0') },
    function() { return new ActiveXObject('MSXML2.DOMDocument.3.0') },
    function() { return new ActiveXObject('MSXML2.DOMDocument') },
    function() { return new ActiveXObject('Msxml2.XMLHTTP') },
    function() { return new ActiveXObject('Microsoft.XMLHTTP') }
  ) || false;
}

function createXMLDOM() {
	var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
						 "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
						 "Microsoft.XmlDom"];
	for (var i=0; i < arrSignatures.length; i++) {
		try {
			var oXmlDom = new ActiveXObject(arrSignatures[i]);
			return oXmlDom;
		} catch (oError) {
			//ignore
		}
	}
	try
	{
		var oXmlDom =  XMLHttpRequest();
	}
	catch(onError)
	{
		alert("你的系统没有安装MSXML");
	}
	return oXmlDom;
}
/*
	url           = 调用的URL
	optionlist    = 填充的option
	selectValue   = 选中的值如果为空就不选中，否则选中，如果为'lastSelect'则自动选择最后一个
*/
function getoption(url,optionlist,selectValue)
{
	var req;
	var isIE6=true;
	if(window.XMLHttpRequest)
	{ //IE7, Mozilla ,Firefox 等浏览器内置该对象
		req = new XMLHttpRequest();
		isIE6 = false;
	}
	else if(window.ActiveXObject)
	{ //IE6、IE5
		isIE6=true;
		try
		{ 
			req = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{ ; }
		if( req == null)
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{; }
	}
	if (req==null)
		alert("你的浏览器不支持AJAX，或者JAVASCRIPT没有打开，请重新设定IE");
	else
	{
			req.onreadystatechange = 
			function()
			{
				// only if req shows "loaded"
				if (req.readyState == 4)
				{
					// only if "OK"
					if (req.status == 200)
					{
						/*
						var source = req.responseXML;
						if (source==null)
							source = req.responseXML.xml;
						*/
						var xml_string = req.responseText;
						xml_string = xml_string.replace(/^\s*/g,"");
						xml_string = xml_string.replace(/\s*$/g,"");
						var source = createXMLDOM();
						source.loadXML(xml_string);
						var root = source;   //设置文档元素为根节点元素		
							
						//var root = source.documentElement;   //设置文档元素为根节点元素
						var sortField = null;
						var sortFieldid=null;
						try
						{
							sortField=root.selectNodes("//@value");   //搜索属性中的value
							sortFieldid=root.selectNodes("//@id");    //搜索属性中的id
						}
						catch (e)
						{
							sortField=source.getElementsByTagName("item");
						}

						for(var i=optionlist.options.length-1;i>=0;--i)   //撤消原来的列表项
						{
							optionlist.options.remove(i)
						}
						
						var oOption = document.createElement('OPTION');
						oOption.text = "==请选择==";
						oOption.value = "";
						optionlist.options.add(oOption);

						for(var i=0;i<sortField.length;++i)   //增加城市名称到下拉列表
						{
							var oOption = document.createElement('OPTION');
							oOption.text = sortField[i].text;
							oOption.value = sortFieldid[i].text;
							if (oOption.value==selectValue)
								oOption.selected = 'selected';
							//alert(oOption.value+" | "+selectValue);
							optionlist.options.add(oOption); 
						}

/*						
						//默认如果没有选择值的话，就选择第一个
						if (selectValue==null || selectValue.length==0)
						{
							if (optionlist.options[1]!=null)
							{
								//alert("111");
								optionlist.options[1].selected = 'selected';
							}
						}
*/
						if (selectValue=='selectFirst')
						{
							if (optionlist.options[1]!=null)
								optionlist.options[1].selected = 'selected';
						}
						if (selectValue=='selectLast')
						{
							var needOption = optionlist.options[optionlist.options.length-1];
							needOption.selected = 'selected';							
						}
					}
					else
					{
						//document.write(req.statusText);
						alert("读取xml数据出错：\n" +req.statusText);
					}
				}
			};
        req.open("POST", url, true); //打开url
		req.setRequestHeader("context-type","text/xml;charset=utf-8");
        req.send(null); //发送

	}
}
/*
	建立时间：2008年2月11日
	功能：
		获取城市列表
		cityParentCode = 父级城市（列子城市）
		onlyP = 只列省城市

	最后修改：2008年2月11日
	修改内容：建立
*/
function getCityList(optionlist,selectValue,cityParentCode,onlyP)
{
	var url = "/xmllist/City.do?1=1";
	if (cityParentCode!=null && cityParentCode.length>0)
		url += "&cityParentCode="+cityParentCode;
	if (onlyP==null)
		url += "&onlyP=-1";
	else
		url += "&onlyP="+onlyP;
	getoption(url,optionlist,selectValue);
}
/*
	建立时间：2008年2月12日
	功能：
		获取角色列表

	最后修改：2008年2月12日
	修改内容：建立
*/
function getRoleList(optionlist,selectValue)
{
	var url = "/xmllist/Role.do?1=1";
	getoption(url,optionlist,selectValue);
}
/*
	建立时间：2008年2月13日
	功能：
		获取css列表

	最后修改：2008年2月13日
	修改内容：建立
*/
function getCssList(optionlist,selectValue)
{
	var url = "/xmllist/Css.do?1=1";
	getoption(url,optionlist,selectValue);
}
/*
	建立时间：2008年2月13日
	功能：
		获取员工分组列表
		companySn = 所属单位

	最后修改：2008年2月13日
	修改内容：建立
*/
function getCpusertypeList(optionlist,selectValue,companySn)
{
	var url = "/xmllist/Cpusertype.do?companySn="+companySn;
	getoption(url,optionlist,selectValue);
}
/*
	建立时间：2008年2月14日
	功能：
		获取视频分类列表

	最后修改：2008年2月14日
	修改内容：建立
*/
function getVtypeList(optionlist,selectValue,vtypeCode)
{
	var url = "/xmllist/Vtype.do?vtypeCode="+vtypeCode;
	getoption(url,optionlist,selectValue);
}

