
function g(arg){
	return document.getElementById(arg);
}

function gv(arg){
	return document.getElementById(arg).value;
}

function isValid(id, v){
	var a=document.getElementsByTagName('label');
	for(var k=0;k<a.length;k++){
		for(var n=0;n<a[k].attributes.length;n++){
			if(a[k].attributes[n].nodeName == 'for' && a[k].attributes[n].nodeValue == id && (a[k].className == "required" || a[k].className == "error")){
				if(v){
					a[k].className = "required";
				} else {
					a[k].className = "error";
				}
			}
		}
	}
	return v;
}

String.prototype.alphaNumeric = function(){return /^[\w\s\.,!\&]+$/.test(this);}
String.prototype.nonBlank = function(){return /^.+$/.test(this);}
String.prototype.numeric = function(){return /^\d+$/.test(this);}
String.prototype.phoneNumber = function(){return /^\(?\d{3}\)?[-\s.]?\d{3}[-\s.]?\d{4}$/.test(this);}
String.prototype.validDate = function(){return /^(0[1-9]|1[012]|[1-9])[- /.](0[1-9]|[12][0-9]|3[01]|[1-9])[- /.](19|20){1}\d\d$/.test(this);}
String.prototype.validEmail = function(){return /\b[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}\b/.test(this.toLowerCase());}
String.prototype.validZip = function(){return /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(this);}
String.prototype.rxNumber = function(){return this.length>=6?true:false;}
String.prototype.creditCard = function(){return /(\d{4}[- ]?){3}\d{4}/.test(this);}
String.prototype.fourDigitSC = function(){return this.length==4?true:false;}
String.prototype.threeDigitSC = function(){return this.length==3?true:false;}
String.prototype.expiredMonth = function(){return ((new Date).getMonth()+1 > this)?false:true;}
String.prototype.expiredYear = function(){return ((new Date).getFullYear() > this)?false:true;}

function check(valid, id){
	var pass = true;
	for(var k=2;k<arguments.length;k++){
		if(!gv(id)[arguments[k]]()){
			pass = false;
		}
	}
	return isValid(id, pass)?valid:false;
}

function validateForm(){
	
	var valid = true;
	valid = check(valid, 'first_name', "nonBlank");
	valid = check(valid, 'last_name', "nonBlank");
	valid = check(valid, 'email', "validEmail");
	valid = check(valid, 'your_name', "nonBlank");
	
		
	if(!valid){
		
	} else {
		
		document.forms[0].submit();
			
	}
	return valid;
}