horizontal_offset=Math.round((screen.availWidth-2-11-960-11-16-2)/2);
if (horizontal_offset<0) horizontal_offset=0;

function LinkActive(status_text, id, type) {
	window.status=status_text;
	type = (type) ? ".jpg" : ".gif";
	if (id) {
		g=document.getElementById(id);
		g.src="graphics/active/"+id+type;
		g.style.cursor="hand";
	}
}

function LinkPassive(id, type) {
	window.status="";
	type = (type) ? ".jpg" : ".gif";
	if (id) {
		g=document.getElementById(id);
		g.src="graphics/"+id+type;
	}
}

function LinkElementActive(status_text, id, serial, type) {
	window.status=status_text;
	type = (type) ? ".jpg" : ".gif";
	g=document.getElementById(id+"_"+serial);
	g.src="graphics/active/"+id+type;
}

function LinkElementPassive(id, serial, type) {
	window.status="";
	type = (type) ? ".jpg" : ".gif";
	g=document.getElementById(id+"_"+serial);
	g.src="graphics/"+id+type;
}

function LinkPopupActive(status_text, id, type) {
	window.status=status_text;
	type = (type) ? ".jpg" : ".gif";
	if (id) {
		g=document.getElementById(id);
		g.src="graphics/active/"+id+type;
	}
}

function LinkPopupPassive(id, type) {
	window.status="";
	type = (type) ? ".jpg" : ".gif";
	if (id) {
		g=document.getElementById(id);
		g.src="graphics/"+id+type;
	}
}

function LinkDotActive(status_text, id) {
	window.status=status_text;
	id="dot_"+id;
	g=document.getElementById(id);
	g.className="LinkActive";
}

function LinkDotPassive(element, id) {
	window.status="";
	id="dot_"+id;
	g=document.getElementById(id);
	g.className="LinkPassive";
}

function SubmitActive(status_text, other) {
	window.status=status_text;
	button="submit";
	if (other) button+="_"+other;
	g=document.getElementById(button);
	g.className="SubmitActive";
}

function SubmitPassive(other) {
	window.status="";
	button="submit";
	if (other) button+="_"+other;
	g=document.getElementById(button);
	g.className="Submit";
}

function BoldItalicActive(type) {
	window.status="";
	g=document.getElementById(type);
	g.className="BoldItalicActive";
}

function BoldItalicPassive(type) {
	window.status="";
	g=document.getElementById(type);
	g.className="BoldItalic";
}

function LoginCheck() {
	errors=false;
	h=InputText(document.login.username.value);
	if (h=="") {
		LoginError("username");
		errors=true;
	} else if (!ValidUsername(h)) {
		LoginError("username_invalid");
		errors=true;
	} else {
		LoginNoError("username");
	}
	h=InputText(document.login.password.value);
	if (h=="") {
		LoginError("password");
		errors=true;
	} else if (!ValidPassword(h)) {
		LoginError("password_invalid");
		errors=true;
	} else {
		LoginNoError("password");
	}
	return (!errors);
}

function LoginError(id) {
	switch (id) {
		case "username": message=error_messages["username_missing"]; error_id="error_username"; break;
		case "username_invalid": message=error_messages["username_wrong"]; error_id="error_username"; break;
		case "password": message=error_messages["password_missing"]; error_id="error_password"; break;
		case "password_invalid": message=error_messages["password_wrong"]; error_id="error_password"; break;
	}
	g=document.getElementById(error_id);
	g.innerHTML=message;
}

function LoginNoError(id) {
	id="error_"+id;
	g=document.getElementById(id);
	g.innerHTML="<SPACER TYPE=block WIDTH=8>";
}

function FormCheck(id) {
	switch (id) {
		case "registration": items_to_checked=new Array("username", "password", "password_again", "email", "domicile"); break;
		case "profile": items_to_checked=new Array("username", "password_changed", "password_changed_again", "email", "domicile"); break;
		case "forgotten": items_to_checked=new Array("email"); break;
		case "send": items_to_checked=new Array("email_1", "email_2", "email_3", "email_4", "name", "email"); break;
		case "opinion": items_to_checked=new Array("opinion"); break;
	}

	errors=false;
	for (i in items_to_checked) {
		ok=FormItemCheck(items_to_checked[i]);
		if (!ok) errors=true;
	}
	form_checked=true;
	return (!errors);
}

