/*
 * 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 238 2010-03-11 05:56:57Z emartin24 $
 *
 */
 //var UrlCheckModal = window.location.protocol + "//localhost:8080/moncarlino"  + "/checkModal.php";
 var UrlCheckModal = window.location.protocol + "//"+ window.location.host + "/checkModal.php";
//alert(UrlCheckModal)
jQuery(document).ready(function($){
//jQuery(function ($) {
	//$('#confirm-dialog input.confirm, #confirm-dialog a.confirm').click(function (e) {
	//	e.preventDefault();
 //alert(UrlCheckModal)
		// example of calling the confirm function
		// you must use a callback function to perform the "yes" action
		
		//check modal is open first?
		var isOpen = false
		jQuery.get(UrlCheckModal,
			function(message)
			{
					//alert(message)
					if(message=="opened")	
						isOpen = true	
					else
						isOpen = false;
					
					//neu popup chua xuat hien lan nao
					//alert(isOpen)
					if(!isOpen)
					{
						var t=setTimeout('doConfirm()',30000);
					}
				}		
		);
		
});
	
function doConfirm()
{
	confirm(null, function () {
		 jQuery.post(UrlCheckModal,{acceptSurvey:1},
				function(message1)
				{
	
				}
				
		 );
	});	
}

function confirm(message, callback) {
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container', 
		containerCss:{		
			height:200,
			width:500,
			
		},
	
		onShow: function (dialog) {
			
			//set trang thai da bat modal popup
			jQuery.post(UrlCheckModal,{openModal:1},
				function(message1)
				{
							
				}						
			);
			
			$('.message', dialog.data[0]).append(message);

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