/*
 *  JavaScript for Modal Dialog
 *  by Brandon McKinney / Staplegun
 *  created 08 26 2008
 *
 *  Requires MooTools 1.2
 */

var modalmsg = "<b>You are leaving the Kirkpatrick Bank website.</b><br /><br />";
modalmsg += "The site you are visiting may not be controlled by Kirkpatrick Bank and may be located on another server. ";
modalmsg += "We cannot endorse or take responsibility for any external site or content. ";
modalmsg += "Kirkpatrick Bank neither endorses the information, content, presentation, or accuracy, nor makes any warranty, express or implied, regarding any external site.<br /><br />";
modalmsg += "The privacy policy of the site may differ from that of Kirkpatrick Bank.<br /><br />";
modalmsg += "<b>Would you like to continue to this site?</b><br /><br />";

var modalbtns = '<center><button onload="this.focus();" onclick="window.open(\'{{LINKURL}}\'); cancelModal();"> YES, CONTINUE </button> &nbsp; &nbsp;';
modalbtns += '<button onclick="cancelModal();"> NEVERMIND </button></center>';



var modalTimeout;
function openModal(modalMessage){
	new Fx.Scroll(window).toTop();
	var modalOverlay = new Element('div', {
		'class': 'modalOverlay',
		'styles': {
			'height': window.getScrollSize().y,
			'width': window.getScrollSize().x
		}
	});
	modalOverlay.setOpacity(0);
	modalOverlay.inject(document.body, 'top');
	modalOverlay.fade(.9);
	
	var modalDialog = new Element('div', {
		'class': 'modalDialog',
		'html': modalMessage
	});
	modalDialog.setStyles({
		'left': (window.getSize().x / 2) - 200,
		'top': -1000
	});
	modalDialog.inject(document.body, 'top');
	modalDialog.fade('show');
	modalDialog.tween('top', 0);
	
	// After 60 seconds, Exit the modal dialog
	modalTimeout = setTimeout(cancelModal, 60*1000);
	return;
}



function cancelModal(){
	clearTimeout(modalTimeout);
	$$('.modalOverlay, .modalDialog').each(function(o){
		var f = new Fx.Tween(o);
		f.addEvent('complete', function(){
			o.destroy();
		});
		f.start('opacity', 0);
	});
	return;
}

closeModal = cancelModal;



function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}


function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}