﻿var temp;
var checkOut=0;
var curyear
var curmonth
var curday
var controlID

var elmCheckIn
var elmCheckOut
var elmPerson

var blnCheckIn = false;

var blnPerson = false;

function positionInfo(object) 
{

  var p_elm = object;
  this.getElementLeft = getElementLeft;
  function getElementLeft() 
  {
    
    var x = 0;
    var elm;
    
    if(typeof(p_elm) == "object")
	{
      elm = p_elm;
    } 
    else {
      elm = document.getElementById(p_elm);
    }

    while (elm != null) {
      x+= elm.offsetLeft;
      x-=3;
      elm = elm.offsetParent;
    }

    return parseInt(x);

  }

   this.getElementWidth = getElementWidth;

  function getElementWidth(){
  
    var elm;
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } 
    else {
      elm = document.getElementById(p_elm);
    }

    return parseInt(elm.offsetWidth);
  }


  this.getElementRight = getElementRight;

  function getElementRight(){

    return getElementLeft(p_elm) + getElementWidth(p_elm);
  }


  this.getElementTop = getElementTop;

  function getElementTop() {
    
    var y = 0;
    var elm;
    
    if(typeof(p_elm) == "object"){
      elm = p_elm;
    } 
    else {
      elm = document.getElementById(p_elm);
    }

    while (elm != null) {
      y+= elm.offsetTop;
      elm = elm.offsetParent;
    }

    return parseInt(y);
  }

 this.getElementHeight = getElementHeight;

  function getElementHeight()
  {
    
    var elm;
    
    if(typeof(p_elm) == "object")
	{
      elm = p_elm;
    } 
    else 
	{
      elm = document.getElementById(p_elm);
    }

    return parseInt(elm.offsetHeight);
  }

 this.getElementBottom = getElementBottom;

  function getElementBottom()
  {
    return getElementTop(p_elm) + getElementHeight(p_elm);
  }


}

 

