﻿// JScript File

//---Date OPeration

//Date Difference
var endDate=new Date(strenddate);




//Control Names


var arrMonth=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
//alert(arrMonth[2]);
var todaydate=new Date();
var date=todaydate.getDate();
var month=todaydate.getMonth();
var year=todaydate.getFullYear();
//var noofmonth=23;//no of month
var noofdays=30;





 function getMonthName(s)
            {
            if(s==0)
            return "Jan";
             if(s==1)
            return "Feb";
             if(s==2)
            return "Mar";
             if(s==3)
            return "Apr";
             if(s==4)
            return "May";
            if(s==5)
            return "Jun";
             if(s==6)
            return "Jul";
              if(s==7)
            return "Aug";
             if(s==8)
            return "Sep";
             if(s==9)
            return "Oct";
             if(s==10)
            return "Nov";
             if(s==11)
            return "Dec";
           }
//populatemonth("date","month",strstartdate);
//populatemonth("dateOut","monthOut",strstartdate);
function populatemonthrfp(ctrd,ctrm,stdate)
{

document.getElementById(ctrm).options.length=null;
 //document.getElementById(ctrm).options.length=null;
 sdate=new Date(stdate); 
 temenddate=new Date(strenddate);
 //temenddate.setFullYear(temenddate.getFullYear()+1);

 document.getElementById(ctrm).options[0]=new Option("Month","-1");
    for(i=1;i<=noofmonth+1;i++)
    {  
     document.getElementById(ctrm).options[i]=new Option(getMonthName(sdate.getMonth()),(sdate.getMonth()+1));
     if(sdate.getMonth()==11)
     break;
     sdate.setMonth(sdate.getMonth()+1);
    // alert(startDate);
    }
}


function populatemonthOnlyrfp(ctrd,ctrm,ctry)
{
 var selectMonth=document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value;

document.getElementById(ctrm).options.length=null;
 //document.getElementById(ctrm).options.length=null;
 sdate=new Date("1/1/2009");
 treatmentstrstartdate=new Date();
 var curDate=new Date(strstartdate);
 temenddate=new Date(strenddate);
 //temenddate.setFullYear(temenddate.getFullYear()+1); treatmentstrstartdate
  if(ctry.indexOf("dd_yy")!="-1")
   {
      if(document.getElementById(ctry).value==curDate.getFullYear()) 
      sdate=curDate
   }
   else
   {
     if(document.getElementById(ctry).value==treatmentstrstartdate.getFullYear()) 
     sdate=treatmentstrstartdate
   
   }
  
  document.getElementById(ctrm).options[0]=new Option("Month","-1");
    for(i=1;i<=noofmonth+1;i++)
    {
     document.getElementById(ctrm).options[i]=new Option(getMonthName(sdate.getMonth()),(sdate.getMonth()+1));
     if(sdate.getMonth()==11)
     break;
     sdate.setMonth(sdate.getMonth()+1);
    // alert(startDate);
    }
    document.getElementById(ctrm).value=selectMonth;
    if(document.getElementById(ctrm).value=="")
     document.getElementById(ctrm).value="-1";
}

try
{
prepopulatedatesrfp("dd_dd","dd_mm","dd_yy",strstartdate);
prepopulatedatesrfp("treatment_day","treatment_month","treatment_year",treatmentstrstartdate);
}
catch(err)
{
}

function prepopulatedatesrfp(ctrd,ctrm,ctry,stdt)
{

       var stdate=new Date(stdt);
       populatemonthrfp(ctrd,ctrm,stdate);
       populatedaterfp(stdate,ctrd);
           var stdate12=new Date(stdt);
       populateyearrfp(ctry,stdate12);
 }

function onchangepopulateIndaterfp(Indate,Inmonth,Inyear)
{
  var selectDate=document.getElementById(Indate).options[document.getElementById(Indate).selectedIndex].value;

  var selIndate=getSelectedDaterfp1(Indate,Inmonth,Inyear);
 
  if(selIndate!=null)
   {
   populatedaterfp(selIndate,Indate,"onchange");
   //alert(selectDate);
   document.getElementById(Indate).value=selectDate;
   if(document.getElementById(Indate).value=="")
   document.getElementById(Indate).value="-1"
   }
  else
  return

}

function onchangepopulatemonthrfp(Indate,Inmonth,Inyear)
{
  
  var selIndate=getSelectedDaterfp1(Indate,Inmonth,Inyear);
  if(selIndate!=null)
   populatemonthrfp(Indate,Inmonth,stdate);
  else
  return

}

