// JavaScript Document



//Function to clear the search box
function clearSearchBox() {
	document.getElementById("SearchTerm").value = '';
}

//Function to clear the email box
function ClearBox() {
	document.getElementById("Email").value = '';
}

function ClearBox2() {
	document.getElementById("PetName").value = '';	
}

function ClearBox3() {
	document.getElementById("Species").value = '';	
}

//Function that checks the search box 
function CheckSearchBox() {	
	if(document.getElementById("SearchTerm").value == '' || document.getElementById("SearchTerm").value == 'Search by Keyword or Product Name') {
		alert("The search term is required.");
		return false;
	}
	
}

//Function check the email entered
function CheckEmails() {
	var emailstring = document.getElementById("Email").value;
	var AtSign = "@";
	var Dot = ".";
	var AtSignPOS = emailstring.indexOf(AtSign);
	var emailLength = emailstring.length;
	var DotPOS = emailstring.indexOf(Dot);
	
	if (emailstring.indexOf(AtSign)==-1){
	   alert("Please enter a valid email address.");
	   return false;
	}
	if (emailstring.indexOf(AtSign)==-1 || emailstring.indexOf(AtSign)==0 || emailstring.indexOf(AtSign)+1==emailLength){
	   alert("Please enter a valid email address.");
	   return false;
	}
	if (emailstring.indexOf(Dot)==-1 || emailstring.indexOf(Dot)==0 || emailstring.indexOf(Dot)+1==emailLength){
		alert("Please enter a valid email address.");
		return false;
	}
	 if (emailstring.indexOf(AtSign,(AtSignPOS+1))!=-1){
		alert("Please enter a valid email address.");
		return false;
	 }
	 if (emailstring.substring(AtSignPOS-1,AtSignPOS)==Dot || emailstring.substring(AtSignPOS+1,AtSignPOS+2)==Dot){
		alert("Please enter a valid email address.");
		return false;
	 }
	 if (emailstring.indexOf(Dot,(AtSignPOS+2))==-1){
		alert("Please enter a valid email address.");
		return false;
	 }
	 if (emailstring.indexOf(" ")!=-1){
		alert("Please enter a valid email address.");
		return false;
	 }
}
