// JavaScript Document
function checkLoginForm(oForm){
	var oError=$(".messageStackError");
	
	oForm.email_address.value=oForm.email_address.value.replace('Email@example.com','');
	
	
	if($.trim(oForm.email_address.value)==''){
		oError.html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20"> Please enter a valid email address.');
		oForm.email_address.focus();
		return false;
	}else if($.trim(oForm.password.value)==''){
		oError.html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20"> Please enter your password.');
		oForm.password.focus();
		return false;
	}else{
		oError.html('');
	}
	
}
function checkEmail(oEmail,ajax){
	var reg = /^[\w\.\-]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i;
	if(reg.test($.trim(oEmail.value)))
	{
		if(ajax){
			$.ajax({
				url: "/",  
				type:"get",  
				dataType:"json",
				data:"main=help&action=forgot_password&act=check_email&email="+oEmail.value+"&rand="+Math.random(),
				success:function(msg)
				{
					if(!msg.status){
						$(".messageStackError").html(msg.mes);
						oEmail.value='';
					}else{
						$(".messageStackError").html('');
					}
				},
				error:function()
				{ 
					$(".messageStackError").html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20">  The email "'+oEmail.value+'" could not be found in our database.');
					oEmail.value='';
				} 
			});
		}else{
			$(".messageStackError").html('');
		}
	}else{
		oEmail.value='';
		$(".messageStackError").html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20"> Please enter a valid email address.');
	}
	
}
function checkContactForm(oForm){
	var oError=$(".messageStackError");
	if($.trim(oForm.contactname.value)==''){
		oError.html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20"> Please enter your name.');
		oForm.contactname.focus();
		return false;
	}else if($.trim(oForm.email_address.value)==''){
		oError.html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20"> Please enter a valid email address.');
		oForm.email_address.focus();
		return false;
	}else if($.trim(oForm.message.value)==''){
		oError.html('<img src="/images/error.gif" alt="Error" title=" Error " height="20" width="20"> Please type a message.');
		oForm.message.focus();
		return false;
	}else{
		oError.html('');
	}
}
function checkForgot(oForm){
	if($.trim(oForm.email_address.value)==''){
		oForm.email_address.focus();
		return false;
	}else{
		oError.html('');
	}
}
function checkRegField(obj,eId){
	var oIcon=$("#icon_"+eId);
	var oMsg=$("#msg_"+eId);
	if(eId=='e'){
		if(!(/^[\w\.\-]+@[a-z\d\-]+(\.[a-z\d\-]+)+$/i).test($.trim(obj.value))){
			obj.value='';
			oIcon.html("<img src=\"/images/login_wrong_icon.png\" />");
			oMsg.text("Please enter a valid email address.").css('display','block');
		}else{
			oIcon.html("<img src=\"/images/regist_right.png\" />");
			oMsg.text('').css('display','none');
		}
	}else{
		if($.trim(obj.value).length<6||$.trim(obj.value).length>24){
			obj.value='';
			oIcon.html("<img src=\"/images/login_wrong_icon.png\" />");
			oMsg.text("The length of password is 6-24 chars.").css('display','block');
		}else{
			oIcon.html("<img src=\"/images/regist_right.png\" />");
			oMsg.text('').css('display','none');
		}
	}
}
function checkConfirm(obj,eId){
	var oIcon=$("#icon_"+eId);
	var oMsg=$("#msg_"+eId);
	if(eId=='ce'){
		if($.trim($("#email_address_s").val())!==''){
			if($.trim(obj.value)!=$.trim($("#email_address_s").val())){
				obj.value='';
				oIcon.html("<img src=\"/images/login_wrong_icon.png\" />");
				oMsg.text("The two emails are not the same.").css('display','block');			
			}else{
				oIcon.html("<img src=\"/images/regist_right.png\" />");
				oMsg.text('').css('display','none');
			}
		}
	}else{
		if($.trim($("#password_s").val())!==''){
			if($.trim(obj.value)!=$.trim($("#password_s").val())){
				obj.value='';
				oIcon.html("<img src=\"/images/login_wrong_icon.png\" />");
				oMsg.text("The two passwords are not the same.").css('display','block');			
			}else{
				oIcon.html("<img src=\"/images/regist_right.png\" />");
				oMsg.text('').css('display','none');
			}
		}
	}
}
function checkRegForm(oForm){
	var oFont=$("font",oForm);
	var oInput=$("input",oForm);
	for(var i=0;i<oFont.length;i++){
		if(oFont.eq(i).html()!=''||$.trim(oInput.eq(i).val())==''){
			oInput.eq(i).focus();
			return false;
		}
	}
}
function checkSearch(oForm){
	if($.trim(oForm.action.value)==''){
		oForm.action.focus();
		return false;
	}else{
		oForm.action.value=escape(oForm.action.value);
	}
}
function checkComment(oForm){
	if($.trim(oForm.title.value)==''){
		oForm.title.focus();
		return false;
	}else if($.trim(oForm.comment.value)==''){
		oForm.comment.focus();
		return false;
	}else{
		alert("Your comment has been submitted. Comments are moderated, and will not appear until the author has approved them.");
	}
}
function check_form_pass(oForm){
	var oldPwd = oForm.old_password;
	var newPwd = oForm.new_password;
	var conPwd= oForm.new_pwd;
	var oErr = $('#msg');
	if($.trim(oldPwd.value)==''){
		oErr.html('You must provide the old password');
		oldPwd.focus();
		return false;
	}else
	{
		oErr.html('');
		if($.trim(newPwd.value)==''||$.trim(newPwd.value).length<6){
			oErr.html('Password must be between 6 and 20');
			newPwd.focus();
			return false;
		}else{
			oErr.html('');
			if($.trim(conPwd.value)!=$.trim(newPwd.value)){
				oErr.html('The two new passwords are not the same');
				conPwd.focus();
				return false;
			}else{
				oErr.html('');
			}
			
		}
	}
}


