function init(menuTitle)
{
	var oTopbar = Compat.getFrame("topbar");
	if(oTopbar == null)
	 document.location.href = ".";

	ieFix();
	if(menuTitle)
	{
		if(menuTitle == "formsent")
			alert("Your comment sent successfully");
		else
			menu(menuTitle);
	}
	
	goToBook();
	top.isNewUser = (isNewUser == "yes");
	goToLoginPage();
}

function goToBook()
{
	try{
	var oTopbar = Compat.getFrame("topbar");
	if ((oTopbar.biblioID != "") || (oTopbar.otzarID != ""))
		oTopbar.showBook();
	}catch(e){ setTimeout(goToBook, 200);}
}

function goToLoginPage()
{
	try{
	var oTopbar = Compat.getFrame("topbar");
	if (oTopbar.urlParam == "login")
	{
		if(top.isUserLoggedIn())
			top.advancedSearch();
		else
			top.showLogin();
	}
	}catch(e){ setTimeout(goToLoginPage, 200);}
}

function menu(show)
{
	var oSpans = document.getElementsByTagName("span");
	for(var i = 0; i < oSpans.length ; i++)
		if(oSpans[i].getAttribute("menu") == "yes")
			oSpans[i].style.display = (oSpans[i].getAttribute("name") == show) ? "block" : "none";
			 
}
function validateForm()
{
	var control = null;
	var errMessage = "";
	var fieldList = new Array(commentForm.name, commentForm.email, commentForm.phone);	
	
	for (var count = 0; count < fieldList.length; count++) 
	{
		control = fieldList[count];
		if (control.value == "") 
		{
			errMessage = "Please insert "  + control.title;
			break;
		}
		else if (control.id == "email") 
		{
			value = control.value;
			if (value.search(/^.+@.+\..+/) == -1) {
				errMessage = "Invalid e-mail address";
				break;
			}
		}
	}
   
	if (errMessage != "") 
	{
		alert(errMessage);
		control.focus();
		return false;
	}
	return true;
}

function sendCommentForm()
{
	if(validateForm())
		commentForm.submit();
}
