;
var hadfocus='';
var setfocus='';
function afterSv(){
  GreenAll();
  applyHTML5();
  var d = document.getElementById('alert_div');
  if (d != null){
    var i = d.innerHTML;
    var r = /(<([^>]+)>)/gi;
    i = i.replace(r, "");
    if ((i != '') && (i != '\n') && (i != '\n\n') && (i != '<br />')){
      var thissound=document.getElementById('soundfail');
      if (thissound != null){
        thissound.Play();
      }
    } else {
      var thissound=document.getElementById('soundok');
      if (thissound != null){
        thissound.Play();
      }
    }
  }
}

var tables = [];
function GreenAll(){
  for(var e = 0; e < tables.length; e++){
     tables[e].table=document.getElementById(tables[e].tid); // necessary after ajax call
     if (tables[e].table != null){
       tables[e].parseCell();
       tables[e].greenBar();
     }
  }
  hidebusy();
}

//ntdialog object is a stack to manage popup dialogs
function ntdialog(){
this.level=-1;
this.luf=new Array();
this.dlg=new Array();
this.pmt=new Array();
this.open=new Array();
}

ntdialog.prototype.push = function (dlg,luf,pmt,run){
 this.level += 1;
 this.dlg[this.level] = dlg;
 this.luf[this.level] = luf;
 this.pmt[this.level] = pmt;
 this.open[this.level] =0;
 if (run == 1){
   this.run();
 }  
}

ntdialog.prototype.run = function (){
 if (this.level>-1){
  SetSessionValue('popup_'+this.dlg[this.level],1);
  jQuery('#popup_'+this.dlg[this.level]+'_div').dialog( "option", "title", this.pmt[this.level] );
  jQuery('#popup_'+this.dlg[this.level]+'_div').dialog('open');
  this.open[this.level]=1;
 }
}

ntdialog.prototype.pop = function (){
 if (this.level > -1){
  SetSessionValue('popup_'+this.dlg[this.level],0)
  this.open[this.level]=0;
  this.level -= 1;
  if (this.level > -1){
    if (this.open[this.level] == 0){
      this.run();
    }  
  }
 }
}

ntdialog.prototype.getluf = function (){
  if (this.level > -1){
    return this.luf[this.level];
  } else {
    return '';
  }    
}

ntdialog.prototype.getdlg = function (){
  if (this.level > -1){
    return this.dlg[this.level];
  } else {
    return '';
  }    
}
var ntd = new ntdialog();

// browseTable object handles all browse table related functionality.
function browseTable(id,frm,phn,rows,sp,gb,mo,hs,par,ufu,uft,dc,dcm,phf,sufu,suft,fpr,pup){
this.id = id;
this.tid = id + '_tbl';
this.table=document.getElementById(this.tid);
this.bgOver='#DDDDDD';
this.bgHigh='#CCCCCC';
this.bgOne='#FFFFFF';
this.bgTwo='#F8F8F8';
this.rowselected=-1;
this.rowshigh=rows;
this.rc=-1;
this.rs=0;
this.sproc=sp;
this.par = par;
this.gb=gb; // greenbar table.
this.mo=mo; // mouse over
this.hs=hs; // highlight selected field
this.form=document.getElementById(frm);
this.frm=frm;
this.phn=phn;
this.ufu=ufu;
this.uft=uft;
this.selectufu=sufu;
this.selectuft=suft;
this.ct=0;
this.vs=0;
this.eipclm=0;
this.dc=dc;
this.dcm=dcm;
this.quiet = 0;
tables[tables.length] = this;
this.parseCell();
this.value = phf;
this.fpr=fpr;
this.pup=pup;
}
// send async request to server
browseTable.prototype.sv = function (p0,p1,p2,p3,p4){
  var parms='';
  for(var d = 1; d < arguments.length; d++){
    parms += arguments[d] + '&';
  }
  parms += '_ParentProc=' + this.par + '&_popup_=' + this.pup + '&_rnd_=' + Math.random();
  jQuery.get(p0,parms,function(data){xmlProcess(data);});
}

