function AdvCountdown(i)
{
	i--;
	if (i < 0)
	{
		CloseVeilAdv();
		return;
	}
	setTimeout("AdvCountdown(" + i + ")", 1000);
}

function CloseVeilAdv()
{
	VeilObj.Close()
	
	var s = document.getElementById("advTop");
	var t = document.getElementById("advBtm");
	s.innerHTML = "";
	t.innerHTML = "";
	
	var o = document.getElementById("veil");
	var p = document.getElementById("veilBox");
	o.className = "";
	p.className = "";
	
	var a = document.getElementById("veilBox");
	a.id = "adv";
	a.style.display = "inline";
	
	var b = document.getElementById("veilBoxWait");
	b.id = "veilBox";
	
	document.getElementById("advBtm").style.display = "none";
	document.getElementById("advTop").style.display = "none";
}

function OpenVeil(w,x,y)
{
	var o = document.getElementById("veil");
	var p = document.getElementById("veilBox");
	var q = document.getElementById("veilHead");
	var r = document.getElementById("veilBody");
	
	o.style.display = "inline";
	p.style.display = "inline";
	p.style.width = w;
	
	q.innerHTML = "<img alt=\"Close\" id=\"veilX\" src=\"http://www.homes-inc.com/images/veil/x.gif\" onClick=\"javascript: VeilObj.Close(); return false;\" />" + x;
	r.innerHTML = y;
	
	VeilObj.Initialize();
}

function OpenVeilAdv(Sec)
{
	document.getElementById("veilBox").id = "veilBoxWait";
	
	var o = document.getElementById("adv");
	o.id = "veilBox";
	o.className = "adv";
	
	var p = document.getElementById("veil");
	p.className = "adv";
	
	var q = document.getElementById("advTop");
	q.innerHTML = "Please wait while your page is customized...";
	
	var r = document.getElementById("advBtm");
	r.innerHTML = "<a href=\"#\" onClick=\"javascript: CloseVeilAdv(); return false;\">Skip this Advertisement</a>";
	
	VeilObj.Initialize();
	AdvCountdown(Sec);
}

function OpenVeilUrl(w,x,u)
{
	var y = AjaxGet(u,false,true);
	if (x == "err=1" || x == "err=2")
		alert("There was a connection timeout. Please try your selection again. If you continue to experience problems, please try a different browser such as Internet Explorer 7.0 (or above) or FireFox 2.0 (or above).");
	else
		OpenVeil(w,x,y);
}

var VeilObj = 
{
	DisableScrollbars: true,
	
	Close : function()
	{
		document.getElementById("veilBody").innerHTML = "";
		this.Veil.style.display = "none";
		this.VeilBox.style.display = "none";
		if (this.DisableScrollbars && window.XMLHttpRequest)
			this.DocBody.style.overflow = "auto";
	},

	FindScrollbarWidth : function()
	{
		var ScrollbarWidth = window.innerWidth - (this.Veil.offsetLeft + this.Veil.offsetWidth);
		this.ScrollbarWidth = (typeof ScrollbarWidth == "number") ? ScrollbarWidth : this.ScrollbarWidth;
	},

	HideScrollbar : function()
	{
		if (this.DisableScrollbars == true)
		{
			if (window.XMLHttpRequest) //ie7, firefox, opera 8+, safari
				this.DocBody.style.overflow = "hidden";
			else
				window.scrollTo(0,0);
		}
	},

	Initialize : function()
	{
		this.DocBody = (document.compatMode == "CSS1Compat") ? document.documentElement : document.body;
		this.Veil = document.getElementById("veil");
		this.VeilBox = document.getElementById("veilBox");
		this.HideScrollbar();
		this.FindScrollbarWidth();
		this.Open();
		this.Listen(window, function(){VeilObj.Open()}, "resize");
	},

	Listen : function(x,y,z) //onload, onunload, etc...
	{
		var z = (window.addEventListener) ? z : "on" + z;
		if (x.addEventListener)
			x.addEventListener(z,y,false);
		else if (x.attachEvent)
			x.attachEvent(z,y);
	},
	
	Open : function()
	{
		var Ie = document.all && !window.opera;
		var ScrollTop = (Ie) ? this.DocBody.scrollTop : window.pageYOffset;
		var DocWidth = (Ie) ? this.DocBody.clientWidth : window.innerWidth - this.ScrollbarWidth;
		var DocHeight = (Ie) ? this.DocBody.clientHeight : window.innerHeight;
		var DocHeightTotal = (Ie) ? ((this.DocBody.offsetHeight > this.DocBody.scrollHeight) ? this.DocBody.offsetHeight : this.DocBody.scrollHeight) : window.innerHeight;
		var BoxWidth = this.VeilBox.offsetWidth;
		var BoxHeight = this.VeilBox.offsetHeight;
		
		this.Veil.style.width = DocWidth + "px";
		this.Veil.style.height = DocHeightTotal + "px";
		this.Veil.style.left = 0;
		this.Veil.style.top = 0;
		this.Veil.style.visibility = "visible";
		
		this.VeilBox.style.left = DocWidth / 2 - BoxWidth / 2 + "px";
		this.VeilBox.style.top = Math.floor(parseInt((DocHeight > BoxHeight) ? ScrollTop + DocHeight / 2 - BoxHeight / 2 + "px" : ScrollTop + 5 + "px")) + "px";
		this.VeilBox.style.visibility = "visible";
	}
}
