 /* - - - - - - - - - - - - - - - - - - - - - - -
JavaScript
Wednesday, July 25, 2007 8:27:22 PM
Author: Jim McMillan
Purpose: This allows the calling page to submit form data to a specified URL and contains Simple Mouse Over effects
for processing and return the reults in the designated <div> tag
- - - - - - - - - - - - - - - - - - - - - - - */
var fadeOutInterval;
var fadeInInterval;
var pageLoadInterval;
var underlay;
var currentStep = "step1";
var isIE = (navigator.userAgent.indexOf('MSIE') > 0);

function checkFileType(sid){
    var field = document.getElementById(sid)
    if (field) {
        if (field.value.indexOf('jpg') > 0 || field.value.indexOf('gif') > 0 || field.value.indexOf('png') > 0) {
            return true;
        } else {
            alert('File Type must be jpg, gif, or png format');
            return false;
        }
    }
}

function mOver(e) {
    e.style.backgroundColor = "#ffcc00";
    e.style.color = "#000000";
}

function mOut(e) {
    e.style.backgroundColor = "";
    e.style.color = "";
}

function xmlhttpPost(strURL, divID,showgif) {
    var xmlHttpReq = false;
    var self = this;
    sformData = getquerystring();
    if (showgif) {
        document.getElementById(divID).innerHTML = '<div valign="middle" align="center"><img src="/images/loadingbar.gif"></div>';
    }
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText, divID);
        }
    }
    self.xmlHttpReq.send(sformData);
}

function getquerystring() {
    var oform
    var oelement
    var qstr = ''
    var oforms = document.getElementsByTagName('form');
    for (i = 0; i < oforms.length; i++) {
        oform = oforms[i];
        if (oform) {
            for (j = 0; j <= oform.elements.length - 1; j++) {
                oelement = oform.elements[j];
                if (oelement.name) {
                    switch (oelement.type) {
                        case 'radio':
                        case 'checkbox':
                            if (oelement.checked) {
                                if (qstr != '') {
                                    qstr += '&' + oelement.name + '=' + escape(oelement.value);
                                } else {
                                    qstr = oelement.name + '=' + escape(oelement.value);
                                }
                            }
                            break;
                        default:
                            if (qstr != '') {
                                qstr += '&' + oelement.name + '=' + escape(oelement.value);
                            } else {
                                qstr = oelement.name + '=' + escape(oelement.value);
                            }
                            break;
                    }
                }
            }
        }
    }
    return qstr;
}

function updatepage(str, divID) {
    document.getElementById(divID).innerHTML = str;
    pageLoadInterval = setInterval("dofadeIn('" + divID + "','pageLoadInterval')",110);
}

function dofadeOut(sid, intervalID,nextcmd) {
    var e = document.getElementById(sid);
    var currentalpha;
    if (!isIE) {
        currentalpha = e.style.opacity;
        if (currentalpha == '') { currentalpha = 1; }
        if (currentalpha > 0) {
            e.style.opacity = currentalpha - .2
        } else {
            e.style.opacity = 0;
            e.style.visibility = 'hidden';
            clearInterval(eval(intervalID));
            eval(nextcmd);
        }
    } else {
        for (i = 0; i < e.children.length; i++) {
            var ochild = e.children[i];
            if (ochild.style.filter != '') {
                currentalpha = ochild.filters.alpha.opacity;
            } else {
                currentalpha = 100;
            }
            if (currentalpha > 0) {
                ochild.style.filter = 'alpha(opacity=' + (currentalpha - 25) + ')';
            }
        }
        if (currentalpha <= 0) {
            e.style.visibility = 'hidden';
            clearInterval(eval(intervalID));
            eval(nextcmd);
        }
    }
}
function dofadeIn(sid, intervalID) {
    var e = document.getElementById(sid);
    window.scrollTo(0, 0);
    var currentalpha;
    e.style.visibility = 'visible';
    if (!isIE) {
        currentalpha = e.style.opacity;
        if (currentalpha == '') { currentalpha = 0; }
        if (currentalpha < 1) {
            e.style.opacity = (parseFloat(currentalpha) + 0.2);
        } else {
            e.style.opacity = 1;
            clearInterval(eval(intervalID));
        }
    } else {
        if (e.style.filter != '') {
            currentalpha = e.filters.alpha.opacity;
        } else {
            currentalpha = 0;
        }
        if (currentalpha <= 100) {
            if (currentalpha == 100) {
                e.style.filter = '';
            } else {
                e.style.filter = 'alpha(opacity=' + (currentalpha + 25) + ')';
            }
        }
        if (currentalpha >= 100) {
            clearInterval(eval(intervalID));
        }
    }
}
function fadeOut(divid, nextcmd) {
    fadeOutInterval = setInterval('dofadeOut("' + divid + '","fadeOutInterval","' + nextcmd + '")', 10);
    if (underlay) {
        underlay.style.visibility = 'hidden';
    }
}

