var expdate = new Date();
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 31 * 12)); 
	
// AUDIO PLAYER

	var ap_instances = new Array();
	
	function ap_stopAll(playerID) {
		for(var i = 0;i<ap_instances.length;i++) {
			try {
				if(ap_instances[i] != playerID) document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
				else document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
			} catch( errorObject ) {
				// stop any errors
			}
		}
	}
	
	function ap_registerPlayers() {
		var objectID;
		var objectTags = document.getElementsByTagName("object");
		for(var i=0;i<objectTags.length;i++) {
			objectID = objectTags[i].id;
			if(objectID.indexOf("audioplayer") == 0) {
				ap_instances[i] = objectID.substring(11, objectID.length);
			}
		}
	}
	
	var ap_clearID = setInterval( ap_registerPlayers, 100 );


//TOOGLE BOX VIEWS

	function toggle(element, cookieVal, defStatus)
	{	
	    var status = getCookie('langBox_'+cookieVal);
	    if(status==1 || (status == null && defStatus == 0))
		{
			document.getElementById(element).style.overflow='visible';
			document.getElementById(element).style.height='';
			document.getElementById(element+"Arrow").innerHTML = '<img src="/images/blueboxArrowOpen.jpg" border="0" />';
			setCookie('langBox_'+cookieVal,0, expdate, '/');
		}
		else
		{
		    document.getElementById(element).style.overflow='hidden';
		    document.getElementById(element).style.height='0px';
			document.getElementById(element+"Arrow").innerHTML ='<img src="/images/blueboxArrowClosed.jpg" border="0" />';	
			//delCookie('langBox_'+cookieVal);
			setCookie('langBox_'+cookieVal,1, expdate, '/');			
		}
	}

//COOKIE FUNCTIONS

	function setCookie(name, value, expires, path, domain, secure) {
	  document.cookie = name + "=" + escape(value) +
	  ((expires == null) ? "" : "; expires=" + expires) +
	  ((path == null) ? "" : "; path=" + path) +
	  ((domain == null) ? "" : "; domain=" + domain) +
	  ((secure == null) ? "" : "; secure");
	}

	function getCookie(name)
	{
	  var cname = name + "=";
	  var dc = document.cookie;
	  if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
		  begin += cname.length;
		  end = dc.indexOf(";", begin);
		  if (end == -1) end = dc.length;
			return unescape(dc.substring(begin, end));
		}
	  }
	  return null;
	}

	function delCookie (name,path,domain)
	{
	  if (getCookie(name)) {
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	  }
	}

//SET TEXT SIZE

	function textSize(type)
	{
		if(getCookie('txt') != null)	offset = getCookie('txt');
			else						offset = 0;
		
		if(type == '+' && offset < mx)
		{
			offset++;
			if(offset < mx)
				document.getElementById('textIncrease').innerHTML = '<img src="/images/textEnlargeActive.gif" border="0" height="13" width="13" />';
			else
				document.getElementById('textIncrease').innerHTML = '<img src="/images/textEnlargeInactive.gif" border="0" height="13" width="13" />';
			document.getElementById('textDecrease').innerHTML = '<img src="/images/textShrinkActive.gif" border="0" height="13" width="13" />';	
			setClass("ayah",1*inc);
			setClass("ayahSign",1*inc);
			//setCookie('txt',offset, expdate);
			//outputLanguage();
		}
		else if(type == '-' && offset > mn)
		{
			offset--;
			if(offset > mn)
				document.getElementById('textDecrease').innerHTML = '<img src="/images/textShrinkActive.gif" border="0" height="13" width="13" />';
			else
				document.getElementById('textDecrease').innerHTML = '<img src="/images/textShrinkInactive.gif" height="13" width="13" border="0" />';
			document.getElementById('textIncrease').innerHTML = '<img src="/images/textEnlargeActive.gif" height="13" width="13" border="0" />';	
			setClass("ayah",-1*inc);
			setClass("ayahSign",-1*inc);
			//setCookie('txt',offset, expdate);
			//outputLanguage();
		}
		setCookie('txt',offset, expdate, '/');
	}

//UPDATE TEXT SIZES

	function setClass(theClass,size) 
	{
		var allPageTags=document.getElementsByTagName("*");
		for (var i=0; i<allPageTags.length; i++) 
		{
			if (allPageTags[i].className==theClass) 
			{
				var classChange = allPageTags[i].style.fontSize;
				allPageTags[i].style.fontSize = (parseInt(classChange.substring(0,classChange.indexOf('px')))+size)+"px";
			}
		}
		if(document.getElementById('bismillah'))
			document.getElementById('bismillah').style.fontSize = (parseInt(document.getElementById('bismillah').style.fontSize.substring(0,document.getElementById('bismillah').style.fontSize.indexOf('px')))+size)+"px";
	} 

