// Data retrieval functions for Interactive Product Selector © Pattern Jugglers Ltd 2007
var ra = new Array();
var ra1 = new Array();
var ra2 = new Array();
var ra3 = new Array();
var ra4 = new Array();
var sortfld = 2;
var sortfld2 = 0;
var nodenm = '';
var arrid = '';
var http_request = false;

    
function makeRequest(url,nodenmx,arridx) {
	nodenm = nodenmx;
	arrid = arridx;
	if (window.ActiveXObject) {
		// internet explorer
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) {
				readtoarray(xmlDoc);
			}
		};
		xmlDoc.load(url);
	}
	else {
		// other browsers
		http_request = false;
		if (window.XMLHttpRequest) {
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		} 
		if (!http_request) {
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
		http_request.onreadystatechange = getresponse;
		http_request.open('GET', url, true);
		http_request.send(null);
	}
}
function getresponse() {
	// check whether local file or http
	if (window.location.href.substring(0,4) != 'http') {
		var rqs = 0;
	}
	else {
		var rqs = 200;
	}
	if (http_request.readyState == 4) {
		if (http_request.status == rqs) {
			var xmlDoc = http_request.responseXML;
			readtoarray(xmlDoc);
		}
		else {
			alert('There was a problem with the request.');
		}
	}
}
function readtoarray(xmlDoc) {
	var x = xmlDoc.getElementsByTagName(nodenm);
	for (j=0;j<x[0].childNodes.length;j++) {
		if (x[0].childNodes[j].nodeType != 1) {
			continue;
		}
	}
	for (i=0;i<x.length;i++) {
		ra[i] = new Array();
		jf=2;
		for (j=0;j<x[i].childNodes.length;j++) {
			if (x[i].childNodes[j].nodeType != 1) {
				continue
			}
			nn = x[i].childNodes[j].nodeName;
			ra[i][nn] = x[i].childNodes[j].firstChild.nodeValue;
			jf += 1;
		}
	}
	var tre = i;
	switch(arrid) {
		case 'ra1' 	: ra1 = ra ;gotx1();break;
		case 'ra2' 	: ra2 = ra ;gotx2();break;
		case 'ra3' 	: ra3 = ra ;gotx3();break;
		case 'ra4' 	: ra4 = ra ;gotx4();break;
	}
}
function SortByFld(a, b) {
	if(a[sortfld] < b[sortfld])	{
		return -1;
	}
	if(a[sortfld] > b[sortfld]) {
		return 1;
	}
	return 0;
} 
function Sortx(a, b) {
	asf = parseInt(a[sortfld]);
	bsf = parseInt(b[sortfld]);
	if(asf < bsf) {
		return -1;
	}
	if(asf > bsf) {
		return 1;
	}
	return 0;
} 
function dispbl(itemid, vis) {
	if (document.layers) {
		document.layers[itemid].display = vis;
	}
	else if (document.all) {
		document.all[itemid].style.display = vis;
	}
	else if (document.getElementById) {
		document.getElementById(itemid).style.display = vis;
	}
}
function pad2d(x) {
	if (parseInt(x) < 10) {
		return '0' + x;
	}
	else {
		return x;
	}
}
function not(thing){
	if (thing) return false;
	return true;
}


