var popupStatus = 0;
var current_popup = false;
function validateEmail(email){
	var reg = /^([A-Za-z0-9_\-\+\.])+\@([A-Za-z0-9_\-\+\.])+\.([A-Za-z]{2,4})$/;
	if (reg.test(email) == false){
		return false;
	} else {
		return true;
	}
}
function validateLength(str){
	return (str.length > 0);
}
function validatePhone(p){
	var reg = /^([0-9]{3}-[0-9]{3}-[0-9]{4})$/;
	return reg.test(p);
}
function loadPopup(popup){
	if (popupStatus==0){
		current_popup = popup
		$("#backgroundPopup").css({
			"opacity": "0.3"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popup" + popup).fadeIn("slow");
		$("#popup" + popup + " :input:visible:enabled:first").focus();
		popupStatus = 1;
	}
}

function disablePopup(){
	if (popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popup" + current_popup).fadeOut("slow");
		popupStatus = 0;
	}
}

function centerPopup(popup){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popup" + popup).height();
	var popupWidth = $("#popup" + popup).width();
	//centering
	$("#popup" + popup).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}
function scrollTo(selector){
	var targetOffset = $(selector).offset().top;
	$('html,body').animate({scrollTop: targetOffset}, 500);
}
$(document).ready(function(){
	$(".popupClose").click(function(){
		disablePopup();
	});
	$("#backgroundPopup").click(function(){
		disablePopup();
	});

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	siteSearchBox = $("#site_search_box");
	
	siteSearchBoxDefault = 'Search placeEasy...';

	if(siteSearchBox.attr("value") == "") siteSearchBox.attr("value", siteSearchBoxDefault);
	siteSearchBox.focus(function(){
		if($(this).attr("value") == siteSearchBoxDefault) $(this).attr("value", "");
	});
	siteSearchBox.blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", siteSearchBoxDefault);
	});
});