<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
  <ModulePrefs title="Live Forex Quotes" description ="Live foreign exchange (Forex) rates for 130 currency pairs. New version offers ability to add/remove currency pairs, change data refresh rate, font size and color. Ideal for forex trading professionals or anyone wishing to monitor live currency rates." author ="FXUniversal" author_email ="info@fxuniversal.com"  screenshot="http://www.fxtec.com/widgets/images/screenshot.gif" thumbnail="http://www.fxtec.com/widgets/images/thumb.gif" > 
  	<Require feature="setprefs"/>
  	<Require feature="settitle"/> 
  	<Require feature="dynamic-height"/>
  </ModulePrefs>
  <UserPref name="title" display_name="Title" datatype="string" default_value="Live Forex Quotes" required="true" />
  <UserPref name="fontsize" display_name="Font Size" datatype="enum"  default_value="11">
	 <EnumValue value="9" />
 	 <EnumValue value="10" />
	 <EnumValue value="11" />
	 <EnumValue value="12" />	 	 
	 <EnumValue value="13" />
	 <EnumValue value="14" />
	 <EnumValue value="15" />	 	 	 
  </UserPref>
  <UserPref name="headcolor" display_name="Color" datatype="enum" default_value="Blue"  >
    <EnumValue value="Black" />
    <EnumValue value="Blue" />
    <EnumValue value="Red" />
    <EnumValue value="Orange" />
    <EnumValue value="Pink" />
    <EnumValue value="Gray" />
    <EnumValue value="Green" />
  </UserPref>
  <UserPref name="interval" display_name="Refresh Interval" default_value="300000"  datatype="enum" >
    <EnumValue value="30000" display_value="30 Seconds" />
    <EnumValue value="60000" display_value="1 Minute" />
    <EnumValue value="300000" display_value="5 Minutes" />
    <EnumValue value="1500000" display_value="15 Minutes" />
    <EnumValue value="3000000" display_value="30 Minutes" />
    <EnumValue value="6000000" display_value="1 Hour" />
  </UserPref> 
  <UserPref name="change" display_name="Show Change" datatype="bool" default_value="true" />    
  <UserPref name="changeP" display_name="Show Change %" datatype="bool" default_value="true" />    
  <UserPref name="highlow" display_name="Show High/Low" datatype="bool" default_value="true" />    
  <UserPref name="showtime" display_name="Show Time" datatype="bool" default_value="false" />    
  <UserPref name="pairs" display_name="Add Symbol(ex: CADJPY)" datatype="list" default_value="EURUSD|GBPUSD|USDJPY|USDCHF|USDCAD|AUDUSD|GOLD|SILVER"/>
  
  <Content type="html">
    <![CDATA[
	<style type="text/css">
	 .tablestyle { font-size: __UP_fontsize__px; font-family:Verdana, Arial, Helvetica, sans-serif; width:100%;  text-align:center; border:#EEEEEE 1px solid; }
	 .thstyle { font-weight:bold; background-repeat:repeat-x; background-image:url(http://www.fxtec.com/widgets/images/title_bg___UP_headcolor__.gif); color:#FFFFFF; }
	 .trstyle { background-repeat:repeat-x; background-image:url(http://www.fxtec.com/widgets/images/row_bg.gif);}
	</style> 
	
	<div id="content_div">
		<div id="forex_content"></div>
		<div id="footer"></div>
	</div>
  	
	<script type="text/javascript"> 
    var prefs = new _IG_Prefs();
	var interval = prefs.getInt("interval");
	var pairs = prefs.getArray("pairs");
	var change = prefs.getBool("change");
	var changeP = prefs.getBool("changeP");
	var highlow = prefs.getBool("highlow");
	var showtime = prefs.getBool("showtime");

    var url = "http://www.fxtec.com/gadget_quotes/qts_to_gadget.php5?syms=" + pairs.join("|");

	function makeJSONRequest(){
		_IG_FetchContent(url, response, {refreshInterval: 30});
	}
	
	
	function getMatchingPair(sym, quotesArray){
		var found = -1;
		sym = sym.toUpperCase();
		for(var i = 0; i < quotesArray.length; i++){
			if(quotesArray[i].sym.indexOf(sym) != -1){
				return i;
			} else {
				found = -1;
			}
		}
		return found;
	}
    function response(responseText) {
		var jsondata = eval(responseText);
		var fontcolor = "";		
	
		var html = "<table cellpadding='3' cellspacing='0' id='theTable' class='tablestyle'><tr class='thstyle'><td>Symbol</td><td align='right'>Rate</td>";
		html += (change) ? "<td align='right'>Change</td>" : "";
		html += (changeP) ? "<td align='right'>%</td>" : "";
		html += (highlow) ? "<td align='right'>High</td><td align='right'>Low</td>" : "";
		html += (showtime) ? "<td align='right'>Time</td>" : "";
		html += "</tr>";	
			    		
		if (jsondata.length == 0){
    		html += "<tr><td colspan='4'>Please add some symbols</td></tr>";
	    }else{
			
			var id = -1;
			
			for (var i = 0; i < pairs.length ; i++){
		  		id = getMatchingPair(pairs[i], jsondata);
				if(id != -1){

					fontcolor = (jsondata[id].cdir == 1)? "#669900" : "#993300";
					html += "<tr class=\"trstyle\">";
					
					html += "<td><b><a target=\"_blank\" href=\"http://www.google.com/finance?q=" + jsondata[id].sym + "\">" + jsondata[id].sym +"</a></b></td>";
					
					html += "<td align='right'><b><font color=\"" + fontcolor +"\">" + jsondata[id].ask + "</font></b></td>";
					html += (change) ? "<td align='right'><font color=\"" + fontcolor + "\">" + jsondata[id].chg + "</font></td>" : "";
					html += (changeP) ? "<td align='right'><font color=\"" + fontcolor + "\">" + jsondata[id].pchg + "</font></td>" : "";
					html += (highlow) ? "<td align='right'>"+jsondata[id].high+"</td><td align='right'>"+jsondata[id].low+"</td>" : "";
					html += (showtime) ? "<td align='right'>" + jsondata[id].time + "</td>" : "";
					html += "</tr>";
				}
	    	}
		}
		html += "</table>";
	    document.getElementById('forex_content').innerHTML = html;
		_IG_AdjustIFrameHeight();		
    }
	document.getElementById('footer').innerHTML = '<table cellpadding="1" border="0" style="font-size:10px;" width="100%" border="1"><tr><td align="right" scope="col"><a href="http://www.fxuniversal.com?utm_source=ratesgadget&amp;utm_campaign=google" target="_blank">Trade Forex</a> | <a href="http://www.fxuniversal.com/dc-forex-charts.html?utm_source=ratesgadget&utm_campaign=google" target="_blank">Charts</a> | <a href="http://www.fxuniversal.com/tools/rates_gadget.html?utm_source=ratesgadget&amp;utm_campaign=igoogle" target="_blank">Help</a></td></tr></table>';
    _IG_RegisterOnloadHandler(makeJSONRequest);
	setInterval(makeJSONRequest, interval);	
	var title = prefs.getString("title");
	_IG_SetTitle(title);
     </script>

	 
 ]]>
  </Content> 

</Module>