/*
 * JavaScript OutbackClub (requires jQuery)
 * http://www.rogerwestcreative.com
 * 
 * Date: 2009-03-02
 * Revision: 1.0
 */

var dialogWindowStatus = false;

function checkOutbackClubSignup()
{
	if (document.OutbackClub.email.value == "")
	{
		alert("Please enter your e-mail address.");
		document.OutbackClub.email.focus();
		return false;
	}
	else if (!IsEMail(document.OutbackClub.email.value)) 	 
	{
		alert("Please enter a valid e-mail address.");
		document.OutbackClub.email.focus();
		return false; 
	}
	return true;
}
function IsEMail(strEmail)
{
	rexEmailExp = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$");
	return rexEmailExp.test(strEmail);
}

function closeDialogWindow()
{
	if(dialogWindowStatus)
	{
		$("#dialogWindowBackground").fadeOut("slow");
		$("#dialogWindowFrame").hide();
		$("#dialogWindow").fadeOut("slow");
		dialogWindowStatus = false;
	}
}

function centerDialogWindow()
{
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#dialogWindow").height();
	var popupWidth = $("#dialogWindow").width();
	
	$("#dialogWindow").css({
		"position": "absolute",
		"top": windowHeight/2 - popupHeight/2,
		"left": (windowWidth/2 - popupWidth/2)
	});
	$("#dialogWindowFrame").css({
		"position": "absolute",
		"top": windowHeight/2 - popupHeight/2,
		"left": (windowWidth/2 - popupWidth/2)
	});
	
	// only need force for IE6
	$("#dialogWindowBackground").css({"height": windowHeight});
}

function loadDialogWindow()
{
	if (!dialogWindowStatus)
	{
		centerDialogWindow();
		$("#dialogWindowBackground").css({"opacity": "0.7"});
		$("#dialogWindowBackground").fadeIn("slow");
		$("#dialogWindow").fadeIn("slow");
		$("#dialogWindowFrame").show();
		dialogWindowStatus = true;
	}
}

function processOutbackClubSignup()
{
	if (!checkOutbackClubSignup())
	{
		return false;
	}
	else
	{
		alert("Thank you for joining the Outback Club!\n\nPlease check your inbox to confirm your subscription.");
		return true;
	}
}

$(document).ready(function(){
	
	//$("#dialogWindow").draggable();
	
	$("#dialogWindowCloseX").click(function(){
		closeDialogWindow();
	});
	$("#dialogWindowCloseButton").click(function(){
		closeDialogWindow();
	});
	
	$("#dialogWindowBackground").click(function(){
		closeDialogWindow();
	});
	
	$(document).keypress(function(e){
		if (e.keyCode == 27 && dialogWindowStatus) {
			closeDialogWindow();
		}
	});
});


//====================================================
// modal dialog box
//====================================================
$(document).ready(function(){

	$('.clickHere').click(function(evt){
		//cancels the link function.
		evt.preventDefault();
		
		//gets the current resolution of the screen.
		var maskHeight =  $(document).height();
		var maskWidth = $(window).width();
		
		//assigns the values to the mask div.
		$('#mask').css({'width': maskWidth, 'height': maskHeight});
		
		//transition effects.
		$('#mask').fadeIn(500);
		$('#mask').fadeTo('slow', 0.25);
		
		//Get the window height and width
		var winH = $(document).height();
		var winW = $(window).width();
		
		//Set the popup window to center
		$('#carpetSample').css('top',  (winH / 2) + $('#carpetSample').height() /1.5);
		$('#carpetSample').css('left', winW/2-$('#carpetSample').width()/2);
	

		//transition effect
		$('#carpetSample').fadeIn(1000); 
		$('.caption').fadeTo('slow', 0.75);
	});
	
	$('#mask').click(function(){
		$(this).fadeOut('slow');
		$('#carpetSample').fadeOut('slow');
	});
	
	$('.closeBtn').click(function(){
		$('#mask').fadeOut('slow');
		$('#carpetSample').fadeOut('slow')
	});
	
});

$(document).ready(function(){
	/*$('#joinclub a').click(function(){
		alert('This form is disabled for the meantime.');
	});*/
	
	$('#joinTheClub a').click(function(){
		alert('This form is disabled for the meantime.');
	});
});

function tempContactUs() {
	alert('This form is disabled for the meantime.');	
	return false;
}
