var OverlayAPI = null, OverlayElementId = "demoOverlay", OverlayUrl = "//store.volusion.com/v/demo-setup/shopping-cart-software-free-trial.asp";
function CloseWizardCancelOnClick() {
	document.getElementById('close_box').style.display = 'none';
}
function CloseWizardOnClick() {
	document.getElementById('close_box').style.display = 'block';
	
}
function OpenWizardOnClick() {
	CloseWizardCancelOnClick();
	if (document.getElementById("DemoSetupIFrame").src.indexOf("blank.html") != -1) {
		document.getElementById("DemoSetupIFrame").src = OverlayUrl;
	}
}

function CreateWizardOverlay(id) {
	return $(id).overlay({
		expose: {
			color: '#000000',
			opacity: 0.45,
			loadSpeed: 0,
			closeSpeed: 0,
			maskId: 'demo_mask'
		},
		oneInstance: false,
		onBeforeLoad: OpenWizardOnClick,
		onBeforeClose: CloseWizardCancelOnClick,
		closeOnClick: false
	});
}

$(document).ready(function() {
	var overlayDiv = document.createElement('div');
	overlayDiv.id = OverlayElementId;
	overlayDiv.className = OverlayElementId;

	var overlayHtml = '<div class="wizard_wrapper" id="wizard_wrapper"><div id="close_box" style="display: none;"><div class="close_box_content"><h2> Are you sure you want to close your 14-day trial?</h2><div class="btn_wrapper"><a class="submit_btn close">Yes</a><a class="submit_btn" onclick="CloseWizardCancelOnClick();">No</a></div></div></div><div class="wizard_header_left"><img src="//store.volusion.com/v/demo-setup/images/logo.gif" /></div><div class="wizard_header_right"><h2>Free 14-day trial wizard</h2></div><iframe id="DemoSetupIFrame" src="//store.volusion.com/blank.html" frameborder="0"></iframe><a onclick="CloseWizardOnClick();" class="wizard_close">Close</a><div class="wizard_footer_wrapper"><div class="wizard_footer">Have questions or need assistance? One of our expert consultants will be happy to help you. <a href="javascript: LaunchVolusionChat(0);">Click here</a> for live chat or call 800.646.3517 xt.2 </div></div><br/><div class="wizard_secure_server">Secure<br/>server</div></div>';

	overlayDiv.innerHTML = overlayHtml;
	document.body.appendChild(overlayDiv);

	OverlayAPI = CreateWizardOverlay("a.demoLink");

	var curLocation = window.location.href;
	if (curLocation.indexOf("?trigger=tryitfree") != -1) {
		$("a.demoLink").overlay().load();
	}
});
