Index: /trunk/phpgwapi/inc/class.common.inc.php
===================================================================
--- /trunk/phpgwapi/inc/class.common.inc.php	(revision 2903)
+++ /trunk/phpgwapi/inc/class.common.inc.php	(revision 2931)
@@ -419,5 +419,5 @@
 					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xevent', NULL, true );
 					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'tools','xobject', NULL, true );
-					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode', 'cookieManager', 'phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] );
+					$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'templatejs', 'cookieManager', 'phpgwapi/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] );
 
 					$this -> phpgw_header( $module_content );
Index: /trunk/phpgwapi/js/expressoAjax/bigInt.js
===================================================================
--- /trunk/phpgwapi/js/expressoAjax/bigInt.js	(revision 2847)
+++ /trunk/phpgwapi/js/expressoAjax/bigInt.js	(revision 2931)
@@ -68,112 +68,5 @@
 // Those returning boolean or int will not allocate memory except possibly on the first 
 // time they're called with a given parameter size.
-// 
-// bigInt  add(x,y)               //return (x+y) for bigInts x and y.  
-// bigInt  addInt(x,n)            //return (x+n) where x is a bigInt and n is an integer.
-// string  bigInt2str(x,base)     //return a string form of bigInt x in a given base, with 2 <= base <= 95
-// int     bitSize(x)             //return how many bits long the bigInt x is, not counting leading zeros
-// bigInt  dup(x)                 //return a copy of bigInt x
-// boolean equals(x,y)            //is the bigInt x equal to the bigint y?
-// boolean equalsInt(x,y)         //is bigint x equal to integer y?
-// bigInt  expand(x,n)            //return a copy of x with at least n elements, adding leading zeros if needed
-// Array   findPrimes(n)          //return array of all primes less than integer n
-// bigInt  GCD(x,y)               //return greatest common divisor of bigInts x and y (each with same number of elements).
-// boolean greater(x,y)           //is x>y?  (x and y are nonnegative bigInts)
-// boolean greaterShift(x,y,shift)//is (x <<(shift*bpe)) > y?
-// bigInt  int2bigInt(t,n,m)      //return a bigInt equal to integer t, with at least n bits and m array elements
-// bigInt  inverseMod(x,n)        //return (x**(-1) mod n) for bigInts x and n.  If no inverse exists, it returns null
-// int     inverseModInt(x,n)     //return x**(-1) mod n, for integers x and n.  Return 0 if there is no inverse
-// boolean isZero(x)              //is the bigInt x equal to zero?
-// boolean millerRabin(x,b)       //does one round of Miller-Rabin base integer b say that bigInt x is possibly prime? (b is bigInt, 1<b<x)
-// boolean millerRabinInt(x,b)    //does one round of Miller-Rabin base integer b say that bigInt x is possibly prime? (b is int,    1<b<x)
-// bigInt  mod(x,n)               //return a new bigInt equal to (x mod n) for bigInts x and n.
-// int     modInt(x,n)            //return x mod n for bigInt x and integer n.
-// bigInt  mult(x,y)              //return x*y for bigInts x and y. This is faster when y<x.
-// bigInt  multMod(x,y,n)         //return (x*y mod n) for bigInts x,y,n.  For greater speed, let y<x.
-// boolean negative(x)            //is bigInt x negative?
-// bigInt  powMod(x,y,n)          //return (x**y mod n) where x,y,n are bigInts and ** is exponentiation.  0**0=1. Faster for odd n.
-// bigInt  randBigInt(n,s)        //return an n-bit random BigInt (n>=1).  If s=1, then the most significant of those n bits is set to 1.
-// bigInt  randTruePrime(k)       //return a new, random, k-bit, true prime bigInt using Maurer's algorithm.
-// bigInt  randProbPrime(k)       //return a new, random, k-bit, probable prime bigInt (probability it's composite less than 2^-80).
-// bigInt  str2bigInt(s,b,n,m)    //return a bigInt for number represented in string s in base b with at least n bits and m array elements
-// bigInt  sub(x,y)               //return (x-y) for bigInts x and y.  Negative answers will be 2s complement
-// bigInt  trim(x,k)              //return a copy of x with exactly k leading zero elements
-//
-//
-// The following functions each have a non-underscored version, which most users should call instead.
-// These functions each write to a single parameter, and the caller is responsible for ensuring the array 
-// passed in is large enough to hold the result. 
-//
-// void    addInt_(x,n)          //do x=x+n where x is a bigInt and n is an integer
-// void    add_(x,y)             //do x=x+y for bigInts x and y
-// void    copy_(x,y)            //do x=y on bigInts x and y
-// void    copyInt_(x,n)         //do x=n on bigInt x and integer n
-// void    GCD_(x,y)             //set x to the greatest common divisor of bigInts x and y, (y is destroyed).  (This never overflows its array).
-// boolean inverseMod_(x,n)      //do x=x**(-1) mod n, for bigInts x and n. Returns 1 (0) if inverse does (doesn't) exist
-// void    mod_(x,n)             //do x=x mod n for bigInts x and n. (This never overflows its array).
-// void    mult_(x,y)            //do x=x*y for bigInts x and y.
-// void    multMod_(x,y,n)       //do x=x*y  mod n for bigInts x,y,n.
-// void    powMod_(x,y,n)        //do x=x**y mod n, where x,y,n are bigInts (n is odd) and ** is exponentiation.  0**0=1.
-// void    randBigInt_(b,n,s)    //do b = an n-bit random BigInt. if s=1, then nth bit (most significant bit) is set to 1. n>=1.
-// void    randTruePrime_(ans,k) //do ans = a random k-bit true random prime (not just probable prime) with 1 in the msb.
-// void    sub_(x,y)             //do x=x-y for bigInts x and y. Negative answers will be 2s complement.
-//
-// The following functions do NOT have a non-underscored version. 
-// They each write a bigInt result to one or more parameters.  The caller is responsible for
-// ensuring the arrays passed in are large enough to hold the results. 
-//
-// void addShift_(x,y,ys)       //do x=x+(y<<(ys*bpe))
-// void carry_(x)               //do carries and borrows so each element of the bigInt x fits in bpe bits.
-// void divide_(x,y,q,r)        //divide x by y giving quotient q and remainder r
-// int  divInt_(x,n)            //do x=floor(x/n) for bigInt x and integer n, and return the remainder. (This never overflows its array).
-// int  eGCD_(x,y,d,a,b)        //sets a,b,d to positive bigInts such that d = GCD_(x,y) = a*x-b*y
-// void halve_(x)               //do x=floor(|x|/2)*sgn(x) for bigInt x in 2's complement.  (This never overflows its array).
-// void leftShift_(x,n)         //left shift bigInt x by n bits.  n<bpe.
-// void linComb_(x,y,a,b)       //do x=a*x+b*y for bigInts x and y and integers a and b
-// void linCombShift_(x,y,b,ys) //do x=x+b*(y<<(ys*bpe)) for bigInts x and y, and integers b and ys
-// void mont_(x,y,n,np)         //Montgomery multiplication (see comments where the function is defined)
-// void multInt_(x,n)           //do x=x*n where x is a bigInt and n is an integer.
-// void rightShift_(x,n)        //right shift bigInt x by n bits.  0 <= n < bpe. (This never overflows its array).
-// void squareMod_(x,n)         //do x=x*x  mod n for bigInts x,n
-// void subShift_(x,y,ys)       //do x=x-(y<<(ys*bpe)). Negative answers will be 2s complement.
-//
-// The following functions are based on algorithms from the _Handbook of Applied Cryptography_
-//    powMod_()           = algorithm 14.94, Montgomery exponentiation
-//    eGCD_,inverseMod_() = algorithm 14.61, Binary extended GCD_
-//    GCD_()              = algorothm 14.57, Lehmer's algorithm
-//    mont_()             = algorithm 14.36, Montgomery multiplication
-//    divide_()           = algorithm 14.20  Multiple-precision division
-//    squareMod_()        = algorithm 14.16  Multiple-precision squaring
-//    randTruePrime_()    = algorithm  4.62, Maurer's algorithm
-//    millerRabin()       = algorithm  4.24, Miller-Rabin algorithm
-//
-// Profiling shows:
-//     randTruePrime_() spends:
-//         10% of its time in calls to powMod_()
-//         85% of its time in calls to millerRabin()
-//     millerRabin() spends:
-//         99% of its time in calls to powMod_()   (always with a base of 2)
-//     powMod_() spends:
-//         94% of its time in calls to mont_()  (almost always with x==y)
-//
-// This suggests there are several ways to speed up this library slightly:
-//     - convert powMod_ to use a Montgomery form of k-ary window (or maybe a Montgomery form of sliding window)
-//         -- this should especially focus on being fast when raising 2 to a power mod n
-//     - convert randTruePrime_() to use a minimum r of 1/3 instead of 1/2 with the appropriate change to the test
-//     - tune the parameters in randTruePrime_(), including c, m, and recLimit
-//     - speed up the single loop in mont_() that takes 95% of the runtime, perhaps by reducing checking
-//       within the loop when all the parameters are the same length.
-//
-// There are several ideas that look like they wouldn't help much at all:
-//     - replacing trial division in randTruePrime_() with a sieve (that speeds up something taking almost no time anyway)
-//     - increase bpe from 15 to 30 (that would help if we had a 32*32->64 multiplier, but not with JavaScript's 32*32->32)
-//     - speeding up mont_(x,y,n,np) when x==y by doing a non-modular, non-Montgomery square
-//       followed by a Montgomery reduction.  The intermediate answer will be twice as long as x, so that
-//       method would be slower.  This is unfortunate because the code currently spends almost all of its time
-//       doing mont_(x,x,...), both for randTruePrime_() and powMod_().  A faster method for Montgomery squaring
-//       would have a large impact on the speed of randTruePrime_() and powMod_().  HAC has a couple of poorly-worded
-//       sentences that seem to imply it's faster to do a non-modular square followed by a single
-//       Montgomery reduction, but that's obviously wrong.
-////////////////////////////////////////////////////////////////////////////////////////
+
 
 //globals
