/* js to detect browser type */
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
	is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
	is_major = parseInt(is_minor);}
var is_opera = (agt.indexOf("opera") != -1);
var is_konq = false;
var kqPos   = agt.indexOf('konqueror');
if (kqPos !=-1) {
	is_konq  = true;}
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var is_khtml  = (is_safari || is_konq);
var is_moz   = ((agt.indexOf('mozilla/5')!=-1) && (agt.indexOf('spoofer')==-1) &&
		(agt.indexOf('compatible')==-1) && (agt.indexOf('opera')==-1)  &&
		(agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)     &&
		((navigator.vendor=="")||(navigator.vendor=="Mozilla")));
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
		&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
		&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)
		&& (!is_khtml) && (!(is_moz)));
var is_nav5up = (is_nav && is_minor >= 5);
var is_ie   = ((iePos!=-1) && (!is_opera) && (!is_khtml));
var is_ie4   = (is_ie && is_major == 4);
var is_ie4up = (is_ie && is_minor >= 4);
var is_ie5up = (is_ie && is_minor >= 5);
var is_ie5_5up =(is_ie && is_minor >= 5.5);
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
if (is_mac) { is_win = !is_mac; }
var is_Flash        = false;
var is_FlashVersion = 0;
if ((is_nav||is_opera||is_moz)||is_safari||(is_mac&&is_ie5up)) {
var plugin = (navigator.mimeTypes &&
              navigator.mimeTypes["application/x-shockwave-flash"] &&
              navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ?
              navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if (plugin) {
   is_Flash = true;
   is_FlashVersion = parseInt(plugin.description.substring(plugin.description.indexOf(".")-1));}}
if (is_win&&is_ie4up){
      document.write(
         '<scr' + 'ipt language=VBScript>' + '\n' +
         'Dim hasPlayer, playerversion' + '\n' +
         'hasPlayer = false' + '\n' +
         'playerversion = 10' + '\n' +
         'Do While playerversion > 0' + '\n' +
            'On Error Resume Next' + '\n' +
            'hasPlayer = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & playerversion)))' + '\n' +
            'If hasPlayer = true Then Exit Do' + '\n' +
            'playerversion = playerversion - 1' + '\n' +
         'Loop' + '\n' +
         'is_FlashVersion = playerversion' + '\n' +
         'is_Flash = hasPlayer' + '\n' +
         '<\/sc' + 'ript>'
      );}
var isBestClient =  false;
if (is_ie5_5up&&(is_FlashVersion >=6)) {
	isBestClient = true;}

var isBestClientFlash =  false;
if (is_FlashVersion >=6) {
	isBestClientFlash = true;}
	
/* js redirect to superpage */
function spVerify(ftype){
	f = document.ypform;
	//alert(ftype);
	if(ftype=='wp'){
		f.action = "http://www.whitepages.com/15055/search/FindPerson";
		if((f.name.value=="")||(f.name.value==" ")){
			alert("Please enter a last name.");
			f.name.focus();
			return false;
		}
		ppAction(f);
		return false;
	}else if(ftype=='yp'){
		f.action = "http://yp.superpages.com/listings.phtml";
		if((f.C.value=="")||(f.C.value==" ")||(f.C.value=="Enter a category")||(f.C.value=="Enter a business name")){
			if(f.ZZ[0].checked){alert("Please enter a category.");}
			if(f.ZZ[1].checked){alert("Please enter a business name.");}
			f.C.focus();
			return false;
		}
		if(f.ys.selectedIndex==0){
			alert("Please select a state.");
			f.ys.focus();
			return false;
		}
		spAction(f);
		return false;
	}
}

function spAction(f){
//Changed the path to point to hte new one.
	var qs="http://yellowpages.superpages.com/listings.jsp?N="+(f.ZZ[0].checked?"":f.C.value)+"&C="+(f.ZZ[1].checked?"":f.C.value)+"&STYPE=S"+"&T="+(f.T.value==null?"":f.T.value)+"&S="+(f.ys.options[f.ys.selectedIndex].value==null?"":f.ys.options[f.ys.selectedIndex].value)+"&PG=L&R=N&SRC=verizon&search=Find+It";
	//alert(qs);
	//qs=escape(qs);
	//var w=window.open("/utilities/redirect/?ID=yellowpages&target="+qs,"spResult");
	var w=window.open(qs,"spResult");
	w.focus();
}

function ppAction(f){
	var loc="";
	if(f.wpT.value!="")loc=escape(f.wpT.value);
	if(f.ws.selectedIndex!=0){
		if(loc!="")loc+=",";
		//loc+=escape(f.ws.options[f.ws.selectedIndex].value);
		loc+=f.ws.options[f.ws.selectedIndex].value;
	}
	f.where.value=loc;
	var qs="?firstname="+f.firstname.value+"&name="+f.name.value+"&where="+f.where.value;
	//alert(loc);
	//var w=window.open("/utilities/redirect/?target="+escape(f.action+qs),"spResult");
	var w=window.open(f.action+qs,"spResult");
	w.focus();
}

function rnlAction(){
	f = document.ypform;
	//f.action = "http://yp.superpages.com/15055/search/ReversePhone";
	f.action = "http://www.whitepages.com/15055/search/ReversePhone";
	if(phoneFieldsValidate(f,f.A2,f.X3,f.P2)){
		f.phone.value=f.A2.value+"-"+f.X3.value+"-"+f.P2.value;
		qs=f.action+"?phone="+f.phone.value;
		//var w=window.open("/utilities/redirect/?target="+qs,"spResult");
		var w=window.open(qs,"spResult");
		w.focus();
		return false;
	}else{
		return false;
	}
}

/* js for phone validation and autotab */
function phoneFieldsValidate(frm,fld1,fld2,fld3,type) {

	errFld = "";
	errMsg = "";
	if( !type ) type="";
	else type=type+" ";
	if( !frm || !fld1 || !fld2 || !fld3 ) return false;

	if((fld3.value).length != 4 || !isIntPh(fld3.value))errFld=fld3;
	if((fld2.value).length != 3 || !isIntPh(fld2.value))errFld=fld2;
	if((fld1.value).length != 3 || !isIntPh(fld1.value))errFld=fld1;

	if(errFld!="") {
		alert("Please enter a complete "+type+"phone number using numbers only.");
		errFld.focus();
		errFld.select();
		return false;
	}
	return true;
}

function isBlankPh(val){if(val==null){return true;}for(var i=0;i<val.length;i++){if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}}return true;}
function isDigPh(num){if(num.length>1){return false;}var string="1234567890";if(string.indexOf(num)!=-1){return true;}return false;}
function isIntPh(val){if(isBlankPh(val)){return false;}for(var i=0;i<val.length;i++){if(!isDigPh(val.charAt(i))){return false;}}return true;}

function AutoTab( hItem, maxLength, linkItem, e ){

if(is_mac||(is_nav&&is_minor<5)){return;}else{var vKeyCode,oItem;oItem=eval('document.'+linkItem);
if(window.event||!e.which){key=e.keyCode;}else if(e){key=e.which;}
vKeyCode=key;if(vKeyCode==9&&e&&e.shiftKey){return;}
switch(vKeyCode){case 37:return;case 39:return;case 16:return;case 46:return;}
if (vKeyCode!=9){if(typeof(oItem)=="object"){if(bAutotab&&(String(oItem.value).length==0)&&(String(hItem.value).length==maxLength)&&(vKeyCode!=8)){oItem.focus();}}}}bAutotab=true;
}
var bAutotab=true;
function stopAutoTab(){bAutotab=false;}
