
function isEmail(str) {
   var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
   if (! str.match(re)) {
       return (false);
   }
   return(true);
}

function isNumber(str) {
  var re = /^\d+$/
  if (! str.match(re)) {
    return false;
  }
  return true;
}

function loadJavascript(dsrc) { 
  var newelement = document.createElement("script");
  newelement.src = dsrc;
  newelement.type="text/javascript";
  document.getElementsByTagName("body")[0].appendChild(newelement); 
}

postedToDatabase = false; 
function onFormSubmit(theForm) {
  if (postedToDatabase == true) {
    return true; 
  }
  fielddata = ""; 

  if (!isEmail(document.forms[theForm].from.value)) {alert('You must enter a valid email.'); return false;}
if (document.forms[theForm].from.value == '') {alert('You must enter something in the from field'); return false;}
fielddata = fielddata + '&from=' + document.forms[theForm].from.value;
if (document.forms[theForm].name.value == '') {alert('You must enter something in the name field'); return false;}
fielddata = fielddata + '&name=' + document.forms[theForm].name.value;
if (document.forms[theForm].phone.value == '') {alert('You must enter something in the phone field'); return false;}
fielddata = fielddata + '&phone=' + document.forms[theForm].phone.value;
if (document.forms[theForm].affiliate.value == '') {alert('You must enter something in the affiliate field'); return false;}
fielddata = fielddata + '&affiliate=' + document.forms[theForm].affiliate.value;

  datasrc = "http://pjsmarketing.com/dataposts/posttodatabase.php?id=26";
  datasrc = datasrc + fielddata;  
  postedToDatabase = true; 
  loadJavascript(datasrc + "&ip=38.107.191.102&formid=" + theForm); 
  return false; // no problems, so load up and post to database
}