function FormItemCheck(id) {
	switch (id) {
		case "username": h=InputText(document.form.username.value); break;
		case "password": h=InputText(document.form.password.value); break;
		case "password_again": h=InputText(document.form.password_again.value); break;
		case "password_changed": h=InputText(document.form.password.value); break;
		case "password_changed_again": h=InputText(document.form.password_again.value); break;
		case "email": h=InputText(document.form.email.value); break;
		case "domicile": h=InputText(document.form.domicile.value); break;
		case "name": h=InputText(document.form.name.value); break;
		case "email_1": h=InputText(document.form.email_1.value); break;
		case "email_2": h=InputText(document.form.email_2.value); break;
		case "email_3": h=InputText(document.form.email_3.value); break;
		case "email_4": h=InputText(document.form.email_4.value); break;
		case "opinion":
			if (navigator.appName=="Microsoft Internet Explorer") {
				iframe=document.getElementById("iframe_opinion");
				field_text=iframe.contentWindow.document;
				h=InputText(field_text.body.createTextRange().htmlText);
			} else {
				h=InputText(document.form.opinion.value);
			}
			break;
	}

	if (h && h!=true) h=TrimString(h);

	if ((!h || h=="" || h==0) && id!="password_changed" && id!="password_changed_again" && id!="email_1" && id!="email_2" && id!="email_3" && id!="email_4") {
		FormError(id);
		error=true;
	} else if (id=="username" && !ValidUsername(h)) {
		FormError("username_invalid");
		error=true;
	} else if (id=="password" && !ValidPassword(h)) {
		FormError("password_invalid");
		error=true;
	} else if (id=="password_again" && document.form.password.value!="" && h!=document.form.password.value) {
		FormError("different_passwords");
		error=true;
	} else if (id=="password_changed" && h=="" && document.form.password_again.value!="") {
		FormError("password_changed");
		error=true;
	} else if (id=="password_changed" && !ValidPassword(h)) {
		FormError("password_invalid");
		error=true;
	} else if (id=="password_changed_again" && h=="" && document.form.password.value!="") {
		FormError("password_changed_again");
		error=true;
	} else if (id=="password_changed_again" && document.form.password.value!="" && h!=document.form.password.value) {
		FormError("different_passwords");
		error=true;
	} else if (id=="email" && !ValidEmail(h)) {
		FormError("email_invalid");
		error=true;
	} else if (id=="email_1" && InputText(document.form.email_1.value)=="" && InputText(document.form.email_2.value)=="" && InputText(document.form.email_3.value)=="" && InputText(document.form.email_4.value)=="") {
		FormError("email_1");
		error=true;
	} else if (id=="email_1" && !ValidEmail(h)) {
		FormError("email_1_invalid");
		error=true;
	} else if (id=="email_2" && !ValidEmail(h)) {
		FormError("email_2_invalid");
		error=true;
	} else if (id=="email_3" && !ValidEmail(h)) {
		FormError("email_3_invalid");
		error=true;
	} else if (id=="email_4" && !ValidEmail(h)) {
		FormError("email_4_invalid");
		error=true;
	} else {
		FormNoError(id);
		error=false;
	}
	return (!error);
}

function FormError(id) {
	switch (id) {
		case "username": message=error_messages["username_missing"]; error_id="username"; break;
		case "username_invalid": message=error_messages["username_invalid"]; error_id="username"; break;
		case "password": message=error_messages["password_new_missing"]; error_id="password"; break;
		case "password_invalid": message=error_messages["password_invalid"]; error_id="password"; break;
		case "password_again": message=error_messages["password_again"]; error_id="password_again"; break;
		case "different_passwords": message=error_messages["passwords_different"]; error_id="password_again"; break;
		case "password_changed": message=error_messages["password_changed_missing"]; error_id="password"; break;
		case "password_changed_again": message=error_messages["password_changed_again"]; error_id="password_again"; break;
		case "email": message=error_messages["email_missing"]; error_id="email"; break;
		case "email_invalid": message=error_messages["email_wrong"]; error_id="email"; break;
		case "domicile": message=error_messages["domicile_missing"]; error_id="domicile"; break;
		case "name": message=error_messages["name_missing"]; error_id="name"; break;
		case "email_1": message=error_messages["email_friend_missing"]; error_id="email_1"; break;
		case "email_1_invalid": message=error_messages["email_wrong"]; error_id="email_1"; break;
		case "email_2_invalid": message=error_messages["email_wrong"]; error_id="email_2"; break;
		case "email_3_invalid": message=error_messages["email_wrong"]; error_id="email_3"; break;
		case "email_4_invalid": message=error_messages["email_wrong"]; error_id="email_4"; break;
		case "opinion": message=error_messages["opinion_empty"]; error_id="opinion"; break;
	}
	g=document.getElementById("error_"+error_id);
	g.innerHTML=message;
}

function FormNoError(id) {
	switch (id) {
		case "password_changed": id="password"; break;
		case "password_changed_again": id="password_again"; break;
	}
	error_id="error_"+id;
	g=document.getElementById(error_id);
	g.innerHTML="<SPACER TYPE=block WIDTH=8>";
}

