var ie5                 = false;
var ns6                 = false;
var moz                 = false;
var mac                 = false;
var flag                = false;
var running             = false;
var timerId             = null;
var delay               = 50;
var currentMenu         = null;
var previousMenu        = null;
var loaded              = false;
var testing             = false;
var allopened           = false;
var homepage            = false;
var dir_images          = 'images/';

agent = navigator.userAgent.toLowerCase();
ie5   = (document.all && document.getElementById)  ? true : false;
ns6   = (document.getElementById && !document.all) ? true : false;
moz   = (document.getElementById && !document.all) ? true : false;
mac   = (agent.indexOf("mac")!=-1);
flag  = (agent.indexOf("firefox")!=-1 || agent.indexOf("msie")!=-1 || agent.indexOf("safari")!=-1);

function SafeMail(name, domain, display, css, subject) {
  css       = (css)     ? ' class="' + css + '"' : '';
  subject   = (subject) ? '?subject=' + subject : '';
  displayed = (display) ? display : name + '@' + domain;
  mailto    = name + '@' + domain + subject;
  document.write('<a href="mailto:' + mailto + '"' + css + '>' + displayed + '</a>');
}
function Popup(title,filename,w,h,scroll,resizable,menubar) {
  title     = (title == '')         ? 'popup' : title;
  scroll    = (scroll == 'scroll')  ? 'yes'   : 'no';
  resizable = (resizable == 'lock') ? 'no'    : 'yes';
  menubar   = (menubar == 'menu')   ? 'yes'   : 'no';
  
  winOptions = eval("'width="+w+",height="+h+",toolbar=no,location=no,directories=no,status=no,menubar="+menubar+",scrollbars="+scroll+",resizable="+resizable+",copyhistory=no'");
  window.open(filename,title,winOptions);
  return;
}
function PopWindow(title, url, width, height) {
  BuildWindow({id:'popwindow', title:title, url:url, width:width, height:height});
}
function SetFocus(fieldname,formname){if (formname == ''){ formname = 'form'; }if (eval("document."+formname+".elements[fieldname].value == ''")){ eval("document."+formname+".elements[fieldname].focus();"); }}
function SpellCheck() {
	var speller = new spellChecker();
	speller.spellCheckAll();
}
function DisableButtonImg(obj) {
  obj.src          = 'images/loading.gif';
  obj.disabled     = true;
  obj.style.border = 'none';
}
function DisableButtonTxt(obj) {
  obj.value        = 'Processing...';
  obj.disabled     = true;
  obj.style.border = 'none';
}
function SubmitForm(obj, form_action) {
  // disable button
  DisableButtonTxt(obj);
  
  // get elements
  var frm = document.forms[obj.form.name];
  var act = frm.elements['form_action'];
  
  // set form action
  act.value = form_action;
  
  // submit form
  frm.submit();
}
function HideOutput() {
  // check for previous reponses/errors
  if ($('flash')) { Element.hide('flash'); }
}
function ToggleElement(id) {
  if ($(id)) { Element.toggle(id); }
}

function SetBrowser() {
  agent       = navigator.userAgent.toLowerCase();
  mac         = (agent.indexOf("mac")!=-1);
  ie4         = (document.all && !document.getElementById) ? true : false;
  ie5         = (document.all && document.getElementById)  ? true : false;
  ns4         = (document.layers)                          ? true : false;
  ns6         = (document.getElementById && !document.all) ? true : false;
  if (testing){ alert("agent: "+agent+"\nmac: "+mac+"\nie4: "+ie4+"\nie5: "+ie5+"\nns4: "+ns4+"\nns6: "+ns6+"\n"); }
}
function DisableButton(obj) {
  obj.src          = 'images/btn_processing.gif';
  obj.disabled     = true;
  obj.style.border = 'none';
}

function ToggleCatDocs (catid,contentid) {
  if (document.getElementById(contentid).style.display == "none") {
    document.getElementById(contentid).style.display = "block";
    document.getElementById(catid).className = "category-open";
  } else {
    document.getElementById(contentid).style.display = "none";
    document.getElementById(catid).className = "category-closed";
  }
}

function Show(id) { if (document.getElementById(id)) document.getElementById(id).style.display = 'block'; }
function Hide(id) { if (document.getElementById(id)) document.getElementById(id).style.display = 'none'; }
function Toggle(id) {
  obj = document.getElementById(id);
  if (obj) {
    obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
  }
}
function LoginNotice (referer) {
  var site = '';
  if (referer == 'AB Austin') {
    site = 'Armbrust & Brown';
  } else if (referer == 'HOA') {
    site = 'The Association';
  } else {
    site = 'The Declarant';
  }
  alert('You are about to enter a secured area of the ' + site + ' website. You will have access to certain documents which may be considered privileged pursuant to the attorney/client privileged information and/or work product privileged information under Texas and Federal Law. If you do not have authorization to access the secured area, you are advised to leave this site and contact Armbrust & Brown for access rights.');
}

Event.onReady(function() {
	// add behavior to menus
	InitMenus("nav");
	
	// add smooth scroll?
	SetBrowser();
	if (!(mac && ie5)) {
		ScrollLinks.start();
	}
});
