function ShowHomeNFO()
{
	var HomeNFOUrl = "../MutualFund/HomeNFO.aspx";	
	var ajax = new Ajax.Updater('HomeNFO',HomeNFOUrl); 
}
function ShowHomeMFNews()
{
	var HomeNewsUrl = "../MutualFund/HomeNews.aspx";	
	var ajax = new Ajax.Updater('HomeMFNews',HomeNewsUrl); 
}
/*MFHome Category Returns*/
function CatRetHome(category,period)
{	
	var id;
 	if(category=="")
	{
		if(navigator.userAgent.indexOf("MSIE")!=-1)
		{			
			if(document.getElementById("TDM1").className=="NewsMenuSel TabBorder_TBL")
				category="EQUITY";
			else if(document.getElementById("TDM2").className=="NewsMenuSel TabBorder_TBL")
				category="DEBT";
			else if(document.getElementById("TDM3").className=="NewsMenuSel TabBorder_TBL")
				category="HYBRID";
			else
				category="EQUITY";
		}
		else
		{
			if(document.getElementById("TDM1").className=="NewsMenuSel TabBorder_TBL")
				category="EQUITY";
			else if(document.getElementById("TDM2").className=="NewsMenuSel TabBorder_TBL")
				category="DEBT";
			else if(document.getElementById("TDM3").className=="NewsMenuSel TabBorder_TBL")
				category="DEBT";
			else
				category="EQUITY";			
		}
	}
 	
 	if(category=="EQUITY")
		id="1";
	else if(category=="DEBT")
		id="2";
	else if(category=="HYBRID")
		id="3";
	
	if(navigator.userAgent.indexOf("MSIE")!=-1)
	{
		for(var j=1;j<=3;j++)
		{
			document.getElementById("TDM"+j).className="NewsMenuUnSel TabBorder";				
			document.getElementById("TDM"+j).style.cursor="pointer";
		}
		document.getElementById("TDM"+id).className="NewsMenuSel TabBorder_TBL";				
		document.getElementById("TDM"+id).style.cursor="default";		 
	}
	else
	{
		for(var j=1;j<=3;j++)
		{
			document.getElementById("TDM"+j).className="NewsMenuUnSel TabBorder";				
			document.getElementById("TDM"+j).style.cursor="pointer";	
		}
		document.getElementById("TDM"+id).className="NewsMenuSel TabBorder_TBL";				
		document.getElementById("TDM"+id).style.cursor="default";		 	
	}	
	
 	if(period=="")
	period=document.getElementById("catPeriod").value;		

	var CatRetUrl = "../MutualFund/HomeCatRet.aspx?category="+category+"&period="+period;
	document.getElementById("CategoryData").innerHTML="<table cellpadding='0' cellspacing='0' width='100%'><tr><td align='center'><img src='../images/loading1.gif'></td></tr></table>";
	var ajax = new Ajax.Updater('CategoryData',CatRetUrl);					
}

var XmlHttp,XmlHttp1;

//Creating object of XMLHTTP For AJAX Method
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;	
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
	return XmlHttp;
}

function showSnapChart(code,period)
{	
	
	var period;
	var periodVal = period.substr(0,1);
	var period = period.substr(1,1)
	document.getElementById("SnapChart").src= "mfchart.aspx?schcode="+ code +"&Period="+ period +"&PeriodVal="+periodVal;
}
function showAssetChart(code,opt)
{
	var opt;
	document.getElementById("AssetChart").src= "AssetChart.aspx?schcode="+ code +"&opt="+opt;
}
/* For SIP Calculator*/
var arrMININVT = new Array();
var arrMF_SCHCODE = new Array();
var SchTypeCode="";

//For Loading schemes from SipCalcSchData.aspx Using AJAX
function loadSipScheme(mf_code)
{	
	CreateXmlHttp();	
	document.body.style.cursor = "progress";
	if(mf_code=='')return false;
	var requestUrl = "SipCalcSchData.aspx?MF_Code="+ mf_code;	
	if(XmlHttp)	{
				XmlHttp.onreadystatechange = function(){sipSchResp()}
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
			}
}

