/************************************************************************************
*	XMl Response Handler Routines													*
*	Created by Sandeep at RSolutions-India, Bangalore								*
*	Client :  Advaithy																*	
*	created on 12-May-2010															*	
*																					*		
************************************************************************************/





function AjaxTimeOut()
{
	alert("Error Loading..... Timed Out");
}


function AjaxReqLoading(obj)
{
	id = obj.parameters.hidParam2;
	
	if (document.getElementById(id))
		document.getElementById(id).options[0].text = "Loading ....."; 
}


function AjaxError(XMLHttpRequestObject)
{	
	alert("Request unprocessed due to errors \n\nReason : " + XMLHttpRequestObject.statusText);
}


function useAjaxRequest(myAjaxParam)
{
  //alert(myAjaxParam.method);
  if(myAjaxParam.method == "Products_SelectCategoryXML")
  {
 
	  var myTempDataParam = new Object();
	   myTempDataParam = {'hidParam1':myAjaxParam.param1,'hidParam2':myAjaxParam.param2,'hidMethod':myAjaxParam.method,'hidParam3':myAjaxParam.param3,'hidParam4':myAjaxParam.param4,'hidParam5':myAjaxParam.param5};
	  
		AjaxRequest.post({
		  'url':myAjaxParam.urlPathname,
		  'onSuccess': Products_SelectCategoryJS,
		  'timeout':9999999,
		  'onLoading':AjaxReqLoading,
		  'onTimeout':AjaxTimeOut,
		  'onError': AjaxError,
		  'parameters':myTempDataParam
		});
  }
  else if(myAjaxParam.method == "ftSelectCategory")
  {
	  var myTempDataParam = new Object();
	  
	   myTempDataParam = {'hidParam1':myAjaxParam.param1,'hidParam2':myAjaxParam.param2,'hidMethod':myAjaxParam.method,'hidParam3':myAjaxParam.param3,'hidParam4':myAjaxParam.param4,'hidParam5':myAjaxParam.param5};
	  
		AjaxRequest.post({
		  'url':myAjaxParam.urlPathname,
		  'onSuccess': LoadCategories,
		  'timeout':9999999,
		  'onTimeout':AjaxTimeOut,
		  'onLoading':AjaxReqLoading,
		  'onError': AjaxError,
		  'parameters':myTempDataParam
		});
  }
  else if(myAjaxParam.method == "ftSelectTestTime")
  {
	  var myTempDataParam = new Object();
	  
	   myTempDataParam = {'hidParam1':myAjaxParam.param1,'hidParam2':myAjaxParam.param2,'hidMethod':myAjaxParam.method,'hidParam3':myAjaxParam.param3,'hidParam4':myAjaxParam.param4,'hidParam5':myAjaxParam.param5};
	  
		AjaxRequest.post({
		  'url':myAjaxParam.urlPathname,
		  'onSuccess': LoadTestTime,
		  'timeout':9999999,
		  'onTimeout':AjaxTimeOut,
		  'onLoading':AjaxReqLoading,
		  'onError': AjaxError,
		  'parameters':myTempDataParam
		});
  }
  
  
   
 
}


function Products_SelectCategoryJS(XMLHttpRequestObject)
{

	var oResponseXml = XMLHttpRequestObject.responseXML;
	var strParamChk = oResponseXml.getElementsByTagName("parametersMisMatch");
	var strRecExist = oResponseXml.getElementsByTagName("recordsExist");
	var rowId = XMLHttpRequestObject.parameters.hidParam2;
	var matchCode = XMLHttpRequestObject.parameters.hidParam1;
	var SelectList = document.getElementById(rowId);
	
	
	
	for (i=0;i<=SelectList.length;i++)
	{	
		SelectList.remove(SelectList);
		if (SelectList.length > 0 )
			i=0;
	}
	
	oOption = document.createElement("OPTION");
	SelectList.add(oOption);
	
	if (strParamChk[0].firstChild.nodeValue == "N")
	{
	
		if (strRecExist[0].firstChild.nodeValue == "Y")
		{
		
			var subTableRows = oResponseXml.getElementsByTagName("subTableRows");
			
			
			SelectList.options[0].text = "---Select---"
			SelectList.options[0].value = ""
			for (index=0;index < subTableRows.length; index++)
			{
			
				rowPtr = subTableRows[index];
			
				oOption = document.createElement("OPTION");
				SelectList.add(oOption);
				SelectList.options[index + 1].text = rowPtr.getElementsByTagName("Loc_City")[0].firstChild.nodeValue;
				SelectList.options[index + 1 ].value = rowPtr.getElementsByTagName("Loc_CityCode")[0].firstChild.nodeValue;
				
				if (matchCode == rowPtr.getElementsByTagName("Loc_CityCode")[0].firstChild.nodeValue)
					SelectList.options[index + 1].selected = true;
			}
		
		
		
		
		}
		else
		{
			SelectList.options[0].text = "City Not Found"
			SelectList.options[0].value = ""
		}
	}	
	else
	{
	
	SelectList.options[0].text = "---Select ---"
	SelectList.options[0].value = ""
	}

}


