function bhon(obj) {
	obj.innerHTML ='<img src=images/arrow_left_on.jpg>';
}

function bhoff(obj) {
	obj.innerHTML ='<img src=images/arrow_left_off.jpg>';
}

function bbon(obj) {
	obj.src =obj.src.replace("1", "2");
}

function bboff(obj) {
	obj.src =obj.src.replace("2", "1");
}

var fontsize = 13;
function changeFontSize(direction) {
	el = document.getElementsByTagName("body");
	if (direction == 0)
	{
		el[0].style.fontSize = "13px";
		fontsize = 13;
	} else {
		if (fontsize >= 19 && direction > 0) return true;
		if (fontsize <= 11 && direction < 0) return true;
		fontsize = parseInt(fontsize) + parseInt(direction); 
		el[0].style.fontSize = fontsize + "px";
	}
	direction = 1 - direction;
}


function showContactForm() {
	el = document.getElementById("contactform");
	el.style.height = "445px";
	window.location="#footer";
}

function  closeContactForm() {
	el = document.getElementById("contactform");
	el.style.height = "145px";
	history.go(-1);

}

function submitContactForm() {

}

var sliderLeft = 0;
var sliderCount = 4;
var slideInterval;
var slideTimer = 150;
var slideDirection = 0;
var slideStep = 0;
var slideSteps = 0;
var stepDuration = 10;
var slideLength = 0; //pixels
function slideLeft() {
	if (sliderLeft>=-100) return false;
	slideDirection = 1;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
}

function slideRight() {
	slideDirection = -1;
	if (sliderLeft <= slideLength) return false;
	slideSteps = slideTimer/stepDuration;
	slideInterval = setInterval(slide, stepDuration);
}

function slide() {
	slideStep ++;
	if (slideStep > slideSteps)
	{
		slideStep = 0;
		clearInterval(slideInterval);
		return true;
	}
	increment = Math.abs(380) / slideSteps;
	el=document.getElementById('slider'); 
	sliderLeft = sliderLeft + increment * slideDirection;
	el.style.marginLeft= sliderLeft + 'px';
	
}

function message5(title, msg, wdth, hgth) {
	if (!wdth) wdth="300";
	if (!hgth) hgth="80";
	showOverlay();
	txt = "<table cellpadding='0' cellspacing='0' border='0'style='border-collapse: collapse;'>";
	txt += "<tr><td height='56' width='55' style='border-left: 1px solid #ff6633; border-top: 1px solid #ff6633; background-color: #fff;'>&nbsp;</td><td style='border-top: 1px solid #ff6633;  background-color: #fff;'' align='right'><img src='images/bt_close.jpg' onmouseover='msover3(this)' onmouseout='msout3(this)' style='cursor: pointer;' onclick='closeWait();'></td><td width='62' align='right' valign='top'><img src='images/box_corner_right.gif'></td></tr>";
	txt += "<tr><td width='55' style='border-left: 1px solid #ff6633;  background-color: #fff;'>&nbsp;</td><td class='popup_body' style='width: "+wdth+"px; height: "+hgth+"px;  background-color: #fff;' valign='top' align='left'>";
	if (title)
	{
		msg = "<h1>" + title + "</h1>" + msg;
	}
	txt += msg;
	txt += "</td><td width='62' style='border-right: 1px solid #ff6633; background-color: #fff;'>&nbsp;</td></tr>";
	txt += "<tr><td height='56' width='55' align='left' valign='bottom' style='border: right: 1px solid #fff; ' ><img src='images/box_corner_left.gif' border=0></td><td style='border-bottom: 1px solid #ff6633;  background-color: #fff;'>&nbsp;</td><td style='border-right: 1px solid #ff6633; border-bottom: 1px solid #ff6633;  background-color: #fff;'>&nbsp;</td></tr>";
	txt += "</table>";


	dv = document.getElementById(messageid);
	if (!dv)
	{
		dv = document.createElement("div");

		dv.style.position = "absolute";
		dv.style.display = "block";
		dv.innerHTML = txt;
		opacity(dv, 0);
		dv.style.top = "0px";
		dv.style.left = "0px";
		dv.style.zIndex = overlayZ + 1;	
		dv.style.padding = "0px";
		dv.id = messageid;
		document.body.appendChild(dv);
	} else  {
		dv.innerHTML = txt;
		dv.style.display = "block";
	}
	w = dv.offsetWidth; //if (parseInt(w) == 0) w = 600;
	h = dv.offsetHeight; //if (parseInt(h) == 0) h = 400;
	c = getCenter(w, h);
	dv.style.left = c.x + "px";
	dv.style.top = c.y + "px";
	opacity(dv, 100);

}