function CalendarControl() {

  var calendarId = 'CalendarControl';
  var currentYear = 0;
  var currentMonth = 0;
  var currentDay = 0;
  var selectedYear = 0;
  var selectedMonth = 0;
  var selectedDay = 0;
  var months = ['JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'];
  var dateField = null;

  function getProperty(p_property)
  {

    var p_elm = calendarId;
    var elm = null;

    if(typeof(p_elm) == "object")
	{
      elm = p_elm;
    } 
    else
	{
      elm = document.getElementById(p_elm);
    }

 if (elm != null)
 {

      if(elm.style)
	  {

        elm = elm.style;
        if(elm[p_property])
		{
          return elm[p_property];
		} 
		else 
		{
          return null;

        }

      } 
	  else 
	  {
        return null;
      }
}
}

   function setElementProperty(p_property, p_value, p_elmId){

    var p_elm = p_elmId;
    var elm = null;

    if(typeof(p_elm) == "object"){

      elm = p_elm;

    } else {

      elm = document.getElementById(p_elm);


    }

 

    if((elm != null) && (elm.style != null)){

      elm = elm.style;

      elm[ p_property ] = p_value;

    }
  } 

  function setProperty(p_property, p_value)
  {
    setElementProperty(p_property, p_value, calendarId);
  }

  function getDaysInMonth(year, month) 
  {
    return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
  }
  
  function getDayOfWeek(year, month, day) 
  {
    var date = new Date(year,month-1,day)
    return date.getDay();
  }
   
  this.clearDate = clearDate; 

  function clearDate() 
  {
    dateField.value = '';
    hide();
  }
   
  this.setDate = setDate;

  function setDate(year, month, day)
   {
    if (dateField)    
     {
         if (month < 10) {month = "0" + month;}
         if (day < 10) {day = "0" + day;}
         var dateString = month+"/"+day+"/"+year;
           
         dateField.value = dateString;
         hide(); 
     }
    return;
  }

this.changeMonth = changeMonth;

function changeMonth(change) 
{
    if(change == 1)
	{
		if (temp < getCurrentMonth() + 12)
		{}
		else
			return;

		temp = temp + 1;
		currentMonth += change;
		currentDay = 0;

		if(currentMonth > 12)
		{
			currentMonth = 1;
			currentYear++;
		}
		else if(currentMonth < 1)
		{
			currentMonth = 12;
			currentYear--;
		}

		calendar = document.getElementById(calendarId);
		calendar.innerHTML = calendarDrawTable();
	}
    else if((change != 1))
    {
		if ((currentMonth > getCurrentMonth()) || (currentYear > getCurrentYear()))
		{}
		else
		{
			if (checkLocation() == false)
				return;
		}

        temp = temp - 1;
        currentMonth += change;
		currentDay = 0;

		if(currentMonth > 12)
		{
			currentMonth = 1;
			currentYear++;
		}
		else if(currentMonth < 1)
		{
			currentMonth = 12;
			currentYear--;
		}

		calendar = document.getElementById(calendarId);
		calendar.innerHTML = calendarDrawTable();
    }
	//--------------*end of proc*-----------------------------------   
}


  this.changeYear = changeYear; 

  function changeYear(change) 
  {
    currentYear += change;
    currentDay = 0;
    calendar = document.getElementById(calendarId);
    calendar.innerHTML = calendarDrawTable();
  }

// Function to get current year ()

  function getCurrentYear() 
  {
    if( checkOut== 1)
        {
        if(document.getElementById(controlID).value!="")
            { 
	         var year = new Date(document.getElementById(controlID).value).getFullYear();
             return year;
            }

        else
            {    
	         var year = new Date().getYear();
             if(year < 1900) year += 1900;
             return year;
            }

        }
    else
      {
        var year = new Date().getYear();
        if(year < 1900) year += 1900;
        return year;
      }
 }

 //-----------End function-------------

 //-----Function to get current month()

  function getCurrentMonth() 
 {
    //if(HotelId==18)
    //{
    //	var month=1
    //	return month
    //}
    var month=1
    return month
    
    if( checkOut== 1)
        {
            if(document.getElementById(controlID).value!="")
                {
                    var month=new Date(document.getElementById(controlID).value).getMonth()+1;
                    return month
                }
            else
                {
                    return new Date().getMonth() + 1;
                }
        }
    else
        {
            return new Date().getMonth() + 1;
        }
  } 

 //----------End of function---------------
 

 // -----function to get current day()--------
function getCurrentDay() 
  {
    if( checkOut== 1)
        {
            if(document.getElementById(controlID).value!="")
                {
                    var day=new Date(document.getElementById(controlID).value).getDate()+1;
                    return day;
                }   
            else
                {
                    return new Date().getDate();
                }
        }
    else
        {
            return new Date().getDate();
        }
  }
  
 //----------end of function----------------

  function calendarDrawTable() 
  {
    var dayOfMonth = 1;
    var validDay = 0;
    var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);

    var daysInMonth = getDaysInMonth(currentYear, currentMonth); 

    var css_class = null; //CSS class for each day 

    var table = "<table cellspacing='0' cellpadding='0' border='0'>";

    table = table + "<tr class='Calheader'>";
    table = table + "  <td colspan='2' class='Calprevious'><a href='javascript:changeCalendarControlMonth(-1);'>&lt;</a></td>";
    table = table + "  <td colspan='3' class='Caltitle'>" + months[currentMonth-1] + "&nbsp;"  + currentYear + "</td>";
    table = table + "  <td colspan='2' class='Calnext'><a href='javascript:changeCalendarControlMonth(1);'>&gt;</a> <a href='javascript:hideCalendarControl();'><img src='http://www.oberoihotels.com/style/close.jpg' name='close' border='0'/></a></td>";
    table = table + "</tr>";
    table = table + "<tr><th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th></tr>"; 
    
    for(var week=0; week < 6; week++) 
    {
      table = table + "<tr>";
      
      for(var dayOfWeek=0; dayOfWeek < 7; dayOfWeek++) 
      {
        if(week == 0 && startDayOfWeek == dayOfWeek) 
         {
            validDay = 1;
         } 
        else if (validDay == 1 && dayOfMonth > daysInMonth) 
        {
          validDay = 0;
        } 

        if(validDay) 
        { 
        if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) 
            {
                css_class = 'Calcurrent';
            }                        
        if(checkOut==1)
            {
                if(document.getElementById(controlID).value!="")
                {
                    curyear=new Date(document.getElementById(controlID).value).getFullYear();
                    curmonth=new Date(document.getElementById(controlID).value).getMonth()+1;
                    curday=new Date(document.getElementById(controlID).value).getDate()+1;
                }
                else
                {
                    curyear = new Date().getYear();                    
                    if(curyear < 1900) curyear += 1900;
                    curmonth= new Date().getMonth() + 1;
                    curday=new Date().getDate();
                }
            }
        else
            {
                curyear = new Date().getYear();
                if(curyear < 1900) curyear += 1900;
                curmonth= new Date().getMonth() + 1;
                curday=new Date().getDate();
            }
            
            if(curyear==currentYear)
            {
               if(curmonth==currentMonth)
               {
                   if(curday > dayOfMonth && checkLocation() == false)
                      {		   
					      css_class = 'Calweekend1';
                      }
                   else if (dayOfWeek == 0 || dayOfWeek == 6) 
                   {
                          css_class = 'Calweekend';
                   }
                   else if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth)
                   {
                          css_class = 'Calcurrent';
                   }
                else
                 {
                    css_class = 'Calweekday';
                 }
             }
             else if (dayOfWeek == 0 || dayOfWeek == 6) 
             {
                css_class = 'Calweekend';
             }
             else if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) 
             {
                css_class = 'Calcurrent';
             }
             else
             {
               css_class = 'Calweekday';
             }
          }
           else if (dayOfWeek == 0 || dayOfWeek == 6) 
           {
                css_class = 'Calweekend';
           } 
            else if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth)
           {
                css_class = 'Calcurrent';
           }
           else
            {
                css_class = 'Calweekday';
            }
            
          table = table + "<td><a class='"+css_class+"' href=\"javascript:setCalendarControlDate("+currentYear+","+currentMonth+","+dayOfMonth+")\">"+dayOfMonth+"</a></td>";
          dayOfMonth++;

        } 
        else 
        {
          table = table + "<td class='Calempty'>&nbsp;</td>";
        }
      }
      table = table + "</tr>";
    }

    table = table + "<tr class='Calheader'><th colspan='7' style='padding: 3px;'><a href='javascript:clearCalendarControl();'>Clear</a></td></tr>";
    table = table + "</table>";
    return table;
  }
  
  this.show = show;
   

  function show(field)
  {    
    can_hide = 0;
    
    // If the calendar is visible and associated with
    // this field do not do anything.    

    if (dateField == field) 
    {
      return;
    } 
    else 
    {
      dateField = field;
    }
    if(dateField) 
    {      
      try 
      {
        var dateString = new String(dateField.value);
        var dateParts = dateString.split("/");
        
        selectedMonth = parseInt(dateParts[0],10);
        selectedDay = parseInt(dateParts[1],10);
        selectedYear = parseInt(dateParts[2],10);
      }       
      catch(e) {}
    }


    if (!(selectedYear && selectedMonth && selectedDay)) 
    {
        //if(HotelId==18)
        //{
        selectedMonth = 1;
        //}
        //else
        //{
        selectedMonth = temp;
        //}
        selectedDay = getCurrentDay();
        selectedYear = getCurrentYear();
    } 

    currentMonth = selectedMonth;
    currentDay = selectedDay;
    currentYear = selectedYear;
        
    if(document.getElementById)
    {
      calendar = document.getElementById(calendarId);
      calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
      
      setProperty('display', 'block');
      var fieldPos = new positionInfo(dateField);
     
      var calendarPos = new positionInfo(calendarId);
      var x = fieldPos.getElementLeft(); 
      var y = fieldPos.getElementBottom();
      setProperty('left', x + "px");
      setProperty('top', y + "px");

      
      if (document.all) 
      { 
        setElementProperty('display', 'block', 'CalendarControlIFrame');
        setElementProperty('left', x + "px", 'CalendarControlIFrame');
        setElementProperty('top', y + "px", 'CalendarControlIFrame');
        setElementProperty('width', calendarPos.getElementWidth() + "px", 'CalendarControlIFrame');
        setElementProperty('height', calendarPos.getElementHeight() + "px", 'CalendarControlIFrame');
      }
    }
  }
  
  this.hide = hide;
   
  function hide() 
  {
    if(dateField) 
    {
      setProperty('display', 'none'); 
      setElementProperty('display', 'none', 'CalendarControlIFrame');
      dateField = null;
    }
  }

  this.visible = visible; 

  function visible() 
  {
      return dateField
  }

  this.can_hide = can_hide;
  var can_hide = 0;
}

