
/*
FILE CONCAT ADD FILE
PATH: /ft/resources/client/modules/glossary/AddEditTermCategories.js
*/
var AddEditTermCategories_class = function(oCategories) {
	this.categories = oCategories || {};
}

AddEditTermCategories_class.prototype.init = function() {	
	Events.add(Element.parseSelector("div.currCategoryHolder", "wsod"), "click", this.removeTerm, this);
	Events.add(Element.parseSelector("select.category", "wsod", "first"), "change", this.addCategory, this);
	
	this.categoryDivs = Element.parseSelector("div.categoryHolder", "wsod");
}

AddEditTermCategories_class.prototype.addCategory = function(e, el) {
	var currCategory = el.value;
	var container = Element.parseSelector("div.currCategoryHolder", "wsod", "first");
	var aCategoryList = [];
	
	for (var i=0; i<this.categoryDivs.length; i++){
		aCategoryList.push(this.categoryDivs[i].getAttribute("category"))
	}
	var oCategories = Common.convertArrayToObject(aCategoryList)
	
	if(currCategory != "default" && !oCategories[currCategory]){
		Element.create("div", {"class":"addedCategory categoryHolder", "category": currCategory},[
			Element.create("div", {"class":"currCategory"}, currCategory),
			Element.create("div", {"class":"icon icon-delete-close deleteCategoryIcon"},[])
		], container);
		
		this.categories[currCategory] = {
			name: currCategory,
			type: 'added'
		}
	}
}

AddEditTermCategories_class.prototype.removeTerm = function(e, el) {
	var target = e.getTarget();

	if (Element.hasClass(target, "icon-delete-close")) {
		var parentDiv = Element.getParentBySelector(target, "div.categoryHolder")
		var category = parentDiv.getAttribute("category")
		
		this.categories[category] = {
			name: category,
			type: 'remove'
		}
		
		Element.remove(parentDiv)
	}
}
/*
FILE CONCAT ADD FILE
PATH: /ft/resources/client/modules/markets/sectorsAndIndustries/industryDropDown.js
*/
var IndustryDropDown = function() {
    this.hasTitle(false);
    this.hasCloseLink(false);

    var preload = new Image();
        preload.src = this.SRC_ACTIVE_ICON;
}

IndustryDropDown.Extend(Popup);

IndustryDropDown.prototype.ICON_SIZE = 24;
IndustryDropDown.prototype.ICON_HORIZONTAL_OFFSET = 10;
IndustryDropDown.prototype.POPUP_SIZE = 325;

IndustryDropDown.prototype.CSS_DROPDOWN = "industryListDropDown";
IndustryDropDown.prototype.CSS_DROPDOWN_TEXT = "industryDropDownText";
IndustryDropDown.prototype.BUFFER_URL = '/ft/resources/buffer/sectorsAndIndustries/getListOfIndustries.asp'
IndustryDropDown.prototype.URL_LINKS = "/ft/markets/sectorsAndIndustries/industries.asp";
IndustryDropDown.prototype.SRC_ACTIVE_ICON = "/ft/resources/image/dropdown-active.gif";

IndustryDropDown.prototype.init = function() {
    var dropDownLink = WSDOM.Element.get('industryDropDown');
    WSDOM.Events.add(dropDownLink, 'click', this.draw, this)
}

IndustryDropDown.prototype.getAnchorElement = function() { return null; }
IndustryDropDown.prototype.setAnchorElement = function(el) {
    el = Element.get(el);

    this.getAnchorElement = function() {
        return el;
    }
}

IndustryDropDown.prototype.position = function() {
    var contentWell = Element.getXY(Element.get("wsod"));

    var view = Element.getViewport();
    var frame = this.getFrame();

    var frameSize = Element.getSize(frame);

    var frameTop, frameLeft;
    if (this.getAnchorElement()) {
        var anchorXY = Element.getXY(this.getAnchorElement());
        var anchorSize = Element.getSize(this.getAnchorElement());

        frameTop = anchorXY.y + this.ICON_SIZE;

        if (anchorXY.x - this.POPUP_SIZE < contentWell.x) {
            frameLeft = anchorXY.x - this.ICON_HORIZONTAL_OFFSET;
        } else {
            frameLeft = anchorXY.x + anchorSize.width - frameSize.width + this.ICON_HORIZONTAL_OFFSET;
        }
    } else {
        frameTop = Math.max(view.top + (view.height / 2) - (frameSize.height / 2), 0) - contentWell.y;
        frameLeft = Math.max((view.width / 2) - (frameSize.width / 2), 0) - contentWell.x;
    }

    Element.setXY(frame, frameLeft, frameTop);
    this.sizeShim();
    // add a class instead
    frame.style.visibility = 'visible';
};