browseTable.prototype.showbusy = function (){
	jQuery("#busy").dialog('open');
 /*var b = document.getElementById('_busy');
 if (b != null){
   b.style.visibility = 'visible';
 }*/
}
function hidebusy(){
	jQuery("#busy").dialog('close');
  /*var b = document.getElementById('_busy');
  if (b != null){
    b.style.visibility = 'hidden';
  }*/
}

// recursive function to find the first checkbox which is "inside" c.
function getCheckbox(c){
 if (c.type == 'checkbox'){
  return c;
 }
 if (c.firstChild != null){
  a = getCheckbox(c.firstChild);
  if (a != null){
  return a;
  }
 }
 while (c.nextSibling != null){
  a = getCheckbox(c.nextSibling);
  if (a != null){
   return a;
  }
 }
 return null;
}

// checkbox on top of column to set checkbox in whole column.
browseTable.prototype.ec = function(hcb){
 for(var i=0;i<this.table.tHead.rows[0].cells.length;i++){
  if (this.table.tHead.rows[0].cells[i] == hcb.parentNode){
   var c = i;
  }
 }
 this.quiet = 1;
 for(i=0;i<this.table.tBodies[0].rows.length;i++){
  var o = this.table.tBodies[0].rows[i].cells[c].firstChild;
  cb = getCheckbox(o);
  if (cb != null){
    cb.checked = hcb.checked;
    cb.onclick();
  }
 }
 this.quiet = 0;
}

// called to trigger eip
browseTable.prototype.eip = function(t,c,v){
 this.sv(this.sproc,'_EIPClm='+c,'ViewState='+v,'Value='+FieldValue(t),'_Quiet='+this.quiet);
}

// parses the top, left cell
browseTable.prototype.parseCell = function (){
 if (this.table == null){
   return;
 }
 if (this.table.tBodies[0] == null){
   return;
 }
 var s = this.table.tBodies[0].rows[0].cells[0].innerHTML;
 var x = s.indexOf('<!--');
 if (x==0){
  var y = s.indexOf('-->');
  if (y>x){
   s = s.slice(x+4,y);
   var parts = s.split(',');
   for (x = 0; x < parts.length; x +=2){
    switch (parts[x]){
     case "selected":
      if (this.hs ==1){
       this.rowselected = parts[x+1]-1;
      }
      break;
     case "rows":
      this.rowshigh = parts[x+1];
      break;
     case "value":
      this.value = parts[x+1];
      break;
    }
   }
  }
  s = this.table.tBodies[0].rows[0].cells[0].innerHTML;
  this.table.tBodies[0].rows[0].cells[0].innerHTML = s.slice(y+3);
 }
}
// green'bars the table. And highlights selected row.
browseTable.prototype.greenBar = function (){
 var x=0;
 var i=0;
 var j=0;
 if (this.table == null){
   return;
 }
 if (this.table.tBodies[0] == null){
   return;
 }
 if ((this.gb == 0) && (this.hs == 0) && (this.mo == 0))
 {
        return;
 }
 if (this.rowshigh>0){
  for(i=0;i<this.table.tBodies[0].rows.length;i = i - -this.rowshigh){
   for(j=0;j<this.rowshigh;j++){
    if ((parseInt(i/this.rowshigh)==this.rowselected)){
     if (this.gb==1){
      if (x==0){
       this.rs = this.bgOne;
      } else {
       this.rs = this.bgTwo;
      }
     } else {
      this.rs = this.table.tBodies[0].rows[i+j].bgColor;
     }
     this.table.tBodies[0].rows[i+j].bgColor= this.bgHigh;
    } else {
     if (this.table.tBodies[0].rows[i+j] != null){
      if (this.gb==1){
       if (x==0){
        this.table.tBodies[0].rows[i+j].bgColor=this.bgOne;
       } else {
        this.table.tBodies[0].rows[i+j].bgColor=this.bgTwo;
       }
      } else {
      this.table.tBodies[0].rows[i+j].bgColor=this.bgOne;
      }
     }
    }
   }
  if (x==0){x=1} else {x=0};
  }
 }
}
// onmouseover
browseTable.prototype.omv = function (r){
 if (this.mo==1){
  this.rc = r.bgColor
  var x=r.sectionRowIndex % this.rowshigh;
  var l=r.sectionRowIndex - (r.sectionRowIndex % this.rowshigh);
  for(x=0;x<this.rowshigh;x++){
   if (this.table.tBodies[0].rows[l+x] != null){
     this.table.tBodies[0].rows[l+x].bgColor=this.bgOver;
   }
  }
 }
}
//onmouseout
browseTable.prototype.omt = function (r){
 if (this.mo==1){
  if (this.rc == -1){
   var x=r.sectionRowIndex % this.rowshigh;
   if (x % 2 == 0){
    this.rc = this.bgOne;
   } else {
    this.rc = this.bgTwo;
   }
  }
  var x=r.sectionRowIndex % this.rowshigh;
  var l=r.sectionRowIndex - (r.sectionRowIndex % this.rowshigh);
  for(x=0;x<this.rowshigh;x++){
   if (this.table.tBodies[0].rows[l+x] != null){
    this.table.tBodies[0].rows[l+x].bgColor=this.rc;
   }
  }
 }
}
// clickrow
browseTable.prototype.cr = function (r,phf,s){
 // this.rs holds the greenbar color under the previously selected color
 // this.rowselected holds the previous row selected
 var i = parseInt(r.sectionRowIndex/this.rowshigh);
 var k = this.rowselected * this.rowshigh;
 if (this.hs ==1){
  for(var j=0;j<this.rowshigh;j++){
   this.table.tBodies[0].rows[k+j].bgColor= this.rs;
  }
 }
 this.rowselected = i;
 if (this.mo==0){
        this.rc = r.bgColor
 }
 this.rs = this.rc
 if (this.hs ==1){
  this.rc = this.bgHigh;
 }
 k = this.rowselected * this.rowshigh;
 if (this.hs ==1){
  for(j=0;j<this.rowshigh;j++){
   this.table.tBodies[0].rows[k+j].bgColor= this.bgHigh;
  }
 }
 this.sv(this.sproc,'_Clicked=1','id='+this.phn,'Value='+phf);
 if (this.par != '' && this.par != this.id){
  var lurl = this.par+'_'+this.id+'_value';
  this.sv(lurl.toLowerCase(),'event=1',this.phn+'='+phf,'_Silent='+s);
 }
 this.value = phf;
 return;
}