function doSearch() {
	el = document.getElementById('txtSearch');
	window.location = 'index.php?s=Search&txt=' + el.value;
}

function showEmail() {
	txt = "<p>Know someone who might like to read this page? Let them know!";
	txt += "<br>Enter their name and email and press submit.</p>";
	txt += "<form id='frmSendEmail'><table cellpadding='0' cellspacing='0' class='sendfriend'>";
	txt += "<tr><td align='right' width='100'>Friend's name</td><td align='left'><input type='text' name='sendName' id='sendName'></td></tr>";
	txt += "<tr><td align='right'>Your email</td><td align='left'><input type='text' name='sendFromEmail' id='sendFromEmail'></td></tr>";
	txt += "<tr><td align='right'>Friend's email</td><td align='left'><input type='text' name='sendEmail' id='sendEmail'></td></tr>";
	txt += "<tr><td align='right'>Message</td><td align='left'><textarea name='sendMessage' id='sendMessage' rows=4 cols=30></textarea></td></tr>";
	txt += "<tr><td align='right'></td><td align='right'><img src='images/bt_submit.png' style=\"cursor: pointer;\" onclick=\"x=document.getElementById('frmSendEmail'); sendEmailFriend(x);\"></td></tr>";
	txt += "</table></form>";
	message5('Share this page', txt, 400, 200);
}


