function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function chekuser(cache_method,ui_id,value){

	if(value!=""){
		
			Http.get({
			
			url: "ajaxresponse/ajaxvalidation.php?act=usernamevalid&username="+Base64.encode(value),
			callback: update,
			cache: cache_method
			
			}, [ui_id]);
		}
  	}
function validateValue( strValue, strMatchPattern ) {
	var objRegExp = new RegExp( strMatchPattern);
	 //check if string matches pattern
	 return objRegExp.test(strValue);
}

function validateadduser(){
	
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	
	with (document.register_frm){
		
	var com = document.getElementById('user_name').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("User Name cannot be empty.");
			user_name.focus();
			return false;
		}
		
	if(user_name.value.length <6 || user_name.value==''){
			alert("User Name must be minimum 6 character long.");
			user_name.focus();
			return false;
		}
	if(!validateValue(document.getElementById('user_name').value, '^[a-zA-Z0-9_-]+$')){
		alert('No special characters are allowed in username other than _ and -');
		user_name.focus();
		return false;
		}
		
	var com = document.getElementById('password').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Password cannot be empty.");
			password.focus();
			return false;
		}
	
	var com = document.getElementById('re_password').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Retype Password cannot be empty.");
			re_password.focus();
			return false;
		}
		
		if(password.value.length <6 || password.value==''){
			alert("Password must be minimum 6 character long.");
			password.focus();
			return false;
		}
		if(password.value!=re_password.value){
			alert("Password does not match with the confirm password.");
			password.focus();
			return false;
		}
			
		
	var com = document.getElementById('email').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Email Address cannot be empty.");
			email.focus();
			return false;
		}
		
		if(email.value.match(pattern)){}else{   
			alert('Please enter your valid email address');
			email.focus();
			return false;
		}
		
	var com = document.getElementById('security_code').value;
	chars = ' ';

		var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Security Code cannot be empty.");
			security_code.focus();
			return false;
		}
	
	}
	return true;

}

function contactupdate(result, ui_id){
	var div = $(ui_id);

	if (result.status==Http.Status.OK){
		
			if (  result.responseText == 'ok' )
			{
				div.innerHTML = "";
				document.getElementById('contactusfrm').submit();
				//document.getElementById('contactSbt').disable=true;
				//document.getElementById('sbtload').innerHTML = '<input name="Submit" value="wait..." class="btnstyle" id="contactSbt" type="submit" disable="disable"/>';
				
			}else{
				div.innerHTML = result.responseText;
			}
			
			}else{
				div.innerHTML = "";
	        }
}// end contactupdate()

function contactvalid(cache_method,ui_id){
	
 with (document.contactusfrm){
	 
	var name=Base64.encode(fname.value);
	var emailadd = Base64.encode(email.value);
	var comment=Base64.encode(feedback.value);
	var sscode=Base64.encode(varcode.value);
	var url="&name="+name+"&emailadd="+emailadd+"&comment="+comment+"&sscode="+sscode;
	
 }

Http.get({

	url: "ajaxresponse/ajaxvalidation.php?act=contactusvalid"+url,
	callback: contactupdate,
	cache: cache_method

 }, [ui_id]);

return true;

}

function validateaddpost(){
		
	with (document.post_frm){
		
	var com = document.getElementById('nick_name').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Nick Name cannot be empty.");
			nick_name.focus();
			return false;
		}
		
	var com = document.getElementById('category').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Please Select category.");
			category.focus();
			return false;
		}
	
	var com = document.getElementById('wish_sell').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Please Select Choice.");
			wish_sell.focus();
			return false;
		}
		
	
	var com = document.getElementById('var_code').value;
	chars = ' ';

		var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Security Code cannot be empty.");
			var_code.focus();
			return false;
		}
		
	}
	return true;

}

function validatecomments(){
	
	with (document.comment_frm){
		
	var com = document.getElementById('nick_name').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Nick Name cannot be empty.");
			nick_name.focus();
			return false;
		}
		
	var com = document.getElementById('comments').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Comment cannot be empty.");
			comments.focus();
			return false;
		}
	
	
	var com = document.getElementById('var_code').value;
	chars = ' ';

		var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Security Code cannot be empty.");
			var_code.focus();
			return false;
		}
		
	}
	return true;

}

function validatechangepassword(){
	
	with (document.changepasswordfrm){
		
	var com = document.getElementById('oldpass').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Old Password cannot be empty.");
			oldpass.focus();
			return false;
		}
	
		
	var com = document.getElementById('newpass').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("New Password cannot be empty.");
			newpass.focus();
			return false;
		}
		
	if(newpass.value.length <6){
			alert("New Password must be minimum 6 character long.");
			newpass.focus();
			return false;
		}
		
	var com = document.getElementById('conpass').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Confirm New Password cannot be empty.");
			newpass.focus();
			return false;
		}
		
	
	if(newpass.value!=conpass.value){
			alert("New Password does not match with the confirm New password.");
			newpass.focus();
			return false;
		}
			
	
	
	var com = document.getElementById('varcode').value;
	chars = ' ';

		var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Security Code cannot be empty.");
			varcode.focus();
			return false;
		}
		
	}
	return true;

}

function validate_email(){
	
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	
	with (document.form1){
		
	var com = document.getElementById('name').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Nick Name cannot be empty.");
			name.focus();
			return false;
		}
	var com = document.getElementById('emails').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Email Address cannot be empty.");
			emails.focus();
			return false;
		}
		
		if(emails.value.match(pattern)){}else{   
			alert('Please enter your valid email address');
			emails.focus();
			return false;
		}
	}
}

function validate_forgotpass(){
	
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	
	with (document.forgotpasswordfrm){
	
	var com = document.getElementById('fmail').value;
	chars = ' ';

	var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Email Address cannot be empty.");
			fmail.focus();
			return false;
		}
		
		if(fmail.value.match(pattern)){}else{   
			alert('Please enter your valid email address');
			fmail.focus();
			return false;
		}
		
	var com = document.getElementById('varcode').value;
	chars = ' ';

		var test = (ltrim(rtrim(com, chars), chars));
	
	if(test == '')
	
		{
			alert("Security Code cannot be empty.");
			varcode.focus();
			return false;
		}
	}
}

//function validate_login(){
//	
//	with (document.login_frm){
//	
//	var com = document.getElementById('user_name').value;
//	chars = ' ';
//
//	var test = (ltrim(rtrim(com, chars), chars));
//	
//	if(test == '')
//	
//		{
//			alert("User Name cannot be empty.");
//			user_name.focus();
//			return false;
//		}
//		
//	var com = document.getElementById('user_pass').value;
//	chars = ' ';
//
//		var test = (ltrim(rtrim(com, chars), chars));
//	
//	if(test == '')
//	
//		{
//			alert("Password cannot be empty.");
//			user_pass.focus();
//			return false;
//		}
//	}
//}