var isIE=(navigator.userAgent.toLowerCase().indexOf("msie")>=0);

var whereopen=0,wherestate=0,wheretime=0,wheretimer=null,wheredoclose=false,whereforceclose=false,wherehasfocus=false,wheredur=300;

function whereover()
{
	if(whereforceclose) return;
	if(wheredoclose) { wheredoclose=false; return; }
	if(wherestate==1||whereopen==1) return;
	wheretime=new Date().getTime()-whereopen*wheredur;
	wherestate=1;
	if(!wheretimer) wheretimer=setInterval(whereslide,15);
	document.getElementById("wherearr").src="/sys/images/ls/uarr6.gif";
}

function whereout()
{
	if(whereopen==0||wherehasfocus) return;
	wheredoclose=true;
	setTimeout(whereclose,100);
}

function whereclose()
{
	if(!wheredoclose||wherestate==2||whereopen==0) return;
	wheredoclose=false;
	wheretime=new Date().getTime()-(1-whereopen)*wheredur;
	wherestate=2;
	if(!wheretimer) wheretimer=setInterval(whereslide,15);	
}

function wherearrc()
{
	if(document.selection) document.selection.empty();
	else window.getSelection().removeAllRanges();
	whereforceclose=true;
	wheredoclose=true;
	whereclose();
}

function whereslide()
{
	if(!wherestate) {
		clearInterval(wheretimer);
		wheretimer=null;
		return;
	}
	if(wherestate==1) {
		whereopen=(new Date().getTime()-wheretime)/wheredur;
		if(whereopen>=1) {
			whereopen=1;
			wherestate=0;
			document.getElementById("wherearr").src="/sys/images/ls/uarr6.gif";
		}
	} else {
		whereopen=1-(new Date().getTime()-wheretime)/wheredur;
		if(whereopen<=0) {
			whereopen=0;
			wherestate=0;
			whereforceclose=false;
			wherehasfocus=false;
			document.getElementById("wherearr").src="/sys/images/ls/darr6.gif";
		}
	}
	var y=(whereopen*whereopen*2)*50;
	if(whereopen>0.5) y=50-((1-whereopen)*(1-whereopen)*2)*50;
	var el=document.getElementById("wherefade");
	var h=y; if(h>45) h=45;
	el.style.height=h;
    el.style.display = h>0?"block":"none";
    document.getElementById("wherefimg").style.top=y-13;
	document.getElementById("wherebot").style.top=Math.floor(-70+y+0.5);
	document.getElementById("wherebox").style.height=Math.floor(92+y+0.5);
}

function wherefocus() {
	wherehasfocus=true;
	setTimeout("document.vform.where.select()",10);
}

function whereblur(e)
{
	if(!e) e=window.event;
	var el=document.getElementById("wherebox");
	var p=getPos(el);
	if(e.clientX<p.x||e.clientX>p.x+el.offsetWidth||e.clientY<p.y||e.clientY>p.y+el.offsetHeight) {
		wherehasfocus=false;
		whereout();
	}
}

function getWindowHeight()
{
	return window.innerHeight?window.innerHeight:(document.documentElement&&document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight);
}

function resized()
{
}

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 processWhat(what)
{
	return what.replace(/[\'\"]/g,"").replace(/[\\\/]/g,"-").replace(/[\.,]/g," ");
}

var vreq=null,vrtimer=null,pwhere=null;
function dosubmit()
{
  //	if(pwhere) location.href="/"+pwhere+"/"+encodeURIComponent(processWhat(document.vform.what.value));
  if (pwhere) location.href = "http://ip.norcallocalsearch.com/" + pwhere + "/" + encodeURIComponent(processWhat(document.vform.what.value));
}
function whereinvalid()
{
	if(pwhere) 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 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);
		if(!vreq) vreq=zXmlHttp.createRequest();
		if(vreq.readyState!=0) vreq.abort();
		//   vreq.open("GET","/sys/pageserver.dll?s=-20&pa="+escape(pwhere),true);
		vreq.open("GET", "http://ip.norcallocalsearch.com/sys/pageserver.dll?s=-20&pa=" + escape(pwhere), true);		
	    vreq.onreadystatechange = function() {
	        if(vreq.readyState==4) {
       			if(vrtimer) { clearTimeout(vrtimer); vrtimer=null; }
	        	if(vreq.responseText.indexOf("\"notfound\":true")>0) { whereinvalid(); pwhere=null; }
	        	else dosubmit();
	        }
	    };
	    vreq.send("");
    }
    else dosubmit(nochange);
	return false;
}



function init()
{
  setTimeout(function() {
  	initheader();
	if(typeof initpage!="undefined") setTimeout(initpage,1);
  },1);
}

