var XmlHttpObj;

// create an instance of XMLHTTPRequest Object, varies with browser type, try for IE first then Mozilla
function CreateXmlHttpObj()
{
	// try creating for IE (note: we don't know the user's browser type here, just attempting IE first.)
	try
	{
		XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpObj = null;
		}
	}
	// if unable to create using IE specific code then try creating for Mozilla (FireFox) 
	if(!XmlHttpObj && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttpObj = new XMLHttpRequest();
	}
}


function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}

/* objFillComboName -- name of the combo you want to fill  
   objFillingComboName -- name of the combo whose onChange event will fill (objFillComboName) combo.
   tblName - name of table from which data will be filled in (objFillComboName) Combo.
   pkFldName - name of the column which is used as value property for (objFillComboName) Combo.
   FldName - name of the column which is used as Text  for (objFillComboName) Combo.
   lnkFldName - name of the column which is used in where clause to fill (objFillComboName) Combo.
   objFirstItem -- First item which is displayed when (objFillComboName) Combo load on Page.
   objClearOtherCombo -- name of the combo which u want to clear when objFillingComboName's onChange event take place.
   
*/
function ComboOnChange(objFillComboName,objFillingComboName,tblName,pkFldName,FldName,lnkFldName,objFirstItem,objClearOtherCombo,ExtraItem,ExtraItemCaption,toggleVisibleControl,ExtraWhereClause)
{
	FillComboName =  objFillComboName;
	var ComboFillList = document.getElementById(objFillComboName);
	for (var count = ComboFillList.options.length-1; count >-1; count--)
	{
		ComboFillList.options[count] = null;
	}
	
	if(toggleVisibleControl === undefined || toggleVisibleControl == '')
	{
		
	}
	else
	{
		var toggleVisibilityControl =  document.getElementById(toggleVisibleControl);
		var dropdownIndex = document.getElementById(objFillingComboName).selectedIndex;
		var dropdownValue = document.getElementById(objFillingComboName)[dropdownIndex].value;
		if(dropdownValue == "-99" )
		{
			  toggleVisibilityControl.style.display = 'block';
		}
		else
		{
			  toggleVisibilityControl.style.display = 'none';
		}
	}
	
	if(objClearOtherCombo === undefined || objClearOtherCombo == '')
	{
		
	}
	else
	{
	   
	   if (objClearOtherCombo.indexOf("|") > 0)
		{
			var  clearOtherComboArray =  objClearOtherCombo.split("|");
			
			for(var i=0; i<clearOtherComboArray.length; i++)
			{
			
				var clearOtherCombo = document.getElementById(clearOtherComboArray[i]);
				for (var count = clearOtherCombo.options.length-1; count >-1; count--)
				{
					clearOtherCombo.options[count] = null;
				}
			}
		}
		else
		{
				
				var clearOtherCombo = document.getElementById(objClearOtherCombo);
				for (var count = clearOtherCombo.options.length-1; count >-1; count--)
				{
					clearOtherCombo.options[count] = null;
				}
		} 
		
		 
	}
	var optionItem;
	optionItem = new Option("Loading.....","tt",false,false);
	ComboFillList.options[0] = optionItem; 
	
	
	var FillingComboList = document.getElementById(objFillingComboName);
	var selectedCountry = FillingComboList.options[FillingComboList.selectedIndex].value; 
	var requestUrl;
	 requestUrl = "generalajax1.php" + "?cid=" + encodeURIComponent(selectedCountry) + "&tableName=" + tblName + "&ValueFieldName=" + pkFldName + "&DataFileName=" + FldName + "&LinkFieldName=" + lnkFldName + "&FirstItem=" + objFirstItem + "&ExtraItem=" + ExtraItem + "&ExtraItemCaption=" + ExtraItemCaption + "&ExtraWhere=" + ExtraWhereClause + "&filter=combo";
	 CreateXmlHttpObj();
	 if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);   
		 
	}   
	
}
function StateChangeHandler()
{
	
	// state ==4 indicates receiving response data from server is completed
	if(XmlHttpObj.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpObj.status == 200)
		{            
			PopulateStateList(XmlHttpObj.responseXML.documentElement);
		}
		else
		{
			alert("problem retrieving data from the server, status code: "  + XmlHttpObj.status);
		}
	}
   

}

