// Doubleclick html tag generator (javascript)

//*************** Global Variables ********//

// Global Variable: top_rand
// Random Number used throughout page (each ad uses same number)
var top_rand = (Math.random() * 10000000000000000) + "?";

// Global Variable: o_urlstring
var o_urlstring = document.URL;
o_urlstring = path(o_urlstring);
o_urlstring = replace(o_urlstring, "_");
if (o_urlstring.indexOf('?') != -1) {
	var temp1_url = o_urlstring.split('?');
	o_urlstring = temp1_url[0];
}

// Global Variable: db_sitename
var db_sitename = siten();

// Global Variable: urlArray
// break up o_urlstring into chunks according to "/"   	
var urlArray = new Array();
urlArray=o_urlstring.split('/');
var page=urlArray[urlArray.length-1];

// Global Variable: pgnm
// represents pagename
var pgnm;
if ((o_urlstring.indexOf(".pl") == -1) && (o_urlstring.indexOf(".html") == -1) && (o_urlstring.indexOf(".jsp") == -1))
  pgnm = "index";
else
  pgnm = page.substring(0, page.indexOf('.'));
  
// Global Variable: kwString
// generate the kw values for targeting purposes
var kwString;
var level;
if (urlArray[0] != -1) { 
  var name=urlArray[0].substring(0, urlArray[0].indexOf('.'));
  if (name.indexOf("findlaw") != -1)
	name = "www";
  kwString = ";area1=" + name;
  level = 0;

  //put the word "area*=" for as many array as we have.
  for (var i = 1; i < urlArray.length-1; i++) {
     kwString += ";area" + (i+1) + "=" + urlArray[i];
     level++;
  }
  kwString += ";level=" + level + ";pgnm=" + pgnm;
}

// Alleviates Netscape document.write bug (refresh problem)
NS4 = document.layers;
if (NS4) {
  origWidth = innerWidth;
  origHeight = innerHeight;
}

function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
  location.reload();
}

if (NS4) onresize=reDo;

//************** Functions Used to Generate Banner Ads **********//

