function div(a, b) {
	return Math.floor(a / b);
}
function convertNumbersToPersian(text) {
	if (text == null)
		return null;
	text += '';
	text = text.replace(/\u0030/g, '\u06F0'); // 0
	text = text.replace(/\u0031/g, '\u06F1'); // 1
	text = text.replace(/\u0032/g, '\u06F2'); // 2
	text = text.replace(/\u0033/g, '\u06F3'); // 3
	text = text.replace(/\u0034/g, '\u06F4'); // 4
	text = text.replace(/\u0035/g, '\u06F5'); // 5
	text = text.replace(/\u0036/g, '\u06F6'); // 6
	text = text.replace(/\u0037/g, '\u06F7'); // 7
	text = text.replace(/\u0038/g, '\u06F8'); // 8
	text = text.replace(/\u0039/g, '\u06F9'); // 9

	return text;
}

function gregorianToJalali(g_y, g_m, g_d) {
	g_days_in_month = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	j_days_in_month = new Array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
	months = new Array("&#1601;&#1585;&#1608;&#1585;&#1583;&#1610;&#1606;","&#1575;&#1585;&#1583;&#1610;&#1576;&#1607;&#1588;&#1578;","&#1582;&#1585;&#1583;&#1575;&#1583;","&#1578;&#1610;&#1585;","&#1605;&#1585;&#1583;&#1575;&#1583;","&#1588;&#1607;&#1585;&#1610;&#1608;&#1585;","&#1605;&#1607;&#1585;","&#1570;&#1576;&#1575;&#1606;","&#1570;&#1584;&#1585;","&#1583;&#1610;","&#1576;&#1607;&#1605;&#1606;","&#1575;&#1587;&#1601;&#1606;&#1583;"); 
	gy = g_y - 1600;
	gm = g_m - 1;
	gd = g_d - 1;
	g_day_no = 365 * gy + div(gy + 3, 4) - div(gy + 99, 100) + div(gy + 399, 400);
	for (i = 0; i < gm; ++i) g_day_no += g_days_in_month[i];
	if (gm > 1 && ((gy % 4 == 0 && gy % 100 != 0) || (gy % 400 == 0)))
		g_day_no++;
	g_day_no += gd;
	j_day_no = g_day_no - 79;
	j_np = div(j_day_no, 12053);
	j_day_no = j_day_no % 12053;
	jy = 979 + 33 * j_np + 4 * div(j_day_no, 1461);
	j_day_no %= 1461;
	if (j_day_no >= 366) {
		jy += div(j_day_no - 1, 365);
		j_day_no = (j_day_no - 1) % 365;
	}
	for (i = 0; i < 11 && j_day_no >= j_days_in_month[i]; ++i)
		j_day_no -= j_days_in_month[i];
	jm = i + 1;
	jd = j_day_no + 1;
	return Array(convertNumbersToPersian(jy), months[jm], convertNumbersToPersian(jd))
}
