﻿// JScript File
Date.prototype.addMilliseconds=function(value){this.setMilliseconds(this.getMilliseconds()+value);return this;};
Date.prototype.addMinutes=function(value){return this.addMilliseconds(value*60000);};
function createDDMMYYY(strDate) // string(dd/mm/yyyy) to date convertion 
    {
        arrDt = strDate.split("/");
        var stdt=null;
   		stdt=new Date();
        stdt = new Date(parseInt(arrDt[2],10),parseInt(arrDt[1],10)-1,parseInt(arrDt[0],10),0,0,0);
        return stdt;
    }    
    function compareDate(endDate,startDate)
    {
        if(endDate.getTime() > startDate.getTime())
            return 1;  // endDate > startDate
        else if(endDate.getTime() == startDate.getTime())
            return 0;  // endDate = startDate
        else 
            return -1; // endDate < startDate
    }
    
    function addday(strDate){ with(strDate) setDate(getDate()+1); return strDate;}
    
    function lessday(strDate){ with(strDate) setDate(getDate()-1);return strDate;}
    
    function getHotelDate(gmtDelta)
    {
        var dtTime = new Date();
        var gmt = new Date(dtTime.toUTCString());
        var hotelDate = gmt.addMinutes(gmtDelta);
        return hotelDate;
    }
    function addDays(strDate,noOfNights) // strDate should be Date
    {
       with(strDate) setDate(getDate()+parseInt(noOfNights,10));
       return strDate;
    }
    
    function DateToString(stDate)  // date to string(dd/mm/yyyy) convertion
    {
        if ((stDate instanceof Date==false) ||isNaN(stDate))
        {
            alert("Invalid date");
            return "";
        }
        else
        {
            var dtSet =parseInt(stDate.getDate(),10);
            dtSet = dtSet<10?"0"+dtSet:dtSet;
            var monSet =parseInt(stDate.getMonth(),10)+1;
            monSet = monSet<10?"0"+monSet.toString():monSet;
            return (dtSet+"/"+monSet+"/"+stDate.getFullYear());  
        }      
    }
    
    
function compareDates (endDate, startDate) {
  var date1, date2;
  var month1, month2;
  var year1, year2;

  date1 = endDate.substring (0, endDate.indexOf ("/"));
  month1 = endDate.substring (endDate.indexOf ("/")+1, endDate.lastIndexOf ("/"));
  year1 = endDate.substring (endDate.lastIndexOf ("/")+1, endDate.length);

  date2 = startDate.substring (0, startDate.indexOf ("/"));
   month2= startDate.substring (startDate.indexOf ("/")+1, startDate.lastIndexOf ("/"));
  year2 = startDate.substring (startDate.lastIndexOf ("/")+1, startDate.length);

  if (year1 > year2) return true;
  else if (year1 < year2) return false;
  else if (month1 > month2) return true;
  else if (month1 < month2) return false;
  else if (date1 > date2) return true;
  else if (date1 < date2) return false;
  else return false;
} 

function compareDatesGreaterThanOrEqual (endDate, startDate) {
  var date1, date2;
  var month1, month2;
  var year1, year2;

  date1 = endDate.substring (0, endDate.indexOf ("/"));
  month1 = endDate.substring (endDate.indexOf ("/")+1, endDate.lastIndexOf ("/"));
  year1 = endDate.substring (endDate.lastIndexOf ("/")+1, endDate.length);
  //alert(month1+"/"+date1+"/"+year1);

  date2 = startDate.substring (0, startDate.indexOf ("/"));
  month2= startDate.substring (startDate.indexOf ("/")+1, startDate.lastIndexOf ("/"));
  year2 = startDate.substring (startDate.lastIndexOf ("/")+1, startDate.length);
  //alert(month2+"/"+date2+"/"+year2);

  if (parseInt(year1,10) > parseInt(year2,0)) return true;
  else if (parseInt(year1,10) < parseInt(year2,10)) return false;
  else if (parseInt(month1,10) > parseInt(month2,10)) return true;
  else if (parseInt(month1,10) < parseInt(month2,10)) return false;
  else if (parseInt(date1,10) > parseInt(date2,10)) return true;
  else if (parseInt(date1,10) < parseInt(date2,10)) return false;
  else return true ;
} 
function datesAreEqual (endDate, startDate) {
  var date1, date2;
  var month1, month2;
  var year1, year2;

  month1 = endDate.substring (0, endDate.indexOf ("/"));
  date1 = endDate.substring (endDate.indexOf ("/")+1, endDate.lastIndexOf ("/"));
  year1 = endDate.substring (endDate.lastIndexOf ("/")+1, endDate.length);
  //alert(month1+"/"+date1+"/"+year1);

  month2 = startDate.substring (0, startDate.indexOf ("/"));
  date2= startDate.substring (startDate.indexOf ("/")+1, startDate.lastIndexOf ("/"));
  year2 = startDate.substring (startDate.lastIndexOf ("/")+1, startDate.length);
  //alert(month2+"/"+date2+"/"+year2);  
  if ((parseInt(year1,10) == parseInt(year2,10))&&(parseInt(month1,10) == parseInt(month2,10))&&(parseInt(date1,10) == parseInt(date2,10)))
  {
    return true;
  }
  else return false;
} 
