﻿var pg;
function showSurah(cObject) {
	document.getElementById('ayatrans').innerHTML="<div id='transe' align='center'>Loading please wait...</div>";
	if (document.fPara.sTrans.value == 0 & document.getElementById('ayatrans').style.height=="440px")
		resize(0);
	switch(cObject) {
		case 'body': 
			show('index.php?p=surah&s=1&r=1&t=0&k=1&c=2');
		break
		case 'sSurah':
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&k=1&r=1&c='+document.fPara.sScript.value);
		break
		case 'sRaku':
			document.fAyah.sAyah.options[0].selected="selected";
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&r='+document.fAyah.sRaku.value+'&c='+document.fPara.sScript.value);
		break
		case 'sPara':
			show('index.php?p=surah&j='+document.fPara.sPara.value+'&k=1&t='+document.fPara.sTrans.value+'&c='+document.fPara.sScript.value);
		break
		case 'sTrans':
			resize(document.fPara.sTrans.value);
			if (document.fAyah.sAyah.value == 0)
				show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&r='+document.fAyah.sRaku.value+'&c='+document.fPara.sScript.value);
			else
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&a='+document.fAyah.sAyah.value+'&c='+document.fPara.sScript.value);
		break
		case 'sAyah':
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&a='+document.fAyah.sAyah.value+'&c='+document.fPara.sScript.value);
		break
		case 'Prev':
			var Prev = document.fAyah.sRaku.value;
			if (Prev > 1) {
				Prev--;
				document.fAyah.sAyah.options[0].selected="selected";
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&r='+Prev+'&c='+document.fPara.sScript.value);
				document.fAyah.sRaku.options[Prev-1].selected="selected";
			}
			else if (document.fSurah.sSurah.value > 1) {
				Prev = document.fSurah.sSurah.value;
				Prev = Prev-1;
				document.fSurah.sSurah.options[Prev-1].selected="selected";
				show('index.php?p=surah&s='+Prev+'&t='+document.fPara.sTrans.value+'&r=1&k=1&c='+document.fPara.sScript.value);
			}
		break
		case 'Next':
			var Next = document.fAyah.sRaku.value;
			if (Next < document.fAyah.sRaku.length) {
				Next++;
				document.fAyah.sAyah.options[0].selected="selected";
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&r='+Next+'&c='+document.fPara.sScript.value);
				document.fAyah.sRaku.options[Next-1].selected="selected";
			}
			else if (document.fSurah.sSurah.value < 114) {
				Next = document.fSurah.sSurah.value;
				document.fSurah.sSurah.options[Next].selected="selected";
				Next++;
				show('index.php?p=surah&s='+Next+'&t='+document.fPara.sTrans.value+'&r=1&k=1&c='+document.fPara.sScript.value);
			}
		break
		case 'sSearch':
			if (document.fPara.sSearch.value == 2)
				document.getElementById('iSearch').style.textAlign="left";
			else
				document.getElementById('iSearch').style.textAlign="right";
		break
		case 'sScript':
			show('index.php?p=surah&s='+document.fSurah.sSurah.value+'&t='+document.fPara.sTrans.value+'&r='+document.fAyah.sRaku.value+'&c='+document.fPara.sScript.value);
		break
	}
}
function fSearch(mpg,nav,trec) {
	if (document.fPara.iSearch.value != "") {
	if (mpg == 1) {
		pg = 1; }
	else {
		if (nav == 0 & pg > 1)
			pg--;
		else if (nav == 1 & pg < mpg)
			pg++;
	}
	if (pg == mpg) var rnum = trec; else var rnum = pg*10;
	if (document.getElementById('pSearch'))
		document.getElementById('pSearch').innerHTML="Records found "+trec+" showing "+((pg*10)-9)+" - "+rnum;
	if (document.fPara.match[0].checked)
		var m = 1;
	else
		var m = 2;
	var mc = encodeURIComponent(document.fPara.iSearch.value);
	var newdiv = document.createElement('div');
  	newdiv.setAttribute('id','spage');
	document.getElementById('qcontent').appendChild(newdiv);
	resize(1);
	document.getElementById('ayatrans').innerHTML="<div id='transe' align='center'>Searching please wait...</div>";
	show('index.php?p=search&s='+mc+'&t='+document.fPara.sSearch.value+'&c='+document.fPara.sScript.value+'&m='+m+'&pg='+pg);
}}
function show(url) { 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
 		alert ("Your browser does not support Java Script");
 		return;
 	}
	xmlHttp.onreadystatechange=stateChanged; 
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
 		var response = xmlHttp.responseText;
        var update = new Array();
        if(response.indexOf('|' != -1)) {
            update = response.split('|');
			for (i=0;i<update.length-1;i++) {
				document.getElementById(update[i]).innerHTML = update[i+1];
				i++;
			}
        }
		if (document.fValues.suraID.value) {
			document.fSurah.sSurah.options[document.fValues.suraID.value-1].selected="selected";
		} 
		else if (document.fValues.paraID.value) {
			document.fPara.sPara.options[document.fValues.paraID.value].selected="selected";
		} 
		else if (document.fValues.RakuID.value) {
			document.fAyah.sRaku.options[document.fValues.RakuID.value].selected="selected";
		}
 	}
}
function GetXmlHttpObject() {
	var xmlHttp=null;
	try	{
		xmlHttp=new XMLHttpRequest();
 	}
	catch (e) {
 		try	{
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e) {
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}
function resize(obj) {
	if (obj == 0) {
		document.getElementById('ayatrans').style.height="220px";
		document.getElementById('tafseer').style.visibility="visible";
		document.getElementById('tafseer').style.height="220px";
		document.getElementById('tafseer').style.marginTop="5px";
		if (document.getElementById('spage'))
		document.getElementById('qcontent').removeChild(document.getElementById('spage'));
	}
	else {
		document.getElementById('ayatrans').style.height="440px";
		document.getElementById('tafseer').style.visibility="hidden";
		document.getElementById('tafseer').style.height="0px";
		document.getElementById('tafseer').style.marginTop="0px";
	}
}
function Hide(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "none";
}
function Show(d) {
if(d.length < 1) { return; }
document.getElementById(d).style.display = "block";
var theHandle = document.getElementById("move");
var theRoot = document.getElementById("keyboard");
Drag.init(theHandle, theRoot);
}
function strkey(k) {
if (document.fPara.sSearch.value == 0 & document.fPara.sScript.value == 1) {
if (k == 'ۃ') k = 'ة';
else if (k == 'ک') k = 'ك';
else if (k == 'ہ' | k == 'ه')  k = 'ه';
else if (k == 'ء') k = 'ئ';
else if (k == 'ی')  k = 'ي';
}
document.fPara.iSearch.value += k;
}
