function validate(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]|\./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    theEvent.preventDefault();
  }
}

function validate_required(field) {
	with (field) {
		if (value==null||value=="") {
			return false;
		}
		else {	
			return true;
		}
	}
}

function validate_dropdown(field) {
	with (field) {
		if (selectedIndex == 0 ) {
        	return false;
		}
		else {	
			return true;
		}
	}
}

function validate_email(field) {
	with (field) {
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
	  
		if (apos<1||dotpos-apos<2) {
		  return false;
		}
		else {
		  return true;
		}
	}
}

function validate_form(thisform) {
	with (thisform) {
		if (validate_required(name) == false) {
				  name.focus();
				  comments.value= "Please complete your full name.";
				  return false;
		}	
		if (validate_required(contactNumber) == false) {
				  contactNumber.focus();
				  comments.value= "Please complete your contact no";
				  return false;
		}		  
		if (validate_email(email) == false) {
		  		  email.focus();
				  comments.value= "Please enter a valid email.";
				  return false;
		}	
		if (validate_required(message) == false) {
				  message.focus();
				  comments.value= "Please add a message.";
				  return false;
		}
	}
}

function validate_form_bookOrder(thisform) {
	with (thisform) {
		if (validate_required(name) == false) {
				  name.focus();
				  comments.value= "Please complete your full name.";
				  return false;
		}	
		if (validate_required(contactNumber) == false) {
				  contactNumber.focus();
				  comments.value= "Please complete your contact no";
				  return false;
		}		  
		if (validate_email(email) == false) {
		  		  email.focus();
				  comments.value= "Please a valid email.";
				  return false;
		}	
		if (validate_required(address) == false) {
				  address.focus();
				  comments.value= "Please complete your address.";
				  return false;
		}
		if (validate_dropdown(bookSelection) == false) {
				  bookSelection.focus();
				  comments.value= "Please select a book.";
				  return false;
		}
	}
}

function validate_addArticle(thisform) {
	with (thisform) {
		if (validate_required(uploadedfile) == false) {
				  document.getElementById("alertMessage").style.display = "block";
				  document.getElementById("alertMessage_Category").style.display = "none";
				  return false;
		}
		if (validate_dropdown(ArticleCategory) == false) {
				  ArticleCategory.focus();
				  document.getElementById("alertMessage").style.display = "none";
				  document.getElementById("alertMessage_Category").style.display = "block";
				  return false;
		}
	}
}
