﻿function GetCurrentTime()
	{
		var localTime= new Date( ) ;
		var year=localTime.getYear();
		result =  GetArabicDay( localTime.getDay( ) )+ " " + localTime.getDate() + " " + GetArabicMonth( localTime.getMonth( ) ) + " " + year+" م" ;
		
		document.write( result );
	}

function GetLocalTime( year , month , day , time ) 
	{ 
		


		var result ;
		var localTime= new Date( ) ;
		var gmtTime= new Date( year , month , day ) ;
		
		//var localmachinetime=new Date();
		//alert(localmachinetime.getTime());
		//alert(localmachinetime.getTimezoneOffset( ))
		
		//var offss=localmachinetime.getTime()-localTime.getTimezoneOffset( );
		//alert(offss);		
		var offset = localTime.getTimezoneOffset( ) ;
		//offset = offset * 60 * 1000 ;
		var varTimeParts = time.split(":");//varTimeParts[0]hours,varTimeParts[1]minutes,varTimeParts[2]seconds,
		//setting the new date object(local time)time
		gmtTime.setHours( varTimeParts[0] ) ;
		gmtTime.setMinutes( varTimeParts[1] ) ;
		gmtTime.setSeconds( varTimeParts[2] ) ;
		if( offset > 0 )
		{
			var noOfAddedHours = offset  / 60 ;
			var noOfAddedMinutes = offset % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) - noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) - noOfAddedMinutes ) ;
		}
		else
		{
			var noOfAddedHours = Math.abs( offset ) / 60 ;
			var noOfAddedMinutes = Math.abs( offset ) % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) + noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) + noOfAddedMinutes ) ;
		}	
		var hoursPart;
		var minutesPart;
		var timePart;
		if(  gmtTime.getHours( ) >= 12  )
		{
			hoursPart = gmtTime.getHours( ) - 12 ;
			timePart = "م";
		}
		else
		{
			hoursPart = gmtTime.getHours( );
			timePart = "ص";
		}
		if( hoursPart < 1 )
			hoursPart = 12;
		minutesPart = gmtTime.getMinutes( );
		if( minutesPart == "0" )
			minutesPart = "00";
		if( minutesPart < 10 && minutesPart != "00" )
			minutesPart="0"+minutesPart;
		if( day != localTime.getDate( ))
		{
		    
			result =   /*GetArabicDay( gmtTime.getDay( ) )+ " " + */gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) );// + " " + year + " " + hoursPart + ":" + minutesPart + " " + timePart ;
			if(year!=localTime.getFullYear())
				result=result+" " + year
				
		}
		else
		{
 			if( month == localTime.getMonth( ) && year== localTime.getFullYear())
				result =  hoursPart + ":" + minutesPart + " " + timePart +" ";
			else
			{
				result =   /*GetArabicDay( gmtTime.getDay( ) )+ " " + */gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) );// + " " + year + " " + hoursPart + ":" + minutesPart + " " + timePart ;
				if(year!=localTime.getFullYear())
					result=result+" " + year	
			}
			
			
		}
			//result =   GetArabicDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) ) + " " + year + " "  + hoursPart + ":" + gmtTime.getMinutes( ) + " " + timePart ;

		document.write( result );
		//return result;
	}
	function GetAllLocalTime( year , month , day , time ) 
	{ 
		var result ;
		var localTime= new Date( ) ;
		var gmtTime= new Date( year , month , day ) ;
		//var localmachinetime=new Date();
		//alert(localmachinetime.getTime());
		//alert(localmachinetime.getTimezoneOffset( ))
		
		//var offss=localmachinetime.getTime()-localTime.getTimezoneOffset( );
		//alert(offss);		
		var offset = localTime.getTimezoneOffset( ) ;
		//offset = offset * 60 * 1000 ;
		var varTimeParts = time.split(":");//varTimeParts[0]hours,varTimeParts[1]minutes,varTimeParts[2]seconds,
		//setting the new date object(local time)time
		gmtTime.setHours( varTimeParts[0] ) ;
		gmtTime.setMinutes( varTimeParts[1] ) ;
		gmtTime.setSeconds( varTimeParts[2] ) ;
		if( offset > 0 )
		{
			var noOfAddedHours = offset  / 60 ;
			var noOfAddedMinutes = offset % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) - noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) - noOfAddedMinutes ) ;
		}
		else
		{
			var noOfAddedHours = Math.abs( offset ) / 60 ;
			var noOfAddedMinutes = Math.abs( offset ) % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) + noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) + noOfAddedMinutes ) ;
		}	
		var hoursPart;
		var minutesPart;
		var timePart;
		if(  gmtTime.getHours( ) >= 12  )
		{
			hoursPart = gmtTime.getHours( ) - 12 ;
			timePart = "م";
		}
		else
		{
			hoursPart = gmtTime.getHours( );
			timePart = "ص";
		}
		if( hoursPart < 1 )
			hoursPart = 12;
		minutesPart = gmtTime.getMinutes( );
		
		if( minutesPart == "0" )
			minutesPart = "00";
		
		if( minutesPart < 10 && minutesPart != "00" )
			minutesPart="0"+minutesPart;
	
		//if( day != localTime.getDate( ) )
		//{
			result =  GetArabicDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) );// + " " + year + " " + hoursPart + ":" + minutesPart + " " + timePart ;
			//if(year!=localTime.getYear())
				result=result+" " + year
		//}
		//else
		//{
			result +="  "+ hoursPart + ":" + minutesPart + " " + timePart +" ";
			
		//}
		//if( day != localTime.getDate( ) )
		//////	result =   GetArabicDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) ) + " " + year + " "  + hoursPart + ":" + minutesPart + " " + timePart ;
		//else
		//	result =  hoursPart + ":" + minutesPart + " " + timePart +" ";
			//result =   GetArabicDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) ) + " " + year + " "  + hoursPart + ":" + gmtTime.getMinutes( ) + " " + timePart ;

		document.write( result );
	}
	//////////// English Functions/////////////////
	function GetCurrentTimeEnglish()
	{
		var localTime= new Date( ) ;
		var year=localTime.getYear();
		result =  GeEnglishDay( localTime.getDay( ) )+ " " + localTime.getDate() + " " + GetEnglishMonth( localTime.getMonth( ) ) + " " + year+" PM" ;
		
		document.write( result );
	}
	
	function GetLocalTimeEnglish( year , month , day , time ) 
	{ 
		var result ;
		var localTime= new Date( ) ;
		var gmtTime= new Date( year , month , day ) ;
		
		//var localmachinetime=new Date();
		//alert(localmachinetime.getTime());
		//alert(localmachinetime.getTimezoneOffset( ))
		
		//var offss=localmachinetime.getTime()-localTime.getTimezoneOffset( );
		//alert(offss);		
		var offset = localTime.getTimezoneOffset( ) ;
		//offset = offset * 60 * 1000 ;
		var varTimeParts = time.split(":");//varTimeParts[0]hours,varTimeParts[1]minutes,varTimeParts[2]seconds,
		//setting the new date object(local time)time
		gmtTime.setHours( varTimeParts[0] ) ;
		gmtTime.setMinutes( varTimeParts[1] ) ;
		gmtTime.setSeconds( varTimeParts[2] ) ;
		if( offset > 0 )
		{
			var noOfAddedHours = offset  / 60 ;
			var noOfAddedMinutes = offset % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) - noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) - noOfAddedMinutes ) ;
		}
		else
		{
			var noOfAddedHours = Math.abs( offset ) / 60 ;
			var noOfAddedMinutes = Math.abs( offset ) % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) + noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) + noOfAddedMinutes ) ;
		}	
		var hoursPart;
		var minutesPart;
		var timePart;
		if(  gmtTime.getHours( ) >= 12  )
		{
			hoursPart = gmtTime.getHours( ) - 12 ;
			timePart = "PM";
		}
		else
		{
			hoursPart = gmtTime.getHours( );
			timePart = "AM";
		}
		if( hoursPart < 1 )
			hoursPart = 12;
		minutesPart = gmtTime.getMinutes( );
		if( minutesPart == "0" )
			minutesPart = "00";
		if( minutesPart < 10 && minutesPart != "00" )
			minutesPart="0"+minutesPart;
		if( day != localTime.getDate( ) )
		{
			result =   /*GetArabicDay( gmtTime.getDay( ) )+ " " + */gmtTime.getDate() + " " + GetEnglishMonth( gmtTime.getMonth( ) );// + " " + year + " " + hoursPart + ":" + minutesPart + " " + timePart ;
			if(year!=localTime.getFullYear())
				result=result+" " + year
		}
		else
		{
 			if( month == localTime.getMonth( ) && year== localTime.getFullYear() )
				result =  hoursPart + ":" + minutesPart + " " + timePart +" ";
			else
			{
				result =   /*GetArabicDay( gmtTime.getDay( ) )+ " " + */gmtTime.getDate() + " " + GetEnglishMonth( gmtTime.getMonth( ) );// + " " + year + " " + hoursPart + ":" + minutesPart + " " + timePart ;
				if(year!=localTime.getFullYear())
					result=result+" " + year	
			}
			
			
		}
			//result =   GetEnglishDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) ) + " " + year + " "  + hoursPart + ":" + gmtTime.getMinutes( ) + " " + timePart ;

		document.write( result );
	}
	function GetAllLocalTimeEnglish( year , month , day , time ) 
	{ 
		var result ;
		var localTime= new Date( ) ;
		var gmtTime= new Date( year , month , day ) ;
		//var localmachinetime=new Date();
		//alert(localmachinetime.getTime());
		//alert(localmachinetime.getTimezoneOffset( ))
		
		//var offss=localmachinetime.getTime()-localTime.getTimezoneOffset( );
		//alert(offss);		
		var offset = localTime.getTimezoneOffset( ) ;
		//offset = offset * 60 * 1000 ;
		var varTimeParts = time.split(":");//varTimeParts[0]hours,varTimeParts[1]minutes,varTimeParts[2]seconds,
		//setting the new date object(local time)time
		gmtTime.setHours( varTimeParts[0] ) ;
		gmtTime.setMinutes( varTimeParts[1] ) ;
		gmtTime.setSeconds( varTimeParts[2] ) ;
		if( offset > 0 )
		{
			var noOfAddedHours = offset  / 60 ;
			var noOfAddedMinutes = offset % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) - noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) - noOfAddedMinutes ) ;
		}
		else
		{
			var noOfAddedHours = Math.abs( offset ) / 60 ;
			var noOfAddedMinutes = Math.abs( offset ) % 60 ;
			gmtTime.setHours( gmtTime.getHours(  ) + noOfAddedHours ) ;
			gmtTime.setMinutes( gmtTime.getMinutes(  ) + noOfAddedMinutes ) ;
		}	
		var hoursPart;
		var minutesPart;
		var timePart;
		if(  gmtTime.getHours( ) >= 12  )
		{
			hoursPart = gmtTime.getHours( ) - 12 ;
			timePart = "PM";
		}
		else
		{
			hoursPart = gmtTime.getHours( );
			timePart = "AM";
		}
		if( hoursPart < 1 )
			hoursPart = 12;
		minutesPart = gmtTime.getMinutes( );
		
		if( minutesPart == "0" )
			minutesPart = "00";
		
		if( minutesPart < 10 && minutesPart != "00" )
			minutesPart="0"+minutesPart;
	
		//if( day != localTime.getDate( ) )
		//{
			result =  GetEnglishDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetEnglishMonth( gmtTime.getMonth( ) );// + " " + year + " " + hoursPart + ":" + minutesPart + " " + timePart ;
			//if(year!=localTime.getYear())
				result=result+" " + year
		//}
		//else
		//{
			result +="  "+ hoursPart + ":" + minutesPart + " " + timePart +" ";
			
		//}
		//if( day != localTime.getDate( ) )
		//////	result =   GetArabicDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) ) + " " + year + " "  + hoursPart + ":" + minutesPart + " " + timePart ;
		//else
		//	result =  hoursPart + ":" + minutesPart + " " + timePart +" ";
			//result =   GetArabicDay( gmtTime.getDay( ) )+ " " + gmtTime.getDate() + " " + GetArabicMonth( gmtTime.getMonth( ) ) + " " + year + " "  + hoursPart + ":" + gmtTime.getMinutes( ) + " " + timePart ;

		document.write( result );
	}
	//
	function GetArabicDay( dayOfWeek )
	{
		
		if( dayOfWeek == 0 )
			return "الاحد";
		else if( dayOfWeek == 1 )
			return "الاثنين";
		else if( dayOfWeek == 2 )
			return "الثلاثاء";
		else if( dayOfWeek == 3 )
			return "الاربعاء";
		else if( dayOfWeek == 4 )
			return "الخميس";
		else if( dayOfWeek == 5 )
			return "الجمعة";
		else if( dayOfWeek == 6 )
			return "السبت";
		return "";
	}
	function GetArabicMonth( Month )
	{
		if( Month == "0" )
		return "يناير";
		else if( Month == "1" )
			return "فبراير";
		else if( Month == "2" )				
			return "مارس";
		else if( Month == "3" )
			return "أبريل";
		else if( Month == "4" )
			return "مايو";
		else if( Month == "5" )
			return "يونيو";	
		else if( Month == "6" )
			return "يوليو";			
		else if( Month == "7" )
			return "أغسطس";			
		else if( Month == "8" )
			return "سبتمبر";	
		else if( Month == "9" )
			return "أكتوبر";			
		else if( Month == "10" )
			return "نوفمبر";			
		else if( Month == "11" )
			return "ديسمبر";			
		return "";
	}
	
