
	//AJAX request support
	dojo.require("dojo.io.*");
	//dojo.require("dojo.io.bind");
	
	//publish and subscribe event support
	dojo.require("dojo.event.*");

function getposOffset(obj, offsettype){
	var totaloffset=(offsettype=="left")? obj.offsetLeft : obj.offsetTop;
	var parentEl=obj.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(contentid, e, visible, hidden, menuwidth){
	var dropmenuobj=document.getElementById(contentid);
	var obj = dropmenuobj.style;
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px";
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style;
		dropmenuobj.widthobj.width=menuwidth;
	}
	if (/*e.type=="click" && */obj.visibility==hidden) {
		obj.visibility=visible;
		obj.display="block";
	}
	else /*if (e.type=="click") */{
		obj.visibility=hidden;
		obj.display="none";
	}
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(dropmenuobj, obj, whichedge,menuwidth){
	var edgeoffset=0;
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		if(dropmenuobj.offsetWidth)
			dropmenuobj.contentmeasure = dropmenuobj.offsetWidth;
		else {
			if (menuwidth != null)
				dropmenuobj.contentmeasure = menuwidth;
			else 
				dropmenuobj.contentmeasure = 287;
		}
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) {
			edgeoffset = dropmenuobj.contentmeasure - (windowedge - dropmenuobj.x);
		}
	}
	else{
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset;
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ 
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
			if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) 
				edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge;
		}
	}
	return edgeoffset;
}

function populatemenu(contentId){
	if (ie4||ns6)
		dropmenuobj.innerHTML = document.getElementById(contentId).innerHTML;
}


function dropdownmenu(contentid, obj, e, menuwidth) {
	if (window.event) {event.cancelBubble=true;}
	else if (e && e.stopPropagation) {
		try {
			e.stopPropagation(); 
		} catch (err) {/* dojo may overwrite default function */}
	}
	clearhidemenu();
	var dropmenuobj=document.getElementById(contentid);
	if (ie4||ns6){
		showhide(contentid, e, "visible", "hidden", menuwidth);
	}
    repositionPopupMenu(contentid, obj.id, menuwidth);
}
function getParentOffset(obj, offsettype){
	var totaloffset=0;
	var parentEl=obj.offsetParent;
	while (parentEl!=null){
	totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}
function repositionPopupMenu(dropmenuobjid,objid,menuwidth) {
	var dropmenuobj = document.getElementById(dropmenuobjid);
	var obj = document.getElementById(objid);
	dropmenuobj.x=getposOffset(obj, "left");
	dropmenuobj.y=getposOffset(obj, "top");
	dropmenuobj.style.left=dropmenuobj.x - getParentOffset(dropmenuobj, "left") -(clearbrowseredge(dropmenuobj, obj, "rightedge",menuwidth))+"px";
	dropmenuobj.style.top=dropmenuobj.y - getParentOffset(dropmenuobj, "top") -clearbrowseredge(dropmenuobj, obj, "bottomedge",menuwidth)+(obj.offsetHeight)+"px";
}

function hidemenu(contentid, e){
	var dropmenuobj = document.getElementById(contentid);
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden";
	}
}

function delayhidemenu(contentid){
	if (ie4||ns6)
	delayhide=setTimeout("hidemenu('"+contentid+"')",1000);
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

// Purpose :	Meant to avoid a page refresh when a link is clicked on
function executeView() {
	;
}
// Purpose :	When an "eventId" event occurs on "to" set focus to "from"
function setFocusToFromOnEvent(to,from,eventId) {
	var zip = document.getElementById(to).value;
	if ((window.event && window.event.keyCode == eventId)) {
		document.getElementById(from).focus();
		return false;
	} else {
		return true;
	}
}
// Purpose :	Show message when control "controlId" is blank
function emptyTagValueMessageHandler(controlId, eventObj, message) {
	var zip = document.getElementById(controlId).value;
	if (eventObj.type == 'click') {
		if (zip == message) {
			document.getElementById(controlId).value = "";
		}
	} else if (eventObj.type == 'blur') {
		if (zip == "") {
			document.getElementById(controlId).value = message;
		}		
	}
}

function verifyZipCookie() {
	zip = dojo.io.cookie.getCookie('zip');
	if (zip != null) {
		dojo.byId(delvZipCode).value = zip;
		verifyZipCodeDelivery();
	}
}

var com;
if (!com) com = {}; 
if (!com.havertys) com.havertys={};

com.havertys.getPopupStartPos = function(childLen, childPos, dim)
{//dim = 'width' or 'height'
  var winSize = com.havertys.getWindowSize(), //view size
      winScroll = com.havertys.getWindowScroll(), //scroll offset
      docSize = com.havertys.getDocumentSize(),
      ind = (dim == 'width') ? 0 : 1,
      viewLen = winSize[ind];
  /*
  if (childLen < winSize) use childPos
  else (check scroll position) - if childLen < scroll + winSize use (scroll + winSize) - childLen
  else set 0
  */
  var startPos = 0;
  if (childLen <= viewLen) {
    //fits in the current view area
    //make sure childPos is in view to start
    childPos = (childPos < winScroll[ind]) ? winScroll[ind] : childPos;
    return ((childPos + childLen) < winScroll[ind] + viewLen) ? childPos : winScroll[ind] + viewLen - childLen;
  }
  viewLen = docSize[ind];
  if (childLen <= viewLen) {
    //if fits and room below just put at top of veiw
    childPos = (childPos < winScroll[ind]) ? winScroll[ind] : childPos;
    //if can put at top of viewing area (because room below
    if (childPos + childLen < docSize[ind])
    {
      childPos = winScroll[ind];
    } else {
      childPos = docSize[ind] - childLen;
    }
    return childPos;
    return (childPos + childLen <= docSize[ind] - winScroll[ind]) ? childPos : docSize[ind] - childLen;
    //otherwise not enough room below, set to fit to bottom
  }
  
  return 0; //doesnt fit so set to top
}

com.havertys.getWindowSize = function() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [(myWidth > 15) ? myWidth - 15 : myWidth, (myHeight > 15 ) ? myHeight - 15 : myHeight];
}
com.havertys.getDocumentSize = function() {
  var w = 0, h = 0;
  if (document.body && (document.body.scrollHeight != null)) {
    w = document.body.scrollWidth;
    h = document.body.scrollHeight;
  } else if (document.height != null) {
    w = document.width;
    h = document.height;
  }
  return [w, h];
}
com.havertys.getWindowScroll = function() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}