/*
 * SimpleModal Confirm Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: confirm.js 254 2010-07-23 05:14:44Z emartin24 $
 */

jQuery(function ($) {
	//$('input.confirm, a.confirm').click(function (e) {
	$('a.confirm').click(function (e) {
		e.preventDefault();
		var a = $(this);
		confirm(a.attr('confirmmsg'), function () {
			if (a.attr('target') == '_blank'){
				TTMedPopUpWindowContainer=window.open(a.attr('href'),'TTMedPopUpWindow','location=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,height=740,width=920,left=50,top=20');
				TTMedPopUpWindowContainer.focus();
			}else{
				window.location.href = a.attr('href');
			}
		});
	});
	
	$('a.basic-modal-content').click(function (e) {
		e.preventDefault();
		var a = $(this);
		alert(a.attr('alertmsg'), function () {});
	});
});

function confirm(message, callback) {
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>Close x</a>",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container', 
		onShow: function (dialog) {
			var modal = this;

			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				modal.close(); // or $.modal.close();
			});
		}
	});
}

function alert(message) {
	$('#basic-modal-content').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>Close x</a>",
		position: ["20%",],
		overlayId: 'simplemodal-overlay',
		containerId: 'simplemodal-container', 
		onShow: function (dialog) {
			var modal = this;
			$('.message', dialog.data[0]).append(message);
		}
	});
}

