/*
 * 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(
			new RegExp("^([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22)(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22))*\\x40([a-zA-Z0-9]{1}|[a-zA-Z0-9]([a-zA-Z0-9-]){0,61}[a-zA-Z0-9])(\\x2e([a-zA-Z0-9]{1}|[a-zA-Z0-9]([a-zA-Z0-9-]){0,61}[a-zA-Z0-9]))*$", "g")
		)){
			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)	
	}	
}

