function FrmValidation()
{
	if(document.frmTranslationRef.buttontype.value == 'SearchBook')
	{
		var theSel = document.frmTranslationRef.ChapterId;
		val = theSel.options[theSel.selectedIndex].value;
		if(val == "0")
		{
			alert("Please enter Chapter Name.");
			document.frmTranslationRef.ChapterId.focus();
			return false;
		}
		theSel = document.frmTranslationRef.TopicId;
		val = theSel.options[theSel.selectedIndex].value;
		if(val == "0")
		{
			alert("Please select topic.");
			return false;
		}
	}
	else if(document.frmTranslationRef.buttontype.value == 'SearchQuran')
	{
		theSel = document.frmTranslationRef.SurahId;
		val = theSel.options[theSel.selectedIndex].value;
		if(val == "0")
		{
			alert("Please enter Surah Name.");
			document.frmTranslationRef.SurahId.focus();
			return false;
		}
		
		theSel = document.frmTranslationRef.AyaatId;
		AyaatNos = "";
		for(i=0; i<theSel.length; i++)
	    {
	      if (theSel.options[i].selected == true) 
	      {
	      	if(AyaatNos == "")
	      		AyaatNos = theSel.options[i].text;
	      	else
	        	AyaatNos = AyaatNos + "," + theSel.options[i].text;	        
	      }
	    }
	    document.frmTranslationRef.AyaatNos.value = AyaatNos;
		/*theSel = document.frmTranslationRef.MuftiId;
		val = theSel.options[theSel.selectedIndex].value;
		if(val == "0")
		{
			alert("Please enter Mufti Name.");
			document.frmTranslationRef.MuftiId.focus();
			return false;
		}	
		if(document.frmTranslationRef.Translation.value == "")
		{
			alert("Translation does not exists.");
			return false;
		}*/
	}
	return true;
}
var combobox = "";
function LoadRecords(combo)
{
	combobox = combo;
	if(combobox == 'Topic')
	{
		var theSel = document.frmTranslationRef.ChapterId;
		if( theSel.options[theSel.selectedIndex].value == 0)
		{
			return;			
		}
		var url="LoadTopic.php" 
	}
	else if(combobox == 'Ayaat')
	{
		var theSel = document.frmTranslationRef.SurahId;
		var url="LoadAyaat.php"
	}
	else
	{
		var theSel = document.frmTranslationRef.SurahId;
		surah = theSel.options[theSel.selectedIndex].value;
		if(surah == "")
		{
			alert("Please select Surah.")
			return;
		}
		var theSel = document.frmTranslationRef.AyaatId;		
		ayaat = "";
		for(i=0; i<theSel.length; i++)
	    {
	      if (theSel.options[i].selected == true) 
	      {
	      	if(ayaat == "")
	      		ayaat = theSel.options[i].text;
	      	else
	        	ayaat = ayaat + "," + theSel.options[i].text;	        
	      }
	    }
	    //alert(ayaat);
	   if(ayaat == "")
		{
			alert("Please select Ayaat Number.")
			return;
		}
		var theSel = document.frmTranslationRef.MuftiId;		
		var url="LoadTranslation.php"
	}	
	//alert(theSel);
	str = theSel.options[theSel.selectedIndex].value;
	//alert(theSel.options[theSel.selectedIndex].value);
	RemoveOldValues();
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	if(combobox == 'LoadTranslation')
	{
		url=url+"?id="+str+"&SuraID="+surah+"&VerseID="+ayaat;
	}
	else
	{
		url=url+"?id="+str;	
	}
	
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.send(null);
}
//----------------------------------------------------------------------
function stateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var ArrValues = new Array();
		var arrcon = new Array(); 
		returnedValues = xmlHttp.responseText;
		if(returnedValues != "" && combobox != 'LoadTranslation')
		{
			//alert(returnedValues);
			ArrValues = returnedValues.split("\r\n");
			var i = 0;
			if(combobox != 'Ayaat')
				InsertNewValues("--------Select---------", 0);
			while(i < ArrValues.length)
			{					
				if(ArrValues[i] != "")
				{
					arrcon = ArrValues[i].split("|||");						
					InsertNewValues(arrcon[1], arrcon[0]);
				}
					
				i++;
			}		
		}
		else
		{
			document.frmTranslationRef.Translation.value = returnedValues;		
		}
		onUnload();
	}
}
//----------------------------------------------------------------------
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
//----------------------------------------------------------------------
function RemoveOldValues()
{
	if(combobox == 'Topic')
	{
		var theSel = document.frmTranslationRef.TopicId;
		for(i=theSel.length-1; i>=0; i--)
	    {      	
        	theSel.options[i] = null;
      	}
	}
	else if(combobox == 'Ayaat')
	{
		var theSel = document.frmTranslationRef.AyaatId;
		for(i=theSel.length-1; i>=0; i--)
	    {      	
        	theSel.options[i] = null;
      	}		
	}
	else if(combobox == 'LoadTranslation')
	{
		document.frmTranslationRef.Translation.value="";			
	}
}
//----------------------------------------------------------------------
var ios = 0;
var aos = 0;
function InsertNewValues(newText, newValue)
{	
	if(combobox == 'Topic')				
		var theSel = document.frmTranslationRef.TopicId;
	else if(combobox == 'Ayaat')
		var theSel = document.frmTranslationRef.AyaatId;
	else if(combobox == 'LoadTranslation')
	{
		//document.frmTranslationRef.Translation.value = newText;
		return;
	}
		
  	if (theSel.length == 0) 
  	{
	    var newOpt1 = new Option(newText, newValue);
	    theSel.options[0] = newOpt1;
	    theSel.selectedIndex = 0;
  	} 
  	else if (theSel.selectedIndex != -1) 
  	{
	    var selText = new Array();
	    var selValues = new Array();
	    var selIsSel = new Array();
	    var newCount = -1;
	    var newSelected = -1;
	    var i;
	    for(i=0; i<theSel.length; i++)
	    {
	      newCount++;
	      if (newCount == theSel.selectedIndex) 
	      {
	        selText[newCount] = newText;
	        selValues[newCount] = newValue;
	        selIsSel[newCount] = false;
	        newCount++;
	        newSelected = newCount;
	      }
	      selText[newCount] = theSel.options[i].text;
	      selValues[newCount] = theSel.options[i].value;
	      selIsSel[newCount] = theSel.options[i].selected;
	    }
	    
	    for(i=0; i<=newCount; i++)
	    {
	      var newOpt = new Option(selText[i], selValues[i]);
	      theSel.options[i] = newOpt;
	      theSel.options[i].selected = selIsSel[i];
	    }
  	}
}
//----------------------------------------------------------------------
function LoadTopics()
{
	LoadRecords("Topic");
}
//----------------------------------------------------------------------
function LoadAyaat()
{
	LoadRecords("Ayaat");
}

//----------------------------------------------------------------------
function LoadTranslation()
{	
	LoadRecords("LoadTranslation");
}
function LoadSelectedTopic()
{
	
}
function ButtonType(bType)
{	
	document.frmTranslationRef.buttontype.value = bType;
}
function SubmitRequest(Chid)
{	
	document.frmChapter.chapterID.value = Chid;
	document.getElementById("frmChapter").submit();
	//alert(document.frmChapter.chapterID.value);
	//document.frmChapter.submit();
}
