/* 
   Ajax Form Box, JavaScript handler
   Version 1.0
   May 5, 2010

   This script custom generated December 8, 2010 at
   http://www.willmaster.com/software/WebSitesSecret/AjaxFormBox/generator.php

   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 customization place.

// 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 = "/ajaxbox.php";

//
// No further customization required.

var fm = '<div style="font-size:10px; font-weight:bold; letter-spacing:2px; text-align:center;"><a href="javascript:acb_HideContactBox()">[HIDE BOX]</a></div>';
fm += '<h2> <f'+'o'+'rm id="acb_f'+'o'+'rmtag" style="margin:0;" on'+'su'+'bmit="return false;">';
fm += '<in'+'pu'+'t t'+'y'+'pe="t'+'e'+'xt" style="width:165px;" onfocus="acb_ClearIfDefaultValue(this,\'Your Name\')" value="Your Name" name="name" id="acb_name">';
fm += '<in'+'pu'+'t t'+'y'+'pe="t'+'e'+'xt" style="width:165px;" onfocus="acb_ClearIfDefaultValue(this,\'Em'+'ai'+'l Address\')" value="Em'+'ai'+'l Address" name="em'+'ai'+'l" id="acb_em'+'ai'+'l">';
fm += '<p style="margin:0;">&nbsp;</p>';
fm += '<te'+'xt'+'area style="width:165px;" rows="3" name="comment" onfocus="acb_ClearIfDefaultValue(this,\'Your Message\')" id="acb_comment">';
fm += 'Your Message';
fm += '</te'+'xt'+'area>';
fm += '<p style="margin:0;">&nbsp;</p>';
fm += '<in'+'pu'+'t t'+'y'+'pe="bu'+'tt'+'on" style="width:165px; margin-top:3px;" onclick="acb_ProcessAjaxContactBox()" value="Send Message">';
fm += '</f'+'o'+'rm>';
fm += '</p>';

document.write('<div id="acb_box" style="display:none; position:absolute; top:-287; left:-287; z-index:99999999; background-color:#94b4ef; width:214px; margin:0;">');
document.write('<div style="border:2px solid #FFFFFF; margin:5px;">');
document.write('<div id="acb_messageBox" style="margin:0 10px 10px 10px;">');
document.write('&nbsp;');
document.write('</div>');
document.write('</div>');
document.write('</div>');

function acb_ClearIfDefaultValue(fld,val) { 
var fval = fld.value;
fval = fval.replace(/[\r\n]+/,"");
if( fval == val ) { fld.value = ""; }
}

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 acb_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 acb_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 addy = document.getElementById("acb_email").value;
   var name = document.getElementById("acb_name").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 tid;
   var params = "acb_field_list_bca=name%09email%09comment";
   params += "&acb_email_field_bca="+encodeURIComponent("email");
   params += "&acb_name_field_bca="+encodeURIComponent("name");
   params += "&name="+encodeURIComponent(document.getElementById("acb_name").value);
   params += "&email="+encodeURIComponent(document.getElementById("acb_email").value);
   params += "&comment="+encodeURIComponent(document.getElementById("acb_comment").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 = acb_findPosX(addyspot);
   var y = acb_findPosY(addyspot);
   if( x < 50 ) { x = 50; }
   if( y < 50 ) { y = 50; }
   document.getElementById("acb_messageBox").innerHTML = fm;
   var ff = document.getElementById("acb_box");
   ff.style.left = (x-4)+"px";
   ff.style.top = (y+35)+"px";
   ff.style.display = "";
}

function acb_HideContactBox()
{
   var ff = document.getElementById("acb_box");
   ff.style.display = "none";
   ff.style.left = "-287px";
   ff.style.top = "-287px";
}


