
// Created on 10/05/2009 6:16:27 PM

//input name, which should be checked on forbidden symbols

var arCheckElements = new Array();

//input name, which should be checked on forbidden symbols

var arRequiredElements = new Array();

//allowed symbols

var gsAllowedSymbols = '';

//error message about forbidden symbols

var gsErrForbiddenSymbols = '';

//error message about forbidden symbols

var gsErrMissingFields = '';

//string which should contains code for additional form validation check

var sAddsValidation = '';

//array for default (from database) field values

var arDefaultValues = new Array();



var bIsFirst = true;

function onFormSubmit(sFormName)

{

    // disabling submit on 'Transfer funds page' if required

    if (sFormName == 'transfers') {

        if(document.transfers.LoginTransfer.selectedIndex != 0) {

            return false;

        }

    } else if (sFormName == 'select_connection') {

        //! May 14, 2007 IRI    Bug #17034 Multibase login screen - its possible to select more then one database

        //!                     - added handling of 'connection' field

        var options = document.forms[sFormName].connection.options;

        var iSelectedCnt = 0;

        for (var i = 0; i < options.length; i++) {

            if (options[i].selected) {

                iSelectedCnt++;

            }

            if (iSelectedCnt > 1) {

                alert(gsErrOnlyOneConnection);

                return false;

            }

        }

    }



    if (bIsFirst && checkFormFields(sFormName) == false) {

        return false;

    }



    //run additional form validation check

    if (bIsFirst && sAddsValidation != '')

        if (eval(sAddsValidation) == false)

            return false;



    // anti double-submit for all forms

    if (bIsFirst) {

        bIsFirst = false;

        window.setTimeout('bIsFirst=true', 100);

        return true;

    }



    return false;

}





function switchAbaSwift() {

    if (document.change_bank_information.ABA != null && document.change_bank_information.ABA.value.length > 0) {

        document.change_bank_information.SWIFT.value = '';

        document.change_bank_information.SWIFT.disabled = true;

        document.change_bank_information.ABA.disabled = false;



        if (layer = document.getElementById('SWIFT_asteriks')) {

            layer.style.display = 'none';

        }

        if (layer = document.getElementById('ABA_asteriks')) {

            layer.style.display = '';

        }



        return true;

    }



    if (document.change_bank_information.SWIFT != null && document.change_bank_information.SWIFT.value.length > 0) {

        document.change_bank_information.ABA.value = '';

        document.change_bank_information.ABA.disabled = true;

        document.change_bank_information.SWIFT.disabled = false;



        if (layer = document.getElementById('SWIFT_asteriks')) {

            layer.style.display = '';

        }

        if (layer = document.getElementById('ABA_asteriks')) {

            layer.style.display = 'none';

        }



        return true;

    }



    if (document.change_bank_information.ABA != null && document.change_bank_information.ABA.value.length == 0 && document.change_bank_information.SWIFT != null && document.change_bank_information.SWIFT.value.length == 0) {

        document.change_bank_information.SWIFT.disabled = false;

        document.change_bank_information.ABA.disabled = false;



        if (layer = document.getElementById('SWIFT_asteriks')) {

            layer.style.display = '';

        }

        if (layer = document.getElementById('ABA_asteriks')) {

            layer.style.display = '';

        }



        return true;

    }



}



/** Check all specified input fields */

