var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var otherValidation;

function Validator(frmname,btnname,otherValidatio)
{
otherValidation=otherValidatio;
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}	
	this.btnobj = this.formobj[btnname];
	if(!this.btnobj)
	this.btnobj=document.getElementById(btnname);
	
	if(!this.btnobj)
	{
	  alert("BUG: couldnot get object "+btnname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	//this.formobj.onsubmit=form_submit_handler;	
	this.btnobj.onclick=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
	
}

function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
function form_submit_handler()
{
	//alert(eval(otherValidation))
	if(eval(otherValidation)==false)
	{
	return false;
	}
	for(var itr=0;itr < this.form.elements.length;itr++)
	{
		if(this.form.elements[itr].validationset &&
	   !this.form.elements[itr].validationset.validate())
		{
		  return false;
		}
	}
	if(this.form.addnlvalidation)
	{
	  str =" var ret = "+this.form.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}
function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
	if(!itemobj)
	itemobj =document.getElementById(itemname);
	
	
  if(!itemobj)
	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}	
	if(descriptor=="compare" || descriptor=="credit" || descriptor=="creditCard")
      { 
      //alert(errstr);
           var arr = errstr.split("|")           
           compControl2 = arr[0];
          var itemComp = this.formobj[compControl2];
	        if(!itemComp)
	            itemComp =document.getElementById(compControl2); 
	         if(!itemComp)
	            {
	              alert("BUG: Couldnot get the input object named: "+compControl2);
		            return;
	            }     
      } 
//	alert(itemname);///////////////////////////////////////
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
    if(!this.itemobj.disabled)
    this.itemobj.focus();
		return false;
 }
 return true;
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}
function IsImage(oObject)
{
	var ext=trim(oObject.value);	
	if(ext.length>0)
	{	   
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if(ext != 'jpg'&& ext != 'gif' && ext != 'bmp' && ext != 'jpeg')
		{
		alert('You selected a .'+ext+' file; please select a image file instead!');
		return false;
		}
		else
		return true; 
	}
		return true;
}	
function IsSound(oObject)
{
	var ext=trim(oObject.value);	
	if(ext.length>0)
	{	   
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if(ext != 'MP3' && ext != 'mp3')
		{
		alert('You selected a .'+ext+' file; please select a MP3 file instead!');
		    return false;
		}
		else
		    return true; 
	}
    return true;
}	
function IsZipOrMp3(oObject)
{
	var ext=trim(oObject.value);	
	if(ext.length>0)
	{	   
		ext = ext.substring(ext.length-3,ext.length);
		ext = ext.toLowerCase();
		if(ext != 'MP3' && ext != 'mp3' && ext != 'ZIP' && ext != 'zip')
		{
		alert('You selected a .'+ext+' file; please select a MP3 or ZIP file instead!');
		    return false;
		}
		else
		    return true; 
	}
    return true;
}	

//function is used to check the radio button selection
function valButton(btn)
{
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--)
    {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1)
         return btn[cnt].value;
    else
         return null;
}
 

