function mailForm(classid,address,agentname,user_id,elm){
		
	this.form = document.createElement("div"); 
	this.form.style.visibility='visible';
	this.form.style.fontSize='12px';
	this.form.style.padding='9px';
	this.msgPrompt = 'Enter your message or inquiry here.';
	this.form.style.fontFamily='verdana';
	this.form.className="e_pop";
	var t = new Array();
	t[t.length] = '<div style="text-align:center;"><span style="font-size:14px;font-weight:bold;border-bottom:1px solid black;">Request More Information</span></div>';
	t[t.length] = '<div style="font-size:10px;padding-bottom:12px;text-align:center;font-style:italic">Items marked with <span style="color:red;font-weight:bold;">*</span> are Required</div>';
	t[t.length] = '<table cellspacing=0 style="font-family:Verdana,Arial;font-size:11px;vertical-align:top;">'
	t[t.length] = '<tr><td></td><td>To:</td><td id="agentname">'+agentname+'</td></tr>';
	t[t.length] = '<tr><td style="color:red;font-weight:bold;">*</td><td>Your Name:</td><td><input id="e_name" size="37" maxlength="50" onkeydown="return checkTab(this,event)"></td></tr>';
	t[t.length] = '<tr><td style="color:red;font-weight:bold;">*</td><td>Your Email:</td><td><input id="e_email" size="37" maxlength="50" onkeydown="return checkTab(this,event)" ></td></tr>';
	t[t.length] = '<tr><td style="color:red;font-weight:bold;">*</td><td>Confirm Email:</td><td><input id="e_email2" size="37" maxlength="50" onpaste="this.value=\'\';return false" onkeydown="return checkTab(this,event)"></td></tr>';
	t[t.length] = '<tr><td></td><td>Your Phone:</td><td><input id="e_phone" size="37" maxlength="30" onkeyup="toggleBT(this)" onkeydown="return checkTab(this,event)"></td></tr>';
	t[t.length] = '<tr id="btRow" style="display:none"><td></td><td style="font-size:9px;">Best Time to Call:</td><td><input id="e_besttime" size="37" maxlength="50" onkeydown="return checkTab(this,event)"></td></tr>';
	t[t.length] = '<tr><td></td><td colspan=2><input type="checkbox" id="haveAgent" value="true" onclick="toggleAgent(this);"><label for="haveAgent">I am currently working with a real estate agent.</label> </td></tr>'
	t[t.length] = '<tr id="agRow" style="display:none"><td></td><td>Agent Name:</td><td><input type="text" id="myAgent" size="37" maxlength="50"> </td></tr>'
	t[t.length] = '<tr><td></td><td>Subject:</td><td id="addr">'+address+'</td></tr>';
	t[t.length] = '<tr><td style="color:red;font-weight:bold;vertical-align:top">*</td><td colspan="2"><textarea rows="5" cols="40" id="e_msg" onkeydown="return checkTab(this,event)" onfocus="clearPrompt(this)" onblur="insertPrompt(this)" style="color:blue">'+this.msgPrompt+'</textarea></td></tr>';
	t[t.length] = '<tr><td></td><td colspan="2"><input id="sButton" type="button" onclick="sendEmail(this)" value="Send" onkeydown="return checkTab(this,event)"> ';
	if (!elm)
		t[t.length] = '<input id="cButton" type="button" onclick="resetEmail(this)" value="Cancel" onkeydown="return checkTab(this,event)">';
	t[t.length] = '</td></tr></table>';
	t[t.length] = '';
	this.form.innerHTML = t.join("");
	this.classid = classid;
	this.user_id = user_id;
	this.form.name = 'mailForm';
	if (elm)
		elm.appendChild(this.form);
	else {
		this.form.style.zIndex=5;
		this.form.style.backgroundColor='#ffffdd';
		this.form.style.border='1px solid black';
		document.body.appendChild(this.form);
		this.form.style.position='absolute';
	}
	
	//var children = this.form.childNodes
	//for (i in children)
		//alert(children[i])
	
	var inputs = this.form.getElementsByTagName('input')
	this.firstInput = inputs[0];
	this.lastInput = inputs[inputs.length-1];
	
	for (var i=0;i<inputs.length;i++){
		switch (inputs[i].id){
		case 'e_name':
			this.e_name = inputs[i];
			break;
		case 'e_email':
			this.e_email = inputs[i];
			break;
		case 'e_email2':
			this.e_email2 = inputs[i];
			break;
		case 'e_phone':
			this.e_phone = inputs[i];
			break;
		case 'e_besttime':
			this.e_besttime = inputs[i];
			break;
		case 'cButton':
			this.cButton = inputs[i];
			break;
		case 'sButton':
			this.sButton = inputs[i];
			break;
		case 'myAgent':
			this.myAgent = inputs[i];
			break;
		case 'haveAgent':
			this.haveAgent = inputs[i];
			break;
		}
	}
	this.e_msg = this.form.getElementsByTagName('textarea')[0];

	var tds = this.form.getElementsByTagName('td')
	for (var i = 0;i<tds.length;i++){
		if (tds[i].id == 'agentname'){
			this.agentname = tds[i];
		}
		if (tds[i].id == 'addr'){
			this.addr = tds[i];
		}
	}
		
	var trs = this.form.getElementsByTagName('tr')
	for (var i = 0;i<trs.length;i++){
		if (trs[i].id == 'btRow'){
			this.btRow = trs[i];
		}
		if (trs[i].id == 'agRow'){
			this.agRow = trs[i];
			break;
		}
	}
		
	this.e_name.value = readCookie('e_name') || '';
	this.e_email.value = readCookie('e_email') || '';
	this.e_email2.value = readCookie('e_email') || '';
	this.e_phone.value = readCookie('e_phone') || '';
	this.e_besttime.value = readCookie('e_besttime') || '';
	this.myAgent.value = readCookie('myAgent') || '';
	//alert(readCookie('haveAgent'))
	if (!readCookie('haveAgent') || readCookie('haveAgent')=='false')
		this.haveAgent.checked = false;
	else
		this.haveAgent.checked = true;

	return this
}
function clearPrompt(elm){
	elm.style.color = 'black';
	if (elm.value == currentForm.msgPrompt){
		elm.value = '';
	}
}
function insertPrompt(elm){
	if (trim(elm.value) == ''){
		elm.value = currentForm.msgPrompt;
		elm.style.color = 'blue';
	}
}
mailForm.prototype.setUser = function (user_id,agentname){
	this.user_id = user_id;
	this.agentname.innerHTML = agentname;
}
function toggleAgent(elm){
	if (!elm.checked){
		currentForm.agRow.style.display='none';
	}
	else {
    	if(window.ActiveXObject) 
			currentForm.agRow.style.display='block';
		else if(window.XMLHttpRequest) 
			currentForm.agRow.style.display='table-row';
	}
}

