/* 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 PopulateSubcategory(subid)
{
	//alert(subid)
	var request = createRequestObject();
	var today = new Date();

	
		request.open('GET', 'sales_action.asp?subid='+subid+'&act=1&temp='+today, true);
		
		
		request.onreadystatechange = function()
		{
		
		if(request.readyState == 4)
		{
			if(request.status == 200)
			{
				//alert(request.responseText);
				var xmlDoc=request.responseXML.documentElement;
				populateSelect('category',xmlDoc);

				//var response = request.responseText;
				//alert("re:"+response)
				//document.getElementById('sel_option2').innerHTML = response;				
				//var ctr2 = document.getElementById('sel_option1');
				//ctr2.style.display='none';
				//var ctr2 = document.getElementById('sel_option3');
				//ctr2.style.display='none';

			}
		}
	}
	request.send(null);
}
function PopulateProduct(subsubid)
{
	//alert(subsubid)
	var request = createRequestObject();
	var today = new Date();

	
		request.open('GET', 'sales_action.asp?subsubid='+subsubid+'&act=2&temp='+today, true);
		
		
		request.onreadystatechange = function()
		{
		
		if(request.readyState == 4)
		{
			if(request.status == 200)
			{
				var xmlDoc=request.responseXML.documentElement;
				//alert(request.responseText);
				populateSelect('product',xmlDoc);
				//var response = request.responseText;
				//alert("re:"+response)
				//document.getElementById('sel_option4').innerHTML = response;				
				//var ctr2 = document.getElementById('sel_option3');
				//ctr2.style.display='none';

			}
		}
	}
	request.send(null);
}




