var hostName = "http://affiliate.zap2it.com"; var filmSelect = filmSelect!=undefined ? filmSelect : 'filmSelect'; var firstFilmItem = firstFilmItem!=undefined ? firstFilmItem : '-- Select Film --'; //alert( filmSelect + ' '+firstFilmItem); /** * The primary library that defines the objects used to model the data * related to theatres and films for Zap2it affiliates. * *
© Copyright 2008, Tribune Media Services
* @author Rakesh Vidyadharan (Sans Pareil Technologies, Inc) 2008-06-07 * @version $Id: affiliate.js 4272 2008-06-20 03:30:16Z rakesh $ */ /** The root namespace for the affiliate library. */ affiliate = {} /** The namespace under which all utility classes and methods are loaded. */ affiliate.movie = { affiliateId : 'zap2it', /** * Parse the data and display the theatres drop-down box. Sample code * that parses data in affiliatedata.js file. */ displayTheatres: function() { var tdata = eval( jsont ); if ( tdata.theaterList.status.code == 200 ) { theatres.init( tdata ); theatres.display( theatreSelect ); } else { alert( 'Error loading theatre data. ' + tdata.theaterList.status.message ); } }, /** * Parse the data and display the films drop-down box. Sample code that * parses data in affiliatedata.js file. */ displayFilms: function() { var fdata = eval( jsonf ); if ( fdata.moviesthisweek.status.code == 200 ) { films.init( fdata ); films.display( filmSelect ); } else { alert( 'Error loading film data. ' + fdata.moviesthisweek.status.message ); } }, /** Event handler for the theatreList select */ selectTheatre: function() { var selectElement = document.getElementById( theatreSelect ); var theatre = theatres.getTheatre( selectElement.selectedIndex ); if ( theatre ) { var url = theatre.getUrl() + '&aid=' + affiliate.movie.affiliateId; document.location = url; } }, /** Event handler for the filmList select */ selectFilm: function() { var selectElement = document.getElementById( filmSelect ); var film = films.getFilm( selectElement.selectedIndex ); if ( film ) { var url = film.getMovieUrl() + '?aid=' + affiliate.movie.affiliateId; document.location = url; } }, /** A model object that represents a film. */ Film: function() { /** The private fields and members of the object. */ var private = { /** The primary key of the film. Uses the Glens Falls ID. */ movieId: null, /** The title of the film. */ title: null, /** The MPAA rating for the film. */ rating: null, /** The array of actors featured in the film. */ actors: new Array(), /** The director(s) of the film. */ directors: new Array(), /** The map of URL's related to the film. */ urls: new affiliate.movie.HashMap() }; /** The public interface of the object. */ var public = { /** Initialise the object from the specified JSON string. */ init: function( data ) { private.movieId = data.movieId; private.title = data.title; private.rating = data.rating; if( data.actors != undefined && data.actors != null ) { for ( var i = 0; i < data.actors.length; ++i ) { private.actors[i] = data.actors[i]; } } if( data.directors != undefined && data.directors != null ) { for ( var i = 0; i < data.directors.length; ++i ) { private.directors[i] = data.directors[i]; } } if ( data.imageurl ) private.urls.put( 'image', data.imageurl ); if ( data.screenplayurl ) { private.urls.put( 'screenplay', data.screenplayurl ); } if ( data.movieurl ) private.urls.put( 'movie', data.movieurl ); if ( data.officialurl ) private.urls.put( 'official', data.officialurl ); }, /** Return the primary key of the film. */ getMovieId: function() { return private.movieId; }, /** Return the title of the film. */ getTitle: function() { return private.title; }, /** Return the rating for the film. */ getRating: function() { return private.rating; }, /** Return the array of actors featured in the film. */ getActors: function() { return private.actors; }, /** Return the array of directors featured in the film. */ getDirectors: function() { return private.directors; }, /** Return the image url for the film. */ getImageUrl: function() { return private.urls.get( 'image' ); }, /** Return the screenplay url for the film. */ getScreenplayUrl: function() { return private.urls.get( 'screenplay' ); }, /** Return the Zap2it movie url for the film. */ getMovieUrl: function() { return private.urls.get( 'movie' ); }, /** Return the official url for the film. */ getOfficialUrl: function() { return private.urls.get( 'official' ); } }; return public; }, /** * A model object that represents a list of films. * * @param firstItem The text to display as the first item in the select. */ Films: function( firstItem ) { /** The private fields and members of the object. */ var private = { /** The hash map of movieId->film mappings maintained in this list. */ list: new affiliate.movie.HashMap(), /** The URL at which further films or information may be gathered. */ moreUrl: null }; /** the public interface for the film list. */ var public = { /** * Initialise the object from the specified JSON string. Note that * this function works off the entire JSON data structure and not * on thefilms array alone.
*/
init: function( data )
{
if( data.moviesthisweek.films != undefined &&
data.moviesthisweek.films != null )
{
for ( var i = 0; i < data.moviesthisweek.films.length; ++i )
{
var film = new affiliate.movie.Film();
film.init( data.moviesthisweek.films[i] );
private.list.put( film.getMovieId(), film );
}
}
private.moreUrl = data.moreurl;
},
/**
* Display the films in a drop-down box.
*
* @param name The name of the select element that is to be updated.
*/
display: function( name )
{
var selectElement = document.getElementById( name );
var films = this.getFilms();
selectElement.options[0] = new Option( firstItem, 0 );
for ( var i = 0; i < films.length; ++i )
{
if(films[i].getMovieId) {
var newOp = document.createElement('option');
newOp.value = films[i].getMovieId();
newOp.innerHTML = films[i].getTitle();
selectElement.appendChild(newOp);
}
}
},
/**
* Return a list of {@link Film#movieId} values that represents the
* list of films stored in this list.
*
* @return An array of movieId values.
*/
getMovieIds: function() { return private.list.keySet(); },
/**
* Return a list of {@link Film} model objects that represent the
* list of films stored in this list.
*
* @return An array of Film objects.
*/
getFilms: function() { return private.list.values(); },
/** Return the film at the specified index in list. */
getFilm: function( index )
{
var f = [];
for (var i = 0; i < this.getFilms().length; i++) {
if (this.getFilms()[i].getMovieId) {
f[f.length] = i;
}
}
return this.getFilms()[f[index-1]];
},
/** Return the URL at which further films or details may be obtained. */
getMoreUrl: function() { return private.moreUrl; }
};
return public;
},
/** A model object that represents a theatre. */
Theatre: function()
{
/** The private fields and members of the object */
var private =
{
/** The primary key of the theatre. */
theatreId: null,
/** The name of the theatre. */
name: null,
/** The street address of the theatre. */
street: null,
/** the city part of the theatre address. */
city: null,
/** the state part of the theatre address. */
state: null,
/** The postal code of the theatre address. */
postalCode: null,
/** The telephone number of the theatre. */
telephone: null,
/** The latitude of the theatre. */
latitude: null,
/** The longitude of the theatre. */
longitude: null,
/** Fandango availablility for the theater */
fandango: false,
/** The URL at which full details about the theatre may be obtained. */
url: null
};
/** The public interface for the object. */
var public =
{
/**
* Initialise the object using the JSON string specified.
*
* @param data The JSON data structure to use to initialise the object.
*/
init: function( data )
{
private.theatreId = data.theatreId;
private.name = data.name;
private.street = data.street;
private.city = data.city;
private.state = data.state;
private.country = data.country;
private.postalCode = data.postalCode;
private.telephone = data.telephone;
private.latitude = data.latitude;
private.longitude = data.longitude;
private.fandango = data.fandango;
private.url = data.theaterurl;
},
/** Return the primary key of the theatre. This is the Glens Falls ID. */
getTheatreId: function() { return private.theatreId; },
/** Return the name of the theatre. */
getName: function() { return private.name; },
/** Return a concatenated address for the theatre. */
getAddress: function()
{
var address = "";
var comma = false;
if ( private.street != null )
{
address += private.street;
comma = true;
}
if ( private.city != null )
{
if ( comma ) address += ", ";
address += private.city;
comma = true;
}
if ( private.state != null )
{
if ( comma ) address += ", ";
address += private.state;
//comma = true;
}
return address;
},
getPhone: function()
{
return ( ( private.telephone ) ? private.telephone : '' );
},
/** Returns the array of films showing at the theatre. */
getFilms: function() { return private.films; },
/** Return the latitude geographic coordinates of the theatre. */
getLatitude: function() { return private.latitude; },
/** Return the longitude geographic coordinates of the theatre. */
getLongitude: function() { return private.longitude; },
/** Return the indicator about fandango ticketing for the theatre. */
getFandango: function() { return private.fandango; },
/** Return the URL at which full details of the theatre may be found. */
getUrl: function() { return private.url; }
};
return public;
},
/**
* A model object used to represent the list of theatres.
*
* @param firstItem The text to display as the first item in select.
*/
Theatres: function( firstItem )
{
/** The private interface of the list. */
var private =
{
/** The hash map of theatres represented in this list. */
list: new affiliate.movie.HashMap(),
/** The URL at which further theatres or information may be gathered. */
moreUrl: null
};
/** The public interface of the list. */
var public =
{
/**
* Initialise the object from the specified JSON string. Note that
* this function works off the entire JSON data structure and not
* on the theaters array alone.
*/
init: function( data )
{
if( data.theaterList.theaters != undefined && data.theaterList.theaters != null )
{
for ( var i = 0; i < data.theaterList.theaters.length; ++i )
{
var theatre = new affiliate.movie.Theatre();
theatre.init( data.theaterList.theaters[i] );
private.list.put( theatre.getTheatreId(), theatre );
}
}
private.moreUrl = data.moreurl;
},
/**
* Display the theatres in a drop-down box.
*
* @param name The name of the select element that is to be updated.
*/
display: function( name )
{
var selectElement = document.getElementById( name );
var theatres = this.getTheatres();
selectElement.options[0] = new Option( firstItem, 0 );
for ( var i = 0; i < theatres.length; ++i )
{
if(theatres[i].getTheatreId) {
var newOp = document.createElement('option');
newOp.value = theatres[i].getTheatreId();
newOp.innerHTML = theatres[i].getName();
selectElement.appendChild(newOp);
}
}
},
/**
* Return a list of {@link Theatre#movieId} values that represents the
* list of theatres stored in this list.
*
* @return An array of movieId values.
*/
getMovieIds: function() { return private.list.keySet(); },
/**
* Return a list of Theatre model objects that represent the
* list of theatres stored in this list.
*
* @return An array of Theatre objects.
*/
getTheatres: function() { return private.list.values(); },
/**
* Return the theatre at the specified index in list. Note that
* the index is decremented by one to account for the "Select
* Theatre" item in the list.
*/
getTheatre: function( index )
{
var f = [];
for (var i = 0; i < this.getTheatres().length; i++) {
if (this.getTheatres()[i].getTheatreId) {
f[f.length] = i;
}
}
return this.getTheatres()[f[index-1]];
},
/** Return the URL at which further theatres or details may be obtained. */
getMoreUrl: function() { return private.moreUrl; }
};
return public;
},
/**
* Created by: Michael Synovic
* on: 01/12/2003
* URL: http://weblogs.asp.net/ssadasivuni/archive/2003/09/17/27902.aspx
* Modified by: Rakesh Vidyadharan
* on: 2007/06/14
*
* This is a Javascript simulation of the Java HashMap object. Note * that no explict hashing or optimisation is performed over and above * that provided in the JavaScript Array object. This object is purely a * decorator around a JavaScript Array.
*/ HashMap: function() { /** The private fields and members of the class. */ var private = { map: new Array() }; /** The public interface of the class. */ var public = { /** Clear the mappings contained in this map. */ clear: function() { private.map = new Array(); }, /** * Tests if the specified object is a key in this map. * * @param Object key The key to check. Usually a string. * @return boolean Returnstrue if the specified
* key exists in the maps keys.
*/
containsKey: function( key )
{
var result = false;
for ( var i in private.map )
{
if ( ( i == key ) && ( private.map[i] != null ) )
{
result = true;
break;
}
}
return result;
},
/**
* Returns true if this HashMap maps one or more keys to
* the specified value.
*
* @param value The object to check for existence of mapping(s).
* @return boolean Returns true if there are mappings for
* the specified object.
*/
containsValue: function( value )
{
var result = false;
if ( value != null )
{
for ( var i in private.map )
{
if ( private.map[i] == value )
{
result = true;
break;
}
}
}
return result;
},
/**
* Return the value of the object mapped by the specified
* key.
*
* @param key The key to lookup in the map for associated value.
* @return Object The value mapped to the specified key, or
* null if no such mapping exists.
*/
get: function( key ) { return private.map[key]; },
/**
* Tests if this HashMap maps no keys to values.
*
* @return boolean Returns true if there are no mappings.
*/
isEmpty: function()
{
return ( private.map.length == 0 ) ? true : false;
},
/**
* Returns an array of the keys in this map.
*
* @return Array The array of keys stored in this map.
*/
keySet: function()
{
var keys = new Array();
for ( var i in private.map )
{
if ( private.map[i] != null ) keys.push( i );
}
return keys;
},
/**
* Maps the specified key to the specified
* value in this map. A NullPointerException is thrown
* if the key or value is null.
*
* @param key The key to map the value to.
* @param value The value to store in the map.
* @throws NullPointerException If either the key or value is null.
*/
put: function( key, value )
{
if ( key == null || value == null )
{
throw "NullPointerException key: {" + key + "}, value: {" + value + "}";
}
private.map[key] = value;
},
/**
* Removes the key (and its corresponding
* value) from this map.
*
* @param key The key whose mapping is to be removed.
* @return Object The value that was removed, or null
* if no such mapping exists.
*/
remove: function( key )
{
var value = private.map[key];
private.map[key] = null;
return value;
},
/**
* Returns the number of keys in this map.
*
* @return int The number of keys-value mappings in this map.
*/
size: function() { return private.map.length; },
/**
* Returns a string representation of this HashMap object in the form
* of a set of entries, enclosed in braces and separated by the ASCII
* characters ", " (comma and space).
*
* @return String The string representation of the mappings.
*/
toString: function()
{
var result = "[";
for ( var i in private.map )
{
if ( private.map[i] != null )
{
result += "{" + i + "},{" + private.map[i] + "}\n";
}
}
return result + "]";
},
/**
* Returns a array view of the values contained in this map.
*
* @return Array The array of values contained in this map.
*/
values: function()
{
var values = new Array();
for ( var i in private.map )
{
if ( private.map[i] != null )
{
values.push( private.map[i] );
}
}
return values;
}
};
return public;
}
}
/**
* Global variables.
*
* Note: It is assumed that the global variables
* firstFilmItem and firstTheatreItem are set
* with the text to be displayed as the first items in the select
* fields.
*/
var films = new affiliate.movie.Films( firstFilmItem );
affiliate.movie.affiliateId = 'ncwssj';
var requestParams = 'aid=ncwssj&v=1&rty=jsona&rvar=jsonf';
if(requestParams!='') {
document.write("");
document.write(" ");
}
function displayMovies() {
if(jsonf!=undefined) affiliate.movie.displayFilms(); //else setTimeout("displayMovies();", 1000);
}