var selected = false;
var thousand = 6500;
var hundred = 100;
var fifty = 50;
var twenty = 20;

function isEmail(address) {
  if (address.value.indexOf("@")  != "-1" &&
      address.value.indexOf(".")  != "-1")
  return true
  else return false;
}

function isFilled(element) {
  if (element.value == "" || element.value == null) 
  return false
  else return true;
}

function validInput(element) {
  if (element.value.indexOf("<")  == "-1" &&
      element.value.indexOf(">")  == "-1")
		return true
		else return false;
		}



function checkLengthMax(field, maxLength) {
	if (field.value.length < maxLength) return true
	else return false;
	}
/**/
function validDate(container, minNum, maxNum) {
	if ( parseInt(container.value) < minNum ) return false;
	if ( parseInt(container.value) > maxNum ) return false
	else return true;
	}

function possibleDate(DD, MM) {
	//Note 31 days month's not checked as this is check by max size of day.
	if (parseInt(MM.value) == 4 ||
		parseInt(MM.value) == 6 ||
		parseInt(MM.value) == 9 ||
		parseInt(MM.value) == 11
		)
	{
	if (parseInt(DD.value) > 30) 
	return false;
	}
	if (parseInt(MM.value) == 2 )
	{
		if (parseInt(DD.value) > 28)
		return false;
	}
	else return true;
	}
	
function isInteger(stringGiven) {
  if (stringGiven.value == "") return false;
  for (var i = 0; i < stringGiven.value.length; i++) {
      if (stringGiven.value.charAt(i) < "0" ||
          stringGiven.value.charAt(i) > "9") {
        return false;
      }
  }
  return true;
}

function checkForm(form) {

   if (isFilled(form.sendersName) == false) {
    alert("Please enter your name.");
    form.sendersName.focus();
    return false;
  }	
  
      if (validInput(form.sendersName) == false) {
    alert("< & > are not allowed.");
    form.sendersName.focus();
    return false;
  }	
	

 if(checkLengthMax(form.sendersName, twenty) == false) {
  	alert ("Your name can not be more than twenty characters")
	form.sendersName.focus();
	return false;
	}  
	
	
   if (isFilled(form.friendsName) == false) {
    alert("Please enter your friends name.");
    form.friendsName.focus();
    return false;
  }	
  
      if (validInput(form.friendsName) == false) {
    alert("< & > are not allowed.");
    form.sendersName.focus();
    return false;
  }	
	

 if(checkLengthMax(form.friendsName, twenty) == false) {
  	alert ("Your friends name can not be more than twenty characters")
	form.sendersName.focus();
	return false;
	}  
	
	


if (isFilled(form.email) == false) {
    alert("Please enter your friends email.");
    form.friendsName.focus();
    return false;
  }	
  
      if (validInput(form.email) == false) {
    alert("< & > are not allowed.");
    form.sendersName.focus();
    return false;
  }	
	

 if(checkLengthMax(form.email, fifty) == false) {
  	alert ("Your friends email can not be more than 100 characters")
	form.sendersName.focus();
	return false;
	}  
if (isEmail(form.email) == false) { 
    alert("Please enter valid email address.");
    form.email.focus();
    return false;
  }
if (isFilled(form.message) == false) {
    alert("Please enter your friends name.");
    form.message.focus();
    return false;
  }	







  return true;
}

