// Converts 10 digit ISBN to EAN/ISBN13
// Please feel free to use this as needed
// No credit needs to be given to STL or any of STL's divisions.

function ISBN10_to_13(ISBN10)
{
	ISBN10 = ISBN10.replace(/-/g, '');				// remove any hyphens
	ISBN13 = '978' + ISBN10.toString();				// prefix the default for ISBN10-to-13 numbers
	ISBN13 = ISBN13.substring(0, 12);				// get the first 12 numbers in the string
	weight = new Array(1,3,1,3,1,3,1,3,1,3,1,3);	// make an array of weights to multiply with
	var total = 0;
	for ( var i=0; i<12; i++ )			// loop the string and build the total with the weights array
	{
		t = ISBN13.charAt(i);
		total += t * weight[i];
	}
	check = (total % 10);				// the check number is the modulus...
	check = 10 - check;					// ... subtrackted from 10
	if ( check == 10 ) check = 0;		// and perhaps one decimal level back
	return ISBN13 + check.toString();
}


function convert(){
	document.main_form.item_id.value = ISBN10_to_13(document.main_form.isbn.value);
}