/************************************************************************************************
* File Name     :   Isbnconversion.js
* Company       :   Elsevier Science
* Description   :   This java script contains methods useful for ISBN 10 - 13 conversion.
* Modifications :
*************************************************************************************************/
//Method to convert 10 digits ISBN to 13 digits ISBN
function Convertisbn(from,to,isbn) {
	var i = 0;
	var v = 0;
	var n = 0;
	var c = "";
	var Result = "";
	var s12 = "";
	var ISBN10 = isbn;
	var len = ISBN10.length;
	//Returns same passed ISBN string if length is <9 or >10
	if (len<9 || len>10) 
		Result=isbn;
	else 
	{
		s12 = "978" + ISBN10.substring(0, 9);
		for (i=0; i<12; i++) 
		{
			if (Result=="") 
			{
				c = s12.charAt(i);
				if (c>="0" && c<="9") 
				{
					v = c - 0;
					if ((i % 2)!=0) 
						v = 3 * v;
					n = n + v; 
				}
				else 
					Result=isbn
			}
		}
		if (Result=="") 
		{
			n = n % 10;
			if (n!=0) 
				n = 10 - n;
			Result = s12 + n; 
		} 
	}
return Result;
}
//Method to validate the ISBN search string whether string consists only 0-9,X,x and - letters
function isValidISBN(str)
{
	var valid="0123456789X-x";
	str=trim(str);
	for (var i=0; i<str.length; i++) {
		if (valid.indexOf(str.charAt(i)) < 0) {
			return false;
		}
	}
	return true;
}
//Method to trim the passed string if it consists of leading left and right white spaces
function trim(str)
{ 
	return str.replace(/^\s*|\s*$/g,""); 
} 

