function expConvert() {
  expcode = document.getElementById('exp_code');
  input = expcode.value;
  expstring = "";
  
  while ( input > 0) {
    charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    remainder = (input % 36);
    mychar = charset.substr(remainder, 1);
    expstring = mychar + expstring;
    input = (input - remainder) / 36;
  }

  expcode.value = expstring;  
}

function clearMe(input) {
  element = document.getElementById(input);
  element.value = '';
}

var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";
var loAZ = "abcdefghijklmnopqrstuvwxyz";
symbols+= loAZ.toUpperCase();
symbols+= "[\\]^_`";
symbols+= loAZ;
symbols+= "{|}~";

function toAscii() {
  input = document.getElementById('hex_code');
  valueStr = input.value;
  valueStr = valueStr.toLowerCase();
  var hex = "0123456789abcdef";
  var text = "";
  var i=0;
	
  for( i=0; i<valueStr.length; i=i+2 ) {
    var char1 = valueStr.charAt(i);
    if ( char1 == ':' ) {
      i++;
      char1 = valueStr.charAt(i);
    }		
    
    var char2 = valueStr.charAt(i+1);
    var num1 = hex.indexOf(char1);
    var num2 = hex.indexOf(char2);
    var value = num1 << 4;
    value = value | num2;
    			
    var valueInt = parseInt(value);
    var symbolIndex = valueInt - 32;		
    var ch = '?';
    
    if ( symbolIndex >= 0 && value <= 126 ) {		
      ch = symbols.charAt(symbolIndex)
    }

    text += ch;				
  }
	
  input.value = text;
  return false;
}

function toHex() {
  input = document.getElementById('hex_code');
  var valueStr = input.value;
  var hexChars = "0123456789abcdef";
  var text = "";

  for( i=0; i<valueStr.length; i++ ) {
    var oneChar = valueStr.charAt(i);
    var asciiValue = symbols.indexOf(oneChar) + 32;
    var index1 = asciiValue % 16;
    var index2 = (asciiValue - index1)/16;
    
    if ( text != "" ) text += ":";

    text += hexChars.charAt(index2);
    text += hexChars.charAt(index1);			
  }

  input.value = text.toUpperCase();
  return false;
}