//CHANGE SURAH

	function changeSurah(surah)
	{
		location='/'+surah;
	}

//SEARCH BOX TIPS

	function popSearchBox()
	{
		var searchBox = document.getElementById('searchBoxTips');
		var canvas = document.getElementById('canvas');
		var html  = '<div id="popup"><div id="popupHeader"><div id="popupClose" onClick="javascript:popSearchBox();"><img src="/images/close.gif" border="0" alt="Close" /></div>Ways to Search the Qur\'an</div><div id="popupBody"><h1>Search by Specific Chapter, Verse </h1><blockquote><p>Enter a surah number and/or an ayah or ayah range in the search bar:</p><table cellpadding=0 cellspacing=0 border=0><tr><th width="115">Example Search</th><th width="300">Returns</th></tr><tr><td>1</td><td>Chapter 1 of the Qur\'an </td></tr><tr><td>4:12</td><td>Chapter 4, Verse 12 of the Qur\'an </td></tr><tr><td>10:5-9</td><td>Chapter 10, Verses 5 through 9 of the Qur\'an </td></tr></table></blockquote><h1>Word or Phrase Search</h1><blockquote><p>Enter a word or phrase in any language:</p><table cellpadding=0 cellspacing=0 border=0><tr><th width="115">Example Search</th><th width="300">Returns</th></tr><tr><td>believer</td><td>Any instance of "believer" in all translations </td></tr><tr><td>"O you who believe"</td><td>Any instance of "O you who believe" in all translations </td></tr><tr><td>"&#1610;&#1575; &#1571;&#1610;&#1607;&#1575; &#1575;&#1604;&#1584;&#1610;&#1606; &#1570;&#1605;&#1606;&#1608;&#1575;"</td><td>Any instance of &quot;&#1610;&#1575; &#1571;&#1610;&#1607;&#1575; &#1575;&#1604;&#1584;&#1610;&#1606; &#1570;&#1605;&#1606;&#1608;&#1575;&quot; in Arabic</td></tr></table></blockquote><h1>Phonetic Search</h1><blockquote>'
		//+'Phonetic search coming soon.'+
		+'<p>Enter a word or phrase to search transliteration: </p><table cellpadding=0 cellspacing=0 border=0><tr><th width="425">Example Search</th></tr><tr><td>bismillah ar rahman ar rahim </td></tr><tr><td>ya ayuhal lathina amanu </td></tr></table>'
		+'</blockquote></div></div>';
		
		if(searchBox.style.visibility == '')
		{
			visible = 'visible';
		}
		else
		{
			if(searchBox.style.visibility == 'hidden')		visible = 'visible';
								else						visible = 'hidden';
		}
		
		if(visible == 'visible')
		{
			searchBox.innerHTML = html;
			canvas.style.height = "100%";
		} else	canvas.style.height = "0px";

		searchBox.style.visibility = visible;
		canvas.style.visibility = visible;
	}
	
//SHOW MORE SEARCH AYAHS

	function expandAyat(trigger,box){
		trigger.innerHTML = (trigger.innerHTML ==  "show all" ? "show first" : "show all");

		document.getElementById(box).style.display = (document.getElementById(box).style.display == "block" ? "none" : "block");
		
	}

//AJAX INITIALIZE

	function initialize()
	{
	  var browser = navigator.appName;
	  if (browser == "Microsoft Internet Explorer"){
		 return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  else { return new XMLHttpRequest(); }
	}
	
	var http = initialize();
	
	function outputLanguage()
	{
		var query = '';
		for(var i=1; document.getElementById("lang_"+i); i++)
		{
			if(document.getElementById("lang_"+i).checked)
				query += "&"+i;
		}

		var loc = '/output.php?s='+s+'&sA='+sA+'&eA='+eA+query;
	
		http.open('get', loc);
		http.onreadystatechange = handle_reply;
		http.send(null);
	}
	
	function handle_reply()
	{
		if (http.readyState == 4)
		{
			var response = http.responseText;
			document.getElementById("quranOutput").innerHTML = http.responseText;
			document.getElementById("statusContainer").style.visibility = "hidden";
		}
		else {	
			document.getElementById("statusContainer").style.visibility = "visible";
		}
		
	}