﻿


var popupStatus = 0;
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupMortage").fadeIn("slow");
		popupStatus = 1;
	}
}

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

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupMortage").height();
	var popupWidth = $("#popupMortage").width();
	//centering
	$("#popupMortage").css({
		"position":"absolute",
		"z-index":"801"
	});
	//only need force for IE6

	$("#backgroundPopup").css({
		"height": windowHeight
	});

}

var popupStatus_ContactRealtor = 0;
function loadPopup_ContactRealtor(){
	//loads popup only if it is disabled
	if(popupStatus_ContactRealtor==0){
		$("#backgroundPopup_ContactRealtor").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_ContactRealtor").fadeIn("slow");
		$("#popupContactRealtor").fadeIn("slow");
		popupStatus_ContactRealtor = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup_ContactRealtor(){
	//disables popup only if it is enabled
	if(popupStatus_ContactRealtor==1){
		$("#backgroundPopup_ContactRealtor").fadeOut("slow");
		$("#popupContactRealtor").fadeOut("slow");
		popupStatus_ContactRealtor = 0;
	}
}

//centering popup
function centerPopup_ContactRealtor(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContactRealtor").height();
	var popupWidth = $("#popupContactRealtor").width();
	//centering
	$("#popupContactRealtor").css({
		"position":"absolute",
		"z-index":"801"
	});
	//only need force for IE6

	$("#backgroundPopup_ContactRealtor").css({
		"height": windowHeight
	});

}

var popupStatus_RequestMore = 0;
function loadPopup_RequestMore(){
	//loads popup only if it is disabled
	if(popupStatus_RequestMore==0){
		$("#backgroundPopup_RequestMore").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_RequestMore").fadeIn("slow");
		$("#popupRequestMore").fadeIn("slow");
		popupStatus_RequestMore = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup_RequestMore(){
	//disables popup only if it is enabled
	if(popupStatus_RequestMore==1){
		$("#backgroundPopup_RequestMore").fadeOut("slow");
		$("#popupRequestMore").fadeOut("slow");
		popupStatus_RequestMore = 0;
	}
}

//centering popup
function centerPopup_RequestMore(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupRequestMore").height();
	var popupWidth = $("#popupRequestMore").width();
	//centering
	$("#popupRequestMore").css({
		"position":"absolute",
		"z-index":"801"
	});
	//only need force for IE6

	$("#backgroundPopup_RequestMore").css({
		"height": windowHeight
	});

}

var popupStatus_sendToFriend = 0;
function loadPopup_sendToFriend(){
	//loads popup only if it is disabled
	if(popupStatus_sendToFriend==0){
		$("#backgroundPopup_sendToFriend").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_sendToFriend").fadeIn("slow");
		$("#popupsendToFriend").fadeIn("slow");
		popupStatus_sendToFriend = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup_sendToFriend(){
	//disables popup only if it is enabled
	if(popupStatus_sendToFriend==1){
		$("#backgroundPopup_sendToFriend").fadeOut("slow");
		$("#popupsendToFriend").fadeOut("slow");
		popupStatus_sendToFriend = 0;
	}
}

//centering popup
function centerPopup_sendToFriend(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupsendToFriend").height();
	var popupWidth = $("#popupsendToFriend").width();
	//centering
	$("#popupsendToFriend").css({
		"position":"absolute",
		"z-index":"801"
	});
	//only need force for IE6

	$("#backgroundPopup_sendToFriend").css({
		"height": windowHeight
	});

}



var popupStatus_SaveTerms = 0;
function loadPopup_SaveTerms(){
	//loads popup only if it is disabled
	if(popupStatus_SaveTerms==0){
		$("#backgroundPopup_SaveTerms").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_SaveTerms").fadeIn("slow");
		$("#popupSaveTerms").fadeIn("slow");
		popupStatus_SaveTerms = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup_SaveTerms(){
	//disables popup only if it is enabled
	if(popupStatus_SaveTerms==1){
		$("#backgroundPopup_SaveTerms").fadeOut("slow");
		$("#popupSaveTerms").fadeOut("slow");
		popupStatus_SaveTerms = 0;
	}
}

//centering popup
function centerPopup_SaveTerms(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupSaveTerms").height();
	var popupWidth = $("#popupSaveTerms").width();
	//centering
	$("#popupSaveTerms").css({
		"position":"absolute",
		"z-index":"801"
	});
	//only need force for IE6

	$("#backgroundPopup_SaveTerms").css({
		"height": windowHeight
	});

}


var popupStatus_Testimonial = 0;
function loadPopup_Testimonial(){
	//loads popup only if it is disabled
	if(popupStatus_Testimonial==0){
		$("#backgroundPopup_Testimonial").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup_Testimonial").fadeIn("slow");
		$("#popupTestimonial").fadeIn("slow");
		popupStatus_Testimonial = 1;
	}
}

var popupStatus_Testimonials = 0;
function loadPopup_Testimonials(){
	//loads popup only if it is disabled
	if(popupStatus_Testimonials==0){
		$(".backgroundPopup_Testimonials").fadeIn("slow");
		$(".popupTestimonials").fadeIn("slow");
		popupStatus_Testimonials = 1;
	}
}


//disabling popup with jQuery magic!
function disablePopup_Testimonial(){
	//disables popup only if it is enabled
	if(popupStatus_Testimonial==1){
		$("#backgroundPopup_Testimonial").fadeOut("slow");
		$("#popupTestimonial").fadeOut("slow");
		popupStatus_Testimonial = 0;
	}
}

//disabling popup with jQuery magic!
function disablePopup_Testimonials(){
	//disables popup only if it is enabled
	if(popupStatus_Testimonials==1){
		$(".backgroundPopup_Testimonials").fadeOut("slow");
		$(".popupTestimonials").fadeOut("slow");
		popupStatus_Testimonials = 0;
	}
}

//centering popup
function centerPopup_Testimonial(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupTestimonial").height();
	var popupWidth = $("#popupTestimonial").width();
	//centering
	$("#popupTestimonial").css({
		"position":"absolute",
		"z-index":"801"
	});
	//only need force for IE6

	$("#backgroundPopup_Testimonial").css({
		"height": windowHeight
	});

}

//centering popup
function centerPopup_Testimonials(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $(".popupTestimonials").height();
	var popupWidth = $(".popupTestimonials").width();
	//centering
	$(".popupTestimonials").css({
		"position":"absolute",
		"z-index":"801"
	});

	//only need force for IE6
	$(".backgroundPopup_Testimonials").css({
		"height": windowHeight
	});
}




//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

	//LOADING POPUP
	//Click the button event!
	$("#mortage").click(function(){

		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});

	$("#ContactRealtor").click(function(){
		//centering with css
		centerPopup_ContactRealtor();
		//load popup
		loadPopup_ContactRealtor();
	});

	$("#Testimonial").click(function(){
		//centering with css
		centerPopup_Testimonial();
		//load popup
		loadPopup_Testimonial();
	});

	$(".Testimonials").click(function(){
		//centering with css
		centerPopup_Testimonials();
		//load popup
		loadPopup_Testimonials();
	});

	$("#RequestMore").click(function(){
		//centering with css
		centerPopup_RequestMore();
		//load popup
		loadPopup_RequestMore();
	});

	$("#sendToFriend").click(function(){
		//centering with css
		centerPopup_sendToFriend();
		//load popup
		loadPopup_sendToFriend();
	});

	$("#SaveTerms").click(function(){
		//centering with css
		centerPopup_SaveTerms();
		//load popup
		loadPopup_SaveTerms();
	});
	$("#MortagePreview").click(function(){

		//centering with css
		centerPopupMortagePreview();
		//load popup
		loadPopupMortagePreview();
	});


	//CLOSING POPUP
	//Click the x event!
	$("#popupMortageClose").click(function(){
		disablePopup();
	});


	$("#popupContactRealtorClose").click(function(){
		disablePopup_ContactRealtor();
	});

	$("#popupTestimonialClose").click(function(){
		disablePopup_Testimonial();
	});

	$(".popupTestimonialsClose").click(function(){
		disablePopup_Testimonials();
	});
	$("#popupRequestMoreClose").click(function(){
		disablePopup_RequestMore();
	});

	$("#popupsendToFriendClose").click(function(){
		disablePopup_sendToFriend();
	});

	$("#popupSaveTermsClose").click(function(){
		disablePopup_SaveTerms();
	});

	$("#popupMortagePreviewClose").click(function(){
		disablePopupMortagePreview();
	});


	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$("#backgroundPopup_ContactRealtor").click(function(){
		disablePopup_ContactRealtor();
	});

	$("#backgroundPopup_Testimonial").click(function(){
		disablePopup_Testimonial();
	});

	$(".backgroundPopup_Testimonials").click(function(){
		disablePopup_Testimonials();
	});

	$("#backgroundPopup_RequestMore").click(function(){
		disablePopup_RequestMore();
	});

	$("#backgroundPopup_sendToFriend").click(function(){
		disablePopup_sendToFriend();
	});

	$("#backgroundPopup_SaveTerms").click(function(){
		disablePopup_SaveTerms();
	});
	$("#backgroundPopup_MortagePreview").click(function(){
		disablePopupMortagePreview();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
		if(e.keyCode==27 && popupStatus_ContactRealtor==1){
			disablePopup_ContactRealtor();
		}
		if(e.keyCode==27 && popupStatus_Testimonial==1){
			disablePopup_Testimonial();
		}
		if(e.keyCode==27 && popupStatus_Testimonials==1){
			disablePopup_Testimonials();
		}

		if(e.keyCode==27 && popupStatus_RequestMore==1){
			disablePopup_RequestMore();
		}
		if(e.keyCode==27 && popupStatus_sendToFriend==1){
			disablePopup_sendToFriend();
		}
		if(e.keyCode==27 && popupStatus_SaveTerms==1){
			disablePopup_SaveTerms();
		}
		if(e.keyCode==27 && popupStatusMortagePreview==1){
			disablePopupMortagePreview();
		}
	});
});
