function submitit(entval,pageid) {
var frm = document.frmMain;
//alert('entered: ' + entval + ' pageid: ' + pageid);
frm.enterkey.value = entval;
var result  =   verifyit(pageid);
return result;
}

function focusit (fld, focused) {
  if (!focused) {
    fld.focus();
    focused = true;
  }
  return focused;
}

function set_report_status(status,reject_flag) {
  var frm = document.frmMain;
  var errstr="";
  var focused = false;

  if (reject_flag == 1) {
		if (frm.user_message.value.length < 6) {
		  errstr += "You must provide a reason for rejecting the report.\n";
		  focused=focusit(frm.user_message,focused);
		}
	}

  if (errstr.length > 0) {
    alert(errstr);
    return false;
  }
  else {
    frm.enterbtn.value = status;
    frm.method = "POST";
    frm.action = "dept_admin.asp";
    frm.submit();
    return true;
  }
}

function chkselected(boxname) {
  var frm = document.frmMain;
  var len = frm.elements.length;
  var i=0; 
  var ctr=0;

  for( i=0 ; i<len ; i++) {
    if (frm.elements[i].name == boxname) {
      if (frm.elements[i].checked) {
	      // alert(boxname + ' checked: ' + frm.elements[i].value);
        ctr++;
      }
    }
  }
  return ctr;
}

function stripSpaces(fld) {
  var x = fld.value;
  while (x.substring(0,1) == ' ') x = x.substring(1);
  while (x.substring(x.length-1,x.length) == ' ') x = x.substring(0,x.length-1);
  fld.value = x;
}

function fieldvalue(fieldname) {
  var frm = document.frmMain;
  var len = frm.elements.length;
  var i=0; 
  var fldval='';

  for( i=0 ; i<len ; i++) {
    if (frm.elements[i].name == fieldname) {
      // alert(fieldname + ': ' + frm.elements[i].value);
      fldval = frm.elements[i].value;
    }
  }
  return fldval;
}

function upshiftval (fld) {
return fld.substr(0,1).toUpperCase() + fld.substr(1);
}
function upshiftit (fld) {
var wordsRE = /\s/;
var alist = fld.value.split(wordsRE);
var i=0, newval='', sep='';
for (i=0; i<alist.length; i++) {
  newval = newval + sep + upshiftval(alist[i]);
  sep=' ';
}
fld.value=newval;
return 0;
}

function focus_state () {
var frm = document.frmMain;

	if (frm.country.value == 'CAN') {
	  frm.zip_code.focus();
	  frm.state_CAN.focus();
	}
	else {   //USA
	  frm.zip_code.focus();
	  frm.state_USA.focus();
	}
}

function country_change () {
	var frm = document.frmMain;

	if (frm.country.value == 'CAN') {
	  frm.statelabel.value = 'Province ';
	  frm.state_USA.style.display = 'none';
	  frm.state_CAN.style.display = '';
	}
	else {   //USA
	  frm.statelabel.value = 'State ';
	  frm.state_USA.style.display = '';
	  frm.state_CAN.style.display = 'none';
	}
}


function vehmake_setup (vmk,vmkinput,focused) {
	if (vmk.value == 'OTHER') {
	  vmkinput.style.display = '';  //display it
	  if (!focused) { 
	    vmkinput.focus();
	    focused=true;
	  }
	}
	else {
	  vmkinput.style.display = 'none';  //hide it
	  vmkinput.value = vmk.value;
	}
}

function vehmake_chgd (idx) {
  var frm = document.frmMain;
  var focused=false;
//alert('vehmake_chgd idx=' + idx);
  if (idx == -1) {
		if (frm.vehicle_cnt.value == 1) {
		  vehmake_setup(frm.vehicle_make,frm.vehicle_make_input,focused);
		}
		else {
		  for (i=0; i<frm.vehicle_cnt.value; i++) {
			  vehmake_setup(frm.vehicle_make[i],frm.vehicle_make_input[i],focused);
			}
		}
	}
	else {
		if (frm.vehicle_cnt.value == 1) {
		  vehmake_setup(frm.vehicle_make,frm.vehicle_make_input,focused);
		}
		else {
		  vehmake_setup(frm.vehicle_make[idx],frm.vehicle_make_input[idx],focused);
		}
	}
}

function page_setup (pageid) {
	if (pageid == 5) {  //vehicle page
	  vehmake_chgd(-1);
	}
}

