﻿
var PatientPersonalityQuiz = {
	overlay: null,
	iFrame: null,

	doPanel: function() {

		if (this.overlay) {
			this.overlay.show();
			return;
		}

		this.overlay = new YAHOO.widget.Panel('PatientPersonalityQuizOverlay', {
			fixedcenter: true,
			constraintoviewport: true,
			width: '723px',
			height: '490px',
			visible: true,
			close: true,
			zindex: '8',
			draggable: false
		});

		this.overlay.setHeader('Patient Personality Quiz');
		this.overlay.render(document.body);
		this.overlay.center();

		this.iFrame = document.createElement('iframe');
		this.iFrame.src = '/Content/PatientPersonalityQuiz/PatientPersonalityQuiz.asp';
		this.iFrame.width = 717;
		this.iFrame.height = 460;
		this.iFrame.frameBorder = 0;
		this.iFrame.setAttribute('marginheight', '0');
		this.iFrame.setAttribute('marginwidth', '0');
		this.iFrame.scrolling = 'auto';
		this.overlay.body.appendChild(this.iFrame);

		this.setCookie();

	},

	setCookie: function() {
		if (this.hasCookie() === true) { return; }
		var oDate = new Date();
		oDate.setMonth( oDate.getMonth() + 6 );
		document.cookie = 'PatientPersonalityQuiz=Shown; expires=' + oDate.toGMTString();
	},

	hasCookie: function() {
		var aCookies = document.cookie.split(';');
		var sCookie, i = aCookies.length; while (i--) {
			sCookie = aCookies[i];
			while (sCookie.charAt(0) === ' ') { sCookie = sCookie.substr(1); }
			if (sCookie.indexOf('PatientPersonalityQuiz') === 0) { return true; }
		}
		return false;
	},

	init: function() {
		Event.addListener('layout_LeftBottom', 'click', this.doPanel, this, true);
//		Event.addListener('personalityQuiz', 'click', this.doPanel, this, true);

		var noquiz = false;
		var str = window.location.href;
		
		if ( str.search('noquiz=y') != -1 )
			noquiz = true;
		
		// If the user does not have a cookie saying they've seen the quiz,
		// then we should open the quiz automatically.
		if (this.hasCookie() === false && noquiz === false) {
			this.doPanel();
		}

	}

};

