/* Making a request.*/
function createRequestObject()
{
/* Initialising the variable xmlhttp */
	var xmlhttp=false;
	
/* Try and catch block for creating xmlhttp object according to the browser */
	try
	{
	/* The xmlhttp object is built into the Microsoft XML Parser. */
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try 
		{
		/* The xmlhttp object is built into the Microsoft IE. */
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch (E) 
		{
			xmlhttp = false;
		}
	}
/* The xmlhttp object is built into the browsers other than Microsoft IE. */
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function clearSelect(OptionList)
{
	//OptionList = document.getElementById('sel1');
	for (x = OptionList.length; x >= 0; x--)
	{
		OptionList[x] = null;
	}
//	alert('cleared');
}
function populateSelect(selectBoxId,xmlDoc)
{
	OptionList = document.getElementById(selectBoxId);
	clearSelect(OptionList);

	var size = xmlDoc.getElementsByTagName('option').length;
	var name, value;
	for(i=0;i<size;i++)
	{
		name = xmlDoc.getElementsByTagName('name')[i].firstChild.data;
		value = xmlDoc.getElementsByTagName('value')[i].firstChild.data;
		OptionList[OptionList.length] = new Option(value, name);
	}
}

function popularRagaArtist(id,personid){
	//alert(id)
	var request = createRequestObject();
	var today = new Date();
	var a = personid.split("-");	
		if(id == "R"){
			request.open('GET', 'raga_artist.asp?id='+id+'&raga_name='+personid+'&temp='+today, true);
		}
		else if(id == "I"){
			request.open('GET', 'raga_artist.asp?id='+id+'&person_id='+a[0]+'&inst_id='+a[1]+'&temp='+today, true);
		}
		else {
			request.open('GET', 'raga_artist.asp?id='+id+'&person_id='+personid+'&temp='+today, true);
		}
		
	tableStructure = "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
    tableStructure = tableStructure + "<tr>";
    tableStructure = tableStructure + "<td align='left' valign='top' style='padding-left:4px;padding-bottom:10px;'>";
	tableStructure = tableStructure + "<img src='/Raga_online/ajax-loader1.gif' alt='' width='16' height='16'>&nbsp;<span style='color:red'>Loading....</span>";
	tableStructure = tableStructure + "</td>";
    tableStructure = tableStructure + "</tr>";
	tableStructure = tableStructure + "</table>";
		request.onreadystatechange = function()
		{
		document.getElementById('content').innerHTML = tableStructure;
		if(request.readyState == 4)
		{
			if(request.status == 200)
			{				
				var response = request.responseText;

				var ctr = document.getElementById('content');
				ctr.style.display='none';
				//alert(response)
				if(id=='A'){
					document.getElementById('RagaArtistAll').innerHTML = response;
					var RagaArtistAll = document.getElementById('RagaArtistAll');
					RagaArtistAll.style.display="inline";
				}
				else if(id=='V'){
					document.getElementById('RagaArtistVocal').innerHTML = response;
					var RagaArtistVocal = document.getElementById('RagaArtistVocal');
					RagaArtistVocal.style.display='inline';
				}
				else if(id=='R'){
					document.getElementById('RagaArtistRaga').innerHTML = response;
					var RagaArtistRaga = document.getElementById('RagaArtistRaga');
					RagaArtistRaga.style.display='inline';
				}
				else if(id=='I'){
					document.getElementById('RagaArtistInst').innerHTML = response;
					var RagaArtistInst = document.getElementById('RagaArtistInst');
					RagaArtistInst.style.display='inline';
				}
				var ctr2 = document.getElementById('defaultTable');
				ctr2.style.display='none';			
			}
		}
	}
	request.send(null);
}
function popularRaga(ragaid,rsperson,id){
	var request = createRequestObject();
	var today = new Date();
	
	request.open('GET', 'raga_artist.asp?raga_name='+ragaid+'&person_id='+rsperson+'&id='+id+'&temp='+today, true);						
		request.onreadystatechange = function()
		{
		
		if(request.readyState == 4)
		{
			if(request.status == 200)
			{				
				var response = request.responseText;				
				document.getElementById('RagaArtistRaga').innerHTML = response;
				var RagaArtistRaga = document.getElementById('RagaArtistRaga');
				RagaArtistRaga.style.display='inline';
				var ctr2 = document.getElementById('defaultTable');
				ctr2.style.display='none';
			}
		}
	}
	request.send(null);
}

function populateInstrument(inst_id)
{
	//alert(inst_id)
	var request = createRequestObject();
	var today = new Date();
	request.open('GET', 'raga_inst.asp?inst_id='+inst_id+'&temp='+today, true);		
	request.onreadystatechange = function()
	{
		if(request.readyState == 4)
		{
			if(request.status == 200)
			{				
				var xmlDoc=request.responseXML.documentElement;				
				populateSelect('personid',xmlDoc);				
			}
		}
	}
	request.send(null);
}





