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',
'University of Islamic Sciences, Karachi',
'Islamic Society of North America (ISNA)',
'Muslim World League (MWL)',
'Umm al-Qura',
'Egyptian General Authority of Survey',
'Custom Setting'
);


var Adhans = new Array(
'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'
);

var DoasOptions = new Array(
'doa1',
'doa2',
'doa3',
'doa4'
);
 

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('setazanmp3'))
{
	setCookie('setazanmp3', 19);
}


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


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



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="../gebedstijden.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(
'Fajr',
'Dhuhr',
'Asr',
'Maghrib',
'Isha',
'Fajr'
);


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+" to "+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="../gebedstijden.html";
			window.close();
		}

	  return;

}
      var azant5=readCookie('ptazantimes');
      if((azant5==null)||(azant5=="1")||(azant5=="0"))
        azant5="ccccc";
      var doat3=readCookie('ptdoatimes');
      if(doat3==null)
        doat3="cccu";
      else
        {
        if(doat3.length<4)
          doat3=doat3+"u";
        }
var AdhansOptions = new Array(
'Adhan1',
'Adhan2',
'Adhan3',
'Adhan4',
'Adhan5'
);

function setAzanTimes()
{
azant5="";
for (var i=0; i<5;i++)
   {
    if(document.getElementById(AdhansOptions[i]).checked)
      azant5=azant5+"c";
    else
      azant5=azant5+"u";
   }
setCookie('ptazantimes', azant5, 356, '/', '', '');
}
 
function setAlarmTime()
{
setCookie('ptalarmtime', document.getElementById('txtalarm').selectedIndex, 356, '/', '', '');
}

function setAzanMp3()
{
azanmp3=adhanForm.option2.selectedIndex;
setCookie('setazanmp3', azanmp3, 356, '/', '', '');
window.location = 'index.php';
}


function OptionStatus()
{
if(optionst==1)
{
return "Hide Options";
}
else
{
return "Options...";
}
}
 setAzan(times[0],times[2],times[3],times[5],times[6]);
for (var i=0; i<5;i++)
{
 if(azant5.substring(i,i+1)=="u")
 {
 document.getElementById(AdhansOptions[i]).checked=false;
 }
}
for (var i=0; i<4;i++)
{
 if(doat3.substring(i,i+1)=="u")
 document.getElementById(DoasOptions[i]).checked=false;
 else
 document.getElementById(DoasOptions[i]).checked=true;
}
setdoaAlarm();
document.getElementById('txtalarm').selectedIndex=readCookie('ptalarmtime')%100;

function GetAdanSound()
{
	  return "http://prayertimes.info/mp3s/"+Adhans[getCookie('setazanmp3')]+".mp3";
}

