<br />
<b>Warning</b>:  Unknown: open_basedir restriction in effect. File(0) is not within the allowed path(s): (/home/halalaho:/usr/lib/php:/usr/local/lib/php:/tmp) in <b>Unknown</b> on line <b>0</b><br />
// ie test
function ifIE() {
	return (navigator.userAgent.toLowerCase().indexOf("msie") != -1 ? true : false);
}

// return an animated gif
function ajax_loader() {
	return "<div style=\"width:100%; height:100px; background-image:url('" + DR + "/assets/images/ajax_loader.gif'); background-position:center center; background-repeat:no-repeat;\"></div>";
}

// number format
function number_format(a,b) {
	c = '.';
	d = ',';
 	a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 	e = a + '';
 	f = e.split('.');
 	if (!f[0]) { f[0] = '0'; }
 	if (!f[1]) { f[1] = ''; }
 	if (f[1].length < b) { 
		g = f[1];
  		for (i=f[1].length + 1; i <= b; i++) {
   			g += '0';
  		}
  		f[1] = g;
 	}
	if(d != '' && f[0].length > 3) {
  		h = f[0];
  		f[0] = '';
  		for(j = 3; j < h.length; j+=3) {
   			i = h.slice(h.length - j, h.length - j + 3);
   			f[0] = d + i +  f[0] + '';
  		}
  		j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  		f[0] = j + f[0];
 	}
 	c = (b <= 0) ? '' : c;
 	return f[0] + c + f[1];
}

// validate 
function validate(what,str) {
	if(what == "email") {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return filter.test(str);
	} else if(what == "phone") {
		var filter = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
		return filter.test(str);
	} else if(what == "num") {
		if((str / str) == 1 && str != 0) { return true; }
		else { return false; }
	} else if(what == "zip") {
		var filter = /\d{5}(-\d{4})?/;
		return filter.test(str);
	} else if(what == "date") {
		var filter = /^([1-9]|0[1-9]|1[012])\D([1-9]|0[1-9]|[12][0-9]|3[01])\D(19[0-9][0-9]|20[0-9][0-9])$/;
		return filter.test(str);
	} else if(what == "url") {
		var filter = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		return filter.test(str);
	} else if(what == "ext") {
		str = str.toLowerCase();
		if(str.lastIndexOf(".jpg") == -1 && str.lastIndexOf(".jpeg") == -1 && str.lastIndexOf(".gif") == -1 && str.lastIndexOf(".png") == -1) { return false; }
		else { return true; }
	}
}

// disable the form
function disable_submit(form,str) {
	
	if(!form.submit_button) { return; }
	if(form.submit_button.disabled == true) {
		form.submit_button.value = form.submit_button.valu;
		form.submit_button.disabled = false;
	} else {
		form.submit_button.valu = form.submit_button.value;
		form.submit_button.value = str;
		form.submit_button.disabled = true;
	} // end else
	
}

// if the user hit the enter key
function submit_enter(e) {
	var key;
	if(window.event) { key = window.event.keyCode; }
	else if(e) { key = e.which; }
	else { return false; }
	if(key == 13) { return true; }
	else { return false; }
}

// jump to next field
function jump_field(obj,form_nm,next_field) {
	var form = document.forms[form_nm];
	if(!form) { return; }
	if(obj.value.length == obj.size) {
		if(next_field !== '') {
			form[next_field].focus();
		} // end if
	} // end if
}

// initaties the slider gallery, must pass the div id
function initSlider(div) {
	
	// put into variables
	var container = $$("div#" + div + " div.container")[0];
	var slider = $$("div#" + div + " div.slider")[0];
	var knob = $$("div#" + div + " div.knob")[0];
	
	// get images
	var image = $$("div#" + div + " div.image");
	
	// first, lets check to see if there are enough images in container
	if(image.length <= 3) { 
		slider.setStyle("display", "none");
		return;
	}
	
	// now set the width with the number of images, then more for the margin (look at css)
	var width = (image.length * image[0].getStyle("width").toInt()) + (image.length * 10) + 10;
	container.setStyle("width", width);
	
	// get distance
	var distance = container.getCoordinates().width - slider.getCoordinates().width;
	
	// begin sliding
	new Slider(slider, knob, {
		steps:distance,
		onChange:function(pos) {
			container.setStyle("margin-left",-pos);
		}
	});
	
}