// finds the element, and sets the value
browseTable.prototype.setvalue = function (phf){
  this.form=document.getElementById(this.frm);
  if ((phf != null) && (phf != '')){
    this.value = phf;
  }
  if (this.phn != null){
    var e = document.getElementById(this.phn.replace(/:/g,"__"));
  }
  if ((e == null) && (this.phn != '')){
    var rid = document.createElement('INPUT');
    rid.type = 'hidden';
    rid.name = this.phn.replace(/:/g,"__");
    rid.value = this.value;
    this.form.appendChild(rid);
  } else {
    if (e != null){
      e.value = this.value;
    }
  }
}

// sets greenbaring,selected and mouse over colors for the browse.
browseTable.prototype.setGreenBar = function (h,o,t,v){
  if ((h != '') && (h != null)){
    this.bgHigh= h;
  }
  if ((o != '') && (o != null)){
    this.bgOne=o;
  }
  if ((t != '') && (t != null)){
    this.bgTwo=t;
  }
  if ((v != '') && (v != null)){
    this.bgOver=v;
  }
}

browseTable.prototype.ufut = function (){
  this.form=document.getElementById(this.frm);
  this.form.action = this.ufu;
  this.form.target = this.uft;
}

browseTable.prototype.alertParent = function(){
  if (this.par != '' && this.par != this.id){
    var lurl = this.par+'_'+this.id+'_value';
    this.sv(lurl.toLowerCase(),'event=1');
  }
}

browseTable.prototype.first = function (){
 this.showbusy();
 this.sv(this.sproc,'Refresh=first')
 this.alertParent();
}

browseTable.prototype.previous = function (){
 this.showbusy();
 this.sv(this.sproc,'Refresh=previous')
 this.alertParent();
}

browseTable.prototype.next = function (){
 this.showbusy();
 this.sv(this.sproc,'Refresh=next')
 this.alertParent();
}

browseTable.prototype.last = function (){
 this.showbusy();
 this.sv(this.sproc,'Refresh=last')
 this.alertParent();
}

