// JavaScript Document
// This script will validate any null orders as well as any required fields
<!--
function validateTmonial(theForm) {
var reason = "";
//alert("BANG");
  //reason += validateUsername(theForm.username);
  //reason += validatePassword(theForm.pwd);
  //The identifier is the ID
  reason += validateEmpty(theForm.T_NAME, "NAME");
  reason += validateEmpty(theForm.T_LOCATION, "LOCATION");
  reason += validateEmpty(theForm.T_TEXT, "TESTIMONIAL");
  
  
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function validateEmpty(fld, emptyFld) {
    var error = "";
    //alert("Validating: " + fld.name);
	//alert("Validating: " + fld.id);
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The yellow highlighted required field, " + emptyFld + ", has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "Please enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

// Radio Button Validation
// copyright Stephen Chapman, 15th Nov 2004,14th Sep 2005
// you may copy this function but please keep the copyright notice with it


function validateRadio(fld) {
    var cnt = -1;
	error = "";    
	for (var i=fld.length-1; i > -1; i--) {
		
		var theName = fld[i].name;
		//alert("field name: " + theName)
        if (fld[i].checked) {
			cnt = i;
			i = -1;
			}
    }
    if (cnt <= -1) {
		if (theName == "4_STEER_SIZE") {
			error = "Please ensure you have chosen a Steer Size.\n";
			//return error;
		}
		if (theName == "5_PRE_DEFINED_CUT_GROUP") {
			error = "Please ensure you have chosen a Pre-Defined Cut.\n";
			//return error;
		}
	}
	return error;
}
                  
-->