@@ -214,101 +107,4 @@
 rpprb=t; //used in randProbPrimeRounds() (which also uses "primes")
 
-////////////////////////////////////////////////////////////////////////////////////////
-
-
-//return array of all primes less than integer n
-function findPrimes(n) {
-  var i,s,p,ans;
-  s=new Array(n);
-  for (i=0;i<n;i++)
-    s[i]=0;
-  s[0]=2;
-  p=0;    //first p elements of s are primes, the rest are a sieve
-  for(;s[p]<n;) {                  //s[p] is the pth prime
-    for(i=s[p]*s[p]; i<n; i+=s[p]) //mark multiples of s[p]
-      s[i]=1;
-    p++;
-    s[p]=s[p-1]+1;
-    for(; s[p]<n && s[s[p]]; s[p]++); //find next prime (where s[p]==0)
-  }
-  ans=new Array(p);
-  for(i=0;i<p;i++)
-    ans[i]=s[i];
-  return ans;
-}
-
-
-//does a single round of Miller-Rabin base b consider x to be a possible prime?
-//x is a bigInt, and b is an integer, with b<x
-function millerRabinInt(x,b) {
-  if (mr_x1.length!=x.length) {
-    mr_x1=dup(x);
-    mr_r=dup(x);
-    mr_a=dup(x);
-  }
-
-  copyInt_(mr_a,b);
-  return millerRabin(x,mr_a);
-}
-
-//does a single round of Miller-Rabin base b consider x to be a possible prime?
-//x and b are bigInts with b<x
-function millerRabin(x,b) {
-  var i,j,k,s;
-
-  if (mr_x1.length!=x.length) {
-    mr_x1=dup(x);
-    mr_r=dup(x);
-    mr_a=dup(x);
-  }
-
-  copy_(mr_a,b);
-  copy_(mr_r,x);
-  copy_(mr_x1,x);
-
-  addInt_(mr_r,-1);
-  addInt_(mr_x1,-1);
-
-  //s=the highest power of two that divides mr_r
-  k=0;
-  for (i=0;i<mr_r.length;i++)
-    for (j=1;j<mask;j<<=1)
-      if (x[i] & j) {
-        s=(k<mr_r.length+bpe ? k : 0); 
-         i=mr_r.length;
-         j=mask;
-      } else
-        k++;
-
-  if (s)                
-    rightShift_(mr_r,s);
-
-  powMod_(mr_a,mr_r,x);
-
-  if (!equalsInt(mr_a,1) && !equals(mr_a,mr_x1)) {
-    j=1;
-    while (j<=s-1 && !equals(mr_a,mr_x1)) {
-      squareMod_(mr_a,x);
-      if (equalsInt(mr_a,1)) {
-        return 0;
-      }
-      j++;
-    }
-    if (!equals(mr_a,mr_x1)) {
-      return 0;
-    }
-  }
-  return 1;  
-}
-
-//returns how many bits long the bigInt is, not counting leading zeros.
-function bitSize(x) {
-  var j,z,w;
-  for (j=x.length-1; (x[j]==0) && (j>0); j--);
-  for (z=0,w=x[j]; w; (w>>=1),z++);
-  z+=bpe*j;
-  return z;
-}
-
 //return a copy of x with at least n elements, adding leading zeros if needed
 function expand(x,n) {
@@ -317,99 +113,9 @@
   return ans;
 }
