﻿ function playSound() {
	                var OnOff = null;
//                   try
//                   {  
                    
		                document.getElementById("BGSOUND_ID").play();
		              
		                OnOff = document.getElementById("OnOff")
		                OnOff.innerHTML = "<a href=# class=Normaltext onclick=stopSound()>(OFF)</a>"
		                FirstTime = true;
//                   }
//                   catch(e)
//                   { 
//		                alert("Unable to play.")
//		                OnOff.innerHTML = null;
//                   }
                 }

                function stopSound() {
	                var OnOff = null;
//                    try
//                    {  
                    document.getElementById("BGSOUND_ID").stop();
                    OnOff = document.getElementById("OnOff")
                    OnOff.innerHTML =  "<a href=# class=Normaltext onclick=playSound()>(ON)</a>"
                    FirstTime = false;
//                   }
//                   catch(e)
//                   { 
//		                alert("Unable to stop.")
//		                OnOff.innerHTML = null;
//                   }
                }


                		 
                //*********************************** This Code is used to Show Clock on Header *********************************
                var timerID = null
                var timerRunning = false
                var prayerTimerId	= null


                function stopclock(){
                    if(timerRunning)
                    clearTimeout(timerID)
                    timerRunning = false
                }



                function startclock(){
                    stopclock()
                    showtime()    
                   showPrayersTime()
                }


                function londonCurrentTime()
                {
	                try	
	                {
		                var londonTime = MasterPages_MPBase.CurrentTime().value;		
		                return londonTime;
	                }
	                catch(e) {}	
                }


                function showtime(){    
                	
                    var now = new Date()
                    var hours = now.getHours()
                    var minutes = now.getMinutes()
                    var seconds = now.getSeconds()
                    var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
                    var timeValue1 = "" + ((hours < 10) ? "0" : "") + hours
                    timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
                    timeValue1 += ((minutes < 10) ? ":0" : ":") + minutes
                    timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
                    timeValue1 += ((seconds < 10) ? ":0" : ":") + seconds
                    timeValue  += (hours >= 12) ? " P.M." : " A.M."
                	
	                //writeInDIV(timeValue1,'divClock');
                	
                    timerID = setTimeout("showtime()",1000)
                    timerRunning = true
                }
                var FirstTime = false;
                function showPrayersTime()
                {
                    MasterPages_MPBase.LondonPrayerTime(22, timeOutPrayerTime);
                    prayerTimerId = setTimeout("showPrayersTime()",30000)
                }

                function timeOutPrayerTime(res)
                {
	                try
	                {
		                var londonPrayerTime = null;
		                var pTime = document.getElementById("PrayerTime");
		                var lTime = document.getElementById("londonTime");
		                var OnOff = document.getElementById("OnOff");
		                londonPrayerTime = res.value;
                		
		                var NamazName = londonPrayerTime.split("|")[0];
		                var AzanFile = londonPrayerTime.split("|")[1];
		                var NamazTime = londonPrayerTime.split("|")[2];
                		
                		
		                if (londonPrayerTime != "" && londonPrayerTime != null)
		                {
			                var icpt = getCookie("ICPT")			
			                //alert(icpt + "\n" + NamazName)
			                lTime.innerHTML = "&nbsp;&nbsp;London Time " + londonCurrentTime();
			                if (icpt == null || icpt!= NamazName)	//if opening for the first Time OR namaz time has changed
			                {
				                setCookie("ICPT",NamazName,null,"/");
				                pTime.innerHTML  =  "<embed src=" + AzanFile + " id=BGSOUND_ID  autostart=true loop=false width=2 height=0></embed><noembed><bgsound src=" + AzanFile + "></noembed>" + "&nbsp;&nbsp;|  " + NamazName + " Prayer Time in London " + NamazTime + "&nbsp;&nbsp;";
				                OnOff.innerHTML =  "<a href=# class=Normaltext onclick=stopSound()>(OFF)</a>"
				                FirstTime = true;
			                }
			                else if(!FirstTime)
			                {				
				                pTime.innerHTML  =  "<embed src=" + AzanFile + " id=BGSOUND_ID  autostart=false loop=false width=2 height=0></embed><noembed><bgsound src=" + AzanFile + "></noembed>" + "&nbsp;&nbsp;|  " + NamazName + " Prayer Time in London " + NamazTime + "&nbsp;&nbsp;";
				                OnOff.innerHTML =  "<a href=# class=Normaltext onclick=playSound()>(ON)</a>"							
			                }
		                }
		                else
		                {		
			                pTime.innerHTML  = "";
			                lTime.innerHTML = "";
			                OnOff.innerHTML = "";
			                deleteCookie("ICPT")
                			
		                }
	                }
	                catch(e) {}	
                	
                }

                //prayers();


                function writeInDIV(text,id)
                {
		                x = document.getElementById(id);
		                x.innerHTML = '';
		                x.innerHTML	= text;
                }