function V2validateData(strValidateStr,objValue,strError) 
{ 
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    
    //compare
        var compControl2=""
        if(command=="compare" || command=="credit" || command=="creditCard")
        {
           var arr = strError.split("|")
           strError = arr[1];
           compControl2 = arr[0];
        } 
    
    //compare
    
  //  alert(command);//////////////////////////////////////////////////////
    switch(command) 
    { 
		case "Image":
		case "image":
		{
		    if(!IsImage(objValue))
		    {
		    alert(IsImage(objValue));
		    return false
		    }
			
			break;
			//IsImage
		}
		case "sound":
		case "Sound":
		{
		    if(!IsSound(objValue))
		    {
		        //alert(IsSound(objValue));
		    return false
		    }
			break;
			//IsImage
		}
		case "MP3ORZIP":
		case "mp3orzip":
		{
		    if(!IsZipOrMp3(objValue))
		    {
		        //alert(IsSound(objValue));
		    return false
		    }
			break;
			//IsImage
		}
		
        case "compare": 
         { //alert(trim(objValue.value))
           if(trim(objValue.value) != document.getElementById(compControl2).value) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " Passwords not matched!!";                
              }//if 
               document.getElementById(compControl2).focus();
              alert(strError); 
              
              return false; 
           }//if 
           break;             
         }//case compare          
        case "req": 
        case "required": 
         { //alert(trim(objValue.value))
           if(eval(trim(objValue.value).length) == 0) 
           { objValue.value="";
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               //alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               alert(strError); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               //alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               alert(strError); 
               //alert("Please enter a minimum of "+cmdvalue + " characters.\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                alert(strError); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
            case "pwdMatch": 
        case "pwdMatch": 
           { 
                var userInput = objValue.value;
                if (userInput.match (/\d/g)!=null && userInput.match(/\d/g).length>=1 && userInput.match (/[a-z]/gi)!=null && userInput.match (/[a-z]/gi).length>=1 ) 
                {
                     /// at least one letter (ignoring case) and one number
                    //alert ("Password is valid")
                }
                else
                {
                    if(!strError || strError.length ==0) 
                    {
                        strError = objValue.name+": Only alpha-numeric characters allowed "; 
                    }//if 
                    //alert(strError + "\n [Please check the position]"); 
                    alert(strError); 
                    return false; 
                }  
             break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                alert(strError); 
                return false; 
              }//if 
              break;               
           }//numeric 
        
        case "onlynum": 
        case "onlynumeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                alert(strError); 
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z ]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alphabetic characters allowed "; 
                }//if                             
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                alert(strError); 
                return false; 
              }//if 
              break; 
           }//alpha 
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                alert(strError); 
                return false; 
              }//if 			
			break;
			}
		case "phone":
		case "PHONE":
		{
            var charpos = objValue.value.search("[^0-9\-+()/. ]"); 
            if(objValue.value.length > 0 &&  charpos >= 0) 
            { 
                if(!strError || strError.length ==0) 
            { 
                strError = objValue.name+": characters allowed are 0-9,-,/,.,+,()"; 
            }//if                             
            //alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
            alert(strError); 
            return false; 
            }//if 			
		break;
		}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = " Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
          
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
		 	if(objValue.value.length > 0)
			{
	            if(!objValue.value.match(cmdvalue)) 
	            { 
	              if(!strError || strError.length ==0) 
	              { 
	                strError = objValue.name+": Invalid characters found "; 
	              }//if                                                               
	              alert(strError); 
	              return false;                   
	            }//if 
			}
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 
            if(objValue.value == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case Check Date
        
        case "numDate": 
        case "numericDate": 
        { 
                if (isDate(objValue.value)==false)
	            {
		            return false
	            }
              break;               
           }//numericDate 
          case "credit": 
          case "creditCard": 
         { 
           // alert(trim(objValue.value))
           nam=eval(document.getElementById(compControl2));
           Cname=nam.options[nam.selectedIndex].text;
            if(!checkCreditCard (trim(objValue.value),Cname))
            {
//                alert(Cname);
                alert (ccErrors[ccErrorNo]);
                document.getElementById(compControl2).focus();
                return false;
            }
           break;             
         }//case creditCard
    }//switch 
    return true; 
}

// Trim leading and trailing spaces
function trim(lstr) 
{
    return ltrim(rtrim(stripLineFeed(lstr)));
}

function stripLineFeed(strText)
{
	var strReturnText = strText;
	var flgContinue = true;

	// Only check if the string passed in has a length greater than zero	
	if (strReturnText.length > 0)
	{
		// Loop as long as the last character is either a line feed or a carriage return
		while (flgContinue == true)
		{
			// If the last character is either a backspace or a line feed, strip it off
			if (strReturnText.charAt(strReturnText.length - 1) == '\n' || strReturnText.charAt(strReturnText.length - 1) == '\r')
			{
				strReturnText = strReturnText.substr(0, strReturnText.length - 1);
			}
			else
			{
				// If the last character is not a carriage return or line feed, stop looping
				flgContinue = false;
			}
		}
	}

	return strReturnText;
}
  
