function fixInputs()
{
	var input;
	
	var inputs=document.getElementsByTagName("input");	
	for(var i=0;i<inputs.length;i++)
	{
		input=inputs.item(i);
		if(
			(input.getAttribute("type")=="text")
		)
		{
			input.onfocus=function () { var s=this.style; s.borderWidth="2px"; s.borderStyle="solid"; s.borderColor="#009900"; };
			input.onblur=function () { var s=this.style; s.borderWidth="2px"; s.borderStyle="solid"; s.borderColor="#aaa"; };
		}
	}
	
	inputs=document.getElementsByTagName("textarea");
	for(var i=0;i<inputs.length;i++)
	{
		input=inputs.item(i);
		input.onfocus=function () { var s=this.style; s.borderWidth="2px"; s.borderStyle="solid"; s.borderColor="#009900"; };
		input.onblur=function () { var s=this.style; s.borderWidth="2px"; s.borderStyle="solid"; s.borderColor="#aaa"; };
	}
	
	inputs=document.getElementsByTagName("select");
	for(var i=0;i<inputs.length;i++)
	{
		input=inputs.item(i);
		input.onfocus=function () { var s=this.style; s.borderWidth="2px"; s.borderStyle="solid"; s.borderColor="#009900"; };
		input.onblur=function () { var s=this.style; s.borderWidth="2px"; s.borderStyle="solid"; s.borderColor="#aaa"; };
	}
	
}

function clearForm(f)
{
	var input;
	
	var inputs=document.getElementsByTagName("input");
	for(var i=0;i<inputs.length;i++)
	{
		input=inputs.item(i);
		if(
			(input.getAttribute("type")=="text")
		)
		{
			input.value="";
		}
	}
	
	inputs=document.getElementsByTagName("textarea");
	for(var i=0;i<inputs.length;i++)
	{
		input=inputs.item(i);
		input.value="";
	}
	
	inputs=document.getElementsByTagName("select");
	for(var i=0;i<inputs.length;i++)
	{
		input=inputs.item(i);
		input.selectedIndex=0;
	}
}

var sPopup=null;

function sendMessage(e,f)
{
	f=$(f);
	var http_request=makeHttpRequestObject();
	if (!http_request)
	{
		return false;
	}
	sPopup=new LightboxGeneric()
	sPopup.start(300,100,"sPopup");
	sPopup.objLightbox.update("Sending Your Message...");

	var query_string=f.serialize(false);
	/*query_string+="name="+f.name.value;
	query_string+="&email="+f.email.value;
	query_string+="&phone="+f.phone.value;
	if(f.moving)
		query_string+="&moving="+f.moving.value;
	if(f.subject)
		query_string+="&subject="+f.subject.value;
	query_string+="&message="+f.message.value;*/
		
	http_request.onreadystatechange = function() { processSendMessage(http_request,f); };
	try {
		AJAXSend(http_request,QBS_site_url+"/user_ajax/send_message",query_string);
	}
	catch (e)
	{
		alert("Error requesting data from server.  Contact Technical Support.\n\r"+e);
		sPopup.end();
	}
}

function processSendMessage(http_request,f)
{
	if (http_request.readyState == 4)
	{
		if (http_request.status == 200)
		{
			var xmldoc=http_request.responseXML;
			var success=parseInt(getNamedNodeValue(xmldoc,"success"));
			if(success==1)
			{
				sPopup.objLightbox.update("Your message has been sent.  You should be getting a response soon, thank you!");
				clearForm(f);
			}
			else if(success==2)
			{
				sPopup.objLightbox.update("Your message has been sent, but there was not enough information to be able to contact you.  If you would like a reply, please provide your contact information and send your message again. Thank you!");
			}
			else
			{
				sPopup.objLightbox.update("I couldn't send your message, please try again.");
			}
			var button=document.createElement("input");
			button.setAttribute("type","button");
			button.setAttribute("value","Close");
			button.onclick=function () { sPopup.end(); };
			sPopup.objLightbox.appendChild(document.createElement("br"));
			sPopup.objLightbox.appendChild(button);
		}
		else
		{
			alert('Server Error, contact Techincal Support.');
			sPopup.end();
		}
	}
}