// set the cookie if not set
function set_recently_viewed(hh_id) {
	
	for(var i = 0; i < 20; i++) {
		if(Cookie.read("Halala_Homes_ID_" + i)) {
			
			// stop the loop, they already looked at property
			if(Cookie.read("Halala_Homes_ID_" + i) == hh_id) {
				break;
			} // end if
			
			// erase old ones if this is the twentyith
			if(i == 19) {
				
				for(var j = 0; j < 19; j++) {
					Cookie.dispose("Halala_Homes_ID_" + j); // lets remove first to be safe
					Cookie.write("Halala_Homes_ID_" + j, Cookie.read("Halala_Homes_ID_" + (j+1)), { path:"/", duration:30 }); // then lets set it
				} // end for j loop
				
				// set it
				Cookie.write("Halala_Homes_ID_" + i, hh_id, { path:"/", duration:30 });
				break;
				
			} // end if 
			
		} else {
			
			Cookie.write("Halala_Homes_ID_" + i, hh_id, { path:"/", duration:30 });
			break;
			
		} // end if
	} // end for i loop
	
}

// place the recently viewed homes in place
function place_recently_viewed() {
	
	var container = $$("div#recently_viewed_gallery div.container")[0]; // container to place the viewed properties
	var hh_ids = ''; // holds the hh_ids
	var hh_id_count = 0; // counter
	var flag = false; // checks to see if there are any properties
	
	// begin loop
	for(var i = 19; i >= 0; i--) {
		if(Cookie.read("Halala_Homes_ID_" + i)) {

			flag = true;
			hh_ids += "&hh_id_" + hh_id_count + "=" + Cookie.read("Halala_Homes_ID_" + i);
			hh_id_count++;
			
		}
	} // end for i loop
	
	// ajax we had results
	if(flag) {
		
		new Request({
			url: DR + "/include/recently_viewed.php",
			onSuccess:function(html,xml) {
				container.set('html', html);
				initSlider("recently_viewed_gallery");
			}
		}).send("c=" + $time() + "&hh_id_count=" + hh_id_count + hh_ids);
		
	} else {
		container.set('html', "Sorry, you have not looked at Properties or Communities");
		initSlider("recently_viewed_gallery");
	}
	
}


// search lease and for sale 
function search_type_commercial(obj) {
	
	var selects = obj.parentNode.parentNode.parentNode.getElementsByTagName("SELECT");
	selects[0].disabled = (obj.checked ? false : true);
	selects[1].disabled = (obj.checked ? false : true);
	
}

// search land 
function search_type_land(obj) {
	
	var form = document.forms["popup_search_property"];
	if(!form) { form = document.forms["home_search_property"]; }
	var table = form.getElementsByTagName("TABLE")[2];
	var selects = table.getElementsByTagName("SELECT");
	
	// disable the sqft select boxes
	selects[2].disabled = selects[3].disabled = (obj.checked ? false : true);
	
}

function getCities(state,form_nm,what) {
	
	var form = document.forms[form_nm];
	
	// remove all from before
	while(form.city.options.length > 0) {
		form.city.remove(0);
	}
	
	if(state === '') {
		form.city.options[0] = new Option("Select a City", '');
		form.city.options[1] = new Option("No State Selected", '');
		return;
	} else {
		form.city.options[0] = new Option("Searching...", '');
	}
	
	new Request({
		url: DR + "/include/search_forms_cities.php",
		onSuccess:function(html,xml) {
			form.city.options[0] = new Option("Select a City", '');
			var cities = html.split("::");
			for(var i = 0; i < cities.length; i++) {
				form.city.options[(i + 1)] = new Option(cities[i], cities[i]);
			} // end for i loop
		}
	}).send("c=" + $time() + "&state=" + state + "&what=" + what);
	
}