function checkFormFields(aFormName) {

    var sFaildLabels = '';

    var sMissingLabels = '';

    var iElemSize = 0;



    var bAbaICanCheck = false;

    var bSwiftICanCheck = false;





    var bAbaCanCheck = false;

    var bSwiftCanCheck = false;

    var bBankAccountCanCheck = false;

    var bTransferAmountCanCheck = false;

    var bSpecialInstructionsCanCheck = false;

    var bIsJ = false;



    if (aFormName == 'change_bank_information') {

        bIsJ = document.change_bank_information.Country.value == 'Japan';

    }

    if (aFormName == 'change_bank_information' && document.change_bank_information.sinkId.value == 'change_bank_information') {

        bIsJ = document.change_bank_information.englishCountry.value == 'Japan';

    }



    if (aFormName == 'revocation_LPOA' && document.revocation_LPOA.TradingAccount.selectedIndex == -1){

        sMissingLabels += (sMissingLabels == '' ? '' : '\n') + ' - ' + gsAccountID;

    }





    if (typeof(arCheckElements) != 'undefined') {

        iElemSize = arCheckElements.length;

    }



    for (var i = 0; i < iElemSize; i++) {

        if (typeof(document.forms[aFormName].elements[arCheckElements[i]].value) == 'undefined') {

            continue;

        }



        if (checkAllowedSymbols(document.forms[aFormName].elements[arCheckElements[i]].value) ==

                false) {

            if ((label = document.getElementById(arCheckElements[i])) != null) {

                sFaildLabels += (sFaildLabels == '' ? '' : '\n') + ' - ' +

                    removeTags(label.innerHTML);

            }

        }

        else if (arCheckElements[i] == 'ABA') {

            bAbaCanCheck = true;

        }

        else if (arCheckElements[i] == 'SWIFT') {

            bSwiftCanCheck = true;

        }

        else if (arCheckElements[i] == 'IntermediaryBankABA') {

            bAbaICanCheck = true;

        }

        else if (arCheckElements[i] == 'IntermediaryBankSWIFT') {

            bSwiftICanCheck = true;

        }

        else if (arCheckElements[i] == 'AccountNumber') {

            bBankAccountCanCheck = true;

        }

        else if (arCheckElements[i] == 'TransferAmount') {

            bTransferAmountCanCheck = true;

        }

        else if (arCheckElements[i] == 'SpecialInst') {

            bSpecialInstructionsCanCheck = true;

        }

    }



    var sError = '';

    if (sFaildLabels != '') {

        sError = gsErrForbiddenSymbols + sFaildLabels;

    }



    if (typeof(arRequiredElements) != 'undefined') {

        iElemSize = arRequiredElements.length;

    }



    for (var i = 0; i < iElemSize; i++) {

        if (typeof(document.forms[aFormName].elements[arRequiredElements[i]].value) == 'undefined') {

            continue;

        }



        if (trim(document.forms[aFormName].elements[arRequiredElements[i]].value) == '' && arRequiredElements[i] != 'ABA') {

            if ((label = document.getElementById(arRequiredElements[i])) != null) {

                sMissingLabels += (sMissingLabels == '' ? '' : '\n') + ' - '

                    + removeTags(label.innerHTML);

            }

        } else  if (arRequiredElements[i] == 'ABA' && !bIsJ) {

            if (trim(document.forms[aFormName].ABA.value) == '' && trim(document.forms[aFormName].SWIFT.value) == '' && document.change_bank_information.Country.value != '')

                sMissingLabels += (sMissingLabels == '' ? '' : '\n') + ' - ' + gsOneOfABA_SWIFT;

        }

    }



    if (aFormName == 'change_bank_information') {

        var bIsUKC = document.change_bank_information.Country.value == 'United Kingdom';

        var bIsUK = document.change_bank_information.IntermediaryBankCountry.value == 'United Kingdom';

        bIsJ = document.change_bank_information.IntermediaryBankCountry.value == 'Japan';

    }





    if (bAbaCanCheck && bSwiftCanCheck && !bIsJ) {

        if (document.forms[aFormName].ABA.value != '') {

            if (checkAbaCode(document.forms[aFormName].ABA.value) == false) {

                if (document.forms[aFormName].ABA.value.length == 9)

                    sError += (sError == '' ? '' : '\n') + gsErrWrongABA;

                else

                    sError += (sError == '' ? '' : '\n') + gsErrWrongLengthABA;

            }

        } else if (document.forms[aFormName].SWIFT.value != '') {

            if (checkSwiftCode(document.forms[aFormName].SWIFT.value) == false) {

                if (document.forms[aFormName].SWIFT.value.length == 6 ||

                        document.forms[aFormName].SWIFT.value.length == 8 ||

                            document.forms[aFormName].SWIFT.value.length == 11) {

                    if (bIsUKC)

                        sError += (sError == '' ? '' : '\n') + gsErrWrongSortCode;

                    else

                        sError += (sError == '' ? '' : '\n') + gsErrWrongSWIFT;

                } else {

                    if (bIsUKC)

                        sError += (sError == '' ? '' : '\n') + gsErrWrongLengthSort;

                    else

                        sError += (sError == '' ? '' : '\n') + gsErrWrongLengthSWIFT;

                }

            }

        }/* else {

            sMissingLabels += (sMissingLabels == '' ? '' : '\n') + ' - ' + gsOneOfABA_SWIFT;

        }*/

    }



    if (bAbaICanCheck && bSwiftICanCheck && !bIsJ) {

        if (document.forms[aFormName].IntermediaryBankABA.value != '') {

            if (checkAbaCode(document.forms[aFormName].IntermediaryBankABA.value) == false) {

                if (document.forms[aFormName].IntermediaryBankABA.value.length == 9)

                    sError += (sError == '' ? '' : '\n') + gsErrWrongABAI;

                else

                    sError += (sError == '' ? '' : '\n') + gsErrWrongLengthABAI;

            }

        } else if (document.forms[aFormName].IntermediaryBankSWIFT.value != '') {

            if (checkSwiftCode(document.forms[aFormName].IntermediaryBankSWIFT.value) == false) {

                if (document.forms[aFormName].IntermediaryBankSWIFT.value.length == 8 ||

                        document.forms[aFormName].IntermediaryBankSWIFT.value.length == 6 ||

                            document.forms[aFormName].IntermediaryBankSWIFT.value.length == 11) {

                    if (bIsUK)

                        sError += (sError == '' ? '' : '\n') + gsErrWrongSortI;

                    else

                        sError += (sError == '' ? '' : '\n') + gsErrWrongSWIFTI;

                } else {

                    if (bIsUK)

                        sError += (sError == '' ? '' : '\n') + gsErrWrongLengthSortI;

                    else

                        sError += (sError == '' ? '' : '\n') + gsErrWrongLengthSWIFTI;

                }

            }

        }

    }

    //+ 07 Mar 2006 Gelin #4425 FXMA - Acceptable Inputs for Bank Account Number Field

    if (bBankAccountCanCheck && document.forms[aFormName].AccountNumber.value != '') {

        if (checkBankAccount(document.forms[aFormName].AccountNumber.value) == false) {

            sError += (sError == '' ? '' : '\n') + gsErrWrongBankAccount;

        }

    }



    //! 10 Apr 2006 Gelin Bug #12670 The transfer amount can be in not format ###.##

    if (bTransferAmountCanCheck && document.forms[aFormName].TransferAmount.value != '') {

        if (checkCurrency(document.forms[aFormName].TransferAmount.value) == false) {

            sError += (sError == '' ? '' : '\n') + gsErrAmountFormat;

        }

    }



    //+ Dec 04, 2007 Kinaram Bug #19133(TCS) FXMA - Crash of FXMA because the

    //                       "Special Instructions" field has unlimited length.

    if (bSpecialInstructionsCanCheck && document.forms[aFormName].SpecialInst.value != '') {

        if (document.forms[aFormName].SpecialInst.value.length > 255) {

            sError += (sError == '' ? '' : '\n') + gsErrWrongLengthSpecialInst;

        }

    }



    if (sMissingLabels != '') {

        if (sError.length > 0) {

            sError += "\n";

        }

        sError = sError + gsErrMissingFields + sMissingLabels;

    }



    if (sError != '') {

        alert(sError);

        return false;

    }



    return true;

}