function HTMLContent(content) {
	html_content="<HTML>";
	html_content+="<HEAD>";
	html_content+="<META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=iso-8859-2\">";
	html_content+="<LINK REL=\"stylesheet\" TYPE=\"text/css\" HREF=\"editorial/style.css\">";
	html_content+="<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\">repair=false;</SCRIPT>";
	html_content+="</HEAD>";
	html_content+="<BODY CONTENTEDITABLE=true CLASS=IFrameBody onLoad=\"document.body.style.overflowX='hidden'; document.body.style.overflowY='auto';\"";
	html_content+=" onkeypress=\"if (event.keyCode==13) { event.returnValue=false; field_selection=selection.createRange(); field_selection.pasteHTML('<BR><U></U>'); }\"";
	html_content+=" onpaste=\"repair=true;\"";
	html_content+=" onkeyup=\"if (repair) { temp=document.body.createTextRange().htmlText; while (temp.indexOf('<P>')!=-1) temp=temp.replace(/<P>/, ''); while (temp.indexOf('</P>')!=-1) temp=temp.replace(/<\\/P>/, '<BR>'); while (temp.indexOf('&nbsp;')!=-1) temp=temp.replace(/&nbsp;/, ' '); while (temp.indexOf('\\n')!=-1) temp=temp.replace(/\\n/, ' '); while (temp.indexOf('<B> ')!=-1) temp=temp.replace(/<B> /, ' <B>'); while (temp.indexOf(' </B>')!=-1) temp=temp.replace(/ <\\/B>/, '</B> '); while (temp.indexOf('<I> ')!=-1) temp=temp.replace(/<I> /, ' <I>'); while (temp.indexOf(' </I>')!=-1) temp=temp.replace(/ <\\/I>/, '</I> '); regular_expression=/<B>(.*?)<\\/B>/; while (regular_expression.test(temp)) temp=temp.replace(regular_expression, '###B@@@$1###/B@@@'); regular_expression=/<I>(.*?)<\\/I>/; while (regular_expression.test(temp)) temp=temp.replace(regular_expression, '###I@@@$1###/I@@@'); while (temp.indexOf('<BR>')!=-1) temp=temp.replace(/<BR>/, '###BR@@@'); regular_expression=/<.*?>/; while (regular_expression.test(temp)) temp=temp.replace(regular_expression, ''); while (temp.indexOf('###')!=-1) temp=temp.replace(/###/, '<'); while (temp.indexOf('@@@')!=-1) temp=temp.replace(/@@@/, '>'); while (temp.indexOf('  ')!=-1) temp=temp.replace(/  /, ' '); while (temp.indexOf(' <BR>')!=-1) temp=temp.replace(/ <BR>/, '<BR>'); while (temp.indexOf('<BR> ')!=-1) temp=temp.replace(/<BR> /, '<BR>'); while (temp.indexOf('<BR><BR><BR>')!=-1) temp=temp.replace(/<BR><BR><BR>/, '<BR><BR>'); temp=temp.replace(/^ /, ''); temp=temp.replace(/ $/, ''); document.body.innerHTML=temp; repair=false; }\"";
	html_content+=" onmousemove=\"if (repair) { temp=document.body.createTextRange().htmlText; while (temp.indexOf('<P>')!=-1) temp=temp.replace(/<P>/, ''); while (temp.indexOf('</P>')!=-1) temp=temp.replace(/<\\/P>/, '<BR>'); while (temp.indexOf('&nbsp;')!=-1) temp=temp.replace(/&nbsp;/, ' '); while (temp.indexOf('\\n')!=-1) temp=temp.replace(/\\n/, ' '); while (temp.indexOf('<B> ')!=-1) temp=temp.replace(/<B> /, ' <B>'); while (temp.indexOf(' </B>')!=-1) temp=temp.replace(/ <\\/B>/, '</B> '); while (temp.indexOf('<I> ')!=-1) temp=temp.replace(/<I> /, ' <I>'); while (temp.indexOf(' </I>')!=-1) temp=temp.replace(/ <\\/I>/, '</I> '); regular_expression=/<B>(.*?)<\\/B>/; while (regular_expression.test(temp)) temp=temp.replace(regular_expression, '###B@@@$1###/B@@@'); regular_expression=/<I>(.*?)<\\/I>/; while (regular_expression.test(temp)) temp=temp.replace(regular_expression, '###I@@@$1###/I@@@'); while (temp.indexOf('<BR>')!=-1) temp=temp.replace(/<BR>/, '###BR@@@'); regular_expression=/<.*?>/; while (regular_expression.test(temp)) temp=temp.replace(regular_expression, ''); while (temp.indexOf('###')!=-1) temp=temp.replace(/###/, '<'); while (temp.indexOf('@@@')!=-1) temp=temp.replace(/@@@/, '>'); while (temp.indexOf('  ')!=-1) temp=temp.replace(/  /, ' '); while (temp.indexOf(' <BR>')!=-1) temp=temp.replace(/ <BR>/, '<BR>'); while (temp.indexOf('<BR> ')!=-1) temp=temp.replace(/<BR> /, '<BR>'); while (temp.indexOf('<BR><BR><BR>')!=-1) temp=temp.replace(/<BR><BR><BR>/, '<BR><BR>'); temp=temp.replace(/^ /, ''); temp=temp.replace(/ $/, ''); document.body.innerHTML=temp; repair=false; }\"";
	html_content+=">";
	html_content+=content;
	html_content+="</BODY>";
	html_content+="</HTML>";
	return html_content;
}