function getSelectedDaterfp1(ctrd,ctrm,ctry)
{
  var newdate;
    if(document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value!="-1")
    {
         
        var curDate=new Date(strstartdate);
      
        if(ctry.indexOf("dd_yy")=="-1")
         {
        
           curDate=new Date();    
         }
        var datandyear=document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value;
       if(document.getElementById(ctry).options[document.getElementById(ctry).selectedIndex].value!="-1")
       {
        if(parseInt(curDate.getMonth())+1==parseInt(document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value) && parseInt(document.getElementById(ctry).options[document.getElementById(ctry).selectedIndex].value)==curDate.getFullYear())
        newdate=curDate;
        else
        newdate=new Date(document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value+"/"+1+"/"+document.getElementById(ctry).options[document.getElementById(ctry).selectedIndex].value);
       }
       else
       {
         newdate=new Date(document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value+"/"+1+"/"+2000);
       }
        
      
        return newdate;
    }
    else
    {
    return null;
    }
}







function populatedaterfp(selDate,ctrd,type)
{

document.getElementById(ctrd).options.length=null;
var strtdate=new Date(strstartdate);
var tempenddate=new Date(strenddate);
if(ctrd.indexOf("dd_dd")=="-1")
{
  strtdate=new Date();
  //temp=strtdate;
  //temp.setYear(temp.getFullYear()+1);
  //tempenddate=temp;
}

//var tempenddate=new Date(strenddate);
//alert(selDate.getMonth()+"Select")
//alert(strtdate.getMonth()+"Start");
if(ctrd.indexOf('Out')!=-1)
 {
 tempenddate.setDate(tempenddate.getDate()+datediff);
 }
if(type=="onchange")
{

    if(ctrd.indexOf('Out')==-1)
    {
      if(selDate.getMonth()==strtdate.getMonth() && selDate.getDate()==strtdate.getDate() && selDate.getFullYear()==strtdate.getFullYear())
      selDate.setDate(strtdate.getDate());
      else
      selDate.setDate(1);
    }
    else
    {
        if(selDate.getMonth()!=strtdate.getMonth() || selDate.getFullYear()!=strtdate.getFullYear())
        selDate.setDate(1);
        else
        selDate.setDate(strtdate.getDate()+datediff);
        
    
    if(selDate.getMonth()==tempenddate.getMonth() && selDate.getDate()==tempenddate.getDate() && selDate.getFullYear()==tempenddate.getFullYear())
    selDate.setDate(tempenddate.getDate());
   // tempenddate.setDate(tempenddate.getDate()+datediff);
    }
    
 }   
        document.getElementById(ctrd).options[0]=new Option("Day","-1");
       for(j=1;j<=32;j++)
        {
        document.getElementById(ctrd).options[j]=new Option(selDate.getDate(),selDate.getDate());
        if(tempenddate.getMonth()==selDate.getMonth() && tempenddate.getDate()==selDate.getDate() && tempenddate.getFullYear()==selDate.getFullYear())
        {
        break
        }
        var mon=selDate.getMonth();
        selDate.setDate(selDate.getDate()+1)
        if(mon!=selDate.getMonth())
        return;
        }
 }

function getSelectedDaterfp(ctrd,ctrm,ctry)
{

var curDate=new Date(strstartdate);
var datandyear=document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value;
var datyear=datandyear.split(":");
if(curDate.getMonth()==parseInt(datyear[0]+1) && parseInt(datyear[1])==curDate.getFullYear())
var newdate=curDate;
else
var newdate=new Date(document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value+"/"+document.getElementById(ctrd).options[document.getElementById(ctrd).selectedIndex].text+"/"+document.getElementById(ctry).options[document.getElementById(ctry).selectedIndex].value);
return newdate;
}

function populateyearrfp(ctry,stdate)
{
var sttdate=new Date(strstartdate);
var enddate=new Date(strenddate);
var noofmonth=(enddate.getFullYear()-sttdate.getFullYear());
document.getElementById(ctry).options.length=null;
 //document.getElementById(ctrm).options.length=null;
 sdate=new Date(stdate); 
 temenddate=new Date(strenddate);
 //temenddate.setFullYear(temenddate.getFullYear()+1);
 var nyear=enddate.getFullYear()-sttdate.getFullYear();

 if(ctry.indexOf('dd_yy')==-1)
 {
nyear=1; //Hard Coded;
 }
 document.getElementById(ctry).options[0]=new Option("Year","-1");
    for(i=1;i<=nyear+1;i++)
    {  
     document.getElementById(ctry).options[i]=new Option(sdate.getFullYear(),sdate.getFullYear());
     if(temenddate.getFullYear()==sdate.getFullYear())
     break;
     sdate.setYear(sdate.getFullYear()+1);
    // alert(startDate);
    }
}