function PopulateStateList(stateNode)
{    
	var stateList = document.getElementById(FillComboName);
	
	// clear items from list 
	for (var count = stateList.options.length-1; count >-1; count--)
	{
		stateList.options[count] = null;
	}

	var stateNodes = stateNode.getElementsByTagName('xmlResponse');
	var idValue;
	var textValue; 
	var optionItem;
	// populate the dropdown list with data from the xml doc
	
	
	for (var count = 0; count < stateNodes.length; count++)
	{
		textValue = GetInnerText(stateNodes[count]);
		idValue = stateNodes[count].getAttribute("id");
		optionItem = new Option( textValue, idValue,  false, false);
		stateList.options[stateList.length] = optionItem;
	}
}

function checkDocumentExist(objControlField,objFieldName,objTableName,objSNo,objWhere,objDiv,objErrorMsg)
{
	
	
   document.getElementById(objDiv).value = ""; 
   var objControlValue = document.getElementById(objControlField).value;
   var requestUrl;
	 requestUrl = "generalajax1.php" + "?CValue=" + objControlValue + "&FieldName=" + objFieldName + "&tableName=" + objTableName + "&VarSNo=" + objSNo + "&WhereConditon=" + objWhere + "&VarErrorMsg=" + objErrorMsg + "&filter=DocumentExist";
	 
	 CreateXmlHttpObj();
	 
	 if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
					
				}
				
			}
		 }
		 
		 
		 
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
		   
		
		 
	}
	
}

function CommissionStructureRange(objControlField,objDiv,objErrorMsg)
{
   document.getElementById(objDiv).value = ""; 
   var objControlValue = document.getElementById(objControlField).value;
   var requestUrl;
   requestUrl = "generalajax1.php" + "?CValue=" + objControlValue + "&FieldName=" + objFieldName + "&tableName=" + objTableName + "&VarSNo=" + objSNo + "&WhereConditon=" + objWhere + "&VarErrorMsg=" + objErrorMsg + "&filter=DocumentExist";
   CreateXmlHttpObj();
	 
	if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
					
				}
				
			}
		 }
		 
		 
		 
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
		   
		
		 
	}
	
} 
function checkCart(objCartSNo,objErrorDiv,objErrorMsg)
{
	
	document.getElementById(objErrorDiv).value = ""; 
   //var objControlValue = document.getElementById(objControlField).value;
   var requestUrl;
	 requestUrl = "generalajax1.php" + "?Cartsno=" + objCartSNo + "&VarErrorMsg=" + objErrorMsg + "&filter=CartEmpty";
	 
	 CreateXmlHttpObj();
	 
	 if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
					
				}
				
			}
		 }
		 
		 
		 
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
		   
		
		 
	} 
	
}
function ComboOnChangeOtherControl(objFillComboName,objControl,tblName,pkFldName,FldName,lnkFldName,objFirstItem,objClearOtherCombo,ExtraItem,ExtraItemCaption,toggleVisibleControl,objFtb)
{
	FillComboName =  objFillComboName;
	var ComboFillList = document.getElementById(objFillComboName);
	for (var count = ComboFillList.options.length-1; count >-1; count--)
	{
		ComboFillList.options[count] = null;
	}
	
	if(toggleVisibleControl === undefined || toggleVisibleControl == '')
	{
		
	}
	else
	{
		var toggleVisibilityControl =  document.getElementById(toggleVisibleControl);
		var dropdownIndex = document.getElementById(objFillingComboName).selectedIndex;
		var dropdownValue = document.getElementById(objFillingComboName)[dropdownIndex].value;
		if(dropdownValue == "-99" )
		{
			  toggleVisibilityControl.style.display = 'block';
		}
		else
		{
			  toggleVisibilityControl.style.display = 'none';
		}
	}
	
	if(objClearOtherCombo === undefined || objClearOtherCombo == '')
	{
		
	}
	else
	{
	   
	   if (objClearOtherCombo.indexOf("|") > 0)
		{
			var  clearOtherComboArray =  objClearOtherCombo.split("|");
			
			for(var i=0; i<clearOtherComboArray.length; i++)
			{
			
				var clearOtherCombo = document.getElementById(clearOtherComboArray[i]);
				for (var count = clearOtherCombo.options.length-1; count >-1; count--)
				{
					clearOtherCombo.options[count] = null;
				}
			}
		}
		else
		{
				
				var clearOtherCombo = document.getElementById(objClearOtherCombo);
				for (var count = clearOtherCombo.options.length-1; count >-1; count--)
				{
					clearOtherCombo.options[count] = null;
				}
		} 
		
		 
	}
	var optionItem;
	optionItem = new Option("Loading.....","tt",false,false);
	ComboFillList.options[0] = optionItem; 
	
	
	var FillingComboList = document.getElementById(objControl);
	var selectedCountry = FillingComboList.value; 
	var requestUrl;
	 requestUrl = "generalajax1.php" + "?cid=" + encodeURIComponent(selectedCountry) + "&tableName=" + tblName + "&ValueFieldName=" + pkFldName + "&DataFileName=" + FldName + "&LinkFieldName=" + lnkFldName + "&FirstItem=" + objFirstItem + "&ExtraItem=" + ExtraItem + "&ExtraItemCaption=" + ExtraItemCaption + "&filter=comboOtherControl&FTB="+objFtb;
	 CreateXmlHttpObj();
	 if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = StateChangeHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);   
		 
	}   
	
}

