﻿
function RObj(ea) { var LS = ""; var QS = new Object(); var un = "undefined"; var x = null; var f = "function"; var n = "number"; var r = "string"; var e1 = "ERROR:Index out of range in\r\nRequest.QueryString"; var e2 = "ERROR:Wrong number of arguments or invalid property assignment\r\nRequest.QueryString"; var e3 = "ERROR:Object doesn't support this property or method\r\nRequest.QueryString.Key"; var dU = window.decodeURIComponent ? 1 : 0; function Err(arg) { if (ea) { alert("Request Object:\r\n" + arg) } }; function URID(t) { var d = ""; if (t) { for (var i = 0; i < t.length; ++i) { var c = t.charAt(i); d += (c == "+" ? " " : c) } } return (dU ? decodeURIComponent(d) : unescape(d)) }; function OL(o) { var l = 0; for (var i in o) { if (typeof o[i] != f) { l++ } }; return l }; function AK(key) { var auk = true; for (var u in QS) { if (typeof QS[u] != f && u.toString().toLowerCase() == key.toLowerCase()) { auk = false; return u } } if (auk) { QS[key] = new Object(); QS[key].toString = function() { return TS(QS[key]) }; QS[key].Count = function() { return OL(QS[key]) }; QS[key].Count.toString = function() { return OL(QS[key]).toString() }; QS[key].Item = function(e) { if (typeof e == un) { return QS[key] } else { if (typeof e == n) { var a = QS[key][Math.ceil(e)]; if (typeof a == un) { Err(e1 + "(\"" + key + "\").Item(" + e + ")") }; return a } else { Err("ERROR:Expecting numeric input in\r\nRequest.QueryString(\"" + key + "\").Item(\"" + e + "\")") } } }; QS[key].Item.toString = function(e) { if (typeof e == un) { return QS[key].toString() } else { var a = QS[key][e]; if (typeof a == un) { Err(e1 + "(\"" + key + "\").Item(" + e + ")") }; return a.toString() } }; QS[key].Key = function(e) { var t = typeof e; if (t == r) { var a = QS[key][e]; return (typeof a != un && a && a.toString() ? e : "") } else { Err(e3 + "(" + (e ? e : "") + ")") } }; QS[key].Key.toString = function() { return x } }; return key }; function AVTK(key, val) { if (key != "") { var key = AK(key); var l = OL(QS[key]); QS[key][l + 1] = val } }; function TS(o) { var s = ""; for (var i in o) { var ty = typeof o[i]; if (ty == "object") { s += TS(o[i]) } else if (ty != f) { s += o[i] + ", " } }; var l = s.length; if (l > 1) { return (s.substring(0, l - 2)) } return (s == "" ? x : s) }; function KM(k, o) { var k = k.toLowerCase(); for (var u in o) { if (typeof o[u] != f && u.toString().toLowerCase() == k) { return u } } } if (window.location && window.location.search) { LS = window.location.search; var l = LS.length; if (l > 0) { LS = LS.substring(1, l); var preAmpAt = 0; var ampAt = -1; var eqAt = -1; var k = 0; var skip = false; for (var i = 0; i < l; ++i) { var c = LS.charAt(i); if (LS.charAt(preAmpAt) == "=" || (preAmpAt == 0 && i == 0 && c == "=")) { skip = true } if (c == "=" && eqAt == -1 && !skip) { eqAt = i } if (c == "&" && ampAt == -1) { if (eqAt != -1) { ampAt = i } if (skip) { preAmpAt = i + 1 }; skip = false } if (ampAt > eqAt) { AVTK(URID(LS.substring(preAmpAt, eqAt)), URID(LS.substring(eqAt + 1, ampAt))); preAmpAt = ampAt + 1; eqAt = ampAt = -1; ++k } } if (LS.charAt(preAmpAt) != "=" && (preAmpAt != 0 || i != 0 || c != "=")) { if (preAmpAt != l) { if (eqAt != -1) { AVTK(URID(LS.substring(preAmpAt, eqAt)), URID(LS.substring(eqAt + 1, l))) } else if (preAmpAt != l - 1) { AVTK(URID(LS.substring(preAmpAt, l)), "") } } if (l == 1) { AVTK(LS.substring(0, 1), "") } } } }; var TC = OL(QS); if (!TC) { TC = 0 }; QS.toString = function() { return LS.toString() }; QS.Count = function() { return (TC ? TC : 0) }; QS.Count.toString = function() { return (TC ? TC.toString() : "0") }; QS.Item = function(e) { if (typeof e == un) { return LS } else { if (typeof e == n) { var e = Math.ceil(e); var c = 0; for (var i in QS) { if (typeof QS[i] != f && ++c == e) { return QS[i] } }; Err(e1 + "().Item(" + e + ")") } else { return QS[KM(e, QS)] } }; return x }; QS.Item.toString = function() { return LS.toString() }; QS.Key = function(e) { var t = typeof e; if (t == n) { var e = Math.ceil(e); var c = 0; for (var i in QS) { if (typeof QS[i] != f && ++c == e) { return i } } } else if (t == r) { var e = KM(e, QS); var a = QS[e]; return (typeof a != un && a && a.toString() ? e : "") } else { Err(e2 + "().Key(" + (e ? e : "") + ")") }; Err(e1 + "().Item(" + e + ")") }; QS.Key.toString = function() { Err(e2 + "().Key") }; this.QueryString = function(k) { if (typeof k == un) { return QS } else { if (typeof k == n) { return QS.Item(k) }; var k = KM(k, QS); if (typeof QS[k] == un) { t = new Object(); t.Count = function() { return 0 }; t.Count.toString = function() { return "0" }; t.toString = function() { return x }; t.Item = function(e) { return x }; t.Item.toString = function() { return x }; t.Key = function(e) { Err(e3 + "(" + (e ? e : "") + ")") }; t.Key.toString = function() { return x }; return t } else { return QS[k] } } }; this.QueryString.toString = function() { return LS.toString() }; this.QueryString.Count = function() { return (TC ? TC : 0) }; this.QueryString.Count.toString = function() { return (TC ? TC.toString() : "0") }; this.QueryString.Item = function(e) { if (typeof e == un) { return LS.toString() } else { if (typeof e == n) { var e = Math.ceil(e); var c = 0; for (var i in QS) { if (typeof QS[i] != f && ++c == e) { return QS[i] } }; Err(e1 + ".Item(" + e + ")") } else { return QS[KM(e, QS)] } } if (typeof e == n) { Err(e1 + ".Item(" + e + ")") }; return x }; this.QueryString.Item.toString = function() { return LS.toString() }; this.QueryString.Key = function(e) { var t = typeof e; if (t == n) { var e = Math.ceil(e); var c = 0; for (var i in QS) { if (typeof QS[i] == "object" && (++c == e)) { return i } } } else if (t == r) { var e = KM(e, QS); var a = QS[e]; return (typeof a != un && a && a.toString() ? e : "") } else { Err(e2 + ".Key(" + (e ? e : "") + ")") }; Err(e1 + ".Item(" + e + ")") }; this.QueryString.Key.toString = function() { Err(e2 + ".Key") }; this.Version = 1.4; this.Author = "Andrew Urquhart (http://andrewu.co.uk)" }; var Request = new RObj(false);
//function addJavascript(jsname) {

