var tke={};
tke.logon={};
tke.logon.hide=function(){tke.logwin.hide();}
tke.logon.logoff=function(){tke.logon.hide();window.location='/logoff.php';}
tke.logon.register=function(){tke.logon.hide();window.location='/register.php';}
tke.logon.register=function(){_ge('logonform').style.display='none';_ge('preregisterform').style.display='block';tke.logwin.setSize(550,370);_ge('preregNext').focus();}
tke.logon.resetpw=function(){
 var u=_ge('userid');
 if(!u.value){
  alert('Enter your user id or email address and we will reset your password');
  u.focus();
  return;
 }
 url='jack.php?o=rp&a='+u.value;
 alert('The url to reset your password is "'+url+'"');
 garyRPC(url);
 alert('Use the link sent to your email address to reset your password.\n\nIf the information entered is invalid, we will ignore this request. While we would like to tell you that your entry is invalid, bad people use those replies to figure out who has accounts with us and then attack those accounts. We regret the inconvenience this causes good people, but for the protection of all of our users, we can\'t advise you when you make a mistake. If you don\'t get your email within 5 minutes, come back and request it again being very careful what you type. In an extreme case, you may also want to have a friend send you an email from a different account to be sure that you are able to recieve emails. You may also email webmaster@tke.coop if you are unable to resolve the issue yourself.')
 tke.logon.hide(); // window.location='/register.php';
}
tke.logon.show=function(){
 var item=_ge('log');
 var state=item.innerHTML;
 if(state=='Logon'){
  tke.logwin=dhtmlmodal.open('logwin','div','logondiv','UPMC Login','width=300px,height=260px,left=670px,top=100px,center=0,resize=0,scrolling=0');
  //tke.logwin=dhtmlwindow.open('logwin','div','logondiv','UPMC Login','width=306px,height=234px,left=670px,top=100px,center=0,resize=0,scrolling=0');
  _ge('logonform').style.display='block';
  _ge('preregisterform').style.display='none';
  _ge('registerform').style.display='none';
  _ge('loginMsg').innerHTML='';
  _ge('userid').focus(); // ie bug requires one before the other
  _ge('userid').select();
  /*
  tke.logwin.onclose=function(){ //Define custom code to run when window is closed
	  return true; //Allow closing of window in any case
  }
  */
 }else{ // if state is log off
  var x=_ge('logoffdiv');
  if(x){
   tke.logwin=dhtmlmodal.open('logwin','div','logoffdiv','UPMC Logoff','width=300px,height=260px,left=670px,top=100px,center=0,resize=0,scrolling=0');
   var y=_ge('logoffform');
   y.style.display='block';
   _ge('logoffMsg').innerHTML='';
   // alert(y.offsetHeight);
//   alert(y.offsetWidth);
  // alert(_ge('logwin').offsetWidth);
   tke.logwin.setSize(y.offsetWidth+8,y.offsetHeight+6)
  }else{
   window.location='/logoff.php'
  }
 }
// alert('wait here');
}
tke.logon.submit=function(){
	var	x=_ese();
 while(x.parentNode	&&	x.tagName!='FORM'){x=x.parentNode;}
 // alert(x.action);
 // x.submit();
 ui=_ge('userid');
 if(!ui.value){
  alert('Please enter your user id');
  ui.focus();
  return false;
 }
 pw=_ge('password');
 if(!pw.value){
  alert('Please enter your password');
  pw.focus();
  return false;
 }
 // alert(_ge('loginMsg').outerHTML);return;
 // tke.logon.hide();
 var t=new Date();
 t=parseInt(t.getTime()/1000).toString();
 //var url='\login.php?u='+ui.value+'&t='+t+'&h='+hex_md5(pw.value)+'&x='+hex_md5(hex_md5(pw.value)+t);
 var url='\login.php?u='+ui.value+'&t='+t+'&x='+hex_md5(hex_md5(pw.value)+t);
 //alert(url);
 if(false){
  window.location=url;
 }else{
  garyRPC(url);
 }
}

// need to RPC to login.php to update the session variables with the desired org
// loging replies with javascript to refresh the current page, possibly by sending you home
// when the page reloads it will be with grants and menus appropriate to your new role
// send the swap info to login by way of an index number so that people can't ask for orgs that they should not.

// need to check for either hidden field or dropdown to know which org to swap to.

// if the selected dropdown is same as current, just hide? or for programming, force a reload without putting in pw?
// Now just hide, I can force a reload by switcing out then back.
tke.logon.swap=function(){
 var org=_ge('selectNewOrg');
 var url='\login.php?o='+org.value;
 // alert(url);
 garyRPC(url);
}
 
// dead? tke.logon.hide();return;alert('Need to swap roles here');} // do what you need to do to toggle titles

tke.register={};
tke.register.checkBack=function(){ // if form is dirty, confirm escape
 return confirm('OK to loose changes?');
};
tke.register.checkForm=function(){
 var x=_ge('user');
 if(!x.value){alert('Please specifiy a user id');x.focus();return false;}
 if(_ge('userMsg').innerText){alert('This user id is already in use');x.select();return false;}
 var u=x;
 var x=_ge('password');
 if(!x.value){alert('Please specifiy a password');x.focus();return false;}
 var y=_ge('confirm');
 if(x.value!=y.value){alert('Passwords do not match, please enter them again');x.select();return false;}
 var p=x;
 // this code is if we want to ajax it
 var url='register.php?o=ru&ui='+u.value+'&nm='+_ge('name').value+'&pw='+p.value+'&x='+hex_md5(p.value);
 //alert(url);
 garyRPC(url);
 return true;

 // this code is if we want to post the data.
 var el=_ese();
 while(el.tagName!='FORM' && el.parentNode){el=el.parentNode;}
 if(el){el.submit();}
 return true;
}; 
tke.register.checkPass=function(){ // Verify that passwords, if entered, match
 var x=_ge('password');
 var y=_ge('confirmpw');
 _ge('passMsg').innerHTML=((x.value && y.value && x.value!=y.value)?'Passwords do not match':'');
}
tke.register.checkUser=function(){
 var se=_ese();
 if(!se.value){
  _ge('userMsg').innerHTML='This field is required!';
  return;
 }
 var url='register.php?o=cu&u='+se.value; // need to encode that to be url safe!!!!!!
 //alert(url);
 garyRPC(url);
}; 


// begin slide show
function pashow(p1){
 document.getElementById('big').src=p1;
 document.getElementById('thumbs').style.display='none';
 document.getElementById('show').style.display='block';
 return false;
}

function pahide(){
 document.getElementById('show').style.display='none';
 document.getElementById('thumbs').style.display='block';
 return false;
}
// end slide show

// begin vbscript compatability code
function Asc(CHARACTER){
 return CHARACTER.charCodeAt(0)
}

function CBool(VALUE){
 VALUE=new String(VALUE);
 VALUE=VALUE.toLowerCase();
 if(VALUE== '1' || VALUE=='-1' || VALUE=='true' || VALUE=='yes'){
  return true;
 }else{
  return false;
 }
}

function Chr(CHARACTER_CODE){
 return String.fromCharCode(CHARACTER_CODE);
}

function CInt(number){
 return parseInt(number);
}

function CStr(VALUE){
return VALUE.toString();
}

function CSng(number){
return parseFloat(number);
}

function CDbl(number){
return parseFloat(number);
}

function CreateObject(STRING){
 var MY_OBJECT=new ActiveXObject(STRING);
 return MY_OBJECT
}


function Eval(STRING){
 eval(STRING);
}

function FormatCurrency(FIGURE){
 if(!FIGURE||FIGURE==''){
  return '0.00';
 }
 var strTemp=FIGURE.toString();
 while(strTemp.indexOf(',') > -1){
  strTemp=strTemp.replace(',','');
 }
 strTemp=parseFloat(strTemp);
 FIGURE=Round(FIGURE,2);
 FIGURE=FIGURE.toString();
 var Place=FIGURE.indexOf('.');
 if(Place >-1){
  if((FIGURE.length - Place)==2){
   FIGURE+='0';
  }
 }else{
  FIGURE+='.00';
 }
 if(FIGURE=='0.00'){
  return'';
 }
 return FIGURE;
}

function FormatDate(DateToFormat,FormatAs){
 if(DateToFormat==''){return'';}
 if(!FormatAs){FormatAs='dd/mm/yyyy';}
 var strReturnDate;
 FormatAs=FormatAs.toLowerCase();
 DateToFormat=DateToFormat.toLowerCase();
 var arrDate
 var arrMonths=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
 var strMONTH;
 var Separator;

 while(DateToFormat.indexOf('st')>-1){
  DateToFormat=DateToFormat.replace('st','');
 }

 while(DateToFormat.indexOf('nd')>-1){
  DateToFormat=DateToFormat.replace('nd','');
 }

 while(DateToFormat.indexOf('rd')>-1){
  DateToFormat=DateToFormat.replace('rd','');
 }

 while(DateToFormat.indexOf('th')>-1){
  DateToFormat=DateToFormat.replace('th','');
 }

 if(DateToFormat.indexOf('.')>-1){
  Separator='.';
 }

 if(DateToFormat.indexOf('-')>-1){
  Separator='-';
 }

 if(DateToFormat.indexOf('/')>-1){
  Separator='/';
 }

 if(DateToFormat.indexOf(' ')>-1){
  Separator=' ';
 }

 arrDate=DateToFormat.split(Separator);
 DateToFormat='';
  for(var iSD=0;iSD < arrDate.length;iSD++){
   if(arrDate[iSD]!=''){
   DateToFormat+=arrDate[iSD]+Separator;
   }
  }
 DateToFormat=DateToFormat.substring(0,DateToFormat.length-1);
 arrDate=DateToFormat.split(Separator);

 if(arrDate.length < 3){
  return '';
 }

 var DAY=arrDate[0];
 var MONTH=arrDate[1];
 var YEAR=arrDate[2];

if(parseFloat(arrDate[1]) > 12){
 DAY=arrDate[1];
 MONTH=arrDate[0];
}

if(parseFloat(DAY) && DAY.toString().length==4){
 YEAR=arrDate[0];
 DAY=arrDate[2];
 MONTH=arrDate[1];
}

for(var iSD=0;iSD < arrMonths.length;iSD++){
 var ShortMonth=arrMonths[iSD].substring(0,3).toLowerCase();
 var MonthPosition=DateToFormat.indexOf(ShortMonth);
	if(MonthPosition > -1){
	 MONTH=iSD+1;
		if(MonthPosition==0){
		 DAY=arrDate[1];
		 YEAR=arrDate[2];
		}
	 break;
	}
}

var strTemp=YEAR.toString();
if(strTemp.length==2){
	if(parseFloat(YEAR)>40){
	 YEAR='19'+YEAR;
	}else{
	 YEAR='20'+YEAR;
	}
}

	if(parseInt(MONTH)< 10 && MONTH.toString().length < 2){
	 MONTH='0'+MONTH;
	}
	if(parseInt(DAY)< 10 && DAY.toString().length < 2){
	 DAY='0'+DAY;
	}
	switch (FormatAs){
	case 'dd/mm/yyyy':
	 return DAY+'/'+MONTH+'/'+YEAR;
	case 'mm/dd/yyyy':
	 return MONTH+'/'+DAY+'/'+YEAR;
	case 'dd/mmm/yyyy':
	 return DAY+' '+arrMonths[MONTH -1].substring(0,3)+' '+YEAR;
	case 'mmm/dd/yyyy':
	 return arrMonths[MONTH -1].substring(0,3)+' '+DAY+' '+YEAR;
	case 'dd/mmmm/yyyy':
	 return DAY+' '+arrMonths[MONTH -1]+' '+YEAR;	
	case 'mmmm/dd/yyyy':
	 return arrMonths[MONTH -1]+' '+DAY+' '+YEAR;
	}
 return DAY+'/'+strMONTH+'/'+YEAR;
}

