var ActivateLookUpScript = false;
var VarientsList = new Array();
var ProdCodeList = new Array();
var FormatType = new Array();

var NumRequests = 0;
var http = new Array();

function getElementById_s(id){
var obj = null;
if(document.getElementById)
	{
	// W3C DOM method, if available:-
	obj = document.getElementById(id);
	}
else if(document.all)
	{
	// Use document.all on document.all only browsers.
	obj = document.all[id];
	}
return obj;
}


function LoadAllVarientPrices()
{

if (VarientsList.length>0)
	{
	ActivateLookUpScript=true;
	for (a=0;a<VarientsList.length;a++)
		{
		AskForPrice(VarientsList[a], ProdCodeList[a], FormatType[a]);
		}
	}
}


function getXmlRequest()
{

try	{
	req = new XMLHttpRequest();
	}
	catch(err1)
		{
		try 	{
			req = new ActiveXObject("msxml2.XMLHTTP");
			}
			catch(err2)
				{
				try 	{
					req = new ActiveXObject("Microsoft.XMLHTTP");
	   				}
					catch(err3)
						{
						req = false;
						}
					
				}
		}

return req;
}


function useHttpResponse()
{
var ThisObj = null;
var a=0;
var str = "";
for (a=0;a<NumRequests;a++)
	{
	if (http[a].readyState==4)
		{
		if (http[a].status==200)
			{
			ProdCode="";
			ProdCode=http[a].responseText.split("|");

			//Just make absolutely sure the price being written corresponds to the varient selected...
			if (ThisObj = getElementById_s("v" + ProdCode[1]))
				{
				if (ProdCode[2]==ThisObj.value)
					{
					window.status = 'Loading price...';
					ThisObj = getElementById_s("P" + ProdCode[1]);
					ThisObj.innerHTML = http[a].responseText;
					http[a].close;
					window.status = 'Done';
					}
				}
			}
		}
	}
}

function AskForPrice(varientid, layer, FormatOption)
{
if (ActivateLookUpScript == true)
	{
	window.status = 'Retreiving price...';
	try {
	    document.getElementById(layer).innerHTML = "<span style='font-weight: bold;'>Retreiving Price...</span>";
	    }
	catch (err1)
		{
		alert ("ERROR!" + layer);
		}

	http[NumRequests] = getXmlRequest();
	if (http[NumRequests])
		{
		var thisURL = "getprice.php?vid=" + varientid + "&fo=" + FormatOption + "&rnd=" + Math.random();

		http[NumRequests].open("GET", thisURL, true);
		http[NumRequests].onreadystatechange = useHttpResponse;
		http[NumRequests].send(null);

		NumRequests +=1;
		}
	else
		{
		alert ("There was an error sending the price request.");
		}
	}
}