-
-//return a k-bit true random prime using Maurer's algorithm.
-function randTruePrime(k) {
-  var ans=int2bigInt(0,k,0);
-  randTruePrime_(ans,k);
-  return trim(ans,1);
-}
-
-//return a k-bit random probable prime with probability of error < 2^-80
-function randProbPrime(k) {
-  if (k>=600) return randProbPrimeRounds(k,2); //numbers from HAC table 4.3
-  if (k>=550) return randProbPrimeRounds(k,4);
-  if (k>=500) return randProbPrimeRounds(k,5);
-  if (k>=400) return randProbPrimeRounds(k,6);
-  if (k>=350) return randProbPrimeRounds(k,7);
-  if (k>=300) return randProbPrimeRounds(k,9);
-  if (k>=250) return randProbPrimeRounds(k,12); //numbers from HAC table 4.4
-  if (k>=200) return randProbPrimeRounds(k,15);
-  if (k>=150) return randProbPrimeRounds(k,18);
-  if (k>=100) return randProbPrimeRounds(k,27);
-              return randProbPrimeRounds(k,40); //number from HAC remark 4.26 (only an estimate)
-}
-
-//return a k-bit probable random prime using n rounds of Miller Rabin (after trial division with small primes)	
-function randProbPrimeRounds(k,n) {
-  var ans, i, divisible, B; 
-  B=30000;  //B is largest prime to use in trial division
-  ans=int2bigInt(0,k,0);
-  
-  //optimization: try larger and smaller B to find the best limit.
-  
-  if (primes.length==0)
-    primes=findPrimes(30000);  //check for divisibility by primes <=30000
-
-  if (rpprb.length!=ans.length)
-    rpprb=dup(ans);
-
-  for (;;) { //keep trying random values for ans until one appears to be prime
-    //optimization: pick a random number times L=2*3*5*...*p, plus a 
-    //   random element of the list of all numbers in [0,L) not divisible by any prime up to p.
-    //   This can reduce the amount of random number generation.
-    
-    randBigInt_(ans,k,0); //ans = a random odd number to check
-    ans[0] |= 1; 
-    divisible=0;
-  
-    //check ans for divisibility by small primes up to B
-    for (i=0; (i<primes.length) && (primes[i]<=B); i++)
-      if (modInt(ans,primes[i])==0 && !equalsInt(ans,primes[i])) {
-        divisible=1;
-        break;
-      }      
-    
-    //optimization: change millerRabin so the base can be bigger than the number being checked, then eliminate the while here.
-    
-    //do n rounds of Miller Rabin, with random bases less than ans
-    for (i=0; i<n && !divisible; i++) {
-      randBigInt_(rpprb,k,0);
-      while(!greater(ans,rpprb)) //pick a random rpprb that's < ans
-        randBigInt_(rpprb,k,0);
-      if (!millerRabin(ans,rpprb))
-        divisible=1;
-    }
-    
-    if(!divisible)
-      return ans;
-  }  
-}
-
-//return a new bigInt equal to (x mod n) for bigInts x and n.
-function mod(x,n) {
-  var ans=dup(x);
-  mod_(ans,n);
-  return trim(ans,1);
-}
-
-//return (x+n) where x is a bigInt and n is an integer.
-function addInt(x,n) {
-  var ans=expand(x,x.length+1);
-  addInt_(ans,n);
-  return trim(ans,1);
-}
-
-//return x*y for bigInts x and y. This is faster when y<x.
-function mult(x,y) {
-  var ans=expand(x,x.length+y.length);
-  mult_(ans,y);
-  return trim(ans,1);
-}
-
 //return (x**y mod n) where x,y,n are bigInts and ** is exponentiation.  0**0=1. Faster for odd n.
 function powMod(x,y,n) {
   var ans=expand(x,n.length);  
-  powMod_(ans,trim(y,2),trim(n,2),0);  //this should work without the trim, but doesn't
-  return trim(ans,1);
+  powMod_(ans,bigintTrim(y,2),bigintTrim(n,2),0);  //this should work without the bigintTrim, but doesn't
+  return bigintTrim(ans,1);
 }
 