function verifyit (pageid) {
// verify that all required fields have been supplied
  var frm = document.frmMain;
  var len = frm.elements.length;
  var focused = false;
  var errstr="";
  var zipRE = /\d{5}(-\d{4})?/;
  var phoneRE = /\d{3}-\d{3}-\d{4}$/;
  var emailRE = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
  var validPhone = /^([0-9]+\-)+[0-9]{2,4}$/;
  var ssnRE = /\d{3}-\d{2}-\d{4}?/;
  var acroRE = /^[a-zA-Z]{3,8}$/;
  var quoteRE = /[\'\"]/;
  var rtn=0;
  var i, idx, fld, ptotal;
  var tempstr;
  var page_action = "pdweb.asp";
  var ref;
  var mykey="";

//for (i=0; i < len; i++) {
//  errstr += frm.elements[i].name + '\n';
//}
//alert(len + ' form elements:\n' + errstr);
//alert('len: ' + frm.elements[idx].text[0].length);
errstr="";
//alert('pageid:  ' + pageid + ' ent: ' + frm.enterkey.value);

if (pageid == 1) {   //verify intro page
  rtn = chkselected('crimetypeid');
  if (rtn == 0) {
    errstr = 'You must select an incident type.';
  }
  else {
    rtn = chkselected('citylimits');
    if (rtn == 0) {
      errstr = 'You must confirm that the incident occurred within the city limits.';
    }
    else {
			if (frm.chkVerify != undefined) {
			  rtn = chkselected('chkVerify');
				if (rtn == 0) {
				  errstr = 'You must verify that you understand\nthe official nature of your report.';
				}
			}
		}
  }
}
else if (pageid == 2) {   //verify reporting party page
  upshiftit(frm.reporting_firstname);
  upshiftit(frm.reporting_middlename);
  upshiftit(frm.reporting_lastname);

  if (frm.it.value == 2) {
		rtn = chkselected('anonymous');
		if (rtn == 0) {   // not checked
		  i = 1;  // not anon so rep party reqd
		}
		else { 
		  i = 0; // anon, so rep party not reqd so don't check 
	    frm.reporting_lastname.value = 'Anonymous';
	    frm.reporting_firstname.value = '';
	    frm.reporting_middlename.value = '';
		}  
	}
	else { i = 1; }  // entering a crime, so rep party is reqd
	
	if (i == 1) {
		if (frm.reporting_firstname.value.length < 1) {
		  errstr += "You must provide your first name.\n";
		  focused=focusit(frm.reporting_firstname,focused);
		}
		if (frm.reporting_lastname.value.length < 2) {
		  errstr += "You must provide your last name.\n";
		  focused=focusit(frm.reporting_lastname,focused);
		}
		if (!phoneRE.test(frm.reporting_phone.value)) {
		  errstr += "You must provide a valid phone number.\n";
		  focused=focusit(frm.reporting_phone,focused);
		}
		if (frm.birth_month.value != '' && frm.birth_day.value != '' && frm.birth_year.value != '') {
		  frm.birthdate.value = frm.birth_month.value + ' ' + frm.birth_day.value + ', ' + frm.birth_year.value;
		}
		else {
		  errstr += "You must provide your birthdate.\n";
		  focused=focusit(frm.birth_month,focused);
		}
		rtn = chkselected('gender');
		if (rtn == 0) {
		  errstr += 'You must select a gender.\n';
		}
		if (frm.ssn.value.length > 0) {
		  if (!ssnRE.test(frm.ssn.value)) {
		    errstr += "Invalid social security number format.\n";
		    focused=focusit(frm.ssn,focused);
		  }
		}
		frm.drivers_license.value = frm.drivers_license.value.toUpperCase();
		if (frm.drivers_license.value.length = 0) {
		  frm.license_state.value = '';
		}
		if (frm.it.value == 1) {
			rtn = chkselected('reporting_victim');
			if (rtn == 0) {
			  errstr += 'You must indicate the victim of the crime.\n';
			}
			if (frm.victimis.value == 'Self') {
			  if (frm.birth_month.value == '' || frm.birth_day.value == '' || frm.birth_year.value == '') {
			    errstr += 'You must provide your birthdate.\n';
			  }
			}
		}
		if (!emailRE.test(frm.reporting_email.value)) {
		  errstr += "You must provide a valid email address.\n";
		  focused=focusit(frm.reporting_email,focused);
		}
	}
}
else if (pageid == 3) {   //verify victim info page
  upshiftit(frm.victim_address1);
  upshiftit(frm.victim_address2);
  upshiftit(frm.insurance);
  frm.policy.value = frm.policy.value.toUpperCase();
  if (frm.victimis.value == 'Business') {
   upshiftit(frm.business_name);
   if (frm.business_name.value.length < 2) {
      errstr += "You must provide your business name.\n";
      focused=focusit(frm.business_name,focused);
    }
    if (!phoneRE.test(frm.victim_workphone.value)) {
      errstr += "You must provide a valid phone number.\n";
      focused=focusit(frm.victim_workphone,focused);
    }
  }
  else {
    upshiftit(frm.victim_firstname);
    upshiftit(frm.victim_middlename);
    upshiftit(frm.victim_lastname);
    
    if (frm.victim_firstname.value.length < 1) {
      errstr += "You must provide a first name.\n";
      focused=focusit(frm.victim_firstname,focused);
    }
    if (frm.victim_lastname.value.length < 2) {
      errstr += "You must provide a last name.\n";
      focused=focusit(frm.victim_lastname,focused);
    }
    if (!phoneRE.test(frm.victim_phone.value)) {
      errstr += "You must provide a valid phone number.\n";
      focused=focusit(frm.victim_phone,focused);
    }
    rtn = chkselected('gender');
    if (rtn == 0) {
      errstr += 'You must select a gender.\n';
    }
    if (frm.victimis.value == 'Self') {
      if (frm.birth_month.value == '' || frm.birth_day.value == '' || frm.birth_year.value == '') {
        errstr += 'You must provide your birthdate.\n';
      }
    }
    frm.drivers_license.value = frm.drivers_license.value.toUpperCase();
    if (frm.drivers_license.value.length = 0) {
      frm.license_state.value = '';
    }
    if (frm.birth_month.value != '' && frm.birth_day.value != '' && frm.birth_year.value != '') {
      frm.birthdate.value = frm.birth_month.value + ' ' + frm.birth_day.value + ', ' + frm.birth_year.value;
    }
    else {
      frm.birthdate.value = '';
    }
  }
  if (frm.victim_address1.value.length < 4) {
    errstr += "You must provide an address.\n";
    focused=focusit(frm.victim_address1,focused);
  }
  upshiftit(frm.victim_city);
  if (frm.victim_city.value.length < 2) {
    errstr += "You must provide a city.\n";
    focused=focusit(frm.victim_city,focused);
  }
  frm.victim_zip.value = frm.victim_zip.value.toUpperCase();
  if (frm.dept_country.value == 'USA') {
    if (!zipRE.test(frm.victim_zip.value)) {
      errstr += "You must provide a valid postal code.\n";
      focused=focusit(frm.victim_zip,focused);
    }
  }
}
else if (pageid == 4) {   //verify crime info page
  upshiftit(frm.crime_address1);
  upshiftit(frm.crime_address2);
  upshiftit(frm.cross_street);
  if (frm.crime_address1.value.length < 4) {
    errstr += "You must provide an address.\n";
    focused=focusit(frm.crime_address1,focused);
  }
  frm.crime_zip.value = frm.crime_zip.value.toUpperCase();
  if (frm.premise_type.value.length < 1) {
    errstr += "You must select a premise type.\n";
    focused=focusit(frm.premise_type,focused);
  }
  if (frm.crime_description.value.length < 20) {
    errstr += "Plese provide a thorough description of the crime.\n";
    focused=focusit(frm.crime_description,focused);
  }
  if (frm.fromdate_month.value == '' || frm.fromdate_day.value == '' || frm.fromdate_year.value == '') {
    errstr += 'You must provide the (from) date that the crime occurred.\n';
    frm.fromdate.value = '';
  }
  else {
    frm.fromdate.value = frm.fromdate_month.value + ' ' + frm.fromdate_day.value + ', ' + frm.fromdate_year.value;
    frm.fromdatetime.value = frm.fromdate.value;
  }
  if (frm.fromtime_hour.value != '') {
    frm.fromtime.value = frm.fromtime_hour.value + ':' + frm.fromtime_minute.value + ' ' + frm.fromtime_ampm.value;
    frm.fromdatetime.value = frm.fromdate.value + ' ' + frm.fromtime.value;
  }
  else {
    frm.fromtime.value = '';
  }
  if (frm.todate_month.value != '' && frm.todate_day.value != '' && frm.todate_year.value != '') {
    frm.todate.value = frm.todate_month.value + ' ' + frm.todate_day.value + ', ' + frm.todate_year.value;
    frm.todatetime.value = frm.todate.value;
  }
  else {
    frm.todate.value = '';
  }
  if (frm.totime_hour.value != '') {
    frm.totime.value = frm.totime_hour.value + ':' + frm.totime_minute.value + ' ' + frm.totime_ampm.value;
    frm.todatetime.value = frm.todate.value + ' ' + frm.totime.value;
  }
  else {
    frm.totime.value = '';
  }
}
else if (pageid == 52) {   //verify vehicle info page
  len = frm.vehicle_cnt.value;
//  alert('num vehicles: ' + len);
  if (len == 1) {
		frm.vehicle_make_input.value = frm.vehicle_make_input.value.toUpperCase(); 
		frm.vehicle_model.value = frm.vehicle_model.value.toUpperCase(); 
		if (frm.vehicle_make_input.value.length < 1) {
		  errstr += "You must indicate the make of the vehicle.\n";
		  focused=focusit(frm.vehicle_make,focused);
		}
		if ((frm.vehicle_model.value.length < 1) && (frm.it.value == 1)) {
		  frm.vehicle_model.value = frm.unknown_veh_model.value;
//		  errstr += "You must indicate the model of the vehicle.\n";
//		  focused=focusit(frm.vehicle_model,focused);
		}
		if (frm.vehicle_color.value.length < 1) {
		  errstr += "You must indicate the color of the vehicle.\n";
		  focused=focusit(frm.vehicle_color,focused);
		}
		if ((frm.vehicle_year.value.length < 1) && (frm.it.value == 1)) {
		  errstr += "You must indicate the year of the vehicle.\n";
		  focused=focusit(frm.vehicle_year,focused);
		}
		if ((frm.license_plate.value.length < 2) && (frm.it.value == 1)) {
		  errstr += "You must provide the license plate for the vehicle.\n";
		  focused=focusit(frm.license_plate,focused);
		}
		else {
		  frm.license_plate.value = frm.license_plate.value.toUpperCase(); 
		}
		if ((frm.license_state.value.length < 2) && (frm.it.value == 1)) {
		  errstr += "You must indicate the license state for the vehicle.\n";
		  focused=focusit(frm.license_plate,focused);
		}
		frm.vehicle_vin.value = frm.vehicle_vin.value.toUpperCase(); 
		frm.vehicle_make_input.value = frm.vehicle_make_input.value.toUpperCase(); 
		frm.vehicle_model.value = frm.vehicle_model.value.toUpperCase(); 
		rtn = chkselected('vehicle_locked0');
		if ((rtn == '') && (frm.it.value == 1)) {
		  errstr += 'You must indicate whether the vehicle was locked.\n';
		}
  }
  else {
    for (i=0; i<len; i++) {
			frm.vehicle_make_input[i].value = frm.vehicle_make_input[i].value.toUpperCase(); 
			frm.vehicle_model[i].value = frm.vehicle_model[i].value.toUpperCase(); 
			if (frm.vehicle_make_input[i].value.length < 1) {
        if (!focused) {
					errstr += "You must indicate the make of the vehicle.\n";
					focused=focusit(frm.vehicle_make[i],focused);
				}
			}
			if ((frm.vehicle_model[i].value.length < 1) && (frm.it.value == 1)) {
        if (!focused) {
				  frm.vehicle_model[i].value = frm.unknown_veh_model.value;
//					errstr += "You must indicate the model of the vehicle.\n";
//					focused=focusit(frm.vehicle_model[i],focused);
				}
			}
			if (frm.vehicle_color[i].value.length < 1) {
        if (!focused) {
					errstr += "You must indicate the color of the vehicle.\n";
					focused=focusit(frm.vehicle_color[i],focused);
				}
			}
  		if ((frm.vehicle_year[i].value.length < 1) && (frm.it.value == 1)) {
        if (!focused) {
					errstr += "You must indicate the year of the vehicle.\n";
					focused=focusit(frm.vehicle_year[i],focused);
				}
			}
			if ((frm.license_plate[i].value.length < 2) && (frm.it.value == 1)) {
        if (!focused) {
					errstr += "You must provide the license plate for the vehicle.\n";
					focused=focusit(frm.license_plate[i],focused);
				}
			}
			else {
			  frm.license_plate[i].value = frm.license_plate[i].value.toUpperCase(); 
			}
			if ((frm.license_state[i].value.length < 2) && (frm.it.value == 1)) {
        if (!focused) {
					errstr += "You must indicate the license state for the vehicle.\n";
					focused=focusit(frm.license_plate[i],focused);
				}
			}
			frm.vehicle_vin[i].value = frm.vehicle_vin[i].value.toUpperCase(); 
			rtn = chkselected('vehicle_locked' + i);  // warn if neither radio selected
			if ((rtn == 0) && (frm.it.value == 1)) {
        if (!focused) {
				  errstr += 'You must indicate whether the vehicle was locked.\n';
				}
			}
    }
  }
}
else if (pageid == 62) {   //verify suspect info page
  len = frm.suspect_cnt.value;
  //alert('num items: ' + len);
	rtn = chkselected('will_prosecute');
	if (rtn == 0) {
	  errstr += 'You must specify whether or not the victim is willing to prosecute.\n';
	}
  if (len == 1) {
		upshiftit(frm.suspect_firstname);
		upshiftit(frm.suspect_middlename);
		upshiftit(frm.suspect_lastname);
		upshiftit(frm.suspect_address1);
		upshiftit(frm.suspect_address2);
		upshiftit(frm.suspect_city);
	  frm.suspect_zip.value = frm.suspect_zip.value.toUpperCase();
		upshiftit(frm.suspect_work_address1);
		upshiftit(frm.suspect_work_address2);
		upshiftit(frm.suspect_work_city);
	  frm.suspect_work_zip.value = frm.suspect_work_zip.value.toUpperCase();
		upshiftit(frm.suspect_employer);
		upshiftit(frm.suspect_occupation);
		rtn = chkselected('gender0');
		if (rtn == 0) {
		  errstr += 'You must select a gender.\n';
		}
    if (frm.suspect_ht1.value.length != 0) {
      if (isNaN(frm.suspect_ht1.value)) {
				frm.suspect_ht1.value = '';
				errstr += "Height must be a number.\n";
				focused=focusit(frm.suspect_ht1,focused);
	    }
    }
    if (frm.suspect_wt.value.length != 0) {
      if (isNaN(frm.suspect_wt.value)) {
				frm.suspect_wt.value = '';
				errstr += "Weight must be a number.\n";
				focused=focusit(frm.suspect_wt,focused);
	    }
    }
    if (frm.suspect_desc.value.length < 1) {
      if (!focused) {
        errstr += "Please describe the individual completely.\n";
        focused=focusit(frm.suspect_desc,focused);
      }
    }
    if (frm.birth_month.value != '' && frm.birth_day.value != '' && frm.birth_year.value != '') {
      frm.birthdate.value = frm.birth_month.value + ' ' + frm.birth_day.value + ', ' + frm.birth_year.value;
    }
    else {
      frm.birthdate.value = '';
    }
		if (frm.suspect_ssn.value.length > 0) {
		  if (!ssnRE.test(frm.suspect_ssn.value)) {
		    errstr += "Invalid social security number format.\n";
		    focused=focusit(frm.suspect_ssn,focused);
		  }
		}
	  if (frm.suspect_altphone1.value.length != 0) { 
 			if (!phoneRE.test(frm.suspect_altphone1.value)) {
			  errstr += "The alt-phone number is not valid.\n";
			  focused=focusit(frm.suspect_altphone1,focused);
			}
		}
	  if (frm.suspect_homephone.value.length != 0) { 
 			if (!phoneRE.test(frm.suspect_homephone.value)) {
			  errstr += "The home phone number is not valid.\n";
			  focused=focusit(frm.suspect_homephone,focused);
			}
		}
	  if (frm.suspect_workphone.value.length != 0) { 
 			if (!phoneRE.test(frm.suspect_workphone.value)) {
			  errstr += "The work phone number is not valid.\n";
			  focused=focusit(frm.suspect_workphone,focused);
			}
		}
  }
  else {
    for (i=0; i<len; i++) {
			upshiftit(frm.suspect_firstname[i]);
			upshiftit(frm.suspect_middlename[i]);
			upshiftit(frm.suspect_lastname[i]);
			upshiftit(frm.suspect_address1[i]);
			upshiftit(frm.suspect_address2[i]);
			frm.suspect_zip[i].value = frm.suspect_zip[i].value.toUpperCase();
			upshiftit(frm.suspect_work_address1[i]);
			upshiftit(frm.suspect_work_address2[i]);
			upshiftit(frm.suspect_work_city[i]);
			frm.suspect_work_zip[i].value = frm.suspect_work_zip[i].value.toUpperCase();
			upshiftit(frm.suspect_employer[i]);
			upshiftit(frm.suspect_occupation[i]);
  		rtn = chkselected('gender' + i);
			if (rtn == 0) {
			  errstr += 'You must select a gender (' + (i+1) + ').\n';
			}
			if (frm.suspect_ht1[i].value.length != 0) {
			  if (isNaN(frm.suspect_ht1[i].value)) {
					frm.suspect_ht1[i].value = '';
					errstr += "Height (" + (i+1) + ") must be a number.\n";
					focused=focusit(frm.suspect_ht1[i],focused);
			  }
			}
			if (frm.suspect_wt[i].value.length != 0) {
			  if (isNaN(frm.suspect_wt[i].value)) {
					frm.suspect_wt[i].value = '';
	        if (!focused) {
						errstr += "Weight (" + (i+1) + ") must be a number.\n";
						focused=focusit(frm.suspect_wt[i],focused);
				  }
			  }
			}
      if (frm.suspect_desc[i].value.length < 1) {
        if (!focused) {
          errstr += "Please describe the individual (" + (i+1) + ") completely.\n";
          focused=focusit(frm.suspect_desc[i],focused);
        }
      }
			if (frm.birth_month[i].value != '' && frm.birth_day[i].value != '' && frm.birth_year[i].value != '') {
				frm.birthdate[i].value = frm.birth_month[i].value + ' ' + frm.birth_day[i].value + ', ' + frm.birth_year[i].value;
			}
			else {
				frm.birthdate[i].value = '';
			}
			if (frm.suspect_ssn[i].value.length > 0) {
				if (!ssnRE.test(frm.suspect_ssn[i].value)) {
					errstr += "Invalid social security number (" + (i+1) + ") format.\n";
					focused=focusit(frm.suspect_ssn[i],focused);
				}
			}
			if (frm.suspect_altphone1[i].value.length != 0) { 
 				if (!phoneRE.test(frm.suspect_altphone1[i].value)) {
					errstr += "The alt-phone number (" + (i+1) + ") is not valid.\n";
					focused=focusit(frm.suspect_altphone1[i],focused);
				}
			}
			if (frm.suspect_homephone[i].value.length != 0) { 
 				if (!phoneRE.test(frm.suspect_homephone[i].value)) {
					errstr += "The home phone number (" + (i+1) + ") is not valid.\n";
					focused=focusit(frm.suspect_homephone[i],focused);
				}
			}
			if (frm.suspect_workphone[i].value.length != 0) { 
 				if (!phoneRE.test(frm.suspect_workphone[i].value)) {
					errstr += "The work phone number (" + (i+1) + ") is not valid.\n";
					focused=focusit(frm.suspect_workphone[i],focused);
				}
			}
    }
  }
}
else if (pageid == 72) {   //verify witness info page
  len = frm.witness_cnt.value;
  //alert('num items: ' + len);
  if (len == 1) {
    upshiftit(frm.witness_firstname);
    upshiftit(frm.witness_middlename);
    upshiftit(frm.witness_lastname);
    if (frm.witness_firstname.value.length < 1) {
      errstr += "You must provide a first name.\n";
      focused=focusit(frm.witness_firstname,focused);
    }
    if (frm.witness_lastname.value.length < 2) {
      errstr += "You must provide a last name.\n";
      focused=focusit(frm.witness_lastname,focused);
    }
		upshiftit(frm.witness_address1);
		upshiftit(frm.witness_address2);
		upshiftit(frm.witness_city);
	  frm.witness_zip.value = frm.witness_zip.value.toUpperCase();
	  if (frm.witness_homephone.value.length != 0) { 
 			if (!phoneRE.test(frm.witness_homephone.value)) {
			  errstr += "The home phone number is not valid.\n";
			  focused=focusit(frm.witness_homephone,focused);
			}
		}
	  if (frm.witness_workphone.value.length != 0) { 
 			if (!phoneRE.test(frm.witness_workphone.value)) {
			  errstr += "The work phone number is not valid.\n";
			  focused=focusit(frm.witness_workphone,focused);
			}
		}
		rtn = chkselected('gender0');
		if (rtn == 0) {
		  errstr += 'You must select a gender.\n';
		}
  }
  else {
    for (i=0; i<len; i++) {
			upshiftit(frm.witness_firstname[i]);
			upshiftit(frm.witness_middlename[i]);
			upshiftit(frm.witness_lastname[i]);
			if (frm.witness_firstname[i].value.length < 1) {
			  errstr += "You must provide a first name for witness #" + (i+1) + ".\n";
			  focused=focusit(frm.witness_firstname[i],focused);
			}
			if (frm.witness_lastname[i].value.length < 2) {
			  errstr += "You must provide a last name for witness #" + (i+1) + ".\n";
			  focused=focusit(frm.witness_lastname[i],focused);
			}
			upshiftit(frm.witness_address1[i]);
			upshiftit(frm.witness_address2[i]);
			upshiftit(frm.witness_city[i]);
			frm.witness_zip[i].value = frm.witness_zip[i].value.toUpperCase();
  		rtn = chkselected('gender' + i);
			if (rtn == 0) {
			  errstr += 'You must select a gender for witness #' + (i+1) + '.\n';
			}
    }
  }
}
else if (pageid == 82) {   //verify property info page
  mykey = frm.pdkey.value;
  len = frm.property_cnt.value;
  ptotal = 0;
  //alert('num items: ' + len);
  if (len == 1) {
    ptotal = (frm.property_value.value * 1);
    if (frm.item_qty.value == 0) {
      errstr += "Quantity must be at least 1.\n";
      focused=focusit(frm.item_qty,focused);
    }
    // remove commas and dollar signs
    tempstr = frm.property_value.value;
    frm.property_value.value = tempstr.replace("$","");
    tempstr = frm.property_value.value;
    frm.property_value.value = tempstr.replace(",","");
    if ((frm.property_value.value == '') || (isNaN(frm.property_value.value))) {
      frm.property_value.value = 0;
      errstr += "Please enter a property value.\n";
      focused=focusit(frm.property_value,focused);
    }
    frm.serial.value = frm.serial.value.toUpperCase();
    frm.license_no.value = frm.license_no.value.toUpperCase();
    frm.frame_no.value = frm.frame_no.value.toUpperCase();
    if (frm.property_type.value.length < 1) {
      errstr += "You must indicate the property type.\n";
      focused=focusit(frm.property_type,focused);
    }
    else {  // since property type specified, must provide a value
      // El Cajon wants to force a value greater than 0
			if ((frm.property_value.value < 0) ||
			    ((frm.property_value.value == 0) && (mykey == 'CA92020ECPD'))) {
				if (!focused) {
				  errstr += "Please enter the value of the property.\n";
				  focused=focusit(frm.property_value,focused);
				}
			}
    }
  }
  else {
    for (i=0; i<len; i++) {
     // alert('item_qty[' + i + ']:' + frm.item_qty[i].value);
	    ptotal = ptotal + (frm.property_value[i].value * 1);
			tempstr = frm.property_value[i].value;
			frm.property_value[i].value = tempstr.replace("$","");

      if ((frm.property_value[i].value == '') || (isNaN(frm.property_value[i].value))) {
        frm.property_value[i].value = 0;
        errstr += "Please enter a property value.\n";
        focused=focusit(frm.property_value[i],focused);
      }
      frm.serial[i].value = frm.serial[i].value.toUpperCase();
      frm.license_no[i].value = frm.license_no[i].value.toUpperCase();
      frm.frame_no[i].value = frm.frame_no[i].value.toUpperCase();
      if (frm.item_qty[i].value == 0) {
        errstr += "Quantity must be at least 1.\n";
        focused=focusit(frm.item_qty[i],focused);
      }
      if (frm.property_type[i].value.length < 1) {
        errstr += "You must indicate the property type.\n";
        focused=focusit(frm.property_type[i],focused);
      }
			else {  // since property type specified, must provide a value
				if ((frm.property_value[i].value < 0) ||
			      ((frm.property_value[i].value == 0) && (mykey == 'CA92020ECPD'))) {
 					if (!focused) {
					  errstr += "Please enter the value of the property.\n";
					  focused=focusit(frm.property_value[i],focused);
					}
				}
			}
    }
  }
  if ((ptotal > frm.plimit.value) && (frm.plimit.value > 0)) {
    errstr += "Total property value exceeds limit of " + frm.plimitf.value;
  }
  frm.ptotal.value = ptotal;
//  alert('prop total: ' + ptotal + '  limit: ' + frm.plimit.value);
}
else if (pageid == 9) {   //verify identification info page
  if (frm.anon.value != 'Y') {
		if (frm.identity_type.value.length < 1) {
		  errstr += "You must provide an identity type.\n";
		  focused=focusit(frm.identification_no,focused);
		}
		if (frm.identification_no.value.length < 2) {
		  errstr += "You must provide your identification number.\n";
		  focused=focusit(frm.identification_no,focused);
		}
		else {
		  frm.identification_no.value = frm.identification_no.value.toUpperCase();
		 // alert('id no: ' + frm.identification_no.value);
		}
		if (!emailRE.test(frm.email1.value)) {
		  errstr += "You must provide a valid email address.\n";
		  focused=focusit(frm.email1,focused);
		}
		if (frm.email1.value != frm.email2.value) {
		  errstr += "The email addresses you entered do not match.\n";
		  focused=focusit(frm.email1,focused);
		}
	}
}
else if (pageid == 10) {   //done reviewing, off to final page
}
else if (pageid == 114) {   //user profile
  var fld = document.getElementsByName("email-1");
	if (!emailRE.test(fld[0].value)) {
	  errstr += "You must provide a valid email address.\n";
	  focused=focusit(fld[0],focused);
	}
  var fld = document.getElementsByName("pwd-1");
  if (quoteRE.test(fld[0].value)) {
    errstr += "Password cannot contain quotes or apostrophes.\n";
    focused=focusit(fld[0],focused);
  }
  var setpwd1 = document.getElementsByName("setpwd-1")[0];
  var oldpwd1 = document.getElementsByName("oldpwd-1")[0];
	if (setpwd1.value == 'Y') {
	  if ((fld[0].value.length < 1) || (fld[0].value == oldpwd1.value)) {
			errstr += "You must provide a new password.\n";
			focused=focusit(fld[0],focused);
	  }
	}
  page_action = "dept_admin.asp";
  frm.enterkey.value = "Save Settings";
}
else if ((pageid == 111) || (pageid == 112) || (pageid == 113) || (pageid == 99)) {  //register
  if (pageid == 113) {
    page_action = "calc.asp"; }
  else if (pageid == 99) {
	  page_action = "upload_test.asp"; }
  else {
	  page_action = "dept_admin.asp"; }
  //alert('subbtn: ' + frm.subbtn.value);
  
  if (frm.dept_name.value.length < 4) {
    errstr += "You must provide a complete department name.\n";
    focused=focusit(frm.dept_name,focused);
  }
  else {
	  upshiftit(frm.dept_name);
  }
  if ((frm.dept_acronym.value.length < 2) || (!acroRE.test(frm.dept_acronym.value))) {
    errstr += "You must provide a valid acronym of at least 3 letters.\n";
    focused=focusit(frm.dept_acronym,focused);
  }
  else {
    frm.dept_acronym.value = frm.dept_acronym.value.toUpperCase();
  }
  frm.zip_code.value = frm.zip_code.value.toUpperCase();
  if (frm.country.value == 'USA') {
    frm.state.value = frm.state_USA.value;
    if (!zipRE.test(frm.zip_code.value)) {
      errstr += "You must provide a valid postal code.\n";
      focused=focusit(frm.zip_code,focused);
    }
  }
  else {
    frm.state.value = frm.state_CAN.value;
		if (frm.zip_code.value.length < 1) {
		  errstr += "You must enter a valid postal code.\n";
		  focused=focusit(frm.zip_code,focused);
		}
  }

  if ((pageid == 111) || (pageid == 113)) {
    if (!emailRE.test(frm.void_email.value)) {
      errstr += "You must provide a valid email address.\n";
      focused=focusit(frm.void_email,focused);
    }
    if ((isNaN(frm.num_reports.value)) || (frm.num_reports.value.length == 0)) {
      errstr += "Please specify the number of reports you take per month.\n";
      focused=focusit(frm.num_reports,focused);
    }
    if ((isNaN(frm.cost.value)) || (frm.cost.value.length == 0)) {
      errstr += "Please specify an amount for the cost of each report.\n";
      focused=focusit(frm.cost,focused);
    }
  }
  else {  //112 is dept info page
    if (frm.address1.value.length < 4) {
      errstr += "You must provide an address.\n";
      focused=focusit(frm.address1,focused);
    }
    if (frm.city.value.length < 4) {
      errstr += "You must provide a city.\n";
      focused=focusit(frm.city,focused);
    }
    if (!phoneRE.test(frm.dept_phone.value)) {
      errstr += "You must provide a valid department phone number.\n";
      focused=focusit(frm.dept_phone,focused);
    }
    if (frm.contact_name.value.length < 4) {
      errstr += "You must provide a contact name.\n";
      focused=focusit(frm.contact_name,focused);
    }
    if (!phoneRE.test(frm.contact_phone.value)) {
      errstr += "You must provide a valid contact phone number.\n";
      focused=focusit(frm.contact_phone,focused);
    }
    if (!emailRE.test(frm.contact_email.value)) {
      errstr += "You must provide a valid contact email address.\n";
      focused=focusit(frm.contact_email,focused);
    }
    if (!emailRE.test(frm.void_email.value)) {
      errstr += "You must provide a valid from-email address.\n";
      focused=focusit(frm.void_email,focused);
    }
    if (frm.admin_phone.value.length > 0) {
			if (!phoneRE.test(frm.admin_phone.value)) {
			  errstr += "Admin phone number is invalid.\n";
			  focused=focusit(frm.admin_phone,focused);
			}
    }
    if (frm.admin_email.value.length > 0) {
			if (!emailRE.test(frm.admin_email.value)) {
			  errstr += "Admin email address is invalid.\n";
			  focused=focusit(frm.admin_email,focused);
			}
    }
    if (frm.url.value.length < 12) {
      errstr += "You must provide a link to your department website.\n";
      focused=focusit(frm.url,focused);
    }
    if ((isNaN(frm.report_sequence_no.value)) || (frm.report_sequence_no.value.length == 0)) {
      errstr += "Report sequence number must be a number.\n";
      focused=focusit(frm.report_sequence_no,focused);
    }
    if ((isNaN(frm.gmt_offset.value)) || (frm.gmt_offset.value.length == 0)) {
      errstr += "GMT offset must be a number.\n";
      focused=focusit(frm.gmt_offset,focused);
    }
  }
}
else if (pageid == 18) {   //report lookup
  errstr = '';
  if (frm.mailid.checked) {
		if (((frm.identity_type.value.length < 1) || (frm.identification_no.value.length < 1)) && 
		    (!emailRE.test(frm.email.value))) {
		  errstr += "You must specify either your drivers license number or email address.";
		  frm.identity_type.value = "Drivers License";
      focused=focusit(frm.email,focused);
		}
		else {
		  page_action = 'pdweb.asp';
		}
	}
	else {
	  if (frm.identity_type.value.length < 1) {
	    errstr += 'You must select an identity type.\n';
	    focused=focusit(frm.identity_type,focused);
	  }
	  if (frm.identification_no.value.length < 1) {
	    errstr += "You must provide your identification number.\n";
	    focused=focusit(frm.identification_no,focused);
	  }
	  if (!emailRE.test(frm.email.value)) {
	    errstr += "You must provide your email address.\n";
	    focused=focusit(frm.email,focused);
	  }
	  
	  if (errstr == '') {  // try showing the report
			if (frm.repid.value.length < 1) {
			  errstr += "You must provide your report id.\n";
			  focused=focusit(frm.repid,focused);
	      page_action = 'pdweb.asp';   // so we can check for multiple reports for this id
			}
			else {
	   // page_action = 'dept_admin.asp';
				frm.reportid.value = frm.repid.value;
				show_report();
				return true;
	    }
	  }
	}
}
else if (pageid == 20) {   //support request
  page_action = "asp/support.asp";
  if (!emailRE.test(frm.email.value)) {
    errstr += "You must provide a valid email address.\n";
    focused=focusit(frm.email,focused);
  }
  if (frm.subject.value.length < 6) {
    errstr += "You must provide a descriptive subject.\n";
    focused=focusit(frm.subject,focused);
  }
  if (frm.description.value.length < 11) {
    errstr += "Please describe your request thoroughly.\n";
    focused=focusit(frm.description,focused);
  }
}
else if (pageid == 998) {   //upload test
  page_action = 'upload_test.asp';
}
else if (pageid == 1000) {   //just submit dept admin page
  page_action = 'dept_admin.asp';
}

//alert('errstr="' + errstr + '"\n');
  if (errstr.length > 0) {
    alert(errstr);
    return false;
  }
  else {
    ref = document.referrer + "";
    if (frm.ref.value == '') {
      frm.ref.value = ref;
    }
    frm.method = "POST";
    frm.action = page_action;
    frm.submit();
    return true;
  }
}

function setref () {
var frm = document.frmMain;
frm.ref.value = document.referrer.substr(0,35).toLowerCase() + "";
return true;
}

function process_report(repid,suppnum) {
var frm = document.frmMain;

window.status='';
frm.reportid.value = repid;
frm.suppnum.value = suppnum;

frm.method = "POST";
frm.action = "dept_admin.asp";
frm.submit();
return true;
}

function show_pdf() {
  show_report('Y');
  return true;
  var frm = document.frmMain;
  var deptid = frm.deptid.value;
  var report_id = frm.reportid.value;
  var suppnum = frm.suppnum.value;
  var theurl = "dept_admin.asp?read=Y&pdf=Y&deptid=" + deptid + "&reportid=" + report_id + "&suppnum=" + suppnum;
  alert('theurl= ' + theurl);
  pdf_window(report_id,theurl);
}

function pdf_window(repid,theurl) {
  var frm = document.frmMain;
//  alert('pdfcnt=' + frm.pdfcnt.value);
//  if (frm.pdfcnt.value != 0) { return true; }
//  frm.pdfcnt.value = 1;
//  alert('pdfcnt2=' + frm.pdfcnt.value);
  
	var winW, WinH;
	if (parseInt(navigator.appVersion) > 3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth-16;
	  winH = window.innerHeight-16;
	 }
	 if (navigator.appName.indexOf("Microsoft") != -1) {
	  winW = document.body.offsetWidth-20;
	  winH = document.body.offsetHeight-20;
	 }
	}

  var win_name = 'ePoliceReport ' + repid;
  var link_name = theurl;
  var details = ""; //"location=yes, resizable=yes, scrollbars=yes, menubar=yes, width=700, height=" + winH;
  win2 = window.open("", "ePoliceReport", details);
  win2.document.location=link_name;
}