function mailto(classid,address,agentname,user_id){
	if (!window.myMailForm)
		myMailForm = new mailForm(classid,address,agentname,user_id);
	else {
		myMailForm.user_id = user_id
		myMailForm.setUser(user_id,agentname);
		myMailForm.form.style.visibility='visible';
		myMailForm.classid = classid;
		myMailForm.addr.innerHTML = address;
	}

	currentForm = myMailForm;
	centerbox(myMailForm.form)
	toggleBT(myMailForm.e_phone);
	toggleAgent(myMailForm.haveAgent);
	insertPrompt(myMailForm.e_msg)
	centerbox(myMailForm.form)
	
	screen_top = document.body.scrollTop;
	document.body.onscroll=window.onscroll=centerMe;
	setTimeout("myMailForm.form.getElementsByTagName('input')[0].focus();",10)
	if (!window.overlay){
		overlay = document.createElement('div');
		overlay.id = 'overlay';
		overlay.onclick='event.cancelBubble=true';
		overlay.style.position='absolute';
		overlay.style.top='0';
		overlay.style.left='0';
		overlay.style.display='none';
		overlay.style.opacity='.5';
		overlay.style.filter='Alpha(Opacity=50)';
		overlay.style.backgroundColor='black';
		document.body.appendChild(overlay); 
	}
	
	pushOverlay(2);

	return;
	
}
function checkTab(elm,event){
	if (event.keyCode != 9)
		return specChars(event)

	if (elm == currentForm.firstInput && event.shiftKey){
		currentForm.lastInput.focus()
		return false
	}
	if (elm == currentForm.lastInput && !event.shiftKey){
		currentForm.firstInput.focus()
		return false
	}
	return specChars(event)
}
function specChars(event){
	if (event.keyCode > 52 && event.keyCode < 56 & event.shiftKey)
		return false

}
function toggleBT(elm){
	if (elm.value == "")
		currentForm.btRow.style.display='none';
	else {
    	if(window.ActiveXObject) 
			currentForm.btRow.style.display='block';
		else if(window.XMLHttpRequest) 
			currentForm.btRow.style.display='table-row';
	}
		
}