@@ -418,5 +124,5 @@
   var ans=expand(x,(x.length>y.length ? x.length+1 : y.length+1)); 
   sub_(ans,y);
-  return trim(ans,1);
+  return bigintTrim(ans,1);
 }
 
@@ -425,179 +131,6 @@
   var ans=expand(x,(x.length>y.length ? x.length+1 : y.length+1)); 
   add_(ans,y);
-  return trim(ans,1);
-}
-
-//return (x**(-1) mod n) for bigInts x and n.  If no inverse exists, it returns null
-function inverseMod(x,n) {
-  var ans=expand(x,n.length); 
-  var s;
-  s=inverseMod_(ans,n);
-  return s ? trim(ans,1) : null;
-}
-
-//return (x*y mod n) for bigInts x,y,n.  For greater speed, let y<x.
-function multMod(x,y,n) {
-  var ans=expand(x,n.length);
-  multMod_(ans,y,n);
-  return trim(ans,1);
-}
-
-//generate a k-bit true random prime using Maurer's algorithm,
-//and put it into ans.  The bigInt ans must be large enough to hold it.
-function randTruePrime_(ans,k) {
-  var c,m,pm,dd,j,r,B,divisible,z,zz,recSize;
-
-  if (primes.length==0)
-    primes=findPrimes(30000);  //check for divisibility by primes <=30000
-
-  if (pows.length==0) {
-    pows=new Array(512);
-    for (j=0;j<512;j++) {
-      pows[j]=Math.pow(2,j/511.-1.);
-    }
-  }
-
-  //c and m should be tuned for a particular machine and value of k, to maximize speed
-  c=0.1;  //c=0.1 in HAC
-  m=20;   //generate this k-bit number by first recursively generating a number that has between k/2 and k-m bits
-  recLimit=20; //stop recursion when k <=recLimit.  Must have recLimit >= 2
-
-  if (s_i2.length!=ans.length) {
-    s_i2=dup(ans);
-    s_R =dup(ans);
-    s_n1=dup(ans);
-    s_r2=dup(ans);
-    s_d =dup(ans);
-    s_x1=dup(ans);
-    s_x2=dup(ans);
-    s_b =dup(ans);
-    s_n =dup(ans);
-    s_i =dup(ans);
-    s_rm=dup(ans);
-    s_q =dup(ans);
-    s_a =dup(ans);
-    s_aa=dup(ans);
-  }
-
-  if (k <= recLimit) {  //generate small random primes by trial division up to its square root
-    pm=(1<<((k+2)>>1))-1; //pm is binary number with all ones, just over sqrt(2^k)
-    copyInt_(ans,0);
-    for (dd=1;dd;) {
-      dd=0;
-      ans[0]= 1 | (1<<(k-1)) | Math.floor(Math.random()*(1<<k));  //random, k-bit, odd integer, with msb 1
-      for (j=1;(j<primes.length) && ((primes[j]&pm)==primes[j]);j++) { //trial division by all primes 3...sqrt(2^k)
-        if (0==(ans[0]%primes[j])) {
-          dd=1;
-          break;
-        }
-      }
-    }
-    carry_(ans);
-    return;
-  }
-
-  B=c*k*k;    //try small primes up to B (or all the primes[] array if the largest is less than B).
-  if (k>2*m)  //generate this k-bit number by first recursively generating a number that has between k/2 and k-m bits
-    for (r=1; k-k*r<=m; )
-      r=pows[Math.floor(Math.random()*512)];   //r=Math.pow(2,Math.random()-1);
-  else
-    r=.5;
-
-  //simulation suggests the more complex algorithm using r=.333 is only slightly faster.
-
-  recSize=Math.floor(r*k)+1;
-
-  randTruePrime_(s_q,recSize);
-  copyInt_(s_i2,0);
-  s_i2[Math.floor((k-2)/bpe)] |= (1<<((k-2)%bpe));   //s_i2=2^(k-2)
-  divide_(s_i2,s_q,s_i,s_rm);                        //s_i=floor((2^(k-1))/(2q))
-
-  z=bitSize(s_i);
-
-  for (;;) {
-    for (;;) {  //generate z-bit numbers until one falls in the range [0,s_i-1]
-      randBigInt_(s_R,z,0);
-      if (greater(s_i,s_R))
-        break;
-    }                //now s_R is in the range [0,s_i-1]
-    addInt_(s_R,1);  //now s_R is in the range [1,s_i]
-    add_(s_R,s_i);   //now s_R is in the range [s_i+1,2*s_i]
-
-    copy_(s_n,s_q);
-    mult_(s_n,s_R); 
-    multInt_(s_n,2);
-    addInt_(s_n,1);    //s_n=2*s_R*s_q+1
-    
-    copy_(s_r2,s_R);
-    multInt_(s_r2,2);  //s_r2=2*s_R
-
-    //check s_n for divisibility by small primes up to B
-    for (divisible=0,j=0; (j<primes.length) && (primes[j]<B); j++)
-      if (modInt(s_n,primes[j])==0 && !equalsInt(s_n,primes[j])) {
-        divisible=1;
-        break;
-      }      
-
-    if (!divisible)    //if it passes small primes check, then try a single Miller-Rabin base 2
-      if (!millerRabinInt(s_n,2)) //this line represents 75% of the total runtime for randTruePrime_ 
-        divisible=1;
-
-    if (!divisible) {  //if it passes that test, continue checking s_n
-      addInt_(s_n,-3);
-      for (j=s_n.length-1;(s_n[j]==0) && (j>0); j--);  //strip leading zeros
-      for (zz=0,w=s_n[j]; w; (w>>=1),zz++);
-      zz+=bpe*j;                             //zz=number of bits in s_n, ignoring leading zeros
-      for (;;) {  //generate z-bit numbers until one falls in the range [0,s_n-1]
-        randBigInt_(s_a,zz,0);
-        if (greater(s_n,s_a))
-          break;
-      }                //now s_a is in the range [0,s_n-1]
-      addInt_(s_n,3);  //now s_a is in the range [0,s_n-4]
-      addInt_(s_a,2);  //now s_a is in the range [2,s_n-2]
-      copy_(s_b,s_a);
-      copy_(s_n1,s_n);
-      addInt_(s_n1,-1);
-      powMod_(s_b,s_n1,s_n);   //s_b=s_a^(s_n-1) modulo s_n
-      addInt_(s_b,-1);
-      if (isZero(s_b)) {
-        copy_(s_b,s_a);
-        powMod_(s_b,s_r2,s_n);
-        addInt_(s_b,-1);
-        copy_(s_aa,s_n);
-        copy_(s_d,s_b);
-        GCD_(s_d,s_n);  //if s_b and s_n are relatively prime, then s_n is a prime
-        if (equalsInt(s_d,1)) {
-          copy_(ans,s_aa);
-          return;     //if we've made it this far, then s_n is absolutely guaranteed to be prime
-        }
-      }
-    }
-  }
-}
-
-//Return an n-bit random BigInt (n>=1).  If s=1, then the most significant of those n bits is set to 1.
-function randBigInt(n,s) {
-  var a,b;
-  a=Math.floor((n-1)/bpe)+2; //# array elements to hold the BigInt with a leading 0 element
-  b=int2bigInt(0,0,a);
-  randBigInt_(b,n,s);
-  return b;
-}
-
-//Set b to an n-bit random BigInt.  If s=1, then the most significant of those n bits is set to 1.
-//Array b must be big enough to hold the result. Must have n>=1
-function randBigInt_(b,n,s) {
-  var i,a;
-  for (i=0;i<b.length;i++)
-    b[i]=0;
-  a=Math.floor((n-1)/bpe)+1; //# array elements to hold the BigInt
-  for (i=0;i<a;i++) {
-    b[i]=Math.floor(Math.random()*(1<<(bpe-1)));
-  }
-  b[a-1] &= (2<<((n-1)%bpe))-1;
-  if (s==1)
-    b[a-1] |= (1<<((n-1)%bpe));
-}
-
+  return bigintTrim(ans,1);
+}
 //Return the greatest common divisor of bigInts x and y (each with same number of elements).
 function GCD(x,y) {
@@ -658,77 +191,4 @@
     x[0]%=y[0];
     t=x[0]; x[0]=y[0]; y[0]=t;
-  }
-}
-
-//do x=x**(-1) mod n, for bigInts x and n.
-//If no inverse exists, it sets x to zero and returns 0, else it returns 1.
-//The x array must be at least as large as the n array.
-function inverseMod_(x,n) {
-  var k=1+2*Math.max(x.length,n.length);
-
-  if(!(x[0]&1)  && !(n[0]&1)) {  //if both inputs are even, then inverse doesn't exist
-    copyInt_(x,0);
-    return 0;
-  }
-
-  if (eg_u.length!=k) {
-    eg_u=new Array(k);
-    eg_v=new Array(k);
-    eg_A=new Array(k);
-    eg_B=new Array(k);
-    eg_C=new Array(k);
-    eg_D=new Array(k);
-  }
-
-  copy_(eg_u,x);
-  copy_(eg_v,n);
-  copyInt_(eg_A,1);
-  copyInt_(eg_B,0);
-  copyInt_(eg_C,0);
-  copyInt_(eg_D,1);
-  for (;;) {
-    while(!(eg_u[0]&1)) {  //while eg_u is even
-      halve_(eg_u);
-      if (!(eg_A[0]&1) && !(eg_B[0]&1)) { //if eg_A==eg_B==0 mod 2
-        halve_(eg_A);
-        halve_(eg_B);      
-      } else {
-        add_(eg_A,n);  halve_(eg_A);
-        sub_(eg_B,x);  halve_(eg_B);
-      }
-    }
-
-    while (!(eg_v[0]&1)) {  //while eg_v is even
-      halve_(eg_v);
-      if (!(eg_C[0]&1) && !(eg_D[0]&1)) { //if eg_C==eg_D==0 mod 2
-        halve_(eg_C);
-        halve_(eg_D);      
-      } else {
-        add_(eg_C,n);  halve_(eg_C);
-        sub_(eg_D,x);  halve_(eg_D);
-      }
-    }
-
-    if (!greater(eg_v,eg_u)) { //eg_v <= eg_u
-      sub_(eg_u,eg_v);
-      sub_(eg_A,eg_C);
-      sub_(eg_B,eg_D);
-    } else {                   //eg_v > eg_u
-      sub_(eg_v,eg_u);
-      sub_(eg_C,eg_A);
-      sub_(eg_D,eg_B);
-    }
-  
-    if (equalsInt(eg_u,0)) {
-      if (negative(eg_C)) //make sure answer is nonnegative
-        add_(eg_C,n);
-      copy_(x,eg_C);
-
-      if (!equalsInt(eg_v,1)) { //if GCD_(x,n)!=1, then there is no inverse
-        copyInt_(x,0);
-        return 0;
-      }
-      return 1;
-    }
   }
 }