browseTable.prototype.cl = function (){
 this.showbusy();
 this.sv(this.sproc,'Refresh=clearlocate')
 this.alertParent();
}

browseTable.prototype.locate = function (id,v){
 this.showbusy();
 this.sv(this.sproc,'Refresh=locate',id+'='+v)
 this.alertParent();
}

browseTable.prototype.sort = function (s){
 this.showbusy();
 this.sv(this.sproc,'Refresh=sort',this.id+'_Sort='+s);
 this.alertParent();
}

browseTable.prototype.insert = function (){
 this.ufut();
 this.dsb('insert_btn');
}

browseTable.prototype.change = function (phf){
 this.setvalue(phf);
 this.ufut();
 this.dsb('change_btn');
}

browseTable.prototype.view = function (phf){
 this.setvalue(phf);
 this.ufut();
 this.dsb('view_btn');
}

browseTable.prototype.copy = function (phf){
 this.setvalue(phf);
 this.ufut();
 this.dsb('copy_btn');
}

browseTable.prototype.deleteb = function (phf,url){
 this.form=document.getElementById(this.frm);
 if(this.dc==1){
  if(confirm(this.dcm)==false){
   return false;
  }
 }
 this.setvalue(phf);
 this.form.action = url+'?FromForm='+this.fpr;
 this.form.target = '_self';
 this.dsb('deleteb_btn');
}

browseTable.prototype.select = function (phf){
 this.setvalue(phf);
 this.form.action = this.selectufu;
 this.form.target = this.selectuft;
 this.dsb('select_btn');
}

browseTable.prototype.pselect = function (phf){
 this.setvalue(phf);
 jQuery('#'+ntd.getluf()).val(this.value);
 jQuery('#'+ntd.getluf()).change();
 jQuery('#popup_'+ntd.getdlg()+'_div').dialog('close'); // close does a ntd.pop
}

browseTable.prototype.pcancel = function (){
  jQuery('#popup_'+ntd.getdlg()+'_div').dialog('close'); // close does a ntd.pop
}

browseTable.prototype.lookup = function (lurl,ltar){
 this.form.action = lurl;
 this.form.target = ltar;
 this.dsb('lookup_btn');
}

// Lookup Date
browseTable.prototype.sd = function (id,p,ec,vs){
 this.ct = document.getElementById(id);
 switch (p){
 case "@D6":
 case "@D06":
  var c = new calendar6(this.ct);
  break;
 case "@D2":
 case "@D02":
  var c = new calendar2(this.ct);
  break;
 }
 this.eipclm = ec;
 this.vs = vs;
 c.popup();
}

// Reset After Date
browseTable.prototype.rad = function(){
 this.eip(this.ct,this.eipclm,this.vs);
}

// button pressed
browseTable.prototype.dsb = function (n){
 this.form=document.getElementById(this.frm);
 if (this.form.target == "" || this.form.target == "_self"){
         jQuery(':button').attr('disabled', 'disabled');
 }
 var pb = document.createElement('INPUT');
 pb.type = 'hidden';
 pb.name = 'pressedButton';
 pb.value = n;
 this.form.appendChild(pb);
 removePlaceHolder();
 this.form.submit();
}

browseTable.prototype.removeOtherBrowses = function (){
 var f=document.getElementById(fn);
 var dv=document.getElementById(dn);
 var a;
 var b;
 if (dv != null){
  var divs = dv.getElementsByTagName('DIV');
  for(var e = divs.length-1; e>=0 ; e--){
   if ((divs[e].id != dn) && (divs[e].id != '')){
    removeElement(fn,divs[e].id);
   }
  }
  if (f != null){
   for(var e = f.elements.length-1; e>=0 ; e--) {
    a = f.elements[e].parentNode.id;
    b = dv.id
    if (a==b){
     try{
      dv.removeChild(f.elements[e]);
     } catch (e) {
     }
    }
   }
  }
 }
}

