// what type of request to use
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

// Toggle Deal view in ad page
function toggleDeal(id, did, dt, areacode) {
  var d = document.getElementById(id);
  if (d.style.display == 'none') {
    d.style.display = '';
    // Call template on server to log view only when opening
    var http = getHTTPObject();
    http.open("GET", "/dealview.cfm?id=" + did + "&type=" + dt + "&areacode=" + areacode, true);
    
    // For testing
    //http.onReadyStateChange = function() {
    //  if (http.readyState == 4) alert(http.responseText);
    //}
    http.send(null);
  } else {
    d.style.display = 'none';
  }    
  //d.style.display = (d.style.display == 'none') ? '' : 'none';
}

// Open the email form in a new window
function openWebmail(type, area, id, site) {
  webmail = window.open("/email/main_form2.cfm?type=" + type + "&area=" + area + "&id=" + id + "&site=" + site, "", "resizable=yes,scrollbars=yes,width=440,height=545")
  webmail.focus()
}

