
var http = createRequestObject();

function step(stepNum, noStep) {
	if (stepNum == '0') {
		if (document.getElementById('step3')) {
			document.getElementById('step3').style.display = 'none';
		}
	}
	if (stepNum == '2') {
		if (document.getElementById('step1')) {
			document.getElementById('step1').style.display = 'none';
		}
		if (document.getElementById('step2')) {
			document.getElementById('step2').style.display = 'inline';
		}
	}
	if (stepNum == '3') {
		if (document.getElementById('step3')) {
			document.getElementById('step3').style.display = 'inline';
		}
		if (document.getElementById('step2')) {
			document.getElementById('step2').style.display = 'none';
		}
		
	}
}
function sndBG(idName) {
  var headers = new Array(); 
  var oExpr = /^\d*_color/g;
  headers = document.getElementsByTagName("DIV");
  for (i=0; i < headers.length; i++) {
    if (headers[i].id.search(idName+'_color') != -1) { 
      headers[i].setAttribute('style','background:url(http://www.homefind.com/images/arrows.gif) no-repeat center right;');
    } else if (headers[i].id.match(oExpr)) { 
      headers[i].setAttribute('style','background-image: none;');
    }
  }
}
function sndShow(idName) {
  if (idName == 'details') {
    document.getElementById('resultCol').width = '320';
    document.getElementById('detailCol').width = '438';
  }
  document.getElementById(idName).style.display = 'block';
} 
function sndHide(idName) {
  document.getElementById(idName).style.display = 'none';
} 
function sndTabState(idName) {
  if (idName == 'mMenu') {
    document.getElementById('searchBox').style.display = 'none';
    document.getElementById('mMenu').className = 'mActive';
    document.getElementById('sMenu').className = 'inactive';
    document.getElementById('hMenu').className = 'inactive';
    document.getElementById('bMenu').className = 'inactive';
    document.getElementById('pMenu').className = 'inactive';
    try {
      i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right";
    } catch (ex) {
      //
    }
  } else if (idName == 'hMenu') {
    document.getElementById('searchBox').style.display = 'none';
    document.getElementById('mMenu').className = 'inactive';
    document.getElementById('sMenu').className = 'inactive';
    document.getElementById('hMenu').className = 'hActive';
    document.getElementById('bMenu').className = 'inactive';
    document.getElementById('pMenu').className = 'inactive';
    try {
      i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right";
    } catch (ex) {
      //
    }
  } else if (idName == 'bMenu') {
    document.getElementById('searchBox').style.display = 'none';
    document.getElementById('mMenu').className = 'inactive';
    document.getElementById('sMenu').className = 'inactive';
    document.getElementById('hMenu').className = 'inactive';
    document.getElementById('bMenu').className = 'hActive';
    document.getElementById('pMenu').className = 'inactive';
    try {
      i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right&broker=1";
    } catch (ex) {
      //
    }
  } else if (idName == 'pMenu') {
    document.getElementById('searchBox').style.display = 'none';
    document.getElementById('mMenu').className = 'inactive';
    document.getElementById('sMenu').className = 'inactive';
    document.getElementById('hMenu').className = 'inactive';
    document.getElementById('bMenu').className = 'inactive';
    document.getElementById('pMenu').className = 'hActive';
    try {
      i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right";
    } catch (ex) {
      //
    }
  } else if (idName == 'none') {
  	document.getElementById('searchBox').style.display = 'none';
    document.getElementById('mMenu').className = 'inactive';
    document.getElementById('sMenu').className = 'inactive';
    document.getElementById('hMenu').className = 'inactive';
    document.getElementById('bMenu').className = 'inactive';
    document.getElementById('pMenu').className = 'inactive';
    try {
      i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right";
    } catch (ex) {
      //
    }
  } else {
    document.getElementById('searchBox').style.display = 'block';
    document.getElementById('mMenu').className = 'inactive';
    document.getElementById('sMenu').className = 'sActive';
    document.getElementById('hMenu').className = 'inactive';
    document.getElementById('bMenu').className = 'inactive';
    document.getElementById('pMenu').className = 'inactive';
    try {
      i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right";
    } catch (ex) {
      //
    }
  }
}
function sndTab(idName) {
  if (!document.getElementById('my_link')) { 
    return; 
  } else if (idName == 'my_tab') {
    document.getElementById('se_tab').className = 'inactive';
    document.getElementById('results').style.display = 'none';
    document.getElementById('my_tab').className = 'active';
    document.getElementById('my_results').style.display = 'block';
  } else {
    document.getElementById('se_tab').className = 'active';
    document.getElementById('results').style.display = 'block';
    document.getElementById('my_tab').className = 'inactive';
    document.getElementById('my_results').style.display = 'none';
  }
}
function sndReq(action,data,pass) {
    http.open('get', '/ajax/rpc.bg?action='+action+'&data='+data+'&pass='+pass+"&ms="+new Date().getTime());
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function sndFirmReq(action,data,firmid,pass) {
    http.open('get', '/ajax/rpc.bg?action='+action+'&data='+data+'&firm='+firmid+'&pass='+pass+"&ms="+new Date().getTime());
    http.onreadystatechange = handleResponse;
    http.send(null);
}
function sndClass(idName,cName) {
  document.getElementById(idName).className = cName;
}
function sndColor(idName,color) {
  document.getElementById(idName).bgColor = escape(color);
}
function sndRes(action,state,type,city,recordNum,sortOrder) {
//  alert(action);
  if (action == 'saved') {
    http.open('get', '/ajax/rpcAdvResults.bg?action='+action+"&ms="+new Date().getTime());//rpcRes_switch
  } else {
    http.open('get', '/ajax/rpcAdvResults.bg?action='+action+'&state='+state+'&type='+type+city+'&recordNum='+recordNum+'&sortOrder='+sortOrder+"&ms="+new Date().getTime());//rpcRes_switch
  }
  http.onreadystatechange = handleResponse;
  http.send(null);
}
function sndMinMax(action,idName,idTarget) {
  var l = document.getElementById(idName);
  if (action == 'minimize') {
    l.innerHTML = '<img border=0 src=http://www.homefind.com/images/maximize.jpg>';
    l.href = 'javascript:sndMinMax(\'maximize\',\''+idName+'\',\''+idTarget+'\');';
    document.getElementById(idTarget).style.display = 'none';
  } else {
    l.innerHTML = '<img border=0 src=http://www.homefind.com/images/minimize.jpg>';
    l.href = 'javascript:sndMinMax(\'minimize\',\''+idName+'\',\''+idTarget+'\');';
    document.getElementById(idTarget).style.display = 'block';
  }
}
function sndDirect(url) {
    http.open('get', url);
    http.onreadystatechange = handleResponse;
    try { http.send(null); } catch(err) { return; }
}
function sndBoxPostDirect(rURL,post) {
  if (rURL.indexOf("?") == -1) {
    http.open('post', rURL+"?ms="+new Date().getTime());
  } else {
    http.open('post', rURL+"&ms="+new Date().getTime());
  }
  sndBoxLoad("on");
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  http.onreadystatechange = boxHandleResponse;
  try { http.send(post); } catch(err) { return; }
}
function sndlBoxPostDirect(rURL,post) {
  if (rURL.indexOf("?") == -1) {
    http.open('post', rURL+"?ms="+new Date().getTime());
  } else {
    http.open('post', rURL+"&ms="+new Date().getTime());
  }
  sndBoxLoad("on");
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  http.onreadystatechange = largeBoxHandleResponse;
  try { http.send(post); } catch(err) { return; }
}
function sndBoxLoad(trig) {
  var loadingBox = document.getElementById('mboxLoad');
  try {
    switch (trig){
      case "on":
        loadingBox.style.display = 'block';
        break;
      case "off":
        loadingBox.style.display = 'none';
        break;
    }
  } catch(ex) {
    return;
  }
}

function sndPostDirect(rURL,post) {
	if (rURL.indexOf("?") == -1) {
    http.open('post', rURL+"?ms="+new Date().getTime());
  } else {
  	http.open('post', rURL+"&ms="+new Date().getTime());
  }
  http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  http.onreadystatechange = handleResponse;
  try { http.send(post); } catch(err) { return; }
}
function sndClose(idName) {
  document.getElementById(idName).innerHTML = '';
}
function sndOpen(idName,data) {
  if (!document.getElementById(idName)) {
    alert('Still loading...');
  } else {
    document.getElementById(idName).innerHTML = data;
  }

}
function sndLoad(idName) {
	try
	{
		document.getElementById(idName).innerHTML = '<table width=100% cellpadding=0 cellspacing=0 border=0><tr><td align=center><img src=http://www.homefind.com/images/loading.gif></td></tr></table>';
	}
	catch(ex)
	{

	}
}
function handleResponse() {
  if (http.readyState == 4){
    var response = http.responseText;
    var update = new Array();

    if(response.indexOf('|||' != -1)) {
      update = response.split('|||');
      if (update[2] == 'alert') {
        alert('>>>'+update[0]+'>>>'+update[2]+'>>>'+update[1]);
      }
      if (update[0] == 'redirect') {
        window.location = update[1];
      } else {
        if (!document.getElementById(update[0])) { return; } 
                                            else { document.getElementById(update[0]).innerHTML = update[1]; }
      }
    }
  }
}
function boxHandleResponse() {
  if (http.readyState == 4){
    var response = http.responseText;
    var update = new Array();

    if(response.indexOf('|||' != -1)) {
      update = response.split('|||');
      if (update[2] == 'alert') {
        alert('>>>'+update[0]+'>>>'+update[2]+'>>>'+update[1]);
      }
      if (update[0] == 'redirect') {
        window.location = update[1];
      } else {
        sndBoxLoad("off");
        if (!document.getElementById(update[0])) { return; } 
                                            else { document.getElementById(update[0]).innerHTML = update[1]; sm('box',400,400); }
      }
    }
  }
}
function largeBoxHandleResponse() {
  if (http.readyState == 4){
    var response = http.responseText;
    var update = new Array();

    if(response.indexOf('|||' != -1)) {
      update = response.split('|||');
      if (update[2] == 'alert') {
        alert('>>>'+update[0]+'>>>'+update[2]+'>>>'+update[1]);
      }
      if (update[0] == 'redirect') {
        window.location = update[1];
      } else {
        sndBoxLoad("off");
        if (!document.getElementById(update[0])) { return; } 
                                            else { document.getElementById(update[0]).innerHTML = update[1]; sm('box',400,500); }
      }
    }
  }
}

function loopRadio(temp) {
  for (i=0; i < 4; i++) {
    if (!document.getElementById(temp+'_'+i)) { break; }
    if (document.getElementById(temp+'_'+i).checked) {
      return(document.getElementById(temp+'_'+i).value);
      break;
    }
  }
}

function loopSelStr(temp) {
  var selectedArray = new Array();
  var selObj = document.getElementById(temp);
  var i;
  var count = 0;
  var qString = '';

  if (selObj) {
    for (i=0; i < selObj.options.length; i++) {
      if (selObj.options[i].selected) {
        selectedArray[count] = selObj.options[i].value;
        count++;
      }
    }
    if (selectedArray.length != 0) {       // no cities selected
      qString = selectedArray.join(",");
    }
  }
  return qString;
}
function loopSelected(temp) {
  var selectedArray = new Array();
  var selObj = document.getElementById(temp);
  var i; 
  var h = 75;
  var count = 0;
  var qString = '';
  
  if (!selObj) { 
    qString = qString+'&city[]=NULL';
  } else {
    for (i=0; i < selObj.options.length; i++) {
      if (selObj.options[i].selected) {
        selectedArray[count] = selObj.options[i].value;
        count++;
      }
    }
    if (selectedArray.length == 0) {       // no cities selected
      qString = qString+'&city[]=NULL';
    } else if (h < selectedArray.length) { // too many cities
      qString = qString+'&city[]=OVERFLOW';
    } else {
      for (var j = 0; j < selectedArray.length; j++) {
        qString = qString+'&city[]='+selectedArray[j];
      }
    }
  }
  return qString;
}
function sndAction(url,name,value) {
  window.location = url + '?' + name + '=' + value;
}
function sndUrlDirect(url) {
  window.location = url;
}

function brokerAd(x) {
//  try {
    switch (x) {
      case 'on': 
        i_right.document.location = "http://www.homefind.com/processAd.bg?broker=1&position=Right";
	setTimeout("brokerAd('off')", 300000);
	break
      case 'off':
        i_right.document.location = "http://www.homefind.com/processAd.bg?position=Right";
        break
    }
//  } catch (ex) {
    //
//  }
}
