function PHPeventCharCode(e) {
   if (e.charCode) {
     return e.charCode;
   } else {
     var key = e.keyCode;
     var ch;
     if ((key>=96)&&(key<=105)) {
       ch = key - 48;
     } else {
       var t = String.fromCharCode(key);
       if (key == 222) t="'";
       if (key == 186) t=";";
       if (key == 188) t=",";
       if (key == 190) t=".";
       if (key == 191) t="/";
       if (e.shiftKey) {
         if (t=='`') t='~';
         if (t=='1') t='!';
         if (t=='2') t='@';
         if (t=='3') t='#';
         if (t=='4') t='$';
         if (t=='5') t='%';
         if (t=='6') t='^';
         if (t=='7') t='&';
         if (t=='8') t='*';
         if (t=='9') t='(';
         if (t=='0') t=')';
         if (t=='-') t='_';
         if (t=='=') t='+';
         if (t=="'") t='"';
         if (t=='.') t='>';
         if (t==',') t='<';
       }
       ch = t.charCodeAt(0);
     }
     return ch;
   }
}
function PHPcancelEvent (e) {
  if (document.all) {
    e.cancelBubble = true;
    e.returnValue = false;
  } else {
    e.preventDefault();
    e.stopPropagation();
  }
}
function PHPisGoodArrow(key, ch) {
  return (key==9) || (key==8) || (key==46) ||
    (key==37) || (key==39);
}
function PHPisGoodAlpha(key, ch) {
  return PHPisGoodArrow(key, ch) || (key==32)
    || ((ch>=65)&&(ch<=90)) || ((ch>=97)&&(ch<=122))
    || (ch==46) || (ch==39)
    || (ch>1000);
}
function PHPisGoodNumber(key, ch) {
  return PHPisGoodArrow(key, ch)
    || ((ch>=48)&&(ch<=57));
}
function PHPisGoodHexNumber(key, ch) {
  return PHPisGoodArrow(key, ch)
    || ((ch>=48)&&(ch<=57)) ||
    ((ch >= 97) && (ch <= 102)) ||
    ((ch >= 65) && (ch <= 70));
}
function PHPisGoodExtra(key, ch) {
  return ch == 32;
}
function PHPisGoodAlphaNumber(key, ch) {
  return PHPisGoodAlpha(key, ch) ||
    PHPisGoodNumber(key, ch) ||
    PHPisGoodExtra(key, ch);
}
function PHPallowAlphas(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodAlpha(key, ch))
     PHPcancelEvent(e);
}
function PHPallowNumbers(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodNumber(key, ch))
     PHPcancelEvent(e);
}
function PHPallowHexNumbers(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodHexNumber(key, ch))
     PHPcancelEvent(e);
}
function PHPallowAlphaNumbers(e, dn)
{
   if (dn == (!document.all)) return;
   if (e.ctrlKey) return;
   var key = e.keyCode;
   var ch = PHPeventCharCode(e);
   if (!PHPisGoodAlphaNumber(key, ch))
     PHPcancelEvent(e);
}
function PHPtrim(s) {
  var re = /^ +| +$/g;
  return s.replace(re, '');
}
function PHPvalidateJump(obj, e, pat, ctrl) {
  var regEx = RegExp(pat);
  var val = PHPtrim(obj.value);
  if ((e.keyCode != 8) && (e.keyCode != 9) && (e.keyCode != 16)
     && (e.keyCode != 37) && (e.keyCode != 39) && (e.keyCode != 46)
     && val.match(regEx))
  {
    document.getElementById(ctrl).focus();
  }
}
function PHPverifyExtra(testRes, fld, val, pat, fldName, mes) {
  var obj = document.getElementById(fld);
  var regEx = RegExp(pat);
  if (val.match(regEx)) {
    var mesEx = RegExp('("")');
    var addMes = mes.replace(mesEx, '"'+fldName+'"');
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += addMes;
    if (!(testRes.toFocus))
      testRes.toFocus = obj;
  }
}
function PHPverifyRequired(testRes, fld, fldName, opt, validFmt,
  valuePat, valueRepl, minLen, maxLen, minVal, maxVal)
{
//alert('hi');
  var obj = document.getElementById(fld);
  //alert(document.getElementById(fld));
  var rawVal = PHPtrim(obj.value);
  var val;
  if (valuePat != '') {
    var regEx = RegExp(valuePat);
    val = rawVal.replace(regEx, valueRepl);
  } else {
    val = rawVal;
  }
  if (val != '')
    testRes.hasData = true;
  var addMes = '';
  if (opt && (val == '')) return;
  if (val == '') {
    addMes = fldName+' is required';
  }
  if ((addMes == '') && (validFmt != '')) {
    var regEx = RegExp(validFmt);
    if (!rawVal.match(regEx))
      addMes = 'Formatting of '+fldName+' is invalid';
  }
  if ((addMes == '') && (minLen > 0)) {
    if (val.length < minLen) {
      if (minLen == maxLen) {
        addMes = fldName+' should be exactly '+minLen+' symbols long';
      } else {
        addMes = fldName+' should be at least '+minLen+' symbols long';
      }
    }
  }
  if ((addMes == '') && (maxLen > 0)) {
    if (val.length > maxLen) {
      if (minLen == maxLen) {
        addMes = fldName+' should be exactly '+maxLen+' symbols long';
      } else {
        addMes = fldName+' should be '+maxLen+' symbols long or shorter';
      }
    }
  }
  if ((addMes == '') && (minVal != -1)) {
    if (val < minVal) {
      if (maxVal != -1) {
        addMes = fldName+' should be between '+minVal+' and '+maxVal;
      } else {
        addMes = fldName+' should be at least '+minVal;
      }
    }
  }
  if ((addMes == '') && (maxVal != -1)) {
    if (val > maxVal) {
      if (minVal != -1) {
        addMes = fldName+' should be between '+minVal+' and '+maxVal;
      } else {
        addMes = fldName+' should be less then '+maxVal;
      }
    }
  }
  if (addMes != '') {
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += addMes;
    if (!(testRes.toFocus))
      testRes.toFocus = obj;
    return '';
  }
  return val;
}
function PHPverifySelection (testRes, fldName, sels) {
  var good = false;
  var i;
  var f = 0;
  for (i = 0; i<sels.length; i++) {
    if (!f) f = document.getElementById(sels[i]);
    if (document.getElementById(sels[i]).checked)
      good = true;
  }
  if (good)
    testRes.hasData = true;
  if ((!good) && f) {
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += 'Please specify if '+fldName;
    if (!(testRes.toFocus))
      testRes.toFocus = f;
  }
}
function PHPverifyList (testRes, fld, fldName, bad) {
  var f = document.getElementById(fld);
  if ((f.selectedIndex < 0) || (f.options[f.selectedIndex].value == bad)) {
    if (testRes.mes != '')
      testRes.mes += '\n';
    testRes.mes += 'Please select '+fldName;
    if (!(testRes.toFocus))
      testRes.toFocus = f;
  } else
    testRes.hasData = true;
}
function PHPvalidateForm(e, emptyOK) {
  var testRes = new Object();
  testRes.mes = '';
  testRes.toFocus = 0;
  testRes.hasData = false;
  var doTest;
//  alert('HI');
PHPverifyRequired(testRes, 'receiveby', 'Date proposal must be received by', false, '', '', '', 0, 0, -1, -1);  
PHPverifyRequired(testRes, 'firstname', 'First Name', false, '', '', '', 0, 0, -1, -1);  
PHPverifyRequired(testRes, 'lastname', 'Last Name', false, '', '', '', 0, 0, -1, -1);  
PHPverifyRequired(testRes, 'email', 'Email', false, '^[^ @]+@{1}[^ @]+$', '', '', 0, 0, -1, -1);


var theVal=PHPverifyRequired(testRes, 'phone[1]', 'Phone Area Code', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'phone[1]', theVal, '411|900|911|^0|^1', 'Phone Area Code', '"" is invalid');
} 
var theVal=PHPverifyRequired(testRes, 'phone[2]', 'Phone Prefix', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'phone[2]', theVal, '411|900|911|^0|^1', 'Phone Prefix', '"" is invalid');
} 
var theVal=PHPverifyRequired(testRes, 'phone[3]', 'Phone Number', false, '', '', '', 4, 4, -1, -1);
PHPverifyList(testRes, 'eventtype', 'Type of Event / Meeting - Function', '00'); 
PHPverifyRequired(testRes, 'arrivaldate', 'Arrival Date', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'departuredate', 'Departure Date', false, '', '', '', 0, 0, -1, -1);


