
var OffersSignup = {		
	init: function(options)
    {
		OffersSignup.openPopup(options.offersSignupUrl);
    },
    
    openPopup: function(offersSignupUrl)
    {
    	$('#offers-signup-button').click(function() {
    		if (empty($('form#offers-signup-form input[name="fname"]').val())) {
    			alert('Please enter your name');
    			return false;
    		}
    		if (empty($('form#offers-signup-form input[name="email"]').val())) {
    			alert('Please enter your email address');
    			return false;
    		}   		
    		if (false === isValidEmail($('form#offers-signup-form input[name="email"]').val())) {
    			return false;
    		};
    		var data = $('form#offers-signup-form').serialize();
    		var fancyUrl = offersSignupUrl + '?' + data; 
    		$.fancybox({    			
    			'padding'		: 0,
    			'autoScale'		: true,
    			'transitionIn'	: 'none',
    			'transitionOut'	: 'none',
    			'title'			: '',
    			'width'		    : 680,
    			'height'		: 595,
    			'href'			: fancyUrl,
    			'type'			: 'iframe'
    		});
    	});
    	return false;
    }
};

function implode (glue, pieces) {
    var i = '', retVal='', tGlue='';
    if (arguments.length === 1) {
        pieces = glue;
        glue = '';
    }
    if (typeof(pieces) === 'object') {
        if (pieces instanceof Array) {
            return pieces.join(glue);
        }
        else {
            for (i in pieces) {
                retVal += tGlue + pieces[i];
                tGlue = glue;
            }
            return retVal;
        }
    }
    else {
        return pieces;
    }
}

function isValidEmail(strEmail)
{
	var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    if (strEmail.search(validRegExp) == -1) {
    	alert('\'' + strEmail + '\' is no valid email address in the basic format local-part@hostname');
    	return false;
    } 
    return true; 
}
