JMB = {
	path:"/",
	login:function(frs) {
		if(frs.elements["email"].value == "") {
			alert(frs.elements["m_email"].value + "!");
			frs.elements["email"].focus();
			return false;
		} else 
		if(!JSTR.isemail(frs.elements["email"].value)) {
			alert(frs.elements["m_erroremail"].value + "!");
			frs.elements["email"].focus();
			return false;
		} else { 
			var passtmp = frs.elements["password"].value;
			frs.elements["password_md5"].value = MD5(passtmp);
			frs.elements['btsigin'].disabled = true;
			AIM.submit(frs, {'onComplete': JCB.complete});
			return true;
		}
	},
	forget:function(frs) {
		if(frs.elements["email"].value == "") {
			alert(frs.elements["m_email"].value + "!");
			frs.elements["email"].focus();
			return false;
		} else
		if(!JSTR.isemail(frs.elements["email"].value)){
			alert(frs.elements["m_erroremail"].value);
			frs.elements["email"].focus();
			return false;
		} else {
			frs.elements['btforget'].disabled = true;
			frs.action = JMB.path + 'ajax.php?o=modules&n=member&f=forget&snt=123';
			AIM.submit(frs, {'onComplete': JCB.complete});
			return true;
		}
	},
	listemail:function(email) {
		var em = email.split(";");
		for(i = 0; i < em.length; i++)
		if(!JSTR.isemail(em[i]))
			return false;
		return true;
	},
	share:function(frs) {
		if(frs.elements["email"].value == "") {
			alert(frs.elements["m_email"].value + "!");
			frs.elements["email"].focus();
			return false;
		} else
		if(!JMB.listemail(frs.elements["email"].value)){
			alert(frs.elements["m_erroremail"].value);
			frs.elements["email"].focus();
			return false;
		} else {
			frs.elements['btforget'].disabled = true;
			frs.action = JMB.path + 'ajax.php?o=modules&n=member&f=share&snt=123';
			AIM.submit(frs, {'onComplete': JCB.complete});
			return true;
		}
	},
	change:function(frs) {
		if(frs.elements["pass_old"].value == "") {
			alert(frs.elements["m_pass_old"].value + "!");
			frs.elements["pass_old"].focus();
		} else
		if(frs.elements["matkhau"].value=="") {
			alert(frs.elements["m_pass_new"].value + "!");
			frs.elements["matkhau"].focus();
		} else
		if(frs.elements["rematkhau"].value != frs.elements["matkhau"].value) {
			alert(frs.elements["m_pass_renew"].value + "!");
			frs.elements["rematkhau"].value="";
			frs.elements["rematkhau"].focus();
		} else {
			var passtmp = frs.elements["pass_old"].value;
			frs.elements["pass_old"].value = MD5(passtmp);
			passtmp = frs.elements["matkhau"].value;
			frs.elements["matkhau"].value = MD5(passtmp);
			frs.elements['btchangepass'].disabled = true;
			frs.action = JMB.path + 'ajax.php?o=modules&n=member&f=chgpass&snt=123';
			AIM.submit(frs, {'onComplete': JCB.complete});
			return true;
		}
		return false;
	},
	edit:function(frs) {
		var currYear = JDATE.cyear();
		if(frs.elements["email"].value == "") {
			alert(frs.elements["m_email"].value + "!");
			frs.elements["email"].focus();
		} else
		if(!JSTR.isemail(frs.elements["email"].value)) {
			alert(frs.elements["m_erroremail"].value + "!");
			frs.elements["email"].focus();
		} else 
		if(frs.elements["fullname"].value == "") {
			alert(frs.elements["m_fullname"].value + "!");
			frs.elements["fullname"].focus();
		} else
		if(!JDATE.fdate(frs.elements["birthdate"].value, (currYear - 80), (currYear - 10))) {
			alert(frs.elements["m_birthdate"].value + "!");
			frs.elements["birthdate"].focus();
		} else
		if(frs.elements["address"].value == "") {
			alert(frs.elements["m_address"].value + "!");
			frs.elements["address"].focus();
		} else 
		if(!JSTR.isphone(frs.elements["phone"].value)) {
			alert(frs.elements["m_errorphone"].value + "!");
			frs.elements["phone"].focus();
		} else
		if(!JSTR.isnumber(frs.elements["cmnd"].value)) {
			alert(frs.elements["m_cmnd"].value + "!");
			frs.elements["cmnd"].focus();
		} else {
			frs.elements['btregmb'].disabled = true;
			frs.elements['btresmb'].disabled = true;
			frs.action = JMB.path + 'ajax.php?o=modules&n=member&f=update&snt=123';
			AIM.submit(frs, {'onComplete': JCB.complete});
			return true;
		}
		return false;
	},
	register:function(frs) {
		var currYear = JDATE.cyear();
		if(frs.elements["email"].value == "") {
			alert(frs.elements["m_email"].value + "!");
			frs.elements["email"].focus();
		} else
		if(!JSTR.isemail(frs.elements["email"].value)) {
			alert(frs.elements["m_erroremail"].value + "!");
			frs.elements["email"].focus();
		} else 
		if(frs.elements["password"].value == "") {
			alert(frs.elements["m_password"].value + "!");
			frs.elements["password"].focus();
		} else 
		if(frs.elements["repassword"].value == "") {
			alert(frs.elements["m_repassword"].value + "!");
			frs.elements["repassword"].focus();
		} else 
		if(frs.elements["password"].value != frs.elements["repassword"].value) {
			alert(frs.elements["m_errorpassword"].value + "!");
			frs.elements["repassword"].focus();
		} else
		if(frs.elements["fullname"].value == "") {
			alert(frs.elements["m_fullname"].value + "!");
			frs.elements["fullname"].focus();
		} else
		if(!JDATE.fdate(frs.elements["birthdate"].value, (currYear - 80), (currYear - 10))) {
			alert(frs.elements["m_birthdate"].value + "!");
			frs.elements["birthdate"].focus();
		} else
		if(frs.elements["address"].value == "") {
			alert(frs.elements["m_address"].value + "!");
			frs.elements["address"].focus();
		} else 
		if(!JSTR.isphone(frs.elements["phone"].value)) {
			alert(frs.elements["m_errorphone"].value + "!");
			frs.elements["phone"].focus();
		} else
		if(!JSTR.isnumber(frs.elements["cmnd"].value)) {
			alert(frs.elements["m_cmnd"].value + "!");
			frs.elements["cmnd"].focus();
		} else
		if(frs.elements["postercode"].value == "") {
			alert(frs.elements["m_postercode"].value + "!");
			frs.elements["postercode"].focus();
		} else
		if(_iH("postercodekey") != "") {
			alert(frs.elements["m_postercode_invalid"].value + "!");
			frs.elements["postercode"].focus();
		} else {
			frs.elements['btregmb'].disabled = true;
			frs.elements['btresmb'].disabled = true;
			frs.action = JMB.path + 'ajax.php?o=modules&n=member&f=register&snt=123';
			AIM.submit(frs, {'onComplete': JCB.complete});
			return true;
		}
		return false;
	},
	refresh:function() {
		JAJAX.element(JMB.path + "ajax.php?o=modules&n=member&f=refesh", "postercodeimg", 2);
	},
	code:function(fl) {
		JAJAX.element(JMB.path + "ajax.php?o=modules&n=member&f=invalid&cd=" + fl.value, "postercodekey", 0);
	},
	avatar:function(resp) {
		if(resp != "") {
			var ss = resp.split("#");
			if(ss[0] == 1) {
				alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
				o = document.forms["frmPost"];
				o.elements['btcavatar'].disabled = false;
				o.elements['myavatar'].value = "";
				window.location.href = window.location.href;
			} else
			if(ss[0] == 2) {
				alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
				o = document.forms["frmPost"];
				o.elements['btcavatar'].disabled = false;
				o.elements['myavatar'].value = "";
			}
		}
	},
	eavatar:function() {
		document.getElementById("iconedit").style.display = "none";
		document.getElementById("avatarid").style.display = "";
	},
	cancel:function() {
		document.getElementById("avatarid").style.display = "none";
		document.getElementById("iconedit").style.display = "";
	},
	oavatar:function(fln) {
		if(fln != "") {
			var lfl = Array("jpg", "gif");
			var exf = (fln.substring((fln.lastIndexOf(".") + 1), fln.length)).toLowerCase();
			for(var ie = 0; ie < lfl.length; ie++) {
				if(exf == lfl[ie])
					return true;
			}
		}
		return false;
	},
	cavater:function(o) {
		if(o.elements["myavatar"].value == "") {
			alert(o.elements["m_only_image"].value + "!");
			o.elements["myavatar"].focus();
		} else
		if(!JMB.oavatar(o.elements["myavatar"].value))	{
			alert(o.elements["m_only_image"].value + "!");
			o.elements["myavatar"].focus();
		} else {
			o.elements['btcavatar'].disabled = true;
			o.action = JMB.path + 'ajax.php?o=modules&n=member&f=cavatar&snt=imc';
			AIM.submit(o, {'onComplete': JMB.avatar});
			return true;
		}
		return false;
	},
	join:function(o) {
		if(!o.elements["termscomfirm"].checked) {
			alert(o.elements["m_termscomfirm"].value + "!");
		} else
		if(o.elements["titlecontest"].value == "") {
			alert(o.elements["m_titlecontest"].value + "!");
			o.elements["titlecontest"].focus();
		} else
		if(o.elements["shortintroduction"].value == "") {
			alert(o.elements["m_shortintroduction"].value + "!");
			o.elements["shortintroduction"].focus();
		} else
		if(o.elements["filecontest"].value == "") {
			alert(o.elements["m_filecontest"].value + "!");
			o.elements["filecontest"].focus();
		} else
		if(!JMB.ofile(o.elements["filecontest"].value))	{
			alert(o.elements["m_filecontest"].value + "!");
			o.elements["filecontest"].focus();
		} else {
			o.elements['btjoinprogram'].disabled = true;
			o.action = JMB.path + 'ajax.php?o=modules&n=ilovetodaytv&f=ilovetodaytv_joined&action=imc';
			AIM.submit(o, {'onComplete': JMB.joined});
			return true;
		}
		return false;
	},
	irefresh:function() {
		JAJAX.element(JMB.path + "ajax.php?o=modules&n=ilovetodaytv&f=refesh", "postercodeimg", 2);
	},
	icode:function(fl) {
		JAJAX.element(JMB.path + "ajax.php?o=modules&n=ilovetodaytv&f=invalid&cd=" + fl.value, "postercodekey", 0);
	},
	maxLength:function(o){  
		var maxLength = parseInt(o.getAttribute('maxlength'));  
		if(o.value.length > maxLength)
			o.value = o.value.substring(0, maxLength);  
		document.getElementById('ncharleft').innerHTML = maxLength - o.value.length;
	},
	ofile:function(fln) {
		if(fln != "") {
			var lfl = Array("zip", "rar");
			var exf = (fln.substring((fln.lastIndexOf(".") + 1), fln.length)).toLowerCase();
			for(var ie = 0; ie < lfl.length; ie++) {
				if(exf == lfl[ie])
					return true;
			}
		}
		return false;
	},
	joined:function(resp) {
		if(resp != "") {
			var ss = resp.split("#");
			if(ss[0] == 1) {
				alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
				window.location.href = ss[2];
			} else
			if(ss[0] == 2) {
				alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
				o = document.forms["frmJoin"];
				o.elements['btjoinprogram'].disabled = false;
				o.elements['postercode'].value = "";
				JMB.irefresh();
			} else
			if(ss[0] == 3) {
				alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
			}
		}
	},
	sharefriend:function(frs) {
		if(frs.elements["sendname"].value == "") {
			alert(frs.elements["m_sendname"].value + "!");
			frs.elements["sendname"].focus();
			return false;
		} else
		if(frs.elements["sendemail"].value == "") {
			alert(frs.elements["m_sendemail"].value + "!");
			frs.elements["sendemail"].focus();
			return false;
		} else
		if(!JSTR.isemail(frs.elements["sendemail"].value)) {
			alert(frs.elements["m_erroremail"].value + "!");
			frs.elements["sendemail"].focus();
		} else 
		if(frs.elements["toemail"].value == "") {
			alert(frs.elements["m_toemail"].value + "!");
			frs.elements["toemail"].focus();
			return false;
		} else
		if(!JMB.listemail(frs.elements["toemail"].value)){
			alert(frs.elements["m_erroremail"].value);
			frs.elements["toemail"].focus();
			return false;
		} else {
			frs.elements['btforget'].disabled = true;
			frs.action = JMB.path + 'ajax.php?o=modules&n=ilovetodaytv&f=sharefriend&imcv2=send';
			AIM.submit(frs, {'onComplete': JMB.complete});
			return true;
		}
	},
	complete:function(res) {
		var ss = res.split("#");
		if(ss[0] == 1) {
			alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
			window.location.href = ss[2];
		} else {
			alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
		}
	}
};
JCL = {
	w : 0,
	h : 0,
	m : 0,
	s : 0,
	c : 0,
	saveFinal:function(o, v, tt) {
		if(tt == 0) {
			o.elements['bttestresult'].disabled = true;
			o.elements['btsaveresult'].disabled = true;
			o.elements['btresetresult'].disabled = true;
			if(v == 0) {
				o.action = JMB.path + 'ajax.php?o=modules&n=games&f=gamestest&action=imctv';
				AIM.submit(o, {'onComplete': JCL.result});
				o.submit();
			} else {
				o.action = JMB.path + 'ajax.php?o=modules&n=games&f=gamessave&action=imctv';
				AIM.submit(o, {'onComplete': JCL.complete});
				o.submit();
			}
		} else
		if(tt == 1) {
			o.elements['continueButton'].disabled = true;
			o.action = JMB.path + 'ajax.php?o=modules&n=games&f=gamessave&action=imctv';
			AIM.submit(o, {'onComplete': JCL.complete});
			o.submit();
		} else
		if(tt == 2) {
			if(v == 0) {
				o.elements['bttestresult'].disabled = true;
				o.elements['btsaveresult'].disabled = true;
				o.elements['btresetresult'].disabled = true;
				o.action = JMB.path + 'ajax.php?o=modules&n=games&f=gamestest&action=imctv';
				AIM.submit(o, {'onComplete': JCL.result});
				o.submit();
			} else
			if(v == 1) {
				o.elements['bttestresult'].disabled = true;
				o.elements['btsaveresult'].disabled = true;
				o.elements['btresetresult'].disabled = true;
				o.action = JMB.path + 'ajax.php?o=modules&n=games&f=gamessave&action=imctv';
				AIM.submit(o, {'onComplete': JCL.complete});
				o.submit();
			} else
			if(v == 2) {
				o.elements['continueButton'].disabled = true;
				o.action = JMB.path + 'ajax.php?o=modules&n=games&f=gamessave&action=imctv';
				AIM.submit(o, {'onComplete': JCL.complete});
				o.submit();
			}
		}
	},
	result:function(res) {
		fr = document.forms["maingamesplay"];
		fr.elements['bttestresult'].disabled = false;
		fr.elements['btsaveresult'].disabled = false;
		fr.elements['btresetresult'].disabled = false;
		alert(JSTR.replace(decodeURIComponent(res), "+", " "));
	},
	complete:function(res) {
		var ss = res.split("#");
		if(ss[0] == 1) {
			alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
			window.location.href = ss[2];
		} else {
			alert(JSTR.replace(decodeURIComponent(ss[1]), "+", " "));
			window.location.href = JMB.path + "trochoi/";
		}
	},
	runTimer:function() {
		JCL.w = window.setInterval("JCL.sleepTimer()", 1000);
	},
	sleepTimer:function() {
		str = (JCL.h > 9 ? JCL.h : "0" + JCL.h) + ":" + (JCL.m > 9 ? JCL.m : "0" + JCL.m) + ":" + (JCL.s > 9 ? JCL.s : "0" + JCL.s);			
		if(document.getElementById("clocktimeplay")) {				
			document.getElementById("clocktimeplay").innerHTML = str;
			if(JCL.s == 60) {
				JCL.s = 0;
				JCL.m++;
			}
			if(JCL.m == 60) {
				JCL.m = 0;
				JCL.h++;
			}
			JCL.s++;
		}
	},
	init:function(h, m, s) {		
		if(document.getElementById("clocktimeplay")) {
			JCL.h = h;
			JCL.m = m;
			JCL.s = s;
			JCL.runTimer();
		}
	}
};