function dsb(f,b,n,prid,prv){
 var i=0;
 if (n=='deleteb_btn'){
  if(confirm('Are you sure you want to delete this record?')==false){
   return false;
  }
 }
 // dont send files if form is cancelled.
 if (n=='cancel_btn'){
                jQuery(':file').remove();
 }
 // set all buttons disabled, if target of button is same frame.
 if (f.target == "" || f.target == "_self"){
         jQuery(':button').attr('disabled', 'disabled');
 }
 for (var e=0 ; e < f.elements.length; e++) {
   if (f.elements[e].name == prid){
    f.elements[e].value = prv;
    i = 1;
   }
 }
 if ((i==0) && (prid != '')){
  var rid = document.createElement('INPUT');
  rid.type = 'hidden';
  rid.name = prid;
  rid.value = prv;
  f.appendChild(rid);
 }
 var pb = document.createElement('INPUT');
 pb.type = 'hidden';
 pb.name = 'pressedButton';
 pb.value = n;
 f.appendChild(pb);
 osf(f);
 removePlaceHolder();
 f.submit();
}

function osf(f){
  if(f.target=='' || f.target=='_self' || f.target=='_top') {
    for (var e=0 ; e < f.elements.length; e++) {
      if(f.elements[e].type=='button'){
  f.elements[e].disabled = true;
      }
    }
  }
}

function ml(ta,ml,e){
  var k;
  if(window.event){ // IE
    k = e.keyCode
  } else if(e.which){ // Netscape/Firefox/Opera/Safari
    k = e.which
  };
  if (k==8 || k==null || k > 60000){
    return true;
  }
  return (ta.value.length <= ml);
}

function nextFocus(f,pname,skipone){
  var i = 0;
  var j = 0;
  if (skipone==2){ // pname is specified control to get focus
    for (var e=0 ; e < f.elements.length; e++) {
      if(f.elements[e].name==pname){
  try{
    f.elements[e].focus();
  } catch (e) {
  }
  break;
      }
    }
  } else {
    for (var e=0 ; e < f.elements.length; e++) {
      if (i==1){
  if ((f.elements[e].type == "text") || (f.elements[e].type == "textarea") || (f.elements[e].type == "checkbox") || (f.elements[e].type == "radio") || (f.elements[e].type == "select-one")){
    //|| (f.elements[e].type == "button")
    if(f.elements[e].readOnly != true){
      if((skipone==1) && (j==0)){
        j = 1;
      } else {
        try{
    f.elements[e].focus();
        } catch (e) {
        }
        break;
      }
    }
  }
      }
      else{
  if(pname==''){
    if(f.elements[e].readOnly != true){
      try{
        f.elements[e].focus();
      } catch (e) {
      }
      break;
    }
  } else {
    if(f.elements[e].name==pname){
      i = 1;
    }
  }
      }
    }
  }
}


function removeElement(fn,dn){
 var f=document.getElementById(fn);
 var dv=document.getElementById(dn);
 var a;
 var b;
 if (dv != null){
  var divs = dv.getElementsByTagName('DIV');
  for(var e = divs.length-1; e>=0 ; e--){
   if ((divs[e].id != dn) && (divs[e].id != '')){
    removeElement(fn,divs[e].id);
   }
  }
  if (f != null){
   for(var e = f.elements.length-1; e>=0 ; e--) {
    a = f.elements[e].parentNode.id;
    b = dv.id
    if (a==b){
     try{
      dv.removeChild(f.elements[e]);
     } catch (e) {
     }
    }
   }
  }
 }
}