//    var th = document.getElementsByTagName('head')[0];

//    var s = document.createElement('script');

//    s.setAttribute('type', 'text/javascript');

//    s.setAttribute('src', jsname);

//    th.appendChild(s);

//}
//addJavascript("http://localhost/www/quran/gadgets/quran/templates/1/telavatplayer.js");

var caution = false
var tabstatus = new Object();

function getCookie(name) {
    var prefix = name + "="
    var cookieStartIndex = document.cookie.indexOf(prefix)
    if (cookieStartIndex == -1)
        return null
    var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
         prefix.length)
    if (cookieEndIndex == -1)
        cookieEndIndex = document.cookie.length
    return unescape(document.cookie.substring(cookieStartIndex +
         prefix.length,
   cookieEndIndex))
}


function ReadCookie(cookieName) {
    var theCookie = "" + document.cookie;
    var ind = theCookie.indexOf(cookieName);
    if (ind == -1 || cookieName == "") return "";
    var ind1 = theCookie.indexOf(';', ind);
    if (ind1 == -1) ind1 = theCookie.length;
    return unescape(theCookie.substring(ind + cookieName.length + 1, ind1));
}


var root = "http://telavat.com/quran";
var root1 = root + "/Gadgets/Quran/";

/*******************/
var templateId = "1";

var currentTab;
var soore, juz, aye, page, trans, ayefolder,telavat,reciter;
var selected_sooreno = Request.QueryString("sno") == null ? 1 : Request.QueryString("sno");
var selected_ayeid = 1;
var selected_ayeno = Request.QueryString("ano") == null ? 1 : Request.QueryString("ano");
var selected_aye = null;
var selected_trans = null;
var selected_juzno = 1;
var selected_pageno = 1;
var sno, isAdv;
var tafsir;

function getDropDownLabel(obj) {
    var element = obj[obj.selectedIndex].firstChild.nodeValue;
    SplitName = element.split("-");
    element = SplitName[1];
    return element;
}
function ShowHideAdvancedSearch() {
    var divadv = $("divSearchAdvanced");
    if ($("divSearchAdvanced").style.display == "none")
    { divadv.style.display = "block"; }
    else { divadv.style.display = "none"; }
}
function DownloadFile(url) {
    $("secimag").style.display = "block";
    $("ifrm").src = url;
    pageScrollup(-100);
}