function SubmitHiddenValueOpinion() {
	if (navigator.appName=="Microsoft Internet Explorer") {
		iframe=document.getElementById("iframe_opinion");
		field_text=iframe.contentWindow.document;
		field_text_content=field_text.body.createTextRange().htmlText;
		g=document.getElementById("opinion");
		g.value=field_text_content;
	}
}

function Emphasize(form_element, emphasis) {
	if (navigator.appName=="Microsoft Internet Explorer") {
		iframe=document.getElementById("iframe_"+form_element);
		field_text=iframe.contentWindow.document;
		field_text.execCommand(emphasis);
		iframe.focus();
	}
}

function Quiz(right_answer) {
	checked_answer="-";
	for (i=0; i<document.quiz.quiz_answer.length; i++)
		if (document.quiz.quiz_answer[i].checked)
			checked_answer=i;
	if (checked_answer=="-") {
		g=document.getElementById("left_quiz_response");
		g.innerHTML="<DIV CLASS=\"Small TextClaret\"><B>"+quiz_choose+"</B></DIV><DIV CLASS=half><BR></DIV>";
	} else if ((checked_answer==0 && right_answer=="a") || (checked_answer==1 && right_answer=="b") || (checked_answer==2 && right_answer=="c")) {
		g=document.getElementById("left_quiz_response");
		g.innerHTML="<DIV CLASS=\"Small TextGreen\"><B>"+quiz_right_answer+"</B></DIV><DIV CLASS=half><BR></DIV>";
		g=document.getElementById("left_quiz_button");
		g.innerHTML="<SPACER TYPE=block WIDTH=119>";
	} else {
		g=document.getElementById("left_quiz_response");
		g.innerHTML="<DIV CLASS=\"Small TextClaret\"><B>"+quiz_wrong_answer+"</B></DIV><DIV CLASS=half><BR></DIV>";
	}
}

function PopupFromIcon(type, section_native, id) {
	width=400;
	height = (type!="send") ? 400 : 480;
	x=screen.availWidth-10-width;
	if (x<0) x=0;
	window.open("popup.php?pagetype="+type+"&section_native="+section_native+"&id="+id, "popup_from_icon", "left="+x+", top=0, width="+width+", height="+height+", scrollbars=yes");
}

function Trivia() {
	width=400;
	height=191;
	x=screen.availWidth-10-width;
	if (x<0) x=0;
	window.open("popup.php?pagetype=trivia", "trivia", "left="+x+", top=0, width="+width+", height="+height);
}

function EnlargedImage(id, width, height) {
	x=screen.availWidth-10-width;
	if (x<0) x=0;
	window.open("popup.php?pagetype=enlarged_image&id="+id, "enlarged_image", "left="+x+", top=0, width="+width+", height="+height);
}

function PopupPrint(section_native, id) {
	width=612;
	height=400;
	x=0;
	window.open("printable_version.php?section_native="+section_native+"&id="+id, "printable_version", "left="+x+", top=0, width="+width+", height="+height+", scrollbars=yes");
}

function BlankPageWithMessage(message, page_language_native) {
	if (window.opener)
		window.opener.location.href="blank.php?message="+message+"&page_language_from_menu="+page_language_native;
}

function Welcome() {
	width=400;
	height=101;
	x=Math.round((screen.availWidth-width)/2);
	if (x<0) x=0;
	y=Math.round((screen.availHeight-height)/2);
	if (y<0) y=0;
	window.open("popup.php?pagetype=welcome", "welcome", "left="+x+", top="+y+", width="+width+", height="+height);
}

function ShowOpinions(section_native, id) {
	if (window.opener)
		window.opener.location.href="blank.php?pagetype="+section_native+"&id="+id;
}

function ShowBook(section_native, id) {
	if (window.opener)
		window.opener.location.href="index.php?pagetype="+section_native+"&id="+id;
}

