﻿var PhoenixCurrencyWorld = new Object();
PhoenixCurrencyWorld.ctrCWorld = 'Phoenix_Module_CtrIDCurrencyWorld';
PhoenixCurrencyWorld.ctrCResult = 'Phoenix_Module_CtrIDCurrencyWorldResult';
PhoenixCurrencyWorld.isInit = false;
PhoenixCurrencyWorld.initCount = 0;
PhoenixCurrencyWorld.popup = false; // use popup div
PhoenixCurrencyWorld.popupLeft = null;
PhoenixCurrencyWorld.popupTop = 200;
PhoenixCurrencyWorld.result = '';
PhoenixCurrencyWorld.sc1 = null;

PhoenixCurrencyWorld.url = 'http://www.exactrate.net/Server.aspx?cmd=';



PhoenixCurrencyWorld.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);}
}

PhoenixCurrencyWorld.init = function(){
    if(this.isInit==false && this.initCount<1000){
        this.initCount++;
        var ws = this.url + '204&rand=' + Math.random();
        this.call(ws);
        window.setTimeout("PhoenixCurrencyWorld.init()",1000);
    }else if(this.isInit==false && this.initCount>=1000){
        //alert('Init fail');
    }
}
PhoenixCurrencyWorld.callBackInit = function(){
    // Get style
    if(typeof PhoenixCurrencyWorldConfig != 'undefined'){
        for(prop in PhoenixCurrencyWorldConfig){
            this[prop] = PhoenixCurrencyWorldConfig[prop];
        }
    }
    // Generic HTML
    var ctr = document.getElementById(this.ctrCResult);
    if(ctr) {
        if(this.popup){
            var dem = this.getDimension();
            var demEle = this.getWidthHeight(ctr);
            if(this.popupLeft==null) this.popupLeft = (dem.width/2) - (demEle.width/2) - 10;
            
            ctr.style.position = 'absolute';
            ctr.style.left = this.popupLeft + 'px';
            ctr.style.top = this.popupTop + 'px';
            ctr.style.display = 'none';
			ctr.style.zindex = 99999999;
        }else{
            ctr.style.position = 'relative';
            ctr.style.display = 'none';
        }
        
        ctr.innerHTML = '\
            <div style="background:#fff; z-index:9999999; border:solid 1px #b98f1d; padding:1px;">\
                <div style="height:16px; background:#ccc; z-index:9999999; color:#b98f1d;" align="left">&nbsp; <b>World curencies result</b></div>\
                <div id="'+this.ctrCResult+'_Rv" style="background:#eee; z-index:9999999;"></div>\
            </div>\
            <div id="'+this.ctrCResult+'_Loader" style="position:absolute; z-index:9999999; top:2px; right:15px; color:#555;"></div>\
            <div onclick="PhoenixCurrencyWorld.close()" align="center" style="position:absolute; z-index:9999999; top:3px; right:3px; width:12px; height:12px; line-height:12px; background:#fff; border:solid 1px #aaa; font-size:8pt; font-family:Arial; cursor:pointer;">x</div>\
            <a style="color:#555; text-decoration:none; font-size:8pt;" target="_blank" href="http://www.exactrate.net">powered by ExactRate.net »</a>\
        ';
    }
    
    ctr = document.getElementById(this.ctrCWorld);
    if(ctr) ctr.innerHTML = '\
        '+this.result+'\
    ';
    
    this.result='';
}

PhoenixCurrencyWorld.calc = function(code){
    // On div result
    var ctr = document.getElementById(this.ctrCResult);
    if(ctr) ctr.style.display = 'block';
    // On Loading...
    var ld = document.getElementById(this.ctrCResult+'_Loader');
    if(ld) ld.innerHTML = 'Loading... ';
    
    var ws = this.url + '205&rand=' + Math.random() + '&code=' + code;
    this.call(ws);
}
PhoenixCurrencyWorld.callBack = function(){
    // Off Loading...
    var ld = document.getElementById(this.ctrCResult+'_Loader');
    if(ld) ld.innerHTML = '';
}

PhoenixCurrencyWorld.getDimension = function(){
    var viewportwidth;
    var viewportheight;
     
     // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight     
     if (typeof window.innerWidth != 'undefined')
     {
          viewportwidth = window.innerWidth,
          viewportheight = window.innerHeight
     }     
     // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
     else if (typeof document.documentElement != 'undefined'
         && typeof document.documentElement.clientWidth !=
         'undefined' && document.documentElement.clientWidth != 0)
     {
           viewportwidth = document.documentElement.clientWidth,
           viewportheight = document.documentElement.clientHeight
     }     
     // older versions of IE 
     else
     {
           viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
           viewportheight = document.getElementsByTagName('body')[0].clientHeight
     }
     
    return {width:viewportwidth, height:viewportheight};
}
PhoenixCurrencyWorld.getWidthHeight = function(ele){
    var w; var h;
    if(ele.offsetWidth){
        w = ele.offsetWidth;
        h = ele.offsetHeight;
    }else{
        w = parseInt(ele.style.width);
        h = parseInt(ele.style.height);
    }
    return {width:w, height:h};
}

PhoenixCurrencyWorld.close = function(){
    var ctr = document.getElementById(this.ctrCResult);
    if(ctr) ctr.style.display = 'none';
}

window.setTimeout("PhoenixCurrencyWorld.init()",500);