﻿// JScript File

// Function used for popup the calculator
function openCalculator(objCalc){
    var ListBox = document.getElementById(objCalc);
    var calcid = ListBox.options[ListBox.selectedIndex].value;
    if(calcid != 0 && calcid < 5)
    {
       newwindow=window.open('MetlifeCalcInfo.aspx?calc='+calcid,'mywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=650,height=530,top=100,left=100')
       if (window.focus) {newwindow.focus()}
       return false;
    }
    else
    {
        alert("Please select any calculator type.!!")
        document.getElementById(objCalc).focus();
        return false;
    }
}



// Function used to open priemuim calculator
function openPremiumCalc(){
        newwindow = window.open('http://ill.metlifeportal.co.in/Illustration/CustomerLogin.aspx', 'mywindow', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=780,height=570,top=100,left=100')
       if (window.focus) {newwindow.focus()}
       //return false;
}

// Function used to open calculator in KCenter_RightNavigation.ascx
function openCalculator_KCenter()
{
    var ListBox = document.getElementById("KCenter_RightNavigation1_cboCalc");
    var calcid = ListBox.options[ListBox.selectedIndex].value;

    if(calcid != 0 && calcid < 5)
    {
       newwindow=window.open('MetlifeCalcInfo.aspx?calc='+calcid,'mywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=550,height=450,top=100,left=100')
       if (window.focus) {newwindow.focus()}
       return false;
    }
    else
    {
        alert("Please select any calculator type.!!")
        document.getElementById("KCenter_RightNavigation1_cboCalc").focus();
        return false;
    }
}
//Added by sandeep kumar on 23 Feb 2009
function DisableControls()
{
    document.getElementById("txtFromDate").disabled='disabled';
    document.getElementById("txtToDate").disabled='disabled';
}
function EnableControls()
{
    document.getElementById("txtFromDate").disabled='';
    document.getElementById("txtToDate").disabled='';
}
// Function used for check NAV page  /changed by sandeep on 23 feb 2008.
function checkNAV(){
    var ListBox = document.getElementById("cboFund");
    var fundid = ListBox.options[ListBox.selectedIndex].value;
    var tperiod = getOptionVal('TPeriod');
    
    if(fundid=="--Select Fund--")
    {
        alert("Please select any fund type.!!")
        document.getElementById("cboFund").focus();
        return false;
    }
    if(tperiod=="rdDate")
    {
        var todate = new Date();
        var fromdate = new Date();

        todate = document.getElementById("txtToDate").value; 
        fromdate = document.getElementById("txtFromDate").value;
        if(fromdate==null || fromdate == '' )
        {
           alert("Please select start date!!")
            document.getElementById("txtFromDate").focus();
            return false;
        }
       if(todate==null || todate == '' )
        {
           alert("Please select end date!!")
            document.getElementById("txtToDate").focus();
            return false;
        }
//        if(fromdate > todate)
//        {
//            alert("End date must be greater than start date.!!")
//            document.getElementById("txtToDate").focus();
//            return false;
//        }
     }
    return true;
 }
 
  //function for date validation written by geeta..................................
function dateDiff() 
{
var todate = new Date();
var fromdate = new Date();
todate = document.getElementById("txtToDate").value; 
fromdate = document.getElementById("txtFromDate").value;
diff  = new Date();
// sets difference date to difference of first date and second date
alert(fromdate.getTime()-todate.getTime());
diff.setTime(Math.abs(fromdate.getTime() - todate.getTime()));

timediff = diff.getTime();
alert(timediff);
weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
timediff -= days * (1000 * 60 * 60 * 24);
alert("Weeks:" + weeks + "Days:" + days);
dateform.difference.value = weeks + " weeks, " + days + " days, " + hours + " hours, " + mins + " minutes, and " + secs + " seconds";
if(days < 7 || weeks > 78)
{
return false;
}
else 
return true;
}

 // Function used for Check the Tax Info Page
  function CheckTaxInfo(){
    var name = document.getElementById("txtName").value; 
    var age = document.getElementById("txtAge").value;
    var email = document.getElementById("txtEmail").value;
    var phone = document.getElementById("txtPhone").value;
    var mobile = document.getElementById("txtMobile").value;
    var StdCode= document.getElementById("txtSTDCode").value; //Added By Sandeep
    
    var gender = document.getElementById("cboGender");	
	var selectedgender = gender.options[gender.selectedIndex].value;	
   
    if(name == null || name == ""){
        alert("Please enter your name!!");
        document.getElementById("txtName").focus();
        return false;
    }
    if(selectedgender == "0"){
        alert("Please select your gender!!");
        document.getElementById("cboGender").focus();
        return false;
    }
    if(age == null || age == "" || age <= 0){       //Changed by Sandeep to validate the (-)ve Entry.
        alert("Please enter your age in years!!");
        document.getElementById("txtAge").focus();
        return false;
    }
    if(email == null || email == ""){
        alert("Please enter your email address!!");
        document.getElementById("txtEmail").focus();
        return false;
    }
    if(email != null || email != ""){
        if(echeck()==false){
            document.getElementById("txtEmail").value="";
            document.getElementById("txtEmail").focus();
		    return false
	    }
    }
    
    if (StdCode !=null && StdCode !="" && (phone == null || phone == "")) //Condition Added by Sandeep Kumar. If STD Code got supplied then Phone must be supplied.
    {
        alert("Please enter phone number!!");
        document.getElementById("txtPhone").focus();
        return false;   
    }
    
    if((phone == null || phone == "") && (mobile == null || mobile == "")){
        alert("Please enter either phone no or mobile no!!");
        document.getElementById("txtPhone").focus();
        return false;
    }
    
    if (phone != null && phone != "" && (StdCode ==null || StdCode ==""))  //Condition Added by Sandeep Kumar. If Phone nuber got supplied then STDCode must be supplied.
    {
        alert("Please enter STD Code!!");
        document.getElementById("txtSTDCode").focus();
        return false;   
    }
    
    if (mobile != null && mobile != "" && mobile.length<10 )  //Condition Added by Sandeep Kumar. If Phone nuber got supplied then STDCode must be supplied.
    {
         alert("Please enter valid mobile number!!");
        document.getElementById("txtMobile").focus();
        return false;   
    }
        
    return true;
  }
  
  // Function used for Check the Tax Calculation Page
  function CheckTaxCalc(){
    var gsalary = document.getElementById("txtGSalary").value;
    var seniorhins = document.getElementById("txtCHInsuraceParent").value; 
    var hins = document.getElementById("txtHInsuraceParent").value;
    

    if(gsalary == "" || gsalary == "0"){
        alert("Please enter gross annual salary!!")
        document.getElementById("txtGSalary").focus();
        return false;
    }
    if((seniorhins != "0") && (hins != "0")){
        alert("Please fill only one parent health insurace field!!")
        document.getElementById("txtCHInsuraceParent").focus();
        return false;
    }
  }
    
  function CheckChild(){
    var cage = document.getElementById("txtCAge").value; 
    var ecollege = document.getElementById("txtECollege").value;
    var cdegree = document.getElementById("txtCDegree").value;
    
    var ListBox = document.getElementById("cboDegree");
    var degree = ListBox.options[ListBox.selectedIndex].value;

    if(cage == "" || cage == "0"){
        alert("Please enter child current age!!");
        document.getElementById("txtCAge").focus();
        return false;
    }
    if(ecollege == "" || ecollege == "0"){
        alert("Please enter age for entering college!!");
        document.getElementById("txtECollege").focus();
        return false;
    }
    if(degree == "0"){
        alert("Please select aspired degree!!");
        document.getElementById("cboDegree").focus();
        return false;
    }
    if(cdegree == "" || cdegree == "0"){
        alert("Please enter current cost of degree!!");
        document.getElementById("txtCDegree").focus();
        return false;
    }
    if(parseInt(cage) > 18){
        alert("Child Age must be between 1-18 years!!");
        document.getElementById("txtCAge").focus();
        return false;
    }
    if((cage != "" || cage != "0") && (ecollege != "" || ecollege != "0")){
        if(parseInt(ecollege) <= parseInt(cage)){
            alert("Age for entering college must be greater than child current age!!");
            document.getElementById("txtECollege").focus();
            return false;                    
        }
    }
    return true;
  }
  
  function CheckRetirement(){
    var ListBox;
    var age = document.getElementById("txtAge").value; 
    var mexpence = document.getElementById("txtCMExp").value;
    var retage = document.getElementById("txtAgeRet").value;
    var irate = document.getElementById("txtIRate").value;
    var rofint = document.getElementById("txtRIFutre").value;
    
    ListBox = document.getElementById("cboMarried");
    var married = ListBox.options[ListBox.selectedIndex].value;
    ListBox = document.getElementById("cboRAtt");
    var riskatt = ListBox.options[ListBox.selectedIndex].value;
    
    if(age == "" || age == "0" || age > 60 || age<0 ){   //Change by Sandeep Kumar. To validate age in (-)ve.
        alert("Please enter current age, and age can not be greater than 60 years!!");
        document.getElementById("txtAge").focus();
        return false;
    }
    if(married == "" || married == "0"){
        alert("Please select marriage status!!");
        document.getElementById("cboMarried").focus();
        return false;
    }
    if(mexpence == "" || mexpence == "0"){
        alert("Please enter currently monthely expenses!!");
        document.getElementById("txtCMExp").focus();
        return false;
    }
    if(retage == "" || retage == "0" || retage > 65 ){
        alert("Please enter age at retirement, and retirement age can not be greater than 65 years!!");
        document.getElementById("txtAgeRet").focus();
        return false;
    }
    if(irate == "" || irate == "0"){
        alert("Please enter inflation Rate!!");
        document.getElementById("txtIRate").focus();
        return false;
    }
    if(riskatt == "" || riskatt == "0"){
        alert("Please select risk attitude!!");
        document.getElementById("cboRAtt").focus();
        return false;
    }
    if(rofint == "" || rofint == "0"){
        alert("Please enter rate of interest expected in future!!");
        document.getElementById("txtRIFutre").focus();
        return false;
    }
    if(retage > 70){
        alert("Age at retirement must be equal to or less than 70 years!!");
        document.getElementById("txtAgeRet").focus();
        return false;
    }
    if((age != "" || age != "0") && (retage != "" || retage != "0")){
        if(age > retage){
            alert("Age of retirement must be greater than age!!");
            document.getElementById("txtCAge").focus();
            return false;                    
        }
    }
  }
  
  // Function used for restrict the alphatabets value in TextBox
function DisAllowAlphabets(e){
      if(e.which){
        if ((e.which >= 48 && e.which <= 57)||(e.which==8)){
      		return true;}
     	else if(e.which == 45){
     		return true;}
    	else{ 
			return false;}
        }
      else if(window.event){    
       	if (window.event.keyCode >= 48 && window.event.keyCode <= 57){
      		window.event.returnValue=true;}
     	else if(window.event.keyCode == 45){
     		window.event.returnValue=true;}
    	else{
			window.event.returnValue=false;}  
        }
  } 
 
 // Function used for restrict the numeric value in TextBox 
 function DisAllowNumbers(e){
      if(e.which){
        if ((e.which >= 65 && e.which <= 90)||(e.which==8)||(e.which >= 97 && e.which <= 122)||(e.which==32)){
      		return true;} 
      	else{ 
			return false; }
       }
      else if(window.event){    
       	if ((window.event.keyCode >= 65 && window.event.keyCode <= 90)||(window.event.keyCode >= 97 && window.event.keyCode <= 122)||(window.event.keyCode==32)){
      		window.event.returnValue=true;} 
       else{ 
			window.event.returnValue= false; } 
   } 
 }
    
  // funcation use for check email
  function echeck() 
     { 
        var str='';
        str=document.getElementById("txtEmail").value;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID");
		   document.getElementById("txtEmail").focus();
		   return false;
		}
		 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		 {
		   alert("Invalid E-mail ID");
		  document.getElementById("txtEmail").focus();
		  return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    alert("Invalid E-mail ID");
		    document.getElementById("txtEmail").focus();
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		    document.getElementById("txtEmail").focus();
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		    document.getElementById("txtEmail").focus();
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		    document.getElementById("txtEmail").focus();   //Changed by Sandeep.
		    return false;
		 }

		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		    document.getElementById("txtEmail").focus();
		    return false;
		 }
		 
		 //Condition added by sandeep kumar.
   		 if (str.charAt(lstr-1)==dot){
		    alert("Invalid E-mail ID");
		    document.getElementById("txtEmail").focus();    //Changed By Sandeep. To validate sandeep@ists. type of incorrect entry.
		    return false;
		 }
		 
 		 return true;					
	}
    
