var bookmarkPopupManager = Class.create({
    initialize: function() {
        this.myWindow = "";
        this.currTitle = "";
        this.currURL = "";
        this.currPrivate = 0;
        this.currTerms = "";
    },
    load: function(title, url, terms,itemTerm) {
        this.currTitle = title;
        this.currURL = url;
        this.currTerms = terms;
        this.itemTerm = itemTerm;
        this.displayPopup();
    },
    popupSubmitBookmark: function() {
	    this.myWindow.opener.layoutManager.currentPage.title = unescape(this.currTitle);
	    //this.myWindow.opener.layoutManager.currentPage.title =this.currTitle;
        this.currTerms = this.myWindow.document.getElementById('bookmarkTerms').value;
        if(this.myWindow.document.getElementById('privateBookmark').checked == true) {
            this.currPrivate = 1;
        }

        bookmarkManager.privateBookmark = this.currPrivate;
		this.currPrivate = 0;
        bookmarkManager.bookmarkTerms = this.currTerms;
		
		var display_confirm = (document.cookie.indexOf('yv_bookmarks_show_confirm=0') != -1) ? false : true;
		if (!display_confirm) {
	        this.myWindow.close();            
        }
        
        bookmarkManager.bookmarkThis();
        this.myWindow.document.getElementById('privateBookmark').checked = '';
    },
    onTitleChange: function() {
        this.currTitle = this.myWindow.document.getElementById('bookmarkPageTitle').value;
    //console.log('[bookmarkPopupManager] detected ' + this.bookmarkTitle + ' as title');
    },
    displayPopup: function() {
        this.myWindow = window.open('index.php?u=bookmarkpopup&item_term='+this.itemTerm,'popupWindow','height=290,width=460,toolbar=no,directories=no, status=no, menubar=no, scrollbars=no, location=no, top=250, left=300');
        this.myWindow.focus();
    },   
    setTitle: function() { //changes the value in the textfield to be some title.
    this.currTitle = this.currTitle.gsub('&#039;',"'");
	this.myWindow.document.getElementById('bookmarkPageTitle').value = unescape(this.currTitle);
    //console.log('attempted to change the title in the popup');
    },
    setURL: function() { //changes the text below the textfield to contain the url...
        var decodedURL = unescape(this.currURL);
        this.myWindow.document.getElementById('urlText').innerHTML = decodedURL.truncate(45);
        //console.log('attempted to change the URL in the popup');
    },
    hide: function() {
        if (this.myWindow != "") {
            this.myWindow.close();
            this.myWindow = "";
        }
    }
});

var myBookmarkPopupManager = new bookmarkPopupManager();

