﻿/*********************************************
** Title..........: Homepage Functions for MarthaBorst.com
** Filename.......: /atom_theme/js/pageHome.js
** Website........: Martha Borst
**
** Author.........: Loren Dias
** Build..........: July, 2009
** Version........: 2009.07.07  14:30
*********************************************/
/* (B) START the Popup with jQuery          */

$(document).ready(function() {

	$("#validate").keyup(function(){
	
		var sEmail = $("#validate").val();
	
		if(sEmail != 0)
		{
			if(isValidEmailAddress(sEmail))
			{
				$("#validEmail").css({
					"background-image": "url('atom_theme/images/formValidYes.png')"
				});
			} else {
				$("#validEmail").css({
					"background-image": "url('atom_theme/images/formValidNo.png')"
				});
			}
		} else {
			$("#validEmail").css({
				"background-image": "none"
			});			
		}
	
	});

});

/* (E) START the Popup with jQuery          */
/********************************************/
/* (B) Homepage Form Functions              */

function isValidEmailAddress(sEmail) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(sEmail);
}

function homePopupForm_Submit() {
	var sName		= document.homePopupForm.Name.value;
	var sEmail		= document.homePopupForm.Email.value;
	
	if (isValidEmailAddress(sEmail) == true) {
		document.homePopupForm.submit();
	} else {
		alert("Please check that your Name & Email Address are entered correctly and try again. Thank You.");
		return false;
	}
}

/* (E) Homepage Form Functions              */
/********************************************/
/* (B) Popup jQuery Code                    */

/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#homePopupBG").css({
			"opacity": "0.7"
		});
		$("#homePopupBG").fadeIn("slow");
		/*$("#homePopup").fadeIn("slow");*/
		$("#homePopup").show("drop", { direction: "up" }, 1000);
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#homePopupBG").fadeOut("slow");
		$("#homePopup").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#homePopup").height();
	var popupWidth = $("#homePopup").width();
	var positionTop = windowHeight/2-popupHeight/2;
	var positionLeft = windowWidth/2-popupWidth/2;
	
	if (positionTop <= 0) {
		positionTop = 0;
	}
	
	if (positionLeft <= 0) {
		positionLeft = 0;
	}
	
	//centering
	$("#homePopup").css({
		"position": "absolute",
		"top": positionTop,
		"left": positionLeft
	});
	//only need force for IE6
	
	$("#homePopupBG").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	//$("#button").click(function(){
	//	//centering with css
	//	centerPopup();
	//	//load popup
	//	loadPopup();
	//});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupClose").click(function(){
		disablePopup();
	});
	//Click the Close button!
	$("#popupInputClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#homePopupBG").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

/* (E) Popup jQuery Code                    */
/********************************************/
/* (B) Letter jQuery Code                   */

/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR LETTER
//0 means disabled; 1 means enabled;
var letterStatus = 0;

//loading letter with jQuery magic!
function loadLetter(){
	//loads letter only if it is disabled
	if(letterStatus==0){
		$("#homeLetterBG").css({
			"opacity": "0.7"
		});
		$("#homeLetterBG").fadeIn("slow");
		$("#homeLetter").fadeIn("slow");
		letterStatus = 1;
	}
}

//disabling letter with jQuery magic!
function disableLetter(){
	//disables letter only if it is enabled
	if(letterStatus==1){
		$("#homeLetterBG").fadeOut("slow");
		$("#homeLetter").fadeOut("slow");
		letterStatus = 0;
	}
}

//centering letter
function centerLetter(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var letterHeight = $("#homeLetter").height();
	var letterWidth = $("#homeLetter").width();
	var positionTop = windowHeight/2-letterHeight/2;
	var positionLeft = windowWidth/2-letterWidth/2;
	
	if (positionTop <= 0) {
		positionTop = 0;
	}
	
	if (positionLeft <= 0) {
		positionLeft = 0;
	}
	
	//centering
	$("#homeLetter").css({
		"position": "absolute",
		"top": positionTop,
		"left": positionLeft
	});
	//only need force for IE6
	
	$("#homeLetterBG").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING LETTER
	//Click the button event!
	//$("#button").click(function(){
	//	//centering with css
	//	centerLetter();
	//	//load letter
	//	loadLetter();
	//});
				
	//CLOSING LETTER
	//Click the x event!
	$("#letterClose").click(function(){
		disableLetter();
	});
	//Click the Close button!
	$("#letterInputClose").click(function(){
		disableLetter();
	});
	//Click out event!
	$("#homeLetterBG").click(function(){
		disableLetter();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && letterStatus==1){
			disableLetter();
		}
	});

});

/* (E) Letter jQuery Code                   */
/********************************************/