var GoogleAr = new Array("en|de","en|es", "en|fr", "en|it", "en|pt","en|ko","en|ar");
var EctacoAr = new Array("13","12", "19", "6", "8", "22", "3");
var EctacoArIndex = new Array("7","20", "6", "10", "15", "11", "1");
var digits = new Array("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
var hasharray = new Array("#one", "#two", "#three", "#four", "#five", "#six", "#seven", "#eight", "#nine", "#ten");
var flagEnd = "false";
var message_tmp = "";
var name_tmp = "";
var cnt = 0;
var submitcount = 0;
var support = new Array("s1","s2","s3","s4","s5","s6","s7","s8","s9","s10");
var schalter = new Array(0,0,0,0,0,0,0,0,0,0);
var test = new Array("p1","p2","p3","p4","p5","p6","p7","p8","p9","p10");
var vstavka = new Array("v1","v2","v3","v4","v5","v6","v7","v8","v9","v10");
var y_vstavka = new Array("y1","y2","y3","y4","y5","y6","y7","y8","y9","y10");
var x_vstavka = new Array("x1","x2","x3","x4","x5","x6","x7","x8","x9","x10");
var z_vstavka = new Array("z1","z2","z3","z4","z5","z6","z7","z8","z9","z10");
var m_vstavka = new Array("m1","m2","m3","m4","m5","m6","m7","m8","m9","m10");
var k_vstavka = new Array("k1","k2","k3","k4","k5","k6","k7","k8","k9","k10");

function formText(number,tmp1,tmp2){
	txtcookiestmp = (window.navigator.cookieEnabled) ? "" : txtcookies;
	return "<TABLE cellSpacing=0 cellpadding=0 border=0 width=582 class='tbb'><TR class='tbb'><TD bgColor='#F4F4ED'><TABLE cellSpacing=3 cellPadding=2 width='100%' border=0 class='tba'><TR class='tba'><TD align=center>Post Your Message<TABLE width=100% cellSpacing=1 cellPadding=2 border=0><TR><TD colspan=2><TEXTAREA NAME='"+tmp1+"' ROWS=6 COLS=20 class='wide'></TEXTAREA></TD></TR><TR><TD width=46 nowrap>Name:&nbsp;</TD><TD><input type='hidden' name='"+tmp2+"' value=''><input type='text' name='echtname' maxlength=25 size=25 value='"+UserName+"' class='wide'></TD></TR></TABLE><TABLE width=100% cellSpacing=1 cellPadding=2 border=0><TR><TD width=50% align=right><input type='button' name='sendenbut' value='send' onClick='senden("+number+")' class='but'onFocus='this.blur()'></TD><TD width=50%><input type='button' value='close' onClick='formclose2("+number+");' class='but'></TD></TR></TABLE></TD><TD width=210 nowrap valign=top><DIV class='i'><B>Please read BEFORE you post<BR><A HREF='"+helpfaq+"' target='_top' class='at'>How to take this test?</A></B><BR><BR>If you want to get an explanation on any of the test questions you can write a message. The system automatically adds your test question, the answer options and your selected answer to the forum. All you have to do is write your message (question) and click on the &quot;send&quot; button. Your name is optional."+txtcookiestmp+"</DIV></TD></TR></TABLE></TD></TR></TABLE>";
}

function closeAll(value){
	for(var i=0; i<support.length; i++){
		if(value != support[i]){
//			document.getElementById(support[i]).style.backgroundColor = 'white';
			document.getElementById(test[i]).style.backgroundColor = 'white';
			if(Slovo == "Answer" && UserS != "User's "){
				document.getElementById(y_vstavka[i]).style.backgroundColor = 'white';
				document.getElementById(x_vstavka[i]).style.backgroundColor = 'white';
				document.getElementById(m_vstavka[i]).style.backgroundColor = 'white';
				document.getElementById(k_vstavka[i]).style.backgroundColor = 'white';
			}
			if(Slovo == "Question" && JSpage == "errors"){
				document.getElementById(z_vstavka[i]).style.backgroundColor = 'white';
			}
			document.getElementById(vstavka[i]).innerHTML = "";
		}
	}
}

function formclose(){
	closeAll(0);
}

function formclose2(number){
	closeAll(0);
	schalter[(number-1)] = 0;
}

function ff(id_number) {
	var f = document.forms['userform'];
	if (!(document.getElementById && f)){
		alert('To use this feature please update your browser or click "ESL FORUM SUPPORT".');
		return false;
	}
	if(flagEnd == "false"){
		alert("This feature hasn't been activated yet. Please, wait a few seconds. Page loaded.");
		return false;
	}
	closeAll(0);
	if(schalter[(id_number-1)] > 0){schalter[(id_number-1)] = 0; return false;}
	else {schalter = new Array(0,0,0,0,0,0,0,0,0,0);}
	schalter[(id_number-1)]++;
	v_id = 'v' + id_number;
	e_id = 'e' + id_number;
	s_id = 's' + id_number;
	p_id = 'p' + id_number;
	y_id = 'y' + id_number;
	x_id = 'x' + id_number;
	z_id = 'z' + id_number;
	m_id = 'm' + id_number;
	k_id = 'k' + id_number;
	if(VstavkaJS == "true"){
		tmp1 = "message2tmp";
		tmp2 = "usernametmp";
	} else {
		tmp1 = "message2";
		tmp2 = "username";
	}
	document.getElementById(v_id).innerHTML = formText(id_number,tmp1,tmp2);
	if(Slovo == "Answer" && UserS != "User's "){
		document.getElementById(x_id).style.backgroundColor = '#DAE2E9';
		document.getElementById(k_id).style.backgroundColor = '#DAE2E9';
		document.getElementById(m_id).style.backgroundColor = '#DAE2E9';
		document.getElementById(y_id).style.backgroundColor = '#DAE2E9';
	}
	if(Slovo == "Question" && JSpage == "errors"){
		document.getElementById(z_id).style.backgroundColor = '#DAE2E9';
	}
	document.getElementById(p_id).style.backgroundColor = '#DAE2E9';
	if(VstavkaJS == "true"){
		if(UserName != ""){document.testform.usernametmp.value = UserName;}
	} else {
		if(UserName != ""){f.username.value = UserName;}
	}
}

function MakeClean(str){
	str=str.replace(/ {2,}/gi," ");
	str=str.replace(/&quot;/gi,"\"");
	str=str.replace(/&#151;/gi,"--");
	str=str.replace(/(^ )|( $)/gi,"");
	str=str.replace(/&amp;/gi,"&");
	return str;
}

function senden(id_number){
	if(submitcount > 0){return;}
	myvariable = digits[(id_number-1)];
	myvariable2 = myvariable + "2";
	var f = document.forms['userform'];
	if(AlexPage == "esl-answers.php"){
		textvar = eval(myvariable);
		textvar2 = eval(myvariable2);
	} else {
		textvar = eval(myvariable2);
		textvar2 = eval(myvariable);
	}
	if(VstavkaJS == "true"){
		f.message2.value = MakeClean(document.testform.message2tmp.value);
		f.username.value = MakeClean(document.testform.usernametmp.value);
	}
	f.message.value = MakeClean(anfang + "esl-test" + folge + myvariable + mitte + "question" + mitte2 + id_number + ende + textvar2 + "\n\n" + anfang + "esl-answers" + folge + myvariable + mitte + "answer" + mitte2 + id_number + ende + textvar);
	f.nmr.value = id_number;
	if((checkForm() == "true") && (submitcount == 0)){
		document.userform.submit();
		submitcount++;
	}
}

function checkForm(){
	formErrors = false;
	if (document.userform.message2.value.length < 3) {
		formErrors = "You must enter a message when posting.";
	}
	if (formErrors) {
		alert(formErrors);
		return "false";
	} else {
		if(AlexPage == "esl-answers.php"){
			newname = document.userform.echtname.value;
		} else {
			newname = document.testform.echtname.value;
		}
		if(newname!="" && newname!=UserName){newname = "\n\n"+newname;}
		else{newname = "";}
		document.userform.message.value += "\n[size=24]_________________________[/size]\n\n" + document.userform.message2.value + newname;
		document.userform.message2.value = "";
		document.userform.subject.value = "Test " + UTestName + ", " + UserS + Slovo + " " + document.userform.nmr.value;
		document.userform.testnumber.value = "http://" + TestURI + "#" + digits[(document.userform.nmr.value - 1)];
		return "true";
	}
}

function addbookmark(bookmarkurl,bookmarktitle){
if(document.all && window.external) {window.external.AddFavorite(bookmarkurl,bookmarktitle);}
else {alert('We are sorry you have to add the bookmark manually yourself.');}
}

function a(qn,index){
document.testform.elements['q['+qn+']'][index].checked = 'true';
document.testform.elements['entry['+qn+']'].focus();
}

function e(){window.status='Ask ESL Forum Support for Explanation';}
function o(){window.status='Select the incorrect part';}
function u(){window.status='';}
function pop(){window.status='Why link to translation doesn\'t work?';}

function translateData(nummer){
	selectlen = eval("document.userform.langpair" + nummer + ".length");
	text = eval("document.userform.tx" + nummer + ".value");
	for(var i=0; i<selectlen; i++){
		if(eval("document.userform.langpair" + nummer + ".options[i].selected") == true){
			var sprache = eval("document.userform.langpair" + nummer + ".options[i].value");
			var selndex = i;
			for(var j=0; j<GoogleAr.length; j++){
				if(GoogleAr[j] == sprache){allE(EctacoArIndex[j]); cook(EctacoAr[j],"ectaco"); break;}
			}
		}
	}
	allF(selndex);
	eval("document.userform.but" + nummer + ".focus()");
	document.translate.langpair.value = sprache;
	document.translate.text.value = text;
	cook(sprache,"google");
	document.translate.submit();
}

function translateDataEctaco(nummer){
	selectlen = eval("document.userform.lang" + nummer + ".length");
	text = eval("document.userform.tt" + nummer + ".value");
	for(var i=0; i<selectlen; i++){
		if(eval("document.userform.lang" + nummer + ".options[i].selected") == true){
			var sprache = eval("document.userform.lang" + nummer + ".options[i].value");
			var selndex = i;
			for(var j=0; j<EctacoAr.length; j++){
				if(EctacoAr[j] == sprache){allF(j); cook(GoogleAr[j],"google"); break;}
			}
		}
	}
	allE(selndex);
	eval("document.userform.butect" + nummer + ".focus()");
	document.ectaco.lang.value = sprache;
	document.ectaco.word.value = text;
	cook(sprache,"ectaco");
	document.ectaco.submit();
}

function allF(selndex){
	for(var k=1; k<11; k++){
		eval("document.userform.langpair" + k + ".selectedIndex = " + selndex);
	}
}

function allE(selndex){
	for(var k=1; k<11; k++){
		eval("document.userform.lang" + k + ".selectedIndex = " + selndex);
	}
}

function cook(val,flag){
	var ablauf = new Date();
	var infuenfTagen = ablauf.getTime() + (5 * 24 * 60 * 60 * 1000);
	ablauf.setTime(infuenfTagen);
	if(flag == "google"){
		document.cookie = "Language=" + escape(val) + "; expires=" + ablauf.toGMTString() + "; path=/";
	} else {
		document.cookie = "LangEctaco=" + escape(val) + "; expires=" + ablauf.toGMTString() + "; path=/";
	}
}

function Killer()
{
if (self.parent.frames.length != 0)
if (self.parent.location != document.location) {self.parent.location = document.location};
}

function checkHash(str)
{
	for(var i=0; i<10; i++){
		if(str == hasharray[i]) return true;
	}
	return false;
}

function MakeAdSense()
{
	if(myhash != "" && sitehash == ""){self.parent.location = myhash;}
}

function ShowTab(){document.write('<TABLE border=0 height=88><TR><TD>&nbsp;</TD></TR></TABLE>');}
function SN(d){
if(d==""){return false;}
else{document.write("<a href='http://dictionary.reference.com/search?q="+d+"' target='_blank' class='q' rel='nofollow'>Dictionary.com</a> &nbsp; <a href='http://dictionary.cambridge.org/results.asp?searchword="+d+"' target='_blank' class='q' rel='nofollow'>Cambridge Dictionaries</a> &nbsp; <a href='http://www.m-w.com/cgi-bin/dictionary?book=Dictionary&va="+d+"' target='_blank' class='q' rel='nofollow'>Merriam-Webster</a> &nbsp; <a href='http://www.answers.com/"+d+"' target='_blank' class='q' rel='nofollow'>Answers.com</a>");}
}
function AN(d){
document.write("<a href='http://www.answers.com/"+d+"' target='_blank' class='q' rel='nofollow'>Answers.com</a>");
}
function abm(){window.status='Add bookmark';}
function ett(){window.status='Email this test to a friend';}
function eca(){return "Translate";}
function ecb(){return "Translation with <A HREF=\"/translators/\" class=\"te\">Ectaco</A>";}
function as(){window.status='answer';}
function qs(){window.status='question';}