function FormatPercent(number,PLACES){
	number=number*100
	if(PLACES){
	 number=Round(number,PLACES);
	}else{
	 number=Round(number,2);
	 number=FormatCurrency(number);
	}
	number+='%';
return number;
}

function GetDate(FORMAT){
 var m_TODAY=new Date();
 var m_Day=m_TODAY.getDate();
 var m_Month=(m_TODAY.getMonth()+1)
 var MY_DATE=m_Day+'/'+m_Month+'/'+m_TODAY.getYear();

 if(!FORMAT){
  FORMAT='mm/dd/yyyy';
  MY_DATE=m_Month+'/'+m_Day+'/'+m_TODAY.getYear();
 }
 MY_DATE=FormatDate(MY_DATE,FORMAT);
 return MY_DATE;
}

function IsArray(MY_ARRAY){
 MY_ARRAY=MY_ARRAY.constructor.toString();
 if(InStr(MY_ARRAY,'Array') > 0){
  return true;
 }else{
  return false;
 }
}

function IsNull(ITEM){
 if(ITEM==null || ITEM==undefined){
  return true;
 }
 return false;
}

function Join(ARRAY,DELIMITER){
 ARRAY=ARRAY.toString();
 if(DELIMITER){
  ARRAY=Replace(ARRAY,',',DELIMITER);
 }else{
  ARRAY=Replace(ARRAY,',',' ');
 }
 return ARRAY;
}

function Now(){
 var NOW=new Date().toString();
 var arrNOW=NOW.split('UTC')
 NOW=arrNOW[0];
 return NOW;
}


function Round(number,PLACES){
 if(!isNumeric(number)){
  return '0';
 }
 number=CStr(number);
 arrnumber=number.split('.');
 if(arrnumber.length==1){return number;}
 if(PLACES){
  number=Math.round(number*Math.pow(10,PLACES))/Math.pow(10,PLACES);
 }else{
  number=Math.round(number);
 }
 return number;
}

function IsDate(DateToCheck){
 if(DateToCheck==''){return true;}
 var m_strDate=FormatDate(DateToCheck);
 if(m_strDate==''){
  return false;
 }
 var m_arrDate=m_strDate.split('/');
 var m_DAY=m_arrDate[0];
 var m_MONTH=m_arrDate[1];
 var m_YEAR=m_arrDate[2];
 if(m_YEAR.length > 4){return false;}
 m_strDate=m_MONTH+'/'+m_DAY+'/'+m_YEAR;
 var testDate=new Date(m_strDate);
 if(testDate.getMonth()+1==m_MONTH){
  return true;
 }else{
  return false;
 }
} //end function

function isNumeric(VALUE){
 for(var ivA=0; ivA < VALUE.length;ivA ++){
  if(VALUE.charCodeAt(ivA) < 48 || VALUE.charCodeAt(ivA) > 57){
	  if(VALUE.charCodeAt(ivA) != 46 && VALUE.charCodeAt(ivA) != 32 && VALUE.charAt(ivA) != ','){
	   return false;
	  }
  }																					
 }
 return true;
}

function TitleCase(STRING){
 var Exceptions='About/about|Above/above|Across/across|After/after|Against/against|Around/around|At/at|Before/before|Behind/behind|Below/below|Beneath/beneath|Beside/beside|Besides/besides|Between/between|Beyond/beyond|By/by|Down/down|During/during|Except/except|For/for|From/from|In/in|Inside/inside|Into/into|Like/like|Near/near|Of/of|Off/off|On/on|Out/out|Outside/outside|Over/over|Since/since|Through/through|Throughout/throughout|Till/till|To/to|Toward/toward|Under/under|Until/until|Up/up|Upon/upon|With/with|Without/without';var arrExceptions=Exceptions.split('|');STRING=pcase(STRING);var arrExValues;
 for(var iEx=0; iEx < arrExceptions.length;iEx++){
  arrExValues=arrExceptions[iEx].split('/');
  var SearchThisValue=' '+arrExValues[0]+' ';
  var ReplaceThisValue=' '+arrExValues[1]+' ';
  while(STRING.indexOf(SearchThisValue)>-1){
   STRING=STRING.replace(SearchThisValue,ReplaceThisValue);
  }
 }
 return STRING;
} //End Function


function InStr(STRING,SUBSTRING,COMPARE,START){
 if(START){
  STRING=STRING.substring(START,STRING.length);
 }
 if(CBool(COMPARE) || COMPARE ==undefined){
  STRING=STRING.toLowerCase();
  SUBSTRING=SUBSTRING.toLowerCase();
 }
 if(STRING.indexOf(SUBSTRING) > -1){
  return STRING.indexOf(SUBSTRING)
 }else{
  return 0;
 }
}

function LCase(STRING){
 return STRING.toLowerCase();
}

function left(STRING,CHARACTER_COUNT){
 return STRING.substring(0,CHARACTER_COUNT);
}

function Len(STRING){
 return STRING.length;
}

function Mid(STRING,START,END){
 if(!START){START=0};
 if(!END || END > STRING.length){END=STRING.length};
 if(END!=STRING.length){END=START+END};
 return STRING.substring(START,END);
}

function Replace(STRING,REPLACE_THIS,REPLACE_WITH){
 while(STRING.indexOf(REPLACE_THIS) > -1){
  STRING=STRING.replace(REPLACE_THIS,REPLACE_WITH);
 }
 return STRING;
}

function Right(STRING,CHARACTER_COUNT){
 return STRING.substring((STRING.length - CHARACTER_COUNT),STRING.length);
}

function Split(STRING,CHARACTER){
 return STRING.split(CHARACTER);
}

function Sqr(number){
 return number*number
}

function strComp(STRING1,STRING2,COMPARE){
 if(IsNull(COMPARE)){
  COMPARE=1;
 }
 if(CBool(COMPARE)){
  STRING1=STRING1.toLowerCase();
  STRING2=STRING2.toLowerCase();
 }

 if(STRING1==STRING2){
  return true;
 }else{
  return false;
 }
}

function Trim(STRING){
 STRING=LTrim(STRING);
 return RTrim(STRING);
}

function RTrim(STRING){
 while(STRING.charAt((STRING.length -1))==' '){
  STRING=STRING.substring(0,STRING.length-1);
 }
 return STRING;
}

function LTrim(STRING){
 while(STRING.charAt(0)==' '){
  STRING=STRING.replace(STRING.charAt(0),'');
 }
 return STRING;
}

function UBound(ARRAY){
 if(IsArray(ARRAY)){
  return ARRAY.length;
 }else{
  return;
 }
}

function UCase(STRING){
 return STRING.toUpperCase();
}

function UNESCAPE(U_VALUE){
 U_VALUE=unescape(U_VALUE);
 while(U_VALUE.indexOf('+') > -1){
  U_VALUE=U_VALUE.replace('+',' ');
 }
 return U_VALUE;
}

var vbCrLf=String.fromCharCode(13)+String.fromCharCode(10);
var vbTab='	'; // change this syntax!

// If you have PHP you can set the post values like this
//var postState = '<?= $_POST['state'] ?>';
//var postCountry = '<?= $_POST['country'] ?>';
var postState='';
var postCountry='';

