//Form Focus Script
function sf(){document.status.fm_ticketnumber.focus();}

// Multiple onSubmit Handler Script
function OnSubmitCheck() {
var one = submitonce(status); // change functionOne() to onsubmit function name
var two = checkWholeForm(status);  // change functionTwo() to onsubmit function name
if((one == false) || (two == false)) { return false; }
return true;
}

// Submit Once form validation
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}

// Agreement Check Script

function agreesubmit(){
	if(document.getElementById("agreecheck").checked==true){
		document.getElementById("submit").disabled = false;
	}
	else {
		document.getElementById("submit").disabled = true;
	}
}

/*var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}
*/

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("You submit to the terms and conditions to submit this form!")
return false
}
}
}

// Data Validation Script

// Ticket Number: - 6, 15, or 16 characters, numbers only
function checkTicketNumber (strng) {
var error = "";
if ((strng == "") || (strng.length == 0)) {
   error = "Please enter your ticket number.\n";
   return error;
}

    var illegalChars = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\/\`\~\=\|\?\!\'\"\<\>\,\.\-\;\=\:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]/; // allow only only numbers
    
    if ((strng.length != 6) && (strng.length != 15) && (strng.length != 16)) {
       error = "The ticket number is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The ticket number field contains invalid characters (use only numbers).\n";
    }   
return error;    
}

// Last Name: between 2-20 characters, letters only

function checkLastName (strng) {
var error = "";
if ((strng == "") || (strng.length == 0)) {
   error = "Please enter your last name.\n";
   return error;
}
    var illegalChars = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\/\`\~\=\|\?\!\'\"\<\>\,\.\-\;\=\:0123456789]/; // allow only letters
    
    if ((strng.length < 2) || (strng.length > 20)) {
       error = "The last name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The last name field contains invalid characters (use only letters).\n";
    }   
return error;    
}

// First Name: between 2-20 characters, letters only

function checkFirstName (strng) {
var error = "";
if ((strng == "") || (strng.length == 0)) {
   error = "Please enter your first name.\n";
   return error;
}
    var illegalChars = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\/\`\~\=\|\?\!\'\"\<\>\,\.\-\;\=\:0123456789]/; // allow only letters
    
    if ((strng.length < 2) || (strng.length > 20)) {
       error = "The first name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The first name field contains invalid characters (use only letters).\n";
    }   
return error;    
}

function checkTagNumber(strng) {
var error = "";
if ((strng == "") || (strng.length == 0)) {
   error = "Please enter your license plate number.\n";
   return error;
}
    var illegalChars = /[$\\@\\\#%\^\&\*\(\)\[\]\+\_\{\}\/\`\~\=\|\?\!\'\"\<\>\,\.\-\;\=\:]/; // allow only letters and numbers
    
    if ((strng.length < 2) || (strng.length > 20)) {
       error = "The last name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The license plate number field contains invalid characters (use only letters and numbers, no spaces or dashes).\n";
    }   
return error;    
}

// valid state from dropdown list

function checkTagState(choice) {
var error = "";
    if (choice == 0) {
    error = "Please select a state from the drop-down list.\n";
    }    
return error;
}

// Terms and Condition Integrity Check: Error if user modified the terms in the textarea
// was textbox altered

function checkTerms(strng) {
var error = ""; 
  if (strng != "Use of this system requires your agreement to be bound by the following terms and conditions: The decisions of the Judicial Board regarding parking ticket appeals are final and cannot be considered, discussed, or appealed further. All interactions between the appellant and the Judicial Board shall be conducted via the Parking Ticket Appeal Form only and any form of verbal communication with the Judicial Board regarding parking ticket appeals will not be entertained. Abuse of the parking ticket appeal process or anyone involved will not be tolerated and may affect eligibility to participate in the parking ticket appeal process and/or result in disciplinary action.") {
     error = "You are not allowed to modify the Terms and Conditions.\n";
  }
return error;
}

// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}

function checkSubmitCount(strng) {
var error = "";
if (strng != 0) {
   error = "Your request is being processed. Please be patient!\n";
   }
return error;
}