IndustryDropDown.prototype.getDropDownListContent = function(args) {
    
    var cb = this.getContentBuffer();

    var conn = cb.load({
        debug: true,
        url: this.BUFFER_URL,
        method: "post",
        contentType: "text/javascript",
        preventEval: true,
        context: this,
        data: {
            wsodIssue: args.symbol
            ,pageType: args.pageType
        },
        onload: this.buildDropDown
    });
}

IndustryDropDown.prototype.close = function(e, el) {
    IndustryDropDown.Super(this, ["close"]);
};

IndustryDropDown.prototype.draw = function(e, el) {
    this.setAnchorElement(el);

    if (!Element.hasClass(this.getFrame(), this.CSS_DROPDOWN)) {
        Element.addClass(this.getFrame(), this.CSS_DROPDOWN);

        Element.addChild(this.getContent(),
			    Element.create("div", { "class": "placeholder" })
		    );

        var closeSide = "right";
        if (Element.getXY(this.getAnchorElement()).x - this.POPUP_SIZE < Element.getXY("wsod").x) {
            closeSide = "left";
        }

        Element.addChild(this.getFrame(),
			    Element.create("img", { "class": "closeDropDown", "src": this.SRC_ACTIVE_ICON, "style": "top:" + ((this.ICON_SIZE - 1) * -1) + "px;" + closeSide + ":" + this.ICON_HORIZONTAL_OFFSET + "px;", "Events":
				    { "type": "click", "handler": this.close, "context": this }
			    })
		    );
    }

    var frame = this.getFrame();
    Element.removeClass(frame, this.CSS_HIDDEN);

    this.position();
    
    this.SECTOR_NAME = el.getAttribute('sectorName');
    this.IS_INDUSTRY = el.getAttribute('isIndustry');

    this.getDropDownListContent({
        symbol: el.getAttribute('symbol')
	    , pageType: el.getAttribute('pageType')
    });

    //IndustryDropDown.Super(this, ["draw"]);    
}

IndustryDropDown.prototype.buildDropDown = function(cb) {
    var results = new Serializer().deserialize(cb.getResult());

    Element.removeChildNodes(this.getContent());

    var dropDownContent = Element.create("div"),
        table,
        tbody;

    table = Element.create("table", {}, [
		tbody = Element.create("tbody")
	])

    for (var i = 0; i < results.length; i++) {
        if (results[i].wsodIssue != -32768) {
            Element.create("tr", {}, [
			    Element.create("td", { "class": "textLeft" }, [
				    Element.create("a", { "href": this.URL_LINKS + "?s=" + results[i].wsodIssue }, results[i].fullName)
			    ]),
		    ], tbody);
        }
    }

    if (results.length) {
        if (this.IS_INDUSTRY == 'true') {
            var text = "There are " + results.length + " other industries in the " + this.SECTOR_NAME + " sector.";
        } else {
            var text = "There are " + results.length + " industries in the " + this.SECTOR_NAME + " sector.";
        }
        Element.create("div", { "class": this.CSS_DROPDOWN_TEXT }, text, dropDownContent)
    }

    Element.addChild(dropDownContent, table);

    Element.addChild(this.getContent(), dropDownContent);

    this.sizeShim();

    this.getDropDownListContent = function() { return; }
    this.buildDropDown = function() { return; }
}

IndustryDropDown.prototype.getContentBuffer = function() {
    var cb = new ContentBuffer();

    this.getContentBuffer = function() {
        return cb;
    }

    return this.getContentBuffer();
}
/*
FILE CONCAT ADD FILE
PATH: /ft/resources/client/modules/glossary/FailedSearches.js
*/
var FailedSearches_class = function() {}

FailedSearches_class.prototype.init = function(){
	Events.add(Element.parseSelector("div.deleteTerm", Element.get("termsListTable")), "click", this.deleteTerm, this);
}

FailedSearches_class.prototype.deleteTerm = function(e, el){
	e.cancel();

	var deleteConfirm = confirm("Are you sure you want to delete this term?");

	if (deleteConfirm ){
		var cb = new ContentBuffer();
		
		var conn = cb.load({
			debug: true,
			url: "/ft/resources/buffer/glossaryDeleteTerm.asp",
			method: "post",
			contentType: "text/javascript",
			preventEval: false,
			data: {
				term: el.getAttribute("term")
			},
			onload: function() {
				alert("Term has been deleted.");
				location.href = location.href;
			}
		});

	}else {
		alert("Term was not deleted.")
	}
}