﻿function TransformCCNumber(value) 
{
    var number = "";
    for (i = 0; i < value.length; i++)
        if (value.charAt(i) >= "0" && value.charAt(i) <= "9")
        number += value.substr(i, 1);
    return number;
}

function TransformQty(value) {
    var number = "";
    for (i = 0; i < value.length; i++) { if (value.charAt(i) >= "0" && value.charAt(i) <= "9") { number += value.substr(i, 1); } }
    if (number == 0) number = 1;
    return number;
}

function htmlEncode(s) {
    var str = new String(s);
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/\(/g, "!***LEFTBRACK***!");
    str = str.replace(/\)/g, "!***RIGHTBRACK***!");
    str = str.replace(/=/g, "!***EQUALS***!");
    return str;
}

function htmlDecode(s) {
    var str = new String(s);
    str = str.replace(/&amp;/g, '&');
    str = str.replace(/&lt;/g, '<');
    str = str.replace(/&gt;/g, '>');
    str = str.replace(/&quot;/g, '"');
    str = str.replace(/!\*\*\*LEFTBRACK\*\*\*!/g, "(");
    str = str.replace(/!\*\*\*RIGHTBRACK\*\*\*!/g, ")");
    str = str.replace(/!\*\*\*EQUALS\*\*\*!/g, "=");
    return str;
}

function getElement(id) {
    if (document.layers)            // Netscape 4
        return eval("document." + id);
    if (document.getElementById)    // Netscape 6
        return eval("document.getElementById('" + id + "')");
    if (document.all)               // IE4+
        return eval("document.all." + id);
}
function createPlayerTest(mediaFile, theFile, placeholder, image, width, height, displayHeight) {
    var s = new SWFObject(mediaFile, "thePlayerId", width, height, "7");
    s.addParam("allowfullscreen", "true");
    s.addVariable("file", theFile);
    s.addVariable("width", width);
    s.addVariable("height", height);
    s.addVariable("wmode", "opaque");
    s.addVariable("autoscroll", "true");
    s.addVariable("allowscriptaccess", "true");
    s.addVariable("wmode", "opaque");
    s.addVariable("bufferlength", "10");
    s.addVariable("displayheight", displayHeight);
    s.addVariable("allowfullscreen", "true");
    s.addVariable("autostart", "false");
    s.addVariable('image', image);
    s.addVariable("shuffle", "false");
    s.addVariable("enablejs", "true");
    s.addVariable("javascriptid", "thePlayerId");
    s.write(placeholder);
}
function getRealTop(element) {
    var position = element.offsetTop;
    var parent = element.offsetParent;
    while (parent != null) {
        position += parent.offsetTop;
        parent = parent.offsetParent
    }
    return position;
}
function getRealLeft(element) {
    var position = element.offsetLeft;
    var parent = element.offsetParent;
    while (parent != null) {
        position += parent.offsetLeft;
        parent = parent.offsetParent
    }
    return position;
}
function FormatPhone(phoneField, Format) {
    if (Format == null) { Format = /^(\D*\d\D*){10}$/ }
    if (Format.test(phoneField.value) == true) {
        var num = phoneField.value.replace(/[^\d]/g, '');
        if (num.length != 10) {
            // alert('Please enter a valid phone number');
        } else {
            phoneField.value = num.substring(0, 3) + "-" + num.substring(3, 6) + "-" + num.substring(6);
        }
    }
}
function fixZipAndPostalCode(zc) {
    var zip;
    zip = zc.replace(/[^0-9A-Za-z]/g, "");
    if (/^\d{5,}$/.test(zip) == true) {
        if (zip.length < 5)
            zip = zc; // Do Nothing
        else
            zip = zip.substring(0, 5);
    }
    else {
        if (zip.length == 6)
            zip = zip.substring(0, 3) + " " + zip.substring(3);
        else if (zip.length >= 3)
            zip = zip.substring(0, 3);
        else
            zip = zc; // Do Nothing
    }
    return zip.toUpperCase();
}