/* wizard stuff

var wizActive=0;
var nextBtn;
var prevBtn;
var finishBtn;
var wizMax=0;
var wizHeight=0;
var wizX=0;
var wizTabs = new Array();

function initWizard(fn,tb,at,hi){
  var f = document.getElementById(fn);
  for (var e=0 ; e < f.elements.length; e++) {
    if(f.elements[e].name=='wiznext_btn'){
      nextBtn = f.elements[e];
    }
    if(f.elements[e].name=='wizprevious_btn'){
      prevBtn = f.elements[e];
    }
    if(f.elements[e].name=='save_btn'){
      finishBtn = f.elements[e];
    }
  }
  if (arguments.length > 3){
    wizHeight = hi;
  }
  wizMax = tb.length-1;
  wizTabs = tb;
  for(e=0 ; e < tb.length ; e++){
    wizTabs[e] = document.getElementById(tb[e]);
    if (wizTabs[e].offsetHeight > wizHeight && arguments.length <= 3){
      wizHeight = wizTabs[e].offsetHeight;
    }
    if (e>0){
      wizTabs[e].style.top = wizTabs[0].offsetTop + 'px';
    }
    wizHide(wizTabs[e])
  }
  wizHeight = wizHeight + 'px';
  wizActive = at;
  wizShow(wizTabs[wizActive],wizMax);
  wizButtons(wizActive,wizMax,prevBtn,nextBtn,finishBtn);
}
function wizNext(){
  if (wizActive < wizMax){
    wizHide(wizTabs[wizActive]);
    wizActive++;
    wizShow(wizTabs[wizActive],wizMax);
    wizButtons(wizActive,wizMax,prevBtn,nextBtn,finishBtn);
  }
}
function wizPrev(){
  if (wizActive > 0){
    wizHide(wizTabs[wizActive]);
    wizActive--;
    wizShow(wizTabs[wizActive],wizMax);
    wizButtons(wizActive,wizMax,prevBtn,nextBtn,finishBtn);
  }
}
function wizHide(a){
  if (a < 0) return;
  a.style.display='none';
  a.style.visibility='hidden';
  a.style.height = 0;
}
function wizShow(a,m){
  if (a > m) return;
  a.style.display='';
  a.style.visibility='visible';
  a.style.height = wizHeight;
}

function wizButtons(a,m,p,n,f){
  if (a ==0){
    p.disabled = true;
  }  else {
    p.disabled = false;
  }
  if (a == m){
    n.disabled = true;
    if (f != null){
      f.disabled = false;
    }
  }  else {
    n.disabled = false;
    if (f != null){
      f.disabled = true;
    }
  }
}

*/

function FieldValue(f,e){
  var ans ='';
  var typ = f.type;
  var i = 0;
  var j = 0;
  if (typ == undefined){
    typ = f[0].type;
  }
  switch (typ){
  case "radio":
    j = f.length;
    for(i = 0; i < j; i++) {
      if(f[i].checked) {
  ans = f[i].value;
  break;
      }
    }
    break;
  case "checkbox":
    if (f.checked){
      ans = f.value;
    }
    break;
  case "select-multiple":
    j = f.length;
    for(i = 0; i < j; i++) {
      if(f.options[i].selected) {
        ans = ans + ';|;' + f.options[i].value;
    }
    }
    break;
  default: ans = f.value;
  }
  // if called as a post, do not encode & and %. If called from EIP then do.
  if ((e == 0) || (e == undefined)){
                ans = ans.replace(/%/,"%25");
                ans = ans.replace(/&/,"%26");
        }
  return ans
}

var defaultButton='';
var defaultButtonSubmit=1;
var defaultButtonId=null;
function oe(ta,e) {
   var a=true;
   var k;
   if(window.event){ // IE
     k = e.keyCode
   } else if(e.which){ // Netscape/Firefox/Opera/Safari
     k = e.which
   };
   if ( k == "13" || k == "3") {
      a = false;
      k = null;
      defaultButtonId = document.getElementById(defaultButton);
      if (defaultButtonId != null){
  if (defaultButtonSubmit==1){
    // if default button is going to submit the form then just
    if (ta.onchange){
      ta.onchange();
    }
    if (defaultButtonId.click){
      defaultButtonId.click();
    }
  } else {
    // otherwise
    if (ta.onchange){
      ta.onchange();
    }
    window.setTimeout('defaultButtonId.click();',100);
    if (e && e.preventDefault)
      e.preventDefault(); // FF style
    return false; // IE style
  }
      } else {
   if (ta.onchange){
     ta.onchange();
   }
      }
   }
   return a;
}

function setDefaultButton(b,s){
  defaultButton = b;
  defaultButtonSubmit = s;
}

function SetSessionValue(name,value){
  jQuery.get('SetSessionValue',name+'='+value,function(data){xmlProcess(data);});
}

function GetTab(name){
  jQuery.get(name,'',function(data){xmlProcess(data);});
}


