// JavaScript Document

function submitForm()
 {
 	var result = validateForm(Quoteform);
	if (result == true)
	{
 		document.Quoteform.action = "colrequest.do";
		document.Quoteform.submit();
	}
 }

function validateForm(Quoteform)								
  {
  if (!validateName(Quoteform.name.value))		
    {
	Quoteform.name.focus()
	return false
	}
  if (!validateCompany(Quoteform.company.value))
    {
	Quoteform.company.focus()
	return false
	}
  if (!validateEmail(Quoteform.email.value))
    {
	Quoteform.email.focus()
	return false
	}
  if (!validateTelephoneno(Quoteform.telephoneno.value))
    {
	Quoteform.telephoneno.focus()
	return false
	}
	return true;
}

function validateName(Name)
  {
  if (isBlank(Name))
    {
	alert("Please enter your name in the field provided!")
	return false
	}
  return true
  }
  
function isBlank(testStr)
  {
  if (testStr.length == 0)										// nothing entered?
    return true
  for (var i = 0; i <= testStr.length-1; i++)					// all spaces?
    if (testStr.charAt(i) != " ")
	  return false
  return true
  }
  
function validateCompany(Company)
  {
  if (isBlank(Company))
    {
	alert("Please enter your company name in the field provided!")
	return false
	}
  return true
  }
  
function validateEmail(Email)
  {
  if (isBlank(Email))										// email address field blank?
    {
    alert("Please enter your email address in the field provided!")
    return false
    }
  var atsignPos = Email.indexOf("@", 0)				// check for @
  if (atsignPos == -1)
    {
    alert("Enter a valid email address including the @ symbol, please!")
    return false
    }
  if (Email.indexOf(".", atsignPos)  == -1)			// check for "." after "@"
    {
    alert("Enter a valid email domain name after the @ symbol, please!")	
    return false
    }
  return true
  }
  
function validateTelephoneno(Telephoneno)	
  {
  if (isBlank(Telephoneno))									// telephone number field blank?
    {
    alert("Enter your contact telephone number, please!")
    return false
    }
  for (var i = 0; i < Telephoneno.length; i++)			// telephone number data numeric?
    {
    var testChar = Telephoneno.charAt(i)
    if (testChar < "0" || testChar > "9")
      {
      alert("Please enter your telephone number using only numeric data and no spaces please!")
      return false
      }
    }
  return true
  }
  
