

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

// updated 20011228 by Bob Clary <bc@bclary.com>
// to support Gecko

// warning: these have not been test, please email me a fix if there's any problems
var flag = 0;

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0) || (navigator.userAgent.indexOf('MSIE 6')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}

// automatically create the "is" object
is = new BrowserCheck()

// get the style object reference
function getObject(id,nestref) {
	//bc:if (is.ns) return (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
	if (is.ns4) return (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
	if (is.ie) return document.all[id].style
  //bc:
	if (is.ns5 || is.ie5) return document.getElementById(id).style
}

// get the element object reference
function getElement(id,nestref) {
	//bc:if (is.ns) return getObject(id,nestref)
	if (is.ns4) return getObject(id,nestref)
	if (is.ie) return document.all[id]
  //bc:
	if (is.ns5 || is.ie5) return document.getElementById(id)
}

// show and hide functions
function show(obj) {
	//bc:if (is.ns) obj.visibility = "show"
	if (is.ns4) obj.visibility = "show"
	//bc:else if (is.ie) obj.visibility = "visible"
	else if (is.ie||is.ns5) obj.visibility = "visible"
}
function hide(obj) {
	//bc:if (is.ns) obj.visibility = "hide"
	if (is.ns4) obj.visibility = "hide"
	//bc:else if (is.ie) obj.visibility = "hidden"
	else if (is.ie||is.ns5) obj.visibility = "hidden"
}

// movement functions
function getX(obj) {
	//bc:if (is.ns) return obj.css.left
	if (is.ns4) return obj.css.left
	//bc:else return obj.css.pixelLeft
	else if (is.ie) return obj.css.pixelLeft
	else if (is.ns5) return obj.css.offsetLeft
}
function getY(obj) {
	//bc:if (is.ns) return obj.css.top
	if (is.ns4) return obj.css.top
	//bc:else return obj.css.pixelTop
	else if (is.ie) return obj.css.pixelTop
	else if (is.ns5) return obj.css.offsetTop
}
function setX(obj,x) {
	//bc:if (is.ns) obj.css.left = x
	if (is.ns4) obj.css.left = x
	//bc:else obj.css.pixelLeft = x
	else obj.css.left = x
}
function setY(obj,y) {
	//bc:if (is.ns) obj.css.top = y
	if (is.ns4) obj.css.top = y
	//bc:else obj.css.pixelTop = y
	else obj.css.top = y
}
function moveTo(obj,x,y) {
	if (x!=null) setX(obj,x)
	if (y!=null)setY(obj,y)
}
function moveBy(obj,x,y) {
	setX(obj,getX(obj)+x)
	setY(obj,getY(obj)+y)
}

// layer write function
function layerWrite(elm,text) {  // use getElement()
	//bc:if (is.ns) {
	if (is.ns4) {
		elm.open()
		elm.write(text)
		elm.close()
	}
	else elm.innerHTML = text
}

// background color
function setbg(id,color) {
	obj=getObject(id);
	//bc:if (is.ns) obj.document.bgColor = color
	//if (is.ns4) obj.document.bgColor = color
	//else obj.backgroundColor = color
}
function searchmode()
{
	s=new String(document.location);
	t=s.split("#a");
	if (t.length>1)
	{
		obj=getObject("aya_"+t[1]);
		obj.color='#FF0000';
	}
}
function redcolor(id)
{
	if (playmode==0 && flag==0)
	{
		obj=getObject(id);
		obj.color='#0000FF';
		str=new String(id);
		tab=str.split("aya_");
		document.aya_form.select.selectedIndex=parseInt(tab[1])-1;
		document.aya_form.select.blur();
	}
}

function blackcolor(id )
{
	if (playmode==0 && flag==0)
	{
		obj=getObject(id);
		obj.color='#000000';
	}
}
function blackcolor2(id)
{
		obj=getObject(id);
		obj.color='#000000';
		flag=0;
}

function greencolor(id)
{
 		obj=getObject(id);
		obj.color='#00FF00';
		flag=1;
}
function jloadAya(id)
{
	str=new String(id);
	tab=str.split("aya_");
	if (ayaplayer==-1) document.quranplayer.setSura(sura);
	if( ayaplayer!=tab[1] && playmode==0)
	{	
		//greencolor(id);
		document.quranplayer.setNextAya(tab[1]);		
		ayaplayer=tab[1];
	}
}

function addZero(str)
{
 value = parseInt(str);
 if (value<10) return new String("00"+str);
 if (value<100) return new String("0"+str);
 if (value<1000) return new String(str);
}

function AutoPlay(id)
{
	if (playmode==0)
	{
		document.quranplayer.setSura(sura);
		document.quranplayer.setAuto('true');
		document.quranplayer.setNbAya(nbAya);
		playmode=1;
	}
	else 
	{
		document.quranplayer.setAuto('false');
		playmode=0
	}
}

    function RGBToHex(ColorString) {
    	HexDigits = "0123456789abcdef";
    if (ColorString.charAt(0) == '#') {
    	return ColorString;
    } 
    else {
     	ColorString = ColorString.substr(4);
     	pos = ColorString.indexOf(',');
     	Result = '#' + HexDigits.substr(Math.floor(ColorString.substr(0, pos) / 16), 1) + HexDigits.substr(ColorString.substr(0, pos) % 16, 1);
     	ColorString = ColorString.substr(pos + 1);
     	pos = ColorString.indexOf(',');
     	Result = Result + HexDigits.substr(Math.floor(ColorString.substr(0, pos) / 16), 1) + HexDigits.substr(ColorString.substr(0, pos) % 16, 1);
     	ColorString = ColorString.substr(pos + 1);
     	Result = Result + HexDigits.substr(Math.floor(ColorString.substr(0, pos) / 16), 1) + HexDigits.substr(ColorString.substr(0, pos) % 16, 1);
     	return Result;
    }
   }

function settitle(str)
{
	 parent.document.title = str+">>>demo version, if there an error plz mail to nobo728x@free.fr";
}
function to_sura(obj,lang)
{
	ind=obj.selectedIndex;
	id_sura=obj.options[ind].value;
	document.location="/index.php?lang="+lang+"&sura="+id_sura;
}

function to_aya(obj)
{
	ind=obj.selectedIndex;
	id_aya=obj.options[ind].value;
	str=new String(document.location);
	
	if (str.indexOf("#")==-1) loc=document.location;
	else {
		tab=str.split("#");
		loc=tab[0];
	}
	obj.blur();
	document.location=loc+"#a"+id_aya;
	
}

function to_lang(obj)
{
	ind=obj.selectedIndex;
	lang=obj.options[ind].value;
	document.location="index.php?lang="+lang;
	
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

var y1 = 20;   // change the # on the left to adjuct the Y co-ordinate
(document.getElementById) ? dom = true : dom = false;

function hideIt() {
  if (dom) {document.getElementById("layer1").style.visibility='hidden';}
  if (document.layers) {document.layers["layer1"].visibility='hide';} }

function showIt() {
  if (dom) {document.getElementById("layer1").style.visibility='visible';}
  if (document.layers) {document.layers["layer1"].visibility='show';} }

function placeIt() {
  if (dom && !document.all) {document.getElementById("layer1").style.top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))}
  if (document.layers) {document.layers["layer1"].top = window.pageYOffset + (window.innerHeight - (window.innerHeight-y1))}
  if (document.all) {document.all["layer1"].style.top = document.body.scrollTop + (document.body.clientHeight - (document.body.clientHeight-y1));}
  window.setTimeout("placeIt()", 10); }
