// Copyright 2007 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 adding a quote.
 */


function VBY_AddQuote(win, doc) {
  this.doc_ = doc;
  this.win_ = win;
}

VBY_AddQuote.prototype.setupQuotes = function (movieId, characters) {
	this.lineCount_ = $("line_count");
	this.movieId_ = movieId;
	this.position_ = 1;

	new Autocompleter.Local('character_1', 'character_ac_1', characters, {});
};

VBY_AddQuote.prototype.addLine = function (link) {
	var currentLine = $("line_sec_" + this.position_);
	var newLine = currentLine.cloneNode(true);	

	this.position_++;
	this.lineCount_.value = this.position_;

	newLine.id = "line_sec_" + this.position_;
	
	var newCharInput = getFirstElementByTagAndClassName("input", null, newLine);
	newCharInput.id = "character_" + this.position_;
	newCharInput.name = "character_" + this.position_;
	var newCharACDiv = getFirstElementByTagAndClassName("div", "auto_complete", 
																											newLine);
	newCharACDiv.id = "character_ac_" + this.position_;
	var numberDiv = getFirstElementByTagAndClassName("div", "number", newLine);
	numberDiv.innerHTML = this.position_;
	
	var newLineInput = getFirstElementByTagAndClassName("textarea", null, newLine);
	newLineInput.id = "line_" + this.position_;
	newLineInput.name = "line_" + this.position_;
	
	insertSiblingNodesAfter(currentLine, newLine);
	
	new Autocompleter.Local('character_' + this.position_, 
	    'character_ac_' + this.position_, characters, {});
};