function show_report(pdf) {
  var frm = document.frmMain;
  var report_id = frm.reportid.value;
  var pd_key = frm.pdkey.value;
  var guid = frm.reportguid.value;
  var deptid = frm.deptid.value;
  var suppnum = 0;
  if (frm.pageid != undefined) {
    if (frm.pageid.value == 18) {  //lookup page
      suppnum = frm.suppno.value;
    } 
    else {
      suppnum = frm.suppnum.value;
    }
  }
  else {
    suppnum = frm.suppnum.value;
  }
  var idtype = '&idtype=' + escape(frm.identity_type.value);
  var idno = '&idno=' + escape(frm.identification_no.value);
  var email = '&email=' + escape(frm.email.value);
  var pdopen = '&pdopen=' + frm.pdopen.value;
  var app = '&aa=' + frm.approveit.value;
  frm.approveit.value = "N";  //approve only once
  var anon = '&ano=' + frm.anon.value;
  var pdf = '&pdf=' + pdf;
  var supp = 'N';
  if (frm.supplemental != undefined) {
    if (frm.supplemental.checked) { 
      supp = 'Y';
      suppnum = 0; 
    }
  }
  supp = '&supp=' + supp;

	var winW, WinH;
	if (parseInt(navigator.appVersion) > 3) {
	 if (navigator.appName=="Netscape") {
	  winW = window.innerWidth-16;
	  winH = window.innerHeight-16;
	 }
	 if (navigator.appName.indexOf("Microsoft") != -1) {
	  winW = document.body.offsetWidth-20;
	  winH = document.body.offsetHeight-20;
	 }
	}
   
  var win_name = 'ePoliceReport ' + report_id;
  var link_name = 'dept_admin.asp?rid=' + report_id + '|' + pd_key + "|" + guid + "|" + deptid + "|" + suppnum +
                  idtype + idno + email + pdopen + app + anon + supp + pdf;
  var details = ""; //"location=yes, resizable=yes, scrollbars=yes, menubar=yes, width=700, height=" + winH;
  win2 = window.open("", "ePoliceReport", details);
  win2.document.location=link_name;
}

