// JScript File
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";
            
             
            }
      function isLastDate1(date,month,year)
            {
          // alert(date);
            var  strReturn="false";
            
          
             if(month==0||month==2||month==4||month==6||month==7||month==9||month==11)
            {
            
            
            if(date==31)
            {
            strReturn="true";
            }
            }
         if(month==3||month==5||month==8||month==10)
            {
           
            if(date==30)
             {
				strReturn="true";
			 }
            }
            
             if(month==1)
            {
            
           
            if(year%4==0)
            {
				if(date==29)
				{
					strReturn="true";
				}
            }
            else
            {
				if(date==28)
				{
				 strReturn="true";
				}
            }
           
            
            }
            
            
            return strReturn;
            }
           
          
               
            
            
             function isLastDateBefore(date,month,year)
            {
           
            var strReturn="false";
            
          
             if(month==0||month==2||month==4||month==6||month==7||month==9||month==11)
            {
            
            
            if(date==30)
            {
            strReturn="true";
            }
            }
         if(month==3||month==5||month==8||month==10)
            {
           
            if(date==29)
             {
				strReturn="true";
			 }
            }
            
             if(month==1)
            {
            
           
            if(year%4==0)
            {
				if(date==28)
				{
					strReturn="true";
				}
            }
            else
            {
				if(date==27)
				{
				 strReturn="true";
				}
            }
            
            
            }
            
            return strReturn;
            }
            
     
            	
		
		 function get_Month_Number(monthnumber)
     {
      var MonName;
      switch(monthnumber)
       {
        case 1:
              MonName="01";
              break;
        case 2:
              MonName="02";
              break;
        case 3:
              MonName="03";
              break;
        case 4:
              MonName="04";
              break;
        case 5:
              MonName="05";
              break;
        case 6:
              MonName="06";
              break;
        case 7:
              MonName="07";
              break;
        case 8:
              MonName="08";
              break;
        case 9:
              MonName="09";
              break;
        case 10:
              MonName="10";
              break;
        case 11:
              MonName="11";
              break;
        case 12:
              MonName="12";
              break;
       }
      return MonName;
     }
     
     function get_date_number(dateid)
     {
     var get_value;
           var get_number;
           get_number=dateid.length;
          if(get_number==1)
          {
           get_value="0"+dateid;
          }
          else
          {
          get_value=dateid;
          }
        return get_value;
     }
	
function getMonthNumber(s)
            {
            if(s=="JAN")
            return 0;
             if(s=="FEB")
            return 1;
             if(s=="MAR")
            return 2 ;
             if(s=="APR")
            return 3;
             if(s=="MAY")
            return 4;
            if(s=="JUN")
            return 5;
             if(s=="JUL")
            return 6;
              if(s=="AUG")
            return 7;
            if(s=="SEP")
            return 8;
             if(s=="OCT")
            return 9;
            if(s=="NOV")
            return 10;
            if(s=="DEC")
            return 11;
            
           }
//---Date Operation


var yy=myscriptTime.getFullYear();
var mm=myscriptTime.getMonth();
//myscriptTime.setDate(myscriptTime.getDate()+1)
var dd=myscriptTime.getDate();

var startDate=new Date();
var strstartdate=(parseInt(mm)+1)+"/"+dd+"/"+yy; //"4/1/2009";  // mm/dd/yyyy

startDate.setDate(startDate.getDate()+1)

var yy=myscriptTime.getFullYear();
var mm=myscriptTime.getMonth();
var dd=myscriptTime.getDate();
var strenddate=parseInt(mm)+1+"/"+dd+"/"+(parseInt(yy)+2);//"1/1/2011";

var datediff=1;//Date Difference
var endDate=new Date(strenddate);


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=24;//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 prepopulatedates(ctrd,stdt)
{
    var stdate=new Date(stdt);
    if(ctrd.indexOf('Out')!=-1)
    {
        stdate.setDate(stdate.getDate()+parseInt(datediff))
        populatemonth("dateOut","monthOut",stdate);
        populatedate(stdate,ctrd);
    }
    else
    {
       populatemonth('date','month',stdate);
       populatedate(stdate,ctrd);
    }
}

function populatemonth(ctrd,ctrm,stdate)
{
  
 document.getElementById(ctrm).options.length=null;
 sdate=new Date(stdate);

 temenddate=new Date(strenddate);
 if(ctrd.indexOf('Out')!=-1)
 {
       temenddate.setDate(temenddate.getDate()+datediff);
 }
    for(i=0;i<=noofmonth;i++)
    {  
     document.getElementById(ctrm).options[i]=new Option(getMonthName(sdate.getMonth())+" "+sdate.getFullYear(),sdate.getMonth()+":"+sdate.getFullYear());
     if(temenddate.getMonth()==sdate.getMonth() && temenddate.getFullYear()==sdate.getFullYear())
     break;
     sdate.setMonth(sdate.getMonth()+1);
    }
}
prepopulatedates('date',strstartdate);
prepopulatedates('dateOut',strstartdate);

