// JavaScript Document



function validate(theform) {
	theform.elementOne
	for (var i = 0; i < theform.elements.length; i++) {
		
		if (theform.elements[i].type != "submit" | theform.elements[i].type != "checkbox") {
			if (theform.elements[i].alt == "validate") {
				if (theform.elements[i].value == "") {
					
					alert (theform.elements[i].name+" requires a value");
					return false;
				}
			}
			if (theform.elements[i].alt == "validate_url") {
				if (theform.elements[i].value != "") {
					
					if (!isUrl(theform.elements[i].value)) {
						alert (theform.elements[i].name+" is an invalid URL");
						return false;
					}

					
				}
				else {
					alert (theform.elements[i].name+" requires a value");
					return false;	
				}
			}
			
			if (theform.elements[i].alt == "validate_email") {
				if (theform.elements[i].value != "") {
					
					if (!isEmail(theform.elements[i].value)) {
						alert (theform.elements[i].name+" is an invalid email");
						return false;
					}

					
				}
				else {
					alert (theform.elements[i].name+" requires a value");
					return false;	
				}
			}
		}
	}
	if (document.getElementById("code1") != null) {
		if (document.getElementById("code1").value != document.getElementById("code2").value) {
			alert ("security code invalid");
			return false;
		}
	}
	return true;
}


function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}

function isEmail(s) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(s) == false) {
		return false;
	}
	return true;
}

