/*
 * RFormValidator - checker for different data types in rehister form
 * 
 * .zip(zipCode, countryCode) 
 * 	RET true if code is ok or no such rule
 * 	EXC throws error message if zipcode is invalid
 * 
 * .email(emailAddress)
 * 	RET true if email is invalid
 * 	EXC throws error message if not
 * 
 * */

RFormValidator = {
	zip : function(zip, countryCode){
		// Validate zip code by state
		if(typeof check_zip_code_rules[countryCode] != 'undefined'){

			var state = false;
			if(typeof check_zip_code_rules[countryCode].lens[zip.toString().length] != 'undefined'){
				state = true;
			}
			state = state &&  (
				typeof check_zip_code_rules[countryCode].re == 'undefined' ||
				zip.toString().search(check_zip_code_rules[countryCode].re) == -1
			)
		
			if(state) return true
			throw(check_zip_code_rules[countryCode].error)
		}
		return true;
		
	},
	
	email : function(mail){
		if(mail.match(/[A-Za-z0-9\.\-_]+@[A-Za-z0-9\-\.]+\.[A-Za-z]{2,6}/ig)){
			return true;
		}else{
			throw(txt_email_invalid);
		}
	},
	
	passwd : function(value1, value2){
		if(value1 && value2 && (value1 == value2))
			return true;
		else
			throw(XCart.Lang.txt_chpass_match)	
	}	
}