function getProducts(catid, target) {
    scmd = "xmlhttpPost('content/productlist.asp?catid=" + catid + "','" + target + "')";
    fadeOut(target, scmd);
}
function returnTo(surl, target) {
    scmd = "xmlhttpPost('" + surl + "','" + target + "')";
    try {
        fadeOut(target, scmd);
    } catch (e) {
        alert(e);
    }
    //xmlhttpPost(surl, target, false);
}

function prodDetail(pid) {
    var oelement;
    var centerx = (screen.availWidth / 2) - 300;
    var centery = 50;
    underlay = document.getElementById('underlay');
    underlay.style.visibility = 'visible';
    if (document.getElementById('ProductDetail')){
        oelement = document.getElementById('ProductDetail');
    }else{
        oelement = document.createElement("div");
        oelement.id = "ProductDetail";
        oelement.className = "dialogbox";
        document.body.appendChild(oelement);
    }
    if (!isIE) {
        oelement.style.position = 'fixed';
        underlay.style.position = 'fixed';
    }
    oelement.style.top = centery + 'px';
    oelement.style.left = centerx + 'px';
    xmlhttpPost('content/productdetail.asp?pid=' + pid, oelement.id, true);
}
function genpopup(surl) {
    var oelement;
    var centerx = (screen.availWidth / 2) - 300;
    var centery = 50;
    underlay = document.getElementById('underlay');
    underlay.style.visibility = 'visible';
    if (document.getElementById('ProductDetail')) {
        oelement = document.getElementById('ProductDetail');
    } else {
        oelement = document.createElement("div");
        oelement.id = "ProductDetail";
        oelement.className = "dialogbox";
        document.body.appendChild(oelement);
    }
    if (!isIE) {
        oelement.style.position = 'fixed';
        underlay.style.position = 'fixed';
    }
    oelement.style.top = centery + 'px';
    oelement.style.left = centerx + 'px';
    xmlhttpPost(surl, oelement.id, true);
}

function closepopup() {
    if (document.getElementById('underlay')) {
        document.getElementById('underlay').style.visibility = 'hidden';
        if (document.getElementById('ProductDetail')) {
            oelement = document.getElementById('ProductDetail');
            oelement.style.visibility = 'hidden';
        }
    }
}

function submitForm() {
    var emailfield = document.getElementById('email');
    if (emailfield.value.indexOf('@') >= 0) {
        semail = emailfield.value;
        returnTo("actions/resetpassword.asp?email=" + semail, "rightcol");
    } else {
        alert("Please enter a valid Email Address");
        emailfield.focus();
    }
}

function showInDialog(surl) {
    var oelement;
    var centerx = (screen.availWidth / 2) - 300;
    var centery = 50;
    underlay = document.getElementById('underlay');
    underlay.style.visibility = 'visible';
    if (document.getElementById('ProductDetail')) {
        oelement = document.getElementById('ProductDetail');
    } else {
        oelement = document.createElement("div");
        oelement.id = "ProductDetail";
        oelement.className = "dialogbox";
        document.body.appendChild(oelement);
    }
    if (!isIE) {
        oelement.style.position = 'fixed';
        underlay.style.position = 'fixed';
    }
    oelement.style.top = centery + 'px';
    oelement.style.left = centerx + 'px';
    xmlhttpPost(surl, oelement.id, true);
}

var currentTab = "userTab";
function switchTabs(e, surl, target) {
    if (document.getElementById(currentTab)) {
        document.getElementById(currentTab).className = 'tab';
    }
    e.className = 'tabselected';
    currentTab = e.id;
    returnTo(surl, target);
}