//Called when response comes back from server Only For sip schemes
function sipSchResp()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{			
			var DrpScheme   = document.getElementById("SipCalcFrm_DrpScheme");
			var strData = XmlHttp.responseText			
			if(strData != "")
			{	
				if(strData!="NA") {
					var arrSchm = strData.split("|");
					
					var arrSCH_NAME   = eval(arrSchm[1]);
					arrMF_SCHCODE = eval(arrSchm[0]);
					arrMININVT    = eval(arrSchm[2]);

						DrpScheme.length = 0;
						DrpScheme.options[0] = new Option();
						DrpScheme.options[0].value = "";
						DrpScheme.options[0].text  = "Select Scheme..";						
						for(i=1; i<=arrMF_SCHCODE.length; i++) {	
							DrpScheme.options[i] = new Option();
							DrpScheme.options[i].value = arrMF_SCHCODE[i-1];
							DrpScheme.options[i].text  = arrSCH_NAME[i-1].replace(/#/g,"'");
						}
				}
				else
					fillSchDef("Scheme is not available");
			}
			else
				fillSchDef("Scheme is not available");
				document.body.style.cursor = "auto";
		}
		else
		{
			fillSchDef("server is not ready");
			document.body.style.cursor = "auto";
		}
	}
}	

function fillSchDef(txt){
	var DrpScheme   = document.getElementById("SipCalcFrm_DrpScheme");
	//alert(txt);
	DrpScheme.length = 0;
	DrpScheme.options[0] = new Option(); 
	DrpScheme.options[0].value = "";
	DrpScheme.options[0].text = txt;	
}


function MinSipAmt(schCode){
	document.body.style.cursor = "progress";
	var inv_Amnt  = document.getElementById("TxtInvstAmt");
	CreateXmlHttp();	
	var requestUrl = "SipStDtData.aspx?schCode="+ schCode;	
	if(XmlHttp)	{
				XmlHttp.onreadystatechange = function(){sipDtResp()}
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
			}
}

//Called when response comes back from server Only For sip Start Date
function sipDtResp()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{	
			var strData = XmlHttp.responseText
			if(strData != "")
			{	
				var stDy = document.getElementById("SipCalcFrm_drpStDay");
				var stMn = document.getElementById("SipCalcFrm_drpStMn");
				var stYr = document.getElementById("SipCalcFrm_drpStYr");
				
				var arrStr = strData.split("|");
				var arrDate = arrStr[0].split("-");
					for(i=0; i<stDy.length; i++)
						if(stDy.options[i].value==arrDate[0])stDy.options[i].selected = true;
					for(i=0; i<stMn.length; i++)
						if(stMn.options[i].value==arrDate[1])stMn.options[i].selected = true;
					for(i=0; i<stYr.length; i++){
						if(stYr.options[i].value==arrDate[2])stYr.options[i].selected = true;										
				}					
				SchTypeCode = arrStr[1];		
				selDy = stDy.options[stDy.selectedIndex].value;
				selMn = stMn.options[stMn.selectedIndex].value;
				selYr = stYr.options[stYr.selectedIndex].value;		
				
			}
		}
	}
	document.body.style.cursor = "auto";
}	
	