function close() {
    $("secimag").style.display = "none";
}
function InitPage() {
    //    activateTab("divQuran");
    soore = $("cbxSoore");
    juz = $("cbxJuz");
    aye = $("cbxAye");
    trans = $("cbxTrans");
    page = $("txtPageNo");
    telavat = $("chkTelavat");
    reciter = $("cbxReciter");
    $("spnQuran").innerHTML = "قرآن";
    $("spnSearch").innerHTML = "جستجو";
    $("spnQeraat").innerHTML = "قرائت";
    $("spnTafsir").innerHTML = "تفسیر";
    $("spnQuranInfo").innerHTML = "اطلاعات قرآنی";
    $("spnTopPage").innerHTML = "صفحه ";
    $("spnBottomPage").innerHTML = "صفحه ";
    ayefolder = "/Tartil/";
    var tab = Request.QueryString("tab");

    var sno = Request.QueryString("sno") == null ? 1 : Request.QueryString("sno");
    var isAdv = Request.QueryString("isAdv");

    if (sno > 0) {
        LoadQuran("sa", selected_sooreno + ';' + selected_ayeno, trans.value);
        LoadQeraat("s", selected_sooreno);
        LoadQuranInfo("category", selected_sooreno);
        $("fsTreeContent").style.display = "none";
    }
    else {
        LoadQuran("sa", 1 + ';' + 1, trans.value);
        //      DoSearch(null, isAdv);
    }
    setTab(tab);
    activateTab(tabstatus.active);
}
function getAyeAddress(soore, aye) {

    var ayename;
    var soorename;
    if (aye > 0 && aye < 10)
    { ayename = '00' + aye; }
    if (aye > 9 && aye < 100)
    { ayename = '0' + aye; }
    if (aye > 99 && aye < 287)
    { ayename = aye; }

    if (soore > 0 && soore < 10)
    { soorename = '00' + soore; }
    if (soore > 9 && soore < 100)
    { soorename = '0' + soore; }
    if (soore > 99 && soore < 115)
    { soorename = soore; }
    return '/aye/' + soorename + ayename + '.mp3';
}
function setTab(tab) {
    if (tab == 1) {
        tabstatus.active = "divQuran";
    }
    if (tab == 2) {
        tabstatus.active = "divSearch";
    }
    if (tab == 3) {
        tabstatus.active = "divQeraat";
    }
    if (tab == 4) {
        tabstatus.active = "divTafsir";
    }
    if (tab == 5) {
        tabstatus.active = "divQuranInfo";
    }
}
function LoadQuranInfo(part, num) {
    //    alert(part + "    " + num);
    ShowLoading();
    var ajax = new AJAX();
    var args = { part: part, num: num };
    var p = root1 + "AjaxifyQuranInfo.aspx";
    ajax.request(p, args, LoadQuranInfoCallBack);
}
function showdesc(Alaam) {
    var ajax = new AJAX();
    var part = 'subcategory'
    var args = { part: part, AlamId: Alaam };
    var p = root1 + "AjaxifyQuranInfo.aspx";
    ajax.request(p, args, showdescCallBack);
}
function showdescCallBack(response) {
    //    alert("desc : " + response);
    if (response == null || /Fatal error/.test(response)) {
        ShowError();
        return;
    }
    $("fsTreeContent").style.display = "block";
    $("divTreeContent").innerHTML = response;
    pageScrollup(-50);
}
function pageScrollup(ud) {
    var st = zxcWWHS()[3];
    window.scrollBy(0, ud); // horizontal and vertical scroll increments
    if (st != zxcWWHS()[3]) {
        scrolldelay = setTimeout('pageScrollup(' + ud + ')', 50);
    }
}
function zxcWWHS() {
    if (window.innerHeight) return [window.innerWidth - 10, window.innerHeight - 10, window.pageXOffset, window.pageYOffset];
    else if (document.documentElement.clientHeight) return [document.documentElement.clientWidth - 10, document.documentElement.clientHeight - 10, document.documentElement.scrollLeft, document.documentElement.scrollTop];
    return [document.body.clientWidth, document.body.clientHeight, document.body.scrollLeft, document.body.scrollTop];
}
function LoadQuranInfoCallBack(response) {
    if (response == null || /Fatal error/.test(response)) {
        ShowError();
        return;
    }
    d = new dTree('d');
    d.add(0, -1, 'اطلاعات قرآنی سوره' + getDropDownLabel(soore));
    var sp = response.split("|");
    for (var i = 0; i < sp.length; i++) {
        var child = sp[i].split(",");
        if (child[1] == '0') {
            d.add(child[0], child[1], child[2] + child[3]);
        }
        else {
            d.add(child[0], child[1], child[2]);
        }
    }
    $("divQuranTree").innerHTML = d;
    UpdateFrameSize();
    HideLoading();
    activateTab(tabstatus.active);
    //    activateTab("divQuranInfo");
}

function LoadQeraat(part, num) {
    ShowLoading();
    var ajax = new AJAX();

    var args = { part: part, num: num, templateId: templateId };
    var p = root1 + "AjaxifyQeraat.aspx";
    ajax.request(p, args, LoadQeraatCallBack);
}
function LoadQeraatCallBack(response) {

    if (response == null || /Fatal error/.test(response)) {
        ShowError();
        return;
    }

    //    activateTab("divQeraat");
    var sp = response.split("<|>");
    $("divQeraat").innerHTML = sp[0];

    UpdateFrameSize();
    HideLoading();
    activateTab(tabstatus.active);
}
function changeTrans() {
    var trans = $("cbxTrans");
    LoadQuran("sa", selected_sooreno + ';' + selected_ayeno, trans.value);
}

function LoadQuran(part, num, translationId) {

    ShowLoading();
    var ajax = new AJAX();
    var args = { part: part, num: num, templateId: templateId, transId: translationId };
    var p = root1 + "Ajaxify.aspx";
    ajax.request(p, args, LoadQuranCallBack);

}