// popup search type
function search_type(obj) {
	
	var form = document.forms["popup_search_property"];
	if(!form) { form = document.forms["home_search_property"]; }
	var inputs = form.getElementsByTagName("INPUT");
	var checkbox = new Array();
	
	// get the checkboxes in array
	for(var i = 0; i < inputs.length; i++) {
		if(inputs[i].type == "checkbox") {
			checkbox.push(inputs[i]);
		} // end if
	} // end for i loop
	
	// hide the commerical table
	form.getElementsByTagName("TABLE")[1].style.display = "none";
	// hide the land table
	form.getElementsByTagName("TABLE")[2].style.display = "none";
	
	// hide/show the rental price row
	var rows = form.getElementsByTagName("TABLE")[3].getElementsByTagName("TR");
	rows[3].style.display = "none";
	var tds = rows[2].getElementsByTagName("TD");
	tds[0].innerHTML = "Price:";
	
	// take off the disable
	var selects = rows[2].getElementsByTagName("SELECT");
	selects[0].disabled = false;
	selects[1].disabled = false;
	
	// set the price
	form.min_price.options.length = form.max_price.options.length = 0;
	form.min_price.options[0] = new Option("No Minimum", "0");
	form.max_price.options[0] = new Option("No Maximum", "99999999");

	//
	if(obj.checked == false) { return; } 
		
	if(obj.value == "all") {
		
		for(var i = 1; i < checkbox.length; i++) {
			checkbox[i].checked = false;
		} // end for i loop
		
	} else if(obj.value == "new" || obj.value == "pre-owned") {
		
		checkbox[0].checked = false;
		for(var i = 3; i < checkbox.length; i++) {
			checkbox[i].checked = false;
		} // end for i loop
		
	} else if(obj.value == "rental") {
		
		for(var i = 0; i < checkbox.length; i++) {
			checkbox[i].checked = (i == 3 ? true : false);
		} // end for i loop
		
	} else if(obj.value == "land") {
		
		for(var i = 0; i < checkbox.length; i++) {
			checkbox[i].checked = (i == 4 ? true : false);
		} // end for i loop
		
		// display the land table
		form.getElementsByTagName("TABLE")[2].style.display = "block";
		
	} else if(obj.value == "commercial") {
		
		for(var i = 0; i < checkbox.length; i++) {
			checkbox[i].checked = (i == 5 ? true : false);
		} // end for i loop
		
		// show rental
		var rows = form.getElementsByTagName("TABLE")[3].getElementsByTagName("TR");
		rows[3].style.display = '';
		var tds = rows[2].getElementsByTagName("TD");
		tds[0].innerHTML = "<label><input type=\"checkbox\" name=\"commercial_type[]\" value=\"sale\" onclick=\"search_type_commercial(this);\" /> Sale:</label>";
		
		var selects = rows[2].getElementsByTagName("SELECT");
		selects[0].disabled = true;
		selects[1].disabled = true;
		
		selects = rows[3].getElementsByTagName("SELECT");
		selects[0].disabled = true;
		selects[1].disabled = true;
		
		// display the commerical table
		form.getElementsByTagName("TABLE")[1].style.display = "block";
		
	} // end else if
	
	
	// set the min and max price
	if(obj.value == "all" || obj.value == "new" || obj.value == "pre-owned" || obj.value == "commercial") {
		
		// set price
		var price = 50000;
		for(var i = 1; i < 20; i++) {
			var p = number_format(price,0); // returns 50,000 ; 100,000; etc
			form.min_price.options[i] = new Option("$" + p, p.replace(/\,/g,'')); // set the new price
			form.max_price.options[i] = new Option("$" + p, p.replace(/\,/g,'')); // set the new price
			price += 50000; // increment by 50,000
		} // end for i loop
		form.min_price.options[20] = new Option("$1,000,000 +", "99999999");
		form.max_price.options[20] = new Option("$1,000,000 +", "99999999");
		
		// set the commerical rental
		if(obj.value == "commercial") {
			
			// set price
			var price = 200;
			for(var i = 1; i < 20; i++) {
				var p = number_format(price,0); // returns 50,000 ; 100,000; etc
				form.min_lease.options[i] = new Option("$" + p, p.replace(/\,/g,'')); // set the new price
				form.max_lease.options[i] = new Option("$" + p, p.replace(/\,/g,'')); // set the new price
				price += 200;
			} // end for i loop
			form.min_lease.options[20] = new Option("$4,000 +", "99999999");
			form.max_lease.options[20] = new Option("$4,000 +", "99999999");
			
		} // end if
		
	} else if(obj.value == "rental") {
		
		// set price
		var price = 100;
		for(var i = 1; i < 20; i++) {
			var p = number_format(price,0); // returns 50,000 ; 100,000; etc
			form.min_price.options[i] = new Option("$" + p, p.replace(/\,/g,'')); // set the new price
			form.max_price.options[i] = new Option("$" + p, p.replace(/\,/g,'')); // set the new price
			price += 100;
		} // end for i loop
		form.min_price.options[20] = new Option("$2,000 +", "99999999");
		form.max_price.options[20] = new Option("$2,000 +", "99999999");
		
	} else if(obj.value == "land") {
		
		// set price
		var price = 25000;
		for(var i = 1; i < 20; i++) {
			var p = number_format(price,0);
			form.min_price.options[i] = new Option("$" + p, p.replace(/\,/g,''));
			form.max_price.options[i] = new Option("$" + p, p.replace(/\,/g,''));
			price += 25000;
		} // end for i loop
		form.min_price.options[20] = new Option("$500,000 +", "99999999");
		form.max_price.options[20] = new Option("$500,000 +", "99999999");
		
		// set acreage
		var acre = .5;
		for(var i = 1; i < 20; i++) {
			var a = (i % 2 ? acre : acre + ".0");
			form.min_acreage.options[i] = new Option(a, a);
			form.max_acreage.options[i] = new Option(a, a);
			acre += .5;
		} // end for i loop
		form.min_acreage.options[20] = new Option("10 + ", "99999999");
		form.max_acreage.options[20] = new Option("10 + ", "99999999");
		
		// set sqft
		var sqft = 1000;
		for(var i = 1; i < 20; i++) {
			var s = number_format(sqft,0);
			form.min_sqft.options[i] = new Option(s, s.replace(/\,/g,''));
			form.max_sqft.options[i] = new Option(s, s.replace(/\,/g,''));
			sqft += 1000;
		} // end for i loop
		form.min_sqft.options[20] = new Option("20,000 +", "99999999");
		form.max_sqft.options[20] = new Option("20,000 +", "99999999");

	} else if(obj.value == "commercial") {
		
		
	}
	
}

