// SEARCH LINK
function vtop(q,state)
{
var ex1="";
var ex2="";
	if(!is_numeric(q))
	{
		if(state!='')
		{
		var ex1="state="+state+"&";
		}
	var ex2="&type=brand";
	}
var vtop = window.location.assign("http://www.easternorthodoxchurchesusa.info/search?"+ex1+"q="+q+ex2);
}

// DRAW MAP
function draw_map(id,lat,lng)
{
var myid = document.getElementById('td-map2');
var idht = '<IFRAME NAME="map" SRC="http://www.easternorthodoxchurchesusa.info/map.html?id='+id+'&lat='+lat+'&lng='+lng+'" WIDTH="100%" HEIGHT="265" FRAMEBORDER="0" SCROLLING="no" CLASS="if-map"></IFRAME>';
myid.innerHTML = idht;
}

// CHECK FOR NUMERIC Q
function is_numeric(mixed_var)
{
	if(mixed_var==='')
	{
	return false;
	}
return !isNaN(mixed_var * 1);
}

// SHOW RESULTS
function res_info()
{
var dest = document.getElementById("td-biz");
var orig = document.getElementById("div-contact");
orig.parentNode.removeChild(orig);
dest.appendChild(orig);
}

// SHOW CM
function cm(did,pid)
{
	if(pid=='index' || pid=='search4' || pid=='search5' || pid=='listings4')
	{
	var wid = 468;
	var hei = 15;
	}
	if(pid=='search1' || pid=='search2' || pid=='search3' || pid=='listings1' || pid=='listings2' || pid=='listings3')
	{
	var wid = 728;
	var hei = 90;
	}
	if(pid=='search6' || pid=='listings8')
	{
	var wid = 160;
	var hei = 600;
	}
	if(pid=='listings5' || pid=='listings6')
	{
	var wid = 300;
	var hei = 250;
	}
	if(pid=='listings7')
	{
	var wid = 200;
	var hei = 90;
	}
var myid = document.getElementById(did);
var idht = '<IFRAME NAME="cm" SRC="http://www.easternorthodoxchurchesusa.info/cm.html?id='+pid+'" WIDTH="'+wid+'" HEIGHT="'+hei+'" FRAMEBORDER="0" SCROLLING="no" CLASS="if-cm"></IFRAME>';
myid.innerHTML = idht;
}

// SET STATE DIV STYLE
function init()
{
var states_div = document.getElementById('states');
states_div.style.display = "none";
}
window.onload = init;

// TOGGLE POPULAR CITIES
function cities()
{
var http = false;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
	http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	http = new XMLHttpRequest();
	}
var cities_short = document.getElementById('cities-short');
var cities = document.getElementById('cities');
	if(cities_short.style.display == "block") 
	{
	cities.style.display = "block";
		http.open("GET", "http://www.easternorthodoxchurchesusa.info/popular-cities.html",true);
		http.onreadystatechange=function()
		{
			if(http.readyState == 4)
			{
			cities_short.style.display = "none";
			cities.innerHTML = http.responseText;
			} else {
			cities.innerHTML = '<IMG SRC="http://www.easternorthodoxchurchesusa.info/images/loader.gif" WIDTH="220" HEIGHT="19" BORDER="0" CLASS="img-loader">';
			}
		}
		http.send(null);
	
	} else {
	cities_short.style.display = "block";
	cities.style.display = "none";
	}
}

// TOGGLE STATES
function states()
{
var http = false;
	if(navigator.appName == "Microsoft Internet Explorer")
	{
	http = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	http = new XMLHttpRequest();
	}
var states = document.getElementById('states');
	if(states.style.display == "none")
	{
		http.open("GET", "http://www.easternorthodoxchurchesusa.info/states.html",true);
		http.onreadystatechange=function()
		{
			if(http.readyState == 4)
			{
			states.innerHTML = http.responseText;
			}
		}
		http.send(null);
	states.style.display = "block";
	} else {
	states.style.display = "none";
	}
}

// SHOW STATES
function show_states()
{
var states_link = getAnchorPosition('states-link');
var states_div = document.getElementById('states');
states();
states_div.style.left = states_link.x+"px";
states_div.style.top = "25px";
}

// CLOSE STATES
function close_states()
{
var states_div = document.getElementById('states');
states_div.style.display = "none";
}

// GET ANCHOR POSISTION
function getAnchorPosition(anchorname)
{
var useWindow=false;
var coordinates=new Object();
var x=0,y=0;
var use_gebi=false, use_css=false, use_layers=false;
if (document.getElementById) { use_gebi=true; }
else if (document.all) { use_css=true; }
else if (document.layers) { use_layers=true; }
	if (use_gebi && document.all)
	{
	x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
	y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if (use_gebi)
	{
	var o=document.getElementById(anchorname);
	x=AnchorPosition_getPageOffsetLeft(o);
	y=AnchorPosition_getPageOffsetTop(o);
	}
	else if (use_css)
	{
	x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
	y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if (use_layers)
	{
	var found=0;
	for (var i=0; i<document.anchors.length; i++)
	{
	if (document.anchors[i].name==anchorname) { found=1; break; }
	}
		if (found==0)
		{
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	x=document.anchors[i].x;
	y=document.anchors[i].y;
	}
	else
	{
	coordinates.x=0; coordinates.y=0; return coordinates;
	}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}
// GET ANCHOR POSISTION - IE
function AnchorPosition_getPageOffsetLeft (el)
{
var ol=el.offsetLeft;
while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
return ol;
}
function AnchorPosition_getWindowOffsetLeft (el)
{
return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
}
function AnchorPosition_getPageOffsetTop (el)
{
var ot=el.offsetTop;
while((el=el.offsetParent) != null) { ot += el.offsetTop; }
return ot;
}
function AnchorPosition_getWindowOffsetTop (el)
{
return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
}

// HOVER PSEUDO-CLASS
phover=function()
{
var els = document.getElementById("body").getElementsByTagName("span");
	for(var i=0; i < els.length; i++)
	{
		els[i].onmouseover=function()
		{
		this.className+=" phover";
		}
		els[i].onmouseout=function()
		{
		this.className=this.className.replace(new RegExp(" phover\\b"),"");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload",phover);

// CLOSE STATES - CLICK ON BODY
function clickedOutsideElement(elemId,evt)
{
var theElem = '';
if(window.event)
theElem = getEventTarget(window.event);
else theElem = getEventTarget(evt);
	while(theElem != null)
	{
	if(theElem.id == elemId)
	return false;
	theElem = theElem.offsetParent;
	}
return true;
}

function getEventTarget(evt)
{
var targ = (evt.target) ? evt.target : evt.srcElement;
	if(targ != null)
	{
	if(targ.nodeType == 3)
	targ = targ.parentNode;
	}
return targ;
}

document.onclick = function(evt)
{
	if(clickedOutsideElement('states',evt) && clickedOutsideElement('states-link',evt))
	{
	close_states();
	}
}