
var TMenu_path_to_files='js/menufiles/';
var menus=[],TM1E,TMF=['click','mouseout','mouseover','hide'];function TMm(TMX){for(var i=0;i<menus.length;i++){if(TMX&&menus[i].TM1C&&!menus[i].TM0H)menus[i].TM1C.TM1v.menus[i].TM1V();menus[i].TM1V();menus[i].TMG=true;}this.TMJ=true;}function TMn(TMY){var TM0z;if(this.width!=(TM0z=this.TM02(window))){this.width=TM0z;TMX=TMY=true;}if(this.height!=(TM0z=this.TMy(window))){this.height=TM0z;TMX=TMY=true;}if(this.TM1x!=(TM0z=this.TM04(window))){this.TM1x=TM0z;TMY=true;}if(this.TM1z!=(TM0z=this.TM05(window))){this.TM1z=TM0z;TMY=true;}if(TMY){this.TMJ=false;this.TM1V(TMX)}}function menu(TM0J,TM18,TM14){this.TM0J=TM0J;this.TM18=TM18;this.TM19=[];this.TM0K=[];this.TM9=[];this.exec=TM0O;this.hide=TM0P;this.onhide=TM0S;this.onclick=TM0R;this.onmouseout=TM0T;this.onmouseover=TM0U;this.TM1V=TM0V;this.TMf=TM0_;this.TM1R=this.TMW=this.TM13=0;this.TM1g=function(){};if(TM14){this.TM13=TM14.zIndex||0;this.TM00=TM14.onexpand&&typeof(TM14.onexpand)=='function'?TM14.onexpand:null;this.TMz=TM14.oncollapse&&typeof(TM14.oncollapse)=='function'?TM14.oncollapse:null;if(TM14.wrapper&&typeof(TM14.wrapper)=='function')this.TM03=TM14.wrapper;this.TM0H=Boolean(TM14.frames);this.TMW=TM14.popup?-1:0;this.TMa=Boolean(TM14.showroot);this.TMK=Boolean(TM14.clickcollapse);var TM7=TM14.frames;if(this.TMW){this.collapse=TM0Y;this.expand=TM0Z;if(document.images[TM14.popup]){this.elements=[document.images[TM14.popup]];this.TM1U=TM0d;}else this.TM1U=function(){};}if(TM14.forms){this.TM6=TM14.forms;this.TM1g=TM0;}}if(!this.TM03)this.TM03=TM0g;this.TM1A={'width':100,'height':20,'block_top':null,'block_left':null,'vertical':false,'expd_delay':0,'hide_delay':100,'table':[0,0,0],'css':{'table':'','inner':'','outer':''}};this.TMi=-1;this.TM1O=this;this.TM0A=function(TM1c){return this.TM1A[TM1c];};if(!TM1E){TM1E=new TMl();TM1E.TM1L={'x':0,'y':0};TM1E.TMI=navigator.userAgent.indexOf('Gecko')>-1;TM1E.TM1T=TMenu_path_to_files+'pixel.gif';if(TM1E.TMR){document.write('<div id="TMAnchor" style="position:absolute">.</div>');TM1E.TMo=TM1E.TM09('TMAnchor');}if(TM1E.TMI){document.write('<div id="TMAnchor" style="position:absolute;width:100%;height:100%;top:0;left:0;visibility:hidden"></div>');TM1E.TMp=TM1E.TM09('TMAnchor');}if(!TM1E.TM1d)TM1E.TM1d='onload';TM1E.TM02=window.innerWidth!=null?function(w){return w.innerWidth}:function(w){return w.document.body.offsetWidth};TM1E.TMy=window.innerHeight!=null?function(w){return w.innerHeight}:function(w){return w.document.body.offsetHeight};TM1E.TM04=window.pageXOffset!=null?function(w){return w.pageXOffset}:function(w){return w.document.body.scrollLeft};TM1E.TM05=window.pageYOffset!=null?function(w){return w.pageYOffset}:function(w){return w.document.body.scrollTop};TM1E.TM1V=TMm;TM1E.TMs=TMn;}this.id=TM14&&TM14.key?TM14.key:menus.length;menus[this.id]=this;this.TM1l=[];this.TMg=this.TM0J.length;this.TMZ=Boolean(this.TM18[0].block_top==null&&this.TM18[0].block_left==null);for(var i=0;i<this.TMg;i++)new TM0Q(i,this,this,i);this.TMf(1);this.TM0M=this.TM15;for(i=0;i<this.TM9.length;i++)this.TM9[i].links();if(top!=window&&(TM7&&(TM7+'').indexOf(',')>-1||!TM7)){TM1E.TM1H=TM1E.TMP||(window.opera&&document.appendChild)||TM1E.TMS?top.document.body:top;if(window.frameElement!=null)TM1E.TMy=function(w){return w.frameElement.offsetHeight};if(!top.TM1){top.TM1={'TMB':[]};var TM0w,TM1W=TM1E.TM1H[TM1E.TM1d]?new String(TM1E.TM1H[TM1E.TM1d]):'';if((TM0w=TM1W.indexOf('{'))>-1)TM1W=TM1W.substring(TM0w+1,TM1W.lastIndexOf('}')-1)+';';TM1E.TM1H[TM1E.TM1d]=Function(TM1W+'top.TM1.TM01()');}if(!top.TM1.TMB[this.id])top.TM1.TMB[this.id]={'TM0n':0,'TM7':[],'TM5':[],'TM8':[]};if(this.TM0H&&!top.TM1.TM01){top.TM1.TM01=function(){for(var TM0q=0;TM0q<this.TMB.length;TM0q++){if(this.TMB[TM0q].TM0n<2){this.TMB[TM0q].TM8[0].TM1C=null;return this.TMB[TM0q].TM7[0].setInterval('TM1E.TMs()',500);}for(var TM0t=0;TM0t<this.TMB[TM0q].TM7.length;TM0t++)if(this.TMB[TM0q].TM7[TM0t]&&this.TMB[TM0q].TM7[TM0t].TM1E)this.TMB[TM0q].TM7[TM0t].TM1E.TMs();}setTimeout('top.TM1.TM01()',200)};top.TM1.TMx=function(TM0v,TM0r,TM0h){var TM8=this.TMB[TM0v].TM8;for(var TM0q=0;TM0q<TM8.length;TM0q++)if(TM8[TM0q]&&!TM8[TM0q].TM0K[TM0r])return setTimeout('top.TM1.TMx("'+TM0v+'","'+TM0r+'",'+TM0h+')',100);for(TM0q=0;TM0q<TM8.length;TM0q++)if(TM8[TM0q])TM8[TM0q]['on'+TMF[TM0h]](TM0r);};}var TM17=this.TM1C=top.TM1.TMB[this.id];if(TM17.TM5[name]==null){TM17.TM5[name]=TM17.TM0n;TM17.TM0n++;}TM17.TM7[TM17.TM5[name]]=window;TM17.TM8[TM17.TM5[name]]=this;if(this.TM0H){TM17.TM1v=window;this.TM7=[];for(i=0;i<TM7.length;i++){this.TM7[i]=[];for(var j=0;j<TM7[i].length;j++)this.TM7[i][j]=eval('top.'+TM7[i][j]);}}window.onunload=function(){for(var TM0q=0;TM0q<menus.length;TM0q++){if(menus[TM0q].TM1C){menus[TM0q].TM1C.TM7[menus[TM0q].TM1C.TM5[name]]=menus[TM0q].TM1C.TM8[menus[TM0q].TM1C.TM5[name]]=null;}}};this.TMK=1;}else if(document.layers)window.onload=function(){setInterval('TM1E.TMs()',200)};else if(!TM1E.TM1n)TM1E.TM1n=setInterval('TM1E.TMs()',200);}function TM0V(){if(this.TM1C){this.TM7=this.TM1C.TM1v.menus[this.id].TM7;if(this.TM0H){var TM1y=0,TM1w;this.TM1C.TM0N=[];for(i=0;i<this.TM7.length;i++){TM1w=0;for(j=0;j<this.TM7[i].length;j++){if(!this.TM1C.TM0N[this.TM7[i][j].name])this.TM1C.TM0N[this.TM7[i][j].name]={'x':TM1w,'y':TM1y};TM1w+=TM1E.TM02(this.TM7[i][j]);}TM1y+=TM1E.TMy(this.TM7[i][--j]);}this.TM1C.TM0M=TM1E.TMu(this.TM0M,this.TM1C.TM0N[window.name].x-TM1E.TM04(window),this.TM1C.TM0N[window.name].y-TM1E.TM05(window),TM1E.TMS);}else{TM1E.TMw(this.TM0M,{'x':this.TM1C.TM0M.x-this.TM1C.TM0N[window.name].x+TM1E.TM04(window),'y':this.TM1C.TM0M.y-this.TM1C.TM0N[window.name].y+TM1E.TM05(window)});if(this.TMa)TM1E.TMv(this.TM0M,1);}}if(document.layers)for(var TM0q=0;TM0q<this.TMg;TM0q++)this.TM9[TM0q].TM1h(0);else if(TMV&&!TM1E.TMR)for(var TM0q=0;TM0q<this.TMg;TM0q++)this.TM9[TM0q].TM1U();}function TM0O(id,TM0h){if(!TM1E.TMJ)return;if(this.TM1C&&TM0h)top.TM1.TMx(this.id,id,TM0h);else return menus[this.id]['on'+TMF[TM0h]](id);}function TM0P(){if(this.TM1R>0||!this.TM1p)return;if(this.TM0L)this.TM0L.collapse(this.TMW);this.TM0L=null;if(this.TMz)this.TMz();if(TM1E.TMp)TM1E.TMv(TM1E.TMp);if(!TM1E.TM0G&&!TM1E.TMI)this.TM1g(true);}function TM0S(){if(this.TM0L)this.TM0L.collapse(this.TMW);this.TM0L=null;this.TM1R=0;}function TM0R(id){var i=this.TM0K[id],TMN=Boolean(i.TM4[1]);if(i.TM9&&i.TM1M.TM9[0].TM0m<0)i.expand();else if(i.TMK==null&&this.TMK||i.TMK)this.exec(id,1);i.TM1h(2);return TMN;}function TM0T(id){this.TM1R--;this.TM0K[id].TM1h(0);if(this.TM1o)clearTimeout(this.TM1o);this.TM1p=setTimeout('menus["'+this.id+'"].hide()',this.TM0K[id].TM0A('hide_delay'));if(this.TM0K[id].TM19.sb!=null)top.status='';if(this.TM0K[id].TM19.oo!=null)this.TM0K[id].TM19.oo(id);}function TM0U(id){if(window.event)event.cancelBubble=true;if((TM1E.TMI||window.opera)&&this.TM0K[id].TM1j==1)return;this.TM1R++;for(var TM1J=this.TM0K[id];TM1J!=this;TM1J=TM1J.TM1M)TM1J.TM1h(1);var TM1J=this.TM0K[id];clearTimeout(this.TM1p);this.TM1p=null;if(TM1J.TM19.sb!=null)setTimeout('menus["'+this.id+'"].TM0K["'+id+'"].TM1i()',10);this.TM1I=TM1J;if(TM1J.TM19.oh!=null)TM1J.TM19.oh(id);if(TM1J.TM1M.TM9[0].TM0m<0)return;if(TM1J.TM1M.TM9[0].TM0m)this.TM1o=setTimeout('menus["'+this.id+'"].TM0K["'+id+'"].expand()',TM1J.TM1M.TM9[0].TM0m);else TM1J.expand();}function TM0Q(TM1S,TM1M,TM1O,TM0s){this.id=this.TM1S=new String(TM1S);this.TM1M=TM1M;this.TM1O=TM1O;this.TMH=this.TM1S.split('_');this.TMi=this.TMH.length-1;var TM1k='';for(var i=0;i<=this.TMi;i++)TM1k+='['+(Number(this.TMH[i])+(i?3:0))+']';eval('this.TM4 = this.TM1O.TM0J'+TM1k);if(!this.TM4)return;this.TM19=this.TM4[2]?this.TM4[2]:[];this.TM1O.TM0K[this.id]=this;TM1M.TM9[TM1M.TM9.length]=this;this.TM1h=TM0e;this.TM1i=TM0f;this.TM1U=TM0d;this.TM03=this.TM1O.TM03;this.TMf=TM0X;this.TM0A=TM0a;this.TM08=TM0b;this.links=TM0c;this.collapse=TM0Y;this.expand=TM0Z;this.TMK=this.TM19.cc;if(!TM0s){this.TM0k=this.TM1M.TM19.bt||this.TM0A('block_top');this.TM0j=this.TM1M.TM19.bl||this.TM0A('block_left');this.TMM=this.TM0A('top')<0;this.TML=this.TM0A('left')<0;this.TM11=this.TM0A('width');this.TM0p=this.TM0A('height');this.TMd=this.TM0A('vertical');this.TM12=this.TM0A('wise_pos');this.TM0m=this.TM0A('expd_delay');}var TM10=this.TM1M.TM9[0].TM11,TM0o=this.TM1M.TM9[0].TM0p;if(this.TM1M.TM9[0].TMd){if(this.TM1M.TM19.bw!=null)TM10=this.TM1M.TM19.bw;if(this.TM19.sh!=null)TM0o=this.TM19.sh;}else{if(this.TM1M.TM19.bh!=null)TM0o=this.TM1M.TM19.bh;if(this.TM19.sw!=null)TM10=this.TM19.sw;}this.TM1M.TM1l[TM0s]=this.TMf(TM10,TM0o);this.TMg=this.TM4.length-3;if(this.TMg>0&&this.TM4[3]){this.TM9=[];this.TMq=TM0_;this.TMr=TM0W;if(TMV&&!document.layers){this.TMr();this.TMb=this.TMi==0&&this.TM1O.TMZ;}}}function TM0g(TM1Y){return TM1Y;}function TM0W(){this.TM1l=[];for(var i=0;i<this.TMg;i++)if(this.TM4[3+i])new TM0Q(this.TM1S+'_'+i,this,this.TM1O,i);else this.TMg--;this.TMq();for(i=0;i<this.TM9.length;i++)this.TM9[i].links();}function TM0f(){top.status=this.TM19.sb;}function TM0a(TM1c){var TM1f=null,TMA=this.TM1O.TM18[this.TMi];if(TMA)TM1f=TMA[TM1c];return(TM1f==null?this.TM1M.TM0A(TM1c):TM1f);}function TM0b(TM1e,TM0x){var TM3=this.TM0A('css'),TMC=TM3[TM1e];if(typeof(TMC)=='string')return TMC;for(var TM0l=TM0x;TM0l>=0;TM0l--)if(TMC[TM0l])return TMC[TM0l];}function TM0d(TMh,value){if(this.TMg>0){if(TM1E.TMR){TM1E.TMw(TM1E.TMo,{'x':0,'y':0});TM1E.TM1L=TM1E.TMu(TM1E.TMo,0,0);TM1E.TMR=0;}var TM1K=this.TM9[0],TM1N=TM1E.TMu(this.elements[0],(this.TM19.bl?this.TM19.bl:TM1K.TM0j)-TM1E.TM1L.x,(this.TM19.bt?this.TM19.bt:TM1K.TM0k)-TM1E.TM1L.y,this.TMb);if(TM1K.TML)TM1N.x-=TM1E.TMt(this.TM15);if(TM1K.TMM)TM1N.y-=TM1E.TMt(this.TM15,1);if(TM1K.TM12&&!this.TM1O.TM1C){var wise=TM1K.TM12,TM1s=TM1E.TMt(this.TM15,0),TM0B=TM1E.TMt(this.TM15,1),TM1u=TM1E.TM02(window),TM0D=TM1E.TMy(window),TM1t=TM1E.TM04(window),TM0C=TM1E.TM05(window);if(TM1N.x+TM1s>TM1u+TM1t)TM1N.x=(wise==1?TM1u+TM1t:TM1N.x)-TM1s;if(TM1N.y+TM0B>TM0D+TM0C)TM1N.y=(wise==1?TM0D+TM0C:TM1N.y)-TM0B;if(TM1N.x<TM1t)TM1N.x=TM1t;if(TM1N.y<TM0C)TM1N.y=TM0C;}TM1E.TMw(this.TM15,TM1N);if(this.TM16)TM1E.TMw(this.TM16,TM1N);if(TMV&&!document.layers)for(var TM0q=0;TM0q<this.TMg;TM0q++)this.TM9[TM0q].TM1U();}}var TME=navigator.appVersion.split('MSIE '),TMV=window.opera||TME.length<2||parseFloat(TME[1])<5||(navigator.appVersion.indexOf('Mac')>-1&&navigator.appVersion.indexOf('MSIE')>-1)||navigator.userAgent.indexOf('Konqueror')>-1;document.write('<scr','ipt language="JavaScript" src="',TMenu_path_to_files,'menu.',(document.layers?'lay':TMV?'opr':'dom'),'.js"></scr','ipt>');

