function followLink(fld,dval)
{// designed to help immitate POST
 eval('document.'+fld).value=dval;
 eval('document.'+fld).form.submit();
 return true;
}

function ccProtectFields(fld)
{
 frm=fld.form;
 readOnly=ccReadOnly(fld);
 ccDisableField(frm.ccfirst,readOnly);
 ccDisableField(frm.cclast,readOnly);
 ccDisableField(frm.ccnumber,readOnly);
// ccDisableField(frm.cvv,readOnly);   CVV is not collected any longer
 ccDisableField(frm.ccexpm,readOnly);
 ccDisableField(frm.ccexpy,readOnly);
 return;
}

function ccDisableField(fld,readOnly)
{
 fld.readOnly=readOnly;
 fld.style.background=(readOnly?'#eeeeee':'#ffffff');
 fld.style.border=(readOnly?'#eeeeee 1px solid':'black 1px solid');
 fld.style.color=(readOnly?'#eeeeee':'#000000');
}

function ccBlurField(fld)
{
 if(ccReadOnly(fld))
 {
  fld.blur();
  fld.form.paymentid.focus();
 }
}

function ccReadOnly(fld)
{
 return (fld.form.paymentid.options[fld.form.paymentid.selectedIndex].text=='Check');
}

// function designed to minimize-maximize window
function WinMoveResize(w,h)
{
 maxW=window.screen.availWidth;
 maxH=window.screen.availHeight;
 if(!h || h>maxH) h=maxH;
 if(!w || w>maxW) w=maxW;
 y=(maxH-h)/2;
 x=(maxW-w)/2;
 window.resizeTo(w,h);  // do not toss statements around!
 window.moveTo(x,y);    // 'resizeTo' than 'moveTo', some browsers are sensitive
}

function fake3D(el,ev)
{
 var bgcolor=(ev=='in')?'#e0eaea':'#f0fafa';
 var ltcolor=(ev=='in')?'#ffffff':'#f0fafa';
 var rbcolor=(ev=='in')?'#888888':'#f0fafa';
 var color=(ev=='in')?'#ff0000':'#0000ff';

 el.style.color=color;
 if(uAgent.ie) el.style.cursor='hand';
 else          el.style.cursor='pointer';
 el.style.backgroundColor=bgcolor;
// el.style.borderTopColor=ltcolor;
// el.style.borderLeftColor=ltcolor;
// el.style.borderRightColor=rbcolor;
// el.style.borderBottomColor=rbcolor;
}

/*
 function designed to toggle background color of HTML element
 which has .style.backgroundColor property
*/
function setBgColor(element,color)
{
 if(!color || color=='' || typeof(element.style)=='undefined')  return false;
 currentColor=element.style.backgroundColor;
 element.style.backgroundColor=color;
 return true;
}

/**
 function designed to support payment page
**/
function resetPayFields(fld)
{
 frm=fld.form;
 // has field been initially selected?
 chg=rshiftPoint(frm.charge.value,2);
 val=rshiftPoint(fld.value,2);
 if(fld.checked)   chg+=val;
 else              chg-=val;
 frm.charge.value=lshiftPoint(chg,2);
 return true;
}

/**
 function designed to support dir_misc::dir_getOptionChk()
**/
function optCheckBox(fld,basename,maxlim)
{
 cnt=eval('fld.form.'+basename+'cnt');
 cntmax=eval('fld.form.'+basename+'cntmax');
 if(fld.checked)
 {
  cnt.value++;
  if(maxlim && parseInt(cnt.value)>parseInt(cntmax.value))
  {
   cnt.value--;
   fld.checked=false;
   alert('Maximum number of selections is limited to '+cntmax.value);
  }
 }
 else                        cnt.value--;
 return true;
}