// State table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var state='\
US:AK:Alaska|\
US:AL:Alabama|\
US:AR:Arkansas|\
US:AS:American Samoa|\
US:AZ:Arizona|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DC:D.C.|\
US:DE:Delaware|\
US:FL:Florida|\
US:FM:Micronesia|\
US:GA:Georgia|\
US:GU:Guam|\
US:HI:Hawaii|\
US:IA:Iowa|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:MA:Massachusetts|\
US:MD:Maryland|\
US:ME:Maine|\
US:MH:Marshall Islands|\
US:MI:Michigan|\
US:MN:Minnesota|\
US:MO:Missouri|\
US:MP:Marianas|\
US:MS:Mississippi|\
US:MT:Montana|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:NE:Nebraska|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NV:Nevada|\
US:NY:New York|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:PR:Puerto Rico|\
US:PW:Palau|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VA:Virginia|\
US:VI:Virgin Islands|\
US:VT:Vermont|\
US:WA:Washington|\
US:WI:Wisconsin|\
US:WV:West Virginia|\
US:WY:Wyoming|\
US:AA:Military Americas|\
US:AE:Military Europe/ME/Canada|\
US:AP:Military Pacific|\
CA:AB:Alberta|\
CA:MB:Manitoba|\
CA:AB:Alberta|\
CA:BC:British Columbia|\
CA:MB:Manitoba|\
CA:NB:New Brunswick|\
CA:NL:Newfoundland and Labrador|\
CA:NS:Nova Scotia|\
CA:NT:Northwest Territories|\
CA:NU:Nunavut|\
CA:ON:Ontario|\
CA:PE:Prince Edward Island|\
CA:QC:Quebec|\
CA:SK:Saskatchewan|\
CA:YT:Yukon Territory|\
AU:AAT:Australian Antarctic Territory|\
AU:ACT:Australian Capital Territory|\
AU:NT:Northern Territory|\
AU:NSW:New South Wales|\
AU:QLD:Queensland|\
AU:SA:South Australia|\
AU:TAS:Tasmania|\
AU:VIC:Victoria|\
AU:WA:Western Australia|\
BR:AC:Acre|\
BR:AL:Alagoas|\
BR:AM:Amazonas|\
BR:AP:Amapa|\
BR:BA:Baia|\
BR:CE:Ceara|\
BR:DF:Distrito Federal|\
BR:ES:Espirito Santo|\
BR:FN:Fernando de Noronha|\
BR:GO:Goias|\
BR:MA:Maranhao|\
BR:MG:Minas Gerais|\
BR:MS:Mato Grosso do Sul|\
BR:MT:Mato Grosso|\
BR:PA:Para|\
BR:PB:Paraiba|\
BR:PE:Pernambuco|\
BR:PI:Piaui|\
BR:PR:Parana|\
BR:RJ:Rio de Janeiro|\
BR:RN:Rio Grande do Norte|\
BR:RO:Rondonia|\
BR:RR:Roraima|\
BR:RS:Rio Grande do Sul|\
BR:SC:Santa Catarina|\
BR:SE:Sergipe|\
BR:SP:Sao Paulo|\
BR:TO:Tocatins|\
NL:DR:Drente|\
NL:FL:Flevoland|\
NL:FR:Friesland|\
NL:GL:Gelderland|\
NL:GR:Groningen|\
NL:LB:Limburg|\
NL:NB:Noord Brabant|\
NL:NH:Noord Holland|\
NL:OV:Overijssel|\
NL:UT:Utrecht|\
NL:ZH:Zuid Holland|\
NL:ZL:Zeeland|\
UK:AVON:Avon|\
UK:BEDS:Bedfordshire|\
UK:BERKS:Berkshire|\
UK:BUCKS:Buckinghamshire|\
UK:CAMBS:Cambridgeshire|\
UK:CHESH:Cheshire|\
UK:CLEVE:Cleveland|\
UK:CORN:Cornwall|\
UK:CUMB:Cumbria|\
UK:DERBY:Derbyshire|\
UK:DEVON:Devon|\
UK:DORSET:Dorset|\
UK:DURHAM:Durham|\
UK:ESSEX:Essex|\
UK:GLOUS:Gloucestershire|\
UK:GLONDON:Greater London|\
UK:GMANCH:Greater Manchester|\
UK:HANTS:Hampshire|\
UK:HERWOR:Hereford & Worcestershire|\
UK:HERTS:Hertfordshire|\
UK:HUMBER:Humberside|\
UK:IOM:Isle of Man|\
UK:IOW:Isle of Wight|\
UK:KENT:Kent|\
UK:LANCS:Lancashire|\
UK:LEICS:Leicestershire|\
UK:LINCS:Lincolnshire|\
UK:MERSEY:Merseyside|\
UK:NORF:Norfolk|\
UK:NHANTS:Northamptonshire|\
UK:NTHUMB:Northumberland|\
UK:NOTTS:Nottinghamshire|\
UK:OXON:Oxfordshire|\
UK:SHROPS:Shropshire|\
UK:SOM:Somerset|\
UK:STAFFS:Staffordshire|\
UK:SUFF:Suffolk|\
UK:SURREY:Surrey|\
UK:SUSS:Sussex|\
UK:WARKS:Warwickshire|\
UK:WMID:West Midlands|\
UK:WILTS:Wiltshire|\
UK:YORK:Yorkshire|\
EI:CO ANTRIM:County Antrim|\
EI:CO ARMAGH:County Armagh|\
EI:CO DOWN:County Down|\
EI:CO FERMANAGH:County Fermanagh|\
EI:CO DERRY:County Londonderry|\
EI:CO TYRONE:County Tyrone|\
EI:CO CAVAN:County Cavan|\
EI:CO DONEGAL:County Donegal|\
EI:CO MONAGHAN:County Monaghan|\
EI:CO DUBLIN:County Dublin|\
EI:CO CARLOW:County Carlow|\
EI:CO KILDARE:County Kildare|\
EI:CO KILKENNY:County Kilkenny|\
EI:CO LAOIS:County Laois|\
EI:CO LONGFORD:County Longford|\
EI:CO LOUTH:County Louth|\
EI:CO MEATH:County Meath|\
EI:CO OFFALY:County Offaly|\
EI:CO WESTMEATH:County Westmeath|\
EI:CO WEXFORD:County Wexford|\
EI:CO WICKLOW:County Wicklow|\
EI:CO GALWAY:County Galway|\
EI:CO MAYO:County Mayo|\
EI:CO LEITRIM:County Leitrim|\
EI:CO ROSCOMMON:County Roscommon|\
EI:CO SLIGO:County Sligo|\
EI:CO CLARE:County Clare|\
EI:CO CORK:County Cork|\
EI:CO KERRY:County Kerry|\
EI:CO LIMERICK:County Limerick|\
EI:CO TIPPERARY:County Tipperary|\
EI:CO WATERFORD:County Waterford|\
';

