var apartmenthideId;
var localehideId;

function drop(elementId) {
	var element = document.getElementById(elementId);
	element.style.display = "block";

	if (element.parentElement) {
		var pos = getAbsolutePos(element.parentElement);
		element.style.left = pos.x;
		element.style.width = element.parentElement.offsetWidth - 7;
	}

	if (element.parentNode) {
		element.style.width = (element.parentNode.offsetWidth - 7) + "px";
	}

}

function dropLocale() {
	cancelHideLocale();
	drop("dropdownLocale");

}

function dropApartments() {
	cancelHideApartments();
	drop("dropdownApartments");
}

function hideApartments() {
	hide('dropdownApartments');
}

function hideLocale() {
	hide('dropdownLocale');
}

function delayedApartmentHide() {
	clearTimeout(apartmenthideId);
	apartmenthideId = setTimeout("hideApartments();", 100);
}

function cancelHideApartments() {
	clearTimeout(apartmenthideId);
}

function delayedLocaleHide() {
	clearTimeout(localehideId);
	localehideId = setTimeout("hideLocale();", 100);
}

function cancelHideLocale() {
	clearTimeout(localehideId);
}

function getAbsoluteLeft(element) {
	var thisElement = element.parentElement;
	var offsetleft = 0;
	while (thisElement) {
		offsetleft += thisElement.offsetLeft
		thisElement = thisElement.parentElement;
	}

	return offsetleft;
}

function hide(elementId) {
	document.getElementById(elementId).style.display = "none";
}

function setcooks() {
	var useremail1 = document.getElementById("txtEmail").value;
	
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailAddr = useremail1
	
	if (emailAddr.match(emailRegEx) == null) 
	{		
		alert("Sorry, that email address doesn't seem valid.  Please check and click submit.\n");
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return false;
	}
	
	//document.cookie = useremail1;
	setCookie("email",useremail1);

}

function remove_txt() {
	if (getCookie("email") == "")
	{
		document.getElementById("txtEmail").value = "";
	}
	document.getElementById("txtEmail").style.color = "#000000";
}

function formosa() {

	if (getCookie("email") == "") {
		document.getElementById("txtEmail").style.color = "#777777";
		document.getElementById("txtEmail").value = "Enter Email Address";
	} else {
		document.getElementById("txtEmail").value = getCookie("email");
	}
}

function setCookie(c_name, value) //, expiredays)
{
  var expiredays = 1;
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + expiredays);
  var cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
  document.cookie = cookie;
}

function getCookie(c_name)
{
	if (document.cookie.length > 0)
	{
		var c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{
			c_start = c_start + c_name.length + 1;
			var c_end = document.cookie.indexOf(";",c_start);
			
			if (c_end == -1)
				c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}



