
function submitISBN()
{
	var isbn = document.getElementById("isbn").value;
	
	if(isbn.length != 0)
	{
		var isbnForm = document.getElementById("isbnForm");
		isbnForm.action = "../cgi-bin/sell.pl";
		isbnForm.submit();
	}
	else
	{
		var errorMsgSpan = document.getElementById("isbnFormError");
		errorMsgSpan.innerHTML = "<b>Please Enter a Valid ISBN Number</b>";
	}
}

function submitISBNKey(e)
{
	if (window.Event)
	{
	   var keyChar = String.fromCharCode(e.which); // Netscape Navigator 4.0
	}
	else
	{
		var keyChar = String.fromCharCode(window.event.keyCode);
	}

	if(keyChar == '\n' || keyChar == '\r')
	{	
		submitISBN();
		return false;
	}
	else
	{
		return true;
	}
}

function confirmBook()
{
	document.sell.submit();
}

function declineBook()
{
	window.location="../sell.html";
}

function login()
{
	var loginForm = document.getElementById("loginForm");
	var usr = document.getElementById("username").value;
	var pw = document.getElementById("password").value;
	var isbn = document.getElementById("isbn").value;
	
	if(usr.length > 0)
	{

		setMaxDigits(19);	
		var key = new RSAKeyPair(
			"3e23a7aacd658c5c8f2a7290724a6da9",
 			"",
 			"8f3040e0b897c7063d158f7d369cc99f" );
		var encryptedUsr = encryptedString(key, usr);
		var encryptedPw = encryptedString(key, pw);

		//loginForm.action = "../cgi-bin/sell.pl";
		//loginForm.submit();

		window.self.location  = "../cgi-bin/sell.pl?username=" + encryptedUsr 
			+ "&password=" + encryptedPw + "&isbn=" + isbn;

	}
	else
	{
		loginForm.reset();
		loginForm.username.focus();
	}
}

function submitInfo()
{
	var hasErrors = false;

	var price = $("price").value;
	var condition = $("condition").value;
	var comments = $("comments").value;
	var isbn = $("isbn").value;
	var title = $("title").value;
	
	price = "" + price + "";
	price = price.replace(/[^0-9.]/g,"");

	// The only thing we need to check is if the user has entered a valid price.
	if(price.length == 0)
	{
		var priceErrorTD = $("priceError");
		priceErrorTD.removeChild(priceErrorTD.firstChild);
		var boldNode = document.createElement("b");
		boldNode.style.color = "black";
		var textNode = document.createTextNode("Please Enter A Valid Price");
		boldNode.appendChild(textNode);
		priceErrorTD.appendChild(boldNode);

		hasErrors = true;
	}

	if(hasErrors == false)
	{
		window.location = "/cgi-bin/sellprocess.pl?isbn=" + isbn + "&price=" + price + "&condition=" + condition + "&comments=" + comments + "&title=" + title;
	}
}

function $(id)
{
	return document.getElementById(id);
}
