var xmlHttp;

function  createRequest ()
{
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
}

function sendMsg (txt)
{
	var obj = document.getElementById('msg');
	obj.innerHTML = obj.innerHTML + txt + '<br />';
	obj.scrollTop = obj.scrollHeight;
}

function exportList()
{
	if(document.getElementById('srcFile').value != '')
	{
	  createRequest();
	  var url = 'xml_ex_ajax.php?action=export&file=' + document.getElementById('srcFile').value;
	  xmlHttp.open("GET", url, true);
	  xmlHttp.onreadystatechange  =  StateChange;
	  xmlHttp.send(null);
	}
	else
	{
	  sendMsg('Enter file name');
	  document.getElementById('srcFile').focus();
	}
}

function addItem (id, sid)
{
	sendMsg('#' + id + ' in progress...');
	createRequest();
	var url = 'xml_ex_ajax.php?action=add&item=' + id + '&' + sid;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange  =  StateChange;
	xmlHttp.send(null);
}

function updateItem (id, code, sid)
{
	sendMsg('#' + code + ' updating...');
	createRequest();
	var url = 'xml_ex_ajax.php?action=update&item=' + id + '&code=' + code + '&' + sid;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange  =  StateChange;
	xmlHttp.send(null);
}


function setCat (id, sid)
{
	createRequest();
	var url = 'xml_ex_ajax.php?action=cat&item=' + id + '&' + sid;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange  =  StateChange;
	xmlHttp.send(null);

}

function checkInp (key)
{
	re = new RegExp("[^ -_0-9a-zà-ÿýúû³¿º¸]", "ig");
	key = key.replace(re, "");
	document.filter_form.elements['filter'].value = key;
}

function  StateChange() {
	if(xmlHttp.readyState == 4) 
	{
/*		alert(xmlHttp.responseText);*/
		sendMsg(xmlHttp.responseText);
	}
}