/**
 function designed to support banner selection page
**/
function resetPayFieldsBanner(fld)
{
 frm=fld.form;
 n=frm.choicecount.value;              // number of fields to update
 chg=rshiftPoint(frm.charge.value,2);  // base value
 crd=rshiftPoint(frm.credit.value,2);  // credit value
 s=new String(fld.value);              // clicked field value
 s=s.substr(s.indexOf("-")+1);         // extract money ->
 s=s.substr(s.indexOf("-")+1);         // portion ->
 val=rshiftPoint(s,2);                 // from value of s
 if(fld.checked)             chg+=val;
 else                        chg-=val;
 frm.charge.value=lshiftPoint(chg,2);
 frm.total.value=lshiftPoint(chg-crd,2);
 if(frm.charge0)        //   running total in each city cell
  for(i=0;i<n;i++)
   eval("frm.charge"+i).value=frm.charge.value;
 // anchored layer (<div>) with running total field
 if(false)  // turn on if using anchored 'total' window else turn off
 {
  if(uAgent.ie4up) slider.runner.value=frm.charge.value;
  if(uAgent.nav4)  topmsg.document.slider.runner.value=frm.charge.value;
  if(uAgent.gecko) document.getElementById('runner').value=frm.charge.value;
 }
 return true;
}

/**
  returns integer part of the number gotten after
  shifting decimal point z places to the right from its original position
  alternative to parseInt(n*(10^z)) which sims to have a problem with precision
  the goal is to eliminate operations such as multiplication and division
**/
function rshiftPoint(n,z)
{
 if(z<0)       return lshiftPoint(n,z);
 if(z==0)      return n;
 num=new String(n);
 pos=num.indexOf(".");
 if(pos>-1)                 num=num.substr(0,pos)+num.substr(pos+1);
 else                       pos=num.length;
 while(num.length<pos+z)    num+="0";
 return num.substr(0,pos+z).valueOf()/1;   // force integer value
}

/**
  returns string with decimal point shifted to the left by z places from original position
  works as an opposite to rshiftPoint()
**/
function lshiftPoint(n,z)
{
 if(z<0)       return rshiftPoint(n,z);
 if(z==0)      return n;
 neg=(n<0);
 n*=(neg?-1:1);
 num=new String(n);
 while(num.length<z+1)      num="0"+num;
 return (neg?"-":"")+num.substr(0,num.length-z)+"."+num.substr(num.length-z);
}

/**
  Moves selected entries from one <select> to another <select>
  Supplements 'dir_showOption'
**/
function moveDualList(s,d,ts,td)
{
 if(s.selectedIndex==-1)    return;     // if nothing is selected in source

 dl=0;
 sl=0;
 ts.value="-1";
 td.value="-1";
 n=new Array();
 for(var i=0;i<d.options.length;i++)
 {
  if(d.options[i].text=="List is empty")      continue;
  n[dl++]=new Option(d.options[i].text,d.options[i].value,false,false);
 }
 for(var i=0;i<s.options.length;i++)
 {
  if(s.options[i].text=="List is empty")      continue;
  if(s.options[i].selected)
  {
   n[dl++]=new Option(s.options[i].text,s.options[i].value,false,true);
  }
  else
  {
   ts.value=ts.value+","+s.options[i].value;
   s.options[sl++]=new Option(s.options[i].text,s.options[i].value,false,false);
  }
 }
 n.length=dl;
 n.sort(compareOptionText);       // Sort new list
 for(var i=0;i<dl;i++)
 {
  td.value=td.value+","+n[i].value;
  d.options[i]=new Option(n[i].text,n[i].value,false,n[i].selected);
 }

 d.options.length=dl;             // reset destination list size to bigger
 if(sl==0)        s.options[sl++]=new Option("List is empty","",false,false);
 s.options.length=sl;             // cut source list size to smaller
} // End of moveDualList()

/**
  Folloving 3 functions are addition to moveDualList()
**/
function compareOptionText(a,b)      {return strcmp(a.text,b.text);}
function compareOptionValue(a,b)     {return parseInt(a.value)-parseInt(b.value);}
function isListEmpty(v,msg)
{
 s=eval(v+"."+v+"r");
 if(s==null)                                                      return true;
 for(var i=0;i<s.options.length;i++)  if(s.options[i].value+0>0)  return false;
 alert(msg);                                                      return true;
}

/**
  Compares 2 strings
**/
function strcmp(a,b)
{
 var l=(a.length>b.length?a.length:b.length);
 for(var i=0;i<l;i++)
 {
  if(i>l-1)   return (a.length<b.length?-1:(a.length==b.length?0:1));
  ac=a.charCodeAt(i);
  bc=b.charCodeAt(i);
  if(ac<bc)            return -1;
  if(ac>bc)            return 1;
 }
 return 0;
}

