var curdate = new Date();
var state = '';
var offset = (curdate.getTimezoneOffset()/ 60)*-1;
var pray;
var azans=new Array(4);
var methods = new Array(
'Leva Research Institute',
'جامعة العلوم الإسلامية بكراتشى',
'الاتحاد الإسلامي بأمريكا الشمالية',
'رابطة العالم الإسلامي',
'جامعة أم القرى',
'الهيئة العامة المصرية للمساحة',
'Custom Setting'
);


var Adhans = new Array(
'Aghaei',
'Ghelvash',
'Kazem-Zadeh',
'Moazzen-Zadeh Ardabili',
'Mohammad-Zadeh',
'Rezaeian',
'Rowhani-Nejad',
'Salimi',
'Sharif',
'Sobhdel',
'Tasvieh-Chi',
'Tookhi',
'Abdul-Basit',
'Abdul-Ghaffar',
'Abdul-Hakam',
'Adhan Alaqsa',
'Adhan Egypt',
'Adhan Halab',
'Adhan Madina',
'Adhan Makkah',
'Al-Hossaini',
'Bakir Bash',
'Hafez',
'Hafiz Murad',
'Menshavi',
'Naghshbandi',
'Saber',
'Sharif Doman',
'Yusuf Islam'
);


if (!getCookie('offset'))
setCookie('offset', (curdate.getTimezoneOffset()/ 60)*-1);

if (!getCookie('latit'))
setCookie('latit', geoip_latitude());

if(!getCookie('longit'))
setCookie('longit', geoip_longitude());

if(!getCookie('gaddress'))
setCookie('gaddress', geoip_city()+', '+geoip_country_code());

if(!getCookie('option2'))
{
	setCookie('option2', 19);
}


if(!getCookie('asr_method'))
{
	setCookie('asr_method', 0);
}


if(!getCookie('calcm'))
{
	setCookie('calcm', 4);
}



function Pop_Up(target_file,PageName)
{
window.open(target_file, PageName, 'width=600,height=700,resizable=yes');
}

function showhide(layer_ref) {

if (state == '') {
state = 'none';
}
else {
state = '';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.display = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].display = state;
}
if (document.getElementById &&!document.all) {
var hza = document.getElementById(layer_ref);
hza.style.display = state;
}
} 


function RunAdan()
{
	if( !document.getElementById('autoplay').checked )
	{
		return;
	}

	wimpy_play();
}


function EditLocation()
{


	if ( document.getElementById('latit').value == "" )
	{
		var latit = getCookie('latit');
	} else {
		var latit = document.getElementById('latit').value;
	}
	
	if ( document.getElementById('longit').value == "" )
	{
		var longit = getCookie('longit');
	} else {
		var longit = document.getElementById('longit').value;
	}
	
	if ( document.getElementById('timezone').value == "" )
	{
		var offset = getCookie('offset');
	} else {
		var offset = document.getElementById('timezone').value;
	}
	

	
	setCookie('offset', offset);
	setCookie('latit', latit);
	setCookie('longit', longit);
	
	  
	  		if (opener != null) {
			opener.document.location="../aw9atu-assalaat.html";
			window.close();
		}
}
	 
	
function GetPrayerTime()
{

// Pray time
prayTime.setTimeFormat(prayTime.Time12);
prayTime.setCalcMethod(getCookie('calcm')); 

if (getCookie('asr_method') == 1)
prayTime.setAsrMethod(prayTime.Hanafi);

	pray = prayTime.getPrayerTimes(curdate, getCookie('latit'), getCookie('longit'), getCookie('offset'));


	document.getElementById('prn1').innerHTML = prayTime.timeNames[0];
	document.getElementById('prn2').innerHTML = prayTime.timeNames[2];
	document.getElementById('prn3').innerHTML = prayTime.timeNames[3];
	document.getElementById('prn4').innerHTML = prayTime.timeNames[5];
	document.getElementById('prn5').innerHTML = prayTime.timeNames[6];
	document.getElementById('pr1').innerHTML = pray[0];
	document.getElementById('pr2').innerHTML = pray[2];
	document.getElementById('pr3').innerHTML = pray[3];
	document.getElementById('pr4').innerHTML = pray[5];
	document.getElementById('pr5').innerHTML = pray[6];
	

pray = "";
prayTime.setTimeFormat(prayTime.Time24);
prayTime.setCalcMethod(getCookie('calcm')); 

if (getCookie('asr_method') == 1)
prayTime.setAsrMethod(prayTime.Hanafi);

pray = prayTime.getPrayerTimes(curdate, getCookie('latit'), getCookie('longit'), getCookie('offset'));

var tmp1=pray[0].split(":");
var tmp2=pray[2].split(":");
var tmp3=pray[3].split(":");
var tmp4=pray[5].split(":");
var tmp5=pray[6].split(":");

azans[0]=parseFloat(tmp1[0])*60+parseFloat(tmp1[1]);
azans[1]=parseFloat(tmp2[0])*60+parseFloat(tmp2[1]);
azans[2]=parseFloat(tmp3[0])*60+parseFloat(tmp3[1]);
azans[3]=parseFloat(tmp4[0])*60+parseFloat(tmp4[1]);
azans[4]=parseFloat(tmp5[0])*60+parseFloat(tmp5[1]);
azans[5]=parseFloat(tmp1[0])*60+parseFloat(tmp1[1])+(24*60);
CountToNext();
}


      

