function SHA1(msg) {
 //alert('hi');
	function rotate_left(n,s) {
		var t4 = ( n<<s ) | (n>>>(32-s));
		return t4;
	};
 
	function lsb_hex(val) {
		var str="";
		var i;
		var vh;
		var vl;
 
		for( i=0; i<=6; i+=2 ) {
			vh = (val>>>(i*4+4))&0x0f;
			vl = (val>>>(i*4))&0x0f;
			str += vh.toString(16) + vl.toString(16);
		}
		return str;
	};
 
	function cvt_hex(val) {
		var str="";
		var i;
		var v;
 
		for( i=7; i>=0; i-- ) {
			v = (val>>>(i*4))&0x0f;
			str += v.toString(16);
		}
		return str;
	};
 
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	var blockstart;
	var i, j;
	var W = new Array(80);
	var H0 = 0x67452301;
	var H1 = 0xEFCDAB89;
	var H2 = 0x98BADCFE;
	var H3 = 0x10325476;
	var H4 = 0xC3D2E1F0;
	var A, B, C, D, E;
	var temp;
 
	msg = Utf8Encode(msg);
 
	var msg_len = msg.length;
 
	var word_array = new Array();
	for( i=0; i<msg_len-3; i+=4 ) {
		j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
		msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
		word_array.push( j );
	}
 
	switch( msg_len % 4 ) {
		case 0:
			i = 0x080000000;
		break;
		case 1:
			i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
		break;
 
		case 2:
			i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
		break;
 
		case 3:
			i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8	| 0x80;
		break;
	}
 
	word_array.push( i );
 
	while( (word_array.length % 16) != 14 ) word_array.push( 0 );
 
	word_array.push( msg_len>>>29 );
	word_array.push( (msg_len<<3)&0x0ffffffff );
 
 
	for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
 
		for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
		for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
 
		A = H0;
		B = H1;
		C = H2;
		D = H3;
		E = H4;
 
		for( i= 0; i<=19; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		for( i=20; i<=39; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		for( i=40; i<=59; i++ ) {
			temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		for( i=60; i<=79; i++ ) {
			temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
			E = D;
			D = C;
			C = rotate_left(B,30);
			B = A;
			A = temp;
		}
 
		H0 = (H0 + A) & 0x0ffffffff;
		H1 = (H1 + B) & 0x0ffffffff;
		H2 = (H2 + C) & 0x0ffffffff;
		H3 = (H3 + D) & 0x0ffffffff;
		H4 = (H4 + E) & 0x0ffffffff;
 
	}
 
	var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
 
	//alert(temp.toLowerCase());
	var hex1=temp.toLowerCase();
       return hex1;
        //alert (hex1);
//var hex1='1234';
         //var a= hex2bin(hex1);
   
	 //alert(a);
//alert(typeof(a));
//var b=doasc(a)
//b=loadView('http://10.1.14.106:8383/dms/sha/testb64?st='+a);
//var b= encode64(a);
//alert(b);

}
var _hex2bin = [
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, // 0-9
     0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, // A-F
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0,10,11,12,13,14,15, 0, 0, 0, 0, 0, 0, 0, 0, 0, // a-f
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];


function hex2bin(str) {
    var len = str.length;
    var rv = '';
    var i = 0;

    var c1;
    var c2;

    while (len > 1) {
        h1 = str.charAt(i++);
        c1 = h1.charCodeAt(0);
        h2 = str.charAt(i++);
        c2 = h2.charCodeAt(0);
        
        rv += String.fromCharCode((_hex2bin[c1] << 4) + _hex2bin[c2]);
        len -= 2;
    }

    return rv;
}


var keyStr = "ABCDEFGHIJKLMNOP" +
               "QRSTUVWXYZabcdef" +
               "ghijklmnopqrstuv" +
               "wxyz0123456789+/" +
               "=";
 
  function encode64(input) {
     input = escape(input);
     var output = "";
     var chr1, chr2, chr3 = "";
     var enc1, enc2, enc3, enc4 = "";
     var i = 0;
 
     do {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);
 
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
 
        if (isNaN(chr2)) {
           enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
           enc4 = 64;
        }
 
        output = output +
           keyStr.charAt(enc1) +
           keyStr.charAt(enc2) +
           keyStr.charAt(enc3) +
           keyStr.charAt(enc4);
        chr1 = chr2 = chr3 = "";
        enc1 = enc2 = enc3 = enc4 = "";
     } while (i < input.length);
 
     return output;
  }



function loadView(path)
{
var fpath1=path+"&timestamp=" + new Date().getTime();
//alert(fpath1)

var xmlhttp;
document.getElementById('dms').style.display="block";
document.getElementById('dms').innerHTML="";
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
if (xmlhttp.status==200)
    {
     document.getElementById('dms').innerHTML=xmlhttp.responseText;
    }
else
   {
    alert("Problem retrieving data:" + xmlhttp.statusText);
   }

  }
}
xmlhttp.open("GET",fpath1,true);
xmlhttp.send(null);
}