/** Check string and return true if given string contains forbidden symbols, false - otherwise */

function checkAllowedSymbols(aString) {

    var checkStr = aString.toUpperCase();

    var isFound = 0;



    for (var i = 0; i < checkStr.length; i++) {

        isFound = 0;



        if (checkStr.charAt(i) == '\n' || checkStr.charAt(i) == '\r') {

            continue;

        }



        for (var j = 0; j < gsAllowedSymbols.length; j++) {

            if (checkStr.charAt(i) == gsAllowedSymbols.charAt(j)) {

                isFound = 1;

                break;

            }

        }



        if (isFound == 0) {

            return false;

        }

    }



    return true;

}



/** Check validation of ABA code */

function checkAbaCode(aCode) {

    if (aCode == '' || typeof(aCode) == 'undefined') {

        return false;

    }



    //check length of ABA code

    if (aCode.length != 9) {

        return false;

    }

    //ABA code contains digits only

    for (var i = 0; i < aCode.length; i++) {

        c = parseInt(aCode.charAt(i), 10);

        if (isNaN(c) || !(c >= 0 && c <= 9))

            return false;

    }



    return true;

}



/** */

function checkSwiftCode(aCode) {

    if (aCode == '' || typeof(aCode) == 'undefined') {

        return false;

    }

    //check length of SWIFT code

    if (aCode.length != 6 && aCode.length != 8 && aCode.length != 11) {

        return false;

    }



    if (aCode.length == 6) {

        // SOrt code contains digits only

        var arSortValidSymbols = '0123456789';

        var isFoundSort = 0;



        for (var i = 0; i < aCode.length; i++) {

            isFoundSort = 0;

            for (var j = 0; j < arSortValidSymbols.length; j++) {

                if (aCode.charAt(i) == arSortValidSymbols.charAt(j)) {

                    isFoundSort = 1;

                    break;

                }

            }



            if (isFoundSort == 0) {

                return false;

            }

        }

    } else {

        //SWIFT code contains Latin letters (in upper case), digits and "_".

        var arSwiftValidSymbols = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_';

        var isFound = 0;



        for (var i = 0; i < aCode.length; i++) {

            isFound = 0;



            for (var j = 0; j < arSwiftValidSymbols.length; j++) {

                if (aCode.charAt(i) == arSwiftValidSymbols.charAt(j)) {

                    isFound = 1;

                    break;

                }

            }



            if (isFound == 0) {

                return false;

            }

        }

    }



    return true;

}



