
var flex;
var maxLength    = 450;
var codeValue    = "document.cform.ticket";
var txt          = "document.cform.ticket.value";

function init(gForm)
  {
  this.getCode               = getCode;
  this.numberFocus     	     = numberFocus;
  this.isCode                = isCode;
  this.Validation            = Validation;
  this.isDots                 = isDots;
this.checkIllegalDots       = checkIllegalDots;
  }

function getCode()
{
return this.number     = eval(codeValue + ".value");
}

function numberFocus()
{
return eval(codeValue);
}

function isCode()
  {
  if (this.checkEmpty(this.getCode(),this.numberFocus(),"Card collection code No.")              &&
       this.noSpacesAllowed(this.getCode(),this.numberFocus(),"Card collection code No.","all")
                     &&
      this.digitSize(this.getCode(),this.numberFocus(),"Card collection code No.",13)      && 
      this.digitmaxSize(this.getCode(),this.numberFocus(),"Card collection code No.",20)    &&         this.digitsOnly(this.getCode(),this.numberFocus(),"Card collection code No.") &&            this.checkIllegalDots(this.getCode(),this.numberFocus(),"Cardcollection code no",5))
    {return (true);}
  return (false);
  }

function digitSize(f,m,s,digitLength)
  {
  var length = f.length;
  if (length < digitLength)
    {
    alert(s + " can not be less than " + digitLength + " digits.");
    m.focus();
    return (false);
    }
if (!isDots(f, 2))
    {
    alert("Please check your Card Collection Code. \n It should contain 2 dots.");
    m.focus();
    return (false);
    }
      return (true);
	  }

function digitmaxSize(f,m,s,digitLength)
  {
  var length = f.length;
  if (length > digitLength)
    {
    alert(s + " can not be greater than " + digitLength + " digits.");
    m.focus();
    return (false);
    }
   return (true);
 }

function digitsOnly(f,m,s)
  {
  var length = f.length;
  for (var i = 0; i < length; i++)
     {
     var ch = f.substring(i, i + 1);
     if ( ((ch < "0") || (ch > "9")) && (ch != "."))
       {
       alert(s  + " contains digits between  (0 - 9) and ' . ' inbetween the code.\nPlease check  your code.");
       m.focus();
       return (false);
              }
    }
  return (true);
  }

function checkEmpty(f,m,s)
  {
  if (f == "")
    {
    alert("Please enter your " + s);
    m.focus();
    return false;
    }
  return (true);
    }

function noSpacesAllowed(f,m,s,w)
  {
  var length = f.length;
  var ch = "";
  if (w == "lt")
    {
    if (f.substring(0,1) == " " || f.substring((length - 1),length) == " ")
      {
      alert(s + " field does not except any before,after or inbetween blank spaces.");
      f=""
      m.focus();
      return (false);
      }
    }
  else {
       for (var i = 1; i < length; i++)
          {
          ch = f.substring(i, i + 1);
          if (ch == " ")
            {
            alert("Please do not leave any blank spaces before,after or inbetween the card collection code no.");
	    m.focus();
            return false;
            }
          }
        }
  return (true);
  }

function Validation(newForm)
  {
  if (!this.isCode()) 
    {
     return (false);
    }
   return (true);
 }

function isDots(f, maxDots)
  {
  var oldIndex = 0;
  var newIndex = -2;
  var length = f.length;
  var count = 0;
  for (var i = 0; i < length; i++)
     {
     var ch = f.substring(i, i + 1);
     oldIndex = newIndex;
     if (ch == ".")
       {
       count++;
       newIndex = f.indexOf(".",i);
       }
     if ((newIndex - oldIndex) == 1) {return (false);}
     }
  if (count < maxDots) {return (false);}
  return (true);
  }

function checkIllegalDots(f,m)
  {
    maxDots = 2;
    if (!isDots(f, maxDots))
      {
      alert("Please check your Card Collection Code.");
     m.focus();
      return (false);
      }
   if ((f.indexOf(".") < 5))
      {
      alert("Please check your Card Collection Code number\n It seems that you have put dots in wrong position.");
      m.focus();
      return (false);
      }
    return (true);
  }
function Checkcode() {
txt=document.cform.code.value;
if (txt.indexOf(".")>=6){
alert("Check your Card collection code .Please"
+"check the prefix and '.' sign.");
document.cform.code.focus();
return false;
}
else
return true; 
}