function resetEmail(elm){
	currentForm.e_msg.value = '';
	if (window.inlineForm && currentForm==inlineForm){
		//
	}
	else{
		popOverlay();
		currentForm.form.style.visibility='hidden';
		window.onscroll=document.body.onscroll=null;
	}

	if(window.inlineForm)
		currentForm = inlineForm;
}
function sendEmail(){
	var eMsg = new Array("Please fix the following errors...");
	if (trim(currentForm.e_name.value)=="")
		eMsg[eMsg.length] = "* Your Name is Required.";
	if (trim(currentForm.e_email.value)=="")
		eMsg[eMsg.length] = "* Your Email Address is Required.";
	else if (!testEmail(trim(currentForm.e_email.value)))
		eMsg[eMsg.length] = "* The Email address entered is not valid.";
	else if (trim(currentForm.e_email2.value)=="")
		eMsg[eMsg.length] = "* Please re-type your email in the 'Confirm Email' field.";
	else if (trim(currentForm.e_email.value)!=trim(currentForm.e_email2.value))
		eMsg[eMsg.length] = "* The 'Confirm' email does not match 'Your' email.";
	if (trim(currentForm.e_msg.value)=="" || trim(currentForm.e_msg.value)==currentForm.msgPrompt)
		eMsg[eMsg.length] = "* Please type a message to send.";
	if (eMsg.length > 1){
		alert(eMsg.join("\n\n"))
		return;
	}

	urlstring = '/wwwroot/remaint/ajax/email.cfm?did='+did+'&user_id='+currentForm.user_id+'&classid='+currentForm.classid;
	urlstring += '&e_name='+currentForm.e_name.value
	urlstring += '&e_phone='+currentForm.e_phone.value
	urlstring += '&e_email='+currentForm.e_email.value
	urlstring += '&e_besttime='+currentForm.e_besttime.value
	urlstring += '&e_msg='+currentForm.e_msg.value
	urlstring += '&search='+escape(document.location.search);
	urlstring += '&pathname='+escape(document.location.pathname);
	urlstring += '&myAgent='+currentForm.myAgent.value;
	urlstring += '&haveAgent='+currentForm.haveAgent.checked;
	
	//myAppBox.innerHTML = urlstring;
	//return;
	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.send(null);
	createCookie('e_name',currentForm.e_name.value,365) 
	createCookie('e_email',currentForm.e_email.value,365) 
	createCookie('e_phone',currentForm.e_phone.value,365) 
	createCookie('e_besttime',currentForm.e_besttime.value,365) 
	createCookie('myAgent',currentForm.myAgent.value,365) 
	createCookie('haveAgent',currentForm.haveAgent.checked,365)
	resetEmail();
	alert('Your message has been sent!');
}
function forward(obj){
	urlstring = '/wwwroot/remaint/ajax/forward.cfm?did='+did;
	urlstring += '&from_search='+escape(document.location.search);
	urlstring += '&from_pathname='+escape(document.location.pathname);
	urlstring += '&to_url='+escape(obj.url);
	if (obj.user_id)
		urlstring += '&user_id='+obj.user_id;
	if (obj.comp_id)
		urlstring += '&comp_id='+obj.comp_id;
	if (obj.classid)
		urlstring += '&classid='+obj.classid;
	if (obj.adid)
		urlstring += '&adid='+obj.adid;
	
	/*initializeBoxes();
	myAppBox.innerHTML = urlstring;
	myAppBox.style.visibility='visible';
	centerbox(myAppBox)
	return;*/
	
	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.send(null)
	var mystring = 'document.location = "'+obj.url+'"';
	//alert(mystring);
	setTimeout(mystring,50)
}
function centerMe(){
	if (document.body.clientHeight >= currentForm.form.offsetHeight){
		if (document.body.scrollTop < screen_top){
			if (currentForm.form.offsetTop+currentForm.form.offsetHeight > document.body.scrollTop+document.body.clientHeight){
				scroll(0,currentForm.form.offsetTop+currentForm.form.offsetHeight-document.body.clientHeight)
				screen_top = currentForm.form.offsetTop+currentForm.form.offsetHeight-document.body.clientHeight
			}
		}
		if (document.body.scrollTop > screen_top){
			if (document.body.scrollTop > currentForm.form.offsetTop){
				scroll(0,currentForm.form.offsetTop)
				screen_top = currentForm.form.offsetTop
			}
		}
	}
	else {
		if (document.body.scrollTop < screen_top){
			//alert()
			if (currentForm.form.offsetTop > document.body.scrollTop){
				//alert()
				scroll(0,currentForm.form.offsetTop)
				screen_top = currentForm.form.offsetTop
			}
		}
		if (document.body.scrollTop > screen_top){
			if (currentForm.form.offsetTop+currentForm.form.offsetHeight < document.body.scrollTop+document.body.clientHeight){
				scroll(0,currentForm.form.offsetTop+currentForm.form.offsetHeight-document.body.clientHeight)
				screen_top = currentForm.form.offsetTop+currentForm.form.offsetHeight-document.body.clientHeight
			}
		}
	}
		
}
