﻿function CreateBookmarkLink() {
    var url = location.href;
    var title = "My favourite";
    if (window.sidebar) { // firefox
        window.sidebar.addPanel(title, url, "");
    } else if (document.all) { //MSIE
        window.external.AddFavorite(url, title);
    } else {
        alert("Sorry, your browser doesn't support this");
    }
}

function toppage()
{ window.scrollTo(0, 0); }

function ShowPopupForm(navigationURL) {
    window.radopen(navigationURL, "rdw");
    return false;
}

function adslide_vivn() {
    $(document).ready(function() {
        $('#adslide').after('<div id="nav" class="nav">Sản phẩm mới > ').cycle({
            fx: 'fade',
            speed: 'fast',
            timeout: 5000,
            pager: '#nav'
        });
    });
}

function adslide_enus() {
    $(document).ready(function() {
        $('#adslide').after('<div id="nav" class="nav">New products > ').cycle({
            fx: 'fade',
            speed: 'fast',
            timeout: 5000,
            pager: '#nav'
        });
    });
}

function ShowGoldPrice(navigationURL) {
    var oWnd = window.radopen(navigationURL + '?width=779&height=434&scroll=0', 'rdwGold');
    oWnd.setSize(830, 435);
    oWnd.center();
    return false;
}

function ShowForeignExchange(navigationURL) {
    var oWnd = window.radopen(navigationURL + '?width=800&height=510&scroll=0', 'rdwForeignExchange');
    oWnd.setSize(850, 510);
    oWnd.center();
    return false;
}

function ShowStockMarket(navigationURL) {
    var oWnd = window.radopen(navigationURL + '?width=930&height=600&scroll=1', 'rdwStockMarket');
    oWnd.setSize(600, 620);
    oWnd.center();
    return false;
}

function ShowWeather(navigationURL) {
    var oWnd = window.radopen(navigationURL + '?width=780&height=500&scroll=1', 'rdwWeather');
    oWnd.setSize(800, 530);
    oWnd.center();
    return false;
}

function ShowSendToFriendForm(navigationURL) {
    var oWnd = window.radopen(navigationURL, "rdwSendToFriend");
    oWnd.setSize(720, 500);
    oWnd.center();
    return false;
}

function ShowFeedbackForm(navigationURL) {
    var oWnd = window.radopen(navigationURL, "rdwFeedback");
    oWnd.setSize(720, 520);
    oWnd.center();
    return false;
}
function ShowQuestionForm(navigationURL) {
    var oWnd = window.radopen(navigationURL, "rdwQuestion");
    oWnd.setSize(720, 520);
    oWnd.center();
    return false;
}




function checkCcValue(pan) {
    newPan = "";
    ll = pan.length;
    for (i = 0; i < ll; i++) {
        strNumber = pan.charAt(i);
        if (strNumber != " ") newPan = newPan + strNumber;
    }

    pan = newPan;
    // check modulo-10

    iSuma = 0;
    ll = pan.length;
    for (i = 0; i < ll; i++) {
        strNumber = pan.charAt(ll - i - 1);

        if ("1234567890".indexOf(strNumber) < 0) {
            return false;
        }
        iValue = parseInt(strNumber);
        if ((i + 1) % 2 == 0) {
            iValue = 2 * iValue;
            if (iValue >= 10) {
                iValue = 1 + iValue - 10;
            }
        }
        iSuma = iSuma + iValue;
    }

    if (!((iSuma > 0) && (iSuma % 10 == 0))) {
        return false;
    }

    // check branch

    brand = "none";
    ident = "00";

    if (typeof (document.paymentmethod.length) != 'undefined') {
        ll = document.paymentmethod.length;
        for (i = 0; i < ll; i++) {
            if (document.paymentmethod[i].checked) {
                brand = document.paymentmethod[i].value;
            }
        }
    }
    else {
        brand = document.paymentmethod.value;
    }

    brand = brand.substring(0, 3);

    if ((brand == "VIS") && (pan.substring(0, 1) != "4")) return false;
    if ((brand == "ECA") && (pan.substring(0, 1) != "5")) return false;

    ident = pan.substring(0, 2);
    if (brand == "AMX") {
        if ((ident != "34") && (ident != "37")) return false;
    }
    if (brand == "DIN") {
        if ((ident != "30") && (ident != "36") && (ident != "38") && (ident != "39")) return false;
    }
    return true;

}


function checkValues(cvv_req) {

    if ((typeof (document.cardno) != 'undefined') && !checkCcValue(document.cardno.value)) {
        alert(document.Wrongcardnumber.value);
        return;
    }
    if ((typeof (document.cvv) != 'undefined') && (cvv_req == 'true')) {
        cvv = document.cvv.value;
        ll = cvv.length;

        if (ll == 0) {
            alert(document.CVVcodeismissing.value);
            return;
        }

        for (i = 0; i < ll; i++) {
            strNumber = cvv.charAt(i);

            if ("1234567890".indexOf(strNumber) < 0) {
                alert(document.CVVcodeisnotnumeric.value);
                return;
            }
        }
    }
    if ((typeof (document.bankaccount) != 'undefined')) {
        bankacc = document.bankaccount.value;
        le = bankacc.length;
        if (le == 0) {
            alert(document.Bankaccountmustnotbeempty.value);
            return;
        }
        for (i = 0; i < le; i++) {
            strNumber = bankacc.charAt(i);

            if ("1234567890".indexOf(strNumber) < 0) {
                alert(document.Bankaccountmustbenumeric.value);
                return;
            }
        }
        if (le < 10) for (i = le; i < 10; i++) bankacc = '0' + bankacc;
        document.bankaccount.value = bankacc;
    }
    if ((typeof (document.bankrouting) != 'undefined')) {
        bankrou = document.bankrouting.value;
        le = bankrou.length;
        if (le == 0) {
            alert(document.Bankroutingmustnotbeempty.value);
            return;
        }
        for (i = 0; i < le; i++) {
            strNumber = bankrou.charAt(i);

            if ("1234567890".indexOf(strNumber) < 0) {
                alert(document.Bankroutingmustbenumeric.value);
                return;
            }
        }
        if (le < 8) for (i = le; i < 8; i++) bankrou = '0' + bankrou;
        document.bankrouting.value = bankrou;
    }
    if (epsMet) {
        var elems = document.getElementsByName("sub_application");
        if (elems.length == 0) return;
        var selFound = false;
        for (i = 0; i < elems.length; i++) {
            if (elems[i].checked) selFound = true;
        }
        if (!selFound) {
            alert(document.Selectbankplease.value);
            return;
        }
    }
    if (idealMet) {
        var elems = document.getElementsByName("sub_application");
        if (elems.length == 0) return;
        var selFound = false;
        for (i = 0; i < elems.length; i++) {
            if (elems[i].checked) selFound = true;
        }
        if (!selFound) {
            alert(document.Selectbankplease.value);
            return;
        }
    }
    if (((typeof (document.expm) == 'undefined') || (document.expm.value.length > 0)) &&
			((typeof (document.expy) == 'undefined') || (document.expy.value.length > 0)) &&
			((typeof (document.cardsqnr) == 'undefined') || (document.cardsqnr.value.length == 0) || (document.cardsqnr.value.length == 3)) &&
			((typeof (document.pin) == 'undefined') || (document.pin.value.length > 0))) {
        document.okbut.disabled = true;
        document.submit();
    }
    else {
        alert(document.Importantpaymentdetailmissing.value);
    }
}