//var datandyear=document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value;
//var datyear=datandyear.split(":");
//if(stdate.getMonth()==parseInt(datyear[0]) && parseInt(datyear[1])==stdate.getFullYear())
//{
//var newdate=curDate;
//newdate.setDate(newdate.getDate()+1)
//}
//else
//var newdate=new Date((parseInt(datyear[0])+1)+"/"+1+"/"+datyear[1]);

function onchangepopulateIndate()
{
  var selIndate=getSelectedDate1("date","month");
  populatedate(selIndate,"date","onchange");
  changeDate("date","month"); 
       
}

function getSelectedDate1(ctrd,ctrm)
{
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]) && parseInt(datyear[1])==curDate.getFullYear())
var newdate=curDate;
else
var newdate=new Date((parseInt(datyear[0])+1)+"/"+document.getElementById(ctrd).options[document.getElementById(ctrd).selectedIndex].text+"/"+datyear[1]);
return newdate;
}

function getSelectedDateChange(ctrd,ctrm)
{
var datandyear=document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value;
var datyear=datandyear.split(":");
var newdate=new Date((parseInt(datyear[0])+1)+"/"+1+"/"+datyear[1]);
return newdate;
}


function onchangepopulateOutdate()
{
var selOutdate=getSelectedDateChange("dateOut","monthOut");
var selIndate=getSelectedDate("date","month");

populatedateOut(selOutdate,selIndate,"dateOut","onchange");
//RevchangeDate("dateOut","monthOut");
}
function populatedateOut(selDate,selIndates,ctrd,type)
{
                 
document.getElementById(ctrd).options.length=null;

var strtdate=new Date(strstartdate);
var tempenddate=new Date(strenddate);
//alert(selDate.getMonth()+"Select")
//alert(strtdate.getMonth()+"Start");

if(type=="onchange")
{
   
 
    if(selDate.getMonth()==selIndates.getMonth() && selDate.getFullYear()==selIndates.getFullYear())
    selDate.setDate(selIndates.getDate()+datediff);
    else
    selDate.setDate(1);
    
  
    
 }   
   var selIsndate=getSelectedDate1("date","month");
          if(ctrd.indexOf('Out')==-1)
             selIsndate=getSelectedDateChange("date","month");
          else
              selIsndate.setDate(selIsndate.getDate()+1)
      
            document.getElementById(ctrd).length=null;
  
       for(j=0;j<=31;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())
//        {
//         
//         
//          var cnt=1;
//           for(y=0;y<=tempenddate.getDate();y++)
//           {
//         
//                document.getElementById(ctrd).options[y]=new Option(selIsndate.getDate(),selIsndate.getDate());
//                var mon1=selIsndate.getMonth();
//                selIsndate.setDate(selIsndate.getDate()+1)
//                if(tempenddate.getMonth()!=selIsndate.getMonth())
//                break;
//           }
//        break
//        }
          var mon=selDate.getMonth();
        selDate.setDate(selDate.getDate()+1)
        if(mon!=selDate.getMonth())
        return;
        }
 }

function revpopulatedate(selDate,ctrd,type)
{
document.getElementById(ctrd).options.length=null;
var strtdate=new Date(strstartdate);
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.setDate(1);
    else
    selDate.setDate(1);
    }
    
    else
    {
    // if(selDate.getMonth()!=strtdate.getMonth())
    // selDate.setDate(strtdate.getDate()+datediff);
    //  else
    selDate.setDate(strtdate.getDate()+datediff);
    
    if(selDate.getMonth()==tempenddate.getMonth())
    selDate.setDate(tempenddate.getDate());
   // tempenddate.setDate(tempenddate.getDate()+datediff);
    }
    
 }   
       for(j=0;j<=31;j++)
        {
        document.getElementById(ctrd).options[j]=new Option(selDate.getDate(),selDate.getDate());
        if(tempenddate.getMonth()==selDate.getMonth() && tempenddate.getDate()==selDate.getDate())
        {
        break
        }
        var mon=selDate.getMonth();
        selDate.setDate(selDate.getDate()+1)
        if(mon!=selDate.getMonth())
        return;
        }
 }



