﻿var PhoenixCurrencyCalculator = new Object();
PhoenixCurrencyCalculator.ctrCRCalculator = 'Phoenix_Module_CtrIDCRCalculator';
PhoenixCurrencyCalculator.isInit = false;
PhoenixCurrencyCalculator.initCount = 0;
PhoenixCurrencyCalculator.result = '';
PhoenixCurrencyCalculator.sc1 = null;
PhoenixCurrencyCalculator.url = 'http://www.exactrate.net/Server.aspx?cmd=';


PhoenixCurrencyCalculator.styleButton = 'width:60px; color:#fff; border:0; background:#b98f1d;';
PhoenixCurrencyCalculator.styleSelect = 'border:solid 1px #b98f1d;';
PhoenixCurrencyCalculator.styleInput = 'border:solid 1px #b98f1d;';

PhoenixCurrencyCalculator.styleTableResult = 'background:#fcbb16; color:#444; font-weight:normal; border-left:solid 1px #b98f1d; border-top:solid 1px #b98f1d; font-size:8pt;';
PhoenixCurrencyCalculator.styleTableResultTr = '';
PhoenixCurrencyCalculator.styleTableResultTd = 'border-right:solid 1px #b98f1d; border-bottom:solid 1px #b98f1d;';
PhoenixCurrencyCalculator.styleTableResultTdTitle = 'background:#b98f1d; border-right:solid 1px #b98f1d; border-bottom:solid 1px #b98f1d; color:#fff; font-size:9pt; height:12px; line-height:12px; font-weight:bold; text-align:left;';
PhoenixCurrencyCalculator.styleTableResultTrAlternate = 'background:#DFFFCE;';

PhoenixCurrencyCalculator.call = function(ws){
    // Remove tag script scriptData
    if(this.sc1) this.sc1.parentNode.removeChild(this.sc1);
    
    // Script tag auto call
    this.sc1 = document.createElement('SCRIPT');
    this.sc1.id = 'sc1';
    this.sc1.type = 'text/javascript';
    this.sc1.src = ws;
    
    // Append script tag
    try{document.getElementsByTagName('head')[0].appendChild(this.sc1);}
    catch(ex){document.body.appendChild(this.sc1);}
}

PhoenixCurrencyCalculator.init = function(){
    if(this.isInit==false && this.initCount<3){
        this.initCount++;
        var ws = this.url + '201&rand=' + Math.random();
        this.call(ws);
        window.setTimeout("PhoenixCurrencyCalculator.init()",1000);
    }else if(this.isInit==false && this.initCount>=3){
        //alert('Init fail');
    }
}
PhoenixCurrencyCalculator.callBackInit = function(){
    // Get style
    if(typeof PhoenixCurrencyCalculatorConfig != 'undefined'){
        for(prop in PhoenixCurrencyCalculatorConfig){
            this[prop] = PhoenixCurrencyCalculatorConfig[prop];
        }
    }
    // Generic HTML
    var ctr = document.getElementById(this.ctrCRCalculator);
    if(ctr) ctr.innerHTML = '\
    <table border="0" cellpadding="3" cellspacing="0" style="font-size:8pt;">\
        <tr><td align="right">Convert</td><td><input style="'+this.styleInput+'" type="text" id="'+this.ctrCRCalculator+'_Num" value="1.00" maxlength="9" onkeypress="PhoenixCurrencyCalculator.hitEnter(event)"/></td></tr>\
        <tr><td align="right">From</td><td><select id="'+this.ctrCRCalculator+'_From" style="'+this.styleSelect+'">'+this.result+'</select></td></tr>\
        <tr><td align="right">To</td><td><select id="'+this.ctrCRCalculator+'_To" style="'+this.styleSelect+'">'+this.result+'</select></td></tr>\
        <tr><td align="right" colspan="2"><span style="display:none;" id="'+this.ctrCRCalculator+'_Loader">Loading...&nbsp;</span><input type="button" value="Go" style="'+this.styleButton+'" onclick="PhoenixCurrencyCalculator.calc();"/></td></tr>\
    </table>\
    <div style="font-size:1px; line-height:1px; height:8px;"></div>\
    <table style="'+this.styleTableResult+'" border="0" cellpadding="3" cellspacing="0" width="100%">\
        <tr style="'+this.styleTableResultTr+'">\
            <td style="'+this.styleTableResultTdTitle+'" colspan="6">Currency Conversion Results</td>\
        </tr>\
        <tr style="'+this.styleTableResultTrAlternate+' font-weight:bold;">\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_F_Txt"></span></td>\
            <td style="'+this.styleTableResultTd+'" colspan="2" align="center">Exchange Rate</td>\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_T_Txt"></span></td>\
            <td style="'+this.styleTableResultTd+'" align="center">Bid</td>\
            <td style="'+this.styleTableResultTd+'" align="center">Ask</td>\
        </tr>\
        <tr style="'+this.styleTableResultTr+'">\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_N_Val"></span></td>\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_D_Val"></span></td>\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_T_Val1"></span></td>\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_T_Val2"></span></td>\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_B_Val"></span></td>\
            <td style="'+this.styleTableResultTd+'" align="center"><span id="'+this.ctrCRCalculator+'_Rs_A_Val"></span></td>\
        </tr>\
        <tr style="'+this.styleTableResultTrAlternate+'">\
            <td style="'+this.styleTableResultTd+' text-align:right; height:12px; line-height:12px;" colspan="6">\
                <a style="color:#555; text-decoration:none; font-size:8pt;" target="_blank" href="http://www.exactrate.net">powered by ExactRate.net »</a>\
            </td>\
        </tr>\
    </table>';
    
    this.result='';
    
    var ctrT = document.getElementById(this.ctrCRCalculator+'_To');
    if(ctrT) ctrT.selectedIndex = 0;
    
    // Default calculator
    this.calc();
}

PhoenixCurrencyCalculator.calc = function(){
    // On Loading...
    var ld = document.getElementById(this.ctrCRCalculator+'_Loader');
    if(ld) ld.style.display = '';
    //
    var ctrN = document.getElementById(this.ctrCRCalculator+'_Num');
    var ctrF = document.getElementById(this.ctrCRCalculator+'_From');
    var ctrT = document.getElementById(this.ctrCRCalculator+'_To');
    if((ctrF)&&(ctrT)&&(ctrN)){
        var vN = ctrN.value;
        var vF = ctrF.options[ctrF.selectedIndex].value;
        var vT = ctrT.options[ctrT.selectedIndex].value;
        var ws = this.url + '202&rand=' + Math.random() + '&n='+vN+'&f='+vF+'&t='+vT;
        this.call(ws);
    }
}
PhoenixCurrencyCalculator.callBack = function(){
    // Off Loading...
    var ld = document.getElementById(this.ctrCRCalculator+'_Loader');
    if(ld) ld.style.display = 'none';
}

PhoenixCurrencyCalculator.hitEnter = function(evt){
    if(evt.keyCode == 13) { this.calc(); return false; }
}

window.setTimeout("PhoenixCurrencyCalculator.init()",500);