var timeout_ID = null;

// Popup layer

var isIE=document.all;
var isNN=!document.all&&document.getElementById;
var isHot=false;
var movinWindow = "";
var winW = 0;
var winH = 0;

function getWinSize(){
  if(parseInt(navigator.appVersion)>3){
    if(navigator.appName=="Netscape"){
      winW = window.innerWidth;
      winH = window.innerHeight;
    }
    if(navigator.appName.indexOf("Microsoft")!=-1){
      winW = document.documentElement.offsetWidth;
      winH = document.documentElement.offsetHeight;
    }
  }
}

getWinSize();

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all[movinWindow] : document.getElementById(movinWindow);
  hotDog=isIE ? event.srcElement : e.target;
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx;
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;
}

document.onmousedown=ddInit;
document.onmouseup=Function("ddEnabled=false");


PMWindow = function(div_name,wsize,hsize){
  this.window_name = div_name;
  this.window_id = div_name;
  this.window_obj = document.getElementById(div_name);
  this.d_opacity = 0;
  this.wformbox = 580;
  this.wposition = null;
  this.act_type = "";
  this.dtrg_width = winW;
  this.dtrg_height = winH;
  this.status = "hide";
  this.content_id = null;
  if(wsize){
    this.wsize = wsize;
  }
  if(hsize){
    this.hsize = hsize;
  }
  this.checkCWidth();
  if(document.all && !window.opera) {
    if (/MSIE (5\.5)|[6789]/.test(navigator.userAgent) && navigator.platform == "Win32") {
      document.write('<style>td.shadowPixel {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="http://isvr.net/bg_pixel.png",sizingMethod="scale");}</style>')
      btype = "ie";
    }
  } else if (document.getElementById) {
    document.write('<style>td.shadowPixel {background-image:url("http://isvr.net/bg_pixel.png");}</style>');
      btype = "opera";
  } else {
    document.write('<style>td.shadowPixel {background-color:#5C646B}</style>');
    btype = "nn";
  }
}

PMWindow.prototype.alphaPlus = function(){
  if(this.window_obj.filters){
    if(this.d_opacity < 100){
//        alert("!"+this.d_opacity);
      this.d_opacity += 10;
      this.window_obj.filters.alpha.opacity = this.d_opacity;
    } else {
      this.status = "show";
      clearInterval(timeout_ID);
    }
  } else {
    if(this.d_opacity < 1){
      this.d_opacity = parseFloat(this.d_opacity) + parseFloat("0.05");
      this.window_obj.style.MozOpacity = this.d_opacity;
    } else {
      this.status = "show";
      clearInterval(timeout_ID);
    }
  }
}

PMWindow.prototype.alphaMinus = function(new_content){
  if(this.window_obj.filters){
    if(this.d_opacity > 0){
      this.d_opacity -= 10;
      this.window_obj.filters.alpha.opacity = this.d_opacity;
    } else {
      this.d_opacity = 0;
      this.window_obj.filters.alpha.opacity = 0;
      this.window_obj.style.visibility = "hidden";
      this.status = "hide";
      clearInterval(timeout_ID);
      if(new_content){
        this.makeContent(new_content);
        this.show();
      } else {
        this.content_id = "";
      }
    }
  } else {
    if(this.d_opacity > 0){
      this.d_opacity = parseFloat(this.d_opacity) - parseFloat("0.05");
      this.window_obj.style.MozOpacity = this.d_opacity;
    } else {
      this.d_opacity = 0;
      this.window_obj.style.MozOpacity = 0;
      this.window_obj.style.visibility = "hidden";
      this.status = "hide";
      clearInterval(timeout_ID);
      if(new_content){
        this.makeContent(new_content);
        this.show();
      } else {
        this.content_id = "";
      }
    }
  }
}

PMWindow.prototype.show = function(){
  if(this.status=="hide"){
    this.checkCWidth();
    this.window_obj.style.visibility = "visible";
    this.status = "progress";
    var cur_obj = this;
    timeout_ID = setInterval(function(){ cur_obj.alphaPlus()},1);
  }
}

PMWindow.prototype.hide = function(new_content){
  if(this.status=="show"){
    this.status = "progress";
    var cur_obj = this;
    timeout_ID = setInterval(function(){ cur_obj.alphaMinus(new_content)},1);
  }
}

