// Copyright 2008 Google Inc.
// All Rights Reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * Javascript for the "Movies" and individual Movie page.
 */

function MoviePage(win, doc, main, isAuthenticated, movieId) {

  this.doc_ = doc;
  this.win_ = win;
  
  // VBY_Main object
  this.main_ = main;
  
  this.ratings_ = {};
  
  this.isFirst_ = {};
  this.isFirst_.userQuotes = true;
  this.isFirst_.script = true;
  
  this.scriptBlock_ = getElement("script_list");
  this.userQuotesBlock_ = getElement("userquotes_list");
  this.scriptLoad_ = getElement("script_load");
  this.userQuotesLoad_ = getElement("userquotes_load");
  this.movieSearch_ = getElement("movie_search");
  if (this.movieSearch_) this.movieSearch_.focus();
  
  this.movieId_ = movieId;
  
  this.isAuthenticated_ = isAuthenticated;
}

MoviePage.submitMovie = function () {
	if (VBY_AC_SELECTED) {
		return true;
	} else {
		showElement("mp_msg");
		return false;
	}
};

MoviePage.verifyAcSelection = function (acInput, acItem) {
	VBY_AC_SELECTED = true;
};

MoviePage.prototype.setupAc = function () {
	connect("movie_select", "onkeydown", bind(this.resetAcFlag_, this));
};

MoviePage.prototype.resetAcFlag_ = function (e) {
	if (e.key().string != "KEY_ENTER") {
	  VBY_AC_SELECTED = false;
	}
};
