<!--
//********************************************************************
// Credit Card Number Validator Written By: Lokesh
//                                   Date : 04/08/2004
// Uses Linh mod-10 formula to determine the validity and then
// calls different functions to check what category the number belongs
// to.
//********************************************************************

var invalid = "Invalid";
//********************************************************************
// Check the Linh Mod-10 validity

function CheckCreditCardNum(num)
{
  var len=num.length;
  var first;
  var sum=0;
  var mul=1;
  var i;
  var numAtI;
  var tempSum;
  var theway;
  var txtcard;
  theway = "";
  for(i=(len-1); i >= 0 ;--i)
  {
   numAtI = parseInt(num.charAt(i));
   tempSum = numAtI * mul;
   theway += numAtI +" x " + mul +"=" + tempSum;
   if(tempSum > 9)
   {
    first = tempSum % 10;
    theway += " => "+ 1 +" + " + first +"=";
    tempSum =  1 +  first;
    theway += tempSum +" ";
   }
   theway += "\n";
   sum += tempSum;

   if (mul == 1)
     mul++;
   else
     mul--;
  }
  theway += "----------\nSum:   "+ sum +"\n";


//*********************************************************
// Comment this line if you want to see the calculation

 
 theway = "Checking for Card Vallidity\n";
  if(sum % 10)
  {
   if (len == 15)
   {
   	txtcard = CheckFor15(num,0);
	if ( txtcard == invalid )
	{
	   alert(theway +"The number: "+ num +" is not valid!! ");
           return false;
        }
   }
   else
   {
    alert(theway +"The number: "+ num +" is not valid!! ");
    return false;
   }

  }

  {
    switch(len)
    {
	case 13:
	   txtcard = CheckFor13(num);
	   break;
	case 14:
	   txtcard = CheckFor14(num);
	   break;
	case 15:
	   txtcard = CheckFor15(num,1);
	   break;
	case 16:
	   txtcard = CheckFor16(num);
	   break;
	default:
	   txtcard = invalid;
    }
    if(txtcard == invalid)
    {
	   alert(theway +"The number: "+ num +" is not valid!! ");
   	   return false;
    }
    else
    theway+= "The number: "+ num +" is valid!! \nand it looks like it is: "+ txtcard;
  }
  alert(theway);
  return true;
} 

//***********************************************************************************
// Checks for Visa..
function CheckFor13(number)
{
  if(parseInt(number.charAt(0)) == 4 )
	return "Visa";
  return invalid;
}

//************************************************************************************
// Check for Diners Club
function CheckFor14(number)
{
  if( parseInt(number.charAt(0)) != 3 )
	return invalid;
  if( (parseInt(number.charAt(1)) == 6) || (parseInt(number.charAt(1)) == 8) )
	return "Diners Club/Carte Blanche"
  if( !(parseInt(number.charAt(1)) ))
	if( (parseInt(number.charAt(2)) >= 0) && (parseInt(number.charAt(2)) <= 5))
		return "Diners Club/Carte Blanche"
  return invalid;
}

//************************************************************************************
// Check for American Express, enRoute, JCB
function CheckFor15(number, chec)
{
    if ( (number.charAt(0) == 3) && ( (number.charAt(1) == 4)||(number.charAt(1) == 7) ) && chec)
	return "American Express";
    var FirstFour =  parseInt(number.charAt(0))*1000;
	FirstFour += parseInt(number.charAt(1))*100;
	FirstFour += parseInt(number.charAt(2))*10;
	FirstFour += parseInt(number.charAt(3));
    //alert(FirstFour);
    if( (FirstFour == 2014) || (FirstFour == 2149) )
	return "enRoute";

    if( ((FirstFour == 2131) || (FirstFour == 1800)) && chec )
	return "JCB";

    return invalid;
}

//************************************************************************************
// Check for Visa, MasterCard, Discover or JCB
function CheckFor16(number)
{
  var a = parseInt(number.charAt(0));
  var b = parseInt(number.charAt(1));
  //alert (a);
  switch (a)
  {
    case 5:
        if((b > 0)&& (b < 6))
		return "MasterCard";
	else
		return invalid;
	break;
   case 4:
	return "Visa";
	break;
   case 6:
	if ( (b == 0) && ( parseInt(number.charAt(2)) == 1) && ( parseInt(number.charAt(3)) == 1))
  		return "Discover";
	else
		return invalid;
	break;
   case 3:
	return "JCB";
	break;
   default:
	return invalid;
	break;
  }
}
//-->

function flvFPW1(){// v1.3
// Copyright 2002, Marja Ribbers-de Vroed, FlevOOware (www.flevooware.nl/dreamweaver/)
var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18;if (v4>1){v10=screen.width;for (v6=0;v6<v2.length;v6++){v18=v2[v6].split("=");if (v18[0]=="width"){v8=parseInt(v18[1]);}if (v18[0]=="left"){v9=parseInt(v18[1]);v11=v6;}}if (v4==2){v7=(v10-v8)/2;v11=v2.length;}else if (v4==3){v7=v10-v8-v9;}v2[v11]="left="+v7;}if (v5>1){v14=screen.height;for (v6=0;v6<v2.length;v6++){v18=v2[v6].split("=");if (v18[0]=="height"){v12=parseInt(v18[1]);}if (v18[0]=="top"){v13=parseInt(v18[1]);v15=v6;}}if (v5==2){v7=(v14-v12)/2;v15=v2.length;}else if (v5==3){v7=v14-v12-v13;}v2[v15]="top="+v7;}v16=v2.join(",");v17=window.open(v1[0],v1[1],v16);if (v3){v17.focus();}document.MM_returnValue=false;}
//-->