/* 
PHPverifyRequired(testRes, 'hotel', 'Hotel', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'zurl', 'URL', false, '', '', '', 0, 0, -1, -1);
PHPverifyList(testRes, 'rm', 'Relationship Manager', '00');  
PHPverifyRequired(testRes, 'intent', 'Intent of landing page', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'theme', 'Theme of landing page', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'taraud', 'Target audience', false, '', '', '', 0, 0, -1, -1);
PHPverifyList(testRes, 'ctaction', 'Require a call to action button', '00');  
PHPverifyRequired(testRes, 'booklink', 'General booking link', false, '', '', '', 0, 0, -1, -1);
 
PHPverifyList(testRes, 'ownrent', 'Do You Own or Rent', '00');  
PHPverifyList(testRes, 'hometime', 'Time Residing', '00');
PHPverifyRequired(testRes, 'homepay', 'Home Payment', false, '', '', '', 0, 0, -1, -1);
   
PHPverifyList(testRes, 'emplytime', 'Time Employed', '00');


var theVal=PHPverifyRequired(testRes, 'wp2', 'Work Phone Prefix', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'wp2', theVal, '000|411|555|911|976|^1', ' Work Phone Prefix', '"" is invalid');
}
PHPverifyRequired(testRes, 'wp3', 'Work Phone Number', false, '', '', '', 4, 4, -1, -1);
PHPverifyRequired(testRes, 'emplytitle', 'Job Title', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'moninc', 'Monthly Income', false, '', '', '', 0, 0, 1200, -1);
PHPverifyList(testRes, 'bmonth', 'Birth Month', '00');
PHPverifyList(testRes, 'bday', 'Birth Day', '00');
PHPverifyList(testRes, 'byear', 'Birth Year', '00');
PHPverifyRequired(testRes, 'ssn1', 'SSN', false, '', '', '', 3, 3, -1, -1);
PHPverifyRequired(testRes, 'ssn2', 'SSN', false, '', '', '', 2, 2, -1, -1);
PHPverifyRequired(testRes, 'ssn3', 'SSN', false, '', '', '', 4, 4, -1, -1);
PHPverifyRequired(testRes, 'firstname', 'First Name', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'lastname', 'Last Name', false, '', '', '', 0, 0, -1, -1);
PHPverifyRequired(testRes, 'zipcode', 'ZIP Code', false, '', '', '', 5, 5, -1, -1);
PHPverifyRequired(testRes, 'city', 'City', false, '', '', '', 0, 0, -1, -1);
PHPverifyList(testRes, 'state', 'State', '00');
var theVal=PHPverifyRequired(testRes, 'hm1', 'Phone Area Code', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'hm1', theVal, '411|900|911|^0|^1', 'Phone Area Code', '"" is invalid');
}
var theVal=PHPverifyRequired(testRes, 'hm2', 'Phone Prefix', false, '', '', '', 3, 3, -1, -1);
if (theVal) {
  PHPverifyExtra(testRes, 'hm2', theVal, '000|411|555|911|976|^1', 'Phone Prefix', '"" is invalid');
}

PHPverifyRequired(testRes, 'hm3', 'Phone Number', false, '', '', '', 4, 4, -1, -1);
PHPverifyList(testRes, 'ctime', 'Contact Prefrence', '00');
*/
  if (document.all) {
    e.cancelBubble = true;
    e.returnValue = false;
  } else {
    e.preventDefault();
    e.stopPropagation();
  }
  if (testRes.toFocus && (testRes.hasData || !emptyOK)) {
    window.alert(testRes.mes);
    testRes.toFocus.focus();
	} else {
//	document.forms[0].Submit.value="+++Please Wait+++";
//	document.forms[0].Submit.disabled=true;
    document.contactform.submit();
  }
}