// JavaScript Document

function trim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(" " + str + " ");
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
			j++;
		}
            s = s.substring(j, i);
	}

	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1;       
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
			i--;
		}
            s = s.substring(0, i+1);
	}
	return s;
}

function validatesignup(theForm) {
	var errmsg = "";
	if (trim(theForm.fullname.value) == "") errmsg += "\tParent First Name\n";
	if (trim(theForm.lastname.value) == "") errmsg += "\tParent Last Name\n";
	var femail = trim(theForm.email.value);
	if (femail == "") {
		errmsg += "\tParent Email\n"; 
	} else {
		num = femail.search(/^[\w\.-]+@{1}([\w-]+\.{1})+[a-z]{2,3}(a-z)?$/i);
		if (num == -1) errmsg += "\tParent Email (properly fomatted)\n";
	}
	var phonenum = theForm.phone.value.replace(/[^\d]+/g,'');
	if (phonenum == "") {
		errmsg += "\tParent Phone #\n";
	} else if (phonenum.length < 10) {
		errmsg += "\tParent Phone # (Including Area Code)\n";
	}
	if (trim(theForm.childname.value) == "") errmsg += "\tChild's Grade Level & Subjects In Need Of Tutoring\n";
	if (trim(theForm.difficulties.value) == "") errmsg += "\tDescribe your child's learning difficulties\n";
	if (trim(theForm.hopes.value) == "") errmsg += "\tWhat are your hopes with our personal etutoring service?\n";
	
	if (errmsg != "") {
		alert("These areas need attention...\n" + errmsg);
		return false;
	}
	return true;			 
}

function validateTutorSignup(joinform) {

    var errmsg = "";
    if (trim(joinform.name1.value) == "") errmsg += "\tFirst Name\n";
    var femail = trim(joinform.email1.value);
    if (femail == "") {
        errmsg += "\tEmail\n";
    } else {
        num = femail.search(/^[\w\.-]+@{1}([\w-]+\.{1})+[a-z]{2,3}(a-z)?$/i);
        if (num == -1) errmsg += "\tEmail (properly fomatted)\n";
    }

    if (errmsg != "") {
        alert("These areas need attention...\n" + errmsg);
        return false;
    }

    return true;
}

  window.onload = function(){
      settings = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }
      var myBoxObject = new curvyCorners(settings, "formbox");
      myBoxObject.applyCornersToAll();
  }