//+ 07 Mar 2006 Gelin #4425 FXMA - Acceptable Inputs for Bank Account Number Field

/**

 *  Checks correctness of bank account field

 */

function checkBankAccount(aAccount) {

    if (aAccount == '' || typeof(aAccount) == 'undefined') {

        return false;

    }

    //Account number must contain latin letters and digits only.

    var arAccountValidSymbols = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    var isFound = 0;



    for (var i = 0; i < aAccount.length; i++) {

        isFound = 0;



        for (var j = 0; j < arAccountValidSymbols.length; j++) {

            if (aAccount.charAt(i) == arAccountValidSymbols.charAt(j)) {

                isFound = 1;

                break;

            }

        }



        if (isFound == 0) {

            return false;

        }

    }



    return true;

}



/** Checks form data changing. If data was changed then Submit button should be enabled,

 *  otherwise - disabled.

 *

 *  @param  aForm   form object

 */

function checkDataChanges(aForm) {

    checkDataChanges(aForm, null);

}

function decodeHtml2Text (asSource) {

    var sBufStr = asSource;

    

    sBufStr = sBufStr.replace("&quot;","\"");

    sBufStr = sBufStr.replace("&gt;",">");

    sBufStr = sBufStr.replace("&lt;","<");  

    sBufStr = sBufStr.replace("&amp;", "&");

    sBufStr = sBufStr.replace("&nbsp;", " ");

    return sBufStr;

}



function decodeHtml2Text(asSource) {

    var sBufStr = asSource;



    sBufStr = sBufStr.replace("&quot;","\"");

    sBufStr = sBufStr.replace("&gt;",">");

    sBufStr = sBufStr.replace("&lt;","<");

    sBufStr = sBufStr.replace("&amp;", "&");

    sBufStr = sBufStr.replace("&nbsp;", " ");

    return sBufStr;

}



//! Aug 07, 2008 Kinaram Bug #21885(TCS) FXMA - Banking Information - Sometimes Submit stayes available after removing the changes