function LoadCategories(XMLHttpRequestObject)
{

	var oResponseXml = XMLHttpRequestObject.responseXML;
	var strParamChk = oResponseXml.getElementsByTagName("parametersMisMatch");
	var strRecExist = oResponseXml.getElementsByTagName("recordsExist");
	var rowId = XMLHttpRequestObject.parameters.hidParam2;
	var matchCode = XMLHttpRequestObject.parameters.hidParam1;
	var SelectList = document.getElementById(rowId);
	
	
	for (i=0;i<=SelectList.length;i++)
	{	
		SelectList.remove(SelectList);
		if (SelectList.length > 0 )
			i=0;
	}
	
	oOption = document.createElement("OPTION");
	SelectList.add(oOption);
	
	if (strParamChk[0].firstChild.nodeValue == "N")
	{
	
		if (strRecExist[0].firstChild.nodeValue == "Y")
		{
		
			var subTableRows = oResponseXml.getElementsByTagName("subTableRows");
			
			
			SelectList.options[0].text = "---Select---"
			SelectList.options[0].value = ""
			for (index=0;index < subTableRows.length; index++)
			{
			
				rowPtr = subTableRows[index];
			
				oOption = document.createElement("OPTION");
				SelectList.add(oOption);
				SelectList.options[index + 1].text = rowPtr.getElementsByTagName("Loc_Location")[0].firstChild.nodeValue;
				SelectList.options[index + 1 ].value = rowPtr.getElementsByTagName("Loc_Location")[0].firstChild.nodeValue;
				
				if (matchCode == rowPtr.getElementsByTagName("Loc_Location")[0].firstChild.nodeValue)
					SelectList.options[index + 1].selected = true;
			}
		
		
		
		}
		else
		{
			SelectList.options[0].text = "Location Not Found"
			SelectList.options[0].value = ""
		}
	}	
	else
	{
	
	SelectList.options[0].text = "Select"
	SelectList.options[0].value = ""
	
	
	
	}
	
	
}

function LoadTestTime(XMLHttpRequestObject)
{

	var oResponseXml = XMLHttpRequestObject.responseXML;
	var strParamChk = oResponseXml.getElementsByTagName("parametersMisMatch");
	var strRecExist = oResponseXml.getElementsByTagName("recordsExist");
	var rowId = XMLHttpRequestObject.parameters.hidParam2;
	var matchCode = XMLHttpRequestObject.parameters.hidParam1;
	var SelectList = document.getElementById(rowId);
	
	
	for (i=0;i<=SelectList.length;i++)
	{	
		SelectList.remove(SelectList);
		if (SelectList.length > 0 )
			i=0;
	}
	
	oOption = document.createElement("OPTION");
	SelectList.add(oOption);
	
	if (strParamChk[0].firstChild.nodeValue == "N")
	{
	
		if (strRecExist[0].firstChild.nodeValue == "Y")
		{
		
			var subTableRows = oResponseXml.getElementsByTagName("subTableRows");
			
			
			SelectList.options[0].text = "---Select---"
			SelectList.options[0].value = ""
			for (index=0;index < subTableRows.length; index++)
			{
			
				rowPtr = subTableRows[index];
			
				oOption = document.createElement("OPTION");
				SelectList.add(oOption);
				SelectList.options[index + 1].text = rowPtr.getElementsByTagName("TimeSchedule")[0].firstChild.nodeValue;
				SelectList.options[index + 1 ].value = rowPtr.getElementsByTagName("TimeSchedule")[0].firstChild.nodeValue;
				
			}
		
		
		
		}
		else
		{
			SelectList.options[0].text = "Time Slot Not Available"
			SelectList.options[0].value = ""
		}
	}	
	else
	{
	
	SelectList.options[0].text = "Select"
	SelectList.options[0].value = ""
	
	
	
	}
	
	
}
