function verReg(url,user_id){
	if (user_id)
		r_user_id = user_id;
	else
		r_user_id = null;
		
	if (url)
		r_url = url;
	else
		r_url = null;
	
	//var x=readCookie('regd');
	if (readCookie('regd') && r_url){
		document.location = r_url
	}
	else {
		initializeBoxes();
		myAppBox.className="e_pop";
		tempvar = new Array()
		tempvar[tempvar.length] = '<table cellspacing="0" cellpadding="0"><tr><td style="width:300px;padding-right:8px"><span id="reg_heading"></span>';
		tempvar[tempvar.length] = '<div style="font-style:italic;font-size:10px;padding-top:5px">fields marked with <span class="ast">*</span> are required.</div>';
		tempvar[tempvar.length] = '<table cellspacing="0"><tr><td class="ast">*</td><td>Name:</td><td><input id="r_name" size="30" maxlength="40" onfocus="rFocus(this)" onkeydown="return checkTab(event,\'top\')"></td></tr>';
		tempvar[tempvar.length] = '<tr><td class="ast">*</td><td>Your Email:</td><td><input id="r_email" size="30" maxlength="50" onfocus="rFocus(this)" onkeydown="return specChars(event)"></td></tr>';
		tempvar[tempvar.length] = '<tr><td class="ast">*</td><td nowrap>Confirm Email:</td><td><input id="r_email2" size="30" maxlength="50" onfocus="rFocus(this)" onkeydown="return specChars(event)"></td></tr>';
		tempvar[tempvar.length] = '<tr><td></td><td>City:</td><td><input id="r_city" size="30" maxlength="40" onfocus="rFocus(this)" onkeydown="return specChars(event)"></td></tr>';
		tempvar[tempvar.length] = '<tr><td></td><td>State/Prov:</td><td><select id="r_state" onfocus="rFocus(this)">';
		var states = new Array("--","AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","AB","BC","MB","NB","NF","NS","ON","PE","PQ","SK","NT","NU","YT");
		var moving = new Array("Time Frame","Immediately","3 Months","6 Months","9 Months","12+Months","Don\'t Know");
		for (i=0;i<states.length;i++){
			tempvar[tempvar.length]='<option value="'+states[i]+'">'+states[i]+' </option>'
		}
		tempvar[tempvar.length] = '</select></td></tr>';
		tempvar[tempvar.length] = '<tr><td></td><td>Phone:</td><td><input class="e_pop_text" id="r_phone" size="30" maxlength="40" onfocus="rFocus(this)" onkeydown="return specChars(event)"></td></tr>';
		tempvar[tempvar.length] = '<tr><td></td><td style="font-size:10px" nowrap>When are<br>you moving?:</td><td><select class="e_pop_text" id="moving" onfocus="rFocus(this)">'
		for (i=0;i<moving.length;i++){
			tempvar[tempvar.length]='<option value="'+moving[i]+'">'+moving[i]+' </option>'
		}
		
		tempvar[tempvar.length] = '</select>';
		tempvar[tempvar.length] = '</table>';
		tempvar[tempvar.length] = '<table><tr id="optionrow"><td><input type="checkbox" id="autolist" checked onclick="togglePrice()" onfocus="rFocus(this)"></td><td nowrap>Get Latest Listings?<br><span style="font-size:10px">Yes! I want to recieve new properties by email.</td></tr>';
		priceprompt = '<input class="e_pop_text" type="text" id="x" size="40" value="Please tell us your price range?" onfocus="xform();">';
		tempvar[tempvar.length] = '<tr id="pricerow"><td></td><td id="pricerange">'+priceprompt+'</td></tr></table>'

		tempvar[tempvar.length] = '<input id="button" type="button" onclick="regMe()" value="" onfocus="rFocus(this)">';
		tempvar[tempvar.length] = '<input type="button" onclick="resetReg()" value="Cancel" onfocus="rFocus(this)" onkeydown="return checkTab(event,\'bot\')">';
		tempvar[tempvar.length] = '<br><a href="javascript:help(1);" style="float:left;font-size:9px">Problems Registering?</a><a href="javascript:help(2);" style="font-size:9px;float:right">Your information is safe with us.</a></td>';
		tempvar[tempvar.length] = '<td id="reg_help" valign="top" style="display:none;width:250px;border-left:2px solid blue;padding-left:8px"><div style="font-weight:bold;font-size:14px;padding-bottom:12px">Be Our Guest Registration Help</div>';
		tempvar[tempvar.length] = 'To submit the Be Our Guest form, you must complete all required fields.<br><br>If Be Our Guest registration is continuing to appear even though you\'ve already registered, check your web browser settings and ensure that "cookies" are enabled. Cookies allow your registration information to be saved.<p>For more information, contact your local computer support technician and/or use your web browser\'s help documentation.<p><p style="text-align:center"><a href="javascript:help(0)">close help</a></td>';

		tempvar[tempvar.length] = '<td id="reg_privacy" valign="top" style="display:none;width:250px;border-left:2px solid blue;padding-left:8px"><div style="font-weight:bold;font-size:14px;padding-bottom:12px">Our strict privacy policy:</div>';
		tempvar[tempvar.length] = 'We will only use your email address to send you new listings on the market within the price range you specify.<p>We\'ll never sell or distribute your email address to anyone.<p>No exceptions.<p><p style="text-align:center"><a href="javascript:help(0)">close privacy statement</a></td>';

		tempvar[tempvar.length] = '</tr></table>';
		
		myAppBox.innerHTML = tempvar.join("");
		if (r_url){
			document.getElementById('button').value='Be Our Guest';
			document.getElementById('optionrow').style.display='';
			document.getElementById('reg_heading').innerHTML='<div style="font-weight:bold;font-size:14px">Be Our Guest</div><div>Registering as our guest allows you access to more information for this and all other properties.</div>';
		}
		else{
			document.getElementById('button').value='Sign Me Up!';
			document.getElementById('optionrow').style.display='none';
			document.getElementById('reg_heading').innerHTML='<div style="font-weight:bold;font-size:14px">Sign up to Receive Latest Listings</div><div>Get an instant email when new properties are added.  You\'ll be the first to know!</div>';
		}
		/*centerbox(myAppBox)
		myAppBox.style.visibility = 'visible';
		pushOverlay(2);
		screen_top = document.body.scrollTop;
		document.body.onscroll=window.onscroll=centerMe;
		activeForm=myAppBox;
		myAppBox.onkeypress=enterKey;*/
		pushForm(myAppBox);
		setTimeout('document.getElementById("r_name").focus();',10)
	}		
}
function rFocus(elm){
	elmWithFocus = elm;
}
function help(o){
	elmWithFocus.focus()
	if (o && o == 1){
		if (document.getElementById('reg_help').style.display == '')
			return;
		document.getElementById('reg_help').style.display = '';
		document.getElementById('reg_privacy').style.display = 'none';
	}
	else if (o && o == 2){
		if (document.getElementById('reg_privacy').style.display == '')
			return;
		document.getElementById('reg_privacy').style.display = '';
		document.getElementById('reg_help').style.display = 'none';
	}
	else{
		document.getElementById('reg_help').style.display = 'none';
		document.getElementById('reg_privacy').style.display = 'none';
	}
	centerbox(myAppBox)
	centerbox(myAppBox)
	//setTimeout('centerbox(myAppBox)',3)
}
function enterKey(e){
	if (window.event)
		 kc = event.keyCode
	else
		kc = e.keyCode
	if (kc == 13)
		regMe()
}

