//Search forms JavaScript
//07/02/2003 by DR
//SuperPages.com

var spbck = document.cookie;

function lastCookie(){
var lastCS = getCookie("SPC_LQ");
var lastC="";
var lastZ="";
var lastS="";
var location="";
var undefined;
if (lastCS != null){
//alert(lastCS);
	var lCS = lastCS.split("|");
		lastC = lCS[0];
		lastC = lastC.replace(/\+/g," ");
		lastS = lCS[1];
		lastZ = lCS[2];
		if ( lastZ == undefined ) lastZ = "";
		location = lastC + " " + lastS + " " +  lastZ; 
		document.ypform.L.value = location;
		//document.ypform.L.value = lastS;
	}
}

function reRoute(anchor,section) {
	if (anchor.href.indexOf("log_redirect2") == -1) {
		anchor.href = "http://www.superpages.com/cgi-bin/log_redirect2.cgi?" + anchor.href + section;
	}
	//self.location=anchor.href;
	//window.open(anchor.href);
    return true;
}

function getCookie(name) { // use: getCookie("name");
   	var index = spbck.indexOf(name + "=");
    if (index == -1) return null;
    index = spbck.indexOf("=", index) + 1;
    var endstr = spbck.indexOf(";", index);
    if (endstr == -1) endstr = spbck.length;
    return unescape(spbck.substring(index, endstr));
}
  
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days
	
function setCookie(name, value) { // use: setCookie("name", value);
   var argv = setCookie.arguments;  
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
    if (value != null && value != "")
     // document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
     document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString()));
	 
	  spbck= document.cookie; // update 
}
  
