// jQuery ------------------------------------------------------------------------------//
$(document).ready(function(){ 

// post settings -----------------------------------------------------------------------//
var options = {
	url:	'../code/mastercode.cfm', 
	success: function(data) {
		//hideLoader();
		if(data.search("false") != "-1"){
			alert("Sorry this email address is already registered.\nWe can only accept one entry per person.");
		} else {
			$("#formHolder").fadeOut('fast', function() { $("#formHolderB").fadeIn('fast'); }); }
		} 
	};
		
	$('#form_competition').ajaxForm(options); 
	

// End -------------------------------------------------------------------------------- //
activeURL = window.location.protocol + "//" + window.location.host;
$("#twitterFeed").load("http://thegreatbake.bacheldremill.co.uk/code/mastercode.cfm?action=grabTwitter");
});

// Tell mate -------------------------------------------------------------------------- //
function tellMate(emailTo, emailFrom) {
	$.ajax({
   		type: "POST",
   		url: "code/mastercode.cfm",
   		data: "action=tellFriend&emailTo="+emailTo+"&emailFrom="+emailFrom,
		success: function(data){
     		$("#sendBtn").fadeOut('fast');
			$(".friendInput2").fadeOut('fast', function(){
														 $("#thankYou").fadeIn('fast');
														});
   		} });
}

// Check email exists ----------------------------------------------------------------- //
function checkEmail(email) {
	$.ajax({
   		type: "POST",
   		url: "code/mastercode.cfm",
   		data: "action=checkEmail&email="+email,
		success: function(data){
     		if(data == "true") {
				document.form_competition.email.value = 'Sorry email already registered';
				document.form_competition.email.focus();
				document.form_competition.email.select();
			}
   		} });
}

// Loader icon functions -------------------------------------------------------------- //
function showLoader() {
	$(".searchSubmit").hide();
	$(".loadingIcon").show(); 
	}
	
function hideLoader() {
	$(".loadingIcon").hide();
	$(".searchSubmit").show(); 
	}
	
// Form clear & appear functions ------------------------------------------------------- //	
function clearField(fieldId, baseTxt) {
	if(baseTxt == fieldId.value) {
		fieldId.value = ''; }	
}

function setField(fieldId, baseTxt) {
	if(fieldId.value == '') {
		fieldId.value = baseTxt; }
}

function tellFriendNext() {
	$("#nextStep").fadeOut();
	$(".friendInput").fadeOut('slow', function(){ 
											   $(".friendInput2").fadeIn('slow');
											   $("#sendBtn").fadeIn('slow');});	
}
// End -------------------------------------------------------------------------------- //
