function trim(str) {
  while (str.charAt(str.length - 1)==" ")
    str = str.substring(0, str.length - 1);
  while (str.charAt(0)==" ")
    str = str.substring(1, str.length);
  return str;
}

function verifyCustom() {

	CustomForm.name.value = trim(CustomForm.name.value);
	CustomForm.email.value = trim(CustomForm.email.value);
	CustomForm.pid.value = trim(CustomForm.pid.value);
	CustomForm.width.value = trim(CustomForm.width.value);
	CustomForm.height.value = trim(CustomForm.height.value);
	
	if (CustomForm.name.value == "Your Name") {
		alert ("Please enter your name.");
		CustomForm.name.focus();
		return false;
	}
	if (CustomForm.email.value == "Your E-mail") {
		alert ("Please enter a valid address.");
		CustomForm.email.focus();
		return false;
	}
	if (CustomForm.email.value !="Your E-mail")
	{ 
		var goodEmail = CustomForm.email.value.match
							(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
		if (goodEmail)
		{
			//alert('good email 1');
		} 
		else 
		{
			alert('Please enter a valid e-mail address.');
			CustomForm.email.focus();
			CustomForm.email.select();
			return false;
		}
	}
	if (!goodEmail) return false;

	if (CustomForm.pid.value == "Painting ID# You are Interested in") {
		alert ("Please enter the painting ID# you are interested in.");
		CustomForm.pid.focus();
		return false;
	}

	if (CustomForm.width.value == "Requested Width") {
		alert ("Please enter the requested width.");
		CustomForm.width.focus();
		return false;
	}

	if (CustomForm.height.value == "Requested Height") {
		alert ("Please enter the requested height.");
		CustomForm.height.focus();
		return false;
	}


	return true;
}

function verifyUpload() {

    CustomForm.email.value = trim(CustomForm.email.value);
    CustomForm.pid.value = trim(CustomForm.pid.value);
    CustomForm.answer.value = trim(CustomForm.answer.value);

    if (CustomForm.email.value == "" || CustomForm.email.value == "Your E-mail") {
        alert("Please enter a valid address.");
        CustomForm.email.focus();
        return false;
    }
    if (CustomForm.email.value != "") {
        var goodEmail = CustomForm.email.value.match
							(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
        if (goodEmail) {
            //alert('good email 1');
        }
        else {
            alert('Please enter a valid e-mail address.');
            CustomForm.email.focus();
            CustomForm.email.select();
            return false;
        }
    }
    if (!goodEmail) return false;

    if (CustomForm.pid.value == "" || CustomForm.pid.value == "Painting ID number(s)") {
        alert("Please enter the painting ID number(s) you are interested in.");
        CustomForm.pid.focus();
        return false;
    }

    if (CustomForm.answer.value != "8") {
        alert("Please enter the correct answer to the math question.");
        CustomForm.answer.focus();
        return false;
    }

    return true;
}

function verifyComment() {

    ForumForm.email.value = trim(ForumForm.email.value);
    ForumForm.name.value = trim(ForumForm.name.value);
    ForumForm.comment.value = trim(ForumForm.comment.value);

    if (ForumForm.comment.value == "" || ForumForm.comment.value == "Enter your comment here...") {
        alert("Please enter your comment.");
        ForumForm.comment.focus();
        return false;
    }

    if (ForumForm.email.value == "" || ForumForm.email.value == "Email (required) - Not published") {
        alert("Please enter a valid email address.");
        ForumForm.email.focus();
        return false;
    }
    if (ForumForm.email.value != "") {
        var goodEmail = ForumForm.email.value.match
							(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
        if (goodEmail) {
            //alert('good email 1');
        }
        else {
            alert('Please enter a valid e-mail address.');
            ForumForm.email.focus();
            ForumForm.email.select();
            return false;
        }
    }
    if (!goodEmail) return false;

    if (ForumForm.name.value == "" || ForumForm.name.value == "Name (required)") {
        alert("Please enter your name.");
        ForumForm.name.focus();
        return false;
    }

    return true;
}