function CountToNext()
{


var now = new Date();
var myday=now.getDate();
var hours=now.getHours()
var minutes=now.getMinutes()
var seconds=now.getSeconds()

var now_hm=hours*60+minutes;

var aznames = new Array(
'الفجر',
'الظهر',
'العصر',
'المغرب',
'العشاء',
'الفجر'
);


for (var i=0; i<6;i++)
{
	//
     if(now_hm<azans[i]+1)
     {
 hours=Math.floor((azans[i]-now_hm)/60);
 minutes=(azans[i]-now_hm)-hours*60;
 seconds=59-seconds;
 if (hours <10) {hours="0"+hours}
 if (minutes < 10) {minutes="0"+minutes}
 if (seconds < 10) {seconds="0"+seconds}
 thistime = hours+":"+minutes+":"+seconds;
 if( thistime == '00:00:00' )
 {
	 RunAdan(true);
 }
 
document.title = thistime+' Prayer Times'; 
document.getElementById('CountDown').innerHTML = "<h5> "+thistime+"  حتى "+aznames[i]+"</h5>";

      break;
     }

}

setTimeout("CountToNext()", 1000);

		
}


	// set cookie
	function setCookie( name, value) {
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime( today.getTime() );
		var expires = 2;
		var path = '/';
		var domain = '';
		var secure = '';
		/*
		if the expires variable is set, make the correct 
		expires time, the current script below will set 
		it for x number of days, to make it for hours, 
		delete * 24, for minutes, delete * 60 * 24
		*/
		if (expires)
			expires = expires * 1000 * 60 * 60 * 24;
		var expires_date = new Date( today.getTime() + (expires) );

		document.cookie = name + "=" +escape( value ) +
		( (expires) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( (path) ? ";path=" + path : "" ) + 
		( (domain) ? ";domain=" + domain : "" ) +
		( (secure) ? ";secure" : "" );
	}


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 "";
}




function EditCalcMeth()
{

   if (document.getElementById('asr_method2').checked)
      {
      	  setCookie('asr_method', document.getElementById('asr_method2').value);
      }
	  else
	  {
		  setCookie('asr_method', document.getElementById('asr_method').value);
	  }
	  
	  setCookie('calcm', document.getElementById('method').selectedIndex);
	  
	  		if (opener != null) {
			opener.document.location="../aw9atu-assalaat.html";
			window.close();
		}

	  return;

}

function SetOption2(adhs)
{	  
	  setCookie('option2', adhs);
	  window.location = '../aw9atu-assalaat.html';
}

function GetAdanSound()
{
	  return "http://www.mgharba.com/mp3s/"+Adhans[getCookie('option2')]+".mp3";
}

