----- thescript -----
<SCRIPT LANGUAGE="JavaScript">
//================================================== ===================||
// NOP Design JavaScript Shopping Cart ||
// ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at
http://www.nopdesign.com ||
// ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design under the GPL. You must keep this comment ||
// unchanged in your code. For more information contact ||
//
[email protected] ||
// ||
// JavaScript Shop Module, V.3.0.2 ||
//================================================== ===================||
//---------------------------------------------------------------------||
// FUNCTION: checkForm ||
// PARAMETERS: Form object, and true/false if we should check for ||
// a credit card number. You shouldn't accept credit cards||
// via email. Only use that when you are connected to a ||
// secure server. ||
// RETURNS: boolean (True form is correct, False form is in error) ||
// PURPOSE: To check form elements ||
//---------------------------------------------------------------------||
function checkForm(thisForm, checkForCreditCard) {
bFormError = false; //Boolean variable to store form state
bIsValidCard = false; //Boolean variable to store CC state
strErrorList = ""; //String list of missing/errorsum fields
if( thisForm.FIRST.value=='' ) {bFormError = true; strErrorList += "First Name, ";}
if( thisForm.LAST.value=='' ) {bFormError = true; strErrorList += "Last Name, ";}
if( thisForm.ADDRESS.value=='') {bFormError = true; strErrorList += "Address, ";}
if( thisForm.CITY.value=='' ) {bFormError = true; strErrorList += "City, ";}
if( thisForm.STATE.value=='' ) {bFormError = true; strErrorList += "State, ";}
if( thisForm.ZIP.value=='' ) {bFormError = true; strErrorList += "Zip, ";}
if( thisForm.PHONE.value=='' ) {bFormError = true; strErrorList += "Phone, ";}
if( thisForm.ACCOUNT.value=='') {bFormError = true; strErrorList += "Credit Card Number, ";}
if( thisForm.MONTH.value=='' ) {bFormError = true; strErrorList += "Month, ";}
if( thisForm.YEAR.value=='' ) {bFormError = true; strErrorList += "Year ";}
if( bFormError == true ) {
alert("I'm sorry, but you had one or more missing or invalid entries.\n"
+"Please check the following fields: \n\n"
+strErrorList
+"\n\n");
return false;
}
//Check for valid Visa
if (((thisForm.ACCOUNT.value.length == 16) || (thisForm.ACCOUNT.value.length == 13)) &&
(thisForm.ACCOUNT.value.substring(0,1) == 4))
bIsValidCard = true;
//Check for valid MasterCard
firstdig = thisForm.ACCOUNT.value.substring(0,1);
seconddig = thisForm.ACCOUNT.value.substring(1,2);
if ((thisForm.ACCOUNT.value.length == 16) &&
(firstdig == 5) && ((seconddig >= 1) &&
(seconddig <= 5))
)
bIsValidCard = true;
if (bIsValidCard == false){
alert("I'm sorry, but you need to enter a valid credit card number.\n");
return false;
}
return needComments();
} //END function checkForm
//---------------------------------------------------------------------||
// FUNCTION: CKquantity ||
// PARAMETERS: Quantity to ||
// RETURNS: Quantity as a number, and possible alert ||
// PURPOSE: Make sure quantity is represented as a number ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
strNewQuantity = ""; // String Adjusted Item Quantity
count = 0; // Generic Loop Counter
for (i = 0; i < checkString.length; i++) {
ch = checkString.substring(i, i+1);
if ((ch >= "0" && ch <= "9") || (ch == '.')) {
strNewQuantity += ch;
}
}
if (strNewQuantity.length < 1)
strNewQuantity = "1";
return strNewQuantity;
}
//---------------------------------------------------------------------||
// FUNCTION: AddToCart ||
// PARAMETERS: Form Object ||
// RETURNS: Cookie to user's browser, with prompt ||
// PURPOSE: Adds a product to the user's shopping cart ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {
iNumberOrdered = 0; //Integer number of products already ordered
iNumberOrdered = GetCookie("NumberOrdered");
iNumberOrdered++;
if ( iNumberOrdered > 12 )
alert("I'm Sorry, your cart is full, please proceed to checkout.");
else {
dbUpdatedOrder = thisForm.QUANTITY.value + "|"
+ thisForm.PRICE.value + "|"
+ thisForm.ID_NUM.value + "|"
+ thisForm.NAME.value;
NewOrder = "Order." + iNumberOrdered;
SetCookie (NewOrder, dbUpdatedOrder, null, "/");
SetCookie ("NumberOrdered", iNumberOrdered, null, "/");
notice = thisForm.QUANTITY.value + " "
+ thisForm.NAME.value
+ " added to your shopping cart.";
alert(notice);
}
}
//---------------------------------------------------------------------||
// FUNCTION: getCookieVal ||
// PARAMETERS: offset ||
// RETURNS: URL unescaped Cookie Value ||
// PURPOSE: Get a specific value from a cookie ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
//---------------------------------------------------------------------||
// FUNCTION: FixCookieDate ||
// PARAMETERS: date ||
// RETURNS: date ||
// PURPOSE: Fixes cookie date, stores back in date ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime();
date.setTime (date.getTime() - skew);
}
//---------------------------------------------------------------------||
// FUNCTION: GetCookie ||
// PARAMETERS: Name ||
// RETURNS: Value in Cookie ||
// PURPOSE: Retrieves cookie from users browser ||
//---------------------------------------------------------------------||
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
//---------------------------------------------------------------------||
// FUNCTION: SetCookie ||
// PARAMETERS: name, value, expiration date, path, domain, security ||
// RETURNS: Null ||
// PURPOSE: Stores a cookie in the users browser ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
//----- CONTINUA....