function handleSuccessRate(o)
{
	if(o != undefined)
	{
		var root = Xparse(o);
		
		var errorTag = document.getElementById("rates_error");
		if (errorTag != undefined)
		{
			if (o.indexOf("<?xml") != 0)
			{
				errorTag.innerHTML = o;
			}
			else
			{
				errorTag.innerHTML = "";
			}
		}

		if (root.contents != undefined)
		{
			for (var i = 0; i < root.contents.length - 1; i++)
			{
				if (root.contents[i].type == "element" && root.contents[i].name == "rates")
				{
					var rates = root.contents[i];
				}
			}

			if (rates != undefined)
			{
				for (var i = 0; i < rates.contents.length - 1; i++)
				{
					if (rates.contents[i].type == "element" && rates.contents[i].name == "rate")
					{
						var curRateSymbol = rates.contents[i].attributes.symbol;
		
						var rateTag = document.getElementById(curRateSymbol);
						if (rateTag != undefined)
						{
							var prevRateBidTag = document.getElementById(curRateSymbol + "_bid");
							var prevRateBidTag2 = document.getElementById(curRateSymbol + "2_bid");
							if (prevRateBidTag != undefined)
							{
								
								var prevRateBid = prevRateBidTag.innerHTML;
								var prevRateBid3 = "#"+curRateSymbol + "_bid";
								var prevRateBid4 = "#"+curRateSymbol + "2_bid";
								var curRateBid = rates.contents[i].attributes.bid;
								if(!isNaN(parseFloat(prevRateBid)) && prevRateBid==0)
								{
									
								}
								else if (!isNaN(parseFloat(prevRateBid)) && curRateBid > prevRateBid)
								{
									//prevRateBidTag.className = "bid, up1";
									//changecolorup(prevRateBidTag);
									if(curRateSymbol=='GCUSD' || curRateSymbol=='SIUSD')
									{
										changecolorup(prevRateBid3);
										//changecolorup("#"+curRateSymbol + "_ask");
									}else
									{
										changecolorup(prevRateBid3);
									}
									//prevRateBidTag2.innerHTML ="<img src=\"images/up.gif\" />";
									//$('#pricefeed_container').find(prevRateBid4).html('<img src=\"images/up.gif\" />');
									//$('.ratebox').find(prevRateBid4).html('<img src=\"images/up.gif\" />');
								}
								else if (!isNaN(parseFloat(prevRateBid)) && curRateBid < prevRateBid)
								{
									//changecolordown(prevRateBidTag);
									if(curRateSymbol=='GCUSD' || curRateSymbol=='SIUSD')
									{
										changecolordown(prevRateBid3);
										//changecolordown("#"+curRateSymbol + "_ask");
									}else
									{
										changecolordown(prevRateBid3);
									}
									//prevRateBidTag2.innerHTML ="<img src=\"images/down.gif\" />";
									//$('#pricefeed_container').find(prevRateBid4).html('<img src=\"images/down.gif\" />');
									//$('.ratebox').find(prevRateBid4).html('<img src=\"images/down.gif\" />');
								}
								//prevRateBidTag.innerHTML = curRateBid;
								$('table').find(prevRateBid3).html(curRateBid);
								//$('.feed_pair_container_content').find(prevRateBid3).html(curRateBid);								
							}
										
							var prevRateAskTag = document.getElementById(curRateSymbol + "_ask");
							if (prevRateAskTag != undefined)
							{
								var prevRateAsk = prevRateAskTag.innerHTML;
								var prevRateAsk3 = "#"+curRateSymbol + "_ask";
								var prevRateAsk4 = "#"+curRateSymbol + "2_ask";
								var curRateAsk = rates.contents[i].attributes.ask;
								if (!isNaN(parseFloat(prevRateAsk)) && prevRateAsk==0)
								{
								}
								else if (!isNaN(parseFloat(prevRateAsk)) && curRateAsk > prevRateAsk)
								{
									//revRateAskTag.className = "ask, up";
									if(curRateSymbol=='GCUSD' || curRateSymbol=='SIUSD')
									{
										changecolorup(prevRateAsk3);
										//changecolorup("#"+curRateSymbol + "_bid");
									}else
									{
										changecolorup(prevRateAsk3);	
									}
									
								}
								else if (!isNaN(parseFloat(prevRateAsk)) && curRateAsk < prevRateAsk)
								{
									//prevRateAskTag.className = "ask, down";
									if(curRateSymbol=='GCUSD' || curRateSymbol=='SIUSD')
									{
										changecolordown(prevRateAsk3);
										//changecolordown("#"+curRateSymbol + "_bid");
									}else
									{
										changecolordown(prevRateAsk3);	
									}	
								}
								$('table').find(prevRateAsk3).html(curRateAsk);
								
							}

							var prevRateHighTag = document.getElementById(curRateSymbol + "_high");
							if (prevRateHighTag != undefined)
							{
								prevRateHighTag.innerHTML = rates.contents[i].attributes.high;
							}
						
							var prevRateLowTag = document.getElementById(curRateSymbol + "_low");
							if (prevRateLowTag != undefined)
							{
								prevRateLowTag.innerHTML = rates.contents[i].attributes.low;
							}
						}
					}
				}
			}
		}
	}
};
function changecolorup(v)
{
	//$('table').find(v).animate( { 'color':"#ff0000"}, 500 ).animate( { 'color':"#a3cce3"}, 100 );
	$('table').find(v).css('color','#ff0000');
	
}
function changecolordown(v)
{
	//$('table').find(v).animate( { "color":"#051f2a"}, 500 ).animate( { "color":"#a3cce3"}, 100 );
	$('table').find(v).css('color','#051f2a');
}

function refresh_currency()
{
	$.ajax({
		method: "GET",
		url: "php/rates.php",
		datatype: "xml",
		//data: "page="+content_show,
		//beforeSend: function(){$("#loading").show();}, //show loading just when link is clicked
		//error: function(){$("#error").fadeIn(500);},
		complete: function(){/* $("#loading").fadeOut(500);*/}, //stop showing loading when the process is complete
		success: function(res){ //so, if data is retrieved, store it in html
			$(".query_response").text(res); //animation
			//$(".content").text(html); //show the html inside .content div
			handleSuccessRate(res);
		}
	}); //close 

	window.setTimeout('refresh_currency()', ratesRefresh * 1000);	
}
function refresh_currency2()
{
	$.ajax({
		method: "GET",
		url: "php/rates2.php",
		datatype: "xml",
		//data: "page="+content_show,
		//beforeSend: function(){$("#loading").show();}, //show loading just when link is clicked
		error: function(){/*$("#error").fadeIn(500);*/},
		complete: function(){/* $("#loading").fadeOut(500);*/}, //stop showing loading when the process is complete
		success: function(res){ //so, if data is retrieved, store it in html
			$(".query_response").text(res); //animation
			//$(".content").text(html); //show the html inside .content div
			handleSuccessRate(res);
		}
	}); //close 

	window.setTimeout('refresh_currency2()', ratesRefresh * 1000);	
}
