function validate_tag(field) {
veh_string = document.getElementById('tfa_CarPlateNo').value;
var temp = "";
veh_string = '' + veh_string;
splitfield = veh_string.split(" ");
for(i = 0; i < splitfield.length; i++)
temp += splitfield[i];
veh_string = temp.toUpperCase();
f_len = veh_string.length; if (f_len==0) {return "";}
if (!isNaN(veh_string.charAt(f_len-1))) {alert("Whoops! Is This The Correct Vehicle Number?"); return veh_string;}
a1=a2=a3=n1=n2=n3=n4="0"; fC=veh_string.charAt(f_len-1);
i=f_len-2;
n4 = parseInt(veh_string.charAt(i)); i-=1;
if (!isNaN(veh_string.charAt(i))) {n3 = parseInt(veh_string.charAt(i)); i-=1;}
if (!isNaN(veh_string.charAt(i))) {n2 = parseInt(veh_string.charAt(i)); i-=1;}
if (!isNaN(veh_string.charAt(i))) {n1 = parseInt(veh_string.charAt(i)); i-=1;}
if (isNaN(veh_string.charAt(i))) {a3 = parseInt(veh_string.charCodeAt(i)); i-=1;} 
if (isNaN(veh_string.charAt(i)) && i>=0) {a2 = parseInt(veh_string.charCodeAt(i)); i-=1;}
if (isNaN(veh_string.charAt(i)) && i>=0) {a1 = parseInt(veh_string.charCodeAt(i)); i-=1;}
a2 -= 64; a2 *= 9; a3 -= 64; a3 *= 4; n1 *= 5; n2 *= 4; n3 *= 3; n4 *= 2;
sum_p = a2 + a3 + n1 + n2 + n3 + n4;
mod_p = sum_p % 19;
var lastD = new Array();
lastD[0] = 'A'; lastD[1] = 'Z'; lastD[2] = 'Y'; lastD[3] = 'X'; lastD[4] = 'U'; lastD[5] = 'T'; lastD[6] = 'S'; lastD[7] = 'R'; lastD[8] = 'P'; lastD[9] = 'M'; lastD[10] = 'L'; lastD[11] = 'K'; lastD[12] = 'J'; lastD[13] = 'H'; lastD[14] = 'G'; lastD[15] = 'E'; lastD[16] = 'D'; lastD[17] = 'C'; lastD[18] = 'B';
if (lastD[mod_p] != fC) {alert("Whoops! Is This The Correct Vehicle Number?");}
return veh_string;}

function ignoreSpaces(string) {
 var temp = "";
 string = '' + string;
 splitstring = string.split(" ");
 for(i = 0; i < splitstring.length; i++)
 temp += splitstring[i];
 temp = temp.toUpperCase();
 return temp;}
 
function toProperCase(s) {
 return s.toLowerCase().replace(/^(.)|\s(.)/g, 
 function($1) { return $1.toUpperCase(); });}

