
var newdiv;

var keyStr = "ABCDEFGHIJKLMNOP" +
               "QRSTUVWXYZabcdef" +
               "ghijklmnopqrstuv" +
               "wxyz0123456789+/" +
               "=";

//-------------------------------------------------------------------------------------------------
function decode64(input)
{
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;
 
     // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
     var base64test = /[^A-Za-z0-9\+\/\=]/g;
     if (base64test.exec(input)) {
        alert("There were invalid base64 characters in the input text.\n" +
              "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
              "Expect errors in decoding.");
     }
     input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
      do {
        enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
        enc4 = keyStr.indexOf(input.charAt(i++));
 
        chr1 = (enc1 << 2) | (enc2 >> 4);
        chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
        chr3 = ((enc3 & 3) << 6) | enc4;
 
         output = output + String.fromCharCode(chr1);
  
         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }
  
         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";
 
     } while (i < input.length);
 
     return unescape(output);
}

//-------------------------------------------------------------------------------------------------
// put popup window in the middle of the screen
function showdeadcenterdiv(Xwidth,Yheight,divid)
{
var scrolledX, scrolledY;
if( self.pageYOffset ) {
scrolledX = self.pageXOffset;
scrolledY = self.pageYOffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
scrolledX = document.documentElement.scrollLeft;
scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
scrolledX = document.body.scrollLeft;
scrolledY = document.body.scrollTop;
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY;
if( self.innerHeight ) {
centerX = self.innerWidth;
centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
} else if( document.body ) {
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}

// Xwidth is the width of the div, Yheight is the height of the
// div passed as arguments to the function:
var leftOffset = scrolledX + (centerX - Xwidth) / 2;
var topOffset = scrolledY + (centerY - Yheight) / 2;
// The initial width and height of the div can be set in the
// style sheet with display:none; divid is passed as an argument to // the function
var o=document.getElementById(divid);
var r=o.style;
r.position='absolute';
r.top = topOffset + 'px';
r.left = leftOffset + 'px';
r.display = "block";
} 

//-------------------------------------------------------------------------------------------------
function popup_email(to)
{

var poptext;

poptext = "";

poptext += "<form method='POST' action='/send.php'>";
poptext += "<table border=0 cellpadding=15 cellspacing=0>";
poptext += "<tr><td>";
poptext += "<table border=0 cellpadding=4 cellspacing=0>";
poptext += "<tr><td colspan=2 align='right'><a href='#' onClick='gray_out(false);document.body.removeChild(newdiv);return false;'>[ close ]</a></td></tr>";
poptext += "<tr>";
poptext += "<input type='hidden' name='to' value='"+to+"'>";
poptext += "    <td>To:</td>";
poptext += "    <td><b>"+decode64(to)+"</b></td>";
poptext += "</tr>";

poptext += "<tr>";
poptext += "    <td>From:</td>";
poptext += "    <td><input type='text' name='from' value='Your email address' style='width:300px;'></td>";
poptext += "</tr>";

poptext += "<tr>";
poptext += "    <td valign='top'>Message:</td>";
poptext += "    <td><b><textarea name='body' style='width:300px;height:80px;'></textarea></td>";
poptext += "</tr>";

poptext += "<tr>";
poptext += "    <td colspan=2 align='center'><input type='submit' value='Send Message'></td>";
poptext += "</tr>";
poptext += "</form>";
poptext += "</table>";
poptext += "</td></tr></table>";



newdiv = document.createElement('div');
var divIdName = 'popDiv';
newdiv.setAttribute('id',divIdName);
newdiv.style.width = "410px";
newdiv.style.height = "240px";
newdiv.style.left = "1px";
newdiv.style.top = "1px";
newdiv.style.position = "absolute";
newdiv.style.background = "#fff";
newdiv.style.border = "2px solid #000";
newdiv.innerHTML = poptext;
document.body.appendChild(newdiv);

document.getElementById('popDiv').style.zIndex = 99;
showdeadcenterdiv(410,240,'popDiv')

gray_out(true);

}

//-------------------------------------------------------------------------------------------------
function gray_out(vis, options) {
  var options = options || {}; 
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 50;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars            
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later
    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
    // Calculate the page width and height 
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        var pageWidth = document.body.scrollWidth+'px';
        var pageHeight = document.body.scrollHeight+'px';
    } else if( document.body.offsetWidth ) {
      var pageWidth = document.body.offsetWidth+'px';
      var pageHeight = document.body.offsetHeight+'px';
    } else {
       var pageWidth='100%';
       var pageHeight='100%';
    }   
    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;                      
    dark.style.MozOpacity=opaque;                   
    dark.style.filter='alpha(opacity='+opacity+')'; 
    dark.style.zIndex=zindex;        
    dark.style.backgroundColor=bgcolor;  
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';                          
  } else {
     dark.style.display='none';
  }
}

//-------------------------------------------------------------------------------------------------