// Function: top()
// Generate 468x60 banner ad html tags for FindLaw site
function top(t_urlstring){
var urli = "http://ad.doubleclick.net/adi/" + db_sitename + "/";
var urlj = "http://ad.doubleclick.net/adj/" + db_sitename + "/;abr=!webtv";

urli += kwString + ";sz=468x60;tile=1;ord=" + top_rand + '" width="468" height="60" frameborder="no" border="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no">';
urlj += kwString + ";sz=468x60;tile=1;ord=" + top_rand;

if (document.URL.indexOf("dir-dev.") != -1)
  document.write("<h2><font color=\"#990000\">TEST ENVIRONMENT</font></h2>");
else if (document.URL.indexOf("boards.") != -1) {
document.write('<table width="468" border="0" cellspacing="0" cellpadding="1">');
document.write('<form action="http://directory.findlaw.com/lawyer/lawyer_dir/search/jsp/stdSearch_process.jsp" method="GET" target="_top">');
document.write('<tr bgcolor="#000033"><td>');
document.write('<table width="327" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="10">');
document.write('<tr align="center"><td width="466" valign="middle" height="0" bgcolor="#FFFFFF"><a href="http://directory.findlaw.com" target="top"><img src="http://images.findlaw.com/ads/directory/468x60/top4.gif" width="466" height="23" border="0"></a></td></tr>');
document.write('<tr bgcolor="#f0f0f0"><td width="466" nowrap align="center">');
document.write('<input type=hidden name="target" value=FIRM>');
document.write('<input type="TEXT" name="city" size="20" maxlength="100" value="City or Zip">');
document.write('<select name="state">');
document.write('<option value="" selected>State</option>');
document.write('<option value="AL">AL </option>');
document.write('<option value="AK">AK </option>');
document.write('<option value="AS">AS </option>');
document.write('<option value="AZ">AZ </option>');
document.write('<option value="AR">AR </option>');
document.write('<option value="BC">BC </option>');
document.write('<option value="CA">CA </option>');
document.write('<option value="CO">CO </option>');
document.write('<option value="CT">CT </option>');
document.write('<option value="DE">DE </option>');
document.write('<option value="DC">DC </option>');
document.write('<option value="FL">FL </option>');
document.write('<option value="GA">GA </option>');
document.write('<option value="GU">GU </option>');
document.write('<option value="HI">HI </option>');
document.write('<option value="ID">ID </option>');
document.write('<option value="IL">IL </option>');
document.write('<option value="IN">IN </option>');
document.write('<option value="IA">IA </option>');
document.write('<option value="KS">KS </option>');
document.write('<option value="KY">KY </option>');
document.write('<option value="LA">LA </option>');
document.write('<option value="ME">ME </option>');
document.write('<option value="MB">MB </option>');
document.write('<option value="MD">MD </option>');
document.write('<option value="MA">MA </option>');
document.write('<option value="MI">MI </option>');
document.write('<option value="MN">MN </option>');
document.write('<option value="MS">MS </option>');
document.write('<option value="MO">MO </option>');
document.write('<option value="MT">MT </option>');
document.write('<option value="NE">NE </option>');
document.write('<option value="NV">NV </option>');
document.write('<option value="NB">NB </option>');
document.write('<option value="NH">NH </option>');
document.write('<option value="NJ">NJ </option>');
document.write('<option value="NM">NM </option>');
document.write('<option value="NY">NY </option>');
document.write('<option value="NF">NF </option>');
document.write('<option value="NC">NC </option>');
document.write('<option value="ND">ND </option>');
document.write('<option value="OH">OH </option>');
document.write('<option value="OK">OK </option>');
document.write('<option value="ON">ON </option>');
document.write('<option value="OR">OR </option>');
document.write('<option value="PA">PA </option>');
document.write('<option value="PR">PR </option>');
document.write('<option value="RI">RI </option>');
document.write('<option value="SC">SC </option>');
document.write('<option value="SD">SD </option>');
document.write('<option value="TN">TN </option>');
document.write('<option value="TX">TX </option>');
document.write('<option value="UT">UT </option>');
document.write('<option value="VT">VT </option>');
document.write('<option value="VI">VI</option>');
document.write('<option value="VA">VA </option>');
document.write('<option value="WA">WA </option>');
document.write('<option value="WV">WV </option>');
document.write('<option value="WI">WI </option>');
document.write('<option value="WY">WY </option>');
document.write('</select>');
document.write('<select name="practice" size="1">');
document.write('<option>Practice Area</option>');
document.write('<option value="FL07">Bankruptcy</option>');
document.write('<option value="FL08">Business Law</option>');
document.write('<option value="FL14">Criminal Law</option>');
document.write('<option value="FL2406">Divorce</option>');
document.write('<option value="FL1402">DUI/DWI</option>');
document.write('<option value="FL17">Employment Law</option>');
document.write('<option value="FL22">Estate Planning</option>');
document.write('<option value="FL24">Family Law</option>');
document.write('<OPTION value=FL29>Immigration Law</option>');
document.write('<OPTION value=FL38>Injury - Defense</option>');
document.write('<OPTION value=FL39>Injury - Plaintiff</option>');
document.write('<OPTION value=FL30>Insurance Law');
document.write('<OPTION value=FL31>IP/Patent Law');
document.write('<OPTION value=FL0809>Lemon Law');
document.write('<OPTION value=FL4203>Med. Malpractice</option>');
document.write('<OPTION value=FL43>Real Estate Law');
document.write('<OPTION value=FL45>Securities Law');
document.write('<OPTION value=FL47>Tax Law');
document.write('<OPTION value=FL50>Workers\' Comp</option>');
document.write('<option value="">Other</option>');
document.write('</select>');
document.write('<input type="submit" value="Search" name="submit" border="0">');
document.write('</td></tr>');
document.write('<tr bgcolor="#f0f0f0">');
document.write('<td width="466" nowrap align="center" bgcolor="#ADADAD"><img src="http://images.findlaw.com/ads/directory/468x60/bottom.gif" width="466" height="12"></td>');
document.write('</tr></table></td></tr></form></table>');
}
else {
   // print out the doubleclick html tags
   document.write("<!--top 468x60 banner ad-->\n");
   document.write('<script language="Javascript1.1" src="' + urlj + '"><\/script>');
   document.write("<!--end top 468x60 banner ad-->\n");
}
}

