/**
 * DISABLED
 */

jQuery(document).ready(function() {

	function newsletterCookieSet() {
		var cookie_date = new Date();
		cookie_date.setTime(cookie_date.getTime() + 1000 * 60 * 60 * 24 * 365);
		document.cookie = 'newsletter-widget=closed; expires=' + cookie_date.toGMTString() + ';';
	}

	jQuery.extend({
		newsletterSubmit : function() {
			// if (emdCheckSubmitForm()) {//temporary disabled
			if (true) {
				newsletterCookieSet();
				return true;
			}
			return false;
		}
	});

	function ReadCookie(cookieName) {
		var theCookie = " " + document.cookie;
		var ind = theCookie.indexOf(" " + cookieName + "=");
		if (ind == -1)
			ind = theCookie.indexOf(";" + cookieName + "=");
		if (ind == -1 || cookieName == "")
			return "";
		var ind1 = theCookie.indexOf(";", ind + 1);
		if (ind1 == -1)
			ind1 = theCookie.length;
		return unescape(theCookie.substring(ind + cookieName.length + 2, ind1));
	}

	cookieStatus = ReadCookie('newsletter-widget');

	if (cookieStatus == 'closed') {
		return;
	}

	jQuery('#newsletter input:text').bind('click', function() {
		jQuery(this).val('');
		jQuery(this).unbind('click');
	});

	// if close button is clicked
	jQuery('#newsletter #nl-headbar-close').click(function(e) {
		jQuery('#mask, #newsletter').hide();
		newsletterCookieSet();
	});

	displayOverlay();

	function displayOverlay() {
		// Get the screen height and width
		var maskHeight = jQuery(document).height();
		var maskWidth = jQuery(window).width();

		// Set height and width to mask to fill up the whole screen
		jQuery('#mask').css({
			'width' : maskWidth,
			'height' : maskHeight
		});

		// transition effect
		jQuery('#mask').fadeIn(200);
		jQuery('#mask').fadeTo("fast", 0.6);

		// Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();

		var newsletter = jQuery('#newsletter');
		var nlTop = winH / 2 - newsletter.height() / 2;
		var nlLeft = winW / 2 - newsletter.width() / 2;

		// Set the popup window to center
		newsletter.css('top', nlTop);
		newsletter.css('left', nlLeft);

		// transition effect
		newsletter.fadeIn(300);
	}

});