function sendEmailFriend(obj) {
	el = document.getElementById("sendName"); if (!el.value) { alert("Name is required!"); return false; }
	el = document.getElementById("sendFromEmail"); if (!el.value) { alert("Your Email is required!"); return false;}
	el = document.getElementById("sendEmail"); if (!el.value) { alert("Email is required!"); return false;}
	url = "index.php?s=send_email&" + getForm(obj);
//	showWait();
	initObj();
//	alert(url);return false;
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_sendEmail;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _sendEmail() {
	if(checkReadyState(xmlhttp)) {
//		closeWait();
//		var response = xmlhttp.responseXML.documentElement;
//		response.normalize;
		message5("Thank you", "Your invitation was sent!");
	}
}


function submitRequest(obj) {

	el = document.getElementById("contactPhone"); 
	el2 = document.getElementById("contactEmail"); if (!el.value && !el2.value) { alert("You must provide a Phone Number and/or and Email Address for callback purposes!"); return false;}
	url = "index.php?s=send_request&" + getForm(obj);
//	showWait();
	initObj();
//	alert(url);return false;
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_submitRequest;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _submitRequest() {
	if(checkReadyState(xmlhttp)) {
//		closeWait();
//		var response = xmlhttp.responseXML.documentElement;
//		response.normalize;
		message5('Thank You', 'Thank you for your interest in V!VA Retirement Communities.<br>We will contact you within 24 hours regarding your inquiry', 360);
	}
}


function loadImage(im, full) {
	el=document.getElementById('galleryMainImage'); 
	el.src = im.replace("_t", "");
	if (full)
	{
		el.style.cursor = "pointer";
		s = im.replace("_t", "_f");
		el.onclick = function () { imageF(s);};
	}
}




 function imageF(path, w, h) {
		i = new Image();
		i.src = path;
	 t = "<img ";
//	 if (w) t += " width=\"" + w + "\" ";
//	 if (h) t += " width=\"" + h + "\" ";
	 t += " src='"+path+"'>";
		i.onload = function () { message2(t)}
//	 message2(t);
 }



function showInventory(comm) {

	url = "index.php?n=community&o=get_inventory_popup&comm="+comm;
//	showWait();
	initObj();
//	alert(url);return false;
	if (xmlhttp!=null) {
	  xmlhttp.onreadystatechange=_showInventory;
	  xmlhttp.open("GET",url,true);
	  xmlhttp.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );
	  xmlhttp.send(null);
	}
	txt = "";
}

function _showInventory() {
	if(checkReadyState(xmlhttp)) {
//		closeWait();
		var response = xmlhttp.responseXML.documentElement;
		response.normalize;
		ret=response.getElementsByTagName("frmdata");
		txt= getXMLNode(ret);
		message2(txt);
	}
}

function showAppliances() {
		txt= "<img src='images/popup-appliances.jpg' usemap='#appliancemap'><map name='appliancemap'><area shape='rect' target='_blank' coords='240,0,390,50' href='http://www.subzero.com/'><area shape='rect'  target='_blank' coords='405,0,560,50' href='http://www.wolfappliance.com/'></map>";
		message2(txt);
//		imageF('images/popup-appliances.jpg', 792,594);
}

var galImages = [];
var curImage = 0;
var fadeDirection = 1;
var fadeInProgress = 0;

function fadeStart() {
 el2 = document.getElementById('picholder');
 el2.src = galImages[curImage];
}

function fadeLeft() {
	if (fadeInProgress) return false;
	fadeDirection = -1;
	fadeInProgress = 1;
	nxtImage = curImage + fadeDirection;
	if (fadeDirection > 0 && nxtImage > galImages.length - 1)
	{
		nxtImage = 0;
	}
	if (fadeDirection < 0 && nxtImage < 0)
	{
		nxtImage = galImages.length - 1;
	}
	el = document.getElementById('picholder');
	el.style.backgroundImage = "url("+galImages[nxtImage]+")";
	slideInterval = setInterval(dofade, 10);
}

function fadeRight() {
	if (fadeInProgress) return false;
	fadeDirection = 1;
	fadeInProgress = 1;
	nxtImage = curImage + fadeDirection;
	if (fadeDirection > 0 && nxtImage > galImages.length - 1)
	{
		nxtImage = 0;
	}
	if (fadeDirection < 0 && nxtImage < 0)
	{
		nxtImage = galImages.length - 1;
	}

	el = document.getElementById('picholder');
	el.style.backgroundImage = "url("+galImages[nxtImage]+")";
	slideInterval = setInterval(dofade, 10);


}

var fadesteps = 0;
var op = 100;
function dofade() {
 el = document.getElementById('picholder');
 el2 = document.getElementById('pic');
 step = 3;
 if (fadesteps > 10)
 {
	 step = 4;
 }
 if (fadesteps > 20)
 {
	 step = 5;
 }
 if (fadesteps > 25)
 {
	 step = 6;
 }
	op = op - step;
	opacity(el2, op);
	fadesteps ++;
	if (op <= 0)
	{
		clearInterval(slideInterval);
		curImage = nxtImage;
//		if (fadeDirection > 0 && curImage > galImages.length - 1)
//		{
//			curImage = 0;
//		}
//		if (fadeDirection < 0 && curImage < 0)
//		{
//			curImage = galImages.length - 1;
//		}
//		nxtImage = curImage + fadeDirection;
//		if (fadeDirection > 0 && nxtImage > galImages.length - 1)
//		{
//			nxtImage = 0;
//		}
//		if (fadeDirection < 0 && nxtImage < 0)
//		{
//			nxtImage = galImages.length - 1;
//		}

		 el2.src = galImages[curImage];
		 el.background = "none";
		 opacity(el2,100);
		 op = 100;
		 fadesteps = 0;
		 fadeInProgress = 0;
		 
	}
}

function fadeImage(imgid) {
	if (fadeInProgress) return false;
	fadeDirection = 1;
	fadeInProgress = 1;
	nxtImage = imgid-1;

	el = document.getElementById('picholder');
	el.style.backgroundImage = "url("+galImages[nxtImage]+")";
	slideInterval = setInterval(dofade, 10);

}

var slideshowIndex = 1;
var imgHolder;

function slideshow() {
	imgHolder = new Image();
//		el = document.getElementById('picholder');
//		v = Viewport();
//		el = document.getElementById('pic');
//		h = el.height;
//		w = el.width;
//
//		ww = v.pageX;
//		hh = v.pageY;
//		
//		rh = hh/h;
//		rw = ww/w;
//		r = Math.min(rh, rw);
//
//		newh = h * r;
//		neww = w * r;
//		
//		el.style.height = newh + "px";
//		el.style.width = neww + "px";
//		el.style.top = ((hh - newh) /2 ) + "px";
//		el.style.left = ((ww - neww) /2 ) + "px";
		el = document.getElementById('pic1');
		opacity(el,0);
		imgHolder.onload=resizeImage2;
		imgHolder.src = galImages[0];

		setTimeout(slideNext, 4000);
}

function slideNext() {
	slideshowIndex ++;
	if (slideshowIndex > galImages.length) slideshowIndex = 1;
		el1 = document.getElementById('pic1');
		el2 = document.getElementById('pic2');
		imgHolder.onload=resizeImage;
		imgHolder.src = galImages[slideshowIndex-1];
		opacity(el1, 0);
		opacity(el2, 100);
		slideInterval = setInterval(dofade2, 10);
//	fadeImage(slideshowIndex);
}

function resizeImage() {
		v = Viewport();
		el = document.getElementById('pic1');
		el.src = galImages[slideshowIndex-1];
		h = imgHolder.height;
		w = imgHolder.width;

		ww = v.pageX;
		hh = v.pageY;
		
		rh = hh/h;
		rw = ww/w;
		r = Math.min(rh, rw);

		newh = h * r;
		neww = w * r;
		
		el.style.height = newh + "px";
		el.style.width = neww + "px";
		el.style.top = ((hh - newh) /2 ) + "px";
		el.style.left = ((ww - neww) /2 ) + "px";

}

function resizeImage2() {
		v = Viewport();
		el = document.getElementById('pic2');
		el.src = galImages[slideshowIndex-1];
		h = imgHolder.height;
		w = imgHolder.width;

		ww = v.pageX;
		hh = v.pageY;
		
		rh = hh/h;
		rw = ww/w;
		r = Math.min(rh, rw);

		newh = h * r;
		neww = w * r;
		
		el.style.height = newh + "px";
		el.style.width = neww + "px";
		el.style.top = ((hh - newh) /2 ) + "px";
		el.style.left = ((ww - neww) /2 ) + "px";

}

//var fadesteps = 0;
//var op = 100;
function dofade2() {
 el1 = document.getElementById('pic1');
 el2 = document.getElementById('pic2');
 step = 3;
 if (fadesteps > 10)
 {
	 step = 4;
 }
 if (fadesteps > 20)
 {
	 step = 5;
 }
 if (fadesteps > 25)
 {
	 step = 6;
 }
	op = op - step;
	opacity(el2, op);
	fadesteps ++;
	if (op <= 0)
	{
		op = 0;
		clearInterval(slideInterval);
		el2.src = el1.src;
		el2.height = el1.height;
		el2.width = el1.width;
		el2.style.top = el1.style.top;
		el2.style.left = el1.style.left;
//		 el2.src = galImages[curImage];
//		 el.background = "none";
//		 opacity(el2,100);
//		 op = 100;
//		 fadesteps = 0;
//		 fadeInProgress = 0;
		slideInterval = setInterval(doFade3, 50);
		 
	}
}

function doFade3() {
	 el1 = document.getElementById('pic1');
	 el2 = document.getElementById('pic2');
	 op = op + 2;
 	opacity(el2, op);
	if (op >= 100)
	{
		op = 100;
		clearInterval(slideInterval);
		setTimeout(slideNext, 4000);
	}

}

