﻿


function Publication( code, locs ) {
    
    this.code = code;
    this.locs = locs;
}

Publication.prototype.getByPrefix = function( prefix ) {
    
    var results = new Array();
    var lcPrefix = prefix.toLowerCase();
    
    this.locs.each( function( location ) { 
        if( location.substr( 0, prefix.length ).toLowerCase() == lcPrefix ) 
            results.push( location );
    });
    
    return results;
}

Publication.prototype.hasPrefix = function( prefix ) {
    
    var lcPrefix = prefix.toLowerCase();
 
    for( var i = 0; i<this.locs.length; i++ ) { 
        if( this.locs[i].substr( 0, prefix.length ).toLowerCase() == lcPrefix ) {
            return true;
         }
    }
    
    return false;
}

var Locations = 
{
    // to be filled in dynamically
    pubs: new Array(),
    
    getByPrefix: function( code, prefix ) { 
        
        for( var i=0; i< this.pubs.length; i++ ) {
            if( this.pubs[i].code == code ) return this.pubs[i].getByPrefix( prefix );
        }
        
        return new Array();
    },
    
    hasPrefix: function( code, prefix ) { 
        
        for( var i=0; i< this.pubs.length; i++ ) {
            if( this.pubs[i].code == code ) return this.pubs[i].hasPrefix( prefix );
        }
        
        return false;
        
    }
    
}