function checkBankInfoChanges() {

    var bDataChanged = true;



    if (document.getElementById('InfoAccountHolder1') != null && document.getElementById('InfoAccountHolder1').checked) {

        if (document.getElementById('InfoAccountHolder1').checked &&

            document.change_bank_information.BankName.value            == decodeHtml2Text(arDefaultValues["BankName"]) &&

            document.change_bank_information.BankAddr.value            == decodeHtml2Text(arDefaultValues["BankAddr"]) &&

            document.change_bank_information.City.value                == decodeHtml2Text(arDefaultValues["City"]) &&

            document.change_bank_information.State.value               == decodeHtml2Text(arDefaultValues["State"]) &&

            document.change_bank_information.ZipCode.value             == decodeHtml2Text(arDefaultValues["ZipCode"]) &&

            document.change_bank_information.Country.value             == decodeHtml2Text(arDefaultValues["Country"]) &&

            document.change_bank_information.ABA.value                 == decodeHtml2Text(arDefaultValues["ABA"]) &&

            document.change_bank_information.SWIFT.value               == decodeHtml2Text(arDefaultValues["SWIFT"]) &&

            document.change_bank_information.SpecialInst.value.replace('\r', '')    == decodeHtml2Text(arDefaultValues["SpecialInst"]) &&

            document.change_bank_information.AccountNumber.value       == decodeHtml2Text(arDefaultValues["AccountNumber"]) &&

            document.change_bank_information.IntermediaryBank.value    == decodeHtml2Text(arDefaultValues["IntermediaryBank"]) &&

            document.change_bank_information.IntermediaryBankABA.value     == decodeHtml2Text(arDefaultValues["IntermediaryBankABA"]) &&

            document.change_bank_information.IntermediaryBankSWIFT.value   == decodeHtml2Text(arDefaultValues["IntermediaryBankSWIFT"]) &&

            document.change_bank_information.IntermediaryBankCity.value    == decodeHtml2Text(arDefaultValues["IntermediaryBankCity"]) &&

            document.change_bank_information.IntermediaryBankCountry.value == decodeHtml2Text(arDefaultValues["IntermediaryBankCountry"])){

            bDataChanged = false;

        } else {

            bDataChanged = true;

        }

    }



    if (document.getElementById('InfoAccountCoSigner1') != null && document.getElementById('InfoAccountCoSigner1').checked) {

        if (document.getElementById('InfoAccountCoSigner1').checked &&

            document.change_bank_information.BankName.value            == decodeHtml2Text(arDefaultValues["BankName"]) &&

            document.change_bank_information.BankAddr.value            == decodeHtml2Text(arDefaultValues["BankAddr"]) &&

            document.change_bank_information.City.value                == decodeHtml2Text(arDefaultValues["City"]) &&

            document.change_bank_information.State.value               == decodeHtml2Text(arDefaultValues["State"]) &&

            document.change_bank_information.ZipCode.value             == decodeHtml2Text(arDefaultValues["ZipCode"]) &&

            document.change_bank_information.Country.value             == decodeHtml2Text(arDefaultValues["Country"]) &&

            document.change_bank_information.ABA.value                 == decodeHtml2Text(arDefaultValues["ABA"]) &&

            document.change_bank_information.SWIFT.value               == decodeHtml2Text(arDefaultValues["SWIFT"]) &&

            document.change_bank_information.SpecialInst.value.replace('\r', '')    == decodeHtml2Text(arDefaultValues["SpecialInst"]) &&

            document.change_bank_information.AccountNumber.value       == decodeHtml2Text(arDefaultValues["AccountNumber"]) &&

            document.change_bank_information.IntermediaryBank.value    == decodeHtml2Text(arDefaultValues["IntermediaryBank"]) &&

            document.change_bank_information.IntermediaryBankABA.value     == decodeHtml2Text(arDefaultValues["IntermediaryBankABA"]) &&

            document.change_bank_information.IntermediaryBankSWIFT.value   == decodeHtml2Text(arDefaultValues["IntermediaryBankSWIFT"]) &&

            document.change_bank_information.IntermediaryBankCity.value    == decodeHtml2Text(arDefaultValues["IntermediaryBankCity"]) &&

            document.change_bank_information.IntermediaryBankCountry.value == decodeHtml2Text(arDefaultValues["IntermediaryBankCountry"])) {

            bDataChanged = false;

        } else {

            bDataChanged = true;

        }

    }

    return bDataChanged;

}

/** Checks form data changing. If data was changed then Submit button should be enabled,

 *  otherwise - disabled.

 *

 *  @param  aForm           form object

 *  @param  aExcludeElems   array of excluded elements which should not be checked

 */

function checkDataChanges(aForm, aExcludeElems) {

    var iElCount = aForm.elements.length;

    var bDataChanged = true;

    var bDataChangedJoint = true;



    for (var i = 0; i < iElCount; i++) {

        var elem = aForm.elements[i];

        if (typeof(elem.type) == 'undefined' ||

            (typeof(elem.name) != 'undefined' && inArray(aExcludeElems, elem.name)))

            continue;

    }



    if (aForm.name == 'change_bank_information') {

        bDataChanged = checkBankInfoChanges();

        if (document.getElementById('InfoAccountHolder1').checked)

            aControl = document.getElementById('InfoAccountHolder1')

        else

            aControl = document.getElementById('InfoAccountCoSigner1');



        if (arDefaultValues["Holder"] == aControl.Type) {

            bDataChangedJoint = false;

        }

    }

    changeSubmitBtnStatus(bDataChanged || bDataChangedJoint);

}



/** Gets default value of form element */

function getDefaultValue(elem) {

    //first, try to get defaults from database

    var defaultValue = arDefaultValues[elem.name];

    if (defaultValue != null && defaultValue.length > 0) {

        return defaultValue;

    }

    //else get default element value according element's type

    defaultValue = "";

    if (elem.type == 'text' || elem.type == 'textarea' || elem.type == 'password') {

        defaultValue = (typeof(elem.defaultValue) != 'undefined' ? elem.defaultValue : "");

    } else if (elem.type == 'select-one') {

        //if select hasn't default value, first option is selected

        var defaultIndex = 0;

        for (var i = 0; i < elem.options.length; i++) {

            if (elem.options[i].defaultSelected) {

                defaultIndex = i;

                break;

            }

        }

        defaultValue = elem.options[defaultIndex].value;

    } else if (elem.type == 'radio') {

        defaultValue = (elem.defaultChecked ? elem.value : "");

    }

    return defaultValue;

}



