
    
    /**************************************************************************************************
    Name:		 isEmpty

    Description: Checks to see if the field passed is blank or not.	
    ***************************************************************************************************/
    function isEmpty(inputStr)
    {
            if (inputStr == null || inputStr == "")
            {
			    return true;
            }
            return false;
    }

    /**************************************************************************************************
    Name: validatestateHome()
    Description: validates that the required state page is linked from homepage
    ***************************************************************************************************/
    function validateStateHome() {
        //alert(selState.States.options[selState.States.selectedIndex].value + '-Medical-Alert.asp');
       var newlocation = (document.selState.elements.item('states').value);
        //newlocation = document.getElementsByName('selState');
        //alert(newlocation);
        var newlocation = ('/products/medical-alert/states/' + document.selState.elements.item('states').value) + '-Medical-Alert.asp';
        //alert(newlocation);
        //var newlocation = selState.States.options[selState.States.selectedIndex].value + '-Medical-Alert.asp';
        //alert(newlocation);
        if (document.selState.elements.item('states').value == 'District of Columbia')
        {
            newlocation = "/products/medical-alert/states/District-of-Columbia-Medical-Alert.asp?States=District%20of%20Columbia";
        }
        if (document.selState.elements.item('states').value == 'New Hampshire')
        {
            newlocation = "/products/medical-alert/states/New-Hampshire-Medical-Alert.asp";
        }
        if (document.selState.elements.item('states').value == 'New Jersey')
        {
            newlocation = "/products/medical-alert/states/New-Jersey-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'New Mexico')
        {
            newlocation = "/products/medical-alert/states/New-Mexico-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'New York')
        {
            newlocation = "/products/medical-alert/states/New-York-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'North Carolina')
        {
            newlocation = "/products/medical-alert/states/North-Carolina-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'North Dakota')
        {
            newlocation = "/products/medical-alert/states/North-Dakota-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'Rhode Island')
        {
            newlocation = "/products/medical-alert/states/Rhode-Island-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'South Carolina')
        {
            newlocation = "/products/medical-alert/states/South-Carolina-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'South Dakota')
        {
            newlocation = "/products/medical-alert/states/South-Dakota-Medical-Alert.asp";
        }  
        if (document.selState.elements.item('states').value == 'West Virginia')
        {
            newlocation = "/products/medical-alert/states/West-Virginia-Medical-Alert.asp";
        } 
        //window.location = newlocation + '?States=' + selState.States.options[selState.States.selectedIndex].value;
        window.location = newlocation + '?States=' + (document.selState.elements.item('states').value);
        }
        
        /**************************************************************************************************
    Name: validatestateHome()
    Description: validates that the required state page is linked from homepage
    ***************************************************************************************************/
    function validateState() {
        //alert(selState.States.options[selState.States.selectedIndex].value + '-Medical-Alert.asp');
       var newlocation = (document.selState.elements.item('states').value);
        //newlocation = document.getElementsByName('selState');
        //alert(newlocation);
        var newlocation = ('/products/medical-alert/states/' + document.selState.elements.item('states').value) + '-Medical-Alert.asp';
        //alert(newlocation);
        //var newlocation = selState.States.options[selState.States.selectedIndex].value + '-Medical-Alert.asp';
        //alert(newlocation);
        if (document.selState.elements.item('states').value == 'District of Columbia')
        {
            newlocation = "/products/medical-alert/states/District-of-Columbia-Medical-Alert.asp?States=District%20of%20Columbia";
        }
        if (document.selState.elements.item('states').value == 'New Hampshire')
        {
            newlocation = "/products/medical-alert/states/New-Hampshire-Medical-Alert.asp";
        }
        if (document.selState.elements.item('states').value == 'New Jersey')
        {
            newlocation = "/products/medical-alert/states/New-Jersey-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'New Mexico')
        {
            newlocation = "/products/medical-alert/states/New-Mexico-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'New York')
        {
            newlocation = "/products/medical-alert/states/New-York-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'North Carolina')
        {
            newlocation = "/products/medical-alert/states/North-Carolina-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'North Dakota')
        {
            newlocation = "/products/medical-alert/states/North-Dakota-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'Rhode Island')
        {
            newlocation = "/products/medical-alert/states/Rhode-Island-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'South Carolina')
        {
            newlocation = "/products/medical-alert/states/South-Carolina-Medical-Alert.asp";
        } 
        if (document.selState.elements.item('states').value == 'South Dakota')
        {
            newlocation = "/products/medical-alert/states/South-Dakota-Medical-Alert.asp";
        }  
        if (document.selState.elements.item('states').value == 'West Virginia')
        {
            newlocation = "/products/medical-alert/states/West-Virginia-Medical-Alert.asp";
        } 
        //window.location = newlocation + '?States=' + selState.States.options[selState.States.selectedIndex].value;
        window.location = newlocation + '?States=' + (document.selState.elements.item('states').value);
        }
        
function validatePrereq() {
	if (isEmpty(document.prereq.States.value))
	{
		alert("Please select the client location");
		document.prereq.States.focus();
		return false;
	}
	if (isEmpty(document.prereq.voip.value))
	{
		alert("Please select what type of Phone Service do you have.");
		document.prereq.voip.focus();
		return false;
	}
}

function checkAll(){
    //alert("CHEKCALL")
    return validateCheckout();
   //alert("checkout");
    
    //CheckCardNumber();
    //alert("cardvalidation")
}

function validateCheckout() {
    if (isEmpty(document.checkout.txtfirstName.value))
    {
        alert("Please enter the Subscriber / Shipping First Name");
        document.checkout.txtfirstName.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtlastName.value))
    {
        alert("Please enter the Subscriber / Shipping Last Name");
        document.checkout.txtlastName.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtaddress1.value))
    {
        alert("Please enter the Subscriber / Shipping Address");
        document.checkout.txtaddress1.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtcity.value))
    {
        alert("Please enter the Subscriber / Shipping City");
        document.checkout.txtcity.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtstate.value))
    {
        alert("Please enter the Subscriber / Shipping State");
        document.checkout.txtstate.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtzip.value))
    {
        alert("Please enter the Subscriber / Shipping Zip Code");
        document.checkout.txtzip.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtcountry.value))
    {
        alert("Please enter the Subscriber / Shipping Country");
        document.checkout.txtcountry.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtphone.value))
    {
        alert("Please enter the Subscriber / Shipping Phone Number");
        document.checkout.txtphone.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBfirstName.value))
    {
        alert("Please enter the Billing First Name");
        document.checkout.txtBfirstName.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBlastName.value))
    {
        alert("Please enter the Billing Last Name");
        document.checkout.txtBlastName.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBaddress1.value))
    {
        alert("Please enter the Billing Address");
        document.checkout.txtBaddress1.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBcity.value))
    {
        alert("Please enter the Billing City");
        document.checkout.txtBcity.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBstate.value))
    {
        alert("Please enter the Billing State");
        document.checkout.txtBstate.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBzip.value))
    {
        alert("Please enter the Billing Zip");
        document.checkout.txtBzip.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBcountry.value))
    {
        alert("Please enter the Billing Country");
        document.checkout.txtBcountry.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtBphone.value))
    {
        alert("Please enter the Billing Phone");
        document.checkout.txtBphone.focus();
        return false;
    }
    if (isEmpty(document.checkout.txtCVV2.value))
    {
        alert("Please enter the Security Code on your credit card");
        document.checkout.txtCVV2.focus();
        return false;
    }
    return CheckCardNumber(this.form)
}

