var errorsuppress='';
function tellerror(){
if(errorsuppress){return true;}}
window.onerror=tellerror

var ISshowDivs='tform.qform'; // dot separated names of divs containing data entry form
/* ---------------------------------------------------------------------- */
function JScalculate(cString,vFld,vDIV,iDIV,eDIV){ var a,b,c,d,e,f,g,F,x,y,r,q;
F=document.forms['PHPhandleForm'];if(!F){alert('Cannot find form PHPhandleForm'); return;}
a='JScalculate input incorrect';
if(iDIV){if(x=MM_findObj(iDIV)){x.innerHTML='Input: '+cString;}}
cString=cString.replace(/[\r\n\s\t\'\"]/g,'');
// php values
r=new RegExp("[V][\[]([^\]]*)[\]]","i");
while(cString.match(r)){x=RegExp.$1;x=(x)?x:'v'; x=(isFinite(x))?x:'v'; cString=cString.replace(r,x); }
// field values
r=new RegExp("[F][\[]([^\]]*)[\]]","i");
while(cString.match(r)){x=RegExp.$1;x=(x)?x:'v'; y='v'; if(b=F.elements[x]){y=(isFinite(b.value))?b.value:'v';}
y=(y)?y:'v';cString=cString.replace(r,y); }
r=new RegExp("([\+\-][\(]?)[^0-9\(\)\+\/\*\-\.]+","i");
while(cString.match(r)){x=RegExp.$1;cString=cString.replace(r,x+'0'); }
r=new RegExp("[^0-9\(\)\+\/\*\-\.]+([\+\-])","i");
while(cString.match(r)){x=RegExp.$1;cString=cString.replace(r,'0'+x); }
r=new RegExp("[^0-9\(\)\+\/\*\-\.]+","gi"); cString=cString.replace(r,'1');
// Divide by Zero
r=new RegExp("([\/][\(]?)[\-0\.]+([^1-9])","i");
while(cString.match(r)){x=RegExp.$1;y=RegExp.$2;cString=cString.replace(r,x+'1'+y); }
r=new RegExp("([\/][\(]?)[\-0\.]+$","i");
while(cString.match(r)){x=RegExp.$1;cString=cString.replace(r,x+'1'); }
if(eDIV){if(x=MM_findObj(eDIV)){x.innerHTML='Trying: '+cString;}}
errorsuppress=1; b=eval(cString); errorsuppress='';
a=(b)?b:a;
if(vFld){if(F.elements[vFld]){F.elements[vFld].value=a;}}
if(vDIV){if(x=MM_findObj(vDIV)){x.innerHTML=a;}}
if(eDIV){if(x=MM_findObj(eDIV)){x.innerHTML='Got result from: '+cString;}}
return a;}
/* ---------------------------------------------------------------------- */
function fillMyVals(){ logLink(logoutLink,logoutText);
var myForm,pA,mA,i,j,k,v,f,x,y,r,m,n;
if(DBinValues){myForm=(document.forms["PHPhandleForm"])?document.forms["PHPhandleForm"]:document.forms[0];
if(myForm){pA=DBinValues.split('~');
for(i=0;i<pA.length;i++){mA=pA[i].split('|');k=unescape(mA[0]);v=unescape(mA[1]);
// handle unique ids
r=new RegExp("(\_[0-9]+x)$","i"); if(k.match(r)){m=RegExp.$1;n=new RegExp(m+"$","i");
for(j=0;j<myForm.elements.length;j++){f=myForm.elements[j];if(f.name){if(f.name.match(n)&& f.name.match(/Field/i)){k=f.name;}}}
}
if(k){if(myForm.elements[k]){f=myForm.elements[k];
if(f.type){
if(f.type.match(/text/i)){f.value=v;}
if(f.type.match(/select/i)){for(x=0;x<f.options.length;x++){if(f.options[x].value==v){f.options[x].selected=true;}}}
if(f.type.match(/checkbox/i) || f.type.match(/radio/) && !(f.length)){
if(f.value){f.checked=(f.value==v)?true:false;}}
} else if(f.length){for(x=0;x<f.length;x++){y=f[x];
if(y.type.match(/checkbox/i) || y.type.match(/radio/)){if(y.value){y.checked=(y.value==v)?true:false;}}}
}}}}
} // end if(myForm){
} // end if(DBinValues)
mA=ISshowDivs.split('.');for(y=0;y<mA.length;y++){
if(x=MM_findObj(mA[y])){x=(x.style)?x.style:x; x.visibility='visible';}}
}
/* ---------------------------------------------------------------------- */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf('?'))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;}
/*-----------------------------------------------------------------------------------------*/
function gengetCookie (cN) {var dC,n,l,c,b,e; dC=document.cookie;n=cN + '=';l=dC.length;c=0;
while(c<l){b=c+n.length;if (dC.substring(c,b)==n){e=dC.indexOf(';',b);if(e==-1){e=l;}
return unescape(dC.substring(b,e));}c=dC.indexOf(' ',c)+1;if(c==0){break;}}return null;}
/*-----------------------------------------------------------------------------------------*/
function gensetCookie (cN,cV,cE){if(!cE){cE=new Date();}
document.cookie=cN+'='+escape(cV)+'; expires='+cE.toGMTString()+'; path=/';}
/*-----------------------------------------------------------------------------------------*/
function autoSetCookie(cN,cV,cE){var ck=gengetCookie(cN);if (ck){ // refresh cookie
gensetCookie(cN,ck,cE);}else{gensetCookie(cN,cV,cE); ck=cV;}return ck;}
/*-----------------------------------------------------------------------------------------*/
// initialise general and edit cookies with zero value. Logon will add a specific value if appropriate
// using gensetCookie to ovverride default value setting
// to logout call gensetCookie with 0 value and empty string for cookieExpires
/* ---------------------------------------------------------------------- */
function logLink(h,t){ var x,v,i; if(v=document.links){if(v.length){
for(x=0;x<v.length;x++){if(v[x].href){if(v[x].href.match(/loglink\_here/i)){
v[x].href=h;v[x].innerHTML=t;}}}}}}

function logMove(c,u){
gensetCookie(c,0,''); self.location.replace(u);}
/* ---------------------------------------------------------------------- */
function submitStuff(){return;}
/* ---------------------------------------------------------------------- */
function printWindow(){
   bV = parseInt(navigator.appVersion)
   if (bV >= 4) window.print()
}