//Expand form with a new File fields if needed.
var nfiles = 3;
function Expand() {
    nfiles++
    var adh = '<BR> File ' + nfiles + ' : <input type="file" name="File' + nfiles + '">';
    files.insertAdjacentHTML('BeforeEnd', adh);
    return false;
}
//Open window with progress bar.
function ProgressBar(uploadID) {
    var ProgressURL
    ProgressURL = '/inc/progress.asp?UploadID=' + uploadID

    var v = window.open(ProgressURL, '_blank', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=350,height=200')

    return true;
}
function validateForm(formid) {
    if (document.getElementById(formid)) {
        var oform = document.getElementById(formid);
        var ofield;
        var arrclass;
        var serr = '';
        var pwd = '';
        for (i = 0; i < oform.length; i++) {
            ofield = oform[i];
            if (ofield.className != '') {
                arrclass = ofield.className.split(':');
                switch (arrclass[0]) {
                    case 'required':
                        switch (arrclass[1]) {
                            case 'zipcode':
                                if (ofield.value.replace(/^\s+|\s+$/g, '') == '') {
                                    serr += arrclass[2] + ' \n';
                                    ofield.focus;
                                    ofield.style.backgroundColor = '#FF0000';
                                    ofield.style.color = '#FFFFFF';
                                } else {
                                    if (!validateZIP(ofield.value)) {
                                        serr += arrclass[2] + '\n';
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                }
                                break;
                            case 'creditcard':
                                var mcstring = '51,52,53,54,55';
                                var disstring = '64,65';
                                var amexstring = '34,37';
                                if (ofield.value.replace(/^\s+|\s+$/g, '') == '') {
                                    serr += arrclass[2] + '\n';
                                    ofield.focus;
                                    ofield.style.backgroundColor = '#FF0000';
                                    ofield.style.color = '#FFFFFF';
                                } else {
                                    var cardnumber = ofield.value.replace(/^\s+|\s+$/g, '')
                                    cardnumber = cardnumber.replace(/-/g, '');
                                    //Check for Visa
                                    if (cardnumber.substring(0, 1) == '4') {
                                        if (!checkCreditCard(cardnumber, 'Visa')) {
                                            serr += (ccErrors[ccErrorNo]) + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    } else if (mcstring.indexOf(cardnumber.substring(0, 2)) >= 0) {
                                        if (!checkCreditCard(cardnumber, 'MasterCard')) {
                                            serr += (ccErrors[ccErrorNo]) + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    } else if (amexstring.indexOf(cardnumber.substring(0, 2)) >= 0) {
                                        if (!checkCreditCard(cardnumber, 'AmEx')) {
                                            serr += (ccErrors[ccErrorNo]) + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    } else if (cardnumber.substring(0, 3) == '6011') {
                                        if (!checkCreditCard(cardnumber, 'Discover')) {
                                            serr += (ccErrors[ccErrorNo]) + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    } else if (cardnumber.substring(0, 3) == '622') {
                                        if (!checkCreditCard(cardnumber, 'Discover')) {
                                            serr += (ccErrors[ccErrorNo]) + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    } else if (disstring.indexOf(cardnumber.substring(0, 2) >= 0)) {
                                        if (!checkCreditCard(cardnumber, 'Discover')) {
                                            serr += (ccErrors[ccErrorNo]) + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    }
                                }
                                break;
                            case 'string':
                                try {
                                    if (ofield.value.replace(/^\s+|\s+$/g, '') == '') {
                                        serr += arrclass[2] + '\n';
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'dependent':
                                try {
                                    var chkfield = document.getElementById(arrclass[2]);
                                    if (chkfield.checked) {
                                        if (ofield.value.replace(/^\s+|\s+$/g, '') == '') {
                                            serr += arrclass[3] + '\n';
                                            ofield.focus;
                                            ofield.style.backgroundColor = '#FF0000';
                                            ofield.style.color = '#FFFFFF';
                                        } else {
                                            ofield.style.backgroundColor = '';
                                            ofield.style.color = '';
                                        }
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'password':
                                try {
                                    if (ofield.value.replace(/^\s+|\s$/g, '') == '') {
                                        serr += arrclass[2] + '\n';
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                    }
                                    if (ofield.value.length < 6) {
                                        serr += 'Password must be at least 6 characters\n';
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'numeric':
                                try {
                                    if (isNaN(ofield.value)) {
                                        serr += arrclass[2];
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'date':
                                try {
                                    if (!isDate(ofield.value)) {
                                        serr += arrclass[2] + '\n';
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'email':
                                try {
                                    if (!ofield.value.match(/^(.+)@(.+)$/)) {
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                        serr += arrclass[2] + '\n';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'checked':
                                try {
                                    if (!ofield.checked) {
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                        serr += arrclass[2] + '\n';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                                break;
                            case 'radio':
                                try {
                                    var radios = oform[ofield.name];
                                    var rchecked = false
                                    for (rcount = 0; rcount < radios.length; rcount++) {
                                        if (!rchecked) {
                                            rchecked = radios[rcount].checked;
                                        }
                                    }
                                    if (!rchecked && serr.indexOf(arrclass[2]) == -1) {
                                        ofield.focus;
                                        ofield.style.backgroundColor = '#FF0000';
                                        ofield.style.color = '#FFFFFF';
                                        serr += arrclass[2] + '\n';
                                    } else {
                                        ofield.style.backgroundColor = '';
                                        ofield.style.color = '';
                                    }
                                } catch (e) {
                                    alert(e.message);
                                }
                        }
                        break;
                }
            }
        }
        if (serr != '') {

            if (document.getElementById(formid + "_err")) {
                var htmlstring = '<p>Error:</p><p><ol><li>' + serr.replace(/\n/g, '</li><li>') + '</li></ol></p>';
                htmlstring = htmlstring.replace('<li></li>', '');
                document.getElementById(formid + "_err").innerHTML = htmlstring;
            } else {
                serr = 'Form Submission Errors:\n' + serr;
                alert(serr);
            }
            return false;
        } else {
            if (document.getElementById(formid + "_err")) {
                document.getElementById(formid + "_err").innerHTML = '';
            }
            return true;
        }

    } else {
        alert("Form not found");
        return false;
    }
}
function isDate(sDate) { // m[m]/d[d]/yyyy format
    var dtepat = /^(\d\d?)\/(\d\d?)\/(\d{4})$/
    var match = sDate.match(dtepat);
    if (!match) { return false; }
    var yr = Number(match[3]);
    var mt = Number(match[1]);
    var da = Number(match[2]);
    var d = new Date(yr, mt - 1, da);
    return (d.getMonth() + 1 == mt && d.getDate() == da);
}
function validateZIP(field) {
    var valid = "0123456789-";
    var hyphencount = 0;

    if (field.length != 5 && field.length != 10) {
        //alert("Please enter your 5 digit or 5 digit+4 zip code.");
        return false;
    }
    for (var i = 0; i < field.length; i++) {
        temp = "" + field.substring(i, i + 1);
        if (temp == "-") hyphencount++;
        if (valid.indexOf(temp) == "-1") {
            //alert("Invalid characters in your zip code.  Please try again.");
            return false;
        }
        if ((hyphencount > 1) || ((field.length == 10) && "" + field.charAt(5) != "-")) {
            //alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
            return false;
        }
    }
    return true;
}


/*============================================================================*/

/*

This routine checks the credit card number. The following checks are made:

1. A number has been provided
2. The number is a right length for the card
3. The number has an appropriate prefix for the card
4. The number has a valid modulus 10 number check digit if required

If the validation fails an error is reported.

The structure of credit card formats was gleaned from a variety of sources on 
the web, although the best is probably on Wikepedia ("Credit card number"):

http://en.wikipedia.org/wiki/Credit_card_number

Parameters:
cardnumber           number on the card
cardname             name of card as defined in the card list below

Author:     John Gardner
Date:       1st November 2003
Updated:    26th Feb. 2005      Additional cards added by request
Updated:    27th Nov. 2006      Additional cards added from Wikipedia
Updated:    18th Jan. 2008      Additional cards added from Wikipedia
Updated:    26th Nov. 2008      Maestro cards extended

*/

/*
If a credit card number is invalid, an error reason is loaded into the 
global ccErrorNo variable. This can be be used to index into the global error  
string array to report the reason to the user if required:
   
e.g. if (!checkCreditCard (number, name) alert (ccErrors(ccErrorNo);
*/

var ccErrorNo = 0;
var ccErrors = new Array()

ccErrors[0] = "Unknown card type";
ccErrors[1] = "No card number provided";
ccErrors[2] = "Credit card number is in invalid format";
ccErrors[3] = "Credit card number is invalid";
ccErrors[4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard(cardnumber, cardname) {

    // Array to hold the permitted card characteristics
    var cards = new Array();

    // Define the cards we support. You may add addtional card types.

    //  Name:      As in the selection box of the form - must be same as user's
    //  Length:    List of possible valid lengths of the card number for the card
    //  prefixes:  List of possible prefixes for the card
    //  checkdigit Boolean to say whether there is a check digit

    cards[0] = { name: "Visa",
        length: "13,16",
        prefixes: "4",
        checkdigit: true
    };
    cards[1] = { name: "MasterCard",
        length: "16",
        prefixes: "51,52,53,54,55",
        checkdigit: true
    };
    cards[2] = { name: "DinersClub",
        length: "14,16",
        prefixes: "36,54,55",
        checkdigit: true
    };
    cards[3] = { name: "CarteBlanche",
        length: "14",
        prefixes: "300,301,302,303,304,305",
        checkdigit: true
    };
    cards[4] = { name: "AmEx",
        length: "15",
        prefixes: "34,37",
        checkdigit: true
    };
    cards[5] = { name: "Discover",
        length: "16",
        prefixes: "6011,622,64,65",
        checkdigit: true
    };
    cards[6] = { name: "JCB",
        length: "16",
        prefixes: "35",
        checkdigit: true
    };
    cards[7] = { name: "enRoute",
        length: "15",
        prefixes: "2014,2149",
        checkdigit: true
    };
    cards[8] = { name: "Solo",
        length: "16,18,19",
        prefixes: "6334, 6767",
        checkdigit: true
    };
    cards[9] = { name: "Switch",
        length: "16,18,19",
        prefixes: "4903,4905,4911,4936,564182,633110,6333,6759",
        checkdigit: true
    };
    cards[10] = { name: "Maestro",
        length: "12,13,14,15,16,18,19",
        prefixes: "5018,5020,5038,6304,6759,6761",
        checkdigit: true
    };
    cards[11] = { name: "VisaElectron",
        length: "16",
        prefixes: "417500,4917,4913,4508,4844",
        checkdigit: true
    };

    // Establish card type
    var cardType = -1;
    for (var i = 0; i < cards.length; i++) {

        // See if it is this card (ignoring the case of the string)
        if (cardname.toLowerCase() == cards[i].name.toLowerCase()) {
            cardType = i;
            break;
        }
    }

    // If card type not found, report an error
    if (cardType == -1) {
        ccErrorNo = 0;
        return false;
    }

    // Ensure that the user has provided a credit card number
    if (cardnumber.length == 0) {
        ccErrorNo = 1;
        return false;
    }

    // Now remove any spaces from the credit card number
    cardnumber = cardnumber.replace(/\s/g, "");

    // Check that the number is numeric
    var cardNo = cardnumber
    var cardexp = /^[0-9]{13,19}$/;
    if (!cardexp.exec(cardNo)) {
        ccErrorNo = 2;
        return false;
    }

    // Now check the modulus 10 check digit - if required
    if (cards[cardType].checkdigit) {
        var checksum = 0;                                  // running checksum total
        var mychar = "";                                   // next char to process
        var j = 1;                                         // takes value of 1 or 2

        // Process each digit one by one starting at the right
        var calc;
        for (i = cardNo.length - 1; i >= 0; i--) {

            // Extract the next digit and multiply by 1 or 2 on alternative digits.
            calc = Number(cardNo.charAt(i)) * j;

            // If the result is in two digits add 1 to the checksum total
            if (calc > 9) {
                checksum = checksum + 1;
                calc = calc - 10;
            }

            // Add the units element to the checksum total
            checksum = checksum + calc;

            // Switch the value of j
            if (j == 1) { j = 2 } else { j = 1 };
        }

        // All done - if checksum is divisible by 10, it is a valid modulus 10.
        // If not, report an error.
        if (checksum % 10 != 0) {
            ccErrorNo = 3;
            return false;
        }
    }

    // The following are the card-specific checks we undertake.
    var LengthValid = false;
    var PrefixValid = false;
    var undefined;

    // We use these for holding the valid lengths and prefixes of a card type
    var prefix = new Array();
    var lengths = new Array();

    // Load an array with the valid prefixes for this card
    prefix = cards[cardType].prefixes.split(",");

    // Now see if any of them match what we have in the card number
    for (i = 0; i < prefix.length; i++) {
        var exp = new RegExp("^" + prefix[i]);
        if (exp.test(cardNo)) PrefixValid = true;
    }

    // If it isn't a valid prefix there's no point at looking at the length
    if (!PrefixValid) {
        ccErrorNo = 3;
        return false;
    }

    // See if the length is valid for this card
    lengths = cards[cardType].length.split(",");
    for (j = 0; j < lengths.length; j++) {
        if (cardNo.length == lengths[j]) LengthValid = true;
    }

    // See if all is OK by seeing if the length was valid. We only check the 
    // length if all else was hunky dory.
    if (!LengthValid) {
        ccErrorNo = 4;
        return false;
    };

    // The credit card is in the required format.
    return true;
}

/*============================================================================*/

function wizardStep(stepid) {
    ocurrent = document.getElementById(currentStep);
    onext = document.getElementById(stepid);
    if (ocurrent) {
        ocurrent.className = 'wizardOff';
    }
    onext.className = 'wizardOn';
    currentStep = stepid;    
}