// tell a friend overlay in
function tafIn()
{
	$('#tafOverlay').css({display: "none"}).load('taf.aspx #tafInner', function() {
	
	    $('#tafOverlay').fadeIn('slow');
		
		// code to populate preview with text on unfocus
		var f = $('#ctl00_cphMainContent_friendName').attr('value');
		
			if(f != "") {
				$('#yourFriendName').text(f);
			} else {
				$('#yourFriendName').text("your friend's name");
			}

		$('#ctl00_cphMainContent_friendName').blur(function() {
			if ($(this).attr('value') != "") {
				$('#yourFriendName').text($(this).attr('value'));
			} else {
				$('#yourFriendName').text("your friend's name");
			}
		});
		
		// validation
		$.getScript('js/jquery.validate.js', function() {
			$("#aspnetForm").validate({
				
				rules: {
					'ctl00$cphMainContent$yourName': "required",
					'ctl00$cphMainContent$yourEmail': {
						required: true,
						email: true
					},
					'ctl00$cphMainContent$friendName': "required",
					'ctl00$cphMainContent$friendEmail': {
						required: true,
						email: true
					},
					'ctl00$cphMainContent$optIn': "required"
				},
				
				// make sure to make .error display:none is css because this jquery.validate adds it's own classes..!
				
				highlight: function(element) {
					 $(element.form).find("label[for=" + element.id + "]").css('color', '#f00');
					 $('label.error').css({display: "none"});
				},
				unhighlight: function(element) {
					 $(element.form).find("label[for=" + element.id + "]").css('color', '#fff');
				},
				
				// for attributes
				messages: {
					'ctl00$cphMainContent$yourName': "",
					'ctl00$cphMainContent$yourEmail': {
						required: "",
						email: ""
					},
					'ctl00$cphMainContent$friendName': "",
					'ctl00$cphMainContent$friendEmail': {
						required: "",
						email: ""
					},
					'ctl00$cphMainContent$optIn': ""
				},
				
				submitHandler: function() {
				
					jQuery.post('/uk/lipfinity/taf-flash.aspx', {
						'ctl00$cphMainContent$yourName': $("#ctl00_cphMainContent_yourName").attr("value"),
						'ctl00$cphMainContent$yourEmail': $("#ctl00_cphMainContent_yourEmail").attr("value"),
						'ctl00$cphMainContent$friendName': $("#ctl00_cphMainContent_friendName").attr("value"),
						'ctl00$cphMainContent$friendEmail': $("#ctl00_cphMainContent_friendEmail").attr("value"),
						'ctl00$cphMainContent$optIn': true,
						'ctl00$cphMainContent$ImageButton1': true
					});
					
					$('#formInner').fadeOut('normal', function() {
						$('#thanks').fadeIn('normal');
					});
					$('#ctl00_cphMainContent_ImageButton1').animate({opacity: "0"}).css({display: 'none'});
					$('#preview *').animate({opacity: "0.5"});
					
					return false;
				
				}
			});
		});
	});
}

// tell a friend overlay out
function tafOut()
{
	    $('#tafOverlay').fadeOut('slow');
}

// compeition max club member sniffer in
function compIn()
{
	$('#compOverlay').css({display: "none"}).load('max-club-member.aspx #tafContainer', function() {
	    $('#overlay').fadeIn('slow', function() {
	        $('#compOverlay').fadeIn('slow');
	    });
		
	});
}

// compeition max club member sniffer out
function compOut()
{
	$('#compOverlay').fadeOut('slow', function() {
	    $('#overlay').fadeOut('slow');
	});
}

// terms popup control
window.onload = function() {
	if (!document.getElementsByTagName) {
		return false; 
	} 
	var popuplinks = document.getElementsByTagName("a");
	for (var i=0; i < popuplinks.length; i++) {
		if (popuplinks[i].className == "popup") {
			popuplinks[i].onclick = function() {
			openPopUp(this.getAttribute("href"));
			return false;
			}
		}
	} 
} 

function openPopUp(linkURL) {
window.open(linkURL,'popup','width=525,height=600,scrollbars=yes,resizable=yes')
}


