function gqv(variable) { 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
return '';
} 

function gxs(){
  var openx_section = '';
  var spans = document.getElementsByTagName('span');
  for (i in spans) {
    if (spans[i].className == "path") {
        // Iterate through the nested HTML to find what we need
        var children = spans[i].getElementsByTagName('a');
        // Get the current "level"
	if (children.length > 2){
	  var openx_section = children[2].innerHTML + "_";
	  var i_children = spans[i].getElementsByTagName('i');
	  for (j in i_children)
	    if (i_children[j].innerHTML)
	      openx_section += i_children[j].innerHTML + ", ";
	}
    }
  }
  return openx_section;
}

function getSelectValue(selectBox){
  var v = "";
  var dropdowns = document.getElementsByTagName('select');
  for(dd in dropdowns) {
    var dd_name = dropdowns[dd].name;
    if (dd_name && dd_name.match(selectBox + "$"))
      v = dropdowns[dd][dropdowns[dd].selectedIndex].value;
  }
  return v;
}

function getCatPath(type){
  var page = window.location.pathname;
  var out = '';
  if (page.match('AutoMoto'))
    out = '&cat=a';
  else if (page.match('Business'))
    out = '&cat=b';
  else if (page.match('RealEstateSimple'))
    out = '&cat=rs';
  else if (page.match('RealEstate'))
    out = '&cat=r';
  else if (page.match('Skafi'))
    out = '&cat=s';
  if (type == 'escaped')
    return escape(out);
  else
    return out;
}

function getCurrentPage(){
  return document.getElementById('ctl00_ctl00_hdnPageNumber').value;
}

function dispImgBanner(file, target, agentId){
  var html = '';
  var url = '';
  if (target == '')
    url = 'AgentResults.aspx?AgntId=' + agentId + '&catId=' + gqv('catId') + '&pageSize=' + getSelectValue('ddlPages') + '&SC_GUID=' + gqv('SC_GUID') + getCatPath('') + '&currentPage=' + getCurrentPage();
  else
    url = target;
  html += '<a href="' + url + '">';
  html += '<img src="' + file + '" border="0" />';
  html += '</a>';
  return html;
}

function disp550Banner(file, agentId){

  var html = '';
  html += '<object width="550" height="90">';
  html += '<param name="wmode" value="opaque" />';
  html += '<param name="movie" value="' + file + '">';
  html += '<param name="flashvars" value="catId=' + gqv('catId') + '&AGENT_URL=AgentResults.aspx%3fAgntId%3d' + agentId + '%26catId%3d' + gqv('catId') + '%26pageSize%3d' + getSelectValue('ddlPages') + '%26SC_GUID%3d' + gqv('SC_GUID') + getCatPath('escaped') + '%26currentPage%3d' + getCurrentPage() + '">';
  html += '<embed src="' + file + '" flashvars="catId=' + gqv('catId') + '&AGENT_URL=AgentResults.aspx%3fAgntId%3d' + agentId + '%26catId%3d' + gqv('catId') + '%26pageSize%3d' + getSelectValue('ddlPages') + '%26SC_GUID%3d' + gqv('SC_GUID')  + getCatPath('escaped') + '%26currentPage%3d' + getCurrentPage() + '" width="550" height="90" wmode="opaque">';
  html += '</embed>';
  html += '</object>';
  return html;
}

function disp175Banner(file, agentId){

  var html = '';
  html += '<object width="175" height="300">';
  html += '<param name="wmode" value="opaque" />';
  html += '<param name="movie" value="' + file + '">';
  html += '<param name="flashvars" value="catId=' + gqv('catId') + '&AGENT_URL=AgentResults.aspx%3fAgntId%3d' + agentId + '%26catId%3d' + gqv('catId') + '%26pageSize%3d' + getSelectValue('ddlPages') + '%26SC_GUID%3d' + gqv('SC_GUID') + getCatPath('escaped') + '%26currentPage%3d' + getCurrentPage() + '">';
  html += '<embed src="' + file + '" flashvars="catId=' + gqv('catId') + '&AGENT_URL=AgentResults.aspx%3fAgntId%3d' + agentId + '%26catId%3d' + gqv('catId') + '%26pageSize%3d' + getSelectValue('ddlPages') + '%26SC_GUID%3d' + gqv('SC_GUID') + getCatPath('escaped') + '%26currentPage%3d' + getCurrentPage() + '" width="175" height="300" wmode="opaque">';
  html += '</embed>';
  html += '</object>';
  return html;
}