function LoadQuranCallBack(response) {

    if (response == null || /Fatal error/.test(response)) 
    {
        ShowError();
        return;
    }
    //    activateTab("divQuran");
    var sp = response.split("<|>");

    $("divAyat").innerHTML = sp[0];
    if (trans.value <= 2)
    { $("divTransIn").innerHTML = sp[1]; $("divTransOut").innerHTML = ""; }
    else
    { $("divTransOut").innerHTML = sp[1]; $("divTransIn").innerHTML = ""; }

    selected_sooreno = sp[2];
    selected_ayeid = sp[3];
    selected_ayeno = sp[4];
    selected_pageno = sp[5];
    selected_juzno = sp[6];
    tafsir = sp[7];
    page.value = selected_pageno;
    $("TopPageLabel").innerHTML = selected_pageno;
    $("BottomPageLabel").innerHTML = selected_pageno;
    ActivateSoore();
    ActivateAye();
    OnAyeHighlight(selected_ayeid);
    juz.value = selected_juzno;
    
    playmp3(root , ayefolder , selected_sooreno, selected_ayeno);

    LoadTafsir(tafsir, selected_ayeno);
    UpdateFrameSize();

    HideLoading();
    $("spnQeraat").innerHTML = "قرائتهاي سوره " + getDropDownLabel(soore);
    //    activateTab("divQuran");
    activateTab(tabstatus.active);
}
function changeReciter() 
{
    playmp3(root, ayefolder, selected_sooreno, selected_ayeno);
}
function playmp3(root1, ayefolder1, selected_sooreno1, selected_ayeno1) 
{
    var ReciterFolder="";
    if (reciter.value == 1)
    {ReciterFolder = "Parhizkar"; }
    else
    { ReciterFolder = "Menshavi"; }
    adres = root + ayefolder1 + ReciterFolder + getAyeAddress(selected_sooreno1, selected_ayeno1);
    if (telavat.checked)
    { telavatplayer('telavatPlayer1').loadAndPlay(adres); }
    else
    { telavatplayer('telavatPlayer1').load(adres); }
}
function LoadTafsir(tafsir, ayeno) {
    $("divTaf").innerHTML = tafsir;
    $("SpnTopTaf").innerHTML = " آیه ";
    $("SpnBottomTaf").innerHTML = " آیه ";
    $("TopTafLabel").innerHTML = ayeno;
    $("BottomTafLabel").innerHTML = ayeno;
    $("spnTafsir").innerHTML = "تفسیر آیه " + ayeno + " سوره " + getDropDownLabel(soore);
}
function ShowQuranPrevPage() {
    if (selected_pageno == 1)
        return;
    LoadQuran("p", selected_pageno - 1, trans.value);
    //    LoadQeraat("sa", soore.value);

}

function ShowQuranNextPage() 
{
    if (selected_pageno == 604)
        return;
    LoadQuran("p", parseInt(selected_pageno) + 1, trans.value);
}
function ShowTafsirPrevAye() {
    if (aye.value == 1)
        return;
    toptaf = $("TopTafLabel");
    tt = toptaf.innerHTML;
    tt = tt - 1;
    LoadQuran("sa", soore.value + ';' + tt, trans.value);
    activateTab(tabstatus.active);
}
function ShowTafsirNextAye() {
    AyeCombo = $("cbxAye");
    if (aye.value == AyeCombo.options.length)
        return;
    toptaf = $("TopTafLabel");
    bt = toptaf.innerHTML;
    bt = TryParseInt(bt) + 1;
    LoadQuran("sa", soore.value + ';' + bt, trans.value);
    activateTab(tabstatus.active);
}
function ShowError() {
    alert("Error");
}

function ActivateSoore() {
    soore.selectedIndex = selected_sooreno - 1;

    if (aye.options.length == soore.options[selected_sooreno - 1].getAttribute("ac"))
        return;

    // SET AYE LIST
    aye.options.length = 0;
    aye.options.length = soore.options[selected_sooreno - 1].getAttribute("ac");
    for (var i = 0; i < aye.options.length; i++) {
        aye.options[i].text = i + 1;
        aye.options[i].value = i + 1;
    }
    aye.value = 1;
    LoadQeraat("sa", soore.value);
    LoadQuranInfo("category", selected_sooreno);
}

function ActivateAye() {
    aye.selectedIndex = selected_ayeno - 1;
}

// **********************
// *****   events   *****
// **********************

function OnSooreSelected() {
    LoadQeraat("sa", soore.value);
    LoadQuran("sa", soore.value + ';' + 1, trans.value);
    LoadQuranInfo("category", soore.value);
    $("fsTreeContent").style.display = "none";
    //    activateTab("divQuran");
    activateTab(tabstatus.active);
}

function OnAyeSelected(sooreno1, ayeno1) {
    LoadQuran("sa", sooreno1 + ';' + ayeno1, trans.value);
    activateTab("divQuran");
}
function OnAyeSelect(sooreno, ayeno) {
    if (!sooreno)
        sooreno = soore.value;

    if (!ayeno)
        ayeno = aye.options[aye.selectedIndex].text;

    var aye = ayeno.split(";");

    LoadQuran("sa", aye[0] + ';' + aye[2], trans.value);
    activateTab("divQuran");
}
function OnAyeCbxSelected() {
    AyeCombo = $("cbxAye");
    ayeno = AyeCombo.options[AyeCombo.selectedIndex].text;
    var aye = ayeno.split(";");
    LoadQuran("sa", soore.value + ';' + ayeno, trans.value);
    activateTab("divQuran");
}
function OnJuzSelected() {
    LoadQuran("j", juz.value, trans.value);
    LoadQeraat("sa", soore.value);
    LoadQuranInfo("category", soore.value);
}