function togglePrice(){
	if (document.getElementById("autolist").checked)
		document.getElementById("pricerow").style.display='';
	else {
		document.getElementById("pricerow").style.display='none';
		document.getElementById("pricerange").innerHTML = priceprompt;
	}
}
function xform(){
	document.getElementById("pricerange").innerHTML = '<input class="e_pop_text" type="text" id="minprice" size="12" onkeydown="return onlynum(event)" onfocus="rFocus(this)"> to <input class="e_pop_text" type="text" id="maxprice" size="12" onkeydown="return onlynum(event)" onfocus="rFocus(this)">';
	setTimeout('document.getElementById("minprice").focus();',10)
}
function onlynum(e){
	if (window.event)
		var keycode = event.keyCode
	else
		var keycode = e.which;
		
	//alert(event.keyCode);
	if (keycode >= 48 && keycode <= 57)
		return true;
	if (keycode >= 96 && keycode <= 105)
		return true;
	if (keycode == 37 || keycode == 39 || keycode == 8 || keycode == 46 || keycode == 9 || keycode == 13)
		return true;
	return false;
	
}
function resetReg(){
	help(0);
	//popOverlay();
	//myAppBox.style.visibility='hidden';
	//window.onscroll=document.body.onscroll=null;
	//myAppBox.onkeypress=null;
	popForm();
}

function regMe(){
	var eMsg = new Array("Please fix the following errors...");
	var name=document.getElementById("r_name").value=trim(document.getElementById("r_name").value);
	if (name == ""){
		eMsg[eMsg.length] = "* Name is required.";
	}
	
	var email=document.getElementById("r_email").value=trim(document.getElementById("r_email").value);
	if (email == "")
		eMsg[eMsg.length] = '* Email is required.'
	else if (!testEmail(email))
		eMsg[eMsg.length] = '* The Email address entered is not valid.'
	else if (trim(document.getElementById('r_email2').value)=="")
		eMsg[eMsg.length] = "* Please re-type your email in the 'Confirm Email' field.";
	else if (trim(document.getElementById('r_email').value)!=trim(document.getElementById('r_email2').value))
		eMsg[eMsg.length] = "* The 'Confirm' email does not match 'Your' email.";

	if (document.getElementById('minprice')){
		var minprice = document.getElementById('minprice')
		var maxprice = document.getElementById('maxprice')
		minprice.value = trim(minprice.value);
		maxprice.value = trim(maxprice.value);
		if (parseInt(maxprice.value) < parseInt(minprice.value)){
			eMsg[eMsg.length] = "* Maximum price should be greater than minimum price."
		}
	}
	if (eMsg.length > 1){
		alert(eMsg.join("\n\n"))
		return;
	}
	createCookie('regd','1',365);

	urlstring = '/wwwroot/remaint/ajax/reg.cfm?did='+did
	var fields = myAppBox.getElementsByTagName('input');
	
	for (var i=0;i<fields.length;i++)
		if (fields[i].type == 'text' || (fields[i].type == 'checkbox' && fields[i].checked))
			urlstring += '&'+fields[i].id+'='+fields[i].value;
	urlstring += '&r_state='+document.getElementById('r_state').value
	urlstring += '&moving='+document.getElementById('moving').value
	
	if (r_user_id)
		urlstring+='&user_id='+r_user_id;
		
	if(window.XMLHttpRequest) 
		var myxmlhttp = new XMLHttpRequest();
    else if(window.ActiveXObject) 
		var myxmlhttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
	myxmlhttp.open("POST", urlstring,true);
	/*myxmlhttp.onreadystatechange=function() {
		if (myxmlhttp.readyState==4) {
			//alert(myxmlhttp.responseText)
			//eval(myxmlhttp.responseText)
			
			document.write(myxmlhttp.responseText);
		}
	}*/
	myxmlhttp.send(null)
	if (r_url)
		document.location = r_url;
	else
		resetReg();
}


