var req;
var product;
var xmldoc;

function importXML() {
	product = "ensure";
	if (!document.getElementById('content1')) {
		return;
	}
	// branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = processReqChange;
		req.open("GET", "/copy/products/products.xml", true);
		req.send(null);
		// branch for IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		isIE = true;
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = processReqChange;
			req.open("GET", "/copy/products/products.xml", true);
			req.send();
		}
	}
}

// handle onreadystatechange event of req object
function processReqChange() {
	// only if req shows "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			xmldoc = req.responseXML;
			getProductData(product);
			getProductFacts("nutrition");
		} else {
			alert("There was a problem retrieving the XML data:\n" +
			req.statusText);
		}
	}
}

function getProductData(productName) {
	product = productName;
	var x = xmldoc.getElementsByTagName(product)[0];  
	var desc = x.getElementsByTagName("description")[0];
	document.getElementById('content1').innerHTML = desc.firstChild.nodeValue;
	//document.getElementById('content1').style.color="red"  
	getProductFacts("nutrition");
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; 
	if((p=n.indexOf("?"))>0&&parent.frames.length) {d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all){
		x=d.all[n];
		for (i=0;!x&&i<d.forms.length;i++){
			x=d.forms[i][n];
			for(i=0;!x&&d.layers&&i<d.layers.length;i++){
				x=MM_findObj(n,d.layers[i].document);
			}
		}
	}
	if(!x && d.getElementById){
		x=d.getElementById(n);
		return x;
	}
}

function getProductFacts(facts) {
	var x = xmldoc.getElementsByTagName(product)[0];
	var theData = x.getElementsByTagName(facts)[0];
	document.getElementById("facts").innerHTML = theData.firstChild.nodeValue;
}


/* Functions that swaps images. */
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; 
	document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* performs the rollovers for the Ensure bottle images*/
var states = new Array(1, 0, 0, 0, 0, 0, 0), changeID = 0, changeName = "ensure", changeImage = "products_ensure";

/* changes the large Ensure bottle display and the top image */
function productChange(bigImg, topImg, id, name, Image, altTag, flvImg){
	if(states[id] == 1){return;}
	else{
		if(document.images){
			document['pnutr'].src='/images/products/pnutr_nutrition.gif';
			document["big"].src = "/images/products/" + bigImg;
			document["top"].src = "/images/products/" + topImg;
			document["flavors"].src = "/images/products/" + flvImg;
			document["top"].alt = altTag;
			getProductData(name);
			document[name].src = "/images/products/" + Image + "_off.jpg";
			document[changeName].src = "/images/products/" + changeImage + ".jpg";
			states[id] = 1; states[changeID] = 0; changeID = id; changeName = name; changeImage = Image;
		}
	}
}