function OnPageSelected() {

}

function OnTransSelected() {

}

function OnAyeClicked(ayeid) {
    OnAyeSelect(soore.value, ayeid);
}
function OnAyeHighlight(ayeid) {
    //    alert(ayeid + "hhh" + selected_ayeid);
    //    if (selected_ayeid == ayeid) return;
    if (ayeid == null) ayeid = selected_ayeid;

    var span_aye = $(format("aye{0}", ayeid));

    var span_trans = $(format("trans{0}", ayeid));

    span_aye.style.backgroundImage = "url(" + root + "/Gadgets/Quran/Templates/Common/Images/bg45.gif)";
    span_trans.style.backgroundImage = "url(" + root + "/Gadgets/Quran/Templates/Common/Images/bg25.gif)";

    if (selected_aye && selected_trans) {
        selected_aye.style.backgroundImage = "";
        selected_trans.style.backgroundImage = "";
    }
    selected_ayeid = ayeid;
    selected_aye = span_aye;
    selected_trans = span_trans;
}
function txtPageNoOnKeyPress(e) {
    var keycode = GetKeyPressed(e);

    if (keycode == 13) {
        var p = (page.value);

        if (TryParseInt(p)) {
            if (p < 1)
                p = 1;
            if (p > 604)
                p = 604;
        }

        LoadQuran("p", p, trans.value);
    }
}

function txtSearchOnKeyPress(e, isAdv) {
    if (GetKeyPressed(e) == 13) {
        DoSearch(null, isAdv);
    }
}
function GetRadioValue(ctrl) {
    var val = 0;
    for (i = 0; i < ctrl.length; i++) {
        if (ctrl[i].checked == true)
            val = ctrl[i].value;
    }
    return val;
}
function DoAdvancedSearch(page) {
    ShowLoading();
    var wrd = GetRadioValue(document.getElementsByName("wrd"));
    var txt = GetRadioValue(document.getElementsByName("txt"));
    var rang = GetRadioValue(document.getElementsByName("rang"));

    if (rang > 0) {
        rang = soore.value;
    }
    var pageIndex;
    if (page)
        pageIndex = page - 1;
    else
        pageIndex = 0;
    var args;
    var searchWord = $("txtSearchAdv").value;
    part = "adv";
    args = { part: part, searchWord: searchWord, wrd: wrd, txt: txt, rang: rang, soore: getDropDownLabel(soore), pageIndex: pageIndex, templateId: 1 };

    var ajax = new AJAX();
    ajax.request(root1 + "AjaxifySearch.aspx", args, SearchQuranCallBack);
}


function DoSearch1(page, isAdv) {
    //alert(isAdv);
    ShowLoading();

    var pageIndex;
    if (page)
        pageIndex = page - 1;
    else
        pageIndex = 0;

    var args;

    if (isAdv) {

        args = { isAdv: true, textAll: escape($("txtSearchAll").value) == "" ? isAdv : escape($("txtSearchAll").value), textAtLeast: escape($("txtSearchAtLeast").value) == "" ? isAdv : escape($("txtSearchAtLeast").value), pageIndex: pageIndex, templateId: templateId };
    }
    else {

        args = { isAdv: false, text: escape($("txtSearch").value) == "" ? isAdv : escape($("txtSearch").value), pageIndex: pageIndex, templateId: templateId };
    }

    var ajax = new AJAX();
    ajax.request(root1 + "AjaxifySearch.aspx", args, SearchQuranCallBack);
}
function DoSearch(page, isAdv) {
    ShowLoading();
    //    alert("DoSearch");
    var pageIndex;
    if (page)
        pageIndex = page - 1;
    else
        pageIndex = 0;

    var args;

    if (isAdv) {

        args = { isAdv: true, textAll: escape($("txtSearchAll").value) == "" ? isAdv : escape($("txtSearchAll").value), textAtLeast: escape($("txtSearchAtLeast").value) == "" ? isAdv : escape($("txtSearchAtLeast").value), pageIndex: pageIndex, templateId: templateId };
    }
    else {

        args = { isAdv: false, text: escape($("txtSearch").value) == "" ? isAdv : escape($("txtSearch").value), pageIndex: pageIndex, templateId: templateId };
    }

    var ajax = new AJAX();
    ajax.request(root1 + "AjaxifySearch.aspx", args, SearchQuranCallBack);
}

function SearchQuranCallBack(response) {
    if (response == null || /Fatal error/.test(response)) {
        ShowError();
        return;
    }

    //    activateTab("divSearch");
    activateTab(tabstatus.active);
    var sp = response.split("<|>");

    if (sp[1] == '-1') {
        $("divResults").innerHTML = 'خطايي رخ داده است. لطفا مجددا تلاش نماييد!';
    }
    if (sp[1] == '-2') {
        $("divResults").innerHTML = 'عبارت وارد شده معتبر نيست!';
    }
    else if (sp[1] == '0') {
        $("divResults").innerHTML = 'جستجو نتيجه اي نداشت!';
    }
    else {
        $("divResults").innerHTML = sp[0];
        $("TopResultsPaging").innerHTML = sp[3];

        $("BottomResultsPaging").innerHTML = sp[3];
    }
    $("divSerachInfo").innerHTML = sp[2];
    if (parseInt(sp[1]) <= 10) {
        $("TopResultsPaging").innerHTML = '';
        $("BottomResultsPaging").innerHTML = '';

        $("TopPaging").style.display = 'none';
        $("BottomPaging").style.display = 'none';
    }
    else {
        $("TopPaging").style.display = 'block';
        $("BottomPaging").style.display = 'block';
    }

    UpdateFrameSize();
    HideLoading();
    activateTab("divSearch");
}