var MENU_ITEMS_V = [['Home','index.php?page=home'],['History','index.php?page=history'],['Training Courses', '',{'tw' : '_self'},['Personal Resilience at Work','index.php?page=personalresilienceatwork'],['Influence at Work','index.php?page=influenceatwork'],['The Influential Presenter','index.php?page=theinfluentialpresenter'],['The Stress Manager&#39;s Toolbox','index.php?page=thestressmanagerstoolbox'],['The Time Manager&#39;s Toolbox','index.php?page=thetimemanagerstoolbox'],['The Influential Leader','index.php?page=theinfluentialleader'],['The Art of Conflict Resolution','index.php?page=theartofconflictresolution'],['Neuro Linguistic Programming','index.php?page=neurolinguisticprogramming'],['Customer Care','index.php?page=customercare'],['Practical Negotiation at Work','index.php?page=practicalnegotiationatwork'],['Professional Development Coaching','index.php?page=professionaldevelopmentcoaching'],],['Fan Mail', '',{'tw' : '_self'},['AT&T','files/Fan_Mail_att.pdf'],['Centrex','files/Fan_Mail_ncof.pdf'],['First Data Resources','files/Fan_Mail_fdr.pdf'],['Hutchison Telecoms','files/Fan_Mail_Hutchison.pdf'],['Lloyds TSB','files/Fan_Mail_Lloydstsb.pdf'],['University of Essex','files/Fan_Mail_Uni_Essex.pdf'],['Wilson Miller','files/Fan_Mail_WilsonMiller.pdf'],],['Contact Us','index.php?page=contact'],];
var MENU_ITEMS_H = [['Terms & Conditions','index.php?page=termsconditions'],['Privacy Policy',''],];