// before we submit, lets check if everything is ok
function search_property_check() {
	
	var form = document.forms["popup_search_property"];
	if(!form) { form = document.forms["home_search_property"]; }
	var location = form.search_location.value;
	var inputs = form.getElementsByTagName("INPUT");
	var radio = new Array();
	var checkbox = new Array();
	
	// get the checkboxes in array
	for(var i = 0; i < inputs.length; i++) {
		if(inputs[i].type == "checkbox") {
			checkbox.push(inputs[i]);
		} else if(inputs[i].type == "radio") {
			radio.push(inputs[i]);
		}
	} // end for i loop
	
	
	// did they enter a hh_id? If so, relocate them
	var filter = /^[a-zA-Z]{2}\-?[0-9]{5,6}/;
	if(form.hh_id.value != '') {
		if(filter.test(form.hh_id.value)) {
			window.location.href = "http://" + DOMAIN + DR + "/" + form.hh_id.value;
			return;
		} else {
			alert("Invalid Halala ID");
			return;
		}
	}
	
	
	// is any of them checked?
	var flag = false;
	var url = '';
	for(var i = 0; i < checkbox.length; i++) {
		if(checkbox[i].checked == true) {
			flag = true;
			url += checkbox[i].value + (i < 3 ? "_homes" : '') + "/";
		}
	}
	if(!flag) { 
		alert("Please select a Property Type");
		return; 
	}
	
	var zip = /^[0-9]{1,}$/;
	var city_state = /^[a-zA-Z\.\s]{1,}\,\s[a-zA-Z]{2}$/;
	
	if(zip.test(location)) {
		
		// its a zip entry
		if(!validate("zip",location)) {
			alert("Invalid Zip entered");
			return;
		} else {
			form.action = "http://" + DOMAIN + DR + "/real_estate/" + url + location;
			form.submit();
			return;
		}
		
	} else if(city_state.test(location)) {
		
		var city = location.substr(0,location.indexOf(","));
		var state = location.substr(location.indexOf(",") + 2);
		
		// city and state entry
		form.action = "http://" + DOMAIN + DR + "/real_estate/" + url + state + "/" + city.replace(/ /g,"-");
		form.submit();
		return;
		
	}
	
	alert("Invalid City, State - or - Zip entry");
	return;
		
}