function activateTab(tabId) {
    if (currentTab == tabId)
        return;

    $("divQuran").style.display = (tabId == "divQuran") ? "block" : "none";
    $("divSearch").style.display = (tabId == "divSearch") ? "block" : "none";
    //    $("divDic").style.display     = (tabId == "divDic")   ? "block" : "none";
    $("divQeraat").style.display = (tabId == "divQeraat") ? "block" : "none";
    $("divTafsir").style.display = (tabId == "divTafsir") ? "block" : "none";
    $("divQuranInfo").style.display = (tabId == "divQuranInfo") ? "block" : "none";

    $("tabQuran").className = (tabId == "divQuran") ? "selected" : "";
    $("tabSearch").className = (tabId == "divSearch") ? "selected" : "";
    //    $("tabDic").className    = (tabId == "divDic")     ? "selected" : "";
    $("tabQeraat").className = (tabId == "divQeraat") ? "selected" : "";
    $("tabTafsir").className = (tabId == "divTafsir") ? "selected" : "";
    $("tabQuranInfo").className = (tabId == "divQuranInfo") ? "selected" : "";

    $("liQuran").className = (tabId == "divQuran") ? "current" : "";
    $("liSearch").className = (tabId == "divSearch") ? "current" : "";
    //    $("liDic").className    = (tabId == "divDic")     ? "current" : "";
    $("liQeraat").className = (tabId == "divQeraat") ? "current" : "";
    $("liTafsir").className = (tabId == "divTafsir") ? "current" : "";
    $("liQuranInfo").className = (tabId == "divQuranInfo") ? "current" : "";
    tabstatus.active = tabId;
    //    alert(tabstatus.active);
    if (tabId == "divQuran") {

    }
    else if (tabId == "divSearch") {

    }
    else if (tabId == "divDic") {

    }
    else if (tabId == "divQeraat") {

    }
    else if (tabId == "divTafsir") {

    }
    else if (tabId == "divQuranInfo") {

    }
    else {
        alert("error!");
    }

    currentTab = tabId;

    UpdateFrameSize();
}

function ShowLoading() {
    var w = 150;
    var h = 30;

    var d = getWinDims();
    var elm = $('divLoading');

    elm.style.left = (d.width - 320) / 2 + "px";
    elm.style.top = "250px"; //(d.height - 100)/2 + "px";
    elm.style.height = h + "px";
    elm.style.width = w + "px";

    elm.style.display = "block";
}

function HideLoading() {
    //return;
    var elm = $('divLoading');
    elm.style.display = "none";
}

function UpdateFrameSize() {
    //alert(this.parent.frames.length);
    //alert(this.parent.frames[0]);
    //alert(this.parent.frames[0].width);
    //alert(window.frameElement);


    //    if(this.parent.frames.length == 0)
    //    {
    //        alert('error');
    //        return;
    //    }
    //    this.parent.frames[0].height = $('divTemplate').offsetHeight + 20 + 'px';
    //    this.parent.frames[0].width  = '800px';



    return;


    //    if(!window.frameElement)
    //        return;
    //        
    //    window.frameElement.height = $('divTemplate').offsetHeight + 20 + 'px';
    //    window.frameElement.width  = '800px';

}

function poonez_click() {
    var d = $("divAdvSearch");
    var p = $("poonez");
    var t = $("tblAdvSearch");

    var status = p.getAttribute("status");

    if (status == "1") {
        t.style.display = "none";
        d.style.height = "18px";
        d.style.width = "125px";

        p.innerHTML = "جستجوي پيشرفته"

        p.setAttribute("status", "0");
        p.style.backgroundPosition = "left bottom";
    }
    else if (status == "0") {
        t.style.display = "block";
        d.style.height = "135px";
        d.style.width = "auto";

        p.innerHTML = "&nbsp;"

        p.setAttribute("status", "1");
        p.style.backgroundPosition = "left top";
    }
}