var MENU_POS_V = [
{
	// item sizes
	'width': 130,
	'hide_delay': 800,
	'expd_delay': 100,
	'vertical': true,
	'css' : {
		'outer': ['vert_main_out_outer', 'vert_main_over_outer'],
		'inner': ['vert_main_out_inner', 'vert_main_over_inner'],
		'table' : 'vert_main_table'
	}
},
{
	'width': 250,
	'block_top': 3,
	'block_left': 100,
	'top': 19,
	'left': 0,
	'vertical': true,
	'hide_delay': 800,
	'expd_delay': 100,
	'wise_pos': 1,
	'css': {
		'outer' : ['vert_sub_out_outer', 'vert_sub_over_outer'],
		'inner' : ['vert_sub_out_inner', 'vert_sub_over_inner'],
		'table' : 'vert_sub_table'
	}
},
{
	'height': 19,
	'width': 250,
	'block_top': 3,
	'block_left': 100,
	'top': 19,
	'left': 0,
	'vertical': true,
	'hide_delay': 800,
	'expd_delay': 100,
	'wise_pos': 1,
	'css': {
		'outer' : ['vert_sub_out_outer', 'vert_sub_over_outer'],
		'inner' : ['vert_sub_out_inner', 'vert_sub_over_inner'],
		'table' : 'vert_sub_table'
	}
}
];
var MENU_POS_H = [
{
	// item sizes
	'height': 20,
	'width': 130,
	'hide_delay': 800,
	'expd_delay': 100,
	'css' : {
		'outer': ['horiz_main_out_outer', 'horiz_main_over_outer'],
		'inner': ['horiz_main_out_inner', 'horiz_main_over_inner'],
		'table' : 'horiz_main_table'
	}
},
{
	'width': 150,
	'block_top': 22,
	'block_left': 0,
	'top': 19,
	'left': 0,
	'horizical': true,
	'hide_delay': 800,
	'expd_delay': 100,
	'wise_pos': 1,
	'css': {
		'outer' : ['horiz_sub_out_outer', 'horiz_sub_over_outer'],
		'inner' : ['horiz_sub_out_inner', 'horiz_sub_over_inner'],
		'table' : 'horiz_sub_table'
	}
},
{
	'height': 19,
	'width': 150,
	'block_top': -1,
	'block_left': 150,
	'top': 19,
	'left': 0,
	'horizical': true,
	'hide_delay': 800,
	'expd_delay': 100,
	'wise_pos': 1,
	'css': {
		'outer' : ['horiz_sub_out_outer', 'horiz_sub_over_outer'],
		'inner' : ['horiz_sub_out_inner', 'horiz_sub_over_inner'],
		'table' : 'horiz_sub_table'
	}
}
];


