﻿
//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){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

// 2POP UP
//loading popup with jQuery magic!
function loadsecondPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#secondpopupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablesecondPopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#secondpopupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centersecondPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#secondpopupContact").height();
	var popupWidth = $("#secondpopupContact").width();
	//centering
	$("#secondpopupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
// 3POP UP
//loading popup with jQuery magic!
function loadthirdPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#thirdpopupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablethirdPopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#thirdpopupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerthirdPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#thirdpopupContact").height();
	var popupWidth = $("#thirdpopupContact").width();
	//centering
	$("#thirdpopupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS for pop up 1
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
$("#Reason").change(function () {
        if ($(this).val()=="Buytolet") {
		centerPopup();
		//load popup
		loadPopup();
      }
    });
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){

//document.getElementById('Reason').reset();
document.forms["mort"]["Reason"].options[0].selected=true;
//document.getElementById("mort").reset()
disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

//CONTROLLING EVENTS for pop up 2
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
$("#PaymentMethods").change(function () {
        if ($(this).val()=="Mix") {
		centersecondPopup();
		//load popup
		loadsecondPopup();
      }
    });
				
	//CLOSING POPUP
	//Click the x event!
	$("#secondpopupContactClose").click(function(){

//document.getElementById('Reason').reset();
document.forms["mort"]["PaymentMethods"].options[0].selected=true;
//document.getElementById("mort").reset()
disablesecondPopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
disablesecondPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablesecondPopup();
		}
	});

});


//CONTROLLING EVENTS for pop up 3
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
$("#ccjyes").click(function () {
        if ($(this).val()=="Yes") {
		// if ($("#ccjyes").attr( "checked" , true )) {
		centerthirdPopup();
		//load popup
		loadthirdPopup();
      }
    });
				
	//CLOSING POPUP
	//Click the x event!
	$("#thirdpopupContactClose").click(function(){

//document.getElementById('Reason').reset();
//document.forms["mort"]["ccjno"].checked==false;
$("#ccjno").attr ( "checked" , true );

//document.getElementById("mort").reset()
disablethirdPopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
disablethirdPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablethirdPopup();
		}
	});

});


$(document).ready(function() 
    { 
$("#Variable").attr("disabled", true);
$("#Tracker").attr("disabled", true);
$("#Discounted").attr("disabled", true);
$("#Capped").attr("disabled", true);


$("#toggleVars").click(function () {
    if ($('#toggleVars').is(':checked')){
	$("#Variable").removeAttr("disabled");
    $("#Tracker").removeAttr("disabled");
    $("#Discounted").removeAttr("disabled");
    $("#Capped").removeAttr("disabled");
	
	} else {
    $("#Variable").attr("disabled", true);
	$("#Tracker").attr("disabled", true);
    $("#Discounted").attr("disabled", true);
    $("#Capped").attr("disabled", true);

		
				}});
		} 
            );