// Java Validation

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}


// Text Field Validation
function valText(textObject) 
{
	var textFilled = false;
	
	if (textObject.value == '') 
	{
		textObject.style.background ='yellow';
	}
	else
	{
		textObject.style.background ='white';
		
		textFilled = true;
	}
	
	return textFilled;
}

// Radio Button Validation
function valRadioButton(radioBtn) 
{
	var buttonChecked = false;
	
	for (i=0;i<radioBtn.length;i++) 
	{
		if (radioBtn[i].checked) 
		{
			buttonChecked = radioBtn[i].value;
		}
	}
	
	// paint in colour
	
	for (i=0;i<radioBtn.length;i++) 
	{
		if( buttonChecked )
		{
			radioBtn[i].style.background ='white';
		}
		else
		{
			radioBtn[i].style.background ='yellow';
		}
	}
	
	return buttonChecked;
}
                  
function checkForm()
{
	var status = true;
	var alertMsg = "";
	
	// firstname
	if( !valText(document.contact.name) )
	{
		status = false;
		alertMsg += "\nName";
	}
	
    // lastname
	if( !valText(document.contact.phone_no) )
	{
		status = false;
		alertMsg += "\nPhone";
	}
		
	// phone_no
	if( !valText(document.contact.message_txt) )
	{
		status = false;
		alertMsg += "\nMessage Text";
	}
	
    // If the script gets this far through all of your fields
	// without problems, it's ok and you can submit the form
	if (alertMsg != "") 
	{
		alert(alertMsg);
	} 

	return status;
}