var mPopup=null;
function showContactForm(e,subject)
{
	var http_request=makeHttpRequestObject();
	if (!http_request)
	{
		return false;
	}
	mPopup=new LightboxGeneric();
	mPopup.start(280,320,"sPopup");
	//mPopup=createPopup(e, 280, 320, "sPopup","center",null,null,true);

	var f=document.createElement("form");
	var tb=document.createElement("table");
	var tr;
	var td;
	var inp;
	tb.setAttribute("id","ajaxContactContainerDiv");
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	td.setAttribute("class","contactLabel");
	td.appendChild(document.createTextNode("Name:"));
	
	td=tr.insertCell(-1);
	inp=document.createElement("input");
	inp.setAttribute("type","text");
	inp.setAttribute("name","name");
	td.appendChild(inp);
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	td.setAttribute("class","contactLabel");
	td.appendChild(document.createTextNode("Email:"));
	
	td=tr.insertCell(-1);
	inp=document.createElement("input");
	inp.setAttribute("type","text");
	inp.setAttribute("name","email");
	td.appendChild(inp);
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	td.setAttribute("class","contactLabel");
	td.appendChild(document.createTextNode("Phone:"));
	
	td=tr.insertCell(-1);
	inp=document.createElement("input");
	inp.setAttribute("type","text");
	inp.setAttribute("name","phone");
	td.appendChild(inp);
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	td.setAttribute("class","contactLabel");
	td.appendChild(document.createTextNode("Moving Soon?:"));
	
	td=tr.insertCell(-1);
	inp=document.createElement("select");
	inp.setAttribute("name","moving");
	var opt=document.createElement("option");
	opt.appendChild(document.createTextNode("Choose Your Time Frame"));
	inp.appendChild(opt);
	opt=document.createElement("option");
	opt.appendChild(document.createTextNode("Immediately"));
	inp.appendChild(opt);
	opt=document.createElement("option");
	opt.appendChild(document.createTextNode("in 1-3 Months"));
	inp.appendChild(opt);
	opt=document.createElement("option");
	opt.appendChild(document.createTextNode("in 3-6 Months"));
	inp.appendChild(opt);
	opt=document.createElement("option");
	opt.appendChild(document.createTextNode("in the next year"));
	inp.appendChild(opt);
	td.appendChild(inp);
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	td.setAttribute("class","contactLabel");
	td.appendChild(document.createTextNode("Subject:"));
	
	td=tr.insertCell(-1);
	inp=document.createElement("input");
	inp.setAttribute("type","text");
	inp.setAttribute("name","subject");
	inp.setAttribute("value",subject);
	td.appendChild(inp);
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	td.setAttribute("class","contactLabel");
	td.appendChild(document.createTextNode("Message:"));
	
	td=tr.insertCell(-1);
	inp=document.createElement("textarea");
	inp.setAttribute("name","message");
	td.appendChild(inp);
	
	tr=tb.insertRow(-1);
	
	td=tr.insertCell(-1);
	
	td=tr.insertCell(-1);
	inp=document.createElement("input");
	inp.setAttribute("type","button");
	inp.setAttribute("value","Send Message");
	inp.setAttribute("style","width: auto");
	inp.onclick=function () { sendMessage(e,f); mPopup.end(); };
	td.appendChild(inp);
	

	tr=tb.insertRow(-1);
	td=tr.insertCell(-1);
	td.colSpan=2;
	td.appendChild(document.createTextNode("If you'll provide your contact information, we'll be happy to help you out.  Leave only as much information as you feel comfortable with. We promise we keep this information confidential."));
	f.appendChild(tb);
	mPopup.objLightbox.appendChild(f);
	fixInputs(mPopup.objLightbox);
}

