﻿function compareButton_click() {

    new Effect.Move('divConverterOuter', { mode: 'relative', duration: 0.5, x: -263, y: 0,
        afterFinish: function() {
            $('divConverter').addClassName('addborder');
            $('divConverterOuter').addClassName('converterWhiteBg');
        }
    });

    $('divCompareNowButton').fade({ duration: 0.1 });
    $('divInsightButton').fade({ duration: 0.1 });
    $('divBetterRatesButton').fade({ duration: 0.1 });
    $('divMidRatesButton').fade({ duration: 0.1 });

    $('bestDealTitle').hide();
    $('compareUsTitle').show();
    $('betterRateTitle').hide();

    $('imgBtnClose').show();

    $('divCompare').appear();

    new Effect.Move('divButtonSection', { mode: 'relative', x: 0, y: 30 });

    return false;
}


function betterRateButton_click() {

    new Effect.Move('divConverterOuter', { mode: 'relative', duration: 0.5, x: -263, y: 0,
        afterFinish: function() {
            $('divConverter').addClassName('addborder');
            $('divConverterOuter').addClassName('converterWhiteBg');
        }
    });

    $('divInsightButton').appear();
    $('divCompareNowButton').fade({ duration: 0.1 });
    $('divBetterRatesButton').fade({ duration: 0.1 });
    $('divMidRatesButton').fade({ duration: 0.1 });

    $('bestDealTitle').hide();
    $('compareUsTitle').hide();
    $('betterRateTitle').show();

    $('divBetterRate').appear();

    $('imgBtnClose').show();

    new Effect.Move('divButtonSection', { mode: 'relative', x: 0, y: 30, afterFinish: function() { } });


    return false;
}

function closeButton_click() {


    $('imgBtnClose').hide();
    $('divConverter').removeClassName('addborder');
    $('divConverterOuter').removeClassName('converterWhiteBg');

    new Effect.Move('divConverterOuter', { mode: 'relative', duration: 0.5, x: 263, y: 0, afterFinish: function() { } });

    $('bestDealTitle').show();
    $('compareUsTitle').hide();
    $('betterRateTitle').hide();

    $('divCompare').hide();
    $('divBetterRate').hide();

    new Effect.Move('divButtonSection', { mode: 'relative', duration: 0.5, x: 0, y: -30,
        afterFinish: function() {
            $('divCompareNowButton').appear();
            $('divBetterRatesButton').appear();
            $('divMidRatesButton').appear();
            $('divInsightButton').hide();
        } 
    });


    return false;
}


function imgConverterSubmit_click() {
    $('divRateSection').appear();
    $('divConverterSubmitButton').hide();
}



function button_overout(imgId, isOver) {
    var imgPath = imgId.src;

    if (isOver == true) {
        imgId.src = imgPath.replace(".png", "_over.png");
    }
    else {
        imgId.src = imgPath.replace("_over.png", ".png");
    }
}

function EnteredFocus(txtBoxControl, text) {
    if (txtBoxControl.value == text) {
        txtBoxControl.value = "";

    }
}

function LeftFocus(txtBoxControl, text) {
    if (txtBoxControl.value == "") {
        txtBoxControl.value = text;

    }
}

function TextChangedConverter(txtTargetCtrl, showCtrl, hideCtrl) {
    txtTargetCtrl.value = "Enter";
    $("'" + showCtrl + "'").appear();
    $("'" + hideCtrl + "'").hide();
}

// Removes leading whitespaces
function LTrim(value) {

    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim(value) {

    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim(value) {

    return LTrim(RTrim(value));

}

function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789.";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}



function padZero(str) {

    var charAfterDecimal;

    if (str.indexOf('.') < 0) {
        charAfterDecimal = 0
    }
    else {
        charAfterDecimal = str.length - (str.indexOf('.') + 1);
    }

    if (charAfterDecimal < 2) {
        if (charAfterDecimal == 1)
            str = str + "0";
        else
            str = str + ".00";
    }
    
    return str;
}

function CommaFormatted(amount) {
    var delimiter = ","; // replace comma if desired
    var a = amount.split('.', 2)
    var d = a[1];
    var i = parseInt(a[0]);
    if (isNaN(i)) { return ''; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = new String(i);
    var a = [];
    
    while (n.length > 3) {
        var nn = n.substr(n.length - 3);
        a.unshift(nn);
        n = n.substr(0, n.length - 3);
    }
    if (n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if (d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;
    return amount;
}