function convertGtoHDate( ) 
{
	var localTime= new Date( ) ;
	
	var D=localTime.getDate()
	var M=localTime.getMonth()+1;
	var Y=localTime.getYear();

	
	var d=parseInt(D);
	var m=parseInt(M);
	var y=parseInt(Y);	
	
	var jd,l,n,j;
	
	if((y>1582)||((y==1582)&&(m>10))||((y==1582)&&(m==10)&&(d>14))) 
	{
		 jd=GetIntPart((1461*(y+4800+GetIntPart((m-14)/12)))/4)+
			 GetIntPart((367*(m-2-12*(GetIntPart((m-14)/12))))/12)-
			 GetIntPart((3*(GetIntPart((y+4900+GetIntPart((m-14)/12))/100)))/4)+d-32075;
	}
	else
	{
		 jd =367*y-GetIntPart((7*(y+5001+GetIntPart((m-9)/7)))/4)+GetIntPart((275*m)/9)+d+1729777;
	}
	
	l=jd-1948440+10632;
	n=GetIntPart((l-1)/10631);
	l=l-10631*n+354;
	
	j=(GetIntPart((10985-l)/5316))*(GetIntPart((50*l)/17719))+(GetIntPart(l/5670))*(GetIntPart((43*l)/15238));
	l=l-(GetIntPart((30-j)/15))*(GetIntPart((17719*j)/50))-(GetIntPart(j/16))*(GetIntPart((15238*j)/43))+29;

	m=GetIntPart((24*l)/709);
	d=l-GetIntPart((709*m)/24);
	y=30*n+j-30;
	
	m=m-1;
	d=d+1;
	if (d==31) {d=1; m=m+1;}
		result = ", "+ d + " من " + GetHijriMonth(m) + " " + y +" هـ";
		
	document.write( result );	
	
}
// to get the Int Part of any Number
function GetIntPart(Fnum)
{
	if (Fnum< -0.0000001)
		{
		 return Math.ceil(Fnum-0.0000001)
		}
		
return Math.floor(Fnum+0.0000001)	
}

