function getJulian(myday, mymonth, myyear) {
    MM=eval(mymonth)
    DD=eval(myday)
    YY=eval(myyear)
    with (Math) {  
      GGG = 1;
      if (YY <= 1585) GGG = 0;
      JD = -1 * floor(7 * (floor((MM + 9) / 12) + YY) / 4);
      S = 1;
      if ((MM - 9)<0) S=-1;
      A = abs(MM - 9);
      J1 = floor(YY + S * floor(A / 7));
      J1 = -1 * floor((floor(J1 / 100) + 1) * 3 / 4);
      JD = JD + floor(275 * MM / 9) + DD + (GGG * J1);
      JD = JD + 1721027 + 2 * GGG + 367 * YY;
    }
	return JD;
}

function getJulianFulldate(date){
	var mySplit = date.split("/");
	return getJulian(mySplit[1], mySplit[0], mySplit[2]);
}

/*  MOD  --  Modulus function which works for non-integers.  */
function mod(a, b)
{
    return a - (b * Math.floor(a / b));
}

var GREGORIAN_EPOCH = 1721425.5;


function gregorian_to_jd(year, month, day)
{
    return (GREGORIAN_EPOCH - 1) +
           (365 * (year - 1)) +
           Math.floor((year - 1) / 4) +
           (-Math.floor((year - 1) / 100)) +
           Math.floor((year - 1) / 400) +
           Math.floor((((367 * month) - 362) / 12) +
           ((month <= 2) ? 0 :
                               (leap_gregorian(year) ? -1 : -2)
           ) +
           day);
}

//  LEAP_GREGORIAN  --  Is a given year in the Gregorian calendar a leap year ?
function leap_gregorian(year)
{
    return ((year % 4) == 0) &&
            (!(((year % 100) == 0) && ((year % 400) != 0)));
}

function jd_to_cal( jd ){
//alert("in jd_to_cal " + jd);
    var wjd, depoch, quadricent, dqc, cent, dcent, quad, dquad,
        yindex, dyindex, year, yearday, leapadj;

    wjd = Math.floor(jd - 0.5) + 0.5;
    depoch = wjd - GREGORIAN_EPOCH;
//    depoch = wjd - 1721425.5;
//alert("made it this far");
    quadricent = Math.floor(depoch / 146097);
    dqc = mod(depoch, 146097);
    cent = Math.floor(dqc / 36524);
    dcent = mod(dqc, 36524);
    quad = Math.floor(dcent / 1461);
    dquad = mod(dcent, 1461);
    yindex = Math.floor(dquad / 365);
    year = (quadricent * 400) + (cent * 100) + (quad * 4) + yindex;
    if (!((cent == 4) || (yindex == 4))) {
        year++;
    }
    yearday = wjd - gregorian_to_jd(year, 1, 1);
    leapadj = ((wjd < gregorian_to_jd(year, 3, 1)) ? 0
                                                  :
                  (leap_gregorian(year) ? 1 : 2)
              );
    month = Math.floor((((yearday + leapadj) * 12) + 373) / 367);
    day = (wjd - gregorian_to_jd(year, month, 1)) + 1;

//    return new Array(year, month, day);
	var retval = month + "/" + day + "/" + year;
//alert("leaving with " + retval);
	return retval;
}

function getdata(what,where) { // get data from source (what)
	// set the where window to the loading image
	var tempTable = '<table class="data_table" border="0" bordercolor="#dedede" width="640" align="center">';
	tempTable = tempTable + '<tr>';
	tempTable = tempTable + '<td valign="top">';
	tempTable = tempTable + '<p>Loading...</p>';
	tempTable = tempTable + '</td>';
	tempTable = tempTable + '</tr>';
	tempTable = tempTable + '</table>';

//alert("we are here");
	 try {
   xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
  		new ActiveXObject("Microsoft.XMLHTTP");
	 }
	 catch (e) { /* do nothing */ }
//alert("made it this far");
	document.getElementById(where).innerHTML = tempTable;
// 		document.getElementById(where).innerHTML ="put load image here";
// we are defining the destination DIV id, must be stored in global variable (ajaxdestination)
//alert("made it that far");
	 ajaxdestination=where;

	 
//alert("destination set");
 	xmlhttp.onreadystatechange = triggered; // when request finished, call the function to put result to destination DIV
//alert("about to get");
 	xmlhttp.open("GET", what);
//alert("got, about to send");
 	xmlhttp.send(null);
//alert("about to return");
  return false;
}

function triggered() { // put data returned by requested URL to selected DIV
//alert("in triggered - destination = " + ajaxdestination);
  if (xmlhttp.readyState == 4) if (xmlhttp.status == 200) {
//alert("response = " + xmlhttp.responseText);
//alert("ajaxdestination is " + ajaxdestination);
    document.getElementById(ajaxdestination).innerHTML =xmlhttp.responseText;
  }
}
