<!-- Cut-N-Paste JavaScript from ISN Toolbox
Copyright 1996, Infohiway, Inc. Restricted use is hereby
granted (commercial and personal OK) so long as this code
is not *directly* sold and the copyright notice is buried
somewhere deep in your HTML document. A link to our site
but is absolutely and positively not necessary. ;-) -->
<SCRIPT LANGUAGE="JavaScript">
<!--
// ЗАМЕНИТЕ НА false ЕСЛИ ХОТИТЕ ОТКАЗАТЬСЯ ОТ ШИФРОВАНИЯ
var encrypt_it = true;
/* ================== ======================= =========================
THIS FUNCTION IS TAKEN DIRECTLY FROM NETSCAPE FROM:
which is a bunch of functions to validate forms
FUNCTION: isCreditCard(st)
INPUT: st - a string representing a credit card number
RETURNS: true, if the credit card number passes the Luhn Mod-10 test
false, otherwise
===================== ======================= ====================== */
function isCreditCard(st) {
// Encoding only works on cards with less than 19 digits
if (st.length > 19)
return (false);
sum = 0; mul = 1; l = st.length;
for (i = 0; i < l; i++) {
digit = st.substring(l-i-1,l-i);
tproduct = parseInt(digit ,10)*mul;
if (tproduct >= 10)
sum += (tproduct % 10) + 1;
else
sum += tproduct;
if (mul == 1)
mul++;
else
mul--;
}
if ((sum % 10) == 0)
return (true);
else
return (false);
}
function getCCNum(default_val) {
msg = 'Введите номер кредитной карты. '
+ 'Он будет '
+ ((encrypt_it) ? "зашифрован и " : "")
+ 'помещен в поле формы '
+ 'после проверки на корректность.';
return prompt(msg,default_val);
}
// takes in a credit card number, adds one to each digit
// (9 becomes 0), and then returns the encrypted credit
// card number with an 'e' tacked on to the end to signal
// the number has been encrypted
function encrypt(val) {
val = "" + val;
var result = "";
for (i=0;i<val.length;i++) {
character = val.charAt(i);
if ("0123456789".indexOf(character) != -1) {
character = parseInt(character);
character = (character+1)%10;
}
result += character;
}
if (result != "")
result += "e";
return result;
}
function unencrypt(val) {
val = "" + val;
for (n=0;n<9;n++)
val = encrypt(val);
return (val.substring(0,val.indexOf('e')));
}
function strip(val) {
val = "" + val;
if (val == null)
return "";
var result = "";
for (i=0;i<val.length;i++) {
character = val.charAt(i);
if ("0123456789".indexOf(character) != -1)
result += character;
}
return result;
}
var last_entry = "";
function doCCStuff(form_element) {
if (blur_reset) {
last_entry = form_element.value;
if (last_entry.indexOf('e') != -1)
last_entry = unencrypt(last_entry);
entry = getCCNum(last_entry);
stripped_entry = strip(entry);
while ((entry != null) && (!isCreditCard(stripped_entry))) {
alert('Вы ввели некорректный номер кредитной карты.'
+ 'Уточните номер и повторите попытку.');
last_entry = entry;
entry = getCCNum(last_entry);
stripped_entry = strip(entry);
}
if (entry != null) {
if (encrypt_it)
form_element.value = encrypt(entry);
else
form_element.value = entry;
}
blur_form(form_element);
}
return false;
}
var blur_reset = true;
function blur_form(form_element) {
form_element.blur();
blur_reset = false;
setTimeout("blur_reset=true",2000);
}
// -->
</SCRIPT>
|