/*
 * 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 $
 *
 */

jQuery(function ($) {
	$('#confirm-dialog input.confirm, #confirm-dialog a.confirm').click(function (e) {
		
		e.preventDefault();
		
		// example of calling the confirm function
		// you must use a callback function to perform the "yes" action
		//confirm("", function () {
		//	window.location.href = 'http://www.meteomedia.com/';
		//});
	});
});

//ray 08/31/2010 added to confirm within js
function gypsybug_disclaimer() {
 var msg="<b>These Ads may contain Adult Content.</b> If you are under 18 years of age or adult content offends you, click on the 'No' button below to exit this area.\n\nBy going beyond this point you acknowlege that you are over 18 years of age\n\n";
 confirm(msg);
}

function createCookie(name, value, hours)
{
  if (hours) {
    var date = new Date();
    date.setTime(date.getTime()+(hours*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
  var ca = document.cookie.split(';');
  var nameEQ = name + "=";
  for(var i=0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
  return null;
}

function eraseCookie(name)
{
  createCookie(name, "", -1);
}


function confirm(message, callback) {
	$('#confirm').modal({
		//ray 4/30/2010 removed the close button of dialog header since it allow escape without confirming
		//closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["40%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container', 
		onShow: function (dialog) {
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				
				//ray 4/30/2010 - no need to call callback since we want to simply stay on the page is user clicks yes
				// call the callback
				//if ($.isFunction(callback)) {
				//	callback.apply();
				//}
				
				if (!readCookie("gypsyconfirm")){
				  eraseCookie("gypsyconfirm");
				  createCookie("gypsyconfirm", "yes", 1); 
				}
				
				// close the dialog
				$.modal.close();
			});
			//ray 4/30/2010 ADDED if user doesn't accept disclaimer we simply move back to the main page (index.php)
			$('.no', dialog.data[0]).click(function () {
			        window.location.href = 'index.php';
				
				$.modal.close();
			});
			
		}
	});
}





