/*
// this snippet resides in a jquery include webpart.
// it assigns the onclick event of the element with a class of 'lnkloanApp'
$j(document).ready(function () {
	$j('.lnkLoanApp').click(function() {
		$j.get('/App_Themes/JSTC/snippets/LoanApplicationPopUp.html', $j(this).ShowLoanAppDialog);
	});
});
*/

$j(document).ready(function () {
	$j.fn.ShowLoanAppDialog = function(data) {
		var promptTitle = 'Do you have an open loan plan with us now?';
		var promptWidth = 600;
		var promptHeight = 'auto';
		var yesText = 'Yes';
		var yesHref = 'https://www.loanliner.com/LoanRequest/CLPPresenter/GettingStarted.aspx?CUID=03705933&LoanFormId=3819523711012154132&ChannelId=1227221411012194007&LocationId=5601221108071192344&IsFramed=F';
		var yesNewWin = true;
		var noText = 'No';
		var noHref = 'https://www.loanliner.com/LoanRequest/CLPPresenter/LoanList.aspx?CUID=03705933&LoanListId=1102&ChannelId=1227221411012194007&LocationId=5601221108071192344&IsFramed=F';
		var noNewWin = true;
		
		var dialogButtons = {};
		dialogButtons[yesText] = function() {
			$j(this).OpenLoanAppLink(yesHref, yesNewWin);
			if (yesNewWin) {
				$loanAppDialog.dialog('close').remove();
			}

		};		
		dialogButtons[noText] = function() {
			$j(this).OpenLoanAppLink(noHref, noNewWin);
			if (noNewWin) {
				$loanAppDialog.dialog('close').remove();
			}
		};
		
		var $loanAppDialog = $j('<div></div>')
			.html(data)
			.dialog({
				modal: true,
				autoOpen: false,
				closeOnEscape: true,
				title: promptTitle,
				width: promptWidth,
				height: promptHeight,
				buttons: dialogButtons,
				resizable: true
		});			

		// hide the 'x' in the right corner. it bypasses the button functionality
		$j('.ui-dialog-titlebar-close').remove();
		
		// move buttons to titlebar
		$j('.ui-dialog-buttonpane button').appendTo('.ui-dialog-titlebar');
		// remove buttonpane (in order to remove horizontal line)
		$j('.ui-dialog-buttonpane').remove();
		
		$loanAppDialog.dialog('open');
	}	

	$j.fn.OpenLoanAppLink = function(href, newWin) {
		if (newWin) {
			window.open(href, 'wLoanApp');
		}
		else {
			location.href = href;
		}	
	}
});


