function testVin(vin) {
	vin = vin.toUpperCase();
	
	if(vin.substring(0,1) == 'I') {
	vin = vin.substring(1);	
	} 
	
	val = vin.charAt(8);
	
	if(vinIsValid(vin) && val == vinCheckSum(vin)) {
	return true;	
	}
	 
	return false;
}

function vinIsValid(vin) {
	if(vin.length != 17) {return false;}
	for(i = 0; i < 17; i++) {
		ptr = vin.charAt(i);
		if(ptr == 'I' || ptr == 'O' || ptr =='Q') {return false;}	
	}
	return true;
}

function vinCheckSum(vin) {
	positions = new Array(16);
	positions[0] = 8;
	positions[1] = 7;
	positions[2] = 6;
	positions[3] = 5;
	positions[4] = 4;
	positions[5] = 3;
	positions[6] = 2;
	positions[7] = 10;
	positions[8] = 'x';
	positions[9] = 9;
	positions[10] = 8;
	positions[11] = 7;
	positions[12] = 6;
	positions[13] = 5;
	positions[14] = 4;
	positions[15] = 3;
	positions[16] = 2;
	
	digval = new digitValues();
	
	sum = 0;
	for(i = 0; i < 17; i++) {
		if(i != 8) {	// skip checksum on char 8
		p = vin.charAt(i);	
		if(isNaN(p)) {x = eval("digval." + p);} else {x = p;}	
		y = positions[i];
	
		sum += parseInt(x * y);
		}
	}
	
	rem = sum % 11;
	b = (rem == 10) ? 'X' : rem;	
	
	return b;
}

function digitValues() {
	this.A = 1;
	this.B = 2;
	this.C = 3;
	this.D = 4;
	this.E = 5;
	this.F = 6;
	this.G = 7;
	this.H = 8;
	this.J = 1;
	this.K = 2;
	this.L = 3;
	this.M = 4;
	this.N = 5;
	this.P = 7;
	this.R = 9;
	this.S = 2;
	this.T = 3;
	this.U = 4;
	this.V = 5;
	this.W = 6;
	this.X = 7;
	this.Y = 8;
	this.Z = 9;
}