(func = function(){

/* How long to wait before showing the box (in milliseconds) */
var timer = 1000;

/* where are the images */
var imageURL = "http://survey.eqr1.com/assets/T04919/";

/* The prefix for our stylesheet rules, to make sure we don't affect the host page's style. */
var stylePrefix = 'SVDS-';

/* Number of days before the cookie expires and the survey box will be shown again. */
var cookieExpiry = 365;

/* The name of the cookie that we will use to check if somebody has already seen the box */
var cookieName = 'SVDSge1cp';

/* Content to put in the box */
var boxContent = "<a href=\"\" title=\"Act Now\" class=\""+stylePrefix+"eqrbutton "+stylePrefix+"behaviour-open\"><span>Act Now<\/span><\/a><a href=\"#\" title=\"Close Window\" class=\""+stylePrefix+"behaviour-continue\" style=\"float: left; width: 82px; height: 17px; margin: 10px 75px 0 20px;\"><img  src=\""+imageURL+"close.gif\" alt=\"Close Window\" \/><\/a>\n";

/* Use an overlay or not */
var overlay = false;

/* Specify the direction to slide in, or false for no sliding */
var slideTo = 'right';

/* Specify the url to go to when ok is clicked */
var fullUrl = 'http://www.eqr1.com/sw.pcm?n=T04919C';

/* Takeover the current window. If false, opens in a new window */
var takeover = false;

/* Let the new window be resized */
var newResizeable = true;

/* Give the new window toolbars */
var newToolbar = false;

/* Give the new window menubars */
var newMenubar = false;

/* Give the new window a status bar */
var newStatus = false;

/* Give the new window direcetories */
var newDirectories = false;



dialogStyle = 
'.'+stylePrefix+'dialog-overlay { background-color: #F0F0F0; opacity: 0.5; filter: alpha(opacity=50); position: fixed; height: 100%; width: 100%; left: 0; top: 0; display: none; z-index: 2147483646 !important; }' +
'.'+stylePrefix+'dialog { position: relative; z-index: 2147483647 !important; } ' +
'.'+stylePrefix+'dialog-content {border: 1px solid #555555;width: 350px; height: 300px; background-image: url('+imageURL+'1_GE_survey_bckgrnd.png); background-repeat: no-repeat; margin: 0; padding: 0;} ' +
'.'+stylePrefix+'eqrbutton {float: left; width: 110px; height: 22px; margin: 235px 75px 0 20px; background-image: url('+imageURL+'2_GE_survey_button.png); background-repeat: no-repeat;}' +
'.'+stylePrefix+'eqrbutton span {display: none;}' +
'iframe.'+stylePrefix+'iefix {	display: none; display/**/: block; position: absolute; top: 0; left: 0; z-index: -1; filter:mask(); }';

var styleNode = document.createElement('style');
styleNode.type = "text/css";
// browser detection (based on prototype.js)
if(!!(window.attachEvent && !window.opera)) {
     styleNode.styleSheet.cssText = dialogStyle;
} else {
     var styleText = document.createTextNode(dialogStyle);
     styleNode.appendChild(styleText);
}
document.getElementsByTagName('head')[0].appendChild(styleNode);

/**
 * Modal dialog box based on code from:
 * http://code.google.com/p/javascript-simple-dialog/ *
 */

/* Utility functions */
function bindEventHandler(element, eventName, handler) {
	if (element.addEventListener) {
		// The standard way
		element.addEventListener(eventName, handler, false);
	} else if (element.attachEvent) {
		// The Microsoft way
		element.attachEvent('on' + eventName, handler);
	}
}

function setClass(element, className) {
	element.className = stylePrefix + className;	
}

function pageWidth() {
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : 0;
}
function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : 0;
}

function getWindowWidth() {
	return window.innerWidth != null ? window.innerWidth : document.body.clientWidth != null ? document.body.clientWidth : document.documentElement && document.documentElement.clientWidth != null ? document.documentElement.clientWidth : 'undefined';
}
function getWindowHeight() {
	return window.innerHeight != null ? window.innerHeight : document.body.clientHeight != null ? document.body.clientHeight : document.documentElement && document.documentElement.clientHeight != null ? document.documentElement.clientHeight : 'undefined';
}

function getComputedHeight(el) {
	if (!document.defaultView || !document.defaultView.getComputedStyle) {
	   return el.offsetHeight;
	} else{
	  return parseInt(document.defaultView.getComputedStyle(el, "").getPropertyValue("height"))
	}
}

// Based on scripts from quirksmode.org
function createCookie(name,value) {
	var date = new Date();
	date.setTime(date.getTime()+(cookieExpiry*86400000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


/**
 * The modal dialog class
 * @constructor
 */
function Dialog(options) {
	this.options = {
		width: 400,
		top: 120,
		modal: false,
		openOnCreate: true,
		destroyOnClose: true,
		escHandler: this.close,
		slide: 'top',
		slideTime: 1500,
		animationTick: 20///,
	};
	// Overwrite the default options
	for (var option in options) {
		this.options[option] = options[option];
	}
	// Create dialog dom
	this._makeNodes();
	if (this.options.openOnCreate) {
		this.open();
	}
}

Dialog.prototype = {
	/* handles to the dom nodes */
	container: null,
	content: null,
	_overlay: null,
	_wrapper: null,
	_zIndex: 0,
	_escHandler: null,
	
	/**
	 * Shows the dialog
	 */
	open: function() {
		this._makeTop();
		
		if (this.options.modal) {
			this._overlay.style.display = 'block';
		}
		
		this.finalLeft = parseInt((pageWidth() - this.options.width) / 2);
		this.finalTop = parseInt((document.body.scrollTop || document.documentElement.scrollTop) + this.options.top);
		this.currentLeft = this.finalLeft;
		this.currentTop = this.finalTop;
		
		var ws = this._wrapper.style;
		ws.visibility = 'hidden';
		ws.display = 'block';
		
		var boxHeight = getComputedHeight(this._wrapper);
		if (this.options.slide == 'right') {
			this.currentLeft = -this.options.width;
		} else if (this.options.slide == 'left') {
			// Start it on the page, as otherwise we create ugly scrollbars
			this.currentLeft = pageWidth() - this.options.width;
		} else if (this.options.slide == 'down') {
			this.currentTop = -boxHeight;
		} else if (this.options.slide == 'up') {
			this.currentTop = pageHeight() - boxHeight;
		}
		
		if (this.options.slide) {
			this.xPerTick = (this.finalLeft - this.currentLeft) / this.options.slideTime;
			this.yPerTick = (this.finalTop - this.currentTop) / this.options.slideTime;
			this.animationTimer = setInterval(this._makeHandler(this._animate, this), this.options.animationTick);
			this.lastTick = (new Date()).getTime();	
		}
		
		ws.left = this.currentLeft + 'px';
		ws.top = this.currentTop + 'px';
		ws.visibility = 'visible';
		this._wrapper.focus();
	},
	
	/**
	 * Closes the dialog
	 */
	close: function() {
		if (this.options.destroyOnClose) {
			this._destroy();
		} else {
			if (this.options.modal)
				this._overlay.style.display = 'none';
			this._wrapper.style.display = 'none';
		}
	},

	/**
	 * Open the survey up in a new window
	 */
	openSurvey: function() {
	  this.close();
		if (takeover) {
			window.location = fullUrl;
		} else {
			var windowOptions = 'scrollbars=1,location=1' +
',  resizable=' + (newResizeable ? '1' : '0') +
',  toolbar=' + (newToolbar ? '1' : '0') + 
',  menubar=' + (newMenubar ? '1' : '0') +
',  status=' + (newStatus ? '1' : '0') + 
',  directories' + (newDirectories ? '1' : '0');

			var survey = window.open(fullUrl,'',windowOptions);
			
			// Need to check if the window exists or was blocked by a popup blocker
			if (survey) {
				window.blur();
				survey.focus();
			}
			if (this.options.link) {
				window.location = this.options.link;
			}
		}
		
		return false;
	},
	
	/**
	 * Continue to the next link unharmed
	 */
	cont: function() {
		this.close();
		
		if (this.options.link) {
			window.location = this.options.link;
		}
		
		return false;
	},
  

	/**
	 * Add buttons to the dialog actions panel after creation
	 * @param {object} buttons Object with property name as button text and value as click handler
	 * @param {boolean} prepend If true, buttons will be prepended to the panel instead of being appended
	 */

	/**
	 * Makes the dom tree for the dialog
	 */
	_makeNodes: function() {
		if (this._overlay || this._wrapper) {
			return; // Avoid duplicate invocation
		}
		
		// Make overlay
		if (this.options.modal) {
			this._overlay = document.createElement('div');
			setClass(this._overlay, 'dialog-overlay');
			document.body.appendChild(this._overlay);
		}
		
		// {begin dialog body
		var content = document.createElement('div');
		setClass(content, 'dialog-content');
		content.innerHTML = this.options.content;
		this.content = content;
		
		var actions = content.getElementsByTagName('a');
		for (var i = 0, ii = actions.length; i != ii; i++) {
			if (actions[i].className.match(new RegExp(stylePrefix+'behaviour-continue'))) {
				actions[i].onclick = this._makeHandler(this.cont, this);
			} else if (actions[i].className.match(new RegExp(stylePrefix+'behaviour-open'))) {
				actions[i].onclick = this._makeHandler(this.openSurvey, this);
			}
		}

		var container = document.createElement('div');
		setClass(container, 'dialog');
		container.appendChild(content); ///container.appendChild(body);
		this.container = container;

		var wrapper = document.createElement('div');
		var ws = wrapper.style;
		ws.position = 'absolute';
		ws.overflow = 'hidden';
		ws.width = this.options.width + 'px';
		ws.display = 'none';
		ws.outline = 'none';
		wrapper.appendChild(container);
		// register keydown event
		if (this.options.escHandler) {
			wrapper.tabIndex = -1;
			this._onKeydown = this._makeHandler(function(e) {
				if (!e) {
					e = window.event;
				}
				if (e.keyCode && e.keyCode == 27) {
					this.options.escHandler.apply(this);
				}
			}, this);
			bindEventHandler(wrapper, 'keydown', this._onKeydown);
		}
		this._wrapper = document.body.appendChild(wrapper);

		if (Dialog.needIEFix) {
			this._fixIE();
		}
	},

	/**
	 * Removes the nodes from document
	 * @param {object} buttons Object with property name as button text and value as click handler
	 * @return {Array} Array of buttons as dom nodes
	 */

	/** A helper function to bind events to this class */
	_makeHandler: function(method, obj) {
		return function(e) {
			return method.call(obj, e);
		}
	},

	/** A helper function used by open */
	_makeTop: function() {
		if (this._zIndex < Dialog.Manager.currentZIndex) {
			if (this.options.modal)
				this._overlay.style.zIndex = Dialog.Manager.newZIndex();
			this._zIndex = this._wrapper.style.zIndex = Dialog.Manager.newZIndex();
		}
	},

	_fixIE: function() {
		var width = document.documentElement["scrollWidth"] + 'px';
		var height = document.documentElement["scrollHeight"] + 'px';
		
		if (this.options.modal) {
			var os = this._overlay.style;
			os.position = 'absolute';
			os.width = width;
			os.height = height;
		}

		var iframe = document.createElement('iframe');
		setClass(iframe, 'iefix');
		iframe.style.width = width;
		iframe.style.height = height;
		this._wrapper.appendChild(iframe);
	},
	
	_animate: function() {
		var ws = this._wrapper.style;
		
		var currentTick = (new Date()).getTime();
		var ticks = currentTick - this.lastTick;
		this.lastTick = currentTick;
		
		var difX = Math.abs(this.currentLeft - this.finalLeft);
		var difY = Math.abs(this.currentTop - this.finalTop);
		var vX = Math.floor(this.xPerTick * ticks);
		var vY = Math.floor(this.yPerTick * ticks);
		
		if (difX != 0) {
			if (difX < Math.abs(vX)) {
				this.currentLeft = this.finalLeft;	
			} else {
				this.currentLeft += vX;
			}
			ws.left = this.currentLeft + 'px';
		}
		if (difY != 0) {
			if (difY < Math.abs(vY)) {
				this.currentTop = this.finalTop;	
			}	else {
				this.currentTop += vY;	
			}
			ws.top = this.currentTop + 'px';
		}
		
		if (difX === 0 && difY === 0) {
			clearTimeout(this.animationTimer);	
		}
	},

	/**
	 * Removes the nodes from document
	 */
	_destroy: function() {
		document.body.removeChild(this._wrapper);
		if (this.options.modal)
			document.body.removeChild(this._overlay);
		this.container = null;
		this.content = null;
		this._overlay = null;
		this._wrapper = null;
	}
};

Dialog.needIEFix = (function () {
	var userAgent = navigator.userAgent.toLowerCase();
	return /msie/.test(userAgent) && !/opera/.test(userAgent) && !window.XMLHttpRequest;
})();

/** This simple object manages the z indices */
Dialog.Manager = {
	currentZIndex: 2147483644,
	newZIndex: function() {
		return ++this.currentZIndex;
	}
};

function survey_init() {
  setTimeout(function() {
  	if (!readCookie(cookieName)) {
    	var dialog = new Dialog({
  	  	content: boxContent,
  			modal: overlay,
  	  	slide: slideTo
    	});
  	  createCookie(cookieName, 'seen');
    }
  }, timer);
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func
    } else {
        window.onload = function () {
            if (oldonload) {
                oldonload()
            }
            func()
        }
    }
};
addLoadEvent(survey_init);



})();