PMWindow.prototype.makeContent = function(content){
  this.window_obj.innerHTML = "";
  this.window_obj.innerHTML = content;
}

PMWindow.prototype.checkCWidth = function(){
  if(this.wsize){
    this.wposition = Math.round((this.wsize - this.wformbox) / 2);
  } else if(this.dtrg_width) {
    this.wposition = Math.round((this.dtrg_width - this.wformbox) / 2);
//    alert("!: "+this.wposition);
  } else {
    this.wposition = 55;
  }
  this.window_obj.style.left = this.wposition;
  if(this.hsize){
    this.window_obj.style.top = this.hsize;
  } else {
    this.window_obj.style.top = 180;
  }
}

// /Popup layer

function doFormD(src_window, form_type){
  if(src_window.status!="progress"){
    if(src_window.content_id!=form_type && src_window.status=="hide"){
      src_window.content_id = form_type;
      src_window.makeContent(makeForm());
      src_window.show();
    } else if (src_window.content_id!=form_type && src_window.status=="show"){
      src_window.content_id = form_type;
      src_window.hide(makeForm());
    }
  }
}

function makeForm(type){
  var result = "";
  var ht_page_title = "";
  var ht_html_code = "";//js code to run hits tracking
  if(pop_window.content_id=="app"){
    var bg_top = "bg_ssa.gif";
    var top_img_head = "ssa_img_head.gif";
    var top_img = "ssa_img.gif";
    var top_title = "ssa_title.gif";
    var top_close = "ssa_close.gif";
    var main_color = "#619B41";
    var msg_title = "Message:";
    ht_page_title = "Schedule Showing Appointment";
  } else {
    var bg_top = "bg_rmi.gif";
    var top_img_head = "rmi_img_head.gif";
    var top_img = "rmi_img.gif";
    var top_title = "rmi_title.gif";
    var top_close = "rmi_close.gif";
    var main_color = "#C55252";
    var msg_title = "Message:";
    ht_page_title = "Request More Information";
  }
  var form_content = "";
  if(type=="contact"){
    var email = listingXmlData.getElementsByTagName("contact_email").item(0).firstChild.data;
    form_content += ""+
    "        <table cellspacing='0' cellpadding='3' border='0'>"+
    "        <input type='hidden' name='operation' value='submit_contact_info'>"+
    "        <tr>"+
    "          <td colspan='2'>"+
    "            <table width='100%' cellspacing='0' cellpadding='0' border='0'>"+
    "            <tr>"+
    "              <td class='basicVb' style='color:#ffffff'>Contact Information</td>"+
    "              <td align='right' class='d' style='color:#ffffff'>* - Required fields</td>"+
    "            </tr>"+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        <tr><td colspan='2'><table width='100%' cellspacing='0' cellpadding='0'><tr><td bgcolor='#FBBE9D'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr></table></td></tr>"+
    "        <tr>"+
    "          <td width='1%' class='d' style='color:#ffffff;font-weight:700;'><nobr>Email:&#160;</nobr></td>"+
    "          <td width='99%' class='d' style='color:#ffffff;'>"+email+"</td>"+
    "        </tr>"+
    "        <tr>";
    if((typeof(ReqFirstName)!= 'undefined') && (ReqFirstName!='0')) {
      form_content += "          <td class='d' style='color:#ffffff;font-weight:700;'><nobr>First Name*:&#160;</nobr></td>";
    }
    else {
      form_content += "          <td class='d' style='color:#ffffff;font-weight:700;'><nobr>First Name:&#160;</nobr></td>";
    }
    form_content += "          <td><input type='text' name='contactFirstName' maxlength='50' class='mainintxt' style='width:150px;'></td>"+
    "        </tr>"+
    "        <tr>"+
    "          <td class='d' style='color:#ffffff;font-weight:700;'><nobr>Last Name*:&#160;</nobr></td>"+
    "          <td><input type='text' name='contactLastName' maxlength='50' class='mainintxt' style='width:150px;'></td>"+
    "        </tr>"+
    "        </table>"+
    "        <table cellspacing='0' cellpadding='3' border='0'>";
    if((typeof(ReqPhone)!= 'undefined') && (ReqPhone!='0')) {
      form_content += "        <tr><td class='d' style='color:#ffffff;font-weight:700;'>Phone Number* <span style='font-weight:500;'>(at least one phone number is required):</span></td></tr>";
    }
    else {
      form_content += "        <tr><td class='d' style='color:#ffffff;font-weight:700;'>Phone Number:</td></tr>";
    }
    form_content += "        <tr>"+
    "          <td>"+
    "            <table width='390' cellspacing='0' cellpadding='0' border='0'>"+
    "            <tr>"+
    "              <td class='d' style='color:#ffffff;'><nobr>Work Phone:&#160;</nobr></td>"+
    "              <td><input type='text' name='contactPhoneWork' onBlur=\"FormatString(this,'(###) ###-####',false,10,10,'','Work Phone');\" class='mainintxt' style='width:95px;'></td>"+
    "              <td class='d' style='color:#ffffff;'>&#160;&#160;ext:&#160;</td>"+
    "              <td><input type='text' name='contactPhoneWorkExt' onblur=\"if(this.value.indexOf('<')!=-1 || this.value.indexOf('>')!=-1) alert('Phone extensions cannot contain symbols < and >.');\" maxlength='4' class='mainintxt' style='width:35px;'></td>"+
    "              <td class='d' style='color:#ffffff;'><nobr>&#160;&#160;Cell Phone:&#160;</nobr></td>"+
    "              <td><input type='text' name='contactPhoneCellular' onBlur=\"FormatString(this,'(###) ###-####',false,10,10,'','Cell Phone');\" class='mainintxt' style='width:95px;'></td>"+
    "            </tr>"+
    "            <tr><td colspan='6'><img src='http://isvr.net/p.gif' width='1' height='4'/></td></tr>"+
    "            <tr>"+
    "              <td class='d' style='color:#ffffff;'><nobr>Home Phone:&#160;</nobr></td>"+
    "              <td><input type='text' name='contactPhoneHome' onBlur=\"FormatString(this,'(###) ###-####',false,10,10,'','Home Phone');\" class='mainintxt' style='width:95px;'></td>"+
    "              <td colspan='2' class='d'>&#160;</td>"+
    "              <td class='d' style='color:#ffffff;'>&#160;&#160;Fax:&#160;</td>"+
    "              <td><input type='text' name='contactFax' onBlur=\"FormatString(this,'(###) ###-####',false,10,10,'','Fax');\" class='mainintxt' style='width:95px;'></td>"+
    "            </tr>"+
    "            <tr><td colspan='6'><img src='http://isvr.net/p.gif' width='1' height='4'/></td></tr>"+
    "            <tr>"+
    "              <td class='d'>&#160;</td>"+
    "              <td colspan='5' class='basicVsm' style='color:#FFD4BD;'><u>Note:</u> By submitting your telephone number you are consenting to being contacted by Me and/or my authorized representatives via telephone and/or e-mail, even if your name appears on the Federal \"Do-not-call List.\"</td>"+
    "            </tr>"+
    "            <tr><td colspan='6'><img src='http://isvr.net/p.gif' width='1' height='4'/></td></tr>"+
    "            <tr>"+
    "              <td class='d' style='color:#ffffff;'><nobr>Address:&#160;</nobr></td>"+
    "              <td colspan='5'><input type='text' name='contactAddressStreet' class='mainintxt' style='width:310px;'></td>"+
    "            </tr>"+
    "            <tr><td colspan='6'><img src='http://isvr.net/p.gif' width='1' height='4'/></td></tr>"+
    "            <tr>"+
    "              <td class='d' style='color:#ffffff;'><nobr>City:&#160;</nobr></td>"+
    "              <td colspan='5'>"+
    "                <table cellspacing='0' cellpadding='0' border='0'>"+
    "                <tr>"+
    "                  <td><input type='text' name='contactAddressCity' class='mainintxt' style='width:143px;'></td>"+
    "                  <td class='d' style='color:#ffffff;'>&#160;&#160;State:&#160;</td>"+
    "                  <td>"+state_select+"</td>"+
    "                  <td class='d' style='color:#ffffff;'><nobr>&#160;&#160;Zip:&#160;</nobr></td>"+
    "                  <td><input type='text' name='contactAddressZip' class='mainintxt' style='width:40px;' maxlength='5'></td>"+
    "                  <input type='hidden' name='clientAgentId' value='"+client_agent_id+"'/>"+
    "                  <input type='hidden' name='target_email' value='"+target_email+"'/>"+
    "                </tr>"+
    "                </table>"+
    "              </td>"+
    "            </tr>"+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        <tr><td><table width='100%' cellspacing='0' cellpadding='0'><tr><td bgcolor='#FBBE9D'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr></table></td></tr>"+
    "        <tr>"+
    "          <td align='right'>"+
    "            <table cellspacing='0' cellpadding='5' border='0'>"+
    "            <tr><td height='24' class='d' bgcolor='#505050' style='font-weight:700;'>&#160;<a href='javascript:sendContactInfo()' style='color:#ffffff;text-decoration:none;'>SUBMIT</a>&#160;</td></tr>"+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        </table>";
    window.chengedTitle = ht_page_title + " - Contact Info";
    window.custom_url = window.location.protocol + "//" + window.location.host
//    __HitRealtorId = undefined;
    __HitAddMB = undefined;
    __HitNotCountRealtor = undefined;
//    __HitInListings = undefined;
    ht_html_code = getHitTrackingHtmlCode();
  } else if(type=="thanks"){
    var i_we = "I";
    if (pop_window.is_plural == "true") {
      i_we = "We";
    }
    form_content = ""+
    "        <table width='100%' cellspacing='0' cellpadding='3' border='0'>"+
    "        <tr>"+
    "          <td>"+
    "            <table width='100%' height='200' cellspacing='0' cellpadding='0' border='0'>"+
    "            <tr>"+
    "              <td align='center' class='d' style='color:#ffffff'><b>Thank you for your request!<br></b>"+i_we+" will contact you shortly.<br><br><br>- <a href='javascript:pop_window.hide();' style='color:#ffffff;'>close window</a> -<br><br></td>"+      "            </tr>"+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        </table>";
    window.chengedTitle = ht_page_title + " - Thank You";
    window.custom_url = window.location.protocol + "//" + window.location.host
//    __HitRealtorId = undefined;
    __HitAddMB = undefined;
    __HitNotCountRealtor = undefined;
//    __HitInListings = undefined;
    ht_html_code = getHitTrackingHtmlCode();
  } else if(type=="loading"){
    form_content = ""+
    "        <table width='100%' cellspacing='0' cellpadding='3' border='0'>"+
    "        <tr>"+
    "          <td>"+
    "            <table width='100%' height='200' cellspacing='0' cellpadding='0' border='0'>"+
    "            <tr>"+
    "              <td align='center' class='d' style='color:#ffffff'>Loading. Please, wait...<br><br><br></td>"+
    "            </tr>"+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        </table>";
  } else {
    if(window.is_custom==true || data_pid=="null"){
      var listing_source = data_location;
    } else {
      var listing_source = data_pid;
    }
    if(pop_window.content_id=="app"){
      var current_subject = "Please show me this property: "+listing_source;
    } else {
      var current_subject = "Request more information. Property: "+listing_source;
    }
    form_content = ""+
    "        <table width='100%' cellspacing='0' cellpadding='3' border='0'>"+
    "        <input type='hidden' name='operation' value='submit_request'>"+
    "        <input type='hidden' name='request_subject' value='"+current_subject+"'>"+
    "        <tr>"+
    "          <td colspan='2'>"+
    "            <table cellspacing='0' cellpadding='1' border='0'>";
    if(!(window.is_custom==true) && data_pid!="null"){
    form_content += ""+
    "            <tr>"+
    "              <td class='d' style='color:#ffffff;font-weight:700;'>MLS#:&#160;</td>"+
    "              <td class='d' style='color:#ffffff'>"+data_pid+"</td>"+
    "            </tr>";
    }
    if(data_location!=""){
    form_content += ""+
    "            <tr>"+
    "              <td valign='top' class='d' style='color:#ffffff;font-weight:700;'>Location:&#160;</td>"+
    "              <td class='d' style='color:#ffffff'>"+data_location+"</td>"+
    "            </tr>";
    }
    form_content += ""+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        <tr><td colspan='2'><table width='100%' cellspacing='0' cellpadding='0'><tr><td bgcolor='#FBBE9D'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr></table></td></tr>";
    if(contact_email!=""){
      form_content += "<input type='hidden' name='contactEmail' value='"+contact_email+"'>";
    }else if(client_agent_id!="" && target_email!=""){
      form_content += "<input type='hidden' name='clientAgentId' value='"+client_agent_id+"'>";
      form_content += "<input type='hidden' name='contactEmail' value='"+target_email+"'>";
    }else {
      form_content += "<tr>"+
                      "  <td class='d' style='color:#ffffff'>Your&nbsp;Email*:<br/></td>"+
                      "  <td><input type='text' name='contactEmail' class='mainintxt' style='width:230px;'><br/></td>"+
                      "</tr>";
    }
    form_content += ""+
    "        <tr><td colspan='2' class='d' style='color:#ffffff'>"+msg_title+"<br/></td></tr>"+
    "        <tr><td colspan='2'><textarea name='request_message' class='maintextarea' cols='50' rows='10' style='width:100%'></textarea></td></tr>"+
    "        <tr>"+
    "          <td colspan='2' align='right'>"+
    "            <table cellspacing='0' cellpadding='5' border='0'>"+
    "            <tr><td height='24' class='d' bgcolor='#505050' style='font-weight:700;'>&#160;<a href='javascript:sendMessage()' style='color:#ffffff;text-decoration:none;'>Send Request</a>&#160;</td></tr>"+
    "            </table>"+
    "          </td>"+
    "        </tr>"+
    "        </table>";
    window.chengedTitle = ht_page_title + " - Home";
    window.custom_url = window.location.protocol + "//" + window.location.host
//    __HitRealtorId = undefined;
    __HitAddMB = undefined;
    __HitNotCountRealtor = undefined;
//    __HitInListings = undefined;
    ht_html_code = getHitTrackingHtmlCode();
  }
  result += ""+
  "<table width='100%' cellspacing='0' cellpadding='0' border='0'>"+
  "<tr>"+
  "  <td rowspan='4' width='1' bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "  <td rowspan='2' width='1' valign='top'>"+
  "    <table cellspacing='0' cellpadding='0' border='0'>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='5'/></td></tr>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='2'/></td></tr>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
  "    <tr><td bgcolor='"+main_color+"'><img src='http://isvr.net/p.gif' width='1' height='44'/></td></tr>"+
  "    </table>"+
  "  </td>"+
  "  <td width='100%' valign='top' bgcolor='#d0d0d0'>"+
  "    <table cellspacing='0' cellpadding='0'>"+
  "    <tr>"+
  "      <td><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "      <td><img src='http://isvr.net/"+top_img_head+"' width='52' height='5'/></td>"+
  "    </tr>"+
  "    </table>"+
  "  </td>"+
  "  <td rowspan='2' width='1' valign='top'>"+
  "    <table cellspacing='0' cellpadding='0' border='0'>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='5'/></td></tr>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='2'/></td></tr>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
  "    <tr><td bgcolor='"+main_color+"'><img src='http://isvr.net/p.gif' width='1' height='44'/></td></tr>"+
  "    </table>"+
  "  </td>"+
  "  <td rowspan='4' width='1' bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "  <td width='5'><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "</tr>"+
  "<tr>"+
  "  <td width='100%' valign='top' bgcolor='#ffffff'>"+
  "    <table width='100%' cellspacing='0' cellpadding='0'>"+
  "    <tr>"+
  "      <td background='http://isvr.net/"+bg_top+"'>"+
  "        <table width='100%' cellspacing='0' cellpadding='0'>"+
  "        <tr>"+
  "          <td>"+
  "            <div id='titleBar' style='cursor:move'>"+
  "            <table cellspacing='0' cellpadding='0'>"+
  "            <tr>"+
  "              <td><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "              <td><img src='http://isvr.net/"+top_img+"' width='52' height='47'/></td>"+
  "              <td><img src='http://isvr.net/p.gif' width='3' height='1'/></td>"+
  "              <td><img src='http://isvr.net/"+top_title+"' width='225' height='47'/></td>"+
  "            </tr>"+
  "            </table>"+
  "            </div>"+
  "          </td>"+
  "          <td align='right' valign='top'>"+
  "            <img src='http://isvr.net/p.gif' width='1' height='10'/><br/>"+
  "            <table cellspacing='0' cellpadding='0'>"+
  "            <tr>"+
  "              <td><img src='http://isvr.net/p.gif' width='9' height='1'/></td>"+
  "              <td><a href='javascript:pop_window.hide()'><img src='http://isvr.net/"+top_close+"' width='16' height='16' border='0'/></a></td>"+
  "              <td><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "            </tr>"+
  "            </table>"+
  "          </td>"+
  "        </tr>"+
  "        </table>"+
  "      </td>"+
  "    </tr>"+
  "    </table>"+
  "  </td>"+
  "  <td rowspan='4' width='5' class='shadowPixel'><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "</tr>"+
  "<tr>"+
  "  <td bgcolor='"+main_color+"'><img src='http://isvr.net/p.gif' width='1' height='1'/></td>"+
  "  <td width='99%' valign='top' bgcolor='#EF7131'>"+
  "    <table width='100%' cellspacing='0' cellpadding='0' border='0'>"+
  "    <tr>"+
  "      <td width='1%'><img src='http://isvr.net/p.gif' width='10' height='1'/></td>"+
  "      <td width='98%'>"+
           form_content+
  "        <img src='http://isvr.net/p.gif' width='1' height='5'/><br/>"+
  "      </td>"+
  "      <td width='1%'><img src='http://isvr.net/p.gif' width='10' height='1'/></td>"+
  "    </tr>"+
  "    </table>"+
  "  </td>"+
  "  <td bgcolor='"+main_color+"'><img src='http://isvr.net/p.gif' width='1' height='1'/></td>"+
  "</tr>"+
  "<tr><td colspan='3' bgcolor='"+main_color+"'><img src='http://isvr.net/p.gif' width='1' height='1'/></td></tr>"+
  "<tr>"+
  "  <td colspan='5'>"+
  "    <table width='100%' cellspacing='0' cellpadding='0' border='0'>"+
  "    <tr><td bgcolor='#CECECE'><img src='http://isvr.net/p.gif' width='1' height='5'/></td></tr>"+
  "    </table>"+
  "    <table width='100%' cellspacing='0' cellpadding='0' border='0'>"+
  "    <tr>"+
  "      <td width='1%'><img src='http://isvr.net/p.gif' width='5' height='1'/></td>"+
  "      <td width='99%' class='shadowPixel'><img src='http://isvr.net/p.gif' width='1' height='5'/></td>"+
  "    </tr>"+
  "    </table>"+
  "  </td>"+
  "</tr>"+
  "</table>";
  // hits tracking now, if need
  if (ht_html_code != "") {
    result += ht_html_code;
  }
  return result;
}