function buildURL(arg_stype) {
 
  if (
      ((navigator.appName == "Netscape") || (navigator.appName == "Microsoft Internet Explorer")) && 
      (parseFloat(navigator.appVersion) >= 3.0) && (document.ypform || document.hiddenform))
	   {
    if(document.ypform) {
       var form_stype= (document.ypform.STYPE)?escape(document.ypform.STYPE.value):((document.hiddenform.STYPE)?escape(document.hiddenform.STYPE.value):"");
       var src= (document.ypform.SRC)?escape(document.ypform.SRC.value):((document.hiddenform.SRC)?escape(document.hiddenform.SRC.value):"");
       var cb= (document.ypform.CB)?escape(document.ypform.CB.value):((document.hiddenform.CB)?escape(document.hiddenform.CB.value):"");
       var cat= (document.ypform.C)?escape(document.ypform.C.value):((document.hiddenform.C)?escape(document.hiddenform.C.value):"");
       var name= (document.ypform.N)?escape(document.ypform.N.value):((document.hiddenform.N)?escape(document.hiddenform.N.value):"");
		var location= (document.ypform.L)?escape(document.ypform.L.value):((document.hiddenform.L)?escape(document.hiddenform.L.value):"");
       var areacode = (document.phoneform)?escape(document.phoneform.A.value):((document.ypform.A)?escape(document.ypform.A.value):((document.hiddenform)?escape(document.hiddenform.A.value):""));
       var exchange = (document.phoneform)?escape(document.phoneform.X.value):((document.ypform.X)?escape(document.ypform.X.value):((document.hiddenform)?escape(document.hiddenform.X.value):""));
       var phoneline = (document.phoneform)?escape(document.phoneform.P.value):((document.ypform.P)?escape(document.ypform.P.value):((document.hiddenform)?escape(document.hiddenform.P.value):""));
       var pagesize= (document.ypform.PS)?escape(document.ypform.PS.options[document.ypform.PS.selectedIndex].value):((document.hiddenform.PS)?escape(document.hiddenform.PS.value):"");
       var resultradius= (document.ypform.RR)?escape(document.ypform.RR.options[document.ypform.RR.selectedIndex].value):((document.hiddenform.RR)?escape(document.hiddenform.RR.value):"");

       var starting_point= "";
       if(document.ypform.AL) {
         var num=document.ypform.AL.length;
         for(var i = 0; i < num; i++) {
            if(document.ypform.AL[i].checked) {
               starting_point = document.ypform.AL[i].value;
            }
         }
       } else {
         starting_point= (document.hiddenform.AL)?escape(document.hiddenform.AL.value):"";
       }

       var street="";
       var city="";
       var zip="";
       var state="";
       if(starting_point != "" && document.ypform.AL){
          street=(document.hiddenform.E)?escape(document.hiddenform.E.value):"";
          city=(document.hiddenform.T)?escape(document.hiddenform.T.value):"";
          zip=(document.hiddenform.Z)?escape(document.hiddenform.Z.value):"";
          state=(document.hiddenform.S)?escape(document.hiddenform.S.value):"";
       } else {
          street=(document.ypform.E)?escape(document.ypform.E.value):((document.ypform.RE)?escape(document.ypform.RE.value):((document.ypform.streetaddress)?escape(document.ypform.streetaddress.value):((document.hiddenform.E)?escape(document.hiddenform.E.value):"")));
          city=(document.ypform.T)?escape(document.ypform.T.value):((document.ypform.RT)?escape(document.ypform.RT.value):((document.ypform.city)?escape(document.ypform.city.value):((document.hiddenform.T)?escape(document.hiddenform.T.value):"")));
          zip=(document.ypform.Z)?escape(document.ypform.Z.value):((document.ypform.RZ)?escape(document.ypform.RZ.value):((document.ypform.zip)?escape(document.ypform.zip.value):((document.hiddenform.Z)?escape(document.hiddenform.Z.value):"")));
          if(document.ypform.S) {
             if(document.ypform.S.options) {
             // selection list
               state = escape(document.ypform.S.options[document.ypform.S.selectedIndex].value);
             } else {
               state = escape(document.ypform.S.value);
             }
          } else if(document.ypform.RS) {
             if(document.ypform.RS.options) {
             // selection list
                state = escape(document.ypform.RS.options[document.ypform.RS.selectedIndex].value);
             } else {
                state = escape(document.ypform.RS.value);
             }
          } else if(document.ypform.state) {
             state = escape(document.ypform.state.value);
          } else if(document.hiddenform.S) {
             state = escape(document.hiddenform.S.value);
          }
       }
       
       var sort= "";
       if(document.ypform.R) {
         var num=document.ypform.R.length;
         for(var i = 0; i < num; i++) {
            if(document.ypform.R[i].checked) {
               sort = document.ypform.R[i].value;
            }
         }
       } else {
         sort= (document.hiddenform.R)?escape(document.hiddenform.R.value):"";
       }
    } else if(document.hiddenform) {
       var form_stype= escape(document.hiddenform.STYPE.value);
       var src = escape(document.hiddenform.SRC.value);
       var cb = escape(document.hiddenform.CB.value);
       var cat = escape(document.hiddenform.C.value);
       var name = escape(document.hiddenform.N.value);
       var street = escape(document.hiddenform.E.value);
       var city = escape(document.hiddenform.T.value);
       var zip = escape(document.hiddenform.Z.value);
       var areacode = escape(document.hiddenform.A.value);
       var exchange = escape(document.hiddenform.X.value);
       var phoneline = escape(document.hiddenform.P.value);
       var state = escape(document.hiddenform.S.value);
       var starting_point= escape(document.hiddenform.AL.value);
       var sort= escape(document.hiddenform.R.value);
       var pagesize= escape(document.hiddenform.PS.value);
       var resultradius= escape(document.hiddenform.RR.value);
    }
    if (arg_stype == "" && form_stype != "") {
       var stype = form_stype;
    } else {
       var stype = arg_stype;
    }
         
    var str="?SRC="+src+"&STYPE="+stype+"&CB="+cb+"&L="+location+"&C="+cat+"&N="+name+"&A="+areacode+"&X="+exchange+"&P="+phoneline+"&AL="+starting_point+"&R="+sort+"&PS="+pagesize+"&RR="+resultradius;
	
     if (stype == "D") {
      str += "&RE="+street+"&RT="+city+"&RS="+state+"&RZ="+zip+"&";
    } else {
      str += "&E="+street+"&T="+city+"&S="+state+"&Z="+zip+"&";
    }
  } else { 
    var str="?SRC=&#38;STYPE=S&#38;PG=L&#38;R=N&#38;C=&#38;N=&#38;T=&#38;S="
  }
  return str;
}
// Keyword to string
function kURL(arg_stype) {
	 if (
      ((navigator.appName == "Netscape") || (navigator.appName == "Microsoft Internet Explorer")) && 
      (parseFloat(navigator.appVersion) >= 3.0) && (document.ypform || document.hiddenform))
	   {
	if(document.ypform) {
	var cat= (document.ypform.C)?escape(document.ypform.C.value):((document.hiddenform.C)?escape(document.hiddenform.C.value):"");
	var src= (document.ypform.SRC)?escape(document.ypform.SRC.value):((document.hiddenform.SRC)?escape(document.hiddenform.SRC.value):"");
}	
	var location= (document.ypform.L)?escape(document.ypform.L.value):((document.hiddenform.L)?escape(document.hiddenform.L.value):"");
	var stype = arg_stype;
	var str = "";
	var q = "\?";
	 if(src != null && src != ""){ str="?SRC="+src; q="&";}
	 if (stype == "all") { str += q + "C="+cat+"&L="+location; } //add location and keyword to SRC
	 if (stype == "prod") { str += q + "search=Find+It"; }
	 if (stype == "kw" ) { if( cat != null && cat != "" ){ str += q + "C="+cat; }}
	return str;

  }
}
//  End -->