function clearDefault(el) {
	if (el.defaultValue==el.value) el.value = "";
	el.className='fixed';
}
function replaceDefault(el) {
	if (!el.value.length) { el.value = el.defaultValue; el.className='search'; }
}

function toggle_visibility(id) {
	var el = document.getElementById('dir_container').getElementsByTagName('div');
	var L, i=0;
	while(L = el[i++]) { L.style.display=(L.getAttribute("id") == id || L.getAttribute("class") == 'col' || L.getAttribute("class" ) == 'pc' ) ? "block" : "none"; }
}
function gotoCity(sid) {
	if (sid != "") { window.top.location.href = '/directory/cities.php?ID=' + sid; }
}
function gotoCounty(sid) {
	if (sid != "") { window.top.location.href = '/directory/counties.php?ID=' + sid; }
}
function gotoUSD(sid) {
	if (sid != "") { window.top.location.href = '/directory/usds.php?ID=' + sid; }
}

function _tag(tagname,attributes){
	var begin = "<" + tagname + (attributes?(" " + attributes):"") + ">";
	var end = "</" + tagname + ">";
	return begin + this + end;
}
String.prototype.tag = _tag;

var toggle = new Object();

/* new function to work with toggle global object for namespace sake */
function tog(obj,state){
	var el = document.getElementById(obj);
	if ( state == "" ) { 
		var opp = el.checked;
		state = ( opp == false ) ? true : false; 
	}
	el.style.display = ( state == 0 ) ? 'none' : 'block';
}

// prep css: BLOCK { display: none; } // or block if you want shown by default
// call: <a href="#" onclick="tog('BLOCK');return false;">

function togBAK(obj,state){
	if(typeof toggle[obj] == "undefined") toggle[obj] = true;
	o = document.getElementById(obj);
	if(o){
		switch(state){
			case true: toggle[obj] = true; break;
			case false: toggle[obj] = false; break;
			default: toggle[obj] = toggle[obj]?false:true; break;
		}
		o.style.display = toggle[obj]?"none":"block";
	}
}

function upd(obj,state) {
	var el = document.getElementById(obj);
	el.checked = ( state == 0 ) ? false : true;
}
function hil(obj,cl) {
	var el = document.getElementById(obj);
	el.className = cl;
}

function tot(elems) {
	var sum = 0;
	var elem, str;
	
	for(i=0; i<elems.length; i++) {
		var el = document.getElementById(elems[i]);
		if ( el.checked == true ) {
			str = el.value;
			sum += Number( str.split(":")[1] );
		}			
	}
	document.getElementById('totalcost').innerHTML = sum.toFixed(2);
}

function geml_o(ln,fn,pn,domain,lo) {
	if(typeof domain == "undefined") domain = "lkm.org";
	if(typeof lo == "undefined") lo = 1;
	var at = String.fromCharCode(64);
	var dot = String.fromCharCode(46);
	if(lo == 2) {
		var address = fn + dot + ln + at + domain;
	} else {
		var address = fn.substr(1) + ln + at + domain;
	}
	if(typeof pn == "undefined") pn = address;
	return pn.tag("a","href=\"mailto:" + address + "\" class=\"eml\"");
}
function geml( b, a, dom, d, t, o ) {
	if(typeof dom == "undefined" ) dom = "lkm.org";
	if(typeof t == "undefined" ) t = 1;
	
	var at = String.fromCharCode(64);
	var dot = String.fromCharCode(46);
	
	if( t == 1 ) {
		var address = a.substr(0,1) + b + at + dom;
	} else if( t == 2 ) {
		var address = a + dot + b + at + dom;
	} else if( t == 3 ) {
		var address = o + at + dom;
	} else if( t == 4 ) {
		var address = a + "_" + b + at + dom;
	} else if( t == 5 ) {
		var address = b + at + dom;
	}
	if(typeof d == "undefined") { d = address.toLowerCase(); }
	if( d == "name" ) { d = a + " " + b; }
	return d.tag("a","class=\"eml\" href=\"mailto:" + address.toLowerCase() + "\"");
}

function gemlim( b, a, coords ) {
	var dom = "lkm.org";
	var at = String.fromCharCode(64);
	var dot = String.fromCharCode(46);
	
	var d = "";
	var address = a.substr(0,1) + b + at + dom;
	
	return d.tag("area","shape=\"rect\" coords=\"" + coords + "\" href=\"mailto:" + address.toLowerCase() + "\"");
}

function popWin(url) {
	var theURL=url;
	newWin = window.open(theURL,'win','toolbar=No,menubar=No,left=200,top=200,width=350,resizable=yes,scrollbars=yes,status=No,location=No,height=400');
}

// Create the new window
function openInNewWindow(e) {
var event;
if (!e) event = window.event;
else event = e;
// Abort if a modifier key is pressed
if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
return true;
}
else {
// Change "_blank" to something like "newWindow" to load all links in the same new window
var newWindow = window.open(this.getAttribute('href'), '_blank');
if (newWindow) {
if (newWindow.focus) {
newWindow.focus();
}
return false;
}
return true;
}
}

// Add the openInNewWindow function to the onclick event of links with a class name of "external"
function getNewWindowLinks() {
// Check that the browser is DOM compliant
if (document.getElementById && document.createElement && document.appendChild) {
// Change this to the text you want to use to alert the user that a new window will be opened
var strNewWindowAlert = "";//" (opens in a new window)";
// Find all links
var objWarningText;
var link;
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
link = links[i];
// Find all links with a class name of "target"
if (/\bexternal\b/.test(link.className)) {
// Create an em element containing the new window warning text and insert it after the link text
objWarningText = document.createElement("em");
objWarningText.appendChild(document.createTextNode(strNewWindowAlert));
link.appendChild(objWarningText);
link.onclick = openInNewWindow;
}
}
objWarningText = null;
}
}

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

addEvent(window, 'load', getNewWindowLinks);//-->
/* 
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
*/

function showResult(str) {
if (str.length==0)
  {
  document.getElementById("livesearch").innerHTML="";
  document.getElementById("livesearch").style.border="0px";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
    document.getElementById("livesearch").style.border="1px solid #A5ACB2";
    }
  }
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}