// Function middle()
// Generate 120x240 Banner Ad for FindLaw site Excluding Search
function middle(t_urlstring){ 
var urli = "http://ad.doubleclick.net/adi/" + db_sitename + "/";
var urlj = "http://ad.doubleclick.net/adj/" + db_sitename + "/;abr=!webtv";

urli += kwString + ";sz=120x240;tile=3;ord=" + top_rand + '" width="120" height="240" frameborder="no" border="0" MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no">';
urlj += kwString + ";sz=120x240;tile=3;ord=" + top_rand;

document.write("<!--This is for the middle right 120x240 ad call-->");
document.write('<script language="Javascript1.1" src="' + urlj + '"><\/script>');
document.write("<!--end middle right 120x240 ad call-->");
}

// Function ad_pos()
// Call appropriate function to generate 120x90 banner ad
function ad_pos(t_urlstring, position){

}

//************** Helper Functions **********//

// Helper Function: path
// strip out 'http://' and convert to lowercase
function path(urlstring)
{
   urlstring = urlstring.toLowerCase();
   var start = urlstring.indexOf('//');
   if (start != -1) {
      start = start+2;   
      //delete the "http://"
      urlstring = urlstring.substring(start, urlstring.length);
   }
   return urlstring;
}

// Helper Function: replace
// strip out t's from s (string)
function replace(s, t) 
{
	i = s.indexOf(t);
	r = "";
	if (i == -1) return s;
	r += s.substring(0,i) + '';
	if ( i + t.length < s.length)
  		r += replace(s.substring(i+t.length, s.length), t, '');
	return r;
}

// Helper Function: siten
// determine DART sitename
function siten()
{
if (o_urlstring.indexOf("pub.findlaw.") != -1)
  return "fl.public.dart";
else if (o_urlstring.indexOf("sites=pubs") != -1)
  return "fl.public.dart";
else if (o_urlstring.indexOf("biz.findlaw.") != -1)
  return "fl.smallbiz.dart";
else if (o_urlstring.indexOf("stu.findlaw.") != -1)
  return "fl.students.dart";
else if (o_urlstring.indexOf("news.findlaw.") != -1)
  return "fl.news.dart";
else
  return "fl.legal.dart";
}

// Helper Function for Justicemail Firmsite Ad
function surfto(form) {
        var myindex=form.select1.selectedIndex
        if (form.select1.options[myindex].value != "0") {
                window.top.location=form.select1.options[myindex].value;}
}

function QueryString(key)
{
    var value = null;
    for (var i=0;i<QueryString.keys.length;i++)
    {
        if (QueryString.keys[i]==key)
        {
            value = QueryString.values[i];
            break;
        }
    }
    return value;
}

QueryString.keys = new Array();
QueryString.values = new Array();

function QueryString_Parse()
{
    var query = window.location.search.substring(1);
	query = query.toLowerCase();
    var pairs = query.split("&");

    for (var i=0;i<pairs.length;i++)
    {
        var pos = pairs[i].indexOf('=');
        if (pos >= 0)
        {
            var argname = pairs[i].substring(0,pos);
            var value = pairs[i].substring(pos+1);
            QueryString.keys[QueryString.keys.length] = argname;
            QueryString.values[QueryString.values.length] = value;
        }
    }

}
QueryString_Parse();
