if (typeof(newsletterSubscriptionObject) == 'undefined') 
{
    newsletterSubscriptionObject = function(objectName, useAlertResponse, ajaxEventUID)
    {
    	this.objectName       = objectName;
    	this.useAlertResponse = useAlertResponse; 
    	this.ajaxEventUID     = ajaxEventUID;
    }
}
newsletterSubscriptionObject.prototype.init = function()
{
	var currentObject     = this;		
	this.defaultValue     = $('#' + this.objectName + '_Email').val();	
	this.loaderHtml       = $('#' + this.objectName + '_Messagebox').html();
	$('#' + this.objectName + '_Messagebox').html('');		
	$('#' + this.objectName + '_Messagebox').show();		
	$('#' + this.objectName + '_Email').toggleVal();	
	$('#' + this.objectName + '_Submit').click(function() { currentObject.submit() } );
	$('#' + this.objectName + '_Email').setEnterHandler(function() { currentObject.submit() } );		    
}
newsletterSubscriptionObject.prototype.submit = function()
{
	var currentObject = this;
	$('#' + this.objectName + '_Body').hide();		
	$('#' + this.objectName + '_Messagebox').show();		
	$('#' + this.objectName + '_Messagebox').html(this.loaderHtml);
	var email = $('#' + this.objectName + '_Email').val(); 
	
	var postData = { __callHandler: 'addNewsletterSubscriber', 
	  		         email: email 
	}; 
	postData[currentObject.objectName + '__ajaxEventUID'] = this.ajaxEventUID;
	
	$.post(selfUrl, postData,	
	function(responseData) { 
  		currentObject.onGetResponse(responseData); 
	},
	'json');
}
newsletterSubscriptionObject.prototype.onGetResponse = function(responseData)
{
    if ((typeof(showAJAXDebugInfo) != 'undefined') && responseData.PHPAJAXDebug != null) 
    {
        showAJAXDebugInfo(responseData.PHPAJAXDebug.Info, responseData.PHPAJAXDebug.Owner);
    }
	
	if (responseData.Response.Code == 1)
	{
		$('#' + this.objectName + '_Body').show();		
		$('#' + this.objectName + '_Messagebox').hide();
                //alert(responseData.Response.Message); comment by priyanka		
		popup(responseData.Response.Message);
	}
	else
	{
		$('#' + this.objectName + '_Email').val(this.defaultValue);
		if (!this.useAlertResponse)
		{
			$('#' + this.objectName + '_Messagebox').html(responseData.Response.Message);		
		}
		else
		{
			$('#' + this.objectName + '_Body').show();		
			$('#' + this.objectName + '_Messagebox').hide();		
			//alert(responseData.Response.Message); comment by priyanka
			popup(responseData.Response.Message);
		} 
	}
}

//added by priyanka
$(document).ready(function () {
 
    // if user clicked on button, the overlay layer or the dialogbox, close the dialog  
    $('a.btn-ok, #dialog-overlay, #dialog-box').click(function () {     
        $('#dialog-overlay, #dialog-box').hide();       
        return false;
    });
     
    // if user resize the window, call the same function again
    // to make sure the overlay fills the screen and dialogbox aligned to center    
    $(window).resize(function () {
         
        //only do it if the dialog box is not hidden
        if (!$('#dialog-box').is(':hidden')) popup();       
    }); 
     
     
});

//Popup dialog
function popup(message) {
         
    // get the screen height and width  
    var maskHeight = $(document).height();  
    var maskWidth = $(window).width();

    //code added by priyanka
    var mheight1 = (maskHeight/3);
    var mheight2 = (mheight1/2);
    //end of added code

     // calculate the values for center alignment
    var dialogTop = (maskHeight-mheight2);
   //org var dialogTop =  (maskHeight/3) - ($('#dialog-box').height());  comment by priyanka
    var dialogLeft = (maskWidth/2) - ($('#dialog-box').width()/2); 

    // assign values to the overlay and dialog box
    $('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();
    $('#dialog-box').css({top:dialogTop, left:dialogLeft}).show();
     
    // display the message
    $('#dialog-message').html(message);
             
}
//end of function