function search_builder_realtor_check() {
	
	var form = document.forms["popup_search_builder_realtor"];
	if(!form) { form = document.forms["home_search_property"]; }
	var checkbox = form.getElementsByTagName("INPUT");
	var url = (checkbox[0].checked ? "builder_and_realtor" : '') + (checkbox[1].checked ? "builder" : '') + (checkbox[2].checked ? "realtor" : '');
	var state = form.state.options[form.state.selectedIndex].value;
	var city = form.city.options[form.city.selectedIndex].value;
	var zip = form.zip.value;
	
	if(state !== '' && city !== '') {
		form.action = "http://" + DOMAIN + DR + "/" + url + "/" + state + "/" + city;
		form.submit();
		return;
	}
	
	if(zip !== '') {
		if(!validate("zip",zip)) {
			alert("Invalid Zip entered");
			return;
		} else {
			form.action = "http://" + DOMAIN + DR + "/" + url + "/" + zip;
			form.submit();
			return;
		}
	}
	
	if(form.search_name.value.trim() != '') {
		form.action = "http://" + DOMAIN + DR + "/" + url + "/" + form.search_name.value.trim();
		form.submit();
		return;
	}
	
	alert("You must select a State and City, or Zip, or enter a Name to search by");
	
}

function search_community_check() {
	
	var form = document.forms["popup_search_community"];
	if(!form) { form = document.forms["home_search_property"]; }
	var state = form.state.options[form.state.selectedIndex].value;
	var city = form.city.options[form.city.selectedIndex].value;
	var zip = form.zip.value;
	var builder_name = form.search_builder_name.value.trim();
	var community_name = form.search_community_name.value.trim();
	
	if(state !== '' && city !== '') {
		form.action = "http://" + DOMAIN + DR + "/real_estate/community/" + state + "/" + city;
		form.submit();
		return;
	}
	
	if(zip !== '') {
		if(!validate("zip",zip)) {
			alert("Invalid Zip entered");
			return;
		} else {
			form.action = "http://" + DOMAIN + DR + "/real_estate/community/" + zip;
			form.submit();
			return;
		}
	}
	
	if(builder_name != '' || community_name != '') {
		form.action = "http://" + DOMAIN + DR + "/real_estate/community/" + (builder_name != '' ? builder_name + "/" : '') + (community_name != '' ? community_name : '');
		form.submit();
		return;
	}
	
	alert("You must select a State and City, or Zip, or enter a Builder or Community Name");
	
}

