
var isIE=(navigator.userAgent.toLowerCase().indexOf("msie")>=0);

function wherefocus() {
	setTimeout("document.vform.where.select()",10);
}

function getPos(el)
{
	var px=0,py=0;
	while(el) {
		px+=el.offsetLeft;
		py+=el.offsetTop;
		el=el.offsetParent;
	}
	return {x:px,y:py};
}

function processWhere(where)
{
	stateNames={"alabama":"AL","alaska":"AK","arizona":"AZ","arkansas":"AR","california":"CA","colorado":"CO","connecticut":"CT","delaware":"DE","florida":"FL","georgia":"GA","hawaii":"HI","idaho":"ID","illinois":"IL","indiana":"IN","iowa":"IA","kansas":"KS","kentucky":"KY","louisiana":"LA","maine":"ME","maryland":"MD","massachusetts":"MA","michigan":"MI","minnesota":"MN","mississippi":"MS","missouri":"MO","montana":"MT","nebraska":"NE","nevada":"NV","ohio":"OH","oklahoma":"OK","oregon":"OR","pennsylvania":"PA","tennessee":"TN","texas":"TX","utah":"UT","vermont":"VT","virginia":"VA","washington":"WA","wisconsin":"WI","wyoming":"WY","guam":"GU","palau":"PW","al":"AL","ak":"AK","az":"AZ","ar":"AR","ca":"CA","co":"CO","ct":"CT","de":"DE","fl":"FL","ga":"GA","hi":"HI","id":"ID","il":"IL","in":"IN","ia":"IA","ks":"KS","ky":"KY","la":"LA","me":"ME","md":"MD","ma":"MA","mi":"MI","mn":"MN","ms":"MS","mo":"MO","mt":"MT","ne":"NE","nv":"NV","nh":"NH","nj":"NJ","nm":"NM","ny":"NY","nc":"NC","nd":"ND","oh":"OH","ok":"OK","or":"OR","pa":"PA","ri":"RI","sc":"SC","sd":"SD","tn":"TN","tx":"TX","ut":"UT","vt":"VT","va":"VA","wa":"WA","wv":"WV","wi":"WI","wy":"WY","as":"AS","dc":"DC","gu":"GU","mh":"MH","pw":"PW","pr":"PR"};
	stateNames2={"new-hampshire":"NH","new-jersey":"NJ","new-mexico":"NM","new-york":"NY","north-carolina":"NC","north-dakota":"ND","rhode-island":"RI","south-carolina":"SC","south-dakota":"SD","west-virginia":"WV","american-samoa":"AS","puerto-rico":"PR"};
	if(where.length<4) return false;
	var w=where.split(",");
	var wu=w[0].replace(/[\\\/\. ]/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/-+/g,"-").replace(/^-/g,"").replace(/-$/g,"");
	if(w.length>1) {
		var sn=w[1].replace(/[\\\/\. ]/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/-+/g,"-").replace(/^-/g,"").replace(/-$/g,"");
		if(stateNames[sn.toLowerCase()]) sn=stateNames[sn.toLowerCase()];
		else if(stateNames2[sn.toLowerCase()]) sn=stateNames2[sn.toLowerCase()];
		wu+=","+sn;
	} else {
		if((stateNames[wu.toLowerCase()] || stateNames2[wu.toLowerCase()]) && wu.toLowerCase()!="new-york") return false;
		var i=wu.lastIndexOf("-");
		if(i>0) {
			var sn=wu.substr(i+1).toLowerCase();
			if(stateNames[sn]) wu=wu.substr(0,i)+","+stateNames[sn];
			else {
				i=wu.substr(0,i).lastIndexOf("-");
				if(i>0) {
					var sn=wu.substr(i+1).toLowerCase();
					if(stateNames2[sn]) wu=wu.substr(0,i)+","+stateNames2[sn];
	}	}	}	}
	return wu;
}

function processWhat(what)
{
	return what.replace(/[\'\"]/g,"").replace(/[\\\/]/g,"-").replace(/[\.,]/g," ");
}

var vrtimer=null,pwhere=null;
var searchtab=0;

function dosubmit()
{
	var pw=processWhat(document.vform.what.value);
	if(pw.length) pw="/"+encodeURIComponent(pw);
	var sec="",opts="";
	if(searchtab==1) sec="/White-Pages";
	if(searchtab==2) opts="/krev:1";
	var view="/list";	// ***** use "/search" for book view *****
	if(pwhere) location.href="http://statewide.informationpages.com/"+pwhere+sec+pw+view+opts;
}
function whereinvalid(alt)
{
	if(pwhere) {
		if(alt && alt.length>1) {
			if(confirm("\""+document.vform.where.value+"\" was not recognized.  Did you mean "+alt+"?")) {
				document.vform.where.value=alt;
				pwhere=processWhere(alt);
				dosubmit();
			}
			return;
		}
		alert("\""+document.vform.where.value+"\" was not recognized.  Please enter a city or zip code.");
	}
	else alert("Please enter a city or zip code.");
}

function JSFeed(r)
{
	if(vrtimer) { clearTimeout(vrtimer); vrtimer=null; }
	if(r&&r.notfound) { whereinvalid(r.dym||0); pwhere=null; }
	else dosubmit();
}

function dogo(nochange)
{
	if(vrtimer) return;
	pwhere=processWhere(document.vform.where.value);
	if(document.vform.where.value!=vwhere && !nochange) {
		if(!pwhere) { whereinvalid(); return; }
		vrtimer=setTimeout("vrtimer=null;dosubmit();",1000);
		JSONrequest("http://www.localscout.com/sys/pageserver.dll?s=-21&pa="+encodeURIComponent(pwhere)+"&p="+Math.random());
	}
	else dosubmit(nochange);
	return false;
}

function initheader()
{
	vrtimer=null;pwhere=null;
	document.vform.what.value=vwhat;
	document.vform.where.value=vwhere;
	new AutoSuggestControl(document.getElementById("what"), new SuggProvider(), "what");
	new AutoSuggestControl(document.getElementById("where"), new LocProvider(), "where");
	searchtab=0;
}

function init()
{
  setTimeout(initheader,1);
}

function yptab()
{
	el=document.getElementById("wwtabs");
	if(!el) return;
	el.src="http://www.informationpages.com/sys/images/62/tabyellow.png";
	searchtab=0;
}

function wptab()
{
	el=document.getElementById("wwtabs");
	if(!el) return;
	el.src="http://www.informationpages.com/sys/images/62/tabwhite.png";
	searchtab=1;
}

function revtab()
{
	el=document.getElementById("wwtabs");
	if(!el) return;
	el.src="http://www.informationpages.com/sys/images/62/tabreverse.png";
	searchtab=2;
}
