<!--

////////////////////////////////////////////////////////
// Copyright 2003, Timothy James Forsythe, all rights reserved.
// Permission granted to use, copy, modify, and distribute so long as
// the above copyright and this permission statement are retained in all
// copies.  THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
//
// based on the algorithms of ?
////////////////////////////////////////////////////////

function intPart(floatNum)
{
  if (floatNum< -0.0000001)
  {
    return Math.ceil(floatNum-0.0000001);
  }
  return Math.floor(floatNum+0.0000001);	
}

function HJDate(d,dstr,m,mstr,y)
{
  this.d    = d;
  this.dstr = dstr;
  this.m    = m;
  this.mstr = mstr;
  this.y    = y;
}

function JDNToHijra(jdn) 
{
  var DAYS   = new Array("Monday", "Tuesday", "Wednsday", "Thursday", "Friday", "Saturday", "Sunday");
  var MONTHS = new Array("Muharram", "Safar", "Rabi'u'l-Avval", "Rabi'u'th-Thani", "Jumadiyu'l-Avval", "Jumadiyu'th-Thani", "Rajab", "Sha'ban", "Ramadan", "Shavval", "Dhi'l-Qa'dih", "Dhi'l-Hijjih");
  
  var date = new HJDate(0,0,0,0,0);
  var l;
  var j;
  var n;
  
  if (jdn >= 1948440)
  {
    l = jdn-1948440+10632;
    n = intPart((l-1)/10631);
    l = l-10631*n+354;
    j = (intPart((10985-l)/5316))*(intPart((50*l)/17719))+(intPart(l/5670))*(intPart((43*l)/15238));
    l = l-(intPart((30-j)/15))*(intPart((17719*j)/50))-(intPart(j/16))*(intPart((15238*j)/43))+29;
  
    date.m    = intPart((24*l)/709);
    date.d    = l-intPart((709*date.m)/24);
    date.y    = 30*n+j-30;
    
    date.dstr = DAYS[jdn%7];
    date.mstr = MONTHS[date.m-1];
  }
  else
  {
    date.m    = -1;
    date.d    = -1;
    date.y    = "";
    date.dstr = "";
    date.mstr = "";
  }

  return date;
}

function HijraToJDN(d,m,y) 
{
  var jdn;
  
  if (y > 0)
  {
    jdn = intPart((11*y+3)/30)+354*y+30*m-intPart((m-1)/2)+d+1948440-385;
  }  
  else
  {
    alert("Please enter a positive year");
  }
	
  return jdn;
}

//-->

