<!-- about this file
/* 
   Ajax Contact Box, JavaScript handler
   Version 1.0
   April 19, 2010

   Will Bontrager
   http://www.willmaster.com/
   Copyright 2010 Bontrager Connection, LLC

   Bontrager Connection, LLC grants you 
   a royalty free license to use or modify 
   this software provided this notice appears 
   on all copies. This software is provided 
   "AS IS," without a warranty of any kind.
*/

// One place to customize.

// Specify the URI to the PHP contact box processor.
//    The URI is the URL minus the domain name.
//    Example: URL http://example.com/ProcessAjaxContactBox.php 
//         is: URI /ProcessAjaxContactBox.php 

var PHPhandlerURI = "AjaxContactBox/ProcessAjaxContactBox.php";

//
// No further customization required. -->

var fm = '<div style="font-size:10px; font-weight:bold; letter-spacing:2px; font-family:verdana,sans-serif; text-align:center;"><a href="javascript:acb_HideContactBox()">[HIDE FO'+'RM]</a></div>';
fm += '<f'+'or'+'m style="margin:0;" onsu'+'bmit="return false;">';
fm += '<div><in'+'put ty'+'pe="text" id="acb_Name" style="width:200px; padding-left:3px;" onclick="if(this.value==\'Name\'){this.value=\'\'}" value="Name"></div>';
fm += '<div style="margin-top:3px; margin-bottom:3px;"><in'+'put ty'+'pe="text" id="acb_Addy" style="width:200px; padding-left:3px;" onclick="if(this.value==\'Em'+'ail\'){this.value=\'\'}" value="Em'+'ail"></div>';
fm += '<div><tex'+'tarea id="acb_Message" style="width:200px; height:100px; padding:3px;" onclick="if(this.value==\'Message\'){this.value=\'\'}">Message</tex'+'tarea></div>';
fm += '<in'+'put ty'+'pe="button" style="width:200px; margin-top:3px;" onclick="acb_ProcessAjaxContactBox()" value="Send Message">';
fm += '</f'+'or'+'m>';
document.write('<div id="acb_box" style="display:none; position:absolute; top:-300; left:-300; background-color:white; width:270px; margin:0;">');
document.write('<div style="border:1px solid black; margin:25px;">');
document.write('<div id="acb_messageBox" style="margin:0 10px 10px 10px;">');
document.write(' ');
document.write('</div>');
document.write('</div>');
document.write('</div>');

function acb_BoxMessage(message,closeafter)
{
   var s = '<div style="font-size:10px; font-weight:bold; letter-spacing:2px; font-family:verdana,sans-serif; text-align:center;"><a href="javascript:acb_HideContactBox()">[HIDE MESSAGE]</a></div>';
   s += '<p style="text-align:center; margin-top:25px; font-weight:bold;">'+message+'</div>';
   document.getElementById("acb_messageBox").innerHTML = s;
   if(closeafter) { setTimeout("acb_HideContactBox()",3000); }
   return false;
}

function findPosX(obj)
{
   var leftedge = 0;
   if(obj.offsetParent)
   {
      while(true) 
      {
         leftedge += obj.offsetLeft;
         if( ! obj.offsetParent ) { break; }
         obj = obj.offsetParent;
      }
   }
   else
   {
      if(obj.x) { leftedge += obj.x; }
   }
   return leftedge;
}

function findPosY(obj)
{
   var topedge = 0;
   if(obj.offsetParent)
   {
      while(true)
      {
         topedge += obj.offsetTop;
         if( ! obj.offsetParent ) { break; }
         obj = obj.offsetParent;
      }
   }
   else
   {
      if(obj.y) { topedge += obj.y; }
   }
   return topedge;
}

function acb_GetResponse(http)
{
   if(http.readyState == 4)
   {
      if(http.status == 200) { acb_BoxMessage(http.responseText,true); }
      else { acb_BoxMessage('Content request error, status code: '+content.status+' '+content.statusText,true); }
   }
}

function acb_GetHTTP()
{
   var xhttp;
   try { xhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch (e) {
      try { xhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch (e2) {
         try { xhttp = new XMLHttpRequest(); }
         catch (e3) { xhttp = false; }
         }
      }
   return xhttp;
}

function acb_ProcessAjaxContactBox()
{
   var name = document.getElementById("acb_Name").value;
   var addy = document.getElementById("acb_Addy").value;
   if( (addy.indexOf("@") < 1) && (name.indexOf("@") > 0) )
   {
      var ts = name;
      name = addy;
      addy = ts;
   }
   if( addy.indexOf("@") < 1 )
   {
      alert("An ema"+"il address is required.");
      return ;
   }
   var http = acb_GetHTTP();
   if(! http) { return acb_BoxMessage('Sorry, unable to open a connection to the server.',true); }
   var params = "name="+encodeURIComponent(name);
   params += "&addy="+encodeURIComponent(addy);
   params += "&message="+encodeURIComponent(document.getElementById("acb_Message").value);
   params += "&url="+encodeURIComponent(document.URL);
   acb_BoxMessage("Sending ema"+"il.<br><br>A moment, please ...",false);
   http.open("POST",PHPhandlerURI,true);
   http.onreadystatechange = function() { acb_GetResponse(http); }
   http.setRequestHeader("Content-type", "application/x-www-fo"+"rm-urlencoded");
   http.setRequestHeader("Content-length", params.length);
   http.setRequestHeader("Connection", "close");
   http.send(params);
}

function acb_DisplayContactBox()
{
   var addyspot = document.getElementById("acb_pubaddy");
   var x = findPosX(addyspot);
   var y = findPosY(addyspot);
   document.getElementById("acb_messageBox").innerHTML = fm;
   var ff = document.getElementById("acb_box");
   ff.style.left = (x-50)+"px";
   ff.style.top = (y-50)+"px";
   ff.style.display = "";
}

function acb_HideContactBox()
{
   var ff = document.getElementById("acb_box");
   ff.style.display = "none";
   ff.style.left = "-300px";
   ff.style.top = "-300px";
}