// show find a property or find a builder or realtor divs if clicked in content box
function show_search(what) {
	
	// hide all
	$("property_div").setStyle("display", "none");
	$("builder_realtor_div").setStyle("display", "none");
	$("community_div").setStyle("display", "none");
	
	// show selected
	$(what + "_div").setStyle("display", "block");
	
	// if property search
	if(what == "property") {
		// have the checkbox 'all' be selected by default
		var input = document.forms["popup_search_property"].getElementsByTagName("INPUT")[0];
		input.checked = true;
		search_type(input);
	} // end if
	
}

// show recently viewed, dream list, or my account divs if clicked in content box
function show_user(what) {

	// hide all
	$("account_div").setStyle("display", "none");
	$("recently_div").setStyle("display", "none");
	$("dream_div").setStyle("display", "none");
	
	// show selected
	$(what + "_div").setStyle("display", "block");
	
	// init the effect
	if(what == "dream") { 
		initSlider("dream_list_gallery"); 
	} else if(what == "recently") { 
		place_recently_viewed();
	} else {
		
		// form
		var form = document.forms["login_form"];
		
		// set timeout for ie 6 annoying bug, it can't focus on input unless it is visible
		if($("overlay_content").getStyle("opacity") == 1) {
			if(form) {
				// we loop to force IE to focus
				for(var i = 0; i < 50; i++) { 
					form.email.focus();
				} // end for i loop
			} // end if
		} else {
			setTimeout(function() {
				if(form) {
					// we loop to force IE to focus
					for(var i = 0; i < 50; i++) { 
						form.email.focus();
					} // end for i loop
				}
			}, 750);
		} // end else
		
	} // end else
}

//display overlay_content with search_forms.php 
function popup_search(what) {

	// open 
	open_popup();
	
	// set height and loading gif
	$$("div#overlay_content div.content")[0].set('html', ajax_loader());
	
	new Request({
		url: DR + "/include/search_forms.php",
		onSuccess:function(html,xml) {
			$$("div#overlay_content div.content")[0].set('html', html);
			show_search(what);
		}
	}).send("c=" + $time());
	
}

// display overlay_content with user_forms.php
function popup_user(what,do_this,id,category,id1) {

	// open 
	open_popup();
	
	// show loading gif
	$$("div#overlay_content div.content")[0].set('html', ajax_loader());
	
	// begin AJAX
	new Request({
		url: DR + "/include/user_forms.php",
		onSuccess:function(html,xml) {
			$$("div#overlay_content div.content")[0].set('html', html);
			show_user(what);
		}
	}).send("c=" + $time() + (do_this !== undefined ? "&do_this=" + do_this : '') + (id !== undefined ? "&id=" + id : '') + (category !== undefined ? "&category=" + category : '') + (id1 !== undefined ? "&id1=" + id1 : ''));

}

// close the popup
function close_popup() {
	$$("div#overlay_content div.content")[0].set('html', '');
	olb.start("opacity", .7, 0);
	olc.start("opacity", 1, 0);
}

function open_popup() {
	if(olc.element.getStyle("opacity") == 0) {
		olb.start("opacity", 0, .7);
		olc.start("opacity", 0, 1);
	}
}


// remove an item from the dream list
function remove_dream(dream_list_id) {
	
	new Request({
		url: DR + "/include/remove_dream.php",
		onSuccess:function(html,xml) {
			if(html == "ok") {
				popup_user("dream");
			}
		}
	}).send("c=" + $time() + "&dream_list_id=" + dream_list_id);
	
}

function dream_add(id,category) {
	
	new Request({
		url: DR + "/include/dream_add.php",
		onSuccess:function(html,xml) {
			if(html == "ok") {
				alert("Added to Dream List");
			} else {
				alert("Already in your Dream List");
			}
		}
	}).send("c=" + $time() + "&id=" + id + "&category=" + category);
	
}

// quick contact 
function quick_contact(user_id,category,id) {
	
	// open 
	open_popup();
	
	// ajax to get the contact form
	new Request({
		url: DR + "/include/quick_contact.php",
		onSuccess:function(html,xml) {
			$$("div#overlay_content div.content")[0].set('html', html);
		}
	}).send("c=" + $time() + "&to_user_id=" + user_id + "&category=" + category + "&id=" + id);
	
}