function xmlProcess(data){
  jQuery('response',data).each(function(i){
  var t = jQuery("response",data).get(i); // returns Element object
  var e = jQuery(t).attr("type");

  if (window.ActiveXObject) {  //for IE
      var s = t.xml;
   } else { // code for Mozilla, Firefox, Opera, etc.
      var s = (new XMLSerializer()).serializeToString(t);
   }
   s = s.substring(s.indexOf('>')+1,s.lastIndexOf('<'));
   if (e=='element'){
     d = jQuery(t).attr("id");
     jQuery("#"+d).replaceWith(s);
   } else if (e=='script'){
     //alert('incoming s = ' + s);
     eval(s);
   }
   afterSv();
  });
}

// SetServer
function sv(id,name,ev,val,par,sil){
 hadfocus = id;
  if(par==undefined){
  jQuery.get(name,{event: ev,value: val, _rnd_: Math.random()},function(data){xmlProcess(data);});
 }else{
  var parms='';
  for(var d = 2; d < arguments.length; d++){
    parms += arguments[d] + '&';
  }
  parms += '_rnd_=' + Math.random();
  jQuery.get(name,parms,function(data){xmlProcess(data);});
 }
}

//Set timer
function SetTimer(name,t,par,sil){
 if(par==undefined)  {par='fred=1'};
 if(sil==undefined)  {sil='fred=2'};
 sv('',name,'','',par,sil);
 setTimeout('SetTimer(\'' + name +'\','+t+',\''+par +'\',\'' + sil+'\')',t);
};

// SelectDate and ResetAfterDate called by Date Lookup button
var cr1;
var cs;
var ct;
var cb1;
var cb2;
// SelectDate
function sd(f,e,p,r,b1,b2){
 ct = document.forms[f].elements[e];
 switch (p){
 case "@D6":
 case "@D06":
  var c = new calendar6(ct);
  break;
 case "@D2":
 case "@D02":
  var c = new calendar2(ct);
  break;
 }
 c.popup();
 if (arguments.length == 4){
  cr1 = r;
  cs = 1;
 }
 if (arguments.length == 6){
  cr1 = r;
  cs = 2;
  cb1 = b1;
  cb2 = b2;
 }
}
// ResetAfterDate
function rad(){
 if (cs==1){
  sv('',cr1,1,ct.value);
  cs = 0;
 }
 if (cs==2){
  sv('',cr1,cb1,cb2,'Value='+ct.value);
  cs = 0;
 }
}

// jQuery Default Settings
jQuery.datepicker.setDefaults({
   closeText: 'Cancel',
   dateFormat: 'm/dd/yy',
   showButtonPanel: true,
   showOn: 'button',
   buttonImageOnly: true,
   buttonImage: 'styles/images/calendar.gif',
   buttonText: 'Calendar'
});


// html5 helper-functions for browsers that don't yet support html5.
// Modernizr is used as a detector so if browser has native support these functions do nothing.
// ---------------------------------------------
function applyPlaceHolderElement(e){
 var t = e.attr('placeholder');
 var f = e.parents('form:first');
 if (e.val() === ''){
  e.val(t);
  e.css('color', '#888');
 }
 e.bind('focus.placeholder', function(event) {
  if (e.val() === t){
   e.val('');
  }
  e.css('color', '');
 });
 e.bind('blur.placeholder', function(event) {
  if (e.val() === ''){
         e.val(t);
   e.css('color', '#888');
  }
 });
 f.bind("submit.placeholder", function(event) {
  if (e.val() === t){
   e.val("");
  }
 });
};
// ---------------------------------------------
// Jan 2010 - Webkit support placeholder on a <input> but none yet on <textarea>
function applyPlaceHolder(){
         jQuery('[placeholder]').each(function(i) {
    var e = jQuery(this);
    if (!Modernizr.input.placeholder && e.type === 'INPUT'){
    // do nothing
    } else {
                 applyPlaceHolderElement(e);
                };
         });
};
// ---------------------------------------------
function removePlaceHolder(){
 jQuery('[placeholder]').each(function(i) {
  var e = jQuery(this);
  if (e.val() === e.attr('placeholder')){
   e.val("");
  }
 });
};
// ---------------------------------------------
function applyHTML5(){
 applyPlaceHolder();
}
// ---------------------------------------------
jQuery(document).ready( function(){jQuery('.rounded').corners();});
// ---------------------------------------------
// run html5 support scripts when page opens
jQuery(document).bind('ready', function(event) {
  applyHTML5();
});

