function oghatsharee_main()
{
	var month_value=document.getElementById("month").selectedIndex+1;
	var day_value=eval(document.getElementById("day").value);
	var lg=eval(document.getElementById("longitude").value);
	var lat=eval(document.getElementById("latitude").value);
//	var lg=52.5125;
//	var lat=29.635;
	var ep=sun(month_value,day_value,4,lg)
	var zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(108.0,delta_angle,lat)
	var t1=Round(zr-ha,24)
	ep=sun(month_value,day_value,t1,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(108.0,delta_angle,lat)
	var t1=Round(zr-ha,24)
	//	<behravesh>
	if(month_value <= 6 && !(month_value == 1 && day_value == 1)) {
		t1 += 1.0;
	}
	//	</behravesh>
	document.getElementById("t1").innerHTML= hms(t1);	
//
//   t2= Sun rise
//
	ep=sun(month_value,day_value,6,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(90.833,delta_angle,lat)
	var t2=Round(zr-ha,24)
	ep=sun(month_value,day_value,t2,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(90.833,delta_angle,lat)
	t2=Round(zr-ha,24)
	//	<behravesh>
	if(month_value <= 6 && !(month_value == 1 && day_value == 1)) {
		t2 += 1.0;
	}
	//	</behravesh>	
	document.getElementById("t2").innerHTML=hms(t2);
//
//	zr=Zohr
//
	ep=sun(month_value,day_value,12,lg)
	ep=sun(month_value,day_value,ep[0],lg)
	zr=ep[0];
	//	<behravesh>
	if(month_value <= 6 && !(month_value == 1 && day_value == 1)) {
		zr += 1.0;
	}
	//	</behravesh>	
	document.getElementById("zr").innerHTML=hms(zr);
//
//   t2= Sun set
//
	ep=sun(month_value,day_value,18,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(90.833,delta_angle,lat)
	var t3=Round(zr+ha,24)
	ep=sun(month_value,day_value,t3,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(90.833,delta_angle,lat)
	t3=Round(zr+ha,24)
	//	<behravesh>
	if(month_value <= 6 && !(month_value == 1 && day_value == 1)) {
		t3 += 1.0;
	}
	//	</behravesh>	
	document.getElementById("t3").innerHTML=hms(t3);
//
//   t2= Maghreb
//
	ep=sun(month_value,day_value,18.5,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(94.3,delta_angle,lat)
	var t4=Round(zr+ha,24)
	ep=sun(month_value,day_value,t4,lg)
	zr=ep[0];
	delta_angle=ep[1];
	ha=loc2hor(94.3,delta_angle,lat)
	t4=Round(zr+ha,24)
	//	<behravesh>
	if(month_value <= 6 && !(month_value == 1 && day_value == 1)) {
		t4 += 1.0;
	}
	//	</behravesh>	
	document.getElementById("t4").innerHTML=hms(t4);
	 cities_by_id=document.getElementById("cities");

	document.getElementById("city_name").innerHTML=cities_by_id.value;
}
function sun(month_value,day_value,h_3600,lg)
{
	if(month_value<7)
		day_value= 31*(month_value-1)+day_value+h_3600/24;
	else
		day_value=6+30*(month_value-1)+day_value+h_3600/24;
	var Mmonth_value=74.2023+0.98560026*day_value;
	var Lday_value=-2.75043+0.98564735*day_value;
	var lst=8.3162159+0.065709824*Math.floor(day_value)+1.00273791*24*(day_value%1)+lg/15;
	var e_num=0.0167065;
	var omega_angle=4.85131-0.052954*day_value;
	var ep=23.4384717+0.00256*cosd(omega_angle);
	var ed=180.0/Math.PI*e_num;
	var u=Mmonth_value;
	for(var i=1;i<5;i++)
		u=u-(u-ed*sind(u)-Mmonth_value)/(1-e_num*cosd(u));
	var v=2*atand(tand(u/2)*Math.sqrt((1+e_num)/(1-e_num)));
	var theta_angle=Lday_value+v-Mmonth_value-0.00569-0.00479*sind(omega_angle);
	var delta_angle=asind(sind(ep)*sind(theta_angle));
	var alpha_angle=180.0/Math.PI*Math.atan2(cosd(ep)*sind(theta_angle),cosd(theta_angle));
	if(alpha_angle>=360)
		alpha_angle-=360;
	var ha=lst-alpha_angle/15;
	var zr=Round(h_3600-ha,24);
	return ([zr,delta_angle])
}
function oghatsharee_init()
{
	lgs = lgs.slice(1,lgs.length);
	lats = lats.slice(1,lats.length);
	
	oghatsharee_coord();
}
function oghatsharee_coord()
{
	var cities_by_id=document.getElementById("cities");
	var i = cities_by_id.selectedIndex;
	document.getElementById("longitude").value=lgs[i].toString()
	document.getElementById("latitude").value=lats[i].toString()

	oghatsharee_main();
}
function sind(x){return(Math.sin(Math.PI/180.0*x));}
function cosd(x){return(Math.cos(Math.PI/180.0*x));}
function tand(x){return(Math.tan(Math.PI/180.0*x));}
function atand(x){return(Math.atan(x)*180.0/Math.PI);}
function asind(x){return(Math.asin(x)*180.0/Math.PI);}
function acosd(x){return(Math.acos(x)*180.0/Math.PI);}
function sqrt(x){return(Math.sqrt(x));}
function frac(x){return(x%1);}
function floor(x){return(Math.floor(x));}
function ceil(x){return(Math.ceil(x));}
function loc2hor(z,day_value,p_){
	return(acosd((cosd(z)-sind(day_value)*sind(p_))/cosd(day_value)/cosd(p_))/15);
}
function Round(x,a){
	var tmp=x%a;
	if(tmp<0)
		tmp+=a;
	return(tmp)
}
function hms(x)
{
	x=Math.floor(3600*x);
	h_3600=Math.floor(x/3600);
	m_p=x-3600*h_3600;
	moment_value=Math.floor(m_p/60);
	secound_value=Math.floor(m_p-60*moment_value);
	return(((h_3600<10)? "0" : "")+h_3600.toString()+":"+((moment_value<10)? "0" : "")+moment_value.toString()+":"+((secound_value<10)? "0" : "")+secound_value.toString())
}
oghatsharee_init();

