// JavaScript Document
var Lng
var Lat
var TimeZone
//---------------------- Trigonometric Functions -----------------------

// degree sin
dsin = function(d)
{
    return Math.sin(dtr(d));
}

// degree cos
dcos = function(d)
{
    return Math.cos(dtr(d));
}

// degree tan
dtan = function(d)
{
    return Math.tan(dtr(d));
}

// degree arcsin
darcsin = function(x)
{
    return rtd(Math.asin(x));
}

// degree arccos
darccos = function(x)
{
    return rtd(Math.acos(x));
}

// degree arctan
darctan = function(x)
{
    return rtd(Math.atan(x));
}

// degree arctan2
darctan2 = function(y, x)
{
    return rtd(Math.atan2(y, x));
}

// degree arccot
darccot = function(x)
{
    return rtd(Math.atan(1/x));
}

// degree to radian
dtr = function(d)
{
    return (d * Math.PI) / 180.0;
}

// radian to degree
rtd = function(r)
{
    return (r * 180.0) / Math.PI;
}

function Ta(a){
	a=  (1/15* darccos((-dsin(a)- dsin(Lat)*dsin(d)) 
			/(dcos(Lat) *dcos(d) )));
	return a
}
// range reduce angle in degrees.
function fixangle(a){
	a = a - 360.0 * (Math.floor(a / 360.0));
	a = a < 0 ? a + 360.0 : a;
	return a;
}
function Aa(k){
	var a = -darccot(k+ dtan(Math.abs(Lat-d)))
	return (Ta(a))
	
}
// range reduce hours to 0..23
function fixhour(a){
	a = a - 24.0 * (Math.floor(a / 24.0));
	a = a < 0 ? a + 24.0 : a;
	return a;
}
function JD(day,month,year){
	if (month <= 2) 
	{
		year -= 1;
		month += 12;
	}
	var A = Math.floor(year/ 100);
	var B = 2- A+ Math.floor(A/ 4);

	var jd = Math.floor(365.25* (year+ 4716))+ Math.floor(30.6001* (month+ 1))+ day+ B- 1524.5;
	var jd = jd-Lng/ (15* 24)+0.75;
	return jd;
}
function PrayTime(jd){
	 D = jd - 2451545.0;
	g = fixangle(357.529 + 0.98560028* D);
	q = fixangle(280.459 + 0.98564736* D);
	L = fixangle(q + 1.915* dsin(g) + 0.020* dsin(2*g));

	R = 1.00014 - 0.01671* dcos(g) - 0.00014* dcos(2*g);
	e = 23.439 - 0.00000036* D;

	d = darcsin(dsin(e)* dsin(L));
	RA = darctan2(dcos(e)* dsin(L), dcos(L))/ 15;
	RA = fixhour(RA);
	EqT = q/15 - RA;

Dhuhr = 12  + TimeZone- Lng/15- EqT+0.5/60;
Fajr = Dhuhr - Ta(16)
Sunrise = Dhuhr - Ta(0.8333);
Asr = Dhuhr + Aa(1)
Sunset = Dhuhr + Ta(0.8333);
Maghrib = Dhuhr + Ta(4)
Isha = Dhuhr + Ta(15)
var TimeValues = new Array(
		Fajr,
		Sunrise,
		Dhuhr,
		Asr,
		Sunset,
		Maghrib,
		Isha
);
	var Time = new Array
	var Hours = new Array
	var Minutes = new Array
	var FormatedTime = new Array
	for (var i = 0; i<7;i++){
		Time[i] = fixhour(TimeValues[i]);
		Hours[i] = (Math.floor(Time[i]) <10) ? '0'+ Math.floor(Time[i]) : Math.floor(Time[i]);
		Minutes[i] = (Math.floor((Time[i]- Hours[i])* 60) <10) ? '0'+ Math.floor((Time[i]- Hours[i])* 60) : Math.floor((Time[i]- Hours[i])* 60);
		FormatedTime[i] =  (Hours[i]+":"+Minutes[i]);
	}
	return FormatedTime
}
function GetPrayTime(day,month,year,Lng1,Lat1,TimeZone1){
	Lng=Lng1
	Lat=Lat1
	TimeZone = TimeZone1
	JD = JD(day,month,year)
	PrayTime = PrayTime(JD)
	return PrayTime
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return null;
}
var TimeNames = new Array(
		'فجر',
		'طلوع آفتاب',
		'ظہر',
		'عصر',
		'غروب آفتاب',
		'مغرب',
		'عشاء'
);
function UppercaseTheFirstLetter(string,option){
var splitby,parts,i,uppercased;
if(option==0){splitby=" ";}
else if(option==1){splitby=".";}
else if(option==2){splitby="<BR>";}

string=string.replace(/^\s+/, '').replace(/\s+$/, '');
//we removed unnecessary spaces at the beginning and ending of string.
parts = string.split(splitby);

for(i=0;i<parts.length;i++){
          parts[i]=parts[i].replace(/^\s+/, '').replace(/\s+$/, '');
          if(parts[i].length>0){
          uppercased=parts[i].slice(0,1).toUpperCase()+parts[i].slice(1,parts[i].length);
                    if(i>0)output+=splitby+uppercased; else output=uppercased;
          }
}

return output;
}