
function decode64(input) {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
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);
    }
  } while (i < input.length);
return output;
}

function perform_post(url,postdata) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, IE >= 7,
  http_request = new XMLHttpRequest();
  }
else if (window.ActiveXObject) { // IE <= 6
  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() {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      process_xml_response(http_request);
      }
    }
  }
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", postdata.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(postdata);
}

function process_xml_response(http_request) {
var xml;
var xmldoc;
var command;
var i;
var element;
xml = http_request.responseXML;
xmldoc = xml.documentElement;
if (xmldoc.nextSibling) {
  xmldoc = xmldoc.nextSibling;
  }
if (xmldoc.nodeName != "response") {
  return;
  }
for (i=0;i<xmldoc.childNodes.length;i++) {
  command = xmldoc.childNodes[i];
  if (command.nodeName == 'redirect') {
    window.location = command.getAttribute('url');
    break;
    }
  else if (command.nodeName == 'css') {
    element = document.getElementById(command.getAttribute('id'));
    element.style[command.getAttribute('property')] = command.getAttribute('value');
    }
  else if (command.nodeName == 'html') {
    element = document.getElementById(command.getAttribute('id'));
    element.innerHTML = decode64(command.childNodes[0].nodeValue);
    }
  else if (command.nodeName == 'javascript') {
    eval(decode64(command.childNodes[0].nodeValue));
    }
  }
}

function vote(number,choice) {
if ( (choice == "1") || (choice == "0") ) {
  perform_post("http://www.boysoftech.com/ajax_vote","n="+number+"&v="+choice);
  }
}






function clickAddComment(item_id) {
var addcommentlink = document.getElementById('addcommentlink_'+item_id);
var addcommentarea = document.getElementById('addcommentarea_'+item_id);
addcommentlink.innerHTML = '<a onclick="return(clickCancelComment(\''+item_id+'\'))" href="">Cancel Comment</a>';
addcommentarea.style.display = 'block';
return false;
}

function clickCancelComment(item_id) {
var addcommentlink = document.getElementById('addcommentlink_'+item_id);
var addcommentarea = document.getElementById('addcommentarea_'+item_id);
var commentname = document.getElementById('commentname_'+item_id);
var commentcomment = document.getElementById('commentcomment_'+item_id);
var edimanswer = document.getElementById('edimanswer_'+item_id);
addcommentlink.innerHTML = '<a onclick="return(clickAddComment(\''+item_id+'\'))" href="">Leave A Comment</a>';
addcommentarea.style.display = 'none';
commentname.value = '';
commentcomment.value = '';
edimanswer.value = '';
return false;
}

function edimImageRefresh(item_id,baseURL,imageID) {
var edim = document.getElementById('edim_'+item_id);
var edimimageid = document.getElementById('edimimageid_'+item_id);
var edimanswer = document.getElementById('edimanswer_'+item_id);
var offset = parseInt(imageID) - loadDateSeconds;
var currentDate = new Date();
var currentMilliseconds = currentDate.getTime();
var currentSeconds = parseInt(parseFloat(currentMilliseconds)/1000);
var newImageID = currentSeconds + offset;
edim.src = baseURL + newImageID;
edimimageid.value = newImageID;
edimanswer.value = '';
return false;
}

function commentKeystroke(item_id) {
var commentcomment = document.getElementById('commentcomment_'+item_id);
if (commentcomment.value.length > 2500) {
  commentcomment.value = commentcomment.value.substring(0,2500);
  }
}

var loadDate = new Date();
var loadDateMilliseconds = loadDate.getTime();
var loadDateSeconds = parseInt(parseFloat(loadDateMilliseconds)/1000);