function CopySubscriber(form){
    if (document.checkout.CSubscriber.checked == true) {
        document.checkout.txtBfirstName.value = document.checkout.txtfirstName.value;
        document.checkout.txtBlastName.value = document.checkout.txtlastName.value;
        document.checkout.txtBcompany.value = document.checkout.txtcompany.value;
        document.checkout.txtBaddress1.value = document.checkout.txtaddress1.value;
        document.checkout.txtBaddress2.value = document.checkout.txtaddress2.value;
        document.checkout.txtBcity.value = document.checkout.txtcity.value;
        document.checkout.txtBstate.value = document.checkout.txtstate.value;
        document.checkout.txtBzip.value = document.checkout.txtzip.value;
        document.checkout.txtBcountry.value = document.checkout.txtcountry.value;
        document.checkout.txtBphone.value = document.checkout.txtphone.value;
        return;
    }
    else{
        document.checkout.txtBfirstName.value = "";
        document.checkout.txtBlastName.value = "";
        document.checkout.txtBcompany.value = "";
        document.checkout.txtBaddress1.value = "";
        document.checkout.txtBaddress2.value = "";
        document.checkout.txtBcity.value = "";
        document.checkout.txtBstate.value = "";
        document.checkout.txtBzip.value = "";
        document.checkout.txtBcountry.value = "";
        document.checkout.txtBphone.value = "";
        return;
    }
}