function GetHijriMonth( Month )
{
		if( Month == "0" )
		return "المحرم";
		else if( Month == "1" )
			return "صفر";
		else if( Month == "2" )				
			return "ربيع الأول";
		else if( Month == "3" )
			return "ربيع الآخر";
		else if( Month == "4" )
			return "جمادى الأولى";
		else if( Month == "5" )
			return "جمادى الآخرة";	
		else if( Month == "6" )
			return "رجب";			
		else if( Month == "7" )
			return "شعبان";			
		else if( Month == "8" )
			return "رمضان";	
		else if( Month == "9" )
			return "شوال";			
		else if( Month == "10" )
			return "ذو القعدة";			
		else if( Month == "11" )
			return "ذو الحجة";

}
function GetEnglishDay( dayOfWeek )
	{
		
		if( dayOfWeek == 0 )
			return "Sun";
		else if( dayOfWeek == 1 )
			return "Mon";
		else if( dayOfWeek == 2 )
			return "Tus";
		else if( dayOfWeek == 3 )
			return "Wed";
		else if( dayOfWeek == 4 )
			return "Thu";
		else if( dayOfWeek == 5 )
			return "Fri";
		else if( dayOfWeek == 6 )
			return "Sat";
		return "";
	}
	function GetEnglishMonth( Month )
	{
		if( Month == "0" )
		return "Jan";
		else if( Month == "1" )
			return "Feb";
		else if( Month == "2" )				
			return "Mar";
		else if( Month == "3" )
			return "Apr";
		else if( Month == "4" )
			return "May";
		else if( Month == "5" )
			return "Jun";	
		else if( Month == "6" )
			return "Jul";			
		else if( Month == "7" )
			return "Aug";			
		else if( Month == "8" )
			return "Sep";	
		else if( Month == "9" )
			return "Oct";			
		else if( Month == "10" )
			return "Nov";			
		else if( Month == "11" )
			return "Dec";			
		return "";
	}
	function GetFullEnglishMonth( Month )
	{
		if(Month=="1" )
			return "January";
		else if(Month=="2" )
			return "February";
		else if(Month=="3" )				
			return "March";
		else if(Month=="4" )
			return "April";
		else if(Month=="5" )
			return "May";
		else if(Month=="6" )
			return "June";	
		else if(Month=="7" )
			return "July";			
		else if(Month=="8" )
			return "August";			
		else if(Month=="9" )
			return "September";	
		else if(Month=="10" )
			return "October";			
		else if(Month=="11" )
			return "November";			
		else if(Month=="12" )
			return "December";			
		return "";
	}
	
	