// must be available in general.js
function getWinDims() {
    var myWidth = 0, myHeight = 0;
    if (typeof window.innerWidth == "number") {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement &&
        (document.documentElement.clientWidth ||
        document.documentElement.clientHeight)) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body &&
        (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return { width: myWidth, height: myHeight };
}
//if (window.addEventListener) {
//    window.addEventListener("load", InitPage, false);
//}
//else if (window.attachEvent) {
//    window.attachEvent("onload", InitPage);
//}

// Node object
function Node(id, pid, name, url, title, target, icon, iconOpen, open) {
    this.id = id;
    this.pid = pid;
    this.name = name;
    this.url = url;
    this.title = title;
    this.target = target;
    this.icon = icon;
    this.iconOpen = iconOpen;
    this._io = open || false;
    this._is = false;
    this._ls = false;
    this._hc = false;
    this._ai = 0;
    this._p;
};
// Tree object
function dTree(objName) {
    this.config = {
        target: null,
        folderLinks: true,
        useSelection: true,
        useCookies: true,
        useLines: true,
        useIcons: true,
        useStatusText: false,
        closeSameLevel: false,
        inOrder: false
    }
    this.icon = {
        root: '../../img/base.gif',
        folder: '../../img/folder.gif',
        folderOpen: '../../img/folderopen.gif',
        node: '../../img/page.gif',
        empty: '../../img/empty.gif',
        line: '../../img/line.gif',
        join: '../../img/join.gif',
        joinBottom: '../../img/joinbottom.gif',
        plus: '../../img/plus.gif',
        plusBottom: '../../img/plusbottom.gif',
        minus: '../../img/minus.gif',
        minusBottom: '../../img/minusbottom.gif',
        nlPlus: '../../img/nolines_plus.gif',
        nlMinus: '../../img/nolines_minus.gif'
    };
    this.obj = objName;
    this.aNodes = [];
    this.aIndent = [];
    this.root = new Node(-1);
    this.selectedNode = null;
    this.selectedFound = false;
    this.completed = false;
};
// Adds a new node to the node array
dTree.prototype.add = function(id, pid, name, url, title, target, icon, iconOpen, open) {
    this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, title, target, icon, iconOpen, open);
};
// Open/close all nodes
dTree.prototype.openAll = function() {
    this.oAll(true);
};
dTree.prototype.closeAll = function() {
    this.oAll(false);
};
// Outputs the tree to the page
dTree.prototype.toString = function() {
    var str = '<div class="dtree">\n';
    if (document.getElementById) {
        if (this.config.useCookies) this.selectedNode = this.getSelected();
        str += this.addNode(this.root);
    } else str += 'Browser not supported.';
    str += '</div>';
    if (!this.selectedFound) this.selectedNode = null;
    this.completed = true;
    return str;
};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
    var str = '';
    var n = 0;
    if (this.config.inOrder) n = pNode._ai;
    for (n; n < this.aNodes.length; n++) {
        if (this.aNodes[n].pid == pNode.id) {
            var cn = this.aNodes[n];
            cn._p = pNode;
            cn._ai = n;
            this.setCS(cn);
            if (!cn.target && this.config.target) cn.target = this.config.target;
            if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
            if (!this.config.folderLinks && cn._hc) cn.url = null;
            if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
                cn._is = true;
                this.selectedNode = n;
                this.selectedFound = true;
            }
            str += this.node(cn, n);
            if (cn._ls) break;
        }
    }
    return str;
};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
    var str = '<div class="dTreeNode">' + this.indent(node, nodeId);
    if (this.config.useIcons) {
        if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
        if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
        if (this.root.id == node.pid) {
            node.icon = this.icon.root;
            node.iconOpen = this.icon.root;
        }
        str += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />';
    }
    if (node.url) {
        str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"';
        if (node.title) str += ' title="' + node.title + '"';
        if (node.target) str += ' target="' + node.target + '"';
        if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ';
        if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
            str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"';
        str += '>';
    }
    else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
        str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">';
    str += node.name;
    if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>';
    //    alert("str : " + str);
    str += '</div>';
    if (node._hc) {
        str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">';
        str += this.addNode(node);
        str += '</div>';
    }
    this.aIndent.pop();
    return str;
};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
    var str = '';
    if (this.root.id != node.pid) {
        for (var n = 0; n < this.aIndent.length; n++)
            str += '<img src="' + ((this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty) + '" alt="" />';
        (node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
        if (node._hc) {
            str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '" src="';
            if (!this.config.useLines) str += (node._io) ? this.icon.nlMinus : this.icon.nlPlus;
            else str += ((node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus));
            str += '" alt="" /></a>';
        } else str += '<img src="' + ((this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join) : this.icon.empty) + '" alt="" />';
    }
    return str;
};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
    var lastId;
    for (var n = 0; n < this.aNodes.length; n++) {
        if (this.aNodes[n].pid == node.id) node._hc = true;
        if (this.aNodes[n].pid == node.pid) lastId = this.aNodes[n].id;
    }
    if (lastId == node.id) node._ls = true;
};
// Returns the selected node
dTree.prototype.getSelected = function() {
    var sn = this.getCookie('cs' + this.obj);
    return (sn) ? sn : null;
};
// Highlights the selected node
dTree.prototype.s = function(id) {
    if (!this.config.useSelection) return;
    var cn = this.aNodes[id];
    if (cn._hc && !this.config.folderLinks) return;
    if (this.selectedNode != id) {
        if (this.selectedNode || this.selectedNode == 0) {
            eOld = document.getElementById("s" + this.obj + this.selectedNode);
            eOld.className = "node";
        }
        eNew = document.getElementById("s" + this.obj + id);
        eNew.className = "nodeSel";
        this.selectedNode = id;
        if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id);
    }
};
// Toggle Open or close
dTree.prototype.o = function(id) {
    var cn = this.aNodes[id];
    this.nodeStatus(!cn._io, id, cn._ls);
    cn._io = !cn._io;
    if (this.config.closeSameLevel) this.closeLevel(cn);
    if (this.config.useCookies) this.updateCookie();
};
// Open or close all nodes
dTree.prototype.oAll = function(status) {
    for (var n = 0; n < this.aNodes.length; n++) {
        if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
            this.nodeStatus(status, n, this.aNodes[n]._ls)
            this.aNodes[n]._io = status;
        }
    }
    if (this.config.useCookies) this.updateCookie();
};
// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
    if (!bFirst) {
        for (var n = 0; n < this.aNodes.length; n++) {
            if (this.aNodes[n].id == nId) {
                nId = n;
                break;
            }
        }
    }
    var cn = this.aNodes[nId];
    if (cn.pid == this.root.id || !cn._p) return;
    cn._io = true;
    cn._is = bSelect;
    if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
    if (this.completed && bSelect) this.s(cn._ai);
    else if (bSelect) this._sn = cn._ai;
    this.openTo(cn._p._ai, false, true);
};
// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
    for (var n = 0; n < this.aNodes.length; n++) {
        if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
            this.nodeStatus(false, n, this.aNodes[n]._ls);
            this.aNodes[n]._io = false;
            this.closeAllChildren(this.aNodes[n]);
        }
    }
}
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
    for (var n = 0; n < this.aNodes.length; n++) {
        if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
            if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
            this.aNodes[n]._io = false;
            this.closeAllChildren(this.aNodes[n]);
        }
    }
}
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
    eDiv = document.getElementById('d' + this.obj + id);
    eJoin = document.getElementById('j' + this.obj + id);
    if (this.config.useIcons) {
        eIcon = document.getElementById('i' + this.obj + id);
        eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
    }
    eJoin.src = (this.config.useLines) ? ((status) ? ((bottom) ? this.icon.minusBottom : this.icon.minus) : ((bottom) ? this.icon.plusBottom : this.icon.plus)) : ((status) ? this.icon.nlMinus : this.icon.nlPlus);
    eDiv.style.display = (status) ? 'block' : 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
    var now = new Date();
    var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
    this.setCookie('co' + this.obj, 'cookieValue', yesterday);
    this.setCookie('cs' + this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
    document.cookie = escape(cookieName) + '=' + escape(cookieValue) + (expires ? '; expires=' + expires.toGMTString() : '') + (path ? '; path=' + path : '') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : '');
};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
    var cookieValue = '';
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1) {
        var posValue = posName + (escape(cookieName) + '=').length;
        var endPos = document.cookie.indexOf(';', posValue);
        if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
        else cookieValue = unescape(document.cookie.substring(posValue));
    }
    return (cookieValue);
};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
    var str = '';
    for (var n = 0; n < this.aNodes.length; n++) {
        if (this.aNodes[n]._io && this.aNodes[n].pid != this.root.id) {
            if (str) str += '.';
            str += this.aNodes[n].id;
        }
    }
    this.setCookie('co' + this.obj, str);
};
// [Cookie] Checks if a node id is in a cookie
dTree.prototype.isOpen = function(id) {
    var aOpen = this.getCookie('co' + this.obj).split('.');
    for (var n = 0; n < aOpen.length; n++)
        if (aOpen[n] == id) return true;
    return false;
};
// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
    Array.prototype.push = function array_push() {
        for (var i = 0; i < arguments.length; i++)
            this[this.length] = arguments[i];
        return this.length;
    }
};
if (!Array.prototype.pop) {
    Array.prototype.pop = function array_pop() {
        lastElement = this[this.length - 1];
        this.length = Math.max(this.length - 1, 0);
        return lastElement;
    }
};