var AJAXPMUrlObj = new AJAXUrlClass();

function sendMessage(){
  var frm = document.forms.action_links_form;
  if(!checkEMailField(frm.contactEmail, true, true)){
    frm.contactEmail.focus();
    return;
  }
  if(pop_window.content_id=="app"){
    var current_servlet = "/RequestAppointment";
  } else {
    var current_servlet = "/RequestMoreInfo";
  }
  var url = site_url+current_servlet+"?operation="+frm.operation.value+"&ndd=1&xml=1";
  var send_params = "&request_property_url="+escape(frm.request_property_url.value)+"&request_subject="+escape(frm.request_subject.value)+"&contactEmail="+frm.contactEmail.value+"&request_message="+escape(frm.request_message.value);
  if(frm.client_agent_id && frm.client_agent_id.value!=""){
    send_params += "&client_agent_id=" + frm.client_agent_id.value;
  }
  if(frm.target_email && frm.target_email.value!=""){
    send_params += "&target_email=" + frm.target_email.value;
  }
  if (typeof p_search_id != 'undefined') {
    send_params += (p_search_id == "" ? "" : "&search_id=" + p_search_id);
  }
    //prompt("fddd",url+send_params);
  pop_window.makeContent(makeForm("loading"));
  AJAXPMUrlObj.set(url,send_params,"updatelistingXmlData","none");
  loadData(AJAXPMUrlObj);
}

