/**
Purpose:The purpose of the function is to solve the problem of creating different XMLHTTP objects for different browsers. 
**/
function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}

var xmlHttp;
function show(str,flag)
{ 
		var url;
		//alert(flag);
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)
		{
			alert ("Browser does not support HTTP Request")
			return
		}
		url="../calc/showData.php";
		/*function IsEmpty(aTextField) 
		{
			if ((aTextField.length==0) ||  (aTextField==null) || aTextField=="") 
			{
				return true;
			}
			else { return false; }
		}*/

		if(flag=="show_scheme")
		{
			/*var option=document.sip_calc.scheme_option.value;
			if(IsEmpty(option))
			{
				alert("Please Select Scheme Option");
				document.sip_calc.mf.value="";
				return false;
			}
			url=url+"?fund_code="+str+"&scheme_option="+option+"&flag="+flag;*/
			url=url+"?fund_code="+str+"&flag="+flag;
			//alert(url);
			xmlHttp.onreadystatechange=showScheme 
		}
		
		if(flag=="show_date")
		{
			var scheme=document.sip_calc.scheme.value;
			//alert(option+'>>> SCHEME >> '+ scheme);
			url=url+"?scheme_code="+scheme+"&flag="+flag;
			//alert(url);
			xmlHttp.onreadystatechange=showDateDropDown
		}

		if(flag=="show_result")
		{
			//alert(flag);
			//var option=document.sip_calc.scheme_option.value;
			var mf=document.sip_calc.mf.value;
			var amount=document.sip_calc.amt.value;
			var scheme=document.sip_calc.scheme.value;	
				if(IsEmpty(mf))
				{
					alert("Please Select Mutual Fund");
					return false;
				}
				
				if(IsEmpty(scheme))
				{
					alert("Please Select Scheme ");
					return false;
				}
				
				
			
			if(scheme!='')
			{
				var start_day=document.sip_calc.from_day.value;
				var start_month=document.sip_calc.from_month.value;
				var start_year=document.sip_calc.from_year.value;
				var end_month=document.sip_calc.to_month.value;
				var end_year=document.sip_calc.to_year.value;

				if(IsEmpty(start_day))
				{
					alert('Please Select Start Day');
					return false;
				}
				if(IsEmpty(start_month))
				{
					alert('Please Select Start Month');
					return false;
				}
				if(IsEmpty(start_year))
				{
					alert('Please Select Start Year');
					return false;
				}
				if(IsEmpty(end_month))
				{
					alert('Please Select End Month');
					return false;
				}
				if(IsEmpty(end_year))
				{
					alert('Please Select End Year');
					return false;
				}
			}
			
			if(IsEmpty(amount))
				{
					alert('Please Enter Invested Amount Per Month');
					return false;
				}
				var sdate=start_day+'-'+start_month+'-'+start_year;
				var edate=start_day+'-'+end_month+'-'+end_year;
			

			//alert('sm >>'+start_month+'em >>'+end_month+'end_year >>'+ end_year+'start_year >>'+start_year);
			//alert('>>>'+scheme);
			if(end_year < start_year)
			{
				alert("Start Year Should Be Less Than End Year");
				return false;
			}
			if(end_year == start_year)
			{
				if(end_month < start_month)
				{
					alert("Start Month Should Be Less Than End Month");
					return false;
				}
			}
			if(end_year>=start_year)
			{
				var year=end_year-start_year;
				var month=end_month - start_month + 1;
				//alert(month);
				var mon=year*12;
				var tot_month=mon + (month);
				//alert("Year >>"+year+"  month >>"+month+ 'total_month >>'+tot_month );
				var tot_invest_amt=tot_month*amount;
				//alert('tot_invest_amt >>>'+tot_invest_amt)
			}
			url=url+"?tot_month="+tot_month+"&invest_amt="+amount+"&flag="+flag+"&tot_invest_amt="+tot_invest_amt+"&start_date="+sdate+"&end_date="+edate+"&scheme="+scheme;
			//alert(url);
			xmlHttp.onreadystatechange=showResult
	}
	

	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

	
/**
The stateChanged() function executes every time the state of the XMLHTTP object changes.When the state changes to 4 (or to "complete"), the content of the txt placeholder is filled with the response text.  
**/
	function showScheme() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById("scheme").innerHTML=xmlHttp.responseText 
		}	 
	}
	
	function showResult() 
	{ 
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById("sip_result").innerHTML=xmlHttp.responseText 
		}	 
	} 

	function showDateDropDown()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{ 
			document.getElementById("date_r").innerHTML=xmlHttp.responseText 
		}	 
	}

function resetor()
{
	//document.sip_calc.mf.value="";
}