function quick_contact_share(obj) {
	
	var form = document.forms["quick_contact_form"];
	
	var input = form.getElementsByTagName("INPUT");
	for(var i = 4; i < (input.length - 1); i++) {
		if(i == input.length - 3) continue;
		input[i].disabled = (obj.checked ? false : true);
	} // end for i loop
	
}

function quick_contact_send() {
	
	var form = document.forms["quick_contact_form"];
	var to_user_id = form.to_user_id.value;
	var category = form.category.value;
	var id = form.the_id.value;
	var comment = form.comment.value.trim();
	var phone = "(" + form.phone_area.value.trim() + ") " + form.phone_3.value.trim() + "-" + form.phone_4.value.trim();
	var email = form.email.value.trim();
	disable_submit(form, "Sending...");
	
	if(comment === '') {
		disable_submit(form,'');
		return;
	}
	
	if((form.phone_area.value.trim() == '' || form.phone_3.value.trim() == '' || form.phone_4.value.trim() == '') && email == '') {
		alert("Either Phone or Email is required");
		disable_submit(form,'');
		return;
	}
	
	if(form.phone_area.value.trim() != '' || form.phone_3.value.trim() != '' || form.phone_4.value.trim() != '') {
		if(!validate("phone", phone)) {
			alert("Invalid Phone entered");
			disable_submit(form,'');
			return;
		}
	} else {
		phone = '';
	}
	
	if(email != '') {
		if(!validate("email",email)) {
			alert("Invalid Email entered");
			disable_submit(form,'');
			return;
		}
	}

	// send the message
	new Request({
		url: DR + "/include/quick_contact_send.php",
		onSuccess:function(html,xml) {
			alert("Message has been sent");
			close_popup();
		}
	}).send("c=" + $time() + "&comment=" + comment + "&phone=" + phone + "&email=" + email + "&to_user_id=" + to_user_id + "&category=" + category + "&id=" + id);	
	
}

// login for user
function check_login() {
	
	var form = document.forms["login_form"];
	var do_this = form.do_this.value;
	var id = form.to_id.value;
	var category = form.category.value;
	var email = form.email.value;
	var password = form.password.value;
	disable_submit(form,"Checking...");
	
	if(email === '' || password === '') {
		disable_submit(form,'');
		return;
	} // end if
	
	// ajax to the login script
	new Request({
		url: DR + "/assets/login.php",
		onSuccess:function(html,xml) {
			
			if(html.indexOf("ok") != -1) {
				
				if(do_this !== '') {
					
					if(do_this === "add_dream") {
						dream_add(id,category);
						popup_user("account");
					} else if(do_this === "quick_contact") {
						quick_contact(id);
					} else if(do_this === "listing_signup") {
						window.location.href = "http://" + DOMAIN + DR + "/members/listings/individual.php?step=1";
					} else if(do_this === "signup_table") {
						window.location.href = "http://" + DOMAIN + DR + "/members/sign_up.php";
					}
					
				} else {
					popup_user("account"); // show user options 
				}
				
				// change the logout to login
				var a = $$("div#session_control a")[0];
				a.set('href', "http://" + DOMAIN + DR + "/?logout=true");
				a.set('html', "Logout");
				
				// set the name if any
				var name = html.split("::");
				var span = $$("div#session_control span")[0];
				span.set('html', (name[1] !== '' ? "Welcome " + name[1] : "<a href=\"http://" + DOMAIN + DR + "/members/personal_profile.php\">Edit Personal Info</a>"));
				
			} else if(html == "deactivated") {
				alert("Your account has been deactivated");
				disable_submit(form,'');
				return;
			} else if(html == "nope") {
				alert("Email and/or Password do not match");
				disable_submit(form,'');
				return;
			} // end else 
			
		} // end onSuccess
	}).send("c=" + $time() + "&email=" + email + "&password=" + password);
		
} // end function

