var currentLang = new Object(), currentTabId = 'byki';
var defBlog = 'http://feeds2.feedburner.com/BykiBlog', defFacebook = 'http://www.facebook.com/byki.language.learning', defMySpace = 'http://www.myspace.com/byki', defTwitter = 'http://www.twitter.com/byki';
var widget_url = 'http://0-www.transparent.com.opac.cadl.org/wotd/today/widget_large';
var img_path = '../library/images/';
var tabOptions = {'byki': 1, 'overview': 0, 'grammar': 0, 'blog': 0, 'wotd': 0, 'test': 0, 'classes': 0};
var homeOptions = {'overview': 0, 'grammar': 0, 'blog': 0, 'wotd': 0, 'test': 0, 'classes': 0, 'facebook': 0, 'twitter': 0};
var langOptions = new Object();
// temp data:
langOptions = {
'chinese': {'Test':'../library/test/chinese.htm'},
'dutch': {'Test':'../library/test/dutch.htm'},
'english4spanish': {'Test':'../library/test/english4spanish.htm'},
'french': {'Test':'../library/test/french.htm'},
'german': {'Test':'../library/test/german.htm'},
'irish': {'Test':'../library/test/irish.htm'},
'italian': {'Test':'../library/test/italian.htm'},
'japanese': {'Test':'../library/test/japanese.htm'},
'latin': {'Test':'../library/test/latin.htm'},
'polish': {'Test':'../library/test/polish.htm'},
'portuguese': {'Test':'../library/test/portuguese.htm'},
'russian': {'Test':'../library/test/russian.htm'},
'spanish': {'Test':'../library/test/spanish.htm'},
'swedish': {'Test':'../library/test/swedish.htm'}
};
function Lang() {// for widget
	return langOptions[currentLang.code].WotdLang;
}
function setLanguage(id, code, name, code2) {
	currentLang['langId'] = id;
	currentLang['langCode'] = code;
	currentLang['langName'] = name;

	currentLang['code1'] = code.replace(/^t_/i, "").replace(/_latin$/i, "").toLowerCase();;
	currentLang['code2'] = code2.replace(/^t_/i, "").toLowerCase();;
	if ((/mandarin/i).test(currentLang['code1'])) currentLang['code1'] = 'chinese';
	if ((/mandarin/i).test(currentLang['code2'])) currentLang['code2'] = 'chinese';
	if ((/portuguese/i).test(currentLang['code1'])) currentLang['code1'] = 'portuguese';
	if ((/portuguese/i).test(currentLang['code2'])) currentLang['code2'] = 'portuguese';
	currentLang['code'] = currentLang['code1'];
	if (!(/english/i).test(currentLang['code2'])) currentLang['code'] += '4' + currentLang['code2'];
	currentLang['codeTitle'] = currentLang['code1'].substr(0, 1).toUpperCase() + currentLang['code1'].substr(1);
	var a = currentLang['codeTitle'].split('_');
	if (a.length > 1) currentLang['codeTitle'] = a[0] + a[1].substr(0, 1).toUpperCase() + a[1].substr(1);;
	if (!langOptions[currentLang.code]) // temp check
		langOptions[currentLang.code] = new Object();
}
function setHomeOptions(obj) {
	if (!obj) return;
	for (var i in obj) homeOptions[i] = obj[i];
}
function setLangOptions(obj) {
	if (!obj) return;
	for (var i in obj) {
		if (!langOptions[currentLang.code][i]) // temp check
			langOptions[currentLang.code][i] = obj[i];
	}
	if (langOptions[currentLang.code].Wotd) {
		langOptions[currentLang.code].WotdLang = langOptions[currentLang.code].Wotd.replace(/^.*\/([^\/]+?)(\.[\w]+)?$/i, '$1');
		var parts = langOptions[currentLang.code].WotdLang.split("-");
		for (var i in parts) parts[i] = parts[i].substr(0, 1).toUpperCase() + parts[i].substr(1);
		langOptions[currentLang.code].WotdLang = parts.join("-");
	}
}
// Email ------------
function doSubmit() {
	window.open('','signup','resizable=1,scrollbars=0,width=300,height=150');
	document.getElementById('wotd-email').style.display = 'none';
	return true;
}
function hidePopup(object) {
	document.getElementById(object).style.display = "none";
}
function showPopup(e, str) {
	document.getElementById(str).style.display = "block";
	document.getElementById('optinL').value = langOptions[currentLang.code].WotdGrp;
	document.getElementById('email').focus();
}
function displayPopup(id, hide) {
	var hide = hide || 0;
	document.getElementById(id).style.display = (hide ? "none" : "block");
}
// email ------------
function onLoginLoad() {
	var el = document.getElementById('username');
	if (el) el.focus();
}
function onRegisterLoad() {
	var el = document.getElementById('fullName');
	if (el) el.focus();
}
function onHomeLoad() {
	requestFontHints();
}
function requestFontHints() {
	var result = null;
	try {
		result = ajax.POST({url: '../flashcards/ajax/game/list/getFonts',
			args: {'osPattern': PlatformInfo.getOs(), 'agentPattern': PlatformInfo.getAgent(),
			'languages': [currentLang.langId]}, onError: function() {return true;}});
	} catch (e) {return;}
	var str = '';
	if (typeof(result) != "object") {
		try {
			result = eval('(' + result + ')');
		} catch(e) {
			result = null;
		}
	}
	if (result && result.length > 0) {
		var showLink = false;
		for (i = 0; i < result.length; i++) {
			if (result[i] && result[i].name && result[i].native == false) {
				showLink = true;
			}
		}
		if (showLink) {
			var arch = PlatformInfo.getOs() == "MAC_OS_X" ? "macosx" : "win32";
			var url = "../fontdownloader?arch=" + arch + "&lang=" + currentLang.langCode;
			document.getElementById("fontDownloaderLink").href = url;
			document.getElementById("fontDownloaderSpan").style.display = "";
		}
	}
}
function setFacebookTwitter() {
	if (homeOptions['facebook']) {
		if (langOptions[currentLang.code].Facebook) {
			document.getElementById('btnFacebookMainImg').src = img_path + 'facebook_' + currentLang.code + '.png';
			document.getElementById('btnFacebookMain').href = langOptions[currentLang.code].Facebook;
		} else {
			document.getElementById('btnFacebookMainImg').src = img_path + 'btnFacebook.png';
			document.getElementById('btnFacebookMain').href = defFacebook;
		}
		document.getElementById('btnFacebookMainHolder').style.display = '';
	}
	if (homeOptions['twitter']) {
		if (langOptions[currentLang.code].Twitter) {
			document.getElementById('btnTwitterMainImg').src = img_path + 'twitter_' + currentLang.code + '.png';
			document.getElementById('btnTwitterMain').href = langOptions[currentLang.code].Twitter;
		} else {
			document.getElementById('btnTwitterMainImg').src = img_path + 'btnTwitter.png';
			document.getElementById('btnTwitterMain').href = defTwitter;
		}
		document.getElementById('btnTwitterMainHolder').style.display = '';
	}
}
function setTabs() {
	if (homeOptions['overview'] && langOptions[currentLang.code].Overview) document.getElementById('tab_overview').style.display = '';
	if (homeOptions['grammar'] && langOptions[currentLang.code].Grammar) document.getElementById('tab_grammar').style.display = '';
	if (homeOptions['blog'] && langOptions[currentLang.code].BlogRss) document.getElementById('tab_blog').style.display = '';
	if (homeOptions['wotd'] && langOptions[currentLang.code].Wotd) document.getElementById('tab_wotd').style.display = '';
	if (homeOptions['test'] && langOptions[currentLang.code].Test) document.getElementById('tab_test').style.display = '';
	if (homeOptions['classes']) document.getElementById('tab_classes').style.display = '';
}
function showInfo(id) {
	var img;
	if (currentInfoId) {
		img = document.getElementById('logo_' + currentInfoId);
		img.src = img.src.replace(/_a\.png/, ".png");
		document.getElementById('descr_' + currentInfoId).style.display = 'none';
	}
	currentInfoId = id;
	img = document.getElementById('logo_' + id);
	img.src = img.src.replace(/\.png/, "_a.png");
	document.getElementById('descr_' + id).style.display = '';
}
function showTab(id) {
	var img;
	if (currentTabId) {
		img = document.getElementById('tab_' + currentTabId);
		img.src = img.src.replace(/_a\.png/, ".png");
		document.getElementById('content_' + currentTabId).style.display = 'none';
	}
	currentTabId = id;
	img = document.getElementById('tab_' + id);
	img.src = img.src.replace(/\.png/, "_a.png");
	document.getElementById('content_' + id).style.display = '';
	if (currentTabId == 'blog') document.getElementById('LinkBlogSubscribe').style.display = '';
	else document.getElementById('LinkBlogSubscribe').style.display = 'none';
	if (tabOptions[currentTabId] == 0) {
		tabOptions[currentTabId] = 1;
		if (currentTabId == 'overview') setOverviewLayout();
		else if (currentTabId == 'grammar') setGrammarLayout();
		else if (currentTabId == 'blog') setBlogLayout();
		else if (currentTabId == 'wotd') setWotdLayout();
		else if (currentTabId == 'test') setTestLayout();
		else if (currentTabId == 'classes') {
			setClassesLayout();
			tabOptions[currentTabId] = 0;
		}
	}
}
function setOverviewLayout() {
	if (!langOptions[currentLang.code].Overview) return;
	var result = null;
	try {
		result = ajax.GET({url: '../flashcards/proxy', args: {url: langOptions[currentLang.code].Overview,
			t: (new Date()).getTime()}, onError: function() {return true;}});
	} catch (e) {return;}
	if (!result) result = currentLang.langName;
	document.getElementById('content_overview').innerHTML = result;
}
function setGrammarLayout(url) {
	if (!langOptions[currentLang.code].Grammar) return;
	if (url) url = langOptions[currentLang.code].Grammar.replace(/^(.*\/)[^\/]+$/, '$1') + decodeURIComponent(url);
	else url = langOptions[currentLang.code].Grammar;
	var result = null;
	try {
		result = ajax.GET({url: '../flashcards/proxy', args: {url: url,
			t: (new Date()).getTime()}, onError: function() {return true;}});
	} catch (e) {return;}
	if (result) {
		result = result.replace(/\s/g, " ").replace(/^.*<body[^>]*>(.*)<\/body.*$/i, '$1');
		result = result.replace(/href=\s*"([^#][^"]+)"/gi, 'href="#" onclick="setGrammarLayout(\'$1\');return false;"');
		result = result.replace(/href=\s*'([^#][^']+)'/gi, 'href="#" onclick="setGrammarLayout(\'$1\');return false;"');
		result = result.replace(/<a\s+href=\s*"#\w+"\s*>(.*?)<\/a>/gi, '');
		result = result.replace(/<a\s+href=\s*'#\w+'\s*>(.*?)<\/a>/gi, '');
	} else result = '';
	document.getElementById('content_grammar').innerHTML = result;
}
function setBlogLayout() {
	if (!langOptions[currentLang.code].BlogRss) return;
	document.getElementById('btnBlogSubscribe').href = langOptions[currentLang.code].BlogRss;
	document.getElementById('imgBlogSubscribe').href = document.getElementById('btnBlogSubscribe').href;
	var result = null;
	try {
		result = ajax.GET({url: '../flashcards/proxy', args: {'url': langOptions[currentLang.code].BlogRss + '?format=xml',
			t: (new Date()).getTime()}, onError: function() {return true;}});
	} catch (e) {return;}
	var str = '';
	if (typeof(result) != "object") {
		try {
			result = eval('(' + result + ')');
		} catch(e) {
			result = null;
		}
	}
	if (result && result.rss && result.rss.channel && result.rss.channel.item) {
		var items = result.rss.channel.item;
		for (var i = 0; i < items.length; i++) {
			var pubDate = Date.parse(items[i].pubDate);
			var dt = new Date();
			dt.setTime(pubDate);
			pubDate = (dt.getMonth() + 1) + '/' + dt.getDate() + '/' + ('' + dt.getFullYear()).substr(2);
			var comments = true;
			var content = trim(items[i]["content:encoded"]);
			content = (content.replace(/\s+/g, " ")).replace(/(<\/[^<>\s]+)\s+[^<>]*>/g, "$1>");
			var words = content.split(" ");
			if (words.length > 100) {
				comments = false;
				content = (words.slice(0, 100)).join(" ");
				var p, content2 = (words.slice(100)).join(" ");
				if (/.*<[^<>]+$/.test(content)) {
					p = content.lastIndexOf('<');
					content2 = content.substr(p) + content2;
					content = trim(content.substring(0, p));
				}
				if (/<table/.test(content)) {
					p = content.indexOf('<table');
					content2 = content.substr(p) + content2;
					content = trim(content.substring(0, p));
				}
				while (/<table.*<\/table[^<>]*>/.test(content2)) content2 = content2.replace(/<table.*<\/table[^<>]*>/g, "");
				content2 = (content2.replace(/&nbsp;/g, " ")).replace(/<(area|base|basefont|br|frame|hr|img|input|link|meta)(\s*|\s+[^<>]*)>/g, "");
				if (/\S/.test(content2.replace(/<[^<>]+>/g, "")) == false) comments = true;
				content += content2.replace(/[^<>]*(<[^<>]+>)[^<>]*/g, "$1");
				while (/<([^<>\s]+)(\s*|\s+[^<>]*)>\s*<\/\1>/.test(content)) content = content.replace(/<([^<>\s]+)(\s*|\s+[^<>]*)>\s*<\/\1>/g, "");
				while (/<([^<>\s]+)(\s*|\s+[^<>]*)>\s*<([^<>\s]+)(\s*|\s+[^<>]*)>\s*<\/\1>\s*<\/\3>/.test(content)) content = content.replace(/<([^<>\s]+)(\s*|\s+[^<>]*)>\s*<([^<>\s]+)(\s*|\s+[^<>]*)>\s*<\/\1>\s*<\/\3>/g, "");
				content = trim(content.replace(/(<\/[^<>]+>)\s*<[^\/<>]+(\s*|\s+[^<>]*)>[^<>]*$/, "$1"));
				if (!comments) {
					if (/([^<>]+|<\/a>)((\s*<\/(?!a)[^<>]+>)*)$/.test(content)) content = content.replace(/([^<>]+|<\/a>)((\s*<\/(?!a)[^<>]+>)*)$/, "$1&hellip;$2");
					else content += '&hellip;'
					content = content.replace(/[\,\.\s]+&hellip;/, "&hellip;");
				}
			}
			str += '<div class="blog_post"><h6>' + items[i].title + '</h6>'
				+ '<div class="posted">Posted on ' + pubDate + '</div>' + content + "\n<div>";
			if (comments) str += '<a href="' + items[i].comments + '"><img src="' + img_path + 'btnViewComments.png" class="btnViewCom" alt="View Comments" /></a>';
			else str += '<a href="' + items[i].link + '"><img src="' + img_path + 'btnViewFullPost.png" class="btnViewPost" alt="View Full Post" /></a>';
			str += "</div>\n</div>\n";
		}
	}
	document.getElementById('content_blog_items').innerHTML = str;
}
function setWotdLayout() {
	if (langOptions[currentLang.code].WotdGrp) document.getElementById('btnEmail').style.display = '';
	else document.getElementById('btnEmail').style.display = 'none';
	if (langOptions[currentLang.code].Twitter) {
		document.getElementById('btnTwitter').href = langOptions[currentLang.code].Twitter;
		document.getElementById('btnTwitter').style.display = '';
	} else {
		document.getElementById('btnTwitter').href = '#';
		document.getElementById('btnTwitter').style.display = 'none';
	}
	if (langOptions[currentLang.code].MySpace) {
		document.getElementById('btnMySpace').href = langOptions[currentLang.code].MySpace;
		document.getElementById('btnMySpace').style.display = '';
	} else {
		document.getElementById('btnMySpace').href = '#';
		document.getElementById('btnMySpace').style.display = 'none';
	}
	if (langOptions[currentLang.code].WotdRss) {
		document.getElementById('btnRss').href = langOptions[currentLang.code].WotdRss;
		document.getElementById('btnRss').style.display = '';
	} else {
		document.getElementById('btnRss').href = '#';
		document.getElementById('btnRss').style.display = 'none';
	}
	if (langOptions[currentLang.code].MyYahoo) {
		document.getElementById('btnYahoo').href = langOptions[currentLang.code].MyYahoo;
		document.getElementById('btnYahoo').style.display = '';
	} else {
		document.getElementById('btnYahoo').href = '#';
		document.getElementById('btnYahoo').style.display = 'none';
	}
	if (langOptions[currentLang.code].iGoogle) {
		document.getElementById('btnGoogle').href = langOptions[currentLang.code].iGoogle;
		document.getElementById('btnGoogle').style.display = '';
	} else {
		document.getElementById('btnGoogle').href = langOptions[currentLang.code].iGoogle;
		document.getElementById('btnGoogle').style.display = 'none';
	}
	document.getElementById('btnReddit').href = 'http://reddit.com/submit?url=' + langOptions[currentLang.code].Wotd + '&amp;title=' + escape(currentLang.codeTitle) + '%20Word%20of%20the%20Day%20from%20Transparent%20Language';
	document.getElementById('btnDelicious').href = 'http://del.icio.us/equinlan?url=' + langOptions[currentLang.code].Wotd + '&amp;title=' + escape(currentLang.codeTitle) + '%20Word%20of%20the%20Day%20from%20Transparent%20Language&amp;tags=' + escape(currentLang.codeTitle) + '%20word%20vocabulary';
	document.getElementById('btnStumbleUpon').href = 'http://www.stumbleupon.com/submit?url=' + langOptions[currentLang.code].Wotd + '&amp;title=' + escape(currentLang.codeTitle) + '%20Word%20of%20the%20Day%20from%20Transparent%20Language';
}
function setTestLayout() {
	if (!langOptions[currentLang.code].Test) return;
	var result = null;
	try {
		//result = ajax.GET({url: '../flashcards/proxy', args: {url: langOptions[currentLang.code].Test,
		result = ajax.GET({url: langOptions[currentLang.code].Test, args: {
			t: (new Date()).getTime()}, onError: function() {return true;}});
	} catch (e) {return;}
	if (result) {
		result = result.replace(/action="[^<>]*"/, 'action="" target="_self" onsubmit="getTestResults();return false;"');
		result = result.replace(/src="images\//g, 'src="../library/test/images/');
		document.getElementById('content_test_questions').innerHTML = result;
	}
}
function setClassesLayout() {
	document.getElementById('content_classes').innerHTML = ajax.GET( { url: "classes" } );
}

function getTestResults() {
	var qn = new Array(50,15,15,10,10), ms = new Array(150,45,45,30,30);
	var qa, ga, level, qr = new Array(), ss = new Array(0,0,0,0,0), sc = new Array();
	var qt = new Array('%s Proficiency Test', 'Part I: %s Grammar', 'Part II: %s Grammar', 'Part III: %s Vocabulary', 'Part IV: %s Reading Comprehension');
	for (p = 1; p < qn.length; p++) {
		qr[p] = new Array();
		for (q = 0; q < qn[p]; q++) {
			pq = "p"+p+"q"+(q + 1);
			qr[p][q] = {"result": 0, "answer": '', "pick": '(nothing)'};
			qa = document.getElementsByName("ANSWER"+pq)[0].value;
			qr[p][q]["answer"] = qa;
			var pks = document.getElementsByName("PICK"+pq);
			for (var i = 0; i < pks.length; i++) {
				if (pks[i].checked) {
					ga = pks[i].value;
					qr[p][q]["pick"] = ga;
					if (ga == qa) {
						qr[p][q]["result"] = 1;
						ss[p] += parseInt(document.getElementsByName("SECTION"+pq)[0].value);
					}
					break;
				}
			}
		}
		ss[0] += ss[p];
		sc[p] = Math.round((ss[p] * 100) / ms[p]);
	}
	sc[0] = Math.round((ss[0] * 100) / ms[0]);
	if (sc[0] >= 130) level = 'Advanced';
	else if (sc[0] >= 110) level = 'Advanced Intermediate';
	else if (sc[0] >= 90) level = 'Intermediate';
	else if (sc[0] >= 70) level = 'Advanced Beginner';
	else if (sc[0] >= 50) level = 'Beginner';
	if (sc[0] >= 50) level = 'You are at the '+level+' level.';
	else level = 'You are just starting out.';
	var str = '<div class="qBlock">'
		+ '<table width="615" cellspacing="0" cellpadding="0" border="0"><tr><td valign="top">'
		+ '<div class="qH1">' + qt[0].replace(/%s/, currentLang.codeTitle) + '</div>'
		+ '<div class="qBlockInfo">' + level + '<br />You scored ' + ss[0] + ' points out of ' + ms[0] + '.</div>'
		+ '</td><td valign="top" align="right">'
		+ '<div class="qH2">Practice Makes Perfect<br /><img src="../library/test/images/btnBackQuiz.gif" width="112" height="25" style="cursor:pointer; margin-top:8px;" onclick="backToQuiz();" alt="" title="Back to Quiz" /></div>'
		+ '</td></tr></table>'
		+ '<div class="qH3">Your score = ' + sc[0] + '%</div>';
	for (p = 1; p < qn.length; p++) {
		str += '<br /><div class="header_red_large">' + qt[p].replace(/%s/, currentLang.codeTitle) + '</div>'
			+ '<div class="qBlockInfo">You scored '+ss[p]+' points out of '+ms[p]+'.<br />';
		if (ss[p] == ms[p]) str += 'Congratulations! You had a perfect score!';
		else str += 'You scored '+sc[p]+'% on this section.';
		str += '</div>';
		for (q = 0; q < qr[p].length; q++) {
			if (qr[p][q]["result"]) {
				str += '<div class="qQue"><img src="../library/test/images/iconCheck.gif" width="23" height="23" alt="" title="Correct answer" class="qQue" /> <span class="qQue">Question '+(q + 1)+'</span></div>'
					+ '<div class="qAns">You gave the correct answer. You answered: <span class="qCorr">'+qr[p][q]["pick"]+'</span></div>';
		 	} else {
				str += '<div class="qQue"><img src="../library/test/images/iconIncorr.gif" width="19" height="19" alt="" title="Incorrect answer" class="qQue" /> <span class="qQue">Question '+(q + 1)+'</span></div>'
					+ '<div class="qAns">You gave an incorrect answer. You answered: <span class="qInCorr">'+qr[p][q]["pick"]+'</span><br />'
					+ 'The correct answer is: <span class="qCorr">' + qr[p][q]["answer"] + '</span></div>';
			}
			str += '<hr class="qSepar" />';
		}
	}
	str += '</div>';
	document.getElementById('content_test_questions').style.display = 'none';
	var el = document.getElementById('content_test_results');
	el.innerHTML = str;
	document.getElementById('content_test').scrollTop = 0;
	el.style.display = '';
}
function backToQuiz() {
	document.getElementById('content_test_questions').style.display = '';
	document.getElementById('content_test_results').style.display = 'none';
}
function trim(str) {return str.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");}
function checkRestorePasswordForm() {
	var fldLogin = document.getElementById('username');
	var fldEmail = document.getElementById('email');
	fldLogin.value = trim(fldLogin.value);
	fldEmail.value = trim(fldEmail.value);
	if (fldLogin.value == '') {
		alert("Please enter your User Name.");
		fldLogin.focus();
		return false;
	}
	if (!checkMail(fldEmail.value, "your Email")) {
		fldEmail.focus();
		return false;
	}
	return true;
}
function checkRegisterForm() {
	var fldFName = document.getElementById('fullName');
	var fldLogin = document.getElementById('username');
	var fldFPswd = document.getElementById('password');
	var fldCPswd = document.getElementById('cpassword');
	//var fldMLang = document.getElementById('mainlang');
	var fldMLang = document.getElementById('mainlang_customselect');
	var fldEmail = document.getElementById('email');
	fldFName.value = trim(fldFName.value);
	fldLogin.value = trim(fldLogin.value);
	fldMLang.value = trim(fldMLang.value);
	fldEmail.value = trim(fldEmail.value);

	if (fldFName.value == '') {
		alert("Please enter Your Name.");
		fldFName.focus();
		return false;
	}
	if ((/[^\w\- \.\']/).test(fldFName.value) == true) { 
		alert("Your Name must not contain special symbols.");
		fldFName.value = '';
		fldFName.focus();
		return false;
	}
	if (fldLogin.value == '') {
		alert("Please enter your User Name.");
		fldLogin.focus();
		return false;
	}
	if ((/\W/).test(fldLogin.value) == true) {
		alert("User Name must not contain special symbols.");
		fldLogin.value = '';
		fldLogin.focus();
		return false;
	}
	if (fldLogin.value.length < 4) {
		alert("User Name should contain at least 4 characters.");
		fldLogin.focus();
		return false;
	}
	if (fldFPswd.value == '') {
		alert("Please enter your Password.");
		fldFPswd.focus();
		return false;
	}
	if (fldFPswd.value.length < 4) {
		alert("Password should contain at least 4 characters.");
		fldFPswd.focus();
		return false;
	}
	if (fldCPswd.value == '') {
		alert("Please confirm your Password.");
		fldCPswd.focus();
		return false;
	}
	if (fldFPswd.value != fldCPswd.value) {
		alert("Passwords do not match.");
		fldFPswd.value = '';
		fldCPswd.value = '';
		fldFPswd.focus();
		return false;
	}
	if (document.getElementById('sendinfo').checked) {
		if (!checkMail(fldEmail.value, "your Email")) {
			fldEmail.focus();
			return false;
		}
	}
	return true;
}
