﻿function tellAFriend(mode, mailobj){
  var domain = 'afbhotels.com';
  var ig =  document.getElementById('taf');
  if(mode == 'initial'){
    ig.innerHTML = ''
     + '<table cellpadding="0" cellspacing="0" border="0">'
     + '<tr valign="top" height="20"><td></td><td></td><td align="right" width="60"><a class="spBlue" href="javascript:tellAFriend(\'close\', \'\', \'\', \'\', \'\')"><img border="0" src="images/close.gif" /></a></td></tr>'
     + '<tr><td><label>To:</label></td><td><input name="to" onchange="javascript:mailobj.to = this.value; " type="text" />*<span>(msmith@example.com)</span></td><td></td></tr>'
     + '<tr><td><label>Your Address</label></td><td><input name="from" onchange="javascript:mailobj.ra = this.value;" type="text" />*<span>(jdoe@comcast.net)</span></td><td></td></tr>'
     + '<tr><td><label>Your Name</label></td><td><input name="name" onchange="javascript:mailobj.from = this.value; " type="text" />*<span>(Jane Doe)</span></td><td></td></tr>'
     + '<tr valign="bottom"><td><label>Your Message</label></td><td><textarea cols="40" onchange="javascript:mailobj.msg = this.value; "></textarea></td><td></td></tr>'
     + '<tr><td></td><td align="left"><label> * required field</label></td><td><a href="javascript:mailobj.subject = document.title; mailobj.sname = sitename; mailobj.url = window.location; tellAFriend(\'\', mailobj);" class="spBlue">send >></a></td></tr>'
     + '<tr><td colspan="3"><p>' + domain + ' values your privacy.  We use these email addresses for the delivery of your message only.  We do not store, sell, or give them away.</p></td></tr>' 
     + '</table>';
  }
  else if(mode == 'close'){
    ig.innerHTML = '';
  }
  else {
    var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	  http_request = new XMLHttpRequest();
	  if (http_request.overrideMimeType) {
	    http_request.overrideMimeType('text/xml');
	  }
    }
    else if (window.ActiveXObject) { // IE
	  try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	  } 
	  catch (e) {
	    try {
	      http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch (e) {}
	  }
    }
    if (!http_request) {
	  return false;
    }
     http_request.onreadystatechange = function() { setSelect1(mailobj, http_request); };
    http_request.open('GET', 'mailer.php?to=' + mailobj.to + '&ra=' + mailobj.ra + '&from=' + mailobj.from + '&msg=' + mailobj.msg + '&url=' + mailobj.url + '&sname=' + mailobj.sname +'&subject=' + mailobj.subject , true);
    http_request.send(null);
  }
}
          
function setSelect1(mailobj, http_request) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      var xmldoc = http_request.responseText;
      var ig =  document.getElementById('taf');
      ig.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="375">'
     + '<tr valign="top" height="20"><td width="20"></td><td></td><td align="right" width="60"><a class="spBlue" style="margin-left: 150px" href="javascript:tellAFriend(\'close\', \'\', \'\', \'\', \'\')"><img border="0" src="images/close.gif" /></a></td></tr>'
       + xmldoc;
    }
    else {
      alert('There was a problem with the request.');
    }
  }
}