// create 
function check_create() {
	
	var form = document.forms["create_form"];
	var do_this = form.do_this.value;
	var id = form.to_id.value;
	var email = form.email.value;
	var password = form.password.value;
	var confirm = form.c_password.value;
	disable_submit(form,"Creating...");
	
	if(email === '' || password === '' || confirm === '') {
		disable_submit(form,'');
		return;
	}
	
	if(!validate("email",email)) {
		alert("Invalid Email was entered");
		disable_submit(form,'');
		return;
	}
	
	if(password.length < 6) {
		alert("Passwords must be at least 6 characters in length");
		disable_submit(form,'');
		return;
	}
	
	if(password !== confirm) {
		alert("Passwords do not match");
		disable_submit(form,'');
		return;
	}
	
	// now create
	new Request({
		url: DR + "/assets/create.php",
		onSuccess:function(html,xml) {
			
			if(html.indexOf("ok") != -1) {
			
				if(do_this !== '') {
					
					if(do_this === "add_dream") {
						dream_add(id,category);
					} else if(do_this === "quick_contact") {
						quick_contact(id);
					} else if(do_this === "listing_signup") {
						window.location.href = "http://" + DOMAIN + DR + "/members/listings/individual.php?step=1";
					} else if(do_this === "signup_table") {
						window.location.href = "http://" + DOMAIN + DR + "/members/sign_up.php";
					}
					
				} else {
					popup_user("account"); // show user options 	
				} 
				
				// change the logout to login
				var a = $$("div#session_control a")[0];
				a.set('href', DR + "/?logout=true");
				a.set('html', "Logout");
				
				// set the name
				var span = $$("div#session_control span")[0];
				span.set('html', "<a href=\"" + DR + "/members/personal_profile.php\">Edit your Personal Profile</a>");
				
			} else if(html == "duplicate") {
				alert("The Email already exists");
				disable_submit(form,'');
				return;
			} // end else if
			
		}
	}).send("c=" + $time() + "&email=" + email + "&password=" + password);
	
}


// window onscroll
window.onscroll = function() {
	if(!document.all) { 
		var top = 0;
		if(window.pageYOffset > 0) {
			top = window.pageYOffset;
		}
	} else {
		var top = 0;
		if(document.body && (document.body.scrollTop)) {
			top = document.body.scrollTop;
		} else {
			top = document.documentElement.scrollTop;
		} // end else
	}

	olb.element.setStyle("margin-top",top);	
	olc.element.setStyle("margin-top",top);
}

window.onresize = function() {
	olb.element.setStyles({"height":window.getHeight(), "width":window.getWidth()});
}


var olb = null;
var olc = null;
window.addEvent("domready", function() {
	
	olb = new Fx.Tween("overlay_black", {
		duration:500,
		onStart:function() {
			if(this.element.getStyle("display") == "none") {
				
				var selects = document.getElementsByTagName("SELECT");
				for(var i = 0; i < selects.length; i++) {
					selects[i].style.visibility = "hidden";
				}
				
				this.element.setStyles({"display":"block","height":window.getHeight(), "width":window.getWidth()}); // set height and width
			}
		},
		onComplete:function() {
			if(this.element.getStyle("opacity") == 0) {
				
				var selects = document.getElementsByTagName("SELECT");
				for(var i = 0; i < selects.length; i++) {
					selects[i].style.visibility = "visible";
				}
				
				this.element.setStyle("display", "none");
			}
		} // end onComplete
	}).set("opacity", 0);
	
	olc = new Fx.Tween("overlay_content", {
		duration:500,
		onStart:function() {
			if(this.element.getStyle("display") == "none") {
				this.element.setStyle("display", "block");
			}
		},
		onComplete:function() {
			if(this.element.getStyle("opacity") == 0) {
				this.element.setStyle("display", "none");
			}
		} // end onComplete
	}).set("opacity", 0);
	
});
