

//	[Product]
//		湖南中小学课程教研网(3633)
//
//	[Copyright]
//		Copyright 2007-2008 Knightmade. All rights reserved.
//
//	[Filename]
//      ajax.js
//
//	[Description]
//		js基类。
//
//	[History]
//		Date        	Version  	Author   	 Content
//		----------  	-------  	--------  	------------------------------------
//		2007/04/28  	1.0.0    	孟刚      	初始版本
//		2007/05/12  	1.0.1    	廖晓刚      添加code2，用于OPTION的SELECT属性	
//		2007/05/22  	1.0.2    	孟刚      	增加博客评论的发布、获取方法	

function __createXmlHttp()
{
	var xmlhttp = null;

	if (typeof(XMLHttpRequest) == "function") 
	{
		xmlhttp = new XMLHttpRequest();
	}
	else if (ActiveXObject) 
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return xmlhttp;
}

function fetchParam($table, $code1, $code2)
{
	var datastr = "";

	try
	{
		var xmlhttp = __createXmlHttp();
		if (!xmlhttp)
		{
			alert ("can not support AXAJ!");
			return;
		}
		
		if (!$code1)
		{
			$code1 = "";
		}
		
		if (!$code2)
		{
			$code2 = "";
		}

		$url = app_root + "cmd/fetchtxt.php";
		$req = "type=param&table=" + $table + "&code1=" + $code1 + "&code2=" + $code2;
		xmlhttp.open("POST", $url, false);
		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send($req);
		var result = xmlhttp.status;

		if (result == 200)
		{
			var datastr = xmlhttp.responseText;
		}
	}
	catch (e)
	{
		alert(e.message);
		return;
	}

	return datastr;
}

/// [Summary]
///     初始化ComboBox中的数据。
function initCombo(combo, table, code1, code2)
{
	combo.innerHTML = "";	

	var opt = document.createElement("option");
	opt.text = "--选择--";
	opt.value = "";
	combo.options.add(opt);

	var txtstr = fetchParam(table, code1, code2);
	var lines = txtstr.split('\n');
	for (var i = 0; i < lines.length; i++)
	{
		line = lines[i];
		var tmp = line.split(',', 2);
		if (tmp.length == 2)
		{
			var opt = document.createElement("option");
			opt.text = tmp[1];
			opt.value = tmp[0];
			combo.options.add(opt);
			if (tmp[0]== code2)
			{
				opt.selected = true;
			}
		}
	}
}
