// this part runs off the main page and executes when you press the Pick Date button

function attachChangeCurrYear() {
  if (document.getElementById) {
    if (document.getElementById('ChangecYear')) {
      document.getElementById('ChangecYear').onchange=function() {
        document.frmChangeCurrYear.submit();
      }
    }
  }
}

function attachChangeCurrMonth() {
  if (document.getElementById) {
    if (document.getElementById('ChangecMonth')) {
      document.getElementById('ChangecMonth').onchange=function() {
//        document.frmChangeCurrMonth.submit();
        document.forms['frmChangeCurrMonth'].submit(); 
      }
    }
  }
}

function attachgetCalendar() {
  if(document.getElementsByTagName&&document.getElementById) {
    x=document.getElementsByTagName('input');
    for (i=0;i<x.length;i++) {
      thisid=x[i].getAttribute('id');
      if (Left(thisid,9)=="pickdate-") {
        relatedid=Replace(thisid,'pickdate-','');
        if (document.getElementById(relatedid)) {
          document.getElementById(relatedid).onfocus=blockDateInput;
//          document.getElementById(relatedid).onblur=removeYellow;
        }
        x[i].onclick=getCalendar;
      }  
    }
  }
}
  
function blockDateInput() {
  thisid=this.getAttribute('id');
  document.getElementById('pickdate-'+thisid).style.background='yellow';
  document.getElementById('pickdate-'+thisid).focus();
}

function removeYellow() {
  thisid=this.getAttribute('id');
	document.getElementById('pickdate-'+thisid).style.background='#ccc';
}


function getCalendar() {
  this.style.background='#D4D0C8';
  popitup('/pop_date_picker.asp?fid='+this.getAttribute('id'),'300','300');
}  


// This part runs off the Calendar Form itself

function attachsetDate() {
  if(document.getElementsByTagName&&document.getElementById) {
    if(document.getElementById('calendarbody')) {
      x=document.getElementById('calendarbody').getElementsByTagName('a');
      for (i=0;i<x.length;i++) {
        x[i].onclick=settheDate;
      }  
    }
  }
}

function settheDate() {
  date_array=this.getAttribute('id').split('_');
  if (date_array.length>=3) {
    yr=date_array[1];
    mth=date_array[2];
    dy=date_array[3];
    
    if (Len(mth)==1) {
      mth='0'+mth;
    }
    if (Len(dy)==1) {
      dy='0'+dy
    }
    thedate=yr+'/'+mth+'/'+dy
    formid=Replace(document.returnfields.formid.value,'pickdate-','');
    opener.document.getElementById(formid).value=thedate;
    self.close();
  }
}



addEvent(window, "load", attachsetDate);
addEvent(window, "load", attachgetCalendar);
addEvent(window, "load", attachChangeCurrYear);
addEvent(window, "load", attachChangeCurrMonth);
