// Newsletter Signup - AW, 15/04/2008 //

newsletter = {
	
	response : function(doc, status) {
		
		if (status != 'success') {
			alert(status);
			return;
		}
		
		var node = doc.firstChild.firstChild;
		var status = node.firstChild.nodeValue;
		
		if (status == 'ok') {
			
			var tm = '';
			$('#contact_wait').hide();
	
			if ($('#checknewsletter').attr('checked'))
				tm += "<p>You have been subscribed to the SustainIT Newsletter and should receive email confirmation shortly.</p>";
			if ($('#checkcontact').attr('checked'))
				tm += "<p>We will contact you within the next 2 working days to discuss how we can help your business.</p>";
			tm = tm ? tm : "<p>Thankyou for adding your details.</p>";
			
			
			$('#thankyou_msg').html(tm);
			$('#finished').show();
			
		} else {
			$('#contact_errmsg').html('<div class="contact_errmsg_title"></div>' + 
			  '<div class="contact_errmsg">' + node.nextSibling.firstChild.nodeValue + '</div>')
				.show();
			$('.contact').toggle();		
		}
		
	},
	
	subscribe : function() {
		$('.contact').toggle();
		$('#newsletter_title').hide();
		$('#contact_errmsg').hide();
		$.post(_root + 'ajax/newsletter.php', 
			   'title='            + $('#title').attr('value') + 
			   '&firstname='       + escapeData($('#firstname').attr('value')) + 
			   '&surname='         + escapeData($('#surname').attr('value')) + 
			   '&email='           + escapeData($('#email').attr('value')) + 
			   '&company='         + escapeData($('#company').attr('value')) + 
			   '&checknewsletter=' + $('#checknewsletter').attr('checked') +
			   '&checkcontact='    + $('#checkcontact').attr('checked'),
			   this.response, 'xml'
		);
		
	}
	
	
};