// Function use for get value from radio button
 function getOptionVal(rtype){
     var opt=document.getElementsByName(rtype);
     for(i=0; i<opt.length;i++){
          if (opt.item(i).checked)
              return opt.item(i).value;
         }
     return 0;
    }
    
   
  function BranchCheck(objBranch)
   {
 
  var ListBox = document.getElementById(objBranch);
  var Branchid = ListBox.options[ListBox.selectedIndex].value;
   if(Branchid == 0 || Branchid == "Branch Locator")
   {
         alert('Please select State!')
         document.getElementById(objBranch).focus();
         return false;
    
   }
//   else
//   {
//   window.location = "../METLIFEONLINE/MetLifeContactUs_BranchOffices.aspx?pg=" + encodeURIComponent(1) + "&CityId=" + encodeURIComponent(0) + "&StateId=" + encodeURIComponent(Branchid);        
//      return true;
//   }
    return true;
 }
  function NAVCheck(objNAV,objFundValue)
   {
 
  var ListBox = document.getElementById(objNAV);
  var FundValue = ListBox.options[ListBox.selectedIndex].value;
   if(FundValue == 0 || FundValue == "--View NAV--")
   {
         alert('Please select Nav!')
         document.getElementById(objBranch).focus();
         return false;
   }
   else
   {
      document.getElementById(objFundValue).value= FundValue; 
      return true;
   }
 }
function showNavNote(ctrl) 
    {
     mywindow = window.open(ctrl,"New","menubar=0,resizable=1,top=100,left=100,width=540,height=500,toolbar=0,location=no,directories=0,status=1,scrollbars=1");     
     //mywindow.moveTo(20,40);
    }