var calendarControl = new CalendarControl();
 

function showCalendarControl(textField, checkOutField, personField)

 {
 
checkOutField = checkOutField + '';
personField = personField + '';
  checkOut=0;

 blnCheckIn = true;

  temp=new Date().getMonth() + 1; 

  calendarControl.show(textField);
  elmCheckIn = textField;
  if (checkOutField != null || checkOutField != "")
  {
    elmCheckOut = document.getElementById(checkOutField);
  } 
  if (checkOutField == "undefined" || checkOutField == "" )
  {
    blnCheckIn = false;
  }
 
  if (personField != null || personField != "")
  {  
  elmPerson = document.getElementById(personField);
  blnPerson = true;
  }
   else
  {
    blnCheckIn = false;
  }
  if (personField == "" || personField == "undefined")
  {
    blnPerson = false;
    blnCheckIn = false;
  }
  
 }
 


function showCalendarControlFeedBackForm(textField, checkoutID)
{
	// textField.onblur = hideCalendarControl;
	checkOut=1;
	blnCheckIn = false;
	controlID=checkoutID.id;

	var val = document.getElementById(controlID).value.toLowerCase();
    if(val != "" && val != "check in")
    {
        temp = new Date(document.getElementById(controlID).value).getMonth() + 1;
		calendarControl.show(textField);
    }
    else
    {
		checkOut = 0;
		temp = new Date().getMonth() + 1;
		calendarControl.show(textField);
    }
}


 
function FillCheckOutAndPerson()
{       
    var checkInValue = elmCheckIn.value;
    var checkDate = new Date(checkInValue); 
    
    checkDate.setDate(checkDate.getDate()+1)
    checkDate = formatDate(checkDate)
  
    if(checkDate!="NaN/NaN/NaN")
    {
    elmCheckOut.value = checkDate;
    }
    else
    {
    return;
    }
    if (blnPerson == true)
    {
        if (elmPerson.selectedIndex == 0)
        {
            elmPerson.selectedIndex = 1;
        }
    }
}

 
function formatDate(objDate)
{
    var day = objDate.getDate();    
    var month = objDate.getMonth()+1;
    var year = objDate.getFullYear();
    if (month < 10) {month = "0" + month;}
    if (day < 10) {day = "0" + day;}
    var dateString = month+"/"+day+"/"+year;
    return dateString;     
}

 

