nav1_off = new Image();
nav1_on = new Image();
nav2_off = new Image();
nav2_on = new Image();
nav3_off = new Image();
nav3_on = new Image();
nav4_off = new Image();
nav4_on = new Image();
nav5_off = new Image();
nav5_on = new Image();
nav6_off = new Image();
nav6_on = new Image();
con_off = new Image();
con_on = new Image();

nav1_off.src = "images/nav1_off.gif";
nav1_on.src = "images/nav1_on.gif";
nav2_off.src = "images/nav2_off.gif";
nav2_on.src = "images/nav2_on.gif";
nav3_off.src = "images/nav3_off.gif";
nav3_on.src = "images/nav3_on.gif";
nav4_off.src = "images/nav4_off.gif";
nav4_on.src = "images/nav4_on.gif";
nav5_off.src = "images/nav5_off.gif";
nav5_on.src = "images/nav5_on.gif";
nav6_off.src = "images/nav6_off.gif";
nav6_on.src = "images/nav6_on.gif";
con_off.src = "images/contact.gif";
con_on.src = "images/contact_on.gif";

function roll(sname,rname){
    sname.src = rname.src;
}

function submenu(menuId,direction){
	var menu = document.getElementById('submenu'+menuId);
	if (direction==1){
    	menu.style.visibility = 'visible';
		}else {
		menu.style.visibility = 'hidden';
		}
}

function mainmenu(menuId,direction){
    if (direction==1){
		document.getElementById('main_'+menuId).className = 'practices_button on';
		}else{
		document.getElementById('main_'+menuId).className = 'practices_button';
		}
}


function id2elem(id) {
	// This is what most folks call "xGetElementById", but
	// again, I wanted to save myself some typing.
	if (typeof(id) != 'string') {
		return id;
	}
	if (document.getElementById) {
		id = document.getElementById(id);
	} else if (document.all) {
		id=document.all[id];
	} else {
		id = null;
	}
	return id;
}

function color_links(elem) {
//alert("running color_links(" + typeof elem + ").");
	var links = document.getElementsByTagName('a');
	for (var i = 0; i < links.length; i++) {
var elem_id = links[i].id;
		if (links[i].id.search(/^officelink\d/) == -1) {
//alert("Skipping link " + elem_id);
			continue;
		}
		if (links[i] == elem) {
			links[i].parentNode.className = 'on';
//alert("Turned on link " + elem_id);
		} else {
//alert("Turned off link " + elem_id);
			links[i].parentNode.className = '';
		}
	}
}


function get_XH_obj() {
	var xhreq;
	if (window.XMLHttpRequest) {
		//alert("Branch 1");
		xhreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		//alert("Branch 2");
		xhreq = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("I'm sorry, your browser doesn't seem to support the XMLHttpRequest object, either as part of the W3C DOM or as an ActiveX object. I regret to say that this means you won't be able to use the features on this site.");
	}
	return xhreq;
}

function std_ajax_send(URL, data) {
	//alert("std_ajax_send, opening GET " + URL + "?q=" + data);
	xhobj.open("GET", URL + "?q=" + data, true);
	xhobj.onreadystatechange = update_office;
	xhobj.send(null);
}


function update_office() {
	if (xhobj.readyState == 4) {
		var stat = xhobj.status;
		var stat_text = xhobj.statusText;
		var resp_text = xhobj.responseText;
		
		var lines = xhobj.responseText.split(/[\r\n]+/);
		for (var i = 0; i < lines.length; i++) {
			var id = lines[i].substr(0, lines[i].indexOf(':'));
			var data = lines[i].substr(lines[i].indexOf(':') + 2);
			//var data = lines[i].split(/:\s*/, 2);
			id = 'office' + id;
			switch(id) {
			case 'officeemaillink':
				id2elem(id).innerHTML = "<a href=\"mailto:" + data + "\">" + data + "</a>";
				break;
			case 'officedirectionslink':
				if (typeof data == 'string' && data.length > 1) {
					id2elem(id).innerHTML = "<a href=\"" + data + "\" target=\"_blank\">Directions&nbsp;&gt;</a>";
				} else {
					id2elem(id).innerHTML = '';
				}
				break;
			default:
				id2elem(id).innerHTML = data;
			}
		}
		id2elem('officeinfo').style.display = 'block';
	}
}


function clear_office() {
	id2elem('officeinfo').style.display = 'none';
}

// ****************
// Form validation functions
 function checkForm()
{
   var cname, cemail, cmessage;
   with(window.document.obj_form)
   {
      cname    = fullname;
      cemail   = email_address;
      cmessage = comments;
   }

   if(trim(cname.value) == '')
   {
      id2elem(frmMsg).style.display = 'block';
      id2elem(frmMsg).innerHTML = "<font color='red'><b>Please enter your email address</b></font>";
      cname.focus();
      return false;
   }
   else if(trim(cemail.value) == '')
   {
      id2elem(frmMsg).style.display = 'block';
      id2elem(frmMsg).innerHTML = "<font color='red'><b>Please enter your email address</b></font>";
      cemail.focus();
      return false;
   }
   else if(!isEmail(trim(cemail.value)))
   {
      id2elem(frmMsg).style.display = 'block';
      id2elem(frmMsg).innerHTML = "<font color='red'><b>Email address entered is not valid</b></font>";
      cemail.focus();
      return false;
   }
   /*else if(trim(cmessage.value) == '')
   {
      id2elem(frmMsg).style.display = 'block';
      id2elem(frmMsg).innerHTML = "<font color='red'><b>Please enter a comment</b></font>";
      cmessage.focus();
      return false;
   }*/
   else
   {
      cname.value    = trim(cname.value);
      cemail.value   = trim(cemail.value);
      //csubject.value = trim(csubject.value);
      cmessage.value = trim(cmessage.value);
      return true;
   }
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str)
{
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;

return regex.test(str);
}