// Country data table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var country='\
AF:Afghanistan|\
AL:Albania|\
DZ:Algeria|\
AS:American Samoa|\
AD:Andorra|\
AO:Angola|\
AI:Anguilla|\
AQ:Antarctica|\
AG:Antigua and Barbuda|\
AR:Argentina|\
AM:Armenia|\
AW:Aruba|\
AU:Australia|\
AT:Austria|\
AZ:Azerbaijan|\
AP:Azores|\
BS:Bahamas|\
BH:Bahrain|\
BD:Bangladesh|\
BB:Barbados|\
BY:Belarus|\
BE:Belgium|\
BZ:Belize|\
BJ:Benin|\
BM:Bermuda|\
BT:Bhutan|\
BO:Bolivia|\
BA:Bosnia And Herzegowina|\
XB:Bosnia-Herzegovina|\
BW:Botswana|\
BV:Bouvet Island|\
BR:Brazil|\
IO:British Indian Ocean Territory|\
VG:British Virgin Islands|\
BN:Brunei Darussalam|\
BG:Bulgaria|\
BF:Burkina Faso|\
BI:Burundi|\
KH:Cambodia|\
CM:Cameroon|\
CA:Canada|\
CV:Cape Verde|\
KY:Cayman Islands|\
CF:Central African Republic|\
TD:Chad|\
CL:Chile|\
CN:China|\
CX:Christmas Island|\
CC:Cocos (Keeling) Islands|\
CO:Colombia|\
KM:Comoros|\
CG:Congo|\
CD:Congo, The Democratic Republic O|\
CK:Cook Islands|\
XE:Corsica|\
CR:Costa Rica|\
CI:Cote d` Ivoire (Ivory Coast)|\
HR:Croatia|\
CU:Cuba|\
CY:Cyprus|\
CZ:Czech Republic|\
DK:Denmark|\
DJ:Djibouti|\
DM:Dominica|\
DO:Dominican Republic|\
TP:East Timor|\
EC:Ecuador|\
EG:Egypt|\
SV:El Salvador|\
GQ:Equatorial Guinea|\
ER:Eritrea|\
EE:Estonia|\
ET:Ethiopia|\
FK:Falkland Islands (Malvinas)|\
FO:Faroe Islands|\
FJ:Fiji|\
FI:Finland|\
FR:France (Includes Monaco)|\
FX:France, Metropolitan|\
GF:French Guiana|\
PF:French Polynesia|\
TA:French Polynesia (Tahiti)|\
TF:French Southern Territories|\
GA:Gabon|\
GM:Gambia|\
GE:Georgia|\
DE:Germany|\
GH:Ghana|\
GI:Gibraltar|\
GR:Greece|\
GL:Greenland|\
GD:Grenada|\
GP:Guadeloupe|\
GU:Guam|\
GT:Guatemala|\
GN:Guinea|\
GW:Guinea-Bissau|\
GY:Guyana|\
HT:Haiti|\
HM:Heard And Mc Donald Islands|\
VA:Holy See (Vatican City State)|\
HN:Honduras|\
HK:Hong Kong|\
HU:Hungary|\
IS:Iceland|\
IN:India|\
ID:Indonesia|\
IR:Iran|\
IQ:Iraq|\
IE:Ireland|\
EI:Ireland (Eire)|\
IL:Israel|\
IT:Italy|\
JM:Jamaica|\
JP:Japan|\
JO:Jordan|\
KZ:Kazakhstan|\
KE:Kenya|\
KI:Kiribati|\
KP:Korea, Democratic People\'S Repub|\
KW:Kuwait|\
KG:Kyrgyzstan|\
LA:Laos|\
LV:Latvia|\
LB:Lebanon|\
LS:Lesotho|\
LR:Liberia|\
LY:Libya|\
LI:Liechtenstein|\
LT:Lithuania|\
LU:Luxembourg|\
MO:Macao|\
MK:Macedonia|\
MG:Madagascar|\
ME:Madeira Islands|\
MW:Malawi|\
MY:Malaysia|\
MV:Maldives|\
ML:Mali|\
MT:Malta|\
MH:Marshall Islands|\
MQ:Martinique|\
MR:Mauritania|\
MU:Mauritius|\
YT:Mayotte|\
MX:Mexico|\
FM:Micronesia, Federated States Of|\
MD:Moldova, Republic Of|\
MC:Monaco|\
MN:Mongolia|\
MS:Montserrat|\
MA:Morocco|\
MZ:Mozambique|\
MM:Myanmar (Burma)|\
NA:Namibia|\
NR:Nauru|\
NP:Nepal|\
NL:Netherlands|\
AN:Netherlands Antilles|\
NC:New Caledonia|\
NZ:New Zealand|\
NI:Nicaragua|\
NE:Niger|\
NG:Nigeria|\
NU:Niue|\
NF:Norfolk Island|\
MP:Northern Mariana Islands|\
NO:Norway|\
OM:Oman|\
PK:Pakistan|\
PW:Palau|\
PS:Palestinian Territory, Occupied|\
PA:Panama|\
PG:Papua New Guinea|\
PY:Paraguay|\
PE:Peru|\
PH:Philippines|\
PN:Pitcairn|\
PL:Poland|\
PT:Portugal|\
PR:Puerto Rico|\
QA:Qatar|\
RE:Reunion|\
RO:Romania|\
RU:Russian Federation|\
RW:Rwanda|\
KN:Saint Kitts And Nevis|\
SM:San Marino|\
ST:Sao Tome and Principe|\
SA:Saudi Arabia|\
SN:Senegal|\
XS:Serbia-Montenegro|\
SC:Seychelles|\
SL:Sierra Leone|\
SG:Singapore|\
SK:Slovak Republic|\
SI:Slovenia|\
SB:Solomon Islands|\
SO:Somalia|\
ZA:South Africa|\
GS:South Georgia And The South Sand|\
KR:South Korea|\
ES:Spain|\
LK:Sri Lanka|\
NV:St. Christopher and Nevis|\
SH:St. Helena|\
LC:St. Lucia|\
PM:St. Pierre and Miquelon|\
VC:St. Vincent and the Grenadines|\
SD:Sudan|\
SR:Suriname|\
SJ:Svalbard And Jan Mayen Islands|\
SZ:Swaziland|\
SE:Sweden|\
CH:Switzerland|\
SY:Syrian Arab Republic|\
TW:Taiwan|\
TJ:Tajikistan|\
TZ:Tanzania|\
TH:Thailand|\
TG:Togo|\
TK:Tokelau|\
TO:Tonga|\
TT:Trinidad and Tobago|\
XU:Tristan da Cunha|\
TN:Tunisia|\
TR:Turkey|\
TM:Turkmenistan|\
TC:Turks and Caicos Islands|\
TV:Tuvalu|\
UG:Uganda|\
UA:Ukraine|\
AE:United Arab Emirates|\
UK:United Kingdom|\
GB:Great Britain|\
US:United States|\
UM:United States Minor Outlying Isl|\
UY:Uruguay|\
UZ:Uzbekistan|\
VU:Vanuatu|\
XV:Vatican City|\
VE:Venezuela|\
VN:Vietnam|\
VI:Virgin Islands (U.S.)|\
WF:Wallis and Furuna Islands|\
EH:Western Sahara|\
WS:Western Samoa|\
YE:Yemen|\
YU:Yugoslavia|\
ZR:Zaire|\
ZM:Zambia|\
ZW:Zimbabwe|\
';

function TrimString(sInString) {
  if ( sInString ) {
    sInString=sInString.replace( /^\s+/g, '' );// strip leading
    return sInString.replace( /\s+$/g, '' );// strip trailing
  }
}

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry) {
  if ( postCountry != '' ) {
    defaultCountry=postCountry;
  }
  var countryLineArray=country.split('|');  // Split into lines
  var selObj=document.getElementById('countrySelect');
  selObj.options[0]=new Option('Select Country','');
  selObj.selectedIndex=0;
  for (var loop=0; loop < countryLineArray.length; loop++) {
    lineArray=countryLineArray[loop].split(':');
    countryCode =TrimString(lineArray[0]);
    countryName =TrimString(lineArray[1]);
    if ( countryCode != '' ) {
      selObj.options[loop+1]=new Option(countryName, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex=loop+1;
    }
  }
}

function populateState() {
  var selObj=document.getElementById('stateSelect');
  var foundState=false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i=0; i < selObj.options.length; i++) {
      selObj.options[i]=null;
    }
    selObj.options.length=null;
    selObj.options[0]=new Option('Select State','');
    selObj.selectedIndex=0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray=state.split('|');  // Split into lines
  var optionCntr=1;
  for (var loop=0; loop < stateLineArray.length; loop++) {
    lineArray=stateLineArray[loop].split(':');
    countryCode =TrimString(lineArray[0]);
    stateCode   =TrimString(lineArray[1]);
    stateName   =TrimString(lineArray[2]);
  if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
    // If it's a input element, change it to a select
      if ( selObj.type == 'text' ) {
        parentObj=document.getElementById('stateSelect').parentNode;
        parentObj.removeChild(selObj);
        var inputSel=document.createElement('SELECT');
        inputSel.setAttribute('name','state');
        inputSel.setAttribute('id','stateSelect');
        parentObj.appendChild(inputSel) ;
        selObj=document.getElementById('stateSelect');
        selObj.options[0]=new Option('Select State','');
        selObj.selectedIndex=0;
      }
      if ( stateCode != '' ) {
        selObj.options[optionCntr]=new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      if ( stateCode == postState && countryCode == postCountry ) {
        selObj.selectedIndex=optionCntr;
      }
      foundState=true;
      optionCntr++
    }
  }
  // If the country has no states, change the select to a text box
  if ( ! foundState ) {
    parentObj=document.getElementById('stateSelect').parentNode;
    parentObj.removeChild(selObj);
  // Create the Input Field
    var inputEl=document.createElement('INPUT');
    inputEl.setAttribute('id', 'stateSelect');
    inputEl.setAttribute('type', 'text');
    inputEl.setAttribute('name', 'state');
    inputEl.setAttribute('size', 20);
    inputEl.setAttribute('value', postState);
    parentObj.appendChild(inputEl) ;
  }
}

function initCountry(country) {
 populateCountry(country);
 populateState();
}

function editcity(t,s,z,n){
 t.value=pcase(t.value);
 var zip=t.value.substr(0,5);
 if(isNumeric(zip)){
  document.getElementsByTagName('body')[0].style.cursor='wait';
  document.getElementById('getscript').src='http://uwtke.com/ajax.php?action=getcity&zip='+zip+'&slit='+s+'&zlit='+z+'&nlit='+n;
 }
}
// end vbscript to jscript compatibility 

function pcase(p1){
 // alert('pcase called, p='+p1)
 if(p1.toUpperCase()==p1){p1=p1.toLowerCase();}
	var strReturn_Value='';
	var iTemp=p1.length;
	if(iTemp==0){return '';}
	var UcaseNext=false;
	strReturn_Value+=p1.charAt(0).toUpperCase();
	for(var iCounter=1;iCounter < iTemp;iCounter++){
 	if(UcaseNext==true){
	  strReturn_Value+=p1.charAt(iCounter).toUpperCase();
	 }else{
	  // strReturn_Value+=p1.charAt(iCounter).toLowerCase();
	  strReturn_Value+=p1.charAt(iCounter);
	 }
	 var iChar=p1.charCodeAt(iCounter);
	 if(iChar==32 || iChar==45 || iChar==46){
	  UcaseNext=true;
	 }else{
	  UcaseNext=false
	 }
	 if(iChar==99 || iChar==67){
	  if(p1.charCodeAt(iCounter-1)==77 || p1.charCodeAt(iCounter-1)==109){
	   UcaseNext=true;
	  }
  }
 } // end for
 return strReturn_Value;
} // end function



// --------------------------------------------
//                  setfocus
// Jun 2005: discovered that reason IE wasn't setting focus was
// due to an IE timing bug. Added 0.1 sec delay to fix.
// Delayed focus setting to get around IE bug
// --------------------------------------------

function setFocusDelayed(){
 global_valfield.focus();
}

function setfocus(valfield){
 // save valfield in global variable so value retained when routine exits
 global_valfield=valfield;
 setTimeout('setFocusDelayed()',100);
}

// Begin ASC  ==================================================================
var upmc={};
tke.onload=function(m){
 if(window.addEventListener){
  window.addEventListener('load',m,false);
 }else if(window.attachEvent){
  window.attachEvent('onload',m);
 }
};
tke.form={};
tke.form.findFirst=function(){
 // access the forms collection See oloesm.js for an example
 // access the first form
 // traverse the form elements looking for either the presence of an IC attribute
 // or the lowest tabindex
 // or the first field that is not disabled.
}
tke.form.wrap=function(){
 // access this element
 // access the next attribute, if found and tab is pressed, select it and return false
 // access the prev attribute, if found and back tab is pressed, select it and return false
 // consider following chain until a non-disabled element is found or you return to self
 // consider if neither next or prev are defined, if a tabindex is defined, wrapping to first/last if need be
 return true; // let nature take her course
}
tke.form.wrapFirst=function(){
 // access the last key that was pressed?
 // if it was not the tab, return true and let it happen
 // access this element
 // access the form that this is a member of
 // if the first field on the form is not yet stored,
 // traverse the form, find the first field and store it.
 // if it was the tab key, then select the first field
 // return false to cancel the wierdness
};
tke.form.wrapLast=function(){
 // access the last key that was pressed?
 // if it was not the back tab, return true and let it happen
 // access this element
 // access the form that this is a member of
 // if the last field on the form is not yet stored,
 // traverse the form, find the last field and store it.
 // select the last field
 // return false to cancel the wierdness
};
tke.logon={};
tke.logon.hide=function(){tke.logwin.hide();}
tke.logon.register=function(){tke.logon.hide();window.location='/register.php';}
tke.logon.resetpw=function(){
 var u=_ge('userid');
 if(!u.value){
  alert('Enter your user id or email address and we will reset your password');
  u.focus();
  return;
 }
 url='jack.php?o=rp&a='+u.value;
 alert('The url to reset your password is "'+url+'"');
 garyRPC(url);
 alert('Use the link sent to your email address to reset your password.\n\nIf the information entered is invalid, we will ignore this request. While we would like to tell you that your entry is invalid, bad people use those replies to figure out who has accounts with us and then attack those accounts. We regret the inconvenience this causes good people, but for the protection of all of our users, we can\'t advise you when you make a mistake. If you don\'t get your email within 5 minutes, come back and request it again being very careful what you type. In an extreme case, you may also want to have a friend send you an email from a different account to be sure that you are able to recieve emails. You may also email webmaster@tke.coop if you are unable to resolve the issue yourself.')
 tke.logon.hide(); // window.location='/register.php';
}
tke.logon.show=function(){
 var item=_ge('log');
 var state=item.innerHTML;
 if(state.indexOf('Logon')+1){
  tke.logwin=dhtmlmodal.open('logwin','div','logondiv','UW TKE Login','width=350px,height=255px,left=470px,top=300px,center=0,resize=0,scrolling=0');
  //tke.logwin=dhtmlwindow.open('logwin','div','logondiv','UPMC Login','width=306px,height=234px,left=670px,top=100px,center=0,resize=0,scrolling=0');
  _ge('loginMsg').innerHTML='';
  _ge('userid').focus();
  /*
  tke.logwin.onclose=function(){ //Define custom code to run when window is closed
	  return true; //Allow closing of window in any case
  }
  */
 }else{ // if state is log off
  window.location='/logoff.php'
 }
}
tke.logon.submit=function(){
	var	x=_ese();
 while(x.parentNode	&&	x.tagName!='FORM'){x=x.parentNode;}
 // alert(x.action);
 // x.submit();
 ui=_ge('userid');
 if(!ui.value){
  alert('Please enter your user id');
  ui.focus();
  return false;
 }
 pw=_ge('password');
 if(!pw.value){
  alert('Please enter your password');
  pw.focus();
  return false;
 }
 // alert(_ge('loginMsg').outerHTML);return;
 // tke.logon.hide();
 var t=new Date();
 t=parseInt(t.getTime()/1000).toString();
 //var url='\login.php?u='+ui.value+'&t='+t+'&h='+hex_md5(pw.value)+'&x='+hex_md5(hex_md5(pw.value)+t);
 var url='/login/login.php?u='+ui.value+'&t='+t+'&x='+hex_md5(hex_md5(pw.value)+t);
 glog(url);
 garyRPC(url);
	return false;
}
tke.register={};
tke.register.checkBack=function(){ // if form is dirty, confirm escape
 return confirm('OK to loose changes?');
};
tke.register.checkForm=function(){
 var x=_ge('user');
 if(!x.value){alert('Please specifiy a user id');x.focus();return false;}
 if(_ge('userMsg').innerText){alert('This user id is already in use');x.select();return false;}
 var x=_ge('password');
 if(!x.value){alert('Please specifiy a password');x.focus();return false;}
 var y=_ge('confirmpw');
 if(x.value!=y.value){alert('Passwords do not match, please enter them again');x.select();return false;}
 return true;
}; 
tke.register.checkPass=function(){ // Verify that passwords, if entered, match
 var x=_ge('password');
 var y=_ge('confirmpw');
 _ge('passMsg').innerHTML=((x.value && y.value && x.value!=y.value)?'Passwords do not match':'');
}
tke.register.checkUser=function(){
 var se=_ese();
 if(!se.value){
  _ge('userMsg').innerHTML='This field is required!';
  return;
 }
 var url='jack.php?o=u&u='+se.value; // need to encode that to be url safe!!!!!!
 // alert(url);
 garyRPC(url);
}; 

var lastFAQ=null;
function toggle(){
 var ese=_ese();
 var thisDIV=ese.getElementsByTagName('div')[0];
 if(lastFAQ){
  lastFAQ.style.display='none';
  if(ese==lastFAQ){lastFAQ=null;return;}
 }
 lastFAQ=thisDIV;
 lastFAQ.style.display='block';
}
// End ASC      ==================================================================
// Begin tke.sm ==================================================================
tke.sm={
 doit:function(){
  // alert('tke.sm.doit() in tke.js is attempting to find first field in a form');
  var fa=document.forms;
  for(var fx=0;fx<fa.length;fx++){
   // alert('fx='+fx);
   var form=fa[fx];
   var ea=form.elements;
   for(var ex=0;ex<ea.length;ex++){
    // alert('ex='+fx+'/'+ex+': '+ea[ex].name);
				var item=ea[ex];
    try{item.focus();if(item.select){item.select();}_ge('apply').style.display='inline';return false;}catch(e){}
   } // end for ex
  } // end for fx
		_ge('apply').style.display='none';
 }, // end doit method
 oc:function(){
  var a=document.forms[0].elements;
  var d=true;
  for(var ax=0;ax<a.length;ax++){
   var item=a[ax];
   if(item.type=='checkbox'){
    if(item.checked.toString()!=item.defaultValue){d=false;break;}
   }else{
    if((item.tagName!='BUTTON') && item.value!=item.defaultValue){d=false;break;}
   }
  }
  _ge('apply').disabled=d;
 }, // end method
 ol:function(){ // tdl: do this for all forms, not just first. there may be zero or two forms as well as one
  var a=document.getElementsByTagName('input');
  var d=true;
  for(var ax=0;ax<a.length;ax++){
   var item=a[ax];
   if(item.type=='checkbox'){
	   item.defaultValue=item.checked;
   }
  }
		tke.sm.doit();
 }, // end method
 toggleClassname:function(el,newClassname,defaultClassname){
  var re;
  if(this.hasClass(el,defaultClassname)){
   re=new RegExp('(^|\\s)'+defaultClassname+'(\\s|$)');
   el.className=trim(el.className.replace(re,' '+ newClassname +' '));
  }else if(this.hasClass(el,newClassname)){
   re=new RegExp('(^|\\s)'+newClassname+'(\\s|$)');
   el.className=trim(el.className.replace(re,' '+defaultClassname+' '));
   //alert(el.className);
  }else{
   el.className=trim(el.className+' '+newClassname);
  }  
 },
 contains:function(needle,haystack,mods){  // tbild: determine if case is important in class names
  if(typeof mods=='undefined'){mods='i';}  // for now, assuming not.
  var re;                                  // are hyphens a word boundary (insignificant) or a character(significant)
  re=new RegExp('\\b'+needle+'\\b',mods);  // this works if a boundary
  re=new RegExp('^| '+needle+' |$',mods);  // this works if a character  since hyphens are valid in class names, using this one
  if(haystack.search(re)<0){return false;}
  return true;
 }, // end contains method
 hasClass:function(obj,className){
  if(typeof obj=='undefined' || obj==null || !RegExp){
   return false; 
  }
  var re=new RegExp('(^|\\s)'+className+'(\\s|$)');
  if(typeof(obj)=='string'){
   return re.test(obj);
  }else if(typeof(obj)=='object' && obj.className){
   return re.test(obj.className);
  }
  return false;
 }, // end has class
 compress:function(p){

  return rc;
 }, // end compress method
 filler:null // avoid compile error
} // tke.sm class
function trim(str){return str.replace(/^\s\s*/,'').replace(/\s\s*$/,'');}
// End tke.sm   ==================================================================
// Begin Window ==================================================================
var dhtmlwindow={
imagefiles:['/images/window/min.gif','/images/window/close.gif','/images/window/restore.gif','/images/window/resize.gif'], //Path to 4 images used by script, in that order
ajaxbustcache: true, //Bust caching when fetching a file via Ajax?
ajaxloadinghtml: '<b>Loading Page. Please wait...</b>', //HTML to show while window fetches Ajax Content?

minimizeorder: 0,
zIndexvalue:100,
tobjects: [], //object to contain references to dhtml window divs, for cleanup purposes
lastactivet: {}, //reference to last active DHTML window

init:function(t){
	var domwindow=document.createElement('div'); //create dhtml window div
	domwindow.id=t;
	domwindow.className='dhtmlwindow';
	var domwindowdata='';
	domwindowdata='<div class="drag-handle">';
	domwindowdata+='DHTML Window <div class="drag-controls"><img src="'+this.imagefiles[0]+'" title="Minimize" /><img src="'+this.imagefiles[1]+'" title="Close" /></div>';
	domwindowdata+='</div>';
	domwindowdata+='<div class="drag-contentarea"></div>';
	domwindowdata+='<div class="drag-statusarea"><div class="drag-resizearea" style="background: transparent url('+this.imagefiles[3]+') top right no-repeat;">&nbsp;</div></div>';
	domwindowdata+='</div>';
	domwindow.innerHTML=domwindowdata;
	_ge('dhtmlwindowholder').appendChild(domwindow);
	//this.zIndexvalue=(this.zIndexvalue)?this.zIndexvalue+1:100; //z-index value for DHTML window: starts at 0, increments whenever a window has focus
	var t=_ge(t);
	var divs=t.getElementsByTagName('div');

 for (var i=0; i<divs.length; i++){ //go through divs inside dhtml window and extract all those with class="drag-" prefix
		if(/drag-/.test(divs[i].className)){
			t[divs[i].className.replace(/drag-/,'')]=divs[i]; //take out the "drag-" prefix for shorter access by name
  }
	}
	//t.style.zIndex=this.zIndexvalue //set z-index of this dhtml window
	t.handle._parent=t; //store back reference to dhtml window
	t.resizearea._parent=t; //same
	t.controls._parent=t; //same
	t.onclose=function(){return true;} //custom event handler "onclose"
	t.onmousedown=function(){dhtmlwindow.setfocus(this);} //Increase z-index of window when focus is on it
	t.handle.onmousedown=dhtmlwindow.setupdrag; //set up drag behavior when mouse down on handle div
	t.resizearea.onmousedown=dhtmlwindow.setupdrag; //set up drag behavior when mouse down on resize div
	t.controls.onclick=dhtmlwindow.enablecontrols;
	t.show=function(){dhtmlwindow.show(this);} //public function for showing dhtml window
	t.hide=function(){dhtmlwindow.hide(this);} //public function for hiding dhtml window
	t.close=function(){dhtmlwindow.close(this);} //public function for closing dhtml window (also empties DHTML window content)
	t.setSize=function(w,h){dhtmlwindow.setSize(this,w,h);} //public function for setting window dimensions
	t.moveTo=function(x,y){dhtmlwindow.moveTo(this,x,y);} //public function for moving dhtml window (relative to viewpoint)
	t.isResize=function(bol){dhtmlwindow.isResize(this,bol);} //public function for specifying if window is resizable
	t.isScrolling=function(bol){dhtmlwindow.isScrolling(this,bol);} //public function for specifying if window content contains scrollbars
	t.load=function(contenttype,contentsource,title){dhtmlwindow.load(this,contenttype,contentsource,title);} //public function for loading content into window
	this.tobjects[this.tobjects.length]=t;
	return t; //return reference to dhtml window div
},

open:function(t,contenttype,contentsource,title,attr,recalonload){
	var d=dhtmlwindow; //reference dhtml window object
	function getValue(Name){
		var config=new RegExp(Name+'=([^,]+)','i'); //get name/value config pair (ie: width=400px,)
		return (config.test(attr))?parseInt(RegExp.$1):0; //return value portion (int), or 0 (false) if none found
	}
	if(_ge(t)==null){ //if window doesn't exist yet, create it
		t=this.init(t); //return reference to dhtml window div
	}else{
		t=_ge(t);
 }
	this.setfocus(t);
	t.setSize(getValue(('width')),(getValue('height'))); //Set dimensions of window
	var xpos=getValue('center')?'middle':getValue('left'); //Get x coord of window
	var ypos=getValue('center')?'middle':getValue('top'); //Get y coord of window
	//t.moveTo(xpos,ypos); //Position window
	if(typeof recalonload!='undefined' && recalonload=='recal' && this.scroll_top==0){ //reposition window when page fully loads with updated window viewpoints?
		if(window.attachEvent && !window.opera){ //In IE, add another 400 milisecs on page load (viewpoint properties may return 0 b4 then)
			this.addEvent(window,function(){setTimeout(function(){t.moveTo(xpos,ypos);},400)},'load');
		}else{
			this.addEvent(window,function(){t.moveTo(xpos,ypos);},'load');
	 }
	}
	t.isResize(getValue('resize')); //Set whether window is resizable
	t.isScrolling(getValue('scrolling')); //Set whether window should contain scrollbars
	t.style.visibility='visible';
	t.style.display='block';
	t.contentarea.style.display='block';
	t.moveTo(xpos,ypos); //Position window
	t.load(contenttype,contentsource,title);
	if(t.state=='minimized' && t.controls.firstChild.title=='Restore'){ //If window exists and is currently minimized?
		t.controls.firstChild.setAttribute('src',dhtmlwindow.imagefiles[0]); //Change "restore" icon within window interface to "minimize" icon
		t.controls.firstChild.setAttribute('title','Minimize');
		t.state='fullview'; //indicate the state of the window as being "fullview"
	}
	return t;
},

setSize:function(t,w,h){ //set window size (min is 150px wide by 100px tall)
	t.style.width=Math.max(parseInt(w),150)+'px';
	t.contentarea.style.height=Math.max(parseInt(h),100)+'px';
},

moveTo:function(t,x,y){ //move window. Position includes current viewpoint of document
	this.getviewpoint(); //Get current viewpoint numbers
	t.style.left=(x=='middle')?this.scroll_left+(this.docwidth-t.offsetWidth)/2+'px':this.scroll_left+parseInt(x)+'px';
	t.style.top=(y=='middle')?this.scroll_top+(this.docheight-t.offsetHeight)/2+'px':this.scroll_top+parseInt(y)+'px';
},

isResize:function(t,bol){ //show or hide resize inteface (part of the status bar)
	t.statusarea.style.display=(bol)?'block':'none';
	t.resizeBool=(bol)?1:0;
},

isScrolling:function(t,bol){ //set whether loaded content contains scrollbars
	t.contentarea.style.overflow=(bol)?'auto':'hidden';
},

load:function(t,contenttype,contentsource,title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax")
	if(t.isClosed){
		alert('DHTML Window has been closed, so no window to load contents into. Open/Create the window again.');
		return;
	}
	var contenttype=contenttype.toLowerCase(); //convert string to lower case
	if(typeof title!='undefined'){
		t.handle.firstChild.nodeValue=title;
 }
	if(contenttype=='inline'){
		t.contentarea.innerHTML=contentsource;
	}else if(contenttype=='div'){
  var inlinedivref=_ge(contentsource);
  if(!inlinedivref){alert('There is no content named "'+contentsource+'"');return;}
		t.contentarea.innerHTML=(inlinedivref.defaultHTML || inlinedivref.innerHTML); //Populate window with contents of inline div on page
		if(!inlinedivref.defaultHTML){
			inlinedivref.defaultHTML=inlinedivref.innerHTML; //save HTML within inline DIV
  }
		inlinedivref.innerHTML=''; //then, remove HTML within inline DIV (to prevent duplicate IDs, NAME attributes etc in contents of DHTML window
		inlinedivref.style.display='none'; //hide that div
	}else if(contenttype=='iframe'){
		t.contentarea.style.overflow='hidden'; //disable window scrollbars, as iframe already contains scrollbars
		if(!t.contentarea.firstChild || t.contentarea.firstChild.tagName!='IFRAME'){ //If iframe tag doesn't exist already, create it first
			t.contentarea.innerHTML='<iframe src="" style="margin:0; padding:0; width:100%; height: 100%" name="_iframe-'+t.id+'"></iframe>';
  }
		window.frames['_iframe-'+t.id].location.replace(contentsource); //set location of iframe window to specified URL
	}else if(contenttype=='ajax'){
		this.ajax_connect(contentsource,t); //populate window with external contents fetched via Ajax
	}
	t.contentarea.datatype=contenttype; //store contenttype of current window for future reference
},

setupdrag:function(e){
	var d=dhtmlwindow;  //reference dhtml window object
	var t=this._parent; //reference dhtml window div
	d.etarget=this;     //remember div mouse is currently held down on ("handle" or "resize" div)
	var e=window.event || e;
	d.initmousex=e.clientX; //store x position of mouse onmousedown
	d.initmousey=e.clientY;
	d.initx=parseInt(t.offsetLeft); //store offset x of window div onmousedown
	d.inity=parseInt(t.offsetTop);
	d.width=parseInt(t.offsetWidth); //store width of window div
	d.contentheight=parseInt(t.contentarea.offsetHeight); //store height of window div's content div
	if(t.contentarea.datatype=='iframe'){ //if content of this window div is "iframe"
		t.style.backgroundColor='#F8F8F8'; //colorize and hide content div (while window is being dragged)
		t.contentarea.style.visibility='hidden';
	}
	document.onmousemove=d.getdistance; //get distance travelled by mouse as it moves
	document.onmouseup=function(){
		if(t.contentarea.datatype=='iframe'){ //restore color and visibility of content div onmouseup
			t.contentarea.style.backgroundColor='white';
			t.contentarea.style.visibility='visible';
		}
		d.stop();
	}
	return false;
},

getdistance:function(e){
	var d=dhtmlwindow;
	var etarget=d.etarget;
	var e=window.event || e;
	d.distancex=e.clientX-d.initmousex; //horizontal distance travelled relative to starting point
	d.distancey=e.clientY-d.initmousey;
	if(etarget.className=='drag-handle'){ //if target element is "handle" div
		d.move(etarget._parent,e);
 }else if(etarget.className=='drag-resizearea'){ //if target element is "resize" div
		d.resize(etarget._parent,e);
 }
	return false; //cancel default dragging behavior
},

getviewpoint:function(){ //get window viewpoint numbers
	var ie=document.all && !window.opera;
	var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000; //Preliminary doc width in non IE browsers
	this.standardbody=(document.compatMode=='CSS1Compat')?document.documentElement:document.body; //create reference to common "body" across doctypes
	this.scroll_top=(ie)?this.standardbody.scrollTop:window.pageYOffset;
	this.scroll_left=(ie)?this.standardbody.scrollLeft:window.pageXOffset;
	this.docwidth=(ie)?this.standardbody.clientWidth:(/Safari/i.test(navigator.userAgent))?window.innerWidth:Math.min(domclientWidth,window.innerWidth-16);
	this.docheight=(ie)?this.standardbody.clientHeight: window.innerHeight;
},

rememberattrs:function(t){ //remember certain attributes of the window when it's minimized or closed, such as dimensions, position on page
	this.getviewpoint(); //Get current window viewpoint numbers
	t.lastx=parseInt((t.style.left || t.offsetLeft))-dhtmlwindow.scroll_left; //store last known x coord of window just before minimizing
	t.lasty=parseInt((t.style.top || t.offsetTop))-dhtmlwindow.scroll_top;
	t.lastwidth=parseInt(t.style.width); //store last known width of window just before minimizing/ closing
},

move:function(t,e){
	t.style.left=dhtmlwindow.distancex+dhtmlwindow.initx+'px';
	t.style.top=dhtmlwindow.distancey+dhtmlwindow.inity+'px';
},

resize:function(t,e){
	t.style.width=Math.max(dhtmlwindow.width+dhtmlwindow.distancex,150)+'px';
	t.contentarea.style.height=Math.max(dhtmlwindow.contentheight+dhtmlwindow.distancey,100)+'px';
},

enablecontrols:function(e){
	var d=dhtmlwindow;
	var sourceobj=window.event?window.event.srcElement:e.target; //Get element within "handle" div mouse is currently on (the controls)
	if(/Minimize/i.test(sourceobj.getAttribute('title'))){ //if this is the "minimize" control
		d.minimize(sourceobj,this._parent);
	}else if(/Restore/i.test(sourceobj.getAttribute('title'))){ //if this is the "restore" control
		d.restore(sourceobj,this._parent);
 }else if(/Close/i.test(sourceobj.getAttribute('title'))){ //if this is the "close" control
		d.close(this._parent);
 }
	return false;
},

minimize:function(button,t){
	dhtmlwindow.rememberattrs(t);
	button.setAttribute('src',dhtmlwindow.imagefiles[2]);
	button.setAttribute('title','Restore');
	t.state='minimized'; //indicate the state of the window as being "minimized"
	t.contentarea.style.display='none';
	t.statusarea.style.display='none';
	if(typeof t.minimizeorder=='undefined'){ //stack order of minmized window on screen relative to any other minimized windows
		dhtmlwindow.minimizeorder++; //increment order
		t.minimizeorder=dhtmlwindow.minimizeorder;
	}
	t.style.left='10px'; //left coord of minmized window
	t.style.width='200px';
	var windowspacing=t.minimizeorder*10; //spacing (gap) between each minmized window(s)
	t.style.top=dhtmlwindow.scroll_top+dhtmlwindow.docheight-(t.handle.offsetHeight*t.minimizeorder)-windowspacing+'px';
},

restore:function(button,t){
	dhtmlwindow.getviewpoint();
	button.setAttribute('src',dhtmlwindow.imagefiles[0]);
	button.setAttribute('title','Minimize');
	t.state='fullview'; //indicate the state of the window as being "fullview"
	t.style.display='block';
	t.contentarea.style.display='block';
	if(t.resizeBool){ //if this window is resizable, enable the resize icon
		t.statusarea.style.display='block';
 }
	t.style.left=parseInt(t.lastx)+dhtmlwindow.scroll_left+'px'; //position window to last known x coord just before minimizing
	t.style.top=parseInt(t.lasty)+dhtmlwindow.scroll_top+'px';
	t.style.width=parseInt(t.lastwidth)+'px';
},


close:function(t){
	try{
		var closewinbol=t.onclose();
	}catch(err){ //In non IE browsers, all errors are caught, so just run the below
		var closewinbol=true;
 }finally{ //In IE, not all errors are caught, so check if variable isn't defined in IE in those cases
		if(typeof closewinbol=='undefined'){
			alert('An error has occured somwhere inside your "onclose" event handler');
			var closewinbol=true;
		}
	}
	if(closewinbol){ //if custom event handler function returns true
		if(t.state!='minimized'){ //if this window isn't currently minimized
			dhtmlwindow.rememberattrs(t); //remember window's dimensions/position on the page before closing
  }
		if(window.frames['_iframe-'+t.id]){ //if this is an IFRAME DHTML window
			window.frames['_iframe-'+t.id].location.replace('about:blank');
		}else{
			t.contentarea.innerHTML='';
  }
		t.style.display='none';
		t.isClosed=true; //tell script this window is closed (for detection in t.show())
	}
	return closewinbol;
},


setopacity:function(targetobject,value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
	if(!targetobject){return;}
	if(targetobject.filters && targetobject.filters[0]){ //IE syntax
		if(typeof targetobject.filters[0].opacity=='number'){ //IE6
			targetobject.filters[0].opacity=value*100;
		}else{ //IE 5.5
			targetobject.style.filter='alpha(opacity='+value*100+')';
  }
	}else if(typeof targetobject.style.MozOpacity!='undefined'){ //Old Mozilla syntax
		targetobject.style.MozOpacity=value;
 }else if(typeof targetobject.style.opacity!='undefined'){ //Standard opacity syntax
		targetobject.style.opacity=value;
 }
},

setfocus:function(t){ //Sets focus to the currently active window
	this.zIndexvalue++;
	t.style.zIndex=this.zIndexvalue;
	t.isClosed=false; //tell script this window isn't closed (for detection in t.show())
	this.setopacity(this.lastactivet.handle,0.5); //unfocus last active window
	this.setopacity(t.handle,1); //focus currently active window
	this.lastactivet=t; //remember last active window
},


show:function(t){
	if(t.isClosed){
		alert('DHTML Window has been closed, so nothing to show. Open/Create the window again.');
		return;
	}
	if(t.lastx){ //If there exists previously stored information such as last x position on window attributes (meaning it's been minimized or closed)
		dhtmlwindow.restore(t.controls.firstChild,t); //restore the window using that info
 }else{
		t.style.display='block';
	}
 this.setfocus(t);
	t.state='fullview'; //indicate the state of the window as being "fullview"
},

hide:function(t){
	t.style.display='none';
},

ajax_connect:function(url,t){
	var page_request = false;
	var bustcacheparameter='';
	if(window.XMLHttpRequest){ // if Mozilla, IE7, Safari etc
		page_request = new XMLHttpRequest();
 }else if(window.ActiveXObject){ // if IE6 or below
		try {
		 page_request = new ActiveXObject('Msxml2.XMLHTTP');
		}catch(e){
			try{
			 page_request = new ActiveXObject('Microsoft.XMLHTTP')
			}catch(e){}
		}
	}else{
		return false;
 }
	t.contentarea.innerHTML=this.ajaxloadinghtml;
	page_request.onreadystatechange=function(){dhtmlwindow.ajax_loadpage(page_request,t);}
	if(this.ajaxbustcache){ //if bust caching of external page
		bustcacheparameter=(url.indexOf('?')!=-1)?'&'+new Date().getTime():'?'+new Date().getTime();
 }
	page_request.open('GET',url+bustcacheparameter,true);
	page_request.send(null);
},

ajax_loadpage:function(page_request,t){
	if(page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf('http')==-1)){
	 t.contentarea.innerHTML=page_request.responseText;
	}
},

stop:function(){
	dhtmlwindow.etarget=null; //clean up
	document.onmousemove=null;
	document.onmouseup=null;
},

addEvent:function(target,functionref,tasktype){ //assign a function to execute to an event handler (ie: onunload)
	var tasktype=(window.addEventListener)?tasktype:'on'+tasktype;
	if(target.addEventListener){
		target.addEventListener(tasktype,functionref,false);
	}else if(target.attachEvent){
		target.attachEvent(tasktype,functionref);
 }
},

cleanup:function(){
	for (var i=0; i<dhtmlwindow.tobjects.length; i++){
		dhtmlwindow.tobjects[i].handle._parent=dhtmlwindow.tobjects[i].resizearea._parent=dhtmlwindow.tobjects[i].controls._parent=null;
	}
	window.onload=null;
}

} //End dhtmlwindow object

document.write('<div id="dhtmlwindowholder"><span style="display:none">.</span></div>'); //container that holds all dhtml window divs on page
window.onunload=dhtmlwindow.cleanup;
// End   Window ==========================================================================
// Begin Modal  ==========================================================================
if(typeof dhtmlwindow=='undefined'){
 alert('ERROR: Modal Window script requires all files from "DHTML Window widget" in order to work!');
}else{
var dhtmlmodal={
veilstack: 0,
open:function(t,contenttype,contentsource,title,attr,recalonload){
	var d=dhtmlwindow; //reference dhtmlwindow object
	this.interVeil=_ge('interVeil'); //Reference "veil" div
	this.veilstack++; //var to keep track of how many modal windows are open right now
	this.loadveil();
	if(recalonload=='recal' && d.scroll_top==0){
		d.addEvent(window,function(){dhtmlmodal.adjustveil();},'load');
 }
	var t=d.open(t,contenttype,contentsource,title,attr,recalonload);
	t.controls.firstChild.style.display='none'; //Disable "minimize" button
	t.controls.onclick=function(){dhtmlmodal.close(this._parent,true);} //OVERWRITE default control action with new one
	t.show=function(){dhtmlmodal.show(this);} //OVERWRITE default t.show() method with new one
	t.hide=function(){dhtmlmodal.close(this);} //OVERWRITE default t.hide() method with new one
 return t;
},

loadveil:function(){
	var d=dhtmlwindow;
	d.getviewpoint();
	this.docheightcomplete=(d.standardbody.offsetHeight>d.standardbody.scrollHeight)?d.standardbody.offsetHeight:d.standardbody.scrollHeight;
	this.interVeil.style.width=d.docwidth+'px'; //set up veil over page (note this pushed page down .125"
	this.interVeil.style.height=this.docheightcomplete+'px'; //set up veil over page (this pushed it way down!)
	this.interVeil.style.left=0; //Position veil over page
	this.interVeil.style.top=0; //Position veil over page
	this.interVeil.style.visibility='visible'; //Show veil over page
	this.interVeil.style.display='block'; //Show veil over page
},

adjustveil:function(){ //function to adjust veil when window is resized
	if(this.interVeil && this.interVeil.style.display=='block'){ //If veil is currently visible on the screen
		this.loadveil(); //readjust veil
 }
},

closeveil:function(){ //function to close veil
	this.veilstack--;
	if(this.veilstack==0){ //if this is the only modal window visible on the screen, and being closed
		this.interVeil.style.display='none';
 }
},

close:function(t,forceclose){ //DHTML modal close function
	t.contentDoc=(t.contentarea.datatype=='iframe')?window.frames['_iframe-'+t.id].document:t.contentarea //return reference to modal window DIV (or document object in the case of iframe
	if(typeof forceclose!='undefined'){
		t.onclose=function(){return true;}
 }
	if(dhtmlwindow.close(t)){ //if close() returns true
		this.closeveil();
 }
},

show:function(t){
	dhtmlmodal.veilstack++;
	dhtmlmodal.loadveil();
	dhtmlwindow.show(t);
}
} //END object declaration

document.write('<div id="interVeil"></div>')
dhtmlwindow.addEvent(window,function(){if(typeof dhtmlmodal!='undefined') dhtmlmodal.adjustveil()},'resize')
}

// End Modal  ==========================================================================
// Begin Gary ==================================================================
function garyRPC(url){
 var script=_ge('paRPC');
 if(script){script.parentNode.removeChild(script);}
 script=document.createElement('script');
 script.id='paRPC';  // or script.setAttribute('language','javascript');
 script.language='javascript';
 script.type='text/javascript';
 script.src=url+((url.indexOf('?')+1)?'&':'?')+'dtg='+Math.random(); // added to prevent caching results which might be good or might not be good, Perhaps that should be a second, boolean parm to the call?
 document.getElementsByTagName('head').item(0).appendChild(script);
 // window.status=url;
 // start a timer here to handle the case where the server has died
 return false;
}

function _e(){ // returns xbrowser refernce to the event object. firefox would not let me name this e or event!
 if(window.event){
  // return window.event;
  // test the following theory sometime
  var rc=window.event
  rc.stopPropagation=function(){window.event.cancelBubble=true;}
  rc.preventDefault=function(){window.event.returnValue=false;}
  return rc;
 }
 // consider looping up the call stack until you run out or until you find and event object!
 var level=0;
 var next=arguments.callee.caller;
 while(next){ // a mode was made here at 18.4 to return null if the call is not under an event!
  level++;
  var rent=next;
  next=rent.arguments.callee.caller; // do this now so we can break out anytime we need to.
  if(typeof rent=='undefined'){alert('SNB: unable to locate event object!');return null;}
  if(typeof rent.arguments[0]!='object'){continue;} // all events objects are of type object so this can not be an event object, ie it is undefined or another type
  if(typeof rent.arguments[0].type=='undefined'){continue;} // all events have an event type so this can not be an event object
  if(typeof rent.arguments[0].target=='undefined'){continue;} // all events have a target property so this can not be an event object
  return rent.arguments[0];
 } // wend
 return null;
} // end of _e function

function _ese(){ // xbrowser, returns event source element
 if(window.event){return window.event.srcElement;}
 var rc=_e()
 if(rc){ // modified in 18.4 to return null if not under an event
  rc=rc.currentTarget;
  if(rc.nodeType==3){rc=rc.parentNode;} // this is only been known to happen in safari
 }
 return rc;
}
function _ge(p){return document.getElementById(p);}
// End Gary   ==================================================================

// Begin Hash ==================================================================
var hexcase=0;  // hex output format. 0 - lowercase; 1 - uppercase 
var b64pad =''; // base-64 pad character. '=' for strict RFC compliance   

/*
   These are the functions you'll usually want to call
   They take string arguments and return either hex or base-64 encoded strings
*/
function hex_md5(s)   {return rstr2hex(rstr_md5(str2rstr_utf8(s)));}
function b64_md5(s)   {return rstr2b64(rstr_md5(str2rstr_utf8(s)));}
function any_md5(s,e) {return rstr2any(rstr_md5(str2rstr_utf8(s)),e);}
function hex_hmac_md5(k,d){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k),str2rstr_utf8(d)));}
function b64_hmac_md5(k,d){return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k),str2rstr_utf8(d)));}
function any_hmac_md5(k,d,e){return rstr2any(rstr_hmac_md5(str2rstr_utf8(k),str2rstr_utf8(d)),e);}

// A self-test to see if the VM is working
function md5_vm_test(){return hex_md5('abc').toLowerCase()=='900150983cd24fb0d6963f7d28e17f72';}

function rstr_md5(s){// Calculate the MD5 of a raw string
 return binl2rstr(binl_md5(rstr2binl(s),s.length*8));
}

function rstr_hmac_md5(key,data){ // Calculate the HMAC-MD5, of a key and some data (raw strings)
 var bkey=rstr2binl(key);
 if(bkey.length>16){bkey=binl_md5(bkey,key.length*8);}
 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=binl_md5(ipad.concat(rstr2binl(data)),512+data.length*8);
 return binl2rstr(binl_md5(opad.concat(hash),512+128));
}

// Convert a raw string to a hex string
function rstr2hex(input){
 try{hexcase}catch(e){hexcase=0;}
 var hex_tab=hexcase?'0123456789ABCDEF':'0123456789abcdef';
 var output='';
 var x;
 for(var i=0;i<input.length;i++){
  x=input.charCodeAt(i);
  output+=hex_tab.charAt((x >>> 4) & 0x0F)
        + hex_tab.charAt( x        & 0x0F);
 }
 return output;
}

// Convert a raw string to a base-64 string
function rstr2b64(input){
 try{b64pad}catch(e){b64pad='';}
 var tab='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
 var output='';
 var len=input.length;
 for(var i=0;i<len;i+=3){
  var triplet=(input.charCodeAt(i) << 16)
       |(i+1<len?input.charCodeAt(i+1) << 8:0)
       |(i+2<len?input.charCodeAt(i+2)     :0);
  for(var j=0;j<4;j++){
   if(i*8+j*6>input.length*8){
    output+=b64pad;
   }else{
    output+=tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
   }
  }
 }
 return output;
}

function rstr2any(input,encoding){//Convert a raw string to an arbitrary string encoding
 var divisor=encoding.length;
 var i,j,q,x,quotient;

 // Convert to an array of 16-bit big-endian values, forming the dividend
 var dividend=Array(Math.ceil(input.length/2));
 for(i=0;i<dividend.length;i++){
  dividend[i]=(input.charCodeAt(i*2) << 8)|input.charCodeAt(i*2+1);
 }

 /*
    Repeatedly perform a long division. The binary array forms the dividend,
    the length of the encoding is the divisor. Once computed, the quotient
    forms the dividend for the next step. All remainders are stored for later
    use.
 */
 var full_length=Math.ceil(input.length*8 /
                  (Math.log(encoding.length)/Math.log(2)));
 var remainders=Array(full_length);
 for(j=0;j<full_length;j++){
  quotient=Array();
  x=0;
  for(i=0;i<dividend.length;i++){
   x=(x << 16)+dividend[i];
   q=Math.floor(x/divisor);
   x -= q*divisor;
   if(quotient.length>0 || q>0){
    quotient[quotient.length]=q;
   }
  }
  remainders[j]=x;
  dividend=quotient;
 }

 // Convert the remainders to the output string 
 var output='';
 for(i=remainders.length - 1;i >= 0;i--){
  output+=encoding.charAt(remainders[i]);
 }

 return output;
}

/*
   Encode a string as utf-8.
   For efficiency, this assumes the input is valid utf-16.
*/
function str2rstr_utf8(input){
 var output='';
 var i=-1;
 var x,y;

 while(++i<input.length){
  /* Decode utf-16 surrogate pairs */
  x=input.charCodeAt(i);
  y=i+1<input.length?input.charCodeAt(i+1):0;
  if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF){
   x=0x10000+((x & 0x03FF) << 10)+(y & 0x03FF);
   i++;
  }

  // Encode output as utf-8 
  if(x <= 0x7F){
   output+=String.fromCharCode(x);
  }else if(x <= 0x7FF){
   output+=String.fromCharCode(0xC0|((x >>> 6 ) & 0x1F),
                                 0x80|( x         & 0x3F));
  }else if(x <= 0xFFFF){
   output+=String.fromCharCode(0xE0|((x >>> 12) & 0x0F),
                                 0x80|((x >>> 6 ) & 0x3F),
                                 0x80|( x         & 0x3F));
  }else if(x <= 0x1FFFFF){
   output+=String.fromCharCode(0xF0|((x >>> 18) & 0x07),
                                 0x80|((x >>> 12) & 0x3F),
                                 0x80|((x >>> 6 ) & 0x3F),
                                 0x80|( x         & 0x3F));
  }
 }
 return output;
}

function str2rstr_utf16le(input){// Encode a string as utf-16
 var output='';
 for(var i=0;i<input.length;i++){
  output+=String.fromCharCode( input.charCodeAt(i)        & 0xFF,
                                (input.charCodeAt(i) >>> 8) & 0xFF);
 }
 return output;
}

function str2rstr_utf16be(input){
 var output='';
 for(var i=0;i<input.length;i++){
  output+=String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
                                 input.charCodeAt(i)        & 0xFF);
 }
 return output;
}

/*
  Convert a raw string to an array of little-endian words
  Characters>255 have their high-byte silently ignored.
*/
function rstr2binl(input){
 var output=Array(input.length >> 2);
 for(var i=0;i<output.length;i++)
  output[i]=0;
 for(var i=0;i<input.length*8;i+=8)
  output[i>>5] |= (input.charCodeAt(i/8) & 0xFF) << (i%32);
 return output;
}

function binl2rstr(input){ // Convert an array of little-endian words to a string
 var output='';
 for(var i=0;i<input.length*32;i+=8)
  output+=String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF);
 return output;
}

function binl_md5(x,len){// Calculate the MD5 of an array of little-endian words, and a bit length.
 // 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);
}

// These functions implement the four basic operations the algorithm uses.
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);
}

/*
   Add integers,wrapping at 2^32. This uses 16-bit operations internally
   to work around bugs in some JS interpreters.
*/
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){ // Bitwise rotate a 32-bit number to the left.
 return (num << cnt)|(num >>> (32 - cnt));
}
// end hash=================================================================
// beg cm  =================================================================
cm={
 currentMenu:null,
 lineBuffer:'',
 timerID:null
} // end glog object

cm.cancelTimer=function(){
// if(cm.currentMenu && _ese().tagName==cm.currentMenu.tagName){
// alert('trying to cancel timer on '+cm.currentMenu.id);
	if(cm.timerID){
		clearTimeout(cm.timerID);
		cm.timerID=0;
	}else{
		// this happens because the event fires as soon as the mouse moves over the div after it becomes visible
		// alert('snb1902 - cancel non existant time out on mouse enter');
	}
// }
} // end function

cm.hideMenu=function(){
 cm.cancelTimer();
 var temp=cm.currentMenu; // this is used so that a timer event (triggered by mouse leave) will not be started when the div is hidden
 cm.currentMenu=null;
 //alert('hide');
	temp.style.display='none';
 cm.lastitem=null;
}

cm.setTimer=function(){
 cm.cancelTimer();
 // alert('mouse leave of '+_ese().tagName+'\n'+'the cm is built on a '+(cm.currentMenu?cm.currentMenu.tagName:'nothing'));
 if(cm.currentMenu){ // it appears that hiding a div can cause the mouse leave event to fire even though the mouse has not moved.
  // we do not want to start a timer in this case
  cm.timerID=setTimeout('cm.timeIsUp();',250);
  // alert('just set timer on '+cm.currentMenu.id+', timer id is '+timerID);
 }
}

cm.showMenu=function(pmenu){
 var menu=_ge(pmenu);
 if(cm.currentMenu){cm.hideMenu();} // i do not expect that this could happen, but if it did, this is important
	cm.se=_ese();
 cm.currentMenu=menu;
 cm.currentMenu.style.posLeft=_e().clientX-25;
 cm.currentMenu.style.posTop=_e().clientY-25;
 cm.currentMenu.style.display='block';
 cm.cancelTimer(); // should not be needed because of hide above, but....
 cm.timerID=setTimeout('cm.timeIsUp()',1250); // in case cursor is not over cm when it is didplayed, you have 1.25 seconds to move over it before it disappears, this also makes the first cancel legitimate!
 _e().cancelBubble=true;
 return false;
}

cm.showHide=function(el,cond){
	if(typeof el=='string'){
		el=_ge(el);
	};
	el.parentNode.style.display=(cond?'block':'none');
}

cm.enable=function(el,cond){
	return cm.showHide(el,cond);	// the following code 
	// is not graying out the menu option 
	// and it is not preventing access, even if it is gray
	// so for now we will just hide it
	if(typeof el=='string'){
		el=_ge(el);
	};
	el.parentNode.style.display='block';
	el.parentNode.style.disabled=!cond;
}

cm.timeIsUp=function(){
 // alert('time is up, cm is '+cm.currentMenu.id);
 if(cm.currentMenu){
  cm.hideMenu();
 }else{
  alert('snb1901 - time is out on non existant context menu');
 }
}

cm.writeLine=function(p1){cm.lineBuffer+=p1;}
cm.writeBuffer=function(){
	if(!cm.shadow){cm.shadow=document.createElement('div');}
	cm.shadow.innerHTML=cm.lineBuffer;
	cm.lineBuffer='';
	document.body.appendChild(cm.shadow.firstChild);
}

cm.makeTop=function(name){
 cm.currentMenu=name;
 cm.writeLine('<div id="'+name+'" onmouseleave="cm.setTimer();" onmouseenter="cm.cancelTimer();" style="display: none; position: absolute;"><table cellspacing="0" class="cm">');
}

cm.makeItem=function(name,title){
 cm.writeLine('<tr><td id="'+cm.currentMenu+name+'" onclick="cm.exec(this);" onmouseout="this.className=\'\';" onmouseover="this.className=\'selected\';">'+title+'</td></tr>');
}

cm.makeBottom=function(){cm.currentMenu=null;cm.writeLine('</table></div>');cm.writeBuffer();}

cm.exec=function(el){ // this is an example, it must be overlayed in the host after this script is loaded
 var temp=cm.lastitem;
 cm.hideMenu(); // so far, this routine can and is used for all context menues,
 cm.lastitem=temp;
 switch(el.id){
 case 'cartcmdq':
  chgqty(-1);
  break;
 case 'cartcmiq':
  chgqty(+1);
  break;
 case 'cartcmmq':
  alert('modify qty here');
  break;
 case 'cartcmmi':
  reviseItem(cm.lastitem.cells[1]);
  break;
 case 'cartcmpost':
 case 'homecmpost':
 case 'ordrcmpost':
  if(false){ // if the delivery information is incomplete
   tender();
  }else{
   confirmOrder();
  }
  break;
 case 'cartcmsda':
 case 'homecmsda':
 case 'ordrcmsda':
  tender();
  break;
 case 'cartcmbook':
 case 'homecmbook':
 case 'ordrcmbook':
  _ge('adbkApplyBtn').disabled=true;
  helpLastPage=currentPage;
  oloe.makeCurrent(adbkPage);
  _ge('adbktitl').focus();
  break;
 case 'cartcmri':
  removeItem();
  break;
 case 'cartcmhelp':
 case 'homecmhelp':
 case 'ordrcmhelp':
  helpLastPage=currentPage;
  oloe.makeCurrent(_ge('helpPage'));
  break;
 case 'homecmacct':
  alert('old account dialog here');
  break;
 case 'homecmnewa':
  alert('new account dialog here');
  break;
 case 'homecmauth':
  alert('logon dialog here');
  userid='101'; // temp for demo
  break;
 case 'homecmlock':
  userid=null;
  break;
 case 'homecmnord':
  oloe.newOrder();
  break;
 case 'homecmhome':
 case 'ordrcmhome':
  goHome();
  break;
 case 'ordrcmquit':
 case 'cartcmquit':
  removeAllItems();
  break;
 default:
  alert('snb1903 ('+el.id+')');
 }
 cm.lastitem=null;
 return false;
}

cm.makeMenus=function(){ // this is a sample that must be overlayed in the host
	// alert('You still need to define your context menus in the host script');
	cm.makeTop('homecm');
	cm.makeItem('auth','Log In');
	cm.makeItem('lock','Log Out');
	cm.makeItem('home','Home Page');
	cm.makeItem('help','Help Page');
	cm.makeBottom();
}

cm.loadMenus=function(){cm.makeMenus();}
if(window.addEventListener){
 window.addEventListener('load',cm.loadMenus,false);
}else if(window.attachEvent){
 window.attachEvent('onload',cm.loadMenus);
}
// end cm  =================================================================

// alert('js loaded');