/* validate form */

function valform(frmObj)
{
	var errMsg = ""

	   /* validate First Name */

	if (fieldBlank(frmObj.sname.value)) {
		return false
	}
	
	if (fieldBlank(frmObj.comments.value)) {
		return false
	}
	
  if (document.contactForm.semail.value.length==0) {
	  return false
	}
	
	var emailRe=new RegExp("^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+$");
	if (!emailRe.test(document.contactForm.semail.value)) {
		return false
	}
	
  return true
	
}

/*********************************************************
* Function: highlight()                                  *
* Purpose : General field check if blank return          *
*                                                        *
* Input   : nodeID, colour                               *
* Output  : change the colour of the background of id    *
* Author  : Mark Monckton                                *
* Date    : March 27, 2006                               *
* Notes   : This code adapted from student Guide week 9  *
********************************************************/
  
function highlight(nodeID,colour) {

//does the browser understand getElementById?
    if (document.getElementById) {
 // find element in HTML DOM tree, change the background color
       document.getElementById(nodeID).style.backgroundColor=colour;
    }

}
/*********************************************************
* Function: showHideMsg()                                *
* Purpose : Display or hide message using css and DOM    *
*                                                        *
* Input   : ID, value                                    *
* Output  : modifies the CSS to display error message    *
* Author  : Mark Monckton                                *
* Date    : March 27, 2006                               *
* Notes   : This code adapted from student Guide week 9  *
********************************************************/

  function showHideMsg(myId,myValue) {

//does the browser understand getElementById?
      if (document.getElementById) {
          //document.getElementById(myId).style.display = myValue;
			  document.getElementById(myId).innerHTML=myValue;
      }
  }
	

function validName(myField) {

    if (myField.value == null || myField.value == "" ) {
			showHideMsg('nameErrormsg','Your Name is Blank.')
        highlight('sname','#ffcccc')
    } else {
        showHideMsg('nameErrormsg','')
        highlight('sname','#cccccc')
    }
}

function validEmail(myField) {

  	var emailRe=new RegExp("^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+$");

    if (myField.value == null || myField.value == ""  || !emailRe.test(myField.value)) {
			showHideMsg('emailErrormsg','Your Email address is Blank or invalid.')
        highlight('semail','#ffcccc')
    } else {
        showHideMsg('emailErrormsg','')
        highlight('semail','#cccccc')
    }
}

function validText(myField) {

    if (myField.value == null || myField.value == "" ) {
			showHideMsg('textErrormsg','Your Message is blank.')
    } else {
        showHideMsg('textErrormsg','')
    }
}

function resetMessage() {
		showHideMsg('nameErrormsg','');
    highlight('sname','#cccccc');
		showHideMsg('emailErrormsg','');
    highlight('semail','#cccccc');
		showHideMsg('textErrormsg','');
}

  function fieldBlank(myField) {
      if (myField == null || myField == "") {
          return true
      } else {
          return false
      }
  }