/*############# FOR AJAX FUNCTION ##################*/
function initXMLHTTPRequest() {
	var xmlHttp = null;
	try {
	    	// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
	       	// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			alert("assd");
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
/*############# AJAX CODE END ##################*/
function callCategory(serverPage, objID, objID2) 
{	
  	xmlHttp = initXMLHTTPRequest();
	document.getElementById(objID2).innerHTML = "";
	var objID1 = document.getElementById(objID);
	xmlHttp.open("GET", serverPage);
	xmlHttp.onreadystatechange = function() 
	{	
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
		{ 
			for(var i=objID1.length-1; i > 0; i--) 
			{ 
				//first of all removes any options if available
				objID1.remove(i);		
			}
			if(xmlHttp.responseText != -1)
			{
				var results = xmlHttp.responseText.split(",");	
				var j = 0;	
				for(var i=0; i < results.length; i++) 
				{		
					//adds new options as per the query
					var catInArray = results[i].split("~");		
					var optn = document.createElement("OPTION");
					optn.text  = catInArray[0];
					optn.value = catInArray[1];		
					j = i + 1;
					objID1.options.add(optn);
				}
			}
			else 
			{ 
	 			document.getElementById(objID2).innerHTML = "<font color='red' size='1'>There is no Category for this Department. Please Add a Category for this Department</font>"; 		
				//obj1.value = '';
				//obj2.value = '';
			}
		}
	}
xmlHttp.send(null);
}


function callBrand(serverPage, objID, objID2)
{
	xmlHttp = initXMLHTTPRequest();
	document.getElementById(objID2).innerHTML = "";
	var objID1 = document.getElementById(objID);
	xmlHttp.open("GET", serverPage);
	xmlHttp.onreadystatechange = function() 
	{
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
		{ 
			for(var i=objID1.length-1; i > 0; i--) 
			{ 
				// first of all removes any options if available
				objID1.remove(i);
			}
			if(xmlHttp.responseText != -1) 
			{
				var results = xmlHttp.responseText.split(",");	
				var j = 0;	
				for(var i=0; i < results.length; i++) 
				{		
					//adds new options as per the query
					var catInArray = results[i].split("~");		
					var optn = document.createElement("OPTION");
					optn.text  = catInArray[0];
					optn.value = catInArray[1];		
					j = i + 1;
					objID1.options.add(optn);
				}
			} 
			else 
			{ 
	 			document.getElementById(objID2).innerHTML = "<font color='red' size='1'>There is no Brand for this Department & Category.</font>"; 		
				//obj1.value = '';
				//obj2.value = '';
			}
		}
	}
xmlHttp.send(null);
}

function searchProduct()
{
	var deptId = document.getElementById("dept1");
	var group = document.getElementById("group1");
	if(deptId.value=="-1")
	{
		alert("Please select a Department.");
		return false;
	}
	if(group.value=="-1")
	{
		alert("Please select a Category.");
		return false;
	}

	document.form1.method="post";
	document.form1.action="handler.php";
	document.form1.submit();
}
