function gmobj(o){
	if(document.getElementById){ m=document.getElementById(o); }
	else if(document.all){ m=document.all[o]; }
	else if(document.layers){ m=document[o]; }
	return m;
}

function ShowStock() {
	var xmlHttp = null;

	try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) {	try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");	} catch (E) { xmlHttp = null; } }
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {	xmlHttp = new XMLHttpRequest();	}
	if (xmlHttp==null) { alert ("Browser does not support HTTP Request"); return; }

	var parameters = "valid="+encodeURIComponent('valid')+"&t="+encodeURIComponent((new Date()).getTime());
	var url = 'modules/mod_vnstock/vnstock.php';

	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 && xmlHttp.status==200) {
			var sHTML = '';
			var hose = '';
			var hastc = '';
			var count = 0;
			var cnt = 0;

			var ho 	= xmlHttp.responseXML.getElementsByTagName('hose').item(0).childNodes;
			var se 	= xmlHttp.responseXML.getElementsByTagName('hose').item(0).firstChild;
			var ha 	= xmlHttp.responseXML.getElementsByTagName('hastc').item(0).childNodes;
			var stc = xmlHttp.responseXML.getElementsByTagName('hastc').item(0).firstChild;

			sHTML = sHTML.concat('<table id="vnstock" border="0" cellpadding="0" cellspacing="0" width="100%">');
			sHTML = sHTML.concat('<tr><td class="title">Mã</td><td class="title">Giá</td>');
			sHTML = sHTML.concat('<td class="title">KL</td><td class="title">+/-</td></tr>');

			for (var i=0; i<ho.length; i++) {
				if (se.nodeType==1) {
					var a = se.firstChild;
					var rows_hose = count%2?'class="le"':'class="chan"';
					hose = hose.concat('<tr ').concat(rows_hose).concat('>');
					if (a.nodeType==1) {
						hose = hose.concat('<td class="').concat(a.getAttribute("class")).concat('">');
						hose = hose.concat(a.childNodes[0].nodeValue).concat('</td>');
					}
					a = a.nextSibling;
					a = a.nextSibling;
					if (a.nodeType==1) {
						hose = hose.concat('<td class="').concat(a.getAttribute("class")).concat('">');
						hose = hose.concat(a.childNodes[0].nodeValue).concat('</td>');
					}
					a = a.nextSibling;
					if (a.nodeType==1) {
						hose = hose.concat('<td class="').concat(a.getAttribute("class")).concat('">');
						hose = hose.concat(a.childNodes[0].nodeValue).concat('</td>');
					}
					a = a.nextSibling;
					if (a.nodeType==1) {
						hose = hose.concat('<td class="').concat(a.getAttribute("class")).concat('">');
						hose = hose.concat(a.childNodes[0].nodeValue).concat('</td>');
					}
					hose = hose.concat('</tr>');
					count = count + 1;
				}
				se = se.nextSibling;
			}
			hose = hose.concat('</table>');
			gmobj('hose').innerHTML = sHTML.concat(hose);
			
			for (var i=0; i<ha.length; i++) {
				if (stc.nodeType==1) {
					var b = stc.firstChild;
					var rows_hastc = cnt%2?'class="le"':'class="chan"';
					hastc = hastc.concat('<tr ').concat(rows_hastc).concat('>');
					if (b.nodeType==1) {
						hastc = hastc.concat('<td class="').concat(b.getAttribute("class")).concat('">');
						hastc = hastc.concat(b.childNodes[0].nodeValue).concat('</td>');
					}
					b = b.nextSibling;
					b = b.nextSibling;
					if (b.nodeType==1) {
						hastc = hastc.concat('<td class="').concat(b.getAttribute("class")).concat('">');
						hastc = hastc.concat(b.childNodes[0].nodeValue).concat('</td>');
					}
					b = b.nextSibling;
					if (b.nodeType==1) {
						hastc = hastc.concat('<td class="').concat(b.getAttribute("class")).concat('">');
						hastc = hastc.concat(b.childNodes[0].nodeValue).concat('</td>');
					}
					b = b.nextSibling;
					if (b.nodeType==1) {
						hastc = hastc.concat('<td class="').concat(b.getAttribute("class")).concat('">');
						hastc = hastc.concat(b.childNodes[0].nodeValue).concat('</td>');
					}
					hastc = hastc.concat('</tr>');
					cnt = cnt + 1;
				}
				stc = stc.nextSibling;
			}
			hastc = hastc.concat('</table>');
			gmobj('hastc').innerHTML = sHTML.concat(hastc);
		}
	}
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(parameters);
	var z = setTimeout('ShowStock()', 30000);
}