/** Gets current value of form element */

function getCurrentValue(elem) {

    var currentValue = "";



    if (elem.type == 'text' || elem.type == 'textarea' || elem.type == 'password') {

        currentValue = elem.value;

    } else if (elem.type == 'select-one') {

        //if select hasn't default value, first option is selected

        var selectedIndex = elem.selectedIndex;

        if (selectedIndex < 0)

            selectedIndex = 0;

        currentValue = elem.options[selectedIndex].value;

    } else if (elem.type == 'radio') {

        currentValue = (elem.checked ? elem.value : "");

    }



    return currentValue;

}



/** Change enable status of received button. */

function changeButtonStatus(aBtnID, aEnableFlg) {

    if ((btn = document.getElementById(aBtnID)) != null) {

        btn.disabled = !aEnableFlg;

    }

}





/** Change enable status of Submit button. */

function changeSubmitBtnStatus(aEnableFlg) {

    changeButtonStatus('_btn_submit', aEnableFlg);

}



/** Change enable status of Continue button. */

function changeContinueBtnStatus(asForm) {

    var iElName = asForm.name;



    if (iElName == 'WithdrawalForm' && document.forms['WithdrawalForm'].withdrawMethod.value == 'yes') {

        changeButtonStatus('_btn_continue', true);

    }



    if (iElName == 'open_new_account') {

        var aForm = document.forms[0];

        if (aForm.NewAccount[0].checked || aForm.NewAccount[1].checked

            || aForm.TransferFund[0].checked || aForm.TransferFund[1].checked) {

            changeButtonStatus('_btn_submit', true);

        }

    }



    if (iElName == 'revocation_LPOA') {

        var aForm = document.forms[0];

        for (i = 0; i < asForm.elements['acct'].length; i++) {

            if (aForm.acct[i].checked) {

                changeButtonStatus('_btn_submit', true);

            }

        }

    }



    if (iElName == 'managed_funds') {

        var aForm = document.forms[0];

        for (i = 0; i < asForm.elements['TransferFund'].length; i++) {

            if (aForm.TransferFund[i].checked) {

                changeButtonStatus('_btn_continue', true);

            }

        }

    }



    if (iElName == 'margin_requirement_change' && document.forms[0].NewMargin.value != "") {

        changeButtonStatus('_btn_submit', true);

    }

}



/** Returns true if received element contained in received array. */

function inArray(aArray, aElem) {

    if (aArray == null || typeof(aArray) == 'undefined')

        return false;



    for (var i = 0; i < aArray.length; i++)

        if (aArray[i] == aElem)

            return true;



    return false;

}



/** Check validation of currency representation on received string. */

function checkCurrency(asValue) {

    if (asValue == null || asValue.length == 0)

        return false;



    for (var i = 0; i < asValue.length; i++) {

        if ((isNaN(parseInt(asValue.charAt(i)))) && asValue.charAt(i) != '.') {

            return false;

        }

    }

    var fValue = parseFloat(asValue);



    // currency must be a positive number

    if (isNaN(fValue) || fValue <= 0.0)

        return false;



    // suppose currency must have up to two decimal places after point

    if (Math.abs(Math.round(fValue * 100.0) - fValue * 100.0) > 0.0001)

        return false;



    return true;

}



//+ 05/04/2006 Gelin Request #4657 FXMA - Withdrawal - New Field

/** Removes some tags from string value */

function removeTags(asValue) {

    return asValue.replace(/<\S+>/, ' ');

}



//+ Mar 20, 2008 Gelin      Bug #20060(TCS) FXMA - Hedging - user can submit page with no changes

/** Returns true if the selected value is default in select */

function isDefaultValueSelected(aSelect) {

    var option = aSelect.options[aSelect.selectedIndex];

    if (option) {

        return option.defaultSelected;

    }

    return false;

}



//+ Apr 29, 2008 Gelin  Bug #20567  FXMA - withdrawal - its possible to not fill required "please specify" field

/** Trims whitespaces at the beginning and the end of the string */

function trim(aString) {

    if (aString == null) {

        return '';

    }

    return aString.replace(/^\s*|\s*$/g, '');

}



