function check_mask(field_value, mask, case_sensitive) {

    // If the strings are different lengths, return false
    if (field_value.length != mask.length) {
        return false
    }
    
    // Run through each character in the mask
    for (var counter = 0; counter < mask.length; counter++) {
        
        // Get the current mask and field_value characters
        current_mask = mask.charAt(counter)
        current_char = field_value.charAt(counter)
        
       // Is the mask character a letter?
       if (current_mask == "@") {
           
           // If so, then if the current character isn't a letter, return false
           if (!its_a_letter(current_char)) {
               return false
           } 
        
       }
       // Is the mask character a digit?
       else if (current_mask == "#") {
           
           // If so, then if the current character isn't a digit, return false
           if (!its_a_digit(current_char)) {
               return false
           } 
        }
        // Otherwise, are the characters the same?
        else {

            // Is this a case-sensitive mask?
            if (!case_sensitive) {
        
                // If not, then use only uppercase characters
                current_mask = current_mask.toUpperCase()
                current_char = current_char.toUpperCase()
            }
            if (current_mask != current_char) {
                return false
            }
        }
    }
    
    // If we get this far, we have a match
    return true
}

function check_length(field1,minlength) {
	if (field1.value.length < (minlength) ) {
		alert("Field must be at least " + minlength + " characters.")
		field1.focus()
	}
	else {
		return true
	}
}

// Function to verify that two fields are identical and not blank
function confirm_check(field1,field2,alertfield) {
	if (field1.value == "") {
		alert(alertfield +" can't be blank.")
		field1.focus()
	}
	else	{
		if (field1.value !== field2.value) {
			alert(alertfield +"s do not match, please reenter.")
			field2.value = ""
			field1.select()
		}
	}
}


function its_empty(string_value) {

// Check for the empty string and null
if (string_value == "" || string_value == null) {
	// If either, it's empty so return true
	return true
}
//Otherwise, it's not empty so return false
return false
}

function its_a_letter(character) {

    var lowercase_letters = "abcdefghijklmnopqrstuvwxyz"
    var uppercase_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    // If it's not in the lowercase_letters string or the
    // uppercase_letters string, then it's not a letter, 
    // so return false
    
    if (lowercase_letters.indexOf(character) == -1 &&
        uppercase_letters.indexOf(character) == -1) {
        return false
    }
    
    // Otherwise, it's a letter, so return true
    return true
}

function its_a_digit(character) {

    var digit_characters = "0123456789"

    // If it's not in the digit_characters string,
    // then it's not a digit so return false
    
    if (digit_characters.indexOf(character) == -1) {
        return false
    }
    
    // Otherwise, it's a digit, so return true
    return true
}



function maskvalidate(current_form) {

    // Loop through the form fields
    for (var counter = 0; counter < current_form.length; counter++) {

      if (current_form[counter].disabled == false) {	
        // Is a mask defined for this field?
        if (current_form[counter].mask) {

            // If so, send the field to the check_mask() function
            if (!check_mask(current_form[counter].value, current_form[counter].mask, false)) {

                // If the value isn't within the range, set up an error message
                var mask_error = "The value in the " + 
                                 current_form[counter].name +
                                 " field is invalid.\n"

                var mask_string = current_form[counter].mask_example
                
                mask_error += "\nThe value must be entered using the following format:\n\n " +
                              mask_string

                // Display the message & return false to bypass the calculation
                alert(mask_error)
	return false
                
            }
        }
      }
    }
    return true
}


function validate(current_form) {

	var missing_fields = new Array()
	var total_missing = 0

	//Loop through all the form elements
	for (counter = 0; counter < current_form.length; counter++) {

		// Is this a visible text field that's mandatory?
		if ((current_form[counter].type == "text" ||
			current_form[counter].type == "textarea" ||
			current_form[counter].type == "password") &&
			current_form[counter].mandatory) {
			
			// Is it empty?
			if (its_empty(current_form[counter].value)) {
			
				//If so, add the field to the array of missing fields
				missing_fields[total_missing] = current_form[counter]
				total_missing++
			}
		}
	}
	

	//Were there any fields missing?
	if (total_missing > 0) {
		
		//Start the message
		var missing_message = "Sorry, you must fill in the following " +
								(total_missing == 1 ? " field:" : " fields:") +
								"\n______________________________\n\n"
								
		//Loop through the missing fields
		for (counter = 0; counter < missing_fields.length; counter++) {
			missing_message += missing_fields[counter].displaytext + "\n"
		}
		
		//Finish up and display the message
		missing_message += "\n________________________________\n\n" +
						"Please fill in these fields and then resubmit the form."
		alert(missing_message)
		
		//For emphasis, put the focus on the first missing field
		missing_fields[0].focus()
	}
	else {
		
		//otherwise, go ahead and submit
		if (maskvalidate(current_form) ) {
			current_form.submit()
		}
	}
}	


function check_open(current_form) {

	if (document.getElementById) {
		var span_node = document.getElementById("openbid")
	
		if (current_form.txtauct_open.value == "false") {
			var new_node = document.createTextNode("Prices Realized")
			var old_node = span_node.firstChild
			span_node.replaceChild(new_node,old_node)
		}
	}
}


function check_open2(current_form) {

	if (document.getElementById) {
		var span_node = document.getElementById("lotheadings")
	
		if (current_form.txtauct_open.value == "false") {
			var exp_node = document.createElement("th")
			span_node.appendChild(exp_node)
			var text_node = document.createTextNode("Prices Realized")
			exp_node.appendChild(text_node)
			exp_node.className = "tableheadings"
		}
	}
}


 function checkstatus() {
 
 	lstatus = false
 	if (document.forms[0].txtlogin.value == "Valid") {
		lstatus = true
	}
	return lstatus
 
}