function SIP_Data()
{   	
	//var tdate = new Date();	
	//var today=(tdate.getMonth()+1) +"/"+ tdate.getDate() +"/"+ tdate.getFullYear();
	var tdate = new Date();
	var tday = tdate.getDate();
	var tmon = tdate.getMonth()+1;
	
	if(String(tday).length == 1)
	{
		tday = "0" + tday;
	}
	if(String(tmon).length == 1)
	{
		tmon = "0" + tmon;
	}
	//var today=(tdate.getMonth()+1) +"/"+ tdate.getDate() +"/"+ tdate.getFullYear();
	var today=(tmon) +"/"+ tday +"/"+ tdate.getFullYear();
	
	var SIPCALC    = document.getElementById("SIPCALC");
	SIPCALC.style.display='none';
	var sch_Code  = document.getElementById("SipCalcFrm_DrpScheme");
	var inv_Amnt  = document.getElementById("SipCalcFrm_TxtInvstAmt");
	
	var stday     = document.getElementById("SipCalcFrm_drpStDay");
    var drpStmonth= document.getElementById("SipCalcFrm_drpStMn");
    var drpStyear = document.getElementById("SipCalcFrm_drpStYr");
    
	var edday     = document.getElementById("SipCalcFrm_drpEdDay");    
	var drpEnmonth= document.getElementById("SipCalcFrm_drpEdMn");
	var drpEnyear = document.getElementById("SipCalcFrm_drpEdYr");
	
	var DrpAMC = document.getElementById("SipCalcFrm_DrpAMC");
	
	if(DrpAMC.value == "")
	{
		alert("Select a Fund")
		DrpAMC.focus();		
		return false;
	}
	
	if(sch_Code.value==""){
		alert("Select any Scheme");
		sch_Code.focus();
		return false;
	}
	
	if(drpStyear.value=="" || drpEnyear.value=="" || drpStmonth.value=="" || drpEnmonth.value=="")
	    {
			alert("End Date should be Greater than Start Date") 	
			return false; 
	    }
	else if(drpStyear.value==drpEnyear.value)
		{
			if (eval(drpStmonth.value)>= eval(drpEnmonth.value))
			{		
				if(eval(stday.value) > eval(edday.value))
				{
					alert("Start Date should not be Greater than End Date") 	
					stday.focus()
					return false; 
				}
				/*else if(eval(stday.value)<= eval(edday.value))
				{
					var st_Date1 = stday.value +"/"+ drpStmonth.value +"/"+ drpStyear.value;
					var ed_Date1 = edday.value +"/"+ drpEnmonth.value +"/"+ drpEnyear.value;
					var one_day=1000*60*60*24; //total time for one day(86400000)
					
					var x=st_Date1.split("/");
					var y=ed_Date1.split("/");
					//Date format fullyear,month,date
					var date1=new Date(x[2],(x[1]),x[0]);  
					var date2=new Date(y[2],(y[1]),y[0])
										
					//for calculating diff bet 2 dates, and convert to days
					_Diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
					if((_Diff+1)<30)
					{
						alert("Please select valid date");
						stday.focus()
						return false; 
					}					
				}*/
			}
		}			
	else if(drpStyear.value > drpEnyear.value)
		{
			alert("End Date should be Greater than Start Date") 	
			drpStyear.focus()
			return false; 
		}
	if(drpStmonth.value==02)
	{
		if(drpStyear.value%4==0)
		{
			if(stday.value>29)
			{
				alert("Day can't be greater than 29");
				stday.focus();
				return false;
			}
		}
		else
		{
			if(stday.value>28)
			{
				alert("Day can't be greater than 28");
				stday.focus();
				return false;
			}
		}
	}
	/*else if(drpStyear.value%4==0 && drpStmonth.value==02 && stday.value>29)  
		{
			alert("Day can't be greater than 29");
			stday.focus();
			return false;
		}
	else if(drpStmonth.value==02 && stday.value>28)  
		{
			alert("Day can't be greater than 28");
			stday.focus();
			return false;
		}*/
	else if((drpStmonth.value==04 || drpStmonth.value==06 || drpStmonth.value==09 || drpStmonth.value==11) && stday.value>30)  
		{
			alert("Day can't be greater than 30");
			stday.focus();
			return false;
		}
	else if(drpEnyear.value%4==0 && drpEnmonth.value==02 && edday.value>29)  
		{
			
			alert("Day can't be greater than 29");
			edday.focus();
			return false;
		}
	else if(drpEnmonth.value==02 && edday.value>28)  
		{
			alert("Day can't be greater than 28");
			edday.focus();
			return false;
		}
	else if((drpEnmonth.value==04 || drpEnmonth.value==06 || drpEnmonth.value==09 || drpEnmonth.value==11) && edday.value>30)  
		{
			alert("Day can't be greater than 30");
			edday.focus();
			return false;
		}
		
		if(inv_Amnt.value == "")
		{
			alert("Enter Investment amount");
			inv_Amnt.focus();
			return false;
		}
	var SelAMC = DrpAMC.options[DrpAMC.selectedIndex].innerText || DrpAMC.options[DrpAMC.selectedIndex].textContent;
		
	if (SelAMC.indexOf("Reliance")> -1)
	{
		if (inv_Amnt.value < 100)
		{
			alert("Investment amount must be greater than 100")
			inv_Amnt.focus();
			return false;
		}
	}
	else
	{
		if (inv_Amnt.value < 500)
		{
			alert("Investment amount must be greater than or equal to 500")
			inv_Amnt.focus();
			return false;
		}
	}
	
	if(selYr == drpStyear.value && selMn == drpStmonth.value && stday.value < selDy)
	{
		alert("Start date can not be less than SIP start date.");
		stday.value = selDy;
		return false;
	}
	if(selYr == drpStyear.value && selMn > drpStmonth.value)
	{
		alert("Start date can not be less than SIP start date.");
		drpStmonth.value = selMn;
		return false;
	}
	if(selYr > drpStyear.value)
	{
		alert("Start date can not be less than SIP start date.");
		drpStyear.value = selYr;
		return false;
	}
	
	st_Date = drpStmonth.value +"/"+ stday.value +"/"+ drpStyear.value;
	ed_Date = drpEnmonth.value +"/"+ edday.value +"/"+ drpEnyear.value;
	
	if(ed_Date>today)
	{
		alert("End date should not be greater than current date");
		edday.focus();
		return false;
	}

	if(SchTypeCode==""){
		alert("This Scheme is not matching with our data..  Kindly Select another Scheme..!");
		sch_Code.focus();
		return false;
	}
	//for float value
	
	var invamtcast= new String();
	var invamtcast1= new String();
	var invamtcast2=new String();
	invamtcast=document.getElementById("SipCalcFrm_TxtInvstAmt").value;
	invamtcast1=invamtcast.substring(0,invamtcast.indexOf("."));
	
	if(invamtcast1!="")
	{
		if(invamtcast!=invamtcast1)
		{		
			alert("Please enter valid investment amount");	
			inv_Amnt.focus();
			return false;
			
		}
		else
			return true;
	}
	invamtcast2=invamtcast.substring(0,9);
	if(invamtcast.length>"9")
	{
		alert("Investment amount is not greater than " +invamtcast2);
		return false;
	}
	//end
	var SchmPlan = document.getElementById("SchmPlan");
	var InvAmount= document.getElementById("InvAmount");
	var InvPeriod= document.getElementById("InvPeriod");
	var SchemeName = document.getElementById("SchemeName");
	
	SchmPlan.innerHTML = sch_Code.options[sch_Code.selectedIndex].text;
	SchmPlan.textContent = sch_Code.options[sch_Code.selectedIndex].text;
	SchemeName.innerText = sch_Code.options[sch_Code.selectedIndex].text;
	SchemeName.textContent = sch_Code.options[sch_Code.selectedIndex].text;
	InvAmount.innerHTML = inv_Amnt.value;
	InvAmount.textContent = inv_Amnt.value;
	InvPeriod.innerHTML = stday.value +"-"+ drpStmonth.options[drpStmonth.selectedIndex].text +"-"+ drpStyear.value +" To  "+ edday.value +"-"+ drpEnmonth.options[drpEnmonth.selectedIndex].text +"-"+ drpEnyear.value;
	InvPeriod.textContent = stday.value +"-"+ drpStmonth.options[drpStmonth.selectedIndex].text +"-"+ drpStyear.value +" To  "+ edday.value +"-"+ drpEnmonth.options[drpEnmonth.selectedIndex].text +"-"+ drpEnyear.value;
	document.body.style.cursor = "progress";
	CreateXmlHttp();
	var requestUrl = "SipCalcData.aspx?sch_Code="+ sch_Code.value +"&sch_Type="+ SchTypeCode +"&st_Date="+ st_Date +"&ed_Date="+ ed_Date +"&inv_Amnt="+inv_Amnt.value;
	
	if(XmlHttp){
				XmlHttp.onreadystatechange = function(){sipDataResp()}
				XmlHttp.open("GET", requestUrl,  true);
				XmlHttp.send(null);
			}	
}
//Called when response comes back from server Only For sip data
function sipDataResp()
{
	if(XmlHttp.readyState == 4)
	{
		if(XmlHttp.status == 200)
		{			
			var SIPCALC    = document.getElementById("SIPCALC");
			var strData = XmlHttp.responseText
			if(strData != "NA")
			{	
				var Tot_InvAmt  = document.getElementById("Tot_InvAmt");
				var Tot_UnitBuy = document.getElementById("Tot_UnitBuy");
				var Inv_ValDate = document.getElementById("Inv_ValDate");
				var Inv_Val	    = document.getElementById("Inv_Val");
				var Return	    = document.getElementById("Return");
				var EntryLoad = document.getElementById("EntryLoad");
				var ExitLoad = document.getElementById("ExitLoad");				
				var TotMonth    = document.getElementById("TotMonth");
				var SIPTable    = document.getElementById("SIPTable");
				var arrStr = strData.split("|");
					SIPTable.innerHTML = arrStr[0];
					Tot_InvAmt.innerHTML = arrStr[1];
					Tot_UnitBuy.innerHTML = arrStr[2];
					Inv_ValDate.innerHTML = arrStr[3];
					Inv_Val.innerHTML = arrStr[4];
					Return.innerHTML = arrStr[5];					
					TotMonth.innerHTML = arrStr[8];
					EntryLoad.innerHTML = arrStr[9];
					ExitLoad.innerHTML = arrStr[10];
					SIPCALC.style.display='inline';				
			}
			else {
				SIPCALC.style.display='inline';
				//SIPCALC.innerHTML="There was a problem retrieving data from the server.";
				SIPCALC.innerHTML="<span class='Nodata'>No Data Available for the selected Period!!!</span>";
			}	
		}
	}
	document.body.style.cursor = "auto";
}



