﻿
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function moveFocus(text1,callBackFunction,callBackFunctionParams)
{
    var licence1 = text1.value;
    licence1 =  replace(replace(licence1,'-',''),'-','');
    var letters =  licence1.length;

    if  (letters < 6)
    {
        text1.focus();
    }
    else
    {
      if (IsLicenceValid(text1))
      { 
         text1.value.length=6;
         if (callBackFunction != "")
            __doPostBack(callBackFunction,callBackFunctionParams); 
      }  
    }
}
      
function EmptyBox(tb)
{
    tb.value="";
}   

function IsLicenceValid(text1)
{
    var licence1 = text1.value;
    licence1 = replace(replace(licence1,'-',''),'-',''); 

    if (licence1==null)
    {
        return false;
    }
        
    if ((licence1.length==6))
    {
        return true;
    }
    else
    {
        return false;
    }
}
