function goState(URL, g, o)
{
	var URL = URL.options[URL.selectedIndex].value;
	URL = "/go.d/s--"+URL+"/g--"+g+"/o--"+o;
  window.location.href = URL;
}

function goStateButton(s, l)
{
	var URL = s.options[s.selectedIndex].value;
	URL = "/go.d/s--"+URL+"/location--"+l;
  window.location.href = URL;
}

function goCounty(pl, s, c, l, n, win)
{
	if(win)
  	return false;
    
  cc = "USA";

	if(typeof c == 'object')
	{
		if(c.options)
			c = c.options[c.selectedIndex].value;
		else
		{
			var muni = c[1];
			c = c[0];
		}
	}
	q = (l ? "location="+l+"&" : "")+(n ? "next="+n+"&" : "")+(muni ? "muni="+muni+"&" : "");
  
  URL = (pl ? pl : "")+(cc ? "/"+cc : "")+(s ? "/"+s : "")+(c ? "/"+ucwords(c) : "")+"/go.php"+(q ? "?"+q : "");
  if(win)
  	window.open(win);
  else
	  window.location.href = URL;
  return true;
}

function goEdit(action, s, c, id, q, n)
{
	cc = "USA";
	s = getObject(s);
  s = s.value;
  if(c)
  {
    c = getObject(c);
    c = c.value;
  }

 	base_url = "";
  if(!pl_using_url)
   	base_url += "/"+current_pl;

  URL = base_url+(cc ? "/"+cc : "")+(s ? "/"+s : "")+(c ? "/"+c : "")+action+(q ? "?"+q : "");
  if(n)
  	window.parent.location.href = URL;
  else
		window.location.href = URL;
	if(id)
		getObject(id).disabled = 'disabled';
}

function goAffiliate(p, s, c, id, q, check)
{
	p = document.getElementById(p);
  p = p.options[p.selectedIndex].value;
	s = document.getElementById(s);
  s = s.options[s.selectedIndex].value;
  c = document.getElementById(c);
  c = c.options[c.selectedIndex].value;  
  
  var regexp = /.*\?.*/;
  if(current_pl_url)
	  base_url = "http://"+current_pl_url;
  else if(current_pl)
  	base_url = "/"+current_pl;
  else
  	base_url = "";
  URL = base_url+p+(regexp.exec(p) ? "&" : "?")+"s="+s+"&c="+c+(q ? "&"+q : "");
  if(p && p != 'header' && s && c)
  {
	  window.location.href = URL;
    document.getElementById(id).disabled = 'disabled';
    document.getElementById(id).value = 'Please Wait ...';
  }
  else if(check)
  {
  	if(p == 'header')
    	alert("The action you selected is only a group heading.\n\nPlease select one of the sub-options.");
    else
    {
    	if(!p)
      	msg = "an action";
      else if(!s)
      	msg = "a state";
      else if (!c)
      	msg = "a county";
    	alert("Please select "+msg+" to edit.");
    }
  }
}

function goSwitch(loc, e)
{
	var ctrlPressed=0;
  if(is_ie4up)
    ctrlPressed = event.ctrlKey;
  
  if(ctrlPressed)
  	window.open(loc);
  else  
		window.location.href=loc;
}

function changeTemplate(URL, obj)
{
	window.location.href = URL+obj.options[obj.selectedIndex].value;
}

function go(loc)
{
	window.location.href=loc;
}

function goThis(obj, loc)
{
	source=event.srcElement;
  fTag = obj.tagName;
	if(fTag == "TABLE" || fTag == "TR")
  	fTag = "TD";
	if(source.tagName != fTag)
		return;
	
	window.location.href=loc;
}

function goLoginContact(logged_in)
{
	if(logged_in)
  {
		alert("All correspondence is now being processed through the Client Message Manager.\n\nPlease click OK to be forwarded.");
  	window.location.href="clients/clients.php?p=contact&action=send";
  }
  else
  {
  	alert("All correspondence is now being processed through the Client Message Manager.\n\nPlease click OK to be forwarded and then login.");
  	window.location.href="clients/clients.php?next="+URLEncode("clients/clients.php?p=contact&action=send");
  }
}

function openNewOpenerWindow(loc)
{
	if(window.opener)
		window.opener.open(loc);
  else
  	window.open(loc);
}

function loginAsClientURL(url, user, r)
{
	window.open("http://www.listingcheckout.com/actions.php?login=true&user="+user+"&return="+URLEncode(url+"/actions.php?login=true&user="+user+"&return="+r));
}
