
function tidnes(InString)
{
	var i, s, t,  OutString;
	
	OutString=new String();
	for(i=InString.length-1; i>= 0; i--)
	{
		t = InString.charCodeAt(i);
		s= String.fromCharCode(t-1);
		OutString += s;
	}

	return OutString;
}

function tiesrever(InString)
{
	var i, s, t,  OutString;
	
	OutString=new String();
	for(i=InString.length-1; i>= 0; i--)
	{
		t = InString.charCodeAt(i);

		s= String.fromCharCode(t+1);

		OutString += s;
	}

	return OutString;
}


// Mod 10 credit card number validator 
// Created by mattf (mattf@mail.com) 2002-09-13 
// This Software is Free with no implied warrantees or guarantees 
// You can use or modify this software any way you may like 
// Bodged into this form by J McAfee March 2003 
function Mod10(ccno) {
	vlengthgood=0;
	ccsum=0;
	badcard=false;
    ino=document.forms[0].issueno.value;
    card=document.forms[0].cardtype.value;
	s=card.search(/solo/i);
	t=card.search(/switch/i);
	if ((s!=t)&&(ino==""))
	{
		alert(card+"Requires an Issue Number");
		return false;
	}
	cclen=ccno.length;
	if (cclen<13)
	{
		badcard=true;
	}
	else
	{
		for (i=1; i<cclen; i++)
		{
			ccdig=parseInt(ccno.charAt(cclen-(i+1)));
			if (i%2==1)
			{
				ccdig*=2;
				if (ccdig.toString().length==2)
				{
					ccdig=(parseInt(ccdig.toString().charAt(0))+parseInt(ccdig.toString().charAt(1)));
				} 
			}
			ccsum+=ccdig;
		}
		ccsum+=parseInt(ccno.charAt(cclen-1));
		if (ccsum%10==0)
// Indicate the cards you don't accept by inserting a '*' at the start of the card name 
// Do NOT remove any of the card types or rearrange the processing order!!! 
// J McAfee 2003 
		{
				cc_type_id = '*NOT VALID TYPE';
			if (ccno.match(/^4/) )
				{cc_type_id = 'VISA';   if (cclen==13 || cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^50|^56|^57|^58|^6/) )
				{cc_type_id = 'MAESTRO';   vlengthgood=1;}
			if (ccno.match(/^51|^52|^53|^54|^55/) )
				{cc_type_id = 'MASTERCARD';   if (cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^413733|^413734|^413735|^413736|^413737|^4462|^453978|^453979|^454313|^454313|^454432|^454433|^454434|^454435|^454742|^456725|^456726|^456727|^456728|^456729|^45673|^456740|^456741|^456742|^456743|^456744|^456745|^46583|^46584|^46585|^46586|^46587|^484409|^484410|^49096|^49097|^492181|^492182|^498824/) )
				{cc_type_id = 'DELTA';   if (cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^450875|^484406|^484407|^484408|^484411|^484412|^484413|^484414|^484415|^484416|^484417|^484418|^484419|^48442|^48443|^48444|^484450|^484451|^484452|^484453|^484454|^484455|^49173|^49174|^49175|^491880/) )
				{cc_type_id = 'ELECTRON';   if (cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^405501|^405502|^405503|^405504|^405550|^405551|^405552|^405553|^405554|^415928|^424604|^424604|^427533|^4288|^443085|^4484|^4485|^4486|^4715|^4716|^4804/) )
				{cc_type_id = '*VISA PURCHASING';   if (cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^490300|^490301|^49031|^49032|^490330|^490331|^490332|^490333|^490334|^49034|^49035|^49036|^49037|^49038|^49039|^49040|^490419|^490451|^490459|^490467|^490475|^490476|^490477|^490478|^4905|^491103|^491104|^491105|^491106|^491107|^491108|^491109|^49111|^49112|^49113|^49114|^49115|^49116|^491170|^491171|^491172|^491173|^491183|^491184|^491185|^491186|^491187|^491188|^491189|^49119|^4928|^4987/) )
				{cc_type_id = '*VISA_ATM';   if (cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^60/) )
				{cc_type_id = '*DISCOVER';   if (cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^63345|^63346|^63347|^63348|^63349|^6767/) )
				{cc_type_id = 'SOLO';   if (cclen==16 || cclen==18 || cclen==19) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^490302|^490303|^490304|^490305|^490306|^490307|^490308|^490309|^490335|^490336|^490337|^490338|^490339|^491101|^491102|^491174|^491175|^491176|^491177|^491178|^491179|^491180|^491181|^491182|^4936|^564182|^63330|^63331|^63332|^63333|^63334|^6759/) )
				{cc_type_id = 'SWITCH';   if (cclen==16 || cclen==18 || cclen==19) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^34|^37/) )
				{cc_type_id = '*AMEX';   if (cclen==13 || cclen==15) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^3528|^3529|^353|^354|^355|^356|^357|^358|^2131|^1800/) )
				{cc_type_id = 'JCB';   if (cclen==15 || cclen==16) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^300|^301|^302|^303|^304|^305|^36|^380|^381|^382|^383|^384|^385|^386|^387|^388/) )
				{cc_type_id = '*DINERS CLUB';   if (cclen==14) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^389/) )
				{cc_type_id = '*CARTE BLANCHE';   if (cclen==14) {vlengthgood=1;}   else {vlengthgood=0;} }
			if (ccno.match(/^2014|^2149/) )
				{cc_type_id = '*ENROUTE';   if (cclen==15) {vlengthgood=1;}   else {vlengthgood=0;} }

			if (cc_type_id.charAt(0)=="*") badcard=true;
			if (vlengthgood==0) badcard=true;
		} 
		else
		{
			badcard=true;
		}
	}
	if (badcard) 
	{
	 	alert("There appears to be an error in the credit card number");
		return false;
	}
	else
	{
		return true;
	}
}
