function NewXML()
{
	var request = false;
	try
	{
		request = new XMLHttpRequest();
	}
	catch (trymicrosoft)
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft)
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed)
			{
				request = false;
			}
		}
	}
	if (!request)
		alert("Error initializing XMLHttpRequest!");
	return request;
}

function loadContent(url,destination,method,reqvars,procfunc,xmlkey)
{
	request = NewXML();
	var postvars = null;
	loadHTML = destination;
	ajaxFunc = procfunc;
	XML = xmlkey;
	if(method == "GET")
	{
		url = url+"?"+reqvars.join("&");
	}
	if(method == "POST")
	{
		contentType = "application/x-www-form-urlencoded; charset=utf-8";
		postvars = reqvars.join("&");
	}
	request.onreadystatechange = processStateChange;
	request.open(method, url, true);
	if(method=="POST")
		request.setRequestHeader("Content-Type", contentType);
	request.send(postvars);
}

function processStateChange()
{
	if (request.readyState == 4)
	{
		var contentDiv = document.getElementById(loadHTML);
		if (request.status == 200)
		{
			if(XML == true)
			{
				var respDoc = request.responseXML;
				ajaxFunc = ajaxFunc+"(respDoc)";
				eval(ajaxFunc);
			}
			if(XML == false)
			{
				var respDoc = request.responseText;
				ajaxFunc = ajaxFunc+"(respDoc)";
				eval(ajaxFunc);
			}
		}
		else
		{
			contentDiv.innerHTML = "Error: Status "+request.status;
		}
	}
}

function viewImage(img,title,width,height)
{
	var myWin= open('', 'displayWindow','height='+height+',width='+width+',resizable=no');
	myWin.document.open();  
	myWin.document.write('<html><head><title>'+title);
	myWin.document.write('</title></head><body>');
	myWin.document.write('<img src="'+img+'">');
	myWin.document.write('</body></html>');
	myWin.document.close();  
}

function loadText(respDoc)
{
	document.getElementById(loadHTML).innerHTML = '';	
	document.getElementById(loadHTML).innerHTML = respDoc;
}

function toBasket(path_name,item_id)
{
	var url = "index.php";
	var url = path_name;
	var reqvars = new Array();
	var buy_item = "item_id="+item_id;
	reqvars.push(buy_item);
	var destination = "basket";
	var method = "POST";
	var procfunc = "loadText";
	var xmlkey = false;
	loadContent(url,destination,method,reqvars,procfunc,xmlkey);		
}

function sendFormValues(formName,nextDest,scriptPath,extraVars,extraFunc,extraKey)
{
	var url = "index.php";
	var reqvars = new Array();
	var scriptPath = "go="+scriptPath;
	reqvars.push(scriptPath);
	for (i=0; i<document.forms[formName].length; i++) 
	{
		var elName = document.forms[formName].elements[i].name;
		var elVal = document.forms[formName].elements[i].value;
		reqvars.push(elName+"="+elVal);
	}
	if((extraVars!='')&&(extraVars!=undefined))
		reqvars.push("extra="+extraVars);
	var destination = nextDest;
	var method = "POST";
	if((extraFunc!='')&&(extraFunc!=undefined))
		var procfunc = extraFunc;
	else
		var procfunc = "loadText";
	if(extraKey!=undefined)
		var xmlkey = extraKey;
	else
		var xmlkey = false;
	loadContent(url,destination,method,reqvars,procfunc,xmlkey);
}