function showCalendarControl1(textField,checkoutID)
{
    // textField.onblur = hideCalendarControl;
    checkOut=1;
    blnCheckIn = false;
    controlID=checkoutID.id;
    var val = document.getElementById(controlID).value.toLowerCase();
 
    if(val != "" &&  val != "check in" && val != "start date" && val != "arrival")
    {
        temp = new Date(document.getElementById(controlID).value).getMonth() + 1;
    }
    else
    {
	    checkOut = 0;
        temp = new Date().getMonth() + 1;
    }
    calendarControl.show(textField);
}
 

function clearCalendarControl()
{
  calendarControl.clearDate();
}

 

function hideCalendarControl()
{
  if (calendarControl.visible()) 
  {
     calendarControl.hide();
  }
}

function hideCalendarControl() 
{
  if (calendarControl.visible())
  {
     calendarControl.hide();
  }
}

 
function setCalendarControlDate(year, month, day) 
{ 
    if(checkOut==1)
    {
	    if(document.getElementById(controlID).value!="")		
	    {			
	       curyear=new Date(document.getElementById(controlID).value).getFullYear();			
	       curmonth=new Date(document.getElementById(controlID).value).getMonth()+1;			
	       curday=new Date(document.getElementById(controlID).value).getDate()+1;			
	    }			
	    else			
	    {			
	      curyear = new Date().getYear();		
		 
	     if(curyear < 1900) curyear += 1900;			 
	        curmonth= new Date().getMonth() + 1;
	        curday=new Date().getDate();
	    }

     }
     else
     { 
       curyear = new Date().getYear();
        if(curyear < 1900) curyear += 1900; 
         curmonth= new Date().getMonth() + 1;
        curday=new Date().getDate();
     }

     if(curyear==year || checkLocation() == true)
     {
        if(curmonth==month || checkLocation() == true)
        {
            if(curday > day && checkLocation() == false)
            { 
                //alert("The date should be greater then current date");
            }
            else
            {
                calendarControl.setDate(year, month, day);
            }
        }
        else
        {
            calendarControl.setDate(year, month, day);
        }
    }
    else
    {
        calendarControl.setDate(year, month, day);
    }
    
    if (blnCheckIn)
    {       
        FillCheckOutAndPerson()
    }
}

 

function changeCalendarControlYear(change) 
{
  calendarControl.changeYear(change);
} 

function changeCalendarControlMonth(change)
{
  calendarControl.changeMonth(change);
}

 
function checkLocation()
{
	var arrLocation = new Array();
        arrLocation.push("http://www.oberoihotels.com/contactus/feedback-test.aspx");
	arrLocation.push("http://www.oberoihotels.com/contactus/feedback.aspx");
	arrLocation.push("http://www.oberoizahra.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoimenahouse.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoisahlhasheesh.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoiphilae.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoidelhi.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoimumbai.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoibangalore.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoikolkata.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.amarvilas.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoirajvilas.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.udaivilas.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.vanyavilas.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.wildflowerhall.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.thececil.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoivrinda.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoibali.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoilombok.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoi-mauritius.com/hotel/contactus_feedback.aspx");
	arrLocation.push("http://www.oberoimadina.com/hotel/contactus_feedback.aspx");

	var loc = window.location.toString().toLowerCase();
    for (var x=0; x<arrLocation.length; x++)
    {
        if (loc.indexOf(arrLocation[x]) != -1)
			return true;						
    }

	return false;
}

document.write("<iframe id='CalendarControlIFrame' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>");

document.write("<div id='CalendarControl'></div>");