YAHOO.namespace("Estalea.util");

YAHOO.Estalea.util.Pop = function(cfg){
    this.limitCount = 1;
    this.shouldPop = true;
    this.url = cfg.url;
    this.width = cfg.width;
    this.height = cfg.height;
    this.type = cfg.type;
    this.features = 'location=0,menubar=0,resizable=yes,scrollbars=yes,width=' + this.width + ',height=' + this.height;
    this.limit = 1;
    if(cfg.limit) {
    	this.limit = cfg.limit;	
    }
    
    this.element = window;
    
    this.eventType = 'load';
    if (this.type == 'EXIT_POP') { // this was kept to avoid breaking old code, but should be removed and the event set to unload everywhere that EXIT_POP has been set
        this.eventType = 'unload';
    }
    
    if(cfg.event) {
    	this.eventType = cfg.event;
    }
    this.preventPop = false;

    YAHOO.util.Event.onDOMReady(function(){
    	if(cfg.el) {
        	this.element = cfg.el;	
        }
    	if(this.eventType == 'submit') {
    		this.element = document.getElementsByTagName('form')[0];
    	}
    	YAHOO.util.Event.on(this.element, this.eventType, this.popupWindow, this, true);
    },null,this);
    
};

<!-- This section can be overriden to implement custom behavior -->
YAHOO.Estalea.util.Pop.prototype = {

    popupWindow : function(event){
        if (this.type != 'EXIT_POP') {
						
            YAHOO.util.Event.stopEvent(event);
            var newPopupWindow = window.open(this.url, '_blank', this.features);
	    	
            if(newPopupWindow) {
                if(this.type == 'POPBEHIND') {
                    newPopupWindow.blur();
                    window.focus();
                } else if (this.type == 'EXIT_POP') {
                    newPopupWindow.focus();
                }
            }
            if(this.limitCount >= this.limit) {
				YAHOO.util.Event.removeListener(this.element, this.eventType,this.popupWindow);
        	}
        	this.limitCount++;
            return newPopupWindow;
        }
    }
};


YAHOO.Estalea.util.Pixel = function(cfg){

    this.url = cfg.url;
    YAHOO.util.Event.on(window, "load", this.addPixel, this, true);
};


YAHOO.Estalea.util.Pixel.prototype = {

    addPixel : function(event){
        var img = document.createElement('img');
        img.width = "1";
        img.height = "1";
        img.src = this.url;    
        document.body.appendChild(img);
    }
};