/*
 USER_AGENT detection function
*/
function objUserAgent()
{
 // var uAgent=new objUserAgent();  // example of how to call it
 var agt=navigator.userAgent.toLowerCase();    // USER_AGENT string

 this.major=parseInt(navigator.appVersion);
 this.minor=parseFloat(navigator.appVersion);

 this.nav      =(agt.indexOf('mozilla')!=-1 && agt.indexOf('spoofer')==-1 &&
                 agt.indexOf('compatible')==-1 && agt.indexOf('opera')==-1 &&
                 agt.indexOf('webtv')==-1 && agt.indexOf('hotjava')==-1);
 this.nav2     =(this.nav && this.major==2);
 this.nav3     =(this.nav && this.major==3);
 this.nav4     =(this.nav && this.major==4);
 this.nav4up   =(this.nav && this.major>=4);
 this.navonly  =(this.nav && (agt.indexOf(";nav")!=-1 || agt.indexOf("; nav")!=-1));
 this.nav6     =(this.nav && this.major==5);
 this.nav6up   =(this.nav && this.major>=5);
 this.gecko    =(agt.indexOf('gecko')!=-1);


 this.ie       =(agt.indexOf("msie")!=-1 && agt.indexOf("opera")==-1);
 this.ie3      =(this.ie && this.major<4);
 this.ie4      =(this.ie && this.major==4 && agt.indexOf("msie 4")!=-1);
 this.ie4up    =(this.ie && this.major>=4);
 this.ie5      =(this.ie && this.major==4 && agt.indexOf("msie 5.0")!=-1);
 this.ie5_5    =(this.ie && this.major==4 && agt.indexOf("msie 5.5")!=-1);
 this.ie5up    =(this.ie && !this.ie3 && !this.ie4);
 this.ie5_5up  =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
 this.ie6      =(this.ie && this.major==4 && agt.indexOf("msie 6.")!=-1);
 this.ie6up    =(this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);

 this.aol      =(agt.indexOf("aol")!=-1);
 this.aol3     =(this.aol && this.ie3);
 this.aol4     =(this.aol && this.ie4);
 this.aol5     =(agt.indexOf("aol 5")!=-1);
 this.aol6     =(agt.indexOf("aol 6")!=-1);

 this.opera    =(agt.indexOf("opera")!=-1);
 this.opera2   =(agt.indexOf("opera 2")!=-1 || agt.indexOf("opera/2")!=-1);
 this.opera3   =(agt.indexOf("opera 3")!=-1 || agt.indexOf("opera/3")!=-1);
 this.opera4   =(agt.indexOf("opera 4")!=-1 || agt.indexOf("opera/4")!=-1);
 this.opera5   =(agt.indexOf("opera 5")!=-1 || agt.indexOf("opera/5")!=-1);
 this.opera5up =(this.opera && !this.opera2 && !this.opera3 && !this.opera4);

 this.webtv    =(agt.indexOf("webtv")!=-1);

 this.TVNav    =(agt.indexOf("navio")!=-1 || agt.indexOf("navio_aoltv")!=-1);
 this.AOLTV    =this.TVNav;

 this.hotjava  =(agt.indexOf("hotjava")!=-1);
 this.hotjava3 =(this.hotjava && this.major==3);
 this.hotjava3up=(this.hotjava && this.major>=3);

 // *** JAVASCRIPT VERSION CHECK ***
 if(this.nav2 || this.ie3)                            this.js=1.0;
 else if(this.nav3)                                   this.js=1.1;
 else if(this.opera5up)                               this.js=1.3;
 else if(this.opera)                                  this.js=1.1;
 else if((this.nav4 && this.minor<=4.05) || this.ie4) this.js=1.2;
 else if((this.nav4 && this.minor>4.05)  || this.ie5) this.js=1.3;
 else if(this.hotjava3up)                             this.js=1.4;
 else if(this.nav6 || this.gecko)                     this.js=1.5;
 else if(this.nav6up)                                 this.js=1.5;
 else if(this.ie5up)                                  this.js=1.3
 else                                                 this.js=0.0;
}

uAgent=new objUserAgent()