function report_home() {
  document.location='pdweb.asp?pdkey=' + document.frmMain.pdkey.value + 
                    '&it=' + document.frmMain.it.value;
}

function reopen(frm) {
//var frm = document.frmReOpen;

var report_id = frm.ri.value;
var pd_key = frm.pdkey.value;
var guid = frm.rg.value;
var deptid = frm.di.value;
var suppnum = frm.sn.value;
// the default value in form for rid is bogus to confuse someone looking at source code
frm.rid.value = report_id + '|' + pd_key + '|' + guid + '|' + deptid + '|' + suppnum;
//alert('going to: ' + frm.rid.value);
frm.method = "POST";
frm.action = "pdweb.asp";   // form sets bogus value, so reset here
frm.target = "_reopened";
frm.submit();
return true;
}

function adminfunc(section) {
  var frm = document.frmMain;
  frm.userlist.value = 'N';
  frm.userprofile.value = 'N';
  frm.edit.value = 'N';
  frm.ctypes.value = 'N';

  if (section == 'userlist') {
    frm.userlist.value = 'Y';
  }
  else if (section == 'editdept') {
    frm.edit.value = 'Y';
  }
  else if (section == 'crimetypes') {
    frm.ctypes.value = 'Y';
  }
  else if (section == 'userprofile') {
    frm.userprofile.value = 'Y';
  }
  frm.submit();
  return true;
}

function adminhome() {
  var frm = document.frmMain;
  frm.submit();
  return true;
}

function sortlist(key,field,order) {
  var frm = document.frmMain;
  frm.sortby.value=field;
  frm.sortorder.value=order;
  frm.enterkey.value=key;
  frm.submit();
  return true;
}

