// JavaScript Document
self.name = 'GardenSuperMart';

function showprodinfo(productname){
	for (var i=1;i<=5;i++) {
	var product = "product" + i;
	document.getElementById(product).style.display = "none";
	}
	if (document.getElementById){ document.getElementById(productname).style.display = "block";}
		else{document[productname].display = "block";} 
}

function featured(productname, navname, totalfeatured){
	if (productname != "featured1"){document.getElementById("featured1").style.display = "none";}
	if (navname != "nav1"){document.getElementById("fnav1").style.background = "url(../images/features-notactive.gif)";}	
	if (totalfeatured >= 2) {
		if (productname != "featured2"){document.getElementById("featured2").style.display = "none";}
		if (navname != "nav2"){document.getElementById("fnav2").style.background = "url(../images/features-notactive.gif)";}
	}
	if (totalfeatured >=3) {
		if (productname != "featured3"){document.getElementById("featured3").style.display = "none";}
		if (navname != "nav3"){	document.getElementById("fnav3").style.background = "url(../images/features-notactive.gif)";}
	}
	if (totalfeatured >=4) {
		if (productname != "featured4"){document.getElementById("featured4").style.display = "none";}
		if (navname != "nav4"){document.getElementById("fnav4").style.background = "url(../images/features-notactive.gif)";}
	}
	if (totalfeatured >=5) {
		if (productname != "featured5"){document.getElementById("featured5").style.display = "none";}
		if (navname != "nav5"){document.getElementById("fnav5").style.background = "url(../images/features-notactive.gif)";}
	}
	if (document.getElementById){
			document.getElementById(productname).style.display = "block";
			document.getElementById(navname).style.background = "url(../images/features-active.gif)";
		}//ends IF
		else{
			document[productname].display = "block";
			document.getElementById(navname).style.background = "url(../images/features-active.gif)";
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(num,total){
	sMax = total;	// Isthe maximum number of stars
	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).src = "http://www.gardensupermart.com/images/rating-2.gif";
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).src = "http://www.gardensupermart.com/images/rating-1.gif";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("_"+i).src = "http://www.gardensupermart.com/images/rating-1.gif";
			}
		}else{
			rating(preSet);
		}
	}
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}


function parseXML(url)
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e)
    {
    alert(e.message);
    return;
    }
  }
xmlDoc.async=false;
var fileurl = "xml/" + url + ".xml";
xmlDoc.load(fileurl);

var averagevote = roundNumber(((xmlDoc.getElementsByTagName("total")[0].childNodes[0].nodeValue) / (xmlDoc.getElementsByTagName("totalvotes")[0].childNodes[0].nodeValue)),1);
document.getElementById("totalvotes").innerHTML=xmlDoc.getElementsByTagName("totalvotes")[0].childNodes[0].nodeValue;
document.getElementById("total").innerHTML= averagevote;


var starsdisplay = 0;
averagevote = Math.round(averagevote);
var stars = "";

while (starsdisplay < averagevote){
	stars = stars + "<img src=\"http://www.gardensupermart.com/images/rating-2.gif\" border=\"0\" alt=\"\" />";
	starsdisplay ++;
}
while (starsdisplay < 5){
	stars = stars + "<img src=\"http://www.gardensupermart.com/images/rating-1.gif\" border=\"0\" alt=\"\" />";
	starsdisplay ++;
}


document.getElementById("stars").innerHTML= stars;

}

function showinfo(infoname){
	if (infoname != "info1"){
		document.getElementById("info1").style.display = "none";
		document.getElementById("infonav1").style.backgroundImage = "none";
	}
	if (infoname != "info2"){document.getElementById("info2").style.display = "none";}
	if (infoname != "info3"){document.getElementById("info3").style.display = "none";}
	if (infoname != "info4"){document.getElementById("info4").style.display = "none";}
	if (document.getElementById){document.getElementById(infoname).style.display = "block";}
	else{document[infoname].display = "block";}
	document.getElementById("infonav1").style.backgroundImage = "none";
	document.getElementById("infonav2").style.backgroundImage = "none";
	document.getElementById("infonav3").style.backgroundImage = "none";
	document.getElementById("infonav4").style.backgroundImage = "none";
	if (infoname == "info1"){document.getElementById("infonav1").style.backgroundImage = "url(../images/productinfobg.gif)";}
	if (infoname == "info2"){document.getElementById("infonav2").style.backgroundImage = "url(../images/productinfobg.gif)";}
	if (infoname == "info3"){document.getElementById("infonav3").style.backgroundImage = "url(../images/productinfobg.gif)";}
	if (infoname == "info4"){document.getElementById("infonav4").style.backgroundImage = "url(../images/productinfobg.gif)";}
}