//**********************************************************************************************
//**********************************************************************************************
// functions for getting xml data.
//**********************************************************************************************
//**********************************************************************************************
var xmlHttp;					//variable to contain the xml object.
var myXML = ""; 				//set a global varaible to contain the xml data structure
var xmlHttpAccepted = false;	//set a global variable to determine is xml data is loaded correctly.


//function to pull the xml data out of the specified page so it will be ready to use
function getData(referalPage){
	p_tempPage = referalPage;
	//determine if XMLHttpRequest or ActiveXObject is required to use.
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		// Internet Explorer
		try{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==1) {
			document.getElementById("top10").innerHTML = "<div style='font-size: 11px; font-family: arial, sans-serif; margin: 15px auto; text-align: center; color: #666;'><img style='margin-bottom:5px;' src='/text/content/gateway/images/ajax-loader.gif' border='0' /><br />Loading favorites</div>";
		}
		if(xmlHttp.readyState==4){
			if (xmlHttp.status == 200){
				//document recieved
				xmlHttpAccepted = true;
				myXML = xmlHttp.responseXML;

				if (p_tempPage == "top10"){
					top10();
				}else{
					top10();
				}
			}else{
				alert("The page failed to load, please try again.");
			}
		}
	}
	xmlHttp.open( "GET", "/text/content/gateway/CustomerFavorites.xml", true );
	xmlHttp.send(null);

	return xmlHttp;
}

function top10(){
		// trim blank space at the string
		String.prototype.Trim = function()
		{
			return this.replace(/(^\s*)|(\s*$)/g, "");
		}
 
		// trim blank space at the beginning
		String.prototype.LTrim = function()
		{
			return this.replace(/(^\s*)/g, "");
		}
  
		// trim blank space at the end
		String.prototype.RTrim = function()
		{
			return this.replace(/(\s*$)/g, "");
		}

		if (window.p_product == undefined){
			var tempproduct = "";
		}else{
			var tempproduct = "";
		}

		var myproducts = myXML.getElementsByTagName('Products');

		for (var n = 0; n < myproducts.length; n++){
			var productImage = myproducts[n].getAttribute('S7FamilyImage');
			var productName = myproducts[n].getAttribute('ProductName');
			var productLink = myproducts[n].getAttribute('ProductId');
			var productCat = myproducts[n].getAttribute('SubCategoryName');
			var catName = myproducts[n].getAttribute('CategoryName');
			var categoryCat = myproducts[n].getAttribute('CategoryID');
			var categorySubCat = myproducts[n].getAttribute('SubCategoryId');

			if (categoryCat == "6510") {
				productImage=productImage.Trim();

				tempproduct = tempproduct + "<div class='favorite' id='" + n + "'>"
				tempproduct = tempproduct + "<a href='/jump.jsp?itemType=PRODUCT&itemID=" + productLink + "&path=1%2C2%2C" + categoryCat + "%2C" + categorySubCat + "' onClick=\"s.linkTrackVars='eVar23';s.linkTrackEvents='None';s.eVar23='" + catName + ": Product Link';s.tl(this,'o','" + catName + ": Product Link');\"><img src=\"http://s7ondemand1.scene7.com/is/image/frontgate/" + productImage + "?wid=75&hei=75&fit=hfit,1&qlt=80&op_usm=2.0,0.5,0,0\" /></a><p><a title=\"header=[] body=[<img src='http://s7ondemand1.scene7.com/is/image/frontgate/" + productImage + "?wid=300&qlt=80&op_usm=2.0,0.5,0,0' />] fixedrelx=[-335] fixedrely=[-150] delay=[300] fadespeed=[0.2] fade=[on]\" href='/jump.jsp?itemType=PRODUCT&itemID=" + productLink + "&path=1%2C2%2C" + categoryCat + "%2C" + categorySubCat + "' onClick=\"s.linkTrackVars='eVar23';s.linkTrackEvents='None';s.eVar23='" + catName + ": Product Link';s.tl(this,'o','" + catName + ": Product Link');\">"
				tempproduct = tempproduct + "" + productName + "</a><br /><em><a href='/jump.jsp?itemType=CATEGORY&itemID=" + categorySubCat + "&path=1%2C2%2C" + categoryCat + "%2C" + categorySubCat + "' onClick=\"s.linkTrackVars='eVar23';s.linkTrackEvents='None';s.eVar23='" + catName + ": Category Link';s.tl(this,'o','" + catName + ": Category Link');\">" + productCat + "</a></em></p></div>"
			}
		}
		
		document.getElementById("top10").innerHTML = tempproduct;
}