/***********************************************
* Cool DHTML tooltip script- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=3; //Customize x offset of tooltip
var offsetypoint=-55; //Customize y offset of tooltip
var ie=document.all;
var ns6=document.getElementById && !document.all;
var enabletip=false;
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : "";

function ietruebody()
{
	
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function overlib( stext )
{
	
	if(document.getElementById("showHoverTrans").checked)
	{
		return ddrivetip( stext );
	}
}
function overlibClick( stext )
{
	return ddrivetip( stext );
}

function ddrivetip(thetext, thecolor, thewidth){
	
		//alert(thetext)
		if (ns6||ie)
		{
			//if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px";
			//if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor;
			//tipobj.innerHTML=thetext;
			alert(document.getElementById('tipobj').innerHTML)
			 
			//enabletip=true;
			//return false;
		}
		
}

function positiontip(e){
	
if (enabletip){
var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left = ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px";
else if (curX<leftedge)
tipobj.style.left="5px";
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px";

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top = ie ? ietruebody().scrollTop + event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
else
tipobj.style.top=curY+offsetypoint+"px";
tipobj.style.visibility="visible";
}
}

function nd()
{
//	if(!document.getElementById("showHoverTrans").checked)
//	{

		return hideddrivetip();
//	}
	
}
function hideddrivetip(){
if (ns6||ie){
enabletip=false;
tipobj.style.visibility="hidden";
//tipobj.style.left="-1000px";
tipobj.style.left="";
tipobj.style.backgroundColor='';
tipobj.style.width='';
}
}

document.onmousemove=positiontip;
$(document).ready(function(){});

function getData(start,end)
{
	
	var StaticString = "<span style=';text-align:center'><img src='/images/ajax-loader.gif'> loading...</span>"
	$("#yavar").empty();
	$("#yavar").append(StaticString);
	
	$("#yavar1").empty();
	$("#yavar1").append(StaticString);
	
	$("#yavar2").empty();
	$("#yavar2").append(StaticString);
	
	$("#yavar4").empty();
	$("#yavar4").append(StaticString);
	
	$("#yavar5").empty();
	$("#yavar5").append(StaticString);
	
	$("#yavar6").empty();
	$("#yavar6").append(StaticString);
	
	$("#yavar7").empty();
	$("#yavar7").append(StaticString);
	
	$("#yavar8").empty();
	$("#yavar8").append(StaticString);

	$("#yavar9").empty();
	$("#yavar9").append(StaticString);

	$("#yavar10").empty();
	$("#yavar10").append(StaticString);

	$("#yavar11").empty();
	$("#yavar11").append(StaticString);

	var soreh=document.getElementById('suraMenu').selectedIndex+1 ;
	document.getElementById('mainFrame').style.display="inline";
	document.getElementById('searchFrame').style.display="none";
	var thisAye = document.getElementById('ayaMenu').selectedIndex+1;
	
	$.get("/quran/quran.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data){
	$("#yavar").empty();
	$("#yavar").append(data);
	});
	
	$.get("/quran/markazTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data1){
	$("#yavar1").empty();
	$("#yavar1").append(data1);
	});

	$.get("/quran/alameTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data2){
	$("#yavar2").empty();
	$("#yavar2").append(data2);
	});

	$.get("/quran/ansarianTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data4){
	$("#yavar4").empty();
	$("#yavar4").append(data4);
	});
	$.get("/quran/ayatiTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data5){
	$("#yavar5").empty();
	$("#yavar5").append(data5);
	});
	$.get("/quran/foladvandTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data6){
	$("#yavar6").empty();
	$("#yavar6").append(data6);
	});
	$.get("/quran/ghomsheiTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data7){
	$("#yavar7").empty();
	$("#yavar7").append(data7);
	});
	$.get("/quran/makaremTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data8){
	$("#yavar8").empty();
	$("#yavar8").append(data8);
	});
	
	$.get("/quran/ENTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data9){
	$("#yavar9").empty();
	$("#yavar9").append(data9);
	});

	$.get("/quran/DETranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data10){
	$("#yavar10").empty();
	$("#yavar10").append(data10);
	});
	$.get("/quran/FRTranslate.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data11){
	$("#yavar11").empty();
	$("#yavar11").append(data11);
	});

	
	document.getElementById('pageNumber').innerHTML = document.getElementById('pageNum').value*1;
	document.getElementById('pageNumber2').innerHTML = document.getElementById('pageNum').value*1;
	document.getElementById('juzName').innerHTML = getjuzName(document.getElementById('juzMenu').selectedIndex+1);
	document.getElementById('suraName').innerHTML = Quran.getSuraName(document.getElementById('suraMenu').selectedIndex+1);
			
}

function showQuran(start,end)
{
	start=1
	end=20
	var soreh=document.getElementById('suraMenu').selectedIndex+1 ;
	document.getElementById('mainFrame').style.display="inline";
	document.getElementById('searchFrame').style.display="none";
	var thisAye = document.getElementById('ayaMenu').selectedIndex+1;
		var StaticString = "<span style=';text-align:center'><img src='/images/ajax-loader.gif'> loading...</span>"
		$("#yavar").empty();
		$("#yavar").append(StaticString);
		
		$("#yavar1").empty();
		$("#yavar1").append(StaticString);
		
		$("#yavar2").empty();
		$("#yavar2").append(StaticString);
		
		$("#yavar4").empty();
		$("#yavar4").append(StaticString);
		
		$("#yavar5").empty();
		$("#yavar5").append(StaticString);
		
		$("#yavar6").empty();
		$("#yavar6").append(StaticString);
		
		$("#yavar7").empty();
		$("#yavar7").append(StaticString);
		
		$("#yavar8").empty();
		$("#yavar8").append(StaticString);
		
		$("#yavar9").empty();
		$("#yavar9").append(StaticString);

		$("#yavar10").empty();
		$("#yavar10").append(StaticString);

		$("#yavar11").empty();
		$("#yavar11").append(StaticString);
 
		$.get("/quran/quran.php",{ from: start , to: end ,selectedAyeh : thisAye ,selectedsoreh: soreh},function(data){
			$("#yavar").append(data);
			
			});
		
		document.getElementById('pageNumber').innerHTML = document.getElementById('pageNum').value*1;
		document.getElementById('pageNumber2').innerHTML = document.getElementById('pageNum').value*1;
		document.getElementById('juzName').innerHTML = getjuzName(document.getElementById('juzMenu').selectedIndex+1);
		document.getElementById('suraName').innerHTML = Quran.getSuraName(document.getElementById('suraMenu').selectedIndex+1);
		
}
function mainFaharesSearch(value ,thisOffset)
{
	
	temp=value.split(':');
	word = temp[1];
	searchListData(word , 1)
}

function searchListData(word ,thisOffset)
{
	
	var StaticString = "<span style=';text-align:center'><img src='/images/ajax-loader.gif'> loading...</span>"
	$("#searchDiv").empty();
	$("#searchDiv").append(StaticString);

	document.getElementById('searchLink').style.display="inline";
	Setare('searchLink')
	var thisLimit = 50;
	document.getElementById('searchTitle').innerHTML = word;
	document.getElementById('mainFrame').style.display="none";
	document.getElementById('searchFrame').style.display="inline";
	$.get("/quran/searchFaharesQuran.php",{ searchWord: word , limit:thisLimit , offset:thisOffset },function(data){
if(data)
{
	
	//alert(data)
	temp=data.split('@');
	document.getElementById('foundedCount').innerHTML = temp[2];
	document.getElementById('searchPageNumber').innerHTML = temp[1];
	document.getElementById('searchType').innerHTML = "fahares";
	//document.getElementById('searchWord').innerHTML = temp[3];
	setSearchBackNext(temp[2] , temp[1])
	
	allAyah = temp[0];
	d = allAyah.split("&&");
	result = new Array();

	for(i=0 ; i<(d.length)-1 ;i++)
	{
		f1 = d[i].split("%%");
		personObj = new Object();
		personObj.text=f1[0];
		
//		word=word.replace('ک','ك');
//		word=word.replace('ل','س');
//		alert(word)
//		break;
		personObj.places=f1[4];
		
		personObj.pattern=word;
		personObj.soreh=f1[2];
		personObj.ayeh=f1[3];
		result[i] = personObj;
	}
		
	resultData = composeSearchPaternPage(result , 1 );
	$("#searchDiv").empty();
	$("#searchDiv").append(resultData.innerHTML);
}else
{
	document.getElementById('searchLeft').style.display = "none";
	document.getElementById('searchRight').style.display = "none";
	$("#searchDiv").empty();
	$("#searchDiv").append("موردی یافت نشد ");
}
	
	});

}

function changeSearchPage(arrow)
{

	var word = document.getElementById('searchTitle').innerHTML ;
	var thisOffset = document.getElementById('searchPageNumber').innerHTML
	if(document.getElementById('searchType').innerHTML != "fahares")
	{
		if(arrow == 'right')
			searchData(word ,  parseInt(thisOffset)+1)
		if(arrow == 'left')
			searchData(word ,  parseInt(thisOffset)-1)
	}else
	{
		if(arrow == 'right')
			searchListData(word ,  parseInt(thisOffset)+1)
		if(arrow == 'left')
			searchListData(word ,  parseInt(thisOffset)-1)
		
	}	
	
}	

function searchData(word ,  thisOffset , cat , translateName)
{
//len = document.searchFrm.category.length
	if(cat == true)
		scat="quran"
	else
		scat="tanslate"
	
	var StaticString = "<span style=';text-align:center'><img src='/images/ajax-loader.gif'> loading...</span>"
	$("#searchDiv").empty();
	$("#searchDiv").append(StaticString);

	document.getElementById('searchLink').style.display="inline";
	Setare('searchLink');
	var thisLimit = 50;
	document.getElementById('searchTitle').innerHTML = word;
	document.getElementById('mainFrame').style.display="none";
	document.getElementById('searchFrame').style.display="inline";

	
	$.get("/quran/searchQuran.php",{ searchWord: word , limit:thisLimit , offset:thisOffset , category:scat , translate:translateName },function(data){
	temp=data.split('@');
	if(temp[2] != 0 )
	{
		document.getElementById('searchCountDive').style.display = "inline";
		document.getElementById('searchCountPage').style.display = "inline";
		data = temp[0];
		document.getElementById('foundedCount').innerHTML = temp[2];
		document.getElementById('searchPageNumber').innerHTML = temp[1];
		document.getElementById('searchType').innerHTML = "public";
		setSearchBackNext(temp[2] , temp[1])
		allAyah = temp[0];
		d = allAyah.split("&&");
		result = new Array();
		for(i=0 ; i<(d.length)-1 ;i++)
		{
			f1 = d[i].split("%%");
			personObj = new Object();
			personObj.text=f1[0];
	//		word=word.replace('ک','ك');
	//		word=word.replace('ی','ي');
	//		alert(word)
	//		break;
			personObj.pattern=word;
	
			personObj.soreh=f1[2];
			personObj.ayeh=f1[3];
			
			personObj.places=f1[4];
			result[i] = personObj;
	
		}
		
		resultData = composeSearchPaternPage(result , 1 ,cat);
		
		$("#searchDiv").empty();
		$("#searchDiv").append(resultData.innerHTML);
	}
	else
	{
		document.getElementById('searchCountDive').style.display = "none";
		document.getElementById('searchCountPage').style.display = "none";
		document.getElementById('searchLeft').style.display = "none";
		document.getElementById('searchRight').style.display = "none";
		$("#searchDiv").empty();
		$("#searchDiv").append("موردی یافت نشد ");
	}

	});
}


function setSearchBackNext(countAll,thisPage)
{
	var Dpage = countAll/50 ;
	if(thisPage > Dpage)
	{
		document.getElementById('searchRight').style.display="none";
	}else
	{
		document.getElementById('searchRight').style.display="inline";
	}
	if(thisPage < 2)
	{
		document.getElementById('searchLeft').style.display = "none";
	}else
	{
		document.getElementById('searchLeft').style.display = "inline";
	}
}

function switchBetSearchAndData(id)
{
	
	if(id == 1)
	{
		document.getElementById('mainFrame').style.display="inline";
		document.getElementById('searchFrame').style.display="none";
	}else
	{
		document.getElementById('mainFrame').style.display="none";
		document.getElementById('searchFrame').style.display="inline";
		
	}
	
}
function quranText()
{
//	document.getElementById('mainFrame').style.display="inline";
//	document.getElementById('mainTextDiv').style.display="none";
//	initPage({sura: 0, aya: 0, page:0, juz: 0})
	
}

function setAyehColor(id,from,to)
{
	//document.getElementById("aye"+id).style.background.color="red";
}
var startWidth = 0;
var startHeight = -200;
 

function ToolTipShow(tagId,start,end)
	{
	
		for(i=start ; i<=end ;i++)
		{
			if(document.getElementById("aye"+i))
			{
				document.getElementById("aye"+i).style.backgroundColor="white";
			}
			if(document.getElementById("markaz"+i))
			{
				document.getElementById("markaz"+i).style.backgroundColor="white";
			}
			if(document.getElementById("alame"+i))
			{
				document.getElementById("alame"+i).style.backgroundColor="white";
			}
		}
		
		document.getElementById("aye"+tagId).style.backgroundColor ="#F2D7B8";
		document.getElementById("markaz"+tagId).style.backgroundColor ="#F2D7B8";
		document.getElementById("alame"+tagId).style.backgroundColor ="#F2D7B8";
		scrollToAya(tagId,'aye');
		scrollToAya(tagId,'markaz');
		scrollToAya(tagId,'alame');
	
	}
function ToolTipShowOne(tagId)
	{
	
		document.getElementById("aye"+tagId).style.backgroundColor ="#F2D7B8";
		document.getElementById("markaz"+tagId).style.backgroundColor ="#F2D7B8";
		document.getElementById("alame"+tagId).style.backgroundColor ="#F2D7B8";
	}

function ToolTipHide(tagId)
	{
		//document.getElementById(tagId).style.display="none";
	}
function showThisAya(soreh , ayeh)
{
	
	document.getElementById('mainFrame').style.display="inline";
	document.getElementById('searchFrame').style.display="none";
	showAya(soreh , ayeh)
	
}
function getjuzName(id)
{
	var unary=Array('اول','دوم','سوم','چهارم','پنجم','ششم','هفتم','هشتم','نهم','دهم','یازدهم' ,'دوازدهم','سیزدهم','چهاردهم ','پانزدهم','شانزدهم','هفدهم','هجدهم','نوزدهم','بیستم ','بیست و یکم ','بیست و دوم ','بیست و سوم ','بیست و چهارم ','بیست و پنجم ','بیست و ششم ','بیست و هفتم ','بیست و هشتم ','بیست و نهم ','سی هم  ');
	return unary[id-1]; 
}
function Setare()
{
	
	document.getElementById('searchLink').style.visibility =        document.getElementById('searchLink').style.visibility == 'hidden'?'visible':'hidden';
    document.getElementById('searchLink').style.color =        document.getElementById('searchLink').style.color == 'black'?'red':'black';                
    setTimeout('Setare()', 500); //500 is the blink time in milisecodns                
}