function populatedate(selDate,ctrd,type)
{
document.getElementById(ctrd).options.length=null;
var strtdate=new Date(strstartdate);
var tempenddate=new Date(strenddate);
//alert(selDate.getMonth()+"Select")
//alert(strtdate.getMonth()+"Start");
if(ctrd.indexOf('Out')!=-1)
 {
 tempenddate.setDate(tempenddate.getDate()-3);

 }
if(type=="onchange")
{
    if(ctrd.indexOf('Out')==-1)
    {
    if(selDate.getMonth()==strtdate.getMonth())
  selDate.setDate(strtdate.getDate());
    else
     selDate.setDate(1);
    
     
   
    }
    else
    {
    if(selDate.getMonth()==strtdate.getMonth())
    selDate.setDate(1);
    else
    selDate.setDate(strtdate.getDate()+datediff);
    
    
    if(selDate.getMonth()==tempenddate.getMonth())
    selDate.setDate(tempenddate.getDate());
   // tempenddate.setDate(tempenddate.getDate()+datediff);
    }
    
 }   
  
       for(j=0;j<=31;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())
        {
         
          var selIsndate=getSelectedDate1("date","month");
          if(ctrd.indexOf('Out')==-1)
             selIsndate=getSelectedDateChange("date","month");
          else
              selIsndate.setDate(selIsndate.getDate()+1)
      
            document.getElementById(ctrd).length=null;
          var cnt=1;
           for(y=0;y<=tempenddate.getDate();y++)
           {
         
                document.getElementById(ctrd).options[y]=new Option(selIsndate.getDate(),selIsndate.getDate());
                var mon1=selIsndate.getMonth();
                selIsndate.setDate(selIsndate.getDate()+1)
                if(tempenddate.getMonth()!=selIsndate.getMonth())
                break;
           }
        break
        }
          var mon=selDate.getMonth();
        selDate.setDate(selDate.getDate()+1)
        if(mon!=selDate.getMonth())
        return;
        }
 }

function getSelectedDate(ctrd,ctrm)
{

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((parseInt(datyear[0])+1)+"/"+document.getElementById(ctrd).options[document.getElementById(ctrd).selectedIndex].text+"/"+datyear[1]);
return newdate;
}


function changeDate(datelist,monthlist)
{

 var ArrDate=document.f1.month.value;
 var DepDate=document.f1.monthOut.selectedIndex;
 var ArArr=new Array();
 ArArr=ArrDate.split(":");
 var mm=parseInt(ArArr[0])+1;

 var yy=ArArr[1];
 var dd=parseInt(document.f1.date.value);
 
 if(parseInt(myscriptTime.getMonth())+1==mm && parseInt(myscriptTime.getFullYear())+1==yy && dd>parseInt(myscriptTime.getDate())-2)
	{
	//alert("O");
	var dt=new Date(myscriptTime.getFullYear()+1,myscriptTime.getMonth(),myscriptTime.getDate());
	var ndt=new Date(dt.setDate(dt.getDate()-1));
	var mName=getMonthName(ndt.getMonth());
	alert("Arrival Date Should be less than "+parseInt(ndt.getDate())+"-"+mName.toUpperCase()+"-"+ndt.getFullYear());
	document.f1.date.value=1;
	return false;
	}
    var datandyear=document.getElementById(monthlist).options[document.getElementById(monthlist).selectedIndex].value;
    var datyear=datandyear.split(":");
    var newdate=new Date((parseInt(datyear[0])+1)+"/"+(parseInt(document.getElementById(datelist).options[document.getElementById(datelist).selectedIndex].text))+"/"+datyear[1]);
    var stdati=new Date(strstartdate);
    prepopulatedates('dateOut',newdate);
    newdate.setDate(stdati.getDate());
    var selIndates=getSelectedDate("date","month");
}

function RevchangeDate(datelist,monthlist)
{
    var selOutdates=getSelectedDate("dateOut","monthOut");
    selOutdates.setDate(selOutdates.getDate()-datediff)
    var mn=getMonthName(selOutdates.getMonth());
    var yr=selOutdates.getFullYear();
    var mnyr=mn+" "+yr;
    //alert(mnyr);
    currform1=document.f1;
		for(i=0;i<currform1.month.options.length;i++)
		{
			if (currform1.month.options[i].text ==mnyr){
			currform1.month.options[i].selected = true;
			break;}
		}
  var sendate=getSelectedDate("date","month");
  //alert(sendate);
  populatedate(sendate,"date","onchange");
			for(i=0;i<currform1.date.options.length;i++)
		{
			if (currform1.date.options[i].text ==selOutdates.getDate()){
				currform1.date.options[i].selected = true;
				break;}
		}
	
}
function revprepopulatedates(ctrd,stdt)
{

    var stdate=new Date(stdt);
    if(ctrd.indexOf('Out')!=-1)
    {
           populatemonth("dateOut","monthOut",stdate);
        revpopulatedate(stdate,ctrd);
        
    }
    else
    {
     stdate.setDate(stdate.getDate()-parseInt(datediff))
       populatemonth("date","month",stdate);
        revpopulatedate(stdate,ctrd);
   
       
    }

}


function changemonth(ctrd,ctrm)
{
mnt=document.getElementById(ctrm).options[document.getElementById(ctrm).selectedIndex].value;
dt=document.getElementById(ctrd).options[document.getElementById(ctrd).selectedIndex].value;
var datyear=mnt.split(":");
//if(isLastDate(dt,datyear[0],datyear[1])=="true")
//document.getElementById("monthOut").value=(parseInt(mnt)+1)+":"+datyear[1];
//else
document.getElementById("monthOut").value=document.getElementById("month").value;
}