<!-- Original:  Simon Tneoh (tneohcb@pc.jaring.my) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var Cards = new makeArray(8);
Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];
Cards[1] = new CardType("VisaCard", "4", "13,16");
var VisaCard = Cards[1];
Cards[2] = new CardType("AmExCard", "34,37", "15");
var AmExCard = Cards[2];
Cards[3] = new CardType("DinersClubCard", "30,36,38", "14");
var DinersClubCard = Cards[3];
Cards[4] = new CardType("DiscoverCard", "6011", "16");
var DiscoverCard = Cards[4];
Cards[5] = new CardType("enRouteCard", "2014,2149", "15");
var enRouteCard = Cards[5];
Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16");
var JCBCard = Cards[6];
var LuhnCheckSum = Cards[7] = new CardType();

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/
function CheckCardNumber() {
//alert("INSIDE CHECKCARD FORM");
var tmpyear;
if (document.checkout.CardNumber.value.length == 0) {
alert("Please enter a Card Number.");
document.checkout.CardNumber.focus();
return false;
}
if (document.checkout.ExpYear.value.length == 0) {
alert("Please enter the Expiration Year.");
document.checkout.ExpYear.focus();
return false;
}
if (document.checkout.ExpYear.value > 96)
tmpyear = "19" + document.checkout.ExpYear.value;
else if (document.checkout.ExpYear.value < 21)
tmpyear = "20" + document.checkout.ExpYear.value;
else {
alert("The Expiration Year is not valid.");
return false;
}
tmpmonth = document.checkout.ExpMon.options[document.checkout.ExpMon.selectedIndex].value;
// The following line doesn't work in IE3, you need to change it
// to something like "(new CardType())...".
// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {
if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
alert("This card has already expired.");
return false;
}
card = document.checkout.CardType.options[document.checkout.CardType.selectedIndex].value;
var retval = eval(card + ".checkCardNumber(\"" + document.checkout.CardNumber.value +
"\", " + tmpyear + ", " + tmpmonth + ");");
cardname = "";
if (retval){



// comment this out if used on an order form
//alert("This card number appears to be valid.");

}
else {
// The cardnumber has the valid luhn checksum, but we want to know which
// cardtype it belongs to.
for (var n = 0; n < Cards.size; n++) {
if (Cards[n].checkCardNumber(document.checkout.CardNumber.value, tmpyear, tmpmonth)) {
cardname = Cards[n].getCardType();
break;
   }
}
if (cardname.length > 0) {
alert("This looks like a " + cardname + " number, not a " + card + " number.");
document.checkout.CardNumber.focus();
return false;
}
else {
alert("This card number is not valid.");
document.checkout.CardNumber.focus();
return false;
      }
   }
}
/*************************************************************************\
Object CardType([String cardtype, String rules, String len, int year, 
                                        int month])
cardtype    : type of card, eg: MasterCard, Visa, etc.
rules       : rules of the cardnumber, eg: "4", "6011", "34,37".
len         : valid length of cardnumber, eg: "16,19", "13,16".
year        : year of expiry date.
month       : month of expiry date.
eg:
var VisaCard = new CardType("Visa", "4", "16");
var AmExCard = new CardType("AmEx", "34,37", "15");
\*************************************************************************/
function CardType() {
var n;
var argv = CardType.arguments;
var argc = CardType.arguments.length;

this.objname = "object CardType";

var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";
var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";
var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";

this.setCardNumber = setCardNumber;  // set CardNumber method.
this.setCardType = setCardType;  // setCardType method.
this.setLen = setLen;  // setLen method.
this.setRules = setRules;  // setRules method.
this.setExpiryDate = setExpiryDate;  // setExpiryDate method.

this.setCardType(tmpcardtype);
this.setLen(tmplen);
this.setRules(tmprules);
if (argc > 4)
this.setExpiryDate(argv[3], argv[4]);

this.checkCardNumber = checkCardNumber;  // checkCardNumber method.
this.getExpiryDate = getExpiryDate;  // getExpiryDate method.
this.getCardType = getCardType;  // getCardType method.
this.isCardNumber = isCardNumber;  // isCardNumber method.
this.isExpiryDate = isExpiryDate;  // isExpiryDate method.
this.luhnCheck = luhnCheck;// luhnCheck method.
return this;
}

