﻿

// Added limit to the popup by making sure it works only once on this page
// In addition, it will also not work for an entire day for other pages of the site,
// if cookies are available

var firstTime=true;
//var loaderStr="<div align='center' style='background:#ffffff;'><br><br><img src=\"http://www.virtualspirits.com/danachat/images/avatar-loading.jpg\"/><br><img src=\"http://www.virtualspirits.com/danachat/images/progress-loading.gif\"/></div>";
var loaderStr="<div style=\"background: url('http://www.virtualspirits.com/danachat/images/dana_chat_load.gif') no-repeat transparent; height: 465px; width: 510px;padding-left:20px;padding-top:50px;\">connecting to agent ... <Br><br><img src=\"http://www.virtualspirits.com/danachat/images/progress-loading.gif\"/></div>";

var strBox1;
var strBox2;

strBox1 = "<span id='loadertext'>"+loaderStr+"</span>";
strBox2 = "<span id='loadertext'>"+loaderStr+"</span>";
//strBox2 = strBox2+"<iframe id='vspiritframe' src='http://www.virtualspirits.com/danachat/danachat.aspx' onload='showAgent();' frameborder='0' hspace='0' vspace='0' scrolling='no' style='margin:0px; padding:0px; visibility:hidden;' ALLOWTRANSPARENCY='true'></iframe>";
strBox2 = strBox2+"<iframe id='vspiritframe' src='http://www.virtualspirits.com/danachat/danahybrid.aspx' onload='showAgent();' frameborder='0' hspace='0' vspace='0' scrolling='no' style='margin:0px; padding:0px; visibility:hidden;' ALLOWTRANSPARENCY='true'></iframe>";

$(document).ready(function() {
document.getElementById("exit_content").innerHTML = strBox1;

$(document).mousemove(function(e) {
	if(e.pageY <= 5)
	{ 
		//if ($.cookie("vspiritspopup")=="true"){
		//	firstTime=false;
		//}
		if (firstTime==true) {
			// Launch MODAL BOX
				$('#exit_content').modal({onOpen: modalOpen, onClose: simplemodal_close});
			}
		}
	});
});


function startChat() {
// Launch MODAL BOX
$('#exit_content').modal({onOpen: modalOpen, onClose: simplemodal_close});
}


/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
	dialog.overlay.fadeIn('fast', function () {
		dialog.container.fadeIn('fast', function () {
			dialog.data.hide().slideDown('fast');
			document.getElementById("exit_content").innerHTML = strBox2;
		});
	});
 firstTime=false;
 //$.cookie("vspiritspopup", "true", { expires: 1 });	
}

   /**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * and data.
 */
function simplemodal_close (dialog) {
	dialog.data.fadeOut('fast', function () {
		dialog.container.hide('fast', function () {
			dialog.overlay.slideUp('fast', function () {
				$.modal.close();
			});
		});
	});
}


function showAgent(){
document.getElementById("vspiritframe").style.visibility = "visible";
document.getElementById("vspiritframe").style.width = "510px";
document.getElementById("vspiritframe").style.height = "465px";
document.getElementById("loadertext").innerHTML = "";
}