function sendContactInfo(){
  var frm = document.forms.action_links_form;
//    if(frm.LeadReqFName.value=="1"){
  if((typeof(ReqFirstName)!= 'undefined') && (ReqFirstName!='0')) {
    if(trim(frm.contactFirstName.value)==""){
      alert("First Name is required!");
      frm.contactFirstName.focus();
      return;
    }
  }
//    }
  if(trim(frm.contactLastName.value)==""){
    alert("Last Name is required!");
    frm.contactLastName.focus();
    return;
  }
  if(frm.contactPhoneWork.value!=""){
    FormatString(frm.contactPhoneWork,'(###) ###-####',false,10,10,'','Work Phone');
  }
  if(frm.contactPhoneCellular.value!=""){
    FormatString(frm.contactPhoneCellular,'(###) ###-####',false,10,10,'','Cell Phone');
  }
  if(frm.contactPhoneHome.value!=""){
    FormatString(frm.contactPhoneHome,'(###) ###-####',false,10,10,'','Home Phone');
  }
//    if(frm.LeadReqPhone.value=="1"){
  if((typeof(ReqPhone)!= 'undefined') && (ReqPhone!='0')) {
    if ((frm.contactPhoneWork && frm.contactPhoneWork.value=="") && (frm.contactPhoneCellular && frm.contactPhoneCellular.value=="") && (frm.contactPhoneHome && frm.contactPhoneHome.value=="")){
      alert("At least one of the phone numbers needs to be entered. Please specify Work, Home or Cell Phone number.");
      return;
    }
  }
//    }
  if(pop_window.content_id=="app"){
    var current_servlet = "/RequestAppointment";
  } else {
    var current_servlet = "/RequestMoreInfo";
  }
  var url = site_url+current_servlet+"?operation="+frm.operation.value+"&ndd=1&xml=1";
  var email = listingXmlData.getElementsByTagName("contact_email").item(0).firstChild.data;
  var request_subject = listingXmlData.getElementsByTagName("request_subject").item(0).firstChild.data;
  if(listingXmlData.getElementsByTagName("request_message").item(0).firstChild){
    var request_message = listingXmlData.getElementsByTagName("request_message").item(0).firstChild.data;
  } else {
    var request_message = "";
  }
  var request_property_url = listingXmlData.getElementsByTagName("request_property_url").item(0).firstChild.data;
  var send_params = "&request_property_url="+escape(request_property_url)+"&request_subject="+escape(request_subject)+
                "&contactEmail="+email+"&request_message="+escape(request_message)+
                "&contactFirstName="+frm.contactFirstName.value+"&contactLastName="+frm.contactLastName.value+
                "&contactPhoneWork="+frm.contactPhoneWork.value+"&contactPhoneWorkExt="+frm.contactPhoneWorkExt.value+"&contactPhoneCellular="+frm.contactPhoneCellular.value+
                "&contactPhoneHome="+frm.contactPhoneHome.value+"&contactFax="+frm.contactFax.value+
                "&contactAddressStreet="+frm.contactAddressStreet.value+"&contactAddressCity="+frm.contactAddressCity.value+
                "&contactAddressState="+frm.contactAddressState.value+"&contactAddressZip="+frm.contactAddressZip.value+"&cliendAgentId="+frm.clientAgentId.value+"&target_email="+frm.target_email.value;
    //prompt("fddd",url+send_params);
  pop_window.makeContent(makeForm("loading"));
  AJAXPMUrlObj.set(url,send_params,"updatelistingXmlData","none");
  loadData(AJAXPMUrlObj);
}

