GetAQuote = {
	instance : null,
	getInstance : function() {
		if (GetAQuote.instance == null) GetAQuote.instance = new _GetAQuote();
		return GetAQuote.instance;
	}
}
function _GetAQuote() {
	this.vPositionElement = null;
	this.hPositionElement = null;
	this.myId = null;
	this.isPointingUp = null;
}
_GetAQuote.IFRAME_ID = "GetAQuoteIframe";

_GetAQuote.prototype.getIframeId = function() {
	return this.myId;
}
_GetAQuote.prototype.close = function(horizontalElement, verticalElement) {
	Transition.addEffect(document.body, Transition.FADE_IN, "duration=.1,interval=.1");
	document.body.effects.play(Transition.FADE_IN);
	// remove iframe so EAF entries will be removed from browser history
	document.body.removeChild(document.getElementById(_GetAQuote.IFRAME_ID));
	jQuery('#pointer').css('visibility','hidden')
}
_GetAQuote.prototype.getLeft = function() {
	return cursor.x + 38 + "px";
}
_GetAQuote.prototype.getTop = function() {
	var getAquote = document.getElementById(_GetAQuote.IFRAME_ID);
	var windowHeight = document.body.clientHeight + document.body.scrollTop;	
	var elementBottom = getAquote.offsetHeight + getAbsOffsetTop(this.vPositionElement);
	if (elementBottom > windowHeight) {
		jQuery("#upPointer").css('display','none');
		jQuery("#downPointer").css('display','block');
		jQuery("#upPointer_right").css('display','none');
  		jQuery("#downPointer_right").css('display','none');
  		this.isPointingUp = false;
		return (getAbsOffsetTop(this.vPositionElement) - (elementBottom - windowHeight) - 15) + "px";				
	} else {
		jQuery("#upPointer").css('display','block');
		jQuery("#downPointer").css('display','none');
		jQuery("#upPointer_right").css('display','none');
  		jQuery("#downPointer_right").css('display','none');
  		this.isPointingUp = true;
		return getAbsOffsetTop(this.vPositionElement) + 30 + "px";
	}
}
_GetAQuote.prototype.getUrl = function(doc) {
	if (!doc) var doc = document;
	var eafUrlUtil = new URLUtility(doc);
	var params = eafUrlUtil.getParameterMap();
	for (var paramName in params) {
		if (!params[paramName]) eafUrlUtil.removeParameter(paramName);
	}
	return eafUrlUtil.getUrl();
}
_GetAQuote.prototype.pageLoad = function(eafContentElement) {
	var iframe = document.getElementById(_GetAQuote.IFRAME_ID);		
	iframe.style.width = eafContentElement.offsetWidth;
	iframe.style.height = eafContentElement.offsetHeight;
	iframe.style.top = this.getTop();
	iframe.style.left = this.getLeft();
	iframe.style.visibility = "visible";
	if(iframe.style.top.substr(0,iframe.style.top.indexOf('px')) < 0)
	iframe.style.top = '0px';
	var windowWidth = document.body.clientWidth + document.body.scrollLeft;
  	var elementRight = parseInt(iframe.style.left) + parseInt(iframe.style.width);
  	
  	if (elementRight > windowWidth) {
  		iframe.style.left = parseInt(this.getLeft()) - 550;
  		jQuery("#pointer").css("left", parseInt(jQuery("#pointer").css("left")) - 50);
  		if (this.isPointingUp) {
  			jQuery("#upPointer").css("display", "none");
  			jQuery("#downPointer").css("display", "none");
  			jQuery("#downPointer_right").css("display", "none");
			jQuery("#upPointer_right").css("display", "block");
  		} else {
  			jQuery("#upPointer").css("display", "none");
  			jQuery("#downPointer").css("display", "none");
  			jQuery("#upPointer_right").css("display", "none");
  			jQuery("#downPointer_right").css("display", "block");
  		}
  	}
}
_GetAQuote.prototype.setIframeHeight = function(eafContentElement) {
	var iframe = document.getElementById(_GetAQuote.IFRAME_ID);		
	iframe.style.width = eafContentElement.offsetWidth;
	iframe.style.height = eafContentElement.offsetHeight;
}
_GetAQuote.prototype.open = function(verticalElement, vehicleId, pageName) {
	
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id", _GetAQuote.IFRAME_ID);
	iframe.name = _GetAQuote.IFRAME_ID;
	this.myId = _GetAQuote.IFRAME_ID;
	iframe.style.position = "absolute";
	iframe.style.top = "0px";
	iframe.style.visibility = "hidden";
	iframe.style.zIndex = 1000;
	iframe.src = "about:blank";	
	iframe.setAttribute("border", "0");
	iframe.setAttribute("frameBorder", "0");
	iframe.setAttribute("scrolling", "no");
	document.body.appendChild(iframe);	
	this.vPositionElement = verticalElement;
	iframe.src = "getAQuoteForm_widget.do?cellName=inv&widgetName=details_widget_redesign&widgetType=inventory&widgetContext=common&id=" + vehicleId + "&pageName=" + pageName;	
	Transition.addEffect(document.body, Transition.FADE_OUT, "duration=.1,interval=.1,backgroundColor=#222222" );
	document.body.effects.play(Transition.FADE_OUT);	
}

if (!window.getAbsOffsetLeft) {
	function getAbsOffsetLeft(element) {
		if (element.offsetParent) return element.offsetLeft + getAbsOffsetLeft(element.offsetParent);
		else return element.offsetLeft;
	}
}
if (!window.getAbsOffsetTop) {
	function getAbsOffsetTop(element) {
		if (element.offsetParent) return element.offsetTop + getAbsOffsetTop(element.offsetParent);
		else return element.offsetTop;
	}
}
var personal = 1;
var business = 0;
function initResizeGetAQuotePopup() {
	document.getElementById(_GetAQuote.IFRAME_ID).style.height = document.getElementById(_GetAQuote.IFRAME_ID).offsetHeight - 24;
}
function resizeGAQpopup(use) {
	if(use == "personal" && personal == 0) {
		document.getElementById(_GetAQuote.IFRAME_ID).style.height = document.getElementById(_GetAQuote.IFRAME_ID).offsetHeight - 24;
		business = 0;
		personal = 1;
	}
	else if(use == "business" && business == 0) {
		document.getElementById(_GetAQuote.IFRAME_ID).style.height = document.getElementById(_GetAQuote.IFRAME_ID).offsetHeight + 24;
		personal = 0;
		business = 1;
	}
}
