/**
 * Function to display generic content modally.
 * Currently used for Add/Edit Dependant and Save Enquiry dialogs.
 */

$(function() {
	// attach a window-resize handler to reposition the dependant form if it is displayed
	$(window).resize(function() {
		positionPopup();
	});
});

function closeDialog(){
	$('.mask').hide();
	$('.window').hide();
}
function closeSaveEnquiryDialog(){

	$('.window').hide();
	$('.enquiry_mask').hide();
	$('.enquiry_mask').stop(true,true);//clear queue of animations

}
function showDialog(elementName){

	positionPopup(elementName);
	$('html, body').animate({scrollTop:0}, 'slow');
	$('#' + elementName + '.dialog').show();
	showMask();
}

function showModalDialog(elementName){
	showSaveDialog(elementName);
}

function closeModalDialog(){
	closeSaveEnquiryDialog();
}

function showSaveDialog(elementName){
	positionPopup(elementName);
	$('html, body').animate({scrollTop:0}, 'slow');
	$('#' + elementName + '.dialog').show();

		//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('.enquiry_mask').css({'width':maskWidth,'height':maskHeight});

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

}


function positionPopup(elementName){
	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	//Position the popup window
	$('#' + elementName + '.dialog').css('top',  50);
	$('#' + elementName + '.dialog').css('left', winW/2-$('#' + elementName + '.dialog').width()/2);
}

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);
}

/* broker Proceed */
$(document).ready(function() {
	$('.showBrokerProceedDialog').on('click', null, function(event) {
		var showBrokerProceedDialog = ($('#showBrokerProceedDialog').val().toLowerCase() == 'true') || 
				($('#showBrokerProceedDialog').val().toLowerCase() == 't');
		if(showBrokerProceedDialog){
			event.preventDefault();
			var href = updateQueryStringParameter( $(this).attr('href'), 'brokerProceed', 'true' );
			$('#brokerProceedYes').attr('href', href);
			showModalDialog('brokerProceedWindow');
		}
	});
});