function updatelistingXmlData(xd){
  listingXmlData = xd;
  var results_type = listingXmlData.getElementsByTagName("result");
  if(results_type.length > 0){
    handlePMResults(results_type.item(0).firstChild.data,listingXmlData);
    return;
  }
}

function handlePMResults(result_type){
  //      alert("!");
  if(result_type=="thank_you"){
    pop_window.makeContent(makeForm("thanks"));
  } else if(result_type=="get_contact_info") {
    pop_window.makeContent(makeForm("contact"));
    pop_window.status=="blocked";
  }
}

  function PUWindowClass(window_id){
    this.window_id = window_id;
  }

  function div_show(cdiv){
    cdiv.style.display = "block";
    cdiv.style.visibility = "visible";
  }

  function div_hide(cdiv){
    cdiv.style.display = "none";
    cdiv.style.visibility = "hidden";
    if (document.getElementById("ls_select"))
      document.getElementById("ls_select").style.visibility = "visible";
  }

  window.size = function(){
    var w = 0;
    var h = 0;
    //IE
    if(!window.innerWidth){
      //strict mode
      if(!(document.documentElement.clientWidth == 0)){
        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
      //quirks mode
      } else {
        w = document.body.clientWidth;
        h = document.body.clientHeight;
      }
    //w3c
    } else {
      w = window.innerWidth;
      h = window.innerHeight;
    }
    return {width:w,height:h};
  }

  window.center = function(){
    var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};
    var _x = 0;
    var _y = 0;
    var offsetX = 0;
    var offsetY = 0;

    //IE
    if(!window.pageYOffset){
      //strict mode
      if(!(document.documentElement.scrollTop == 0)){
        offsetY = document.documentElement.scrollTop;
        offsetX = document.documentElement.scrollLeft;
      //quirks mode
      } else {
        offsetY = document.body.scrollTop;
        offsetX = document.body.scrollLeft;
      }
    //w3c
    } else {
      offsetX = window.pageXOffset;
      offsetY = window.pageYOffset;
    }
    _x = ((this.size().width-hWnd.width)/2)+offsetX;
    _y = ((this.size().height-hWnd.height)/2)+offsetY;
    return{x:_x,y:_y};
  }

  PUWindowClass.prototype.show = function(state){
    var cdiv = document.getElementById(this.window_id);
    if(cdiv){
      if(state==true){
        div_show(cdiv);
      } else {
        div_hide(cdiv);
      }
    }
  }

  PUWindowClass.prototype.set_position = function(x,y){
    var window_div = document.getElementById(this.window_id);
    window_div.style.left = x;
    window_div.style.top = y;
  }

  PUWindowClass.prototype.set_content = function(title,content,handler){
    var window_div = document.getElementById(this.window_id);
    window_div.style.top = 150;
    window_div.style.left = 250;
    var result = ""+
    "  <table width='100%' cellspacing='0' cellpadding='0' border='0'>"+
    "  <tr>"+
    "    <td width='100%'>"+
    "      <table width='100%' cellspacing='5' cellpadding='0' border='0' bgcolor='#00659C'>"+
    "      <tr>"+
    "        <td bgcolor='#639ACE'>"+
    "          <table width='100%' cellspacing='0' cellpadding='5' border='0'>"+
    "          <tr>"+
    "            <td id='titleBar' style='cursor:move;color:#ffffff' width='100%' class='basicAb'>"+title+"</td>"+
    "            <td style='cursor:hand;color:#ffffff' valign='top' class='basicAb'><a href='#' onClick='div_hide(document.getElementById(\""+this.window_id+"\"));return false;' style='color:#ffffff;text-decoration:none;'>X</a></td>"+
    "          </tr>"+
    "          <tr bgcolor='white'><td style='padding:4px' colspan='2' class='d'>"+content+"</td></tr>"+
    "          </table>"+
    "        </td>"+
    "      </tr>"+
    "      </table>"+
    "    </td>"+
    "    <td width='4' rowspan='2' height='100%'><table height='100%' cellspacing='0' cellpadding='0' border='0'><tr><td height='6'><img src='http://isvr.net/p.gif' width='1' height='6'></td></tr><tr><td height='100%'><div style='background-color:#000000;width:5px;height:100%;-moz-opacity:.60;filter:alpha(opacity=60)'><img src='http://isvr.net/p.gif' width='5' height='1'><br></div></td></tr></table></td>"+
    "  </tr>"+
    "  <tr><td><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td width='6'><img src='http://isvr.net/p.gif' width='6' height='1'><br></td><td width='100%'><div style='background-color:#000000;width:100%;height:5px;-moz-opacity:.60;filter:alpha(opacity=60)'><img src='http://isvr.net/p.gif' width='1' height='5'><br></div></td></tr></table></td></tr>"+
    "  </table>";
    var window_div = document.getElementById(this.window_id);
    window_div.innerHTML = "";
    window_div.innerHTML = result;
  }

//window.onresize = function(){
//  pop_window.checkCWidth();
//}