function PicFit(picid,maxH,maxW){
var p,r,h,w;
p=document.getElementById(picid);
var r=p.width/p.height;
if( p.height > maxH ){ p.height = maxH; p.width = maxH * r }
if( p.width > maxW ){ p.width = maxW; p.height = maxW /  r }
}

function ltov(L,d,quot){
if ("string"==typeof L){var s=L[0];d=(d)? d : "|";L=L.split(d)}
if (quot){for (var i=0;i<L.length;i++){
		L[i]=quot+L[i]+quot}
	}
return L
}

function vtol(v,d){
d=d||',';
if ("array"==typeof v){v=v.join(d)}
return(this)
}

function trim(str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function arraydrop(arrObj,n) { // remove first n elements
	var tempArray = new Array();n=n||1 
	for(var p = n; p < arrObj.length; p++) {
		tempArray[p - n] = arrObj[p];
		}
	return tempArray;
	}

function arraypick(arrObj,n) { 
	var tempArray = new Array(n.length) 
	for(var p = 0; p < n.length; p++) {
		tempArray[p] = arrObj[n[p]];
		}
	return tempArray;
	}

function stringtomat(S) { //creates 2 dimensional array from |¬ delimitted string 
		if ("string"==typeof S){
		S = ltov(S,'¬') 
		for(var i = 0; i < S.length; i++) { 
		//if (i<1){alert("43 S is "+S[i])}
		S[i] = ltov(S[i],'|') }
	}
return S;
}

function invert_array(A) { 
	var AL=A.length;var IL=A[0].length
	var x,y,z,I;
	I=new Array(IL);z=new Array(AL);
	for(x = 0; x < IL; x++) {
		for(y = 0; y < AL; y++) {
		z[y]=A[y][x];
		}
	I[x]=z.join('|');
	}
//alert(I[0]+"=Inv 0 Inv 1="+I[1])
return I;
}	

function makenum_array(A,F) { 
	for(var i = 0; i < A.length; i++) { 
		if (F){ A[i] = parseFloat(A[i])
		}else{A[i] = parseInt(A[i]) }
}
return A;
}



function negif(N,test){return (test)?-N:N}

function enquote(a){return ('"'+a+'"')}

function range(b,t,rev) { //creates array from b to t 
	var R,i;
	R=new Array();
	for(var i = b; i <= t; i++) { R.push(i)}
	if(rev==1){ R.reverse() };
	return R;
	}

function RandomArray(n) {
	var rand,temp,newnumber;
	rand = new Array(n)

	for (i = 0; i < n; i++) {
		rand[i] = i
	}
	for (i = 0; i < n; i++) {
		newnumber = ( Math.random() * (n-1) )
		newnumber = parseInt(newnumber, 10)
		temp = rand[i]
		rand[i] = rand[newnumber]
		rand[newnumber] = temp
	}
return(rand);
}


function MakeNum(x){
	x=parseInt(x)
	if (isNaN(x)){x=0}
	return (x)
	}

// Ensure that each number printed as a string 
// is in 0.00 format
function numberFormat(amount) {
	var rawNumStr = round(amount) + '';
	rawNumStr = (rawNumStr.charAt(0) == '.' ? '0' + rawNumStr : rawNumStr);
	if (rawNumStr.charAt(rawNumStr.length - 3) == '.') {
		return rawNumStr
		}
	else if (rawNumStr.charAt(rawNumStr.length - 2) == '.') {
		return rawNumStr + '0';
		}
	else { return rawNumStr + '.00'; }
	}

// Round all passed numbers to two 
// decimal places (hundredths place)
function round(number,decPlace) {
	decPlace = (!decPlace ? 2 : decPlace);
	return Math.round(number * Math.pow(10,decPlace)) / Math.pow(10,decPlace);
	}

function arraysearch(A,S){
if(S!=null||999){
	A=ltov(A);
	var a=A.length
	for (x=0;x<a;x++){
	if (-1<A[x].indexOf(S)){return (x)}
    	}}
return (-1)}


var secscount=0,pausesecs=0,pausethen 
function pause(){
secscount++
if (secscount>pausesecs){secscount=0;pausesecs=0;pausethen;return(1)} 
setTimeout("pause()", 1000)
}


//SORT FUNCTIONS
SortType='u';
function multisort(array1, array2, ud){
var copy1=new Array();
var copy2=new Array();
var smartDouble=new Array();
for(var i=0;i<array1.length;i++){
copy1.length++
copy1[copy1.length-1]=array1[i]
smartDouble.length++;
smartDouble[smartDouble.length-1]=0;
};
copy2.length=copy1.length;
SortType=(ud) ? ud : 'u'; //default is sort up & case insensitive
copy1.sort(JCsort)
var redrawCopy2=0;
for(var x=0;x<copy1.length;x++){
for(var y=0;y<array1.length;y++){
if(copy1[x]==array1[y]){
if(smartDouble[y]==1){continue}
copy2[redrawCopy2++]=array2[y];
smartDouble[y]=1;}}}
return new Array(copy1,copy2);
}

function JCsort(a,b){
var ud=0;
if (!isNaN(a-b)){ ud=a-b }
else{
  	if (SortType=='u'||SortType=='d'){
		a=a.toLowerCase();
		b=b.toLowerCase();
		}
	try{
		if (a == b){ud=0}
		else if(a < b){ud=-1}
		else if (a > b){ud=1}
		}
	catch(e){return 0}//alert((dltypeof(a))+"=type a \n a="+a+"\n b="+b)}
	}
if (SortType=='D'||SortType=='d'){ud=ud*-1}
return ud;
}


/* 
NUMERIC SORT
var List2 = new Array(14,505,1000,132,56)
function compareNumbers(a, b) {
   return a-b
}
document.write(List2.sort(compareNumbers))

____________________________________________

see http://www.unitedscripters.com/scripts/array8.html
to get the "value" of a jscript associate array index use 

for (anItem in aa)
{
  alert("The value of item '" + anItem + "' is " + aa[anItem]);
}

*/

function hasher(array,outputType, noPrepend){
var hash=new Array(0)
var nullHash=new Array(0);
if(!outputType){
 for(var H=0;H<array.length;H++){
  var H2=(!noPrepend)?"#"+array[H]:array[H];
  if(hash[H2]){
   hash[H2].length++
   hash[H2][hash[H2].length-1]=H
  continue;}
 hash[H2]=new Array();
 hash[H2].length++
 hash[H2][hash[H2].length-1]=H
 }
}
else if (outputType){
  for(var H=0;H<array.length;H++){
  var H2=(!noPrepend)?"#"+array[H]:array[H];
   if(!array[H]||array[H]==null){
    if(nullHash[H2]){
     nullHash[H2].length++
     nullHash[H2][nullHash[H2].length-1]=H
    continue}
    nullHash[H2]=new Array();
    nullHash[H2].length++
    nullHash[H2][nullHash[H2].length-1]=H
   continue;}
  if(hash[H2]){
   hash[H2].length++
   hash[H2][hash[H2].length-1]=H
  continue;}
 hash[H2]=new Array();
 hash[H2].length++
 hash[H2][hash[H2].length-1]=H
 }
}
return (!outputType)?hash:
(outputType==1)?nullHash:
new Array(hash,nullHash)
/*with thanks to http://www.unitedscripters.com */
}  

//____________________________________________________________________
//OLD FUNCS

function mytip(ev){
//alert(this.id);
ev=(ev)?ev:((window.event) ? window.event : null);
var mm=ev.type;
alert(mm);
/*
var card=ev.target
//card = (card.currentTarget) ? card.currentTarget : card.element; 
card = ( card.element ) ? card.element : card;


status=(mm+"=mm id="+card.id);
//lay.tip.setVisible(mm=="mouseover")
*/
}

function jpgLoad(ims,n,w,h){
jpgdir=root+"pics/"
return picload(ims,"jpg",jpgdir,n,w,h)}

function gifLoad(ims,n,w,h){
gifdir=root+"images/"
return picload(ims,"gif",gifdir,n,w,h)}

function picload(imsrc,typ,dir,n,w,h){
var a,i,s,z="()"
if (w&&h){z="("+w+","+h+")"}
n=n||0
typ="."+typ||"jpg"
if (!dir){dir=jpgdir}
if (n<2){ims=ltov(imsrc)}
	else{ims=new Array();
	for (i=0;i<n;i++){ims[i]=imsrc+(i+1);}
	}
for(i=0;i<ims.length;i++) {
	a=ims[i]+" = new Image"+z
	s=dir+ims[i]+typ
	s=ims[i]+'.src = "'+s+'"'
	//alert(s+"=s a="+a)
	eval (a);eval (s)}
return (ims)
}

function dynchgImgSrc(lay,newImg){
if (newImg){lay.setBgImage(eval(newImg+".src"))}
else{
var I=1+lay.imcount||999; I=I*(lay.ims.length>I)
lay.imcount=I;I=lay.ims[I];lay.setBgImage(eval(I+".src"))}
}

function currentImgno(lay){
var i=lay.getBgImage();i=parseInt(i.charAt(i.length-5))
return i
}

//______________________________________
function readTableCells(id) {

  var tableEl = document.getElementById(id);
  if (!tableEl){return ''};
  var r, c, i, j, d, e, tr, data='';
	r=tableEl.rows.length-1;
	if (r < 0){return ''};
		
	for (i = 0; i <= r; i++){
		tr='';
		c=tableEl.rows[i].cells.length - 1;
		for (j = 0; j <= c; j++){
			d='';
			e=tableEl.rows[i].cells[j].firstChild;
			if(e){
				
				if (e.nodeValue) {d=e.nodeValue;}
				else if(e.firstChild){d=e.firstChild.nodeValue;} 
				}
			tr+=d;
			tr+=(j<c)?'|' : (i<r) ? '¬' : ' ';
		}
	//alert(i+"=i tr="+tr);
	data+=tr;
	}
  return (data);
}
/*__________________________________________________________________________________
Pass Array from PHP to Javascript

<SCRIPT>

javascriptArray = new Array();

<?php

$array = ( 'list', 'of', 'elements' );

foreach ( $array as $element )
{
print "javascriptArray.push( $element );";
}

?>

</SCRIPT>
*/
