// JavaScript Document
// show/hide element by id
function toggle_display(id)
{
	if (document.getElementById(id).style.display == 'none') {
		document.getElementById(id).style.display = 'block';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}
// show element by id
function showById(id)
{
	document.getElementById(id).style.display = 'block';
}
// hide element by id
function hideById(id)
{
	document.getElementById(id).style.display = 'none';
}
// change image by element id
function change_image(id, img) 
{
	document.getElementById(id).src = 'images/' + img;
}
// change element forecolor by id
function change_color(id, color)
{
	document.getElementById(id).style.color = '#' + color;
}
function menu_rollover(id) {
	var clr = document.getElementById(id).style.color;
	var cls = document.getElementById(id).className;
	if (cls == 'white') {
		document.getElementById(id).style.color = '#C8DF8E';
	}
}
function change_class(id, cls) {
	document.getElementById(id).className = cls;
}
function validate_required(field)
{
	with (field)
	{
		if (value==null||value=="")
		{
			return false;
		} else {
			field.focus();
			return true;
		}
	}
}
function validate_expression(field, expr)
{
	var val = field.value.replace(/ /,'');
	if (val.match(expr)) {
		return true;	
	} else {
		field.focus();
		return false;
	}
}
// contact us form validation
function validate_contact(this_form) 
{
	var alphaExp = /^[a-zA-Z ]+$/;
	var numExp  = /^[0-9]+$/;
	var alphaNumExp = /^[0-9a-zA-Z ]+$/;
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;
	var ok = true;
	var msg = '';
	
	with (this_form)
	{
		// check required fields; values
		if (validate_required(tbCompany) == false)
		{
			msg = msg + "<br />Enter a Company Name";
			ok = false;
		} else {
			if (validate_expression(tbCompany, alphaNumExp) == false)
			{
				msg = msg + "<br />Your Company Name contains some invalid characters";
				ok = false;
			}
		}
		if (validate_required(tbContact) == false)
		{
			msg = msg + "<br />Enter a Contact Name";
			ok = false;
		} else {
			if (validate_expression(tbContact, alphaNumExp) == false)
			{
				msg = msg + "<br />Your Contact Name contains some invalid characters";
				ok = false;
			}
		}
		if (validate_required(tbEmail) == false)
		{
			msg = msg + "<br />Enter a valid Email Address";
			ok = false;
		} else {
			if (validate_expression(tbEmail, emailExp) == false)
			{
				msg = msg + "<br />Your Email Address is not valid";
				ok = false;
			}
		}
		if (validate_required(captcha) == false)
		{
			msg = msg + "<br />Enter the Characters that appear in the image";
			ok = false;
		} else {
			if (validate_expression(tbEmployeeCount, alphaNumExp) == false)
			{
				msg = msg + "<br />There are invalid characters in the Entry for the characters that appear in the image";
				ok = false;
			}
		}
	}
}
// quick quote form validation
function validate_form(this_form)
{
	var alphaExp = /^[a-zA-Z ]+$/;
	var numExp  = /^[0-9]+$/;
	var alphaNumExp = /^[0-9a-zA-Z ]+$/;
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;
	var ok = true;
	var msg = '';
	
	with (this_form)
	{
		// check required fields
		if (validate_required(tbCompany) == false)
		{
			msg = msg + "<br />Enter a Company Name";
			ok = false;
		} else {
			if (validate_expression(tbCompany, alphaNumExp) == false)
			{
				msg = msg + "<br />Your Company Name contains some invalid characters";
				ok = false;
			}
		}
		if (validate_required(tbContact) == false)
		{
			msg = msg + "<br />Enter a Contact Name";
			ok = false;
		} else {
			if (validate_expression(tbContact, alphaNumExp) == false)
			{
				msg = msg + "<br />Your Contact Name contains some invalid characters";
				ok = false;
			}
		}
		if (validate_required(tbEmail) == false)
		{
			msg = msg + "<br />Enter a valid Email Address";
			ok = false;
		} else {
			if (validate_expression(tbEmail, emailExp) == false)
			{
				msg = msg + "<br />Your Email Address is not valid";
				ok = false;
			}
		}
		if (validate_required(tbEmployeeCount) == false)
		{
			msg = msg + "<br />Enter the Number of Employees";
			ok = false;
		} else {
			if (validate_expression(tbEmployeeCount, numExp) == false)
			{
				msg = msg + "<br />There are invalid characters in the Number of Employees entry";
				ok = false;
			}
		}
		if (validate_required(captcha) == false)
		{
			msg = msg + "<br />Enter the Characters that appear in the image";
			ok = false;
		} else {
			if (validate_expression(tbEmployeeCount, alphaNumExp) == false)
			{
				msg = msg + "<br />There are invalid characters in the Entry for the characters that appear in the image";
				ok = false;
			}
		}
	}
	if (msg.length > 0) {
		msg = "Please correct the information below and re-submit your request:<br />" + msg;
		document.getElementById('dMsg').innerHTML = msg;
	}
	return ok;
}

