function $(id) {
	return document.getElementById(id);
}
function trim(str) {
	return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}

function postform(fc, div) {
	if(trim($('fullname').value) == '' || trim($('fullname').value).length < 5) {
		$('fullname').focus();
		alert('Please input your full name!');
		return false;
	}

	if(trim($('email').value) == '' || trim($('email').value).length < 6) {
		$('email').focus();
		alert('Please input your email!');
		return false;
	}

	if(trim($('inquire').value) == '' || trim($('inquire').value).length < 10) {
		$('inquire').focus();
		alert('Please input your question in the content text area!');
		return false;
	}

	//alert(fc.length);

	//组装字符串
	var i,qs="",and="",ev="";
	for(i=0;i<fc.length;i++) {
		e=fc[i];
		if (e.name!='') {
			if (e.type=='select-one'&&e.selectedIndex>-1) ev=e.options[e.selectedIndex].value;
			else if (e.type=='checkbox' || e.type=='radio') {
				if (e.checked==false) continue;
				ev=e.value;
			}
			else ev=e.value;
			qs+=and+e.name+'='+ev;
			and="&";
		}
	}
	//return qs;
	//alert(qs);
	//return false;

	var obj = $(div);
	var ajax = new AJAX();
	ajax.URLString = 'ajax.php';
	ajax.onLoading = function() {
		obj.innerHTML = '&nbsp;&nbsp;<img src="images/loading.gif" /> Data is sending...';
	}
	ajax.onCompletion = function() {
		//fc.reset();
		obj.innerHTML = '&nbsp;&nbsp;' + ajax.response;
	}
	ajax.onError = function() {
		obj.innerHTML = '&nbsp;&nbsp;Data submit failed, please try again later!';
	}
	ajax.Send(qs);

	return false;
}

var last_id = 2;
function showfull(id) {
	$('showroom_list_' + last_id).className = "";
	$('showroom_item_' + last_id).className = "";

	$('showroom_list_' + id).className = "on";
	$('showroom_item_' + id).className = "on";

	last_id = id;
}

function AJAX() {
	this.XMLHttpReq = null;
	this.method = "post";
	this.URLString = "";
	this.response = "";
	this.responseXML = "";
	this.failed = false;

	this.onLoading = function() { };
	this.onLoaded = function() { };
	this.onInteractive = function() { };
	this.onCompletion = function() { };
	this.onError = function() { };
	this.onFail = function() { };

	this.resetFunctions = function() {
		this.onLoading = function() { };
		this.onLoaded = function() { };
		this.onInteractive = function() { };
		this.onCompletion = function() { };
		this.onError = function() { };
		this.onFail = function() { };
	};

	this.Init = function()
	{
		if(window.XMLHttpRequest)
		{
			this.XMLHttpReq = new XMLHttpRequest();
		} else if (window.ActiveXObject)
		{
			try
			{
				this.XMLHttpReq = new ActiveXObject("Msxml4.XMLHTTP");
			}
			catch(e)
			{
				try
				{
					this.XMLHttpReq = new ActiveXObject("Msxml3.XMLHTTP");
				}
				catch(e)
				{
					try
					{
						this.XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch(e)
					{
						try
						{
							this.XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
						}
						catch(oc)
						{
							this.failed=true;
						}
					}
				}
			}
		}
	};

	this.Send=function(data)
	{
		var self=this;

		//data = 'inajax=1&' + data;

		if(this.method=="post")
		{
			this.XMLHttpReq.open(self.method,self.URLString,true);
		}
		else
		{
			this.XMLHttpReq.open(self.method,self.URLString+"?"+encodeURI(data),true);
		}
		this.XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

		this.XMLHttpReq.onreadystatechange = function()
		{
			if (self.failed) {
				self.onFail();
				return;
			}

			switch (self.XMLHttpReq.readyState) {
				case 1:
				{
					self.onLoading();
					break;
				}
				case 2:
				{
					self.onLoaded();
					break;
				}
				case 3:
				{
					self.onInteractive();
					break;
				}
				case 4:
				{
					if(self.XMLHttpReq.status==200) {
						self.response = self.XMLHttpReq.responseText;
						self.responseXML = self.XMLHttpReq.responseXML;
						self.onCompletion();
					}
					else
					{
						self.onError();
					}
					break;
				}
			}
		};


		if(this.method=="post")
		{
			this.XMLHttpReq.send(encodeURI(data));
		}
		else
		{
			this.XMLHttpReq.send();
		}
	};

	this.Abort=function()
	{
		this.XMLHttpReq.abort();
	}

	this.Close=function()
	{
		this.XMLHttpReq=null;
	}
	this.Init();
}


