jQuery(function() {
	attachClickHandlers();
});


function attachClickHandlers(){
	//select all the a tag with name equal to modal
	jQuery('a[name=modal]').unbind('click');
	jQuery('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();

		showMask();

		//Get the window height and width
		var winH = jQuery(window).height();
		var winW = jQuery(window).width();

		if(this.id == 'editPerson1' || this.id == 'editPerson2') {
			//Set the popup window to center
			jQuery('#addDepWindow.dialog').css('top',  winH/2-jQuery('#addDepWindow.dialog').height()/2);
			jQuery('#addDepWindow.dialog').css('left', winW/2-jQuery('#addDepWindow.dialog').width()/2);

			//transition effect
			jQuery('#addDepWindow.dialog').show();
		}

		/*if(this.id == 'saveQuoteLink') {
			saveAndEmailHelper(this, winH, winW, '/quote/pages/quote/SaveQuote.html', '#saveQuoteWindow.dialog2');
			$('#emailQuoteLink').show();
		}
		if(this.id == 'emailQuoteLink') {
			saveAndEmailHelper(this, winH, winW, '/quote/pages/quote/EmailQuote.html', '#emailQuoteWindow.dialog2');
		}*/

		if(this.id == 'editMedicalLink1' || this.id == 'editMedicalLink2' || this.id =='noSub1') {
			//Set the popup window to center
			jQuery('#editMedicalWindow.dialog').css('top',  winH/2-jQuery('#editMedicalWindow.dialog').height()/2);
			jQuery('#editMedicalWindow.dialog').css('left', winW/2-jQuery('#editMedicalWindow.dialog').width()/2);

			//transition effect
			jQuery('#editMedicalWindow.dialog').show();
		}

		if(this.id == 'underwriting1') {
			//Set the popup window to center
			jQuery('#underwritingCondition1.dialog').css('top',  winH/2-jQuery('#underwritingCondition1.dialog').height()/2);
			jQuery('#underwritingCondition1.dialog').css('left', winW/2-jQuery('#underwritingCondition1.dialog').width()/2);

			//transition effect
			jQuery('#underwritingCondition1.dialog').show();
		}

		if(this.id == 'person1Condition1HeartEdit') {
			//Set the popup window to center
			jQuery('#uwQ1.dialog').css('top',  winH/2-jQuery('#uwQ1.dialog').height()/2);
			jQuery('#uwQ1.dialog').css('left', winW/2-jQuery('#uwQ1.dialog').width()/2);

			//transition effect
			jQuery('#uwQ1.dialog').show();
		}

		if(this.id == 'person1Condition2HeartComplete') {
			//Set the popup window to center
			jQuery('#uwQ2.dialog').css('top',  winH/2-jQuery('#uwQ2.dialog').height()/2);
			jQuery('#uwQ2.dialog').css('left', winW/2-jQuery('#uwQ2.dialog').width()/2);

			//transition effect
			jQuery('#uwQ2.dialog').show();
		}

		if(this.id == 'person1Condition1EndocrineEdit') {
			//Set the popup window to center
			jQuery('#uwQ3.dialog').css('top',  winH/2-jQuery('#uwQ3.dialog').height()/2);
			jQuery('#uwQ3.dialog').css('left', winW/2-jQuery('#uwQ3.dialog').width()/2);

			//transition effect
			jQuery('#uwQ3.dialog').show();
		}

		if(this.id == 'person1Condition2EndocrineComplete') {
			//Set the popup window to center
			jQuery('#uwQ4.dialog').css('top',  winH/2-jQuery('#uwQ4.dialog').height()/2);
			jQuery('#uwQ4.dialog').css('left', winW/2-jQuery('#uwQ4.dialog').width()/2);

			//transition effect
			jQuery('#uwQ4.dialog').show();
		}

		if(this.id == 'prodSummaryLink') {
			//Set the popup window to center
			jQuery('#prodSummaryWindow.dialog3').css('top',  winH/2-jQuery('#prodSummaryWindow.dialog3').height()/2);
			jQuery('#prodSummaryWindow.dialog3').css('left', winW/2-jQuery('#prodSummaryWindow.dialog3').width()/2);

			//transition effect
//			jQuery('#prodSummaryWindow.dialog3').css('overflow-y', 'hidden');
//			jQuery('#prodSummaryWindow.dialog3').fadeIn(2000)
//			.delay(1).queue(function () {$(this).css('overflow-y', 'auto');$(this).dequeue();})
			jQuery('#prodSummaryWindow.dialog3').show();

		}

		if(this.id == 'lowBenefitSummaryLink') {
			//Set the popup window to center
			jQuery('#lowBenefitSummaryWindow.dialog3').css('top',  winH/2-jQuery('#lowBenefitSummaryWindow.dialog3').height()/2);
			jQuery('#lowBenefitSummaryWindow.dialog3').css('left', winW/2-jQuery('#lowBenefitSummaryWindow.dialog3').width()/2);

			//transition effect
			jQuery('#lowBenefitSummaryWindow.dialog3').show();

		}
		if(this.id == 'medBenefitSummaryLink') {
			//Set the popup window to center
			jQuery('#medBenefitSummaryWindow.dialog3').css('top',  winH/2-jQuery('#medBenefitSummaryWindow.dialog3').height()/2);
			jQuery('#medBenefitSummaryWindow.dialog3').css('left', winW/2-jQuery('#medBenefitSummaryWindow.dialog3').width()/2);

			//transition effect
			jQuery('#medBenefitSummaryWindow.dialog3').show();

		}
		if(this.id == 'highBenefitSummaryLink') {
			//Set the popup window to center
			jQuery('#highBenefitSummaryWindow.dialog3').css('top',  winH/2-jQuery('#highBenefitSummaryWindow.dialog3').height()/2);
			jQuery('#highBenefitSummaryWindow.dialog3').css('left', winW/2-jQuery('#highBenefitSummaryWindow.dialog3').width()/2);

			//transition effect
			jQuery('#highBenefitSummaryWindow.dialog3').show();

		}
		if(this.id == 'deductibleHelpLink') {
			//Set the popup window to center
			jQuery('#deductibleHelpWindow.dialog3').css('top',  winH/2-jQuery('#deductibleHelpWindow.dialog3').height()/2);
			jQuery('#deductibleHelpWindow.dialog3').css('left', winW/2-jQuery('#deductibleHelpWindow.dialog3').width()/2);

			jQuery('img[alt="infoDeductibles1"]').attr('src', '../../images/infoDeductibles1.jpg');
			jQuery('img[alt="infoDeductibles2"]').attr('src', '../../images/infoDeductibles2.jpg');
			jQuery('img[alt="infoDeductibles3"]').attr('src', '../../images/infoDeductibles3.jpg');
			jQuery('img[alt="infoDeductibles4"]').attr('src', '../../images/infoDeductibles4.jpg');
			
			//transition effect
			jQuery('#deductibleHelpWindow.dialog3').show();

		}
		if(this.id == 'outpatientBenefitLink') {
			//Set the popup window to center
			jQuery('#outpatientBenefitWindow.dialog3').css('top',  winH/2-jQuery('#outpatientBenefitWindow.dialog3').height()/2);
			jQuery('#outpatientBenefitWindow.dialog3').css('left', winW/2-jQuery('#outpatientBenefitWindow.dialog3').width()/2);

			//transition effect
			jQuery('#outpatientBenefitWindow.dialog3').show();

		}
		if(this.id == 'medicalEvacuationLink') {
			//Set the popup window to center
			jQuery('#medicalEvacuationBenefitWindow.dialog3').css('top',  winH/2-jQuery('#medicalEvacuationBenefitWindow.dialog3').height()/2);
			jQuery('#medicalEvacuationBenefitWindow.dialog3').css('left', winW/2-jQuery('#medicalEvacuationBenefitWindow.dialog3').width()/2);

			//transition effect
			jQuery('#medicalEvacuationBenefitWindow.dialog3').show();
		}
		if(this.id == 'healthWellbeingLink') {
			//Set the popup window to center
			jQuery('#healthWellbeingLinkBenefitWindow.dialog3').css('top',  winH/2-jQuery('#healthWellbeingLinkBenefitWindow.dialog3').height()/2);
			jQuery('#healthWellbeingLinkBenefitWindow.dialog3').css('left', winW/2-jQuery('#healthWellbeingLinkBenefitWindow.dialog3').width()/2);

			//transition effect
			jQuery('#healthWellbeingLinkBenefitWindow.dialog3').show();
		}
		if(this.id == 'visionDentalLink') {
			//Set the popup window to center
			jQuery('#visionDentalLinkBenefitWindow.dialog3').css('top',  winH/2-jQuery('#visionDentalLinkBenefitWindow.dialog3').height()/2);
			jQuery('#visionDentalLinkBenefitWindow.dialog3').css('left', winW/2-jQuery('#visionDentalLinkBenefitWindow.dialog3').width()/2);

			//transition effect
			jQuery('#visionDentalLinkBenefitWindow.dialog3').show();
		}
		if(this.id == 'usaLink') {
			//Set the popup window to center
			jQuery('#usaLinkBenefitWindow.dialog3').css('top',  winH/2-jQuery('#usaLinkBenefitWindow.dialog3').height()/2);
			jQuery('#usaLinkBenefitWindow.dialog3').css('left', winW/2-jQuery('#usaLinkBenefitWindow.dialog3').width()/2);

			//transition effect
			jQuery('#usaLinkBenefitWindow.dialog3').show();
		}
	});

	//if nextQuote button is clicked
	jQuery('.nextQuote').unbind('click');
	jQuery('.nextQuote').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();

		jQuery('.mask').hide();
		jQuery('.window').hide();
	});

	jQuery('.done').unbind('click');
	jQuery('.done').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();

		jQuery('.mask').hide();
		jQuery('.window').hide();
  		jQuery('#editButton1').show();
	});

	$('#addPersonTable').hide();

	$('#saveAddPerson').click(function() {
		$('#addPersonTable').show();
		$('.mask').hide();
		$('.window').hide();
	});

	$('#cancelAddPerson').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

		$('#saveUWQ1').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#cancelUWQ1').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#saveUWQ2').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#cancelUWQ2').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#saveUWQ3').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#cancelUWQ3').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#saveUWQ4').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

	$('#cancelUWQ4').click(function() {
		$('.mask').hide();
		$('.window').hide();
	});

}

function showMask(){
	//Get the screen height and width
	var maskHeight = $(document).height();
	var maskWidth = $(window).width();

	//Set heigth and width to mask to fill up the whole screen
	jQuery('.mask').css({'width':maskWidth,'height':maskHeight});

	//transition effect
	jQuery('.mask').fadeIn(1000);
	jQuery('.mask').fadeTo("slow",0.5);
}