<script language="javascript">
<!--	
function dec2hex(dec_num)
{
var hex_num='';
var temp;
dec_num=dec_num.toUpperCase();
if(dec_num)
  {
   while( dec_num/16 != 0 )
     {
	   temp = dec_num % 16;
	   dec_num = dec_num - temp;
	
switch(temp){
      case 10: temp='A'; break;
      case 11: temp='B'; break;
      case 12: temp='C'; break;
      case 13: temp='D'; break;
      case 14: temp='E'; break;
      case 15: temp='F'; break;
      }
	   hex_num = temp + hex_num;
	   dec_num = dec_num / 16;
	 }
  return(hex_num);
   }
else
  {
  var NotEmpty="<?php echo $strTheValueCannotBeEmpty; ?>";
  alert(NotEmpty);
  }
}



function hex2dec(hex_num)
{
var dec_num='';
var temp,i,j;
var len;
hex_num=hex_num.toUpperCase();

len=hex_num.length;

for(i=len;i > 0 ;i--)
   {
    temp=hex_num.charAt(len - i);

switch(temp){
      case 'A': temp=10; break;
      case 'B': temp=11; break;
      case 'C': temp=12; break;
      case 'D': temp=13; break;
      case 'E': temp=14; break;
      case 'F': temp=15; break;
      }

    j=i-1; 
   
   while(j > 0)
      {
      j--;  
      temp = temp*16;
      }
     temp=Math.abs(temp);
     dec_num += temp;
     dec_num = Math.abs(dec_num); 
    }

return(dec_num);

}


function hex2bin(hex_num)
 {
 var bin_num='';
 var temp,i,j;
 var len;
 hex_num=hex_num.toUpperCase();
 len=hex_num.length;
 
 for(i=len;i > 0;i--)
  {
   temp=hex_num.charAt(len - i);
   switch(temp)
     {
     case '0':  temp = '0000';  break;
     case '1':  temp = '0001';  break;
     case '2':  temp = '0010';  break;
     case '3':  temp = '0011';  break;
     case '4':  temp = '0100';  break;
     case '5':  temp = '0101';  break;
     case '6':  temp = '0110';  break;
     case '7':  temp = '0111';  break;
     case '8':  temp = '1000';  break;
     case '9':  temp = '1001';  break;
     case 'A':  temp = '1010';  break;
     case 'B':  temp = '1011';  break;
     case 'C':  temp = '1100';  break;
     case 'D':  temp = '1101';  break;
     case 'E':  temp = '1110';  break;
     case 'F':  temp = '1111';  break;
      }
   bin_num += temp;
  }
 return(bin_num);
 }


function bin2hex(bin_num)
  {
  var hex_num='';
  var dec_num='';
  var temp ;
  var i,j,len;
  
  len=bin_num.length;
    
  for(i=len;i > 0;i--)
    {
    temp = bin_num.charAt(len - i);
    j=i-1;
   while( j > 0)
      {
      j--;
      temp=temp*2;
      }
     temp=Math.abs(temp);
     dec_num += temp;
     dec_num = Math.abs(dec_num); 
     }

 if(dec_num !='')
  {
   while( dec_num/16 != 0 )
     {
	   temp = dec_num % 16;
	   dec_num = dec_num - temp;
	switch(temp){
      case 10: temp='A'; break;
      case 11: temp='B'; break;
      case 12: temp='C'; break;
      case 13: temp='D'; break;
      case 14: temp='E'; break;
      case 15: temp='F'; break;
      }
	
	   hex_num = temp + hex_num;
	   dec_num = dec_num / 16;
	 }
  return(hex_num);
   }

  }




function check_hex_input(term)
{

  var checkOK = "0123456789ABCDEF";
  var checkStr = term.value.toUpperCase();
  var allValid = true;
 
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

  if (!allValid)
  {
    var MustBe="<?php echo $strParaMustBeAHexNumber; ?>"+"<?php echo '\n\n'; ?>"+"<?php echo $strTheFollowingLetterCanBeUsed; ?>"+"<?php echo ':0123456789ABCDEF'; ?>";
    alert(MustBe);
    term.focus();
    term.style.color="RED";
    return (false);
  }
    term.style.color="BLACK";
return (true);

}

function check_dec_input(term)
{

  var checkOK = "0123456789";
  var checkStr = term.value.toUpperCase();
  var allValid = true;
  
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

  if (!allValid)
  { 
    var MustDec="<?php echo $strParaMustBeADecNumber; ?>";
    alert(MustDec);
    term.focus();
    term.style.color="RED";
    return (false);
  }
    term.style.color="BLACK"; 
return (true);

}


function check_bin_input(term)
{

  var checkOK = "01";
  var checkStr = term.value.toUpperCase();
  var allValid = true;
 
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }

  if (!allValid)
  {
    var MustBin="<?php echo $strParaMustBeABinNumber; ?>";
    alert(MustBin);
    term.focus();
    term.style.color="RED";
    return (false);
  }
    term.style.color="BLACK"; 
return (true);

}



function hex2dec_input(hex_num)
 {
 hex_num.value=hex_num.value.toUpperCase();
 if(check_hex_input(hex_num))
 document.D2H2B.dec.value = hex2dec(document.D2H2B.hex.value);
 }

function dec2hex_input(dec_num)
 {
 dec_num.value=dec_num.value.toUpperCase();
 if(check_dec_input(dec_num))
 document.D2H2B.hex.value = dec2hex(document.D2H2B.dec.value);
 }

function hex2bin_input(hex_num)
 {
 hex_num.value=hex_num.value.toUpperCase();
 if(check_hex_input(hex_num))
 document.D2H2B.bin.value = hex2bin(document.D2H2B.hex.value);
 }

function bin2hex_input(bin_num)
 {
 bin_num.value=bin_num.value.toUpperCase();
 if(check_bin_input(bin_num))
 document.D2H2B.hex.value = bin2hex(document.D2H2B.bin.value);
 }
 -->
</script> 
<form name="D2H2B">
<table style="position: relative; top: -4; left: 5" border="1" width="620" cellpadding="2" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" > 
   <tr bgcolor="#E6E6E6">
      <td align="center" width="102"><?php echo $strDecNumber;?></td>
      <td align="center" width="65">&nbsp;</td>
      <td align="center" width="106"><?php echo $strHexadecNumber;?></td>
      <td align="center" width="70">&nbsp;</td>
      <td align="center" width="164"><?php echo $strBinNumber;?></td>
    </tr>
    <tr>
      <td width="102" align="center"><input type="text" name="dec" size="15"></td>
      <td width="65" align="center"><input type="button" value="&lt;-" name="B4" onClick="hex2dec_input(document.D2H2B.hex)"> 
        <input type="button" value="-&gt;" name="B3" onClick="dec2hex_input(document.D2H2B.dec)"></td>
      <td width="106" align="center"><input type="text" name="hex" size="10"></td>
      <td width="70" align="center"><input type="button" value="&lt;-" name="B6" onClick="bin2hex_input(document.D2H2B.bin)"> 
        <input type="button" value="-&gt;" name="B5" onClick="hex2bin_input(document.D2H2B.hex)"></td>
      <td width="164" align="center"><input type="text" name="bin" size="35"></td>
     </tr>
</table>
<table border="0">
<tr><td>
<?php echo"  <b>$strRemarks </b>: $strCalculatorRemarks";?>
</td></tr>
</table>
</form>



