﻿var DWSCurrencyWorld = new Object();
DWSCurrencyWorld.ctrCWorld = 'DWS_Module_CtrIDCurrencyWorld';
DWSCurrencyWorld.ctrCResult = 'DWS_Module_CtrIDCurrencyWorldResult';
DWSCurrencyWorld.isInit = false;
DWSCurrencyWorld.initCount = 0;
DWSCurrencyWorld.popup = false; // use popup div
DWSCurrencyWorld.popupLeft = null;
DWSCurrencyWorld.popupTop = 200;
DWSCurrencyWorld.result = '';
DWSCurrencyWorld.sc1 = null;
//DWSCurrencyWorld.url = 'http://dws01/dws_CurrenciesCalculator/Server.aspx?cmd=';
//DWSCurrencyWorld.url = 'http://76.12.3.132/CurrenciesCalculator/Server.aspx?cmd=';
//DWSCurrencyWorld.url = 'http://localhost:25988/Website/Server.aspx?cmd=';
//DWSCurrencyWorld.url = 'http://localhost/CurrencyRateCalculator/Server.aspx?cmd=';
DWSCurrencyWorld.url = 'http://www.currenciescalculator.com/Server.aspx?cmd=';


DWSCurrencyWorld.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);}
}

DWSCurrencyWorld.init = function(){
    if(this.isInit==false && this.initCount<3){
        this.initCount++;
        var ws = this.url + '204&rand=' + Math.random();
        this.call(ws);
        window.setTimeout("DWSCurrencyWorld.init()",1000);
    }else if(this.isInit==false && this.initCount>=3){
        //alert('Init fail');
    }
}
DWSCurrencyWorld.callBackInit = function(){
    // Get style
    if(typeof DWSCurrencyWorldConfig != 'undefined'){
        for(prop in DWSCurrencyWorldConfig){
            this[prop] = DWSCurrencyWorldConfig[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';
        }else{
            ctr.style.position = 'relative';
            ctr.style.display = 'none';
        }
        
        ctr.innerHTML = '\
            <div style="background:#fff; border:solid 1px #aaa; padding:1px;">\
                <div style="height:16px; background:#ccc; color:#09f;" align="left">&nbsp; <b>World curencies result</b></div>\
                <div id="'+this.ctrCResult+'_Rv" style="background:#eee;"></div>\
            </div>\
            <div id="'+this.ctrCResult+'_Loader" style="position:absolute; top:2px; right:15px; color:#555;"></div>\
            <div onclick="DWSCurrencyWorld.close()" align="center" style="position:absolute; 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>\
        ';
    }
    
    ctr = document.getElementById(this.ctrCWorld);
    if(ctr) ctr.innerHTML = '\
        '+this.result+'\
    ';
    
    this.result='';
}

DWSCurrencyWorld.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);
}
DWSCurrencyWorld.callBack = function() {
    // Off Loading...
    var ld = document.getElementById(this.ctrCResult + '_Loader');    
    if (ld) ld.innerHTML = '';
}

DWSCurrencyWorld.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};
}
DWSCurrencyWorld.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};
}

DWSCurrencyWorld.close = function(){
    var ctr = document.getElementById(this.ctrCResult);
    if(ctr) ctr.style.display = 'none';
}

window.setTimeout("DWSCurrencyWorld.init()",500);
