//contact us form validation
isValidEmail = function(address) {
	if (address != "" && address.search) {
      if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
      else return false;
	}
   else return true;
};

passwordMatch = function(first,second) {
	if (first != second) {
      return false;
	}
   else return true;
};

validate = function(form) {
	var errorList = [];
	if(!form.firstname.value) errorList[errorList.length] = "Please enter your first name.";
	if(!form.lastname.value) errorList[errorList.length] = "Please enter your last name.";
	if(!form.email.value) errorList[errorList.length] = "Please enter your email address.";
	if(form.email.value && !isValidEmail(form.email.value)) errorList[errorList.length] = "Your email address is not valid.";
	if(!form.comment.value) errorList[errorList.length] = "Please enter your comments.";
	
	if(errorList.length > 0) {
		var message = "";
		for(var i=0; i<errorList.length; i++) {
			message += errorList[i] + "\n";
		}
		alert(message);
		return false;
	}
	return true;
};

//registration form validation
validateregistration = function(form) {
	var errorList = [];
	
	//user name
	if(!form.username.value) errorList[errorList.length] = "Please enter your username.";
	
	//password
	if(!form.password.value) errorList[errorList.length] = "Please enter a password.";
	
	//confirm password
	if(form.confirm.value && !passwordMatch(form.password.value,form.confirm.value)) errorList[errorList.length] = "Password mismatch. Please double-check.";
	
	//email
	if(!form.email.value) errorList[errorList.length] = "Please enter your email address.";
	if(form.email.value && !isValidEmail(form.email.value)) errorList[errorList.length] = "Your email address is not valid.";
	
	//first name
	if(!form.firstname.value) errorList[errorList.length] = "Please enter your first name.";
	
	//last name
	if(!form.lastname.value) errorList[errorList.length] = "Please enter your last name.";
	
	//company
	if(!form.company.value) errorList[errorList.length] = "Please enter your company name.";
	
	//country
	if(form.country.options[0].selected) errorList[errorList.length] = "Please select your country.";
	
	//license
	if(!form.license.checked) errorList[errorList.length] = "You must accept the LICENSE AGREEMENT.";
	
	if(errorList.length > 0) {
		var message = "";
		for(var i=0; i<errorList.length; i++) {
			message += errorList[i] + "\n";
		}
		alert(message);
		return false;
	}
	return true;
};

//get country
//alert(this.form.country.options[this.form.country.selectedIndex].value);