function checkrequired() {
	var vendors = new Array();
	isbn = document.getElementById("isbnform").isbnno.value.replace(/[- \.]/g, "");
	isbn = correctisbn(isbn);
	if (isbn == false) {
//		returnisbn10 = "false";
//		returnisbn13 = "false";
//		vendors[1] = "not defined";
		alert("Invalid ISBN or EAN number.");
		document.getElementById("isbnform").isbnno.focus();
		return false;
	}
	else if (isbn.length == 13 && isbn.substring(0, 3) != "977" && isbn.substring(0, 3) != "978" && isbn.substring(0, 3) != "979") {
		// Search EAN
		returnisbn10 = "This is an EAN code.";
		returnisbn13 = isbn;
		vendors[1] = checkean(isbn.substring(0, 3));
	}
	else if (isbn.length == 13 && isbn.substring(0, 3) == "977" && isbn.substr(10, 2) == "00") {
		// Search EAN
		returnisbn10 = "This is an ISSN code.";
		returnisbn13 = isbn;
		vendors[1] = checkean(isbn.substring(0, 3));
	}
	else {
		countrylength = checkcountrylength(isbn);
		countrycode = parseFloat(isbn.substring(0, countrylength));
		vendors = checkvendor(countrycode, isbn.substring(countrylength, 12));
		vendorlength = vendors[0];
		vendorcode = isbn.substring(countrylength, countrylength + vendorlength);
		if (vendorlength != -1) {
			countrycode = "" + countrycode;
			if (isbn.substring(0, 3) == "978") {
				returnisbn10 = checkISBN10(isbn.substring(3, 12));
				returnisbn10 = countrycode.substring(3, countrylength) + "-" + vendorcode + "-" + returnisbn10.substring(countrylength + vendorlength - 3, 9) + "-" + returnisbn10.substring(9, 10);
				returnisbn13 = "978-" + countrycode.substring(3, countrylength) + "-" + vendorcode + "-" + isbn.substring(countrylength + vendorlength, 12) + "-" + isbn.substring(12, 13);
			}
			else if (isbn.substring(0, 3) == "979") {
				returnisbn10 = "N/A";
				returnisbn13 = "979-" + countrycode.substring(3, countrylength) + "-" + vendorcode + "-" + isbn.substring(countrylength + vendorlength, 12) + "-" + isbn.substring(12, 13);
			}
			else {
				returnisbn10 = "N/A";
				returnisbn13 = isbn;
			}
		}
		else {
			returnisbn10 = checkISBN10(isbn.substring(3, 12));
			returnisbn13 = isbn;
		}
	}
	document.getElementById("isbnform").isbnno.value = "";
	document.getElementById("isbnform").isbnno10.value = returnisbn10;
	document.getElementById("isbnform").isbnno13.value = returnisbn13;
	document.getElementById("isbnform").isbnregion.value = vendors[1];
	document.getElementById("isbnform").isbnno.focus();
	return false;
}
function correctisbn(isbn) {
	if (isbn.length == 9 || isbn.length == 12) {
		isbn = isbn + " ";
	}
	if (isbn.length != 10 && isbn.length != 13 || (isbn.length == 10 && isNaN(isbn.substring(0, 9))) || (isbn.length == 13 && isNaN(isbn))) {
		return false;
	}
	if (isbn.length == 10) {
		isbn = "978" + isbn;
	}
	return checkISBN13(isbn.substring(0, 12))
}
function checkcountrylength(isbn) {
	if (isbn >= 9780000000000 && isbn <= 9785999999999 || isbn >= 9787000000000 && isbn <= 9787999999999) {
		countrylength = 4;
	}
	else if (isbn >= 9788000000000 && isbn <= 9789499999999 || isbn >= 9791000000000 && isbn <= 9791099999999) {
		countrylength = 5;
	}
	else if (isbn >= 9786000000000 && isbn <= 9786499999999 || isbn >= 9789500000000 && isbn <= 9789899999999) {
		countrylength = 6;
	}
	else if (isbn >= 9789900000000 && isbn <= 9789989999999) {
		countrylength = 7;
	}
	else if (isbn >= 9789990000000 && isbn <= 9789999999999) {
		countrylength = 8;
	}
	else {
		countrylength = 10;
	}
	return countrylength;
}
function checkISBN10(code) {
	code = (code + '').replace(/[-\s]/g, '');
	if (!/^\d{9}[\dxX]?$/.test(code)) return;
	var i = 0,
		c = 0; // c:checksum
	for (; i < 9;)
	c += code.charAt(i++) * i;
	c %= 11;
	if (c == 10) c = 'X';
	if (code.length == 9) return code + c;
	return c == (i = code.charAt(9)) || c == 'X' && i == 'x';
}
function checkISBN13(code) {
	code = (code + '').replace(/[-\s]/g, '');
	if (!/^\d{12,13}$/.test(code)) return;
	var i = 1,
		c = 0; // c:checksum
	for (; i < 12; i += 2)
	c += Math.floor(code.charAt(i));
	for (c *= 3, i = 0; i < 12; i += 2)
	c += Math.floor(code.charAt(i));
	c = (220 - c) % 10; // 220: larger than(1*6+3*6), so %10==0.
	if (code.length == 12) return code + c;
	return c == code.charAt(12);
}
function log10(arg) {
	// Returns the base-10 logarithm of the number
	return Math.log(arg) / Math.LN10;
}
