	/*
	*		Author: Mark Wang
	*		Date: April 2008
	*		
	*		RateCity sponsored link Ad service via JavaScript
	*/

	// global variable - for pop-up product detail page
	var detailWindow;
	//var js_service = "http://test.ratecity.com.au/js/";
	var js_service = "http://www.ratecity.com.au/js/";

	function loadRateCityTable(url)
	{
		var headID = document.getElementsByTagName("head")[0];
		var newScript = document.createElement("script");

		newScript.type = "text/javascript";
		newScript.src = url;
		headID.appendChild(newScript);
	}

	function ratecityTable(jData)
	{

		var response = "";

		if (jData.error.length > 0)
		{
			response += "<table class=\"ratecity_error\">";
			response += "<tr><td align=\"center\"><b>RateCity Error: " + jData.error + "</b></td></tr>";
			response += "</table>";
		} else
		{
			response += "<div class=\"ratecity_top\"><h2 class=\"ratecity_tablehead\">" + jData.title + "</h2></div>";
			response += "<table class=\"ratecity_list\">";

			if (jData.msg.length > 0)
			{
				response += "<tr>";
				response += "<td align=\"center\">" + jData.msg + "</td>";
				response += "</tr>";
			} else
			{
				response += "<tr class=\"ratecity_header\">";

				for (i = 0;i < jData.header.length;i++)
				{
					response += "<td align=\"center\">" + jData.header[i].name + "</td>";
				}

				response += "</tr>";

				for (i = 0;i < jData.product.length;i++)
				{
					if ((i % 2) == 0)
					{
						response += "<tr class=\"ratecity_rowodd\">";
					} else
					{
						response += "<tr class=\"ratecity_roweven\">";
					}

					response += "<td class=\"ratecity_company\">" + jData.product[i].field1 + "</td>";
					response += "<td class=\"ratecity_product\">" + jData.product[i].field2 + "</td>";
					response += "<td class=\"ratecity_rate\">" + jData.product[i].field3 + "</td>";
					response += "<td class=\"ratecity_apply\">" + jData.product[i].field4 + "</td>";
					response += "</tr>";
				}
			}

			response += "</table>";
			response += "<div class=\"ratecity_footer\">";
			if (jData.footer.url.length > 0)
			{
				response += "<a href=\"" + jData.footer.url + "\" target=\"_blank\" title=\"" + jData.footer.url_title + "\"><img src=\"" + jData.footer.image + "\" alt=\"" + jData.footer.image_alt + "\" border=\"0\"></a>";
			} else
			{
				response += "<img src=\"" + jData.footer.image + "\" alt=\"" + jData.footer.image_alt + "\" border=\"0\">";
			}

			response += jData.footer.notes + "</div>";

			response += "<!-- Debug";
			response += "jp_ip:" + jData.client.js_ip;
			response += "js_domain:" + jData.client.js_domain;
			response += "-->";
		}

		document.getElementById(jData.tableid).innerHTML = response;
		document.close();
	}

	function openProductDetail(country, type, view, recno)
	{
		detailWindow = window.open("","_blank","Scrollbars=1,menubar=0,toolbar=0,status=0,resizable=1,width=500,height=600,left=150,top=50");
		loadRateCityTable(js_service + "ratecity_products.php?country=" + country + "&type=" + type + "&view=" + view + "&recno=" + recno + "&domain=" + document.domain + "&callback=ratecityProductDetail");
	}

	function ratecityProductDetail(jData)
	{
		detailWindow.document.write("<!-- RateCity product detail start -->");
		detailWindow.document.write("<html><head><title>RateCity Product Detail - ratecity.com.au</title>");

		if (css["detail"] != "")
		{
			detailWindow.document.write("<link rel=\"stylesheet\" href=\"" + css["detail"] + "\" type=\"text/css\" />");
		}

		detailWindow.document.write("</head><body>");

		if (jData.error.length > 0)
		{
			detailWindow.document.write("<table class=\"ratecity_error\">");
			detailWindow.document.write("<tr><td align=\"center\">RateCity Error: " + jData.error + "</td></tr>");
			detailWindow.document.write("</table>");
		} else
		{
			detailWindow.document.write("<table cellspacing=\"0\" class=\"ratecity_productdetail\">");
			detailWindow.document.write("<tr><td class=\"ratecity_poweredby\"><img src=\"" + jData.rclogo + "\" alt=\"" + jData.rclogo_alt + "\" border=\"0\"></td>");
			detailWindow.document.write("<td class=\"ratecity_clientlogo\"></td></tr>");

			for (i = 0;i < jData.fieldname.length;i++)
			{
				if ((i % 2) == 0)
				{
					detailWindow.document.write("<tr class=\"ratecity_rowodd\">");
				} else
				{
					detailWindow.document.write("<tr class=\"ratecity_roweven\">");
				}

				detailWindow.document.write("<td>" + jData.fieldname[i].name + "</td>");

				if (jData.fieldname[i].name == "Online Application")
				{
					detailWindow.document.write("<td class=\"ratecity_apply\">" + jData.fielddata[i].value + "</td>");
				} else
				{
					detailWindow.document.write("<td>" + jData.fielddata[i].value + "</td>");
				}

				detailWindow.document.write("</tr>");
			}

			detailWindow.document.write("</table>");
		}

		detailWindow.document.write("</body></html>");
		detailWindow.document.write("<!-- RateCity product detail end -->");
		detailWindow.document.close();
	}

	// start output the table data
	document.writeln("<!-- RateCity top table start -->");

	if (css["table"] != "")
	{
		document.writeln("<link rel=\"stylesheet\" href=\"" + css["table"] + "\" type=\"text/css\" />");
	}

	document.writeln("<div id=\"ratecityTable_" + prod["country"] + prod["type"] + prod["view"] + "\"><img src=\"" + js_service + "loading_progress.gif\" alt=\"Loading...\"><br>Loading...</div>");
	document.writeln("<!-- RateCity top table end -->");

	loadRateCityTable(js_service + "ratecity_products.php?country=" + prod["country"] + "&type=" + prod["type"] + "&view=" + prod["view"] + "&num=" + prod["num"] + "&domain=" + document.domain + "&callback=ratecityTable");