@@ -1385,5 +845,5 @@
 
 //return x with exactly k leading zero elements
-function trim(x,k) {
+function bigintTrim(x,k) {
   var i,y;
   for (i=x.length; i>0 && !x[i-1]; i--);
Index: /trunk/phpgwapi/templates/default/head.inc.php
===================================================================
--- /trunk/phpgwapi/templates/default/head.inc.php	(revision 2628)
+++ /trunk/phpgwapi/templates/default/head.inc.php	(revision 2931)
@@ -28,5 +28,5 @@
 			. "<![endif]-->\n";
 
-	$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'jscode',
+	$GLOBALS[ 'phpgw' ] -> js -> validate_file( 'templatejs',
 		( ( ! $GLOBALS['phpgw_info']['user']['preferences']['common']['disable_slider_effects'] ) ? 'slidereffects' : 'simple_show_hide' ),
 		'phpgwapi/templates/' . $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'template_set' ], true );
Index: /trunk/phpgwapi/templates/default/js/templatejs/cookieManager.js
===================================================================
--- /trunk/phpgwapi/templates/default/js/templatejs/cookieManager.js	(revision 2565)
+++ /trunk/phpgwapi/templates/default/js/templatejs/cookieManager.js	(revision 2565)
@@ -0,0 +1,50 @@
+/*  Script contendo funcoes de manipulacao de cookies.
+	// baseado em script de Bill Dortch, hIdaho Design <bdortch@hidaho.com> e
+	// adaptado por Jorge Kinoshita.
+*/
+	function getCookieVal (offset) {
+	  var endstr = document.cookie.indexOf (";", offset);
+	  if (endstr == -1)
+	    endstr = document.cookie.length;
+	  return unescape(document.cookie.substring(offset, endstr));
+	}
+	
+	function FixCookieDate (date) {
+	  var base = new Date(0);
+	  var skew = base.getTime(); // dawn of (Unix) time - should be 0
+	  if (skew > 0)  // Except on the Mac - ahead of its time
+	    date.setTime (date.getTime() - skew);
+	}
+	//
+	//  Function to return the value of the cookie specified by "name".
+	//    name - String object containing the cookie name.
+	//    returns - String object containing the cookie value, or null if
+	//      the cookie does not exist.
+	
+	function GetCookie (name) {
+	  var arg = name + "=";
+	  var alen = arg.length;
+	  var clen = document.cookie.length;
+	  var i = 0;
+	  while (i < clen) {
+	    var j = i + alen;
+	    if (document.cookie.substring(i, j) == arg)
+	      return getCookieVal (j);
+	    i = document.cookie.indexOf(" ", i) + 1;
+	    if (i == 0) break; 
+	  }
+
+	  return 'true';
+	}
+		
+	function SetCookie (name,value,expires,path,domain,secure) {
+	  document.cookie = name + "=" + escape (value) +
+    	((expires) ? "; expires=" + expdate.toGMTString() : "") +
+	    ((path) ? "; path=" + path : "") +
+    	((domain) ? "; domain=" + domain : "") +
+	    ((secure) ? "; secure" : "");
+	}	
+	
+	var expdate = new Date ();
+	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
+	expdate.setTime (expdate.getTime() + (30 * 24 * 60 * 60 * 1000)); // Valid for 30 days.
Index: /trunk/phpgwapi/templates/default/js/templatejs/simple_show_hide.js
===================================================================
--- /trunk/phpgwapi/templates/default/js/templatejs/simple_show_hide.js	(revision 2565)
+++ /trunk/phpgwapi/templates/default/js/templatejs/simple_show_hide.js	(revision 2565)
@@ -0,0 +1,183 @@
+/*****************************************************
+ * ypSlideOutMenu
+ * 3/04/2001
+ * 
+ * a nice little script to create exclusive, slide-out
+ * menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
+ * mac and win32. I've got no linux or unix to test on but 
+ * it should(?) work... 
+ *
+ * --youngpup--
+ *****************************************************/
+
+//var isIE = false;
+//var isOther = false;
+//var isNS4 = false;
+//var isNS6 = false;
+// constructor
+function ypSlideOutMenu(id, dir, left, top, width, height,pos)
+{
+
+	this.ie  = document.all ? 1 : 0
+		this.ns4 = document.layers ? 1 : 0
+		this.dom = document.getElementById ? 1 : 0
+
+		if (this.ie || this.ns4 || this.dom) {
+			this.id			 = id
+				this.dir		 = dir
+				this.orientation = dir == "left" || dir == "right" ? "h" : "v"
+				this.dirType	 = dir == "right" || dir == "down" ? "-" : "+"
+				this.dim		 = this.orientation == "h" ? width : height
+				//this.hideTimer	 = false
+				//this.aniTimer	 = false
+				this.open		 = false
+				this.over		 = false
+				//this.startTime	 = 0
+
+				// global reference to this object
+				//this.gRef = "ypSlideOutMenu_"+id
+				//eval(this.gRef+"=this")
+
+				// add this menu object to an internal list of all menus
+				//ypSlideOutMenu.Registry[id] = this
+
+				var d = document
+
+				var strCSS = '<style type="text/css">';
+			strCSS += '#' + this.id + 'Container { visibility:hidden; '
+				if(pos)
+				{
+					strCSS += pos+':' + left + 'px; '
+				}
+				else
+				{
+					strCSS += 'left:' + left + 'px; '
+				}
+				strCSS += 'top:' + top + 'px; '
+					strCSS += 'overflow:visible; z-index:10000; }'
+					strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
+						strCSS += 'width:' + width + 'px; '
+							//		strCSS += 'height:' + height + 'px; '
+							//		strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
+							strCSS += '}'
+							strCSS += '</style>';
+
+						d.write(strCSS);
+						//	alert(strCSS);
+//						this.load()
+
+					}
+		}
+
+	ypSlideOutMenu.aLs = function(layerID)
+	{
+
+		this.isIE = false;
+		this.isOther = false;
+		this.isNS4 = false;
+		this.isNS6 = false;
+		if(document.getElementById)
+		{
+			if(!document.all)
+			{
+				this.isNS6=true;
+			}
+			if(document.all)
+			{
+				this.isIE=true;
+			}
+		}
+		else
+		{
+			if(document.layers)
+			{
+				this.isNS4=true;
+			}
+			else
+			{
+				this.isOther=true;
+			}
+		}
+
+		var returnLayer;
+		if(this.isIE)
+		{
+			returnLayer = eval("document.all." + layerID + ".style");
+		}
+		if(this.isNS6)
+		{
+			returnLayer = eval("document.getElementById('" + layerID + "').style");
+		}
+		if(this.isNS4)
+		{
+			returnLayer = eval("document." + layerID);
+		}
+		if(this.isOther)
+		{
+			returnLayer = "null";
+			alert("Error:\nDue to your browser you will probably not\nbe able to view all of the following page\nas it was designed to be viewed. We regret\nthis error sincerely.");
+		}
+		return returnLayer;
+	}
+	// HideShow 1.0	Jim Cummins - http://www.conxiondesigns.com
+
+	ypSlideOutMenu.ShowL = function(ID)
+	{
+		ypSlideOutMenu.aLs(ID).visibility = "visible";
+	}
+
+	ypSlideOutMenu.HideL =function(ID)
+	{
+		ypSlideOutMenu.aLs(ID).visibility = "hidden";
+	}
+
+	ypSlideOutMenu.HideShow = function(ID)
+	{
+
+		if((ypSlideOutMenu.aLs(ID).visibility == "visible") || (ypSlideOutMenu.aLs(ID).visibility == ""))
+		{
+			ypSlideOutMenu.aLs(ID).visibility = "hidden";
+		}
+		else if(ypSlideOutMenu.aLs(ID).visibility == "hidden")
+		{
+			ypSlideOutMenu.aLs(ID).visibility = "visible";
+		}
+	}
+
+
+	ypSlideOutMenu.showMenu = function(id)
+	{
+		//temporarly hide all selectboxes to fix IE bug with z-index  
+		if(document.all)
+		{
+			for (var i=0; i<document.all.length; i++) {
+				o = document.all(i)
+					if (o.type == 'select-one' || o.type == 'select-multiple') {
+						// todo: add check for select in div?
+						if (o.style) o.style.display = 'none';
+					}
+			}
+		}
+		ypSlideOutMenu.ShowL(id+'Container');
+
+	}
+
+	ypSlideOutMenu.hide = function(id)
+	{
+		ypSlideOutMenu.HideL(id+'Container');
+		//show all selectboxes again to fix IE bug with z-index  
+		if(document.all)
+		{
+			for (var i=0; i<document.all.length; i++) {
+				o = document.all(i)
+					if (o.type == 'select-one' || o.type == 'select-multiple') {
+						// todo: add check for select in div?
+						if (o.style) o.style.display = 'inline';
+					}
+			}
+		}
+
+	}
+
+
+
Index: /trunk/phpgwapi/templates/default/js/templatejs/slidereffects.js
===================================================================
--- /trunk/phpgwapi/templates/default/js/templatejs/slidereffects.js	(revision 2568)
+++ /trunk/phpgwapi/templates/default/js/templatejs/slidereffects.js	(revision 2568)
@@ -0,0 +1,220 @@
+/*****************************************************
+ * ypSlideOutMenu
+ * 3/04/2001
+ * 
+ * a nice little script to create exclusive, slide-out
+ * menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
+ * mac and win32. I've got no linux or unix to test on but 
+ * it should(?) work... 
+ *
+ * --youngpup--
+ *****************************************************/
+
+ypSlideOutMenu.Registry = [];
+ypSlideOutMenu.aniLen = 250;
+ypSlideOutMenu.hideDelay = 1000;
+ypSlideOutMenu.minCPUResolution = 10;
+
+// constructor
+function ypSlideOutMenu(id, dir, left, top, width, height,pos)
+{
+	this.ie  = document.all ? 1 : 0;
+		this.ns4 = document.layers ? 1 : 0;
+		this.dom = document.getElementById ? 1 : 0;
+
+		if (this.ie || this.ns4 || this.dom) {
+			this.id	 = id;
+				this.dir		 = dir;
+				this.orientation = dir == "left" || dir == "right" ? "h" : "v";
+				this.dirType	 = dir == "right" || dir == "down" ? "-" : "+";
+				this.dim		 = this.orientation == "h" ? width : height;
+				this.hideTimer	 = false;
+				this.aniTimer	 = false;
+				this.open		 = false;
+				this.over		 = false;
+				this.startTime	 = 0;
+
+				// global reference to this object
+				this.gRef = "ypSlideOutMenu_"+id;
+				eval(this.gRef+"=this");
+
+				// add this menu object to an internal list of all menus
+				ypSlideOutMenu.Registry[id] = this;
+
+				var d = document;
+
+				var strCSS = '<style type="text/css">';
+			strCSS += '#' + this.id + 'Container { visibility:hidden; ';
+				if(pos)
+				{
+					strCSS += pos+':' + left + 'px; ';
+				}
+				else
+				{
+					strCSS += 'left:' + left + 'px; ';
+				}
+				strCSS += 'top:' + top + 'px; ';
+					strCSS += 'overflow:visible; z-index:10000; }';
+					strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ';
+						strCSS += 'width:' + width + 'px; ';
+							//		strCSS += 'height:' + height + 'px; ';
+							//		strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); ';
+							strCSS += '}';
+							strCSS += '</style>';
+
+						d.write(strCSS);
+
+							this.load();
+					}
+		}
+
+	ypSlideOutMenu.prototype.load = function() {
+		var d = document;
+			var lyrId1 = this.id + "Container";
+			var lyrId2 = this.id + "Content";
+			var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1];
+			if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2);
+				var temp;
+
+					if (!obj1 || !obj2)
+						window.setTimeout(this.gRef + ".load()", 100);
+					else {
+						this.container	= obj1;
+							this.menu		= obj2;
+							this.style		= this.ns4 ? this.menu : this.menu.style;
+							this.homePos	= eval("0" + this.dirType + this.dim);
+							this.outPos		= 0;
+							this.accelConst	= (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen ;
+
+							// set event handlers.
+							if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
+						this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')");
+							this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')");
+
+							//set initial state
+							this.endSlide();
+					}
+	};
+
+	ypSlideOutMenu.showMenu = function(id)
+	{
+		var reg = ypSlideOutMenu.Registry;
+			var obj = ypSlideOutMenu.Registry[id];
+
+			//document.all.select.style="visibily:hidden";
+
+
+			//temporarly hide all selectboxes to fix IE bug with z-index  
+			if(document.all);
+			{
+				for (var i=0; i<document.all.length; i++) {
+					o = document.all(i);
+						if (o.type == 'select-one' || o.type == 'select-multiple') {
+							// todo: add check for select in div?
+							if (o.style) o.style.display = 'none';
+						}
+				}
+			}
+
+
+		if (obj.container) {
+			obj.over = true;
+
+				// close other menus.
+				for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu);
+
+					// if this menu is scheduled to close, cancel it.
+					if (obj.hideTimer) { 
+						reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer);
+						 }
+
+			// if this menu is closed, open it.
+			if (!obj.open && !obj.aniTimer) reg[id].startSlide(true);
+		}
+	};
+
+	ypSlideOutMenu.hideMenu = function(id)
+	{
+		// schedules the menu to close after <hideDelay> ms, which
+		// gives the user time to cancel the action if they accidentally moused out
+		var obj = ypSlideOutMenu.Registry[id];
+			if (obj.container) {
+				if (obj.hideTimer) window.clearTimeout(obj.hideTimer);
+					obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
+			}
+	};
+
+	ypSlideOutMenu.hide = function(id)
+	{
+		var obj = ypSlideOutMenu.Registry[id];
+			obj.over = false;
+
+			if (obj.hideTimer) window.clearTimeout(obj.hideTimer);
+
+				// flag that this scheduled event has occured.
+				obj.hideTimer = 0;
+
+					// if this menu is open, close it.
+					if (obj.open && !obj.aniTimer) obj.startSlide(false);
+
+						//show all selectboxes again to fix IE bug with z-index  
+						if(document.all)
+						{
+							for (var i=0; i<document.all.length; i++) {
+								o = document.all(i);
+									if (o.type == 'select-one' || o.type == 'select-multiple') {
+										// todo: add check for select in div?
+										if (o.style) o.style.display = 'inline';
+									}
+							}
+						}
+
+
+
+	};
+
+ypSlideOutMenu.prototype.startSlide = function(open) {
+	this[open ? "onactivate" : "ondeactivate"]();
+	this.open = open;
+	if (open) this.setVisibility(true);
+	this.startTime = (new Date()).getTime()	;
+	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution);
+};
+
+ypSlideOutMenu.prototype.slide = function() {
+	var elapsed = (new Date()).getTime() - this.startTime;
+	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide();
+	else {
+		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst);
+		if (this.open && this.dirType == "-")		d = -d;
+		else if (this.open && this.dirType == "+")	d = -d;
+		else if (!this.open && this.dirType == "-")	d = -this.dim + d;
+		else										d = this.dim + d;
+
+		this.moveTo(d);
+	}
+};
+
+ypSlideOutMenu.prototype.endSlide = function() {
+	this.aniTimer = window.clearTimeout(this.aniTimer);
+	this.moveTo(this.open ? this.outPos : this.homePos);
+	if (!this.open) this.setVisibility(false);
+	if ((this.open && !this.over) || (!this.open && this.over)) {
+		this.startSlide(this.over);
+	}
+};
+
+ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
+	var s = this.ns4 ? this.container : this.container.style;
+	s.visibility = bShow ? "visible" : "hidden";
+};
+ypSlideOutMenu.prototype.moveTo = function(p) { 
+	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px";
+};
+ypSlideOutMenu.prototype.getPos = function(c) {
+	return parseInt(this.style[c]);
+};
+
+// events
+ypSlideOutMenu.prototype.onactivate		= function() { };
+ypSlideOutMenu.prototype.ondeactivate	= function() { };
Index: /trunk/expressoMail1_2/js/jscode/draw_api_folders.js
===================================================================
--- /trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2930)
+++ /trunk/expressoMail1_2/js/jscode/draw_api_folders.js	(revision 2931)
@@ -603,5 +603,5 @@
 		var spam_span = document.getElementById( 'lINBOX/' + spamfolder + 'tree_folders' );
 
-		var folder_img = URL_SERVER + "phpgwapi/templates/" +template + "/images/foldertree_"
+		var folder_img = URL_SERVER + "phpgwapi/templates/" +template + "/images/foldertree_";
 
 		if ( trash_span )
@@ -1122,5 +1122,5 @@
 	this.prepare_box( alternate );
 	this.draw_box_messages(headers_msgs,msg_folder);
-}
+};
 
 draw_folder.prototype.prepare_box = function(alternate){
