$(document).ready(function(){
    // In IE6 + 7 there was an issue where these were not displaying
    // This is a temporary fix for this issue.
    setTimeout(function(){
        $('#betaBadge, #secondaryLogo').css('display', 'block');
    }, 200);
});

function showLogin() {
	$('#login').show();		
}
function hideLogin() {
	$('#login').hide();		
}

function clearField(ValueToClear, IdToClear) {
	if($('#'+IdToClear).val() == ValueToClear) {
		$('#'+IdToClear).val('');
	}
}
function setField(ValueToReplace, ValueToSet, IdToSet) {
	if($('#'+IdToSet).val() == ValueToReplace) {
		$('#'+IdToSet).val(ValueToSet);
	}
}


function CancelSendForm() {
	//hide 
	$('#recipient_email').val('Friend\'s email address');
	$('#btTell').show();
	$('#tellDesc').show();
	$('#friends-name').hide();
	$('#sender-details').hide();
	$('#form-actions').hide();
	clearSendError();
}

function ShowSendRest() {
	$('#btTell').hide();
	$('#tellDesc').hide();
	$('#friends-name').show();
	$('#sender-details').show();
	$('#form-actions').show();
}

function SubmitSendForm() {
	clearSendError();
	var Url = '/tell-a-friend/p/ajax/1';
	var Data = $("#frmTellFriend").serialize();
	$('#send_page').onclick=function() {
		return false;
	}
	$('#ajax-loader').show();
	$.ajax({
	    url: Url,
	    type: 'post',
	    data: Data,
	    dataType: 'json',
	    error: function(){
	        onSendError();
	    },
	    success: function(data) {	    	
	    	onSent(data);
	    }
	});

}

function onSent(Response) {
	$('#ajax-loader').hide();
	if(Response.Status && 'ok' == Response.Status && Response.Template) {
		$('#send-overlay').html(Response.Template);
	}
}

function onSendError() {
	$('#ajax-loader').hide();
	$('#message-container').html('Your request has timed out. please try again later');
	$('#message-container').show();
}

function clearSendError() {
	$('#message-container').html('');
	$('#message-container').hide();
	$('small.error-container').html('');
	$('div.error').removeClass('error');
}

function ShowBetaOverlay() {
	$('#overlay-beta').show();
	if(document.body.clientHeight) {
		$('#overlay-beta').css("height", document.body.clientHeight +'px');
		$('#overlay-beta').css("width", document.body.clientWidth +'px');
	} else {
		$("body").css("overflow","hidden");
	}
	$.scrollTo("#top",300);
}

function HideBetaOverlay() {
	$("body").css("overflow","visible");
	$('#overlay-beta').hide();
}