var FlashHelper =
{
    movieIsLoaded: function(theMovie) {

        if (typeof (theMovie) != "undefined") return theMovie.PercentLoaded() == 100;
        else return
        false;
    },

    getMovie: function(movieName) {
        if (window.document[movieName]) {
            return window.document[movieName];
        }
        if (navigator.appName.indexOf("Microsoft Internet") == -1) {
            if (document.embeds && document.embeds[movieName])
                return document.embeds[movieName];
        }
        else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
        {
            return document.getElementById(movieName);
        }

    }
};
   
      function pause(millis)
      {
      var date = new Date();
      var curDate = null;
      do { curDate = new Date(); }
      while(curDate-date < millis)
      }
function telavatplayer(name) {
    this.obj = FlashHelper.getMovie(name);
    if (!FlashHelper.movieIsLoaded(this.obj)) return;

    this.play = function() {

    this.obj.TCallLabel('/', 'playToggle');
    };

    this.stop = function() {
        this.obj.TCallLabel('/', 'stop');
    };

    this.pause = function() {
        this.obj.TCallLabel('/', 'pause');
    };

    this.playToggle = function() {
        this.obj.TCallLabel('/', 'playToggle');
    };

    this.reset = function() {
        this.obj.TCallLabel('/', 'reset');
    };

    this.load = function(url) {
    this.obj.SetVariable('currentSong', url);
        this.obj.TCallLabel('/', 'load');
    };

    this.loadAndPlay = function(url) {
        this.load(url);
        this.play();
    };

    this.getState = function() {
        var ps = this.obj.GetVariable('playingState');
        var ls = this.obj.GetVariable('loadingState');

        if (ps == 'playing')
            if (ls == 'loaded') return ps;
        else return ls;

        if (ps == 'stopped')
            if (ls == 'empty') return ls;
        if (ls == 'error') return ls;
        else return ps;

        return ps;

    };

    this.getPlayingState = function() {
        return this.obj.GetVariable('playingState');
    };

    this.getLoadingState = function() {
        return this.obj.GetVariable('loadingState');
    };

    this.registerEvent = function(eventName, action) {
        this.obj.SetVariable(eventName, action);
    };

    return this;
}

