//Newsletter Class
var Successpopup = Class.create();
Successpopup.prototype = {
    initialize: function(form, getSubscribeUrl){
        this.form = form;
        
		this.getSubscribeUrl = getSubscribeUrl;
		this.onComplete = this.resetLoadWaiting.bindAsEventListener(this);
		this.containerSuffix = '';
    },
	
	_disableEnableAll: function(element, isDisabled) {
        var descendants = element.descendants();
        for (var k in descendants) {
            descendants[k].disabled = isDisabled;
        }
        element.disabled = isDisabled;
    },
	
	resetLoadWaiting: function(transport){
        this.setLoadWaiting(false);
    },
	
	setLoadWaiting: function(enable) {
        if (enable) {
			var container = $('news-container'+this.containerSuffix);
            container.setStyle({opacity:.5});
            this._disableEnableAll(container, true);
            Element.show('news-please-wait'+this.containerSuffix);
        }
		else {
			var container = $('news-container'+this.containerSuffix);
            container.setStyle({opacity:1});
            this._disableEnableAll(container, false);
            Element.hide('news-please-wait'+this.containerSuffix);
        }
    },
	
    getsuccessPopup: function(){  
			this.setLoadWaiting(true);
            var request = new Ajax.Request(
                this.getSubscribeUrl,
                {
                    method: 'post',
					onComplete: this.onComplete,
                    onFailure: function(response){
						alert('An error occurred while processing your request');
						this.onComplete;
					},
					onSuccess: function(response){
						if(response.responseText!=''){
							$('newsletter-popup-added').style.display='';
							$('newsletter-popup-added').style.left = xstooltip_findPosX($('btnnewsletter')) - 292 + "px";
							$('newsletter-popup-added').style.top = xstooltip_findPosY($('btnnewsletter')) - 124 + "px";
							$('newsletter-msgs').innerHTML = response.responseText;
							$('newsletter').value='Enter your email address';
						}
						else{
							$('newsletter-popup-added').style.display='none';
							$('newsletter').value='Enter your email address';
						}
					},
                    parameters: Form.serialize(this.form)
                }
            );
	}
}