/*************************************************************************\
boolean checkCardNumber([String cardnumber, int year, int month])
return true if cardnumber pass the luhncheck and the expiry date is
valid, else return false.
\*************************************************************************/
function checkCardNumber() {
var argv = checkCardNumber.arguments;
var argc = checkCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
var year = (argc > 1) ? argv[1] : this.year;
var month = (argc > 2) ? argv[2] : this.month;

this.setCardNumber(cardnumber);
this.setExpiryDate(year, month);

if (!this.isCardNumber())
return false;
if (!this.isExpiryDate())
return false;

return true;
}
/*************************************************************************\
String getCardType()
return the cardtype.
\*************************************************************************/
function getCardType() {
return this.cardtype;
}
/*************************************************************************\
String getExpiryDate()
return the expiry date.
\*************************************************************************/
function getExpiryDate() {
return this.month + "/" + this.year;
}
/*************************************************************************\
boolean isCardNumber([String cardnumber])
return true if cardnumber pass the luhncheck and the rules, else return
false.
\*************************************************************************/
function isCardNumber() {
var argv = isCardNumber.arguments;
var argc = isCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
if (!this.luhnCheck())
return false;

for (var n = 0; n < this.len.size; n++)
if (cardnumber.toString().length == this.len[n]) {
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cardnumber.substring(0, this.rules[m].toString().length);
if (headdigit == this.rules[m])
return true;
}
return false;
}
return false;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
var argv = isExpiryDate.arguments;
var argc = isExpiryDate.arguments.length;

year = argc > 0 ? argv[0] : this.year;
month = argc > 1 ? argv[1] : this.month;

if (!isNum(year+""))
return false;
if (!isNum(month+""))
return false;
today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime())
return false;
else
return true;
}

/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
\*************************************************************************/
function luhnCheck() {
var argv = luhnCheck.arguments;
var argc = luhnCheck.arguments.length;

var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

if (! isNum(CardNumber)) {
return false;
  }

var no_digit = CardNumber.length;
var oddoeven = no_digit & 1;
var sum = 0;

for (var count = 0; count < no_digit; count++) {
var digit = parseInt(CardNumber.charAt(count));
if (!((count & 1) ^ oddoeven)) {
digit *= 2;
if (digit > 9)
digit -= 9;
}
sum += digit;
}
if (sum % 10 == 0)
return true;
else
return false;
}

/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
this.size = size;
return this;
}

/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
this.cardnumber = cardnumber;
return this;
}

/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
this.cardtype = cardtype;
return this;
}

/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
this.year = year;
this.month = month;
return this;
}

/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
// Create the len array.
if (len.length == 0 || len == null)
len = "13,14,15,16,19";

var tmplen = len;
n = 1;
while (tmplen.indexOf(",") != -1) {
tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);
n++;
}
this.len = new makeArray(n);
n = 0;
while (len.indexOf(",") != -1) {
var tmpstr = len.substring(0, len.indexOf(","));
this.len[n] = tmpstr;
len = len.substring(len.indexOf(",") + 1, len.length);
n++;
}
this.len[n] = len;
return this;
}

/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
// Create the rules array.
if (rules.length == 0 || rules == null)
rules = "0,1,2,3,4,5,6,7,8,9";
  
var tmprules = rules;
n = 1;
while (tmprules.indexOf(",") != -1) {
tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
n++;
}
this.rules = new makeArray(n);
n = 0;
while (rules.indexOf(",") != -1) {
var tmpstr = rules.substring(0, rules.indexOf(","));
this.rules[n] = tmpstr;
rules = rules.substring(rules.indexOf(",") + 1, rules.length);
n++;
}
this.rules[n] = rules;
return this;
}
//  End -->
