/**
 * @author jamescw
 */

var validation = {
	/*
 	* 
    * Validates a single panel ID.
    */
    validate_search_single: function(event, elm_key_id, elm_error_id) {
     
        var errors = new Array();
     
        // retrieve the panel key with all spaces removed
        var key = $(elm_key_id).value.replace(/ /g, '');
    
        // check: panel key is 14 characters
        if(key.length != 14) {
            errors.push('Panel key must be 14 characters');
        }
        
        // check: panel key is alphanumeric - allow *'s also
        if(key.test('^([a-zA-Z0-9]+)$') == false) {
            errors.push('Panel key can only contain characters and numbers');
        }
        
        // if we have errors, cancel the submission event
        if(errors.length > 0) {
            (new Event(event)).stop();
            alert(errors.join('\n'));
        }
    
    },
    
    /**
     * Validates the file upload item has content for file upload submission
     */
    validate_search_file: function(event) {
		
        // if there is no value, cancel the event
		if(!$('panelavl').value) {
			(new Event(event)).stop();
			alert('Please choose a file to upload containing panel keys');
		}
	}
}
