/***************************************************************************
* 
*
***************************************************************************/
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

/***************************************************************************
* 
*
***************************************************************************/
function prepPage()
{
	if (document.getElementById("read_more"))
	{
		document.getElementById("read_more").onclick = prepReadMore;
	}
	if (document.getElementById("inline_contact"))
	{
		document.getElementById("inline_contact").onclick = processContact;
	}
	//wsa_include_js();
}
/***************************************************************************
*
*
***************************************************************************/
function prepReadMore()
{
	var btn = document.getElementById("read_more");
	var cbox = document.getElementById("hidden_content");
	btn.style.visibility = "visible";

	if (btn.innerHTML == "READ MORE")
	{
		cbox.style.visibility = "visible";
		cbox.style.overflow = "visible";
		cbox.style.height = "auto";
		btn.innerHTML = "READ LESS";
	}
	else
	{
		cbox.style.visibility = "hidden";
		cbox.style.overflow = "hidden";
		cbox.style.height = "1px";
		btn.innerHTML = "READ MORE";
	}
}

/***************************************************************************
*
*
***************************************************************************/
function processContact()
{
	var cname = document.getElementById("name").value,
		cemail = document.getElementById("email").value;
		cphone = document.getElementById("phone").value;
		//caddress = document.getElementById("address").value;
		
		cstreet = document.getElementById("street").value;
		ccity = document.getElementById("city").value;
		cprovince = document.getElementById("province").value;
		ccountry = document.getElementById("country").value;
		cpostal_code = document.getElementById("postal_code").value;
		caddress = cstreet + ccity + cprovince + cpostal_code + ccountry;
		
		ccomment = document.getElementById("comment").value;
		cbrochure = document.getElementById("brochure_").checked;
		/*csecurity_code = document.getElementById("security_code").value;*/
		csubject = document.getElementById("subject");
	
	var errors = new Array();
	if (cname == "")
	{
		errors.push("Please enter your name");
	}
	if (cemail == "" && cphone == "")
	{
		errors.push("Please enter either an email address or a phone number");
	}
	if (caddress == "" && cbrochure)
	{
		errors.push("To receive a brochure, you must provide your address");
	}

	/*if (csecurity_code == "")
	{
		errors.push("Please enter the security code ");
	}*/

	if (ccomment == "")
	{
		errors.push("Please enter a question or comment");
	}


	if (errors.length > 0)
	{
		errors = "Please correct the following errors and try again:\n\n" + errors.join("\n");
		alert(errors);
	}
	else
	{
		document.forms[0].submit();
		
	}
	
}

/***************************************************************************
*
*
***************************************************************************/
function processPostback(error)
{
	if(! isNaN(error))
	{
		//wopen("comment_sent.php", "comment_sent", 330, 150);
		alert("Thank you for submitting your comment/question.\nOne of our representatives will be in touch shortly.");
		document.forms[0].reset();
	}
	else
	{
		if (error == "Security code was incorrect")
		{
			document.getElementById("security_code").select();
			document.getElementById("security_code").focus();
		}
		alert(error);	
	}
}

/***************************************************************************
*
*
***************************************************************************/
function wopen(url, name, w, h)
{
	// Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	// IE5 and other old browsers might allow a window that is
	// partially offscreen or wider than the screen. Fix that.
	// (Newer browsers fix this for us, but let's be thorough.)
	if (wleft < 0) 
	{
		w = screen.width;
		wleft = 0;
	}
	if (wtop < 0) 
	{
		h = screen.height;
		wtop = 0;
	}
	

}
