
function formatFloat(src, pos)
{
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}
function chkNum(strString)
{

	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function chkNum2(strString)
{

	var strValidChars = "0123456789.()+ ";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	
	// test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}
function emailCheck (emailStr) {

  var checkTLD=1;
  var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
  var emailPat=/^(.+)@(.+)$/;
  var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  var validChars="\[^\\s" + specialChars + "\]";
  var quotedUser="(\"[^\"]*\")";
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
  var atom=validChars + '+';
  var word="(" + atom + "|" + quotedUser + ")";
  var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
  var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
  var matchArray=emailStr.match(emailPat);

  if (matchArray==null) {
    return false;
  }

  var user=matchArray[1];
  var domain=matchArray[2];

  for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {
      return false;
    }
  }

  for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {
      return false;
    }
  }

  if (user.match(userPat)==null) {
    return false;
  }

  var IPArray=domain.match(ipDomainPat);
  if (IPArray!=null) {

    for (var i=1;i<=4;i++) {
     if (IPArray[i]>255) {
       return false;
     }
   }
  return true;
  }

  var atomPat=new RegExp("^" + atom + "$");
  var domArr=domain.split(".");
  var len=domArr.length;

  for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat)==-1) {
      return false;
    }
  }

  if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
    return false;
  }

  if (len<2) {
    return false;
  }
  return true;
}


function submit_form(){

	var f = document.submitForm;
	
	comp_name = f.comp_name.value;
	client_name = f.client_name.value;
	subject = f.subject.value;
	phone = f.phone.value;
	email = f.email.value;
	content = f.content.value;
	checkbox1 = f.checkbox1.checked;
	checkbox2 = f.checkbox2.checked;
	checkbox3 = f.checkbox3.checked;
	checkbox4 = f.checkbox4.checked;
	checkbox5 = f.checkbox5.checked;
	checkbox6 = f.checkbox6.checked;
	checkbox7 = f.checkbox7.checked;

	if (client_name == ""){
			alert("Please enter your name.");
			return;
	}
		if (email == ""){
			alert("Please enter your email address. ");
			return;
	}
	if (!emailCheck(email)){
			alert("The email address is invalid.");
			return;
	}
	if (comp_name == ""){
			alert("Please enter your company name. ");
			return;
	}

	if (phone == ""){
			alert("Please enter your telephone number. ");
			return;
	}
		if (!chkNum2(phone)){
			alert("The telephone number is invalid.");
			return;
	}
	if (subject == ""){
			alert("Please select the subject.");
			return;
	}


	if (content == ""){
			alert("Please enter enquiry content.");
			return;
	}

	if (checkbox1 == false && checkbox2 == false && checkbox3 == false && checkbox4 == false && checkbox5 == false && checkbox6 == false && checkbox7 == false){
			alert("Please state which channel(s) you learn about empower.");
			return;
	}
	document.submitForm.submit();

	//return false;

}