function doasc(text) {

if (text.length % 8 != 0) {
  alert (text + " is not an even binary.\n\nYou may have missed a digit or maybe added an additional digit/character.\n\nSeparaters are NOT required here.")
  return false;
  last;
}
var letasc = ""
lettot = text.length / 8
j=0
for (i=0; i<lettot;i++) {

let = text.substr(j,8);



if (let ==  "01000001") {letasc = letasc + 'A'}
if (let ==  "01000010") {letasc = letasc + 'B'}
if (let ==  "01000011") {letasc = letasc + 'C'}
if (let ==  "01000100") {letasc = letasc + 'D'}
if (let ==  "01000101") {letasc = letasc + 'E'}
if (let ==  "01000110") {letasc = letasc + 'F'}
if (let ==  "01000111") {letasc = letasc + 'G'}
if (let ==  "01001000") {letasc = letasc + 'H'}
if (let ==  "01001001") {letasc = letasc + 'I'}
if (let ==  "01001010") {letasc = letasc + 'J'}
if (let ==  "01001011") {letasc = letasc + 'K'}
if (let ==  "01001100") {letasc = letasc + 'L'}
if (let ==  "01001101") {letasc = letasc + 'M'}
if (let ==  "01001110") {letasc = letasc + 'N'}
if (let ==  "01001111") {letasc = letasc + 'O'}
if (let ==  "01010000") {letasc = letasc + 'P'}
if (let ==  "01010001") {letasc = letasc + 'Q'}
if (let ==  "01010010") {letasc = letasc + 'R'}
if (let ==  "01010011") {letasc = letasc + 'S'}
if (let ==  "01010100") {letasc = letasc + 'T'}
if (let ==  "01010101") {letasc = letasc + 'U'}
if (let ==  "01010110") {letasc = letasc + 'V'}
if (let ==  "01010111") {letasc = letasc + 'W'}
if (let ==  "01011000") {letasc = letasc + 'X'}
if (let ==  "01011001") {letasc = letasc + 'Y'}
if (let ==  "01011010") {letasc = letasc + 'Z'}
if (let ==  "01100001") {letasc = letasc + 'a'}
if (let ==  "01100010") {letasc = letasc + 'b'}
if (let ==  "01100011") {letasc = letasc + 'c'}
if (let ==  "01100100") {letasc = letasc + 'd'}
if (let ==  "01100101") {letasc = letasc + 'e'}
if (let ==  "01100110") {letasc = letasc + 'f'}
if (let ==  "01100111") {letasc = letasc + 'g'}
if (let ==  "01101000") {letasc = letasc + 'h'}
if (let ==  "01101001") {letasc = letasc + 'i'}
if (let ==  "01101010") {letasc = letasc + 'j'}
if (let ==  "01101011") {letasc = letasc + 'k'}
if (let ==  "01101100") {letasc = letasc + 'l'}
if (let ==  "01101101") {letasc = letasc + 'm'}
if (let ==  "01101110") {letasc = letasc + 'n'}
if (let ==  "01101111") {letasc = letasc + 'o'}
if (let ==  "01110000") {letasc = letasc + 'p'}
if (let ==  "01110001") {letasc = letasc + 'q'}
if (let ==  "01110010") {letasc = letasc + 'r'}
if (let ==  "01110011") {letasc = letasc + 's'}
if (let ==  "01110100") {letasc = letasc + 't'}
if (let ==  "01110101") {letasc = letasc + 'u'}
if (let ==  "01110110") {letasc = letasc + 'v'}
if (let ==  "01110111") {letasc = letasc + 'w'}
if (let ==  "01111000") {letasc = letasc + 'x'}
if (let ==  "01111001") {letasc = letasc + 'y'}
if (let ==  "01111010") {letasc = letasc + 'z'}
if (let ==  "00100000") {letasc = letasc + ' '}

//Numbers:
if (let ==  "00110000") {letasc = letasc + '0'}
if (let ==  "00110001") {letasc = letasc + '1'}
if (let ==  "00110010") {letasc = letasc + '2'}
if (let ==  "00110011") {letasc = letasc + '3'}
if (let ==  "00110100") {letasc = letasc + '4'}
if (let ==  "00110101") {letasc = letasc + '5'}
if (let ==  "00110110") {letasc = letasc + '6'}
if (let ==  "00110111") {letasc = letasc + '7'}
if (let ==  "00111000") {letasc = letasc + '8'}
if (let ==  "00111001") {letasc = letasc + '9'}

//Special Characters:
if (let ==  "00100001") {letasc = letasc + '!'}
if (let ==  "00100010") {letasc = letasc + '\"'}
if (let ==  "00100011") {letasc = letasc + '#'}
if (let ==  "00100100") {letasc = letasc + '$'}
if (let ==  "00100101") {letasc = letasc + '%'}
if (let ==  "00100110") {letasc = letasc + '&'}
if (let ==  "00100111") {letasc = letasc + '\''}
if (let ==  "00101000") {letasc = letasc + '('}
if (let ==  "00101001") {letasc = letasc + ')'}
if (let ==  "00101001") {letasc = letasc + '*'}
if (let ==  "00101011") {letasc = letasc + '+'}
if (let ==  "00101100") {letasc = letasc + ','}
if (let ==  "00101101") {letasc = letasc + '-'}
if (let ==  "00101110") {letasc = letasc + '.'}
if (let ==  "00101111") {letasc = letasc + '/'}
if (let ==  "00111010") {letasc = letasc + ':'}
if (let ==  "00111011") {letasc = letasc + ';'}
if (let ==  "00111100") {letasc = letasc + '<'}
if (let ==  "00111101") {letasc = letasc + '='}
if (let ==  "00111110") {letasc = letasc + '>'}
if (let ==  "00111111") {letasc = letasc + '?'}
if (let ==  "01000000") {letasc = letasc + '@'}
if (let ==  "01011011") {letasc = letasc + '['}
if (let ==  "01011100") {letasc = letasc + '\\'}
if (let ==  "01011101") {letasc = letasc + ']'}
if (let ==  "01011110") {letasc = letasc + '^'}
if (let ==  "01011111") {letasc = letasc + '_'}
if (let ==  "01100000") {letasc = letasc + '`'}
if (let ==  "01111011") {letasc = letasc + '{'}
if (let ==  "01111100") {letasc = letasc + '|'}
if (let ==  "01111101") {letasc = letasc + '}'}
if (let ==  "01111110") {letasc = letasc + '~'}
if (let ==  "10000000") {letasc = letasc + '�'}
if (let ==  "10100001") {letasc = letasc + '¡'}
if (let ==  "10100010") {letasc = letasc + '¢'}
if (let ==  "10100011") {letasc = letasc + '£'}
if (let ==  "10100100") {letasc = letasc + '�'}
if (let ==  "10100101") {letasc = letasc + '�'}
if (let ==  "10100110") {letasc = letasc + '�'}
if (let ==  "10100111") {letasc = letasc + '§'}
if (let ==  "10100111") {letasc = letasc + '�'}
if (let ==  "10101001") {letasc = letasc + '�'}
if (let ==  "10101010") {letasc = letasc + '�'}
if (let ==  "10101011") {letasc = letasc + '«'}
if (let ==  "10101100") {letasc = letasc + '�'}
if (let ==  "10101101") {letasc = letasc + '�'}
if (let ==  "10101110") {letasc = letasc + '�'}
if (let ==  "10101111") {letasc = letasc + '�'}
if (let ==  "10110000") {letasc = letasc + '�'}
if (let ==  "10110001") {letasc = letasc + '�'}
if (let ==  "10110010") {letasc = letasc + '�'}
if (let ==  "10110011") {letasc = letasc + '�'}
if (let ==  "10110100") {letasc = letasc + '�'}
if (let ==  "10110101") {letasc = letasc + '�'}
if (let ==  "10110110") {letasc = letasc + '�'}
if (let ==  "10110111") {letasc = letasc + '�'}
if (let ==  "10111000") {letasc = letasc + '�'}
if (let ==  "10111001") {letasc = letasc + '�'}
if (let ==  "10111010") {letasc = letasc + '�'}
if (let ==  "10111011") {letasc = letasc + '»'}
if (let ==  "10111100") {letasc = letasc + '�'}
if (let ==  "10111101") {letasc = letasc + '�'}
if (let ==  "10111110") {letasc = letasc + '�'}
if (let ==  "10111111") {letasc = letasc + '�'}
if (let ==  "11000000") {letasc = letasc + '�'}
if (let ==  "11000001") {letasc = letasc + '�'}
if (let ==  "11000010") {letasc = letasc + '�'}
if (let ==  "11000011") {letasc = letasc + '�'}
if (let ==  "11000100") {letasc = letasc + 'Ä'}
if (let ==  "11000101") {letasc = letasc + 'Å'}
if (let ==  "11000110") {letasc = letasc + 'Æ'}
if (let ==  "11000111") {letasc = letasc + 'Ç'}
if (let ==  "11001000") {letasc = letasc + '�'}
if (let ==  "11001001") {letasc = letasc + '�'}
if (let ==  "11001010") {letasc = letasc + '�'}
if (let ==  "11001011") {letasc = letasc + 'Ë'}
if (let ==  "11001100") {letasc = letasc + '�'}
if (let ==  "11001101") {letasc = letasc + '�'}
if (let ==  "11001110") {letasc = letasc + '�'}
if (let ==  "11001111") {letasc = letasc + '�'}
if (let ==  "11010000") {letasc = letasc + '�'}
if (let ==  "11010001") {letasc = letasc + '�'}
if (let ==  "11010010") {letasc = letasc + '�'}
if (let ==  "11010011") {letasc = letasc + '�'}
if (let ==  "11010100") {letasc = letasc + '�'}
if (let ==  "11010101") {letasc = letasc + '�'}
if (let ==  "11010110") {letasc = letasc + 'Ö'}
if (let ==  "11010111") {letasc = letasc + '�'}
if (let ==  "11011000") {letasc = letasc + 'Ø'}
if (let ==  "11011001") {letasc = letasc + '�'}
if (let ==  "11011010") {letasc = letasc + '�'}
if (let ==  "11011011") {letasc = letasc + '�'}
if (let ==  "11011100") {letasc = letasc + 'Ü'}
if (let ==  "11011101") {letasc = letasc + '�'}
if (let ==  "11011110") {letasc = letasc + '�'}
if (let ==  "11011111") {letasc = letasc + 'ß'}
if (let ==  "11100000") {letasc = letasc + 'à'}
if (let ==  "11100001") {letasc = letasc + 'á'}
if (let ==  "11100010") {letasc = letasc + 'â'}
if (let ==  "11100011") {letasc = letasc + '�'}
if (let ==  "11100100") {letasc = letasc + 'ä'}
if (let ==  "11100101") {letasc = letasc + 'å'}
if (let ==  "11100110") {letasc = letasc + 'æ'}
if (let ==  "11100111") {letasc = letasc + 'ç'}
if (let ==  "11101000") {letasc = letasc + 'è'}
if (let ==  "11101001") {letasc = letasc + 'é'}
if (let ==  "11101010") {letasc = letasc + 'ê'}
if (let ==  "11101011") {letasc = letasc + 'ë'}
if (let ==  "11101100") {letasc = letasc + 'ì'}
if (let ==  "11101101") {letasc = letasc + 'í'}
if (let ==  "11101110") {letasc = letasc + 'î'}
if (let ==  "11101111") {letasc = letasc + '�'}
if (let ==  "11110000") {letasc = letasc + '�'}
if (let ==  "11110001") {letasc = letasc + 'ñ'}
if (let ==  "11110010") {letasc = letasc + 'ò'}
if (let ==  "11110011") {letasc = letasc + 'ó'}
if (let ==  "11110100") {letasc = letasc + 'ô'}
if (let ==  "11110101") {letasc = letasc + '�'}
if (let ==  "11110110") {letasc = letasc + 'ö'}
if (let ==  "11110111") {letasc = letasc + '�'}
if (let ==  "11111000") {letasc = letasc + 'ø'}
if (let ==  "11111001") {letasc = letasc + 'ù'}
if (let ==  "11111010") {letasc = letasc + 'ú'}
if (let ==  "11111011") {letasc = letasc + 'û'}
if (let ==  "11111100") {letasc = letasc + 'û'}
if (let ==  "11111101") {letasc = letasc + '�'}
if (let ==  "11111110") {letasc = letasc + '�'}
if (let ==  "11111111") {letasc = letasc + '�'}
if (letasc == "") {
  alert ("not found")
  break;
}
j=j+8
}
document.bin2asc.ascii.value = letasc
return false;
}
 