// Popup windows 

var newwin;

function launchwin(winurl,winname,winfeatures) {
	    
  if(newwin) { newwin.close(); }
  newwin = window.open(winurl,winname,winfeatures);
  newwin.focus();
}

function placeFocus() {
  if (document.forms.length > 0) {
    var field = document.forms[0];
      for (i = 0; i < field.length; i++) {
        if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
        document.forms[0].elements[i].focus();
        break;
        }
      }
  }
}      

// Return characters pressed, in input boxes etc, and filter (e.g. numbers only)

function getkey(e) {
  if (window.event)
   return window.event.keyCode;
  else if (e)
   return e.which;
  else
   return null;
}

function goodchars(e, goods) {

  var key, keychar;
  key = getkey(e);
  if (key == null) return true;

  // get character
  keychar = String.fromCharCode(key);
  keychar = keychar.toLowerCase();
  goods = goods.toLowerCase();

  // check goodkeys
  if (goods.indexOf(keychar) != -1)
	return true;

  // control keys
  if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
     return true;

  // else return false
  return false;
}

function changeqty(dir, id) {

  currentqty = parseInt(document.getElementById(id).value);
  if (dir=='up') document.getElementById(id).value = currentqty+1;
  else if (dir=='down' && currentqty > 1)
    document.getElementById(id).value = currentqty-1;
  else if (dir=='down' && currentqty < 2)
    document.getElementById(id).value = 1;
}

function checksearch(searchform,searchbox)
{
  if (document.forms[searchform].elements[searchbox].value == "") {
    alert( "Please enter your criteria in the search box." );
    document.forms[searchform].elements[searchbox].focus();
    return false;
  }
  else if (document.forms[searchform].elements[searchbox].value.length < 4) {
    alert( "Search term should be more than 3 characters" );
    document.forms[searchform].elements[searchbox].focus();
    return false;
  }
  else return true;
}

function show_ee() {
  //
}

// CHAP for site login

var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}
function doCHAP() {
  var password=document.getElementById('psw').value;
  document.getElementById('challenge').value=hex_md5(hex_md5(password)+'');
  document.getElementById('psw').value='';
  return true;
} 