function GenerateCheckboxList(objValueField,objTextField,objTableName,objLinkedField,objLinkedcontrol,objCheckboxName,objWhereClause,objCheckboxDiv)
{
	
	divCheckBox = 	document.getElementById(objCheckboxDiv);  
	divCheckBox.innerHTML = "";
	var linkedControl = document.getElementById(objControl);
	var linkedControlValue = linkedControl.value;
	var requestUrl;
	requestUrl = "generalajax1.php" + "?cid=" + encodeURIComponent(linkedControlValue) + "&tableName=" + tblName + "&ValueFieldName=" + objValueField + "&DataFileName=" + objTextField + "&LinkFieldName=" + objLinkedField + "&filter=CheckBoxList&CheckBoxName=" + objCheckboxName + "&whereClause="+objWhereClause;
	CreateXmlHttpObj();
	if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		XmlHttpObj.onreadystatechange = checkboxHandler;
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  true);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);   
		 
	}   
	
}
function checkboxHandler()
{
if (XmlHttpObj.readyState==4)
	{
	document.getElementById("divCheckBox").innerHTML=XmlHttpObj.responseText;
	}
}

function checkKeywordInUse(objListingKeywordSNo,objTableName,objErrorMsg)
{
	
   
	 var requestUrl;
	 requestUrl = "generalajax1.php" + "?ListingKeywordSNo=" + objListingKeywordSNo + "&VarTableName="+ objTableName +"&VarErrorMsg=" + objErrorMsg + "&filter=CheckKeyword";
	 
	 CreateXmlHttpObj();
	 
	 if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
					
				}
				
			}
		 }
		 
		 
		 
		
		// define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
		   
		
		 
	} 
	
}

function UpdateOutLog()
{
	
	var requestUrl;	
	requestUrl = "generalajax1.php?filter=OutLogTime";
	CreateXmlHttpObj();
	if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
				}
			}
		 }
		 // define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
	}
	
}


function AddToCart(lvarSNo,lvarFTB,lvarClientSNo,lvarFranchiseSNo)
{
	var requestUrl;	
	requestUrl = "generalajax1.php?filter=AddToCart&SNo=" + lvarSNo + "&FTB=" + lvarFTB + "&ClientSNo=" + lvarClientSNo + "&FranchiseSNo=" +lvarFranchiseSNo;
	CreateXmlHttpObj();
	if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
				}
			}
		 }
		 // define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
	}
}
function ajaxSaveRights(lvarRightsString,lvarUserSNo)
{
	var requestUrl;	
	requestUrl = "generalajax1.php?filter=SaveRights&RightString=" + lvarRightsString + "&UserSNo=" + lvarUserSNo;
	CreateXmlHttpObj();
	if(XmlHttpObj)
	{
		// assign the StateChangeHandler function ( defined below in this file)
		// to be called when the state of the XmlHttpObj changes
		// receiving data back from the server is one such change
		 XmlHttpObj.onreadystatechange =  function()
		 {
			 if(XmlHttpObj.readyState == 4)
			{
				// To make sure valid response is received from the server, 200 means response received is OK
				if(XmlHttpObj.status == 200)
				{   
				  
					//document.getElementById(objDiv).innerHTML=XmlHttpObj.responseText;
				}
			}
		 }
		 // define the iteraction with the server -- true for as asynchronous.
		XmlHttpObj.open("GET", requestUrl,  false);
		// send request to server, null arg  when using "GET"
		XmlHttpObj.send(null);
		return XmlHttpObj.responseText;
	}
}

