﻿var popupStatus = 0;
var popupStatusDrive = 0;
var popupStatusOrder = 0;
function loadPopup(){
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}
function loadPopupDrive(){
	if(popupStatusDrive==0){
		$("#backgroundPopupDrive").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupDrive").fadeIn("slow");
		$("#popupDrive").fadeIn("slow");
		popupStatusDrive = 1;
	}
}
function loadPopupOrder(){
	if(popupStatusOrder==0){
		$("#backgroundPopupOrder").css({
			"opacity": "0.7"
		});
		$("#backgroundPopupOrder").fadeIn("slow");
		$("#popupOrder").fadeIn("slow");
		popupStatusOrder = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}
function disablePopupDrive(){
	if(popupStatusDrive==1){
		$("#backgroundPopupDrive").fadeOut("slow");
		$("#popupDrive").fadeOut("slow");
		popupStatusDrive = 0;
	}
}
function disablePopupOrder(){
	if(popupStatusOrder==1){
		$("#backgroundPopupOrder").fadeOut("slow");
		$("#popupOrder").fadeOut("slow");
		popupStatusOrder = 0;
	}
}

function centerPopup(){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	
	$("#popupContact").css({
		"position": "absolute",		
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	
	$("#backgroundPopup").css({
		"height": windowHeight		
	});	
}
function centerPopupDrive(){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupDrive").height();
	var popupWidth = $("#popupDrive").width();
	
	$("#popupDrive").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	
	$("#backgroundPopupDrive").css({
		"height": windowHeight		
	});	
}
function centerPopupOrder(){

	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupOrder").height();
	var popupWidth = $("#popupOrder").width();
	
	$("#popupOrder").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});	
	
	$("#backgroundPopupOrder").css({
		"height": windowHeight		
	});	
}
$(document).ready(function(){
	
	$("#OpenQa").click(function(){		
		centerPopup();		
		loadPopup();
	});		
	$("#OpenDrive").click(function(){		
		centerPopupDrive();		
		loadPopupDrive();
	});		
	$("#OpenOrder").click(function(){		
		centerPopupOrder();		
		loadPopupOrder();
	});				
	
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupDriveClose").click(function(){
		disablePopupDrive();
	});
	$("#popupOrderClose").click(function(){
		disablePopupOrder();
	});
	
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	$("#backgroundPopupDrive").click(function(){
		disablePopupDrive();
	});
	$("#backgroundPopupOrder").click(function(){
		disablePopupOrder();
	});
	
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});
