var whitespace = " \t\n\r";

function isEmpty(s)  {   
	return ((s == null) || (s.length == 0))
	}

function isWhitespace(s)  {
    var i;
    if (isEmpty(s)) return true;
 
    for (i = 0; i < s.length; i++)  {
	var c = s.charAt(i);
	if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function validEmail(strEmail) {
 invalidChars = " /:,;";
 if (strEmail == "")  {
  return false;
 }
 
 for (i=0; i<invalidChars.length; i++)  {
  badChar = invalidChars.charAt(i)
  if (strEmail.indexOf(badChar,0) != -1)  {
     return false;
     }
  }
  atPos = strEmail.indexOf("@", 1)
  if (atPos == -1)  {
    return false;
  }
  if (strEmail.indexOf("@", atPos+1) != -1)  {
    return false;
  }
  periodPos = strEmail.indexOf(".", atPos)
  if (periodPos == -1)  {
    return false;
  }
  if (periodPos+3 > strEmail.length)  {
    return false;
  }
 return true;
}

function submitIt(advert)  {

	if (isWhitespace(advert.tContact.value))  {
	 alert("Please enter missing contact name and then re-submit.");
 		advert.tContact.focus();
	 	advert.tContact.select();
		return false;
			}

	if (isWhitespace(advert.tTitle.value))  {
	 alert("Please enter missing Company Title and then re-submit.");
 		advert.tTitle.focus();
	 	advert.tTitle.select();
		return false;
			}

	if (isWhitespace(advert.tStreet.value))  {
	 alert("Please enter missing Street Address and then re-submit.");
 		advert.tStreet.focus();
	 	advert.tStreet.select();
		return false;
			}

	if (isWhitespace(advert.tCity.value))  {
	 alert("Please enter missing City Name and then re-submit.");
 		advert.tCity.focus();
	 	advert.tCity.select();
		return false;
			}

	if (isWhitespace(advert.tState.value))  {
	 alert("Please enter missing State Name and then re-submit.");
 		advert.tState.focus();
	 	dadvert.tState.select();
		return false;
			}

	if (isWhitespace(advert.tZip.value))  {
	 alert("Please enter missing Zip Code and then re-submit.");
 		advert.tZip.focus();
	 	advert.tZip.select();
		return false;
			}

	if (isWhitespace(advert.tPhone.value))  {
	 alert("Please enter missing Telephone Number and then re-submit.");
 		advert.tPhone.focus();
	 	advert.tPhone.select();
		return false;
			}

	if (!validEmail(advert.tEmail.value))  {
	 alert("Invalid e-mail address.\n Please try again.");
		advert.tEmail.focus();
	 	advert.tEmail.select();
		return false;
			}

	if (isWhitespace(advert.tUrl.value))  {
	 alert("Please enter missing Website HomePage and then re-submit.");
 		advert.tUrl.focus();
	 	advert.tUrl.select();
		return false;
			}
		
	return true;
}