//  This function trims all spaces from the left-hand side of a string.
function ltrim(lstr) 
{
	if (lstr != "") 
	{
		var strlen, cptr, lpflag, chk;
		strlen = lstr.length;
		cptr = 0;
		lpflag = true;

		do 
		{
			chk = lstr.charAt(cptr);
            if (chk != " ") 
            {
				lpflag = false;
			}
            else 
            {
                if (cptr == strlen) 
                {
					lpflag = false;
				}
                else 
                {
					cptr++;
				}
			}
		}
        
        while (lpflag == true)
		if (cptr > 0) 
		{
			lstr = lstr.substring(cptr,strlen);
		}
	}
	
	return lstr;
}

//  This function trims all spaces from the right-hand side of a string.
function rtrim(lstr) 
{
	if (lstr != "") 
	{
		var strlen, cptr, lpflag, chk;
		strlen = lstr.length;
		cptr = strlen;
		lpflag = true;

		do 
		{
			chk=lstr.charAt(cptr-1);
			if (chk != " ") 
			{
			    lpflag = false;
			}
			else 
			{
				if (cptr == 0) 
				{
					lpflag = false;
				}
				else 
				{
				    cptr--;
				}
			}
		}

        while (lpflag == true)
        if (cptr < strlen) 
        {
			lstr = lstr.substring(0, cptr);
		}
	}
    
    return lstr;
}

/*function checkCheckBox(f)
{
if (f.checkBox2.checked == false )
{
alert('Please check the box I Agree to abide by Rules and Regulations.');
return false;
}else
return true;
}
*/
/*function validateConfirm(vfld,ifld)   // checkbox to be validated
                               // id of element to receive info/error msg
{
  var stat = commonCheck2(vfld, ifld);
  if (stat != proceed) return stat;

  if (vfld.checked) return true;

  // if we get here then the validation has failed

  var errorMsg = 'Please read the above message and confirm you agree to it';

  msg (ifld, "error", errorMsg);
  return false;
}*/
/*
	Copyright 2003 JavaScript-coder.com. All rights reserved.
*/


/**
 
 */
// Declaring valid date character, minimum year and maximum year


function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Please enter the date.")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}









/*============================================================================
   e.g. if (!checkCreditCard (number, name) alert (ccErrors(ccErrorNo);
*/

var ccErrorNo = 0;
var ccErrors = new Array ()

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function checkCreditCard (cardnumber, cardname) {

//alert(cardnumber);  
  // Array to hold the permitted card characteristics
  var cards = new Array();

  // Define the cards we support. You may add addtional card types.
  
  //  Name:      As in the selection box of the form - must be same as user's
  //  Length:    List of possible valid lengths of the card number for the card
  //  prefixes:  List of possible prefixes for the card
  //  checkdigit Boolean to say whether there is a check digit
  
  cards [0] = {name: "VISA", 
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "Master Card", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "DinersClub", 
               length: "14,", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [3] = {name: "CarteBlanche", 
               length: "14", 
               prefixes: "300,301,302,303,304,305,36,38",
               checkdigit: true};
  cards [4] = {name: "American Express", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [5] = {name: "Discover", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
  cards [6] = {name: "JCB", 
               length: "15,16", 
               prefixes: "3,1800,2131",
               checkdigit: true};
  cards [7] = {name: "Enroute", 
               length: "15", 
               prefixes: "2014,2149",
               checkdigit: true};
               
  // Establish card type
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {

    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }
   
  // Ensure that the user has provided a credit card number
  if (cardnumber.length == 0)  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Check that the number is numeric, although we do permit a space to occur  
  // every four digits. 
  var cardNo = cardnumber
  var cardexp = /^([0-9]{4})\s?([0-9]{4})\s?([0-9]{4})\s?([0-9]{1,4})$/;
  if (!cardexp.exec(cardNo))  {
     ccErrorNo = 2;
     return false; 
  }
    
  // Now remove any spaces from the credit card number
  cardexp.exec(cardNo);
  cardNo = RegExp.$1 + RegExp.$2 + RegExp.$3 + RegExp.$4;
       
  // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  

  // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid) {
     ccErrorNo = 4;
     return false; 
  };   
  
  // The credit card is in the required format.
  return true;
}


/*============================================================================*/
/*function ValidateForm()
{
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false)
	{
		dt.focus()
		return false
	}
    return true
}*/

