function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}
var browser = new Browser();

//Global Variables

var XmlHttp;
var XmlHttpCom;
function CreateXmlHttp()
	{
		try
		{
			XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(oc)
			{
				XmlHttp = null;
					
			}
		}
		if(!XmlHttp && typeof XMLHttpRequest != "undefined")
    {
        XmlHttp = new XMLHttpRequest();
    }
}
	
function CreateXmlHttpNew()
{
	try
	{
		XmlHttpCom = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttpCom = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttpCom = null;
				
		}
	}
	if(!XmlHttpCom && typeof XMLHttpRequest != "undefined")
    {
        XmlHttpCom = new XMLHttpRequest();
    }
}

	
	function SelectNewCat()
	{
		
		var fund = document.getElementById("_ctl0_drp_FundHouse");		
		var category = document.getElementById("_ctl0_drp_Category");
		var scheme = document.getElementById("_ctl0_drp_Scheme");
		scheme.length = 0;
		scheme.options[0] = new Option(); 
		scheme.options[0].value = "";
		scheme.options[0].text = "Select Scheme";	
		CreateXmlHttpNew();		
		document.body.style.cursor = "progress";
		
		var requestUrl = "MF_SchemeData.aspx?&Fund="+ encodeURIComponent(fund.value) +"&Category="+encodeURIComponent(category.value)+"&scheme="+encodeURIComponent(scheme.value);
		
		if(XmlHttpCom)	{
					XmlHttpCom.onreadystatechange = function(){getSchemeRespCat(category);};
					XmlHttpCom.open("GET", requestUrl,  true);
					XmlHttpCom.send(null);
				}
	}
	
	
	
function getSchemeRespCat(ig_)
{
	
	// To make sure receiving response data from server is completed
	if(XmlHttpCom.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttpCom.status == 200)
		{
			//alert(ig_)
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttpCom.responseText
			if(strData != "") {	
				var arrSchm = strData.split("|");
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Select Category";	
				for(i=1; i<arrSchm.length; i++) {	
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					ig_.options[i] = new Option();
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "No Categories available";			
			}
			document.body.style.cursor = "auto";
				
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}

	
	

function SelectMFScheme(ig_,ig_a,ig_b)
{

		var fund = document.getElementById("_ctl0_drp_FundHouse");	// for live change the controls id
		var category = document.getElementById("_ctl0_drp_Category");
		var scheme = document.getElementById("_ctl0_drp_Scheme");	
		
		
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "MF_SchemeData.aspx?Fund="+ encodeURIComponent(fund.value) +"&category="+encodeURIComponent(category.value);		
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getSchemeResp2(scheme)};
					XmlHttp.open("GET", requestUrl,  true);
					XmlHttp.send(null);
				}
}

//Called when response comes back from server Only For MF_SchemeData
function getSchemeResp2(ig_)
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttp.responseText
			if(strData != "") {	
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				for(i=0; i<arrSchm.length-1; i++) {	
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					ig_.options[i] = new Option();
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "Scheme is not available";			
			}
			document.body.style.cursor = "auto";	
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}	

function SelectCat(ig_,ig_a,ig_b)
	{
		var fund = document.getElementById("_ctl0_drp_FundHouse");
		var category = document.getElementById("_ctl0_drp_Category");
		CreateXmlHttp();
		document.body.style.cursor = "progress";
		var requestUrl = "MF_CategoryData.aspx?IpTrack="+ window.location.hostname +"&timeStamp="+ new Date().getTime() +"&Fund="+ fund.value;// +"&Category="+category.value;
		if(XmlHttp)	{
					XmlHttp.onreadystatechange = function(){getSchemeRespcat(category)};
					XmlHttp.open("GET", requestUrl, true);
					XmlHttp.send(null);
				}
	}
	
	function getSchemeRespcat(ig_)
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{
			//var availSchemes   = document.getElementById(ig_);
			var strData = XmlHttp.responseText
			if(strData != "") {	
				var arrSchm = strData.split("|");
				ig_.length = 0; 	
				for(i=0; i<arrSchm.length-1; i++) {	
					var strSchm = arrSchm[i];
					var arrSchmCode = strSchm.split("~");
					ig_.options[i] = new Option();
					ig_.options[i].value = arrSchmCode[0];
					ig_.options[i].text = arrSchmCode[1];
				}
			}
			else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "No Categories available";			
			}
			document.body.style.cursor = "auto";
				
		}
		else {
					ig_.length = 0;
					ig_.options[0] = new Option(); 
					ig_.options[0].value = "";
					ig_.options[0].text = "server is not ready";
					document.body.style.cursor = "auto";		
		}
	}
}	

