/*

To Do:
1) Add date range from and to restriction - i.e. forward only from today or from ##/##/#### to ##/##/#### only...
2) Add time option to output - i.e. ##/##/#### 12:00:00 AM/PM - maybe add default time value as well

*/
    var length;
    var ctlEndDate="01/01/1970"
    var format="mm/dd/yyyy"
    var type=""
	var iCalWidth = 155
	var iCalHeight = 135
	var	fixedX = -1 // x position (-1 if to appear below control)
	var	fixedY = -1 // y position (-1 if to appear below control)
	var startAt = 0 // 0 - sunday ; 1 - monday
	var showWeekNumber = 0	// 0 - don't show; 1 - show
	var showToday = 1		// 0 - don't show; 1 - show
	var imgDir = "include/controls/popup_cal/"	// directory for images ... e.g. var imgDir="/img/"
	var bShowFullDayName = false //whether to display T or Tue on day headings
	 var forwardallow= '0';
	 var backallow= '0';
	//UI vars for control messages
	var gotoString = "Go To Current Month"
	var todayString = "Today is"
	var weekString = "Wk"
	var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically."
	var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically."
	var selectMonthMessage = "Click to select a month."
	var selectYearMessage = "Click to select a year."
	var selectDateMessage = "Select [date] as date." // do not replace [date], it will be replaced by date.

	//vars related to whether data was selected and what each data point selected was
	var crossobj="", crossMonthObj, crossYearObj;
	var monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected;
	var monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2;
	var ctlNow, dateFormat, nStartingYear;
	
    //form elements to place selected date(s) into
    var ctlToPlaceValue, ctlToPlaceEndDateValue;

	var bPageLoaded=false
	var ie=document.all //check to see browser type
	var dom=getObj 

	var ns4=document.layers
	var today =	new	Date()
	var dateNow	 = today.getDate()
	var monthNow = today.getMonth()
	var yearNow	 = today.getYear()
	var imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif")
	var img	= new Array()

	var bShow = false;
	var objName;
	var noOfYears;
	var checkin;
	var checkout;
	
	var startDate= new Date('10/23/2007');
	
	var endDate= new Date('10/23/2008');
	
	
    /* hides <select> and <applet> objects (for IE only) */
	function getObj(objID) 
	{
	    if (document.getElementById)
	    {
	        return document.getElementById(objID);
	    }
	    else if (document.all)
	    {
	        return document.all[objID];
	    }
	    else if (document.layers)
	    {
	        return document.layers[objID];
	    }
	}
	
	//* call in popUpCalendarUser()
    function hideElement( elmID, overDiv )
    {      
        if( ie )
        {
            for( i = 0; i < document.all.tags( elmID ).length; i++ )
            {
                obj = document.all.tags( elmID )[i];
                if( !obj || !obj.offsetParent )
                {
                    continue;
                }
      
          // Find the element's offsetTop and offsetLeft relative to the BODY tag.
		  
                objLeft   = obj.offsetLeft;
                objTop    = obj.offsetTop;
                objParent = obj.offsetParent;

                while( objParent.tagName.toUpperCase() != "BODY" )
                {
                    objLeft  += objParent.offsetLeft;
                    objTop   += objParent.offsetTop;
                    objParent = objParent.offsetParent;
                }
      
                objHeight = obj.offsetHeight;
                objWidth = obj.offsetWidth;
      	        if (overDiv !=null)
      	        {
	                if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
	                else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
	                else if( overDiv.offsetTop >= ( objTop + objHeight ));
	                else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
	                else
	                {
	                obj.style.visibility = "hidden";	           
	                }
		        }
		  
            }
        }
    }
     
    /*
    * unhides <select> and <applet> objects (for IE only)
    */
    //* call in hideCalendar()
    function showElement( elmID )
    {
      if( ie )
        {
            for( i = 0; i < document.all.tags( elmID ).length; i++ )
            {
                obj = document.all.tags( elmID )[i];
          
                if( !obj || !obj.offsetParent )
                {
                    continue;
                }
        
                obj.style.visibility = "";
            }
        }
    }
// * get day month year and description
// * call in addHoliday ()
	function HolidayRec (d, m, y, desc)
	{
		this.d = d
		this.m = m
		this.y = y
		this.desc = desc
	}

	var HolidaysCounter = 0
	var Holidays = new Array()
    // * add holidays get day,month,year and description
	function addHoliday (d, m, y, desc)
	{
		Holidays[HolidaysCounter++] = new HolidayRec ( d, m, y, desc )
	}

	//write div containing calendar and place holders for cal header and calendar content
	if (dom)// dom=documnet.getElementId
	        
	{
		for	(i=0;i<imgsrc.length;i++)
		{
			img[i] = new Image
			img[i].src= imgDir + imgsrc[i]
		}

    	document.write ("<div onclick='bShow=true' id='calendar' class='div-style'><table width="+ iCalWidth + " cellpadding=1 cellspacing=0 class='table-style' height=" + iCalHeight + "><tr class='title-background-style'><td height=13><table cellpadding=0 cellspacing=0 width=100%><tr><td class='title-style' height=13 valign=top><span id='caption'></span></td><td align=right width=15><a href='javascript:hideCalendar()'><img src='"+imgDir+"close.gif' width='15' id='closeimg' height='13' border='0' alt='Close the Calendar'></a></td></tr></table></td></tr><tr><td class='body-style' valign=top><span id='content'></span></td></tr>")

		if (showToday==1)
		{
			document.write ("<tr class='today-style'><td><span id='lblToday' class='body-style'></span></td></tr>")
		}
			
		document.write ("</table></div><div id='selectMonth' class='div-style' style=\"width:58px\"></div><div id='selectYear' class='div-style'></div>");
	}
	
	

	var	monthName =	new	Array("January","February","March","April","May","June","July","August","September","October","November","December")
	var	monthName2 = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")
		
	if (startAt==0)
	{
		if (bShowFullDayName == false)
		{
			dayName = new Array	("S","M","T","W","T","F","S")
		}
		else
		{
			dayName = new Array	("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
		} 
	}
	else
	{	
		if (bShowFullDayName == false)
		{
			dayName = new Array	("M","T","W","T","F","S","S")
		}
		else
		{
			dayName = new Array	("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
		}
	}

	function swapImage(srcImg, destImg)
	{
		if (ie)
		{
		    getObj(srcImg).setAttribute("src",imgDir + destImg)
		}
	}
// * set header of  calender
// * call in popUpCalendarUser()
	function init()
	{
		if (!ns4)
		{			
			if (!ie)
			{
			   yearNow += 1900
			
			}

			crossobj=(dom)?getObj("calendar").style : ie? document.all.calendar : document.calendar
			hideCalendar()

			crossMonthObj=(dom)?getObj("selectMonth").style : ie? document.all.selectMonth	: document.selectMonth

			crossYearObj=(dom)?getObj("selectYear").style : ie? document.all.selectYear : document.selectYear

			monthConstructed=false;
			yearConstructed=false;

			if (showToday==1)
			{
				if (bShowFullDayName == false)
				{
					var sToday = monthName[monthNow].substring(0,3) + " " +  dateNow +  " " + yearNow
				}
				else
				{ 
					var sToday = dayName[(today.getDay()-startAt==-1)?6:(today.getDay()-startAt)]+", " + dateNow + " " + monthName[monthNow].substring(0,3) + "	" +	yearNow
				}				
				getObj("lblToday").innerHTML =	todayString + " <a class='today-style' onmousemove='window.status=\""+gotoString+"\"' onmouseout='window.status=\"\"' title='"+gotoString+"' href='javascript:monthSelected=monthNow;yearSelected=yearNow;constructCalendar();'>" +	sToday + "</a>"
			}
	
			///*make calendar header fixed width so that header does not "flop" around			
				
			sHTMLCalHead = "<table cellpadding=0 cellspacing=0><tr>"			
			sHTMLCalHead+="<td id='spanLeft' height=13 width=10 valign=top class='title-control-normal-style' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.className=\"title-control-select-style\";window.status=\""+scrollLeftMessage+"\"' title=\""+scrollLeftMessage+"\" onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.className=\"title-control-normal-style\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'><img id='changeLeft' src='"+imgDir+"left1.gif' width=10 height=11 border=0></td>"
			sHTMLCalHead+="<td id='spanRight' height=13 width=10 valign=top class='title-control-normal-style' onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.className=\"title-control-select-style\";window.status=\""+scrollRightMessage+"\"' title=\""+scrollRightMessage+"\" onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.className=\"title-control-normal-style\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)' onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'><img id='changeRight' src='"+imgDir+"right1.gif' width=10 height=11 border=0></td>"
			sHTMLCalHead+="<td id='spanMonth' height=13 width=70 valign=top class='title-control-normal-style' onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.className=\"title-control-select-style\";window.status=\""+selectMonthMessage+"\"' title=\""+selectMonthMessage+"\" onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.className=\"title-control-normal-style\";window.status=\"\"' onclick='popUpMonth()'></td>"
			sHTMLCalHead+="<td id='spanYear' height=13 valign=top class='title-control-normal-style' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.className=\"title-control-select-style\";window.status=\""+selectYearMessage+"\"' title=\""+selectYearMessage+"\" onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.className=\"title-control-normal-style\";window.status=\"\"'	onclick='popUpYear()'></td>"
			sHTMLCalHead+= "</tr></table>"
			//*/
			getObj("caption").innerHTML  =	sHTMLCalHead

			bPageLoaded=true
		}
	}

	function hideCalendar()
	{
		crossobj.visibility="hidden"
		if (crossMonthObj != null)
		{
		    crossMonthObj.visibility="hidden"
		}
		if (crossYearObj !=	null)
		{
		    crossYearObj.visibility="hidden"
		}

		showElement( 'SELECT' );
		showElement( 'APPLET' );
	}
// * call in constructDate()
	function padZero(num)
	{
		return (num	< 10)? '0' + num : num ;
	}

	//controls formatting of date
	//* call in closeCalendar(),ChDate(),constructCalendar (), 
	function constructDate(d,m,y)
	{
	   
		sTmp = dateFormat
		sTmp = sTmp.replace	("dd","<e>")
		sTmp = sTmp.replace	("d","<d>")
		sTmp = sTmp.replace	("<e>",padZero(d))
		sTmp = sTmp.replace	("<d>",d)
		if(type=="1")
		{
		    sTmp = sTmp.replace (" ","/")
		  //comment this out to remove /
		}
		sTmp = sTmp.replace	("mmm","<o>")
		sTmp = sTmp.replace	("mm","<n>")
		sTmp = sTmp.replace	("m","<m>")
		sTmp = sTmp.replace	("<m>",m+1)		
		sTmp = sTmp.replace	("<n>",padZero(m+1))
		if(type=="1")
		{
		    sTmp = sTmp.replace	("<o>",monthName[m])
		    
		}
		else
		{
		    sTmp = sTmp.replace	("<o>",monthName2[m])
		}
		sTmp = sTmp.replace ("yyyy",y)
		//return sTmp.replace ("yyyy",y) //original code
		if(type=="1")
		{
		
		    return sTmp.replace (" ","/") //comment this out to remove /
		}
		else
		{
		    return sTmp.replace ("yy",padZero(y%100))
		}
		
	}

	//handles setting of actual dat value in form field
	// *call in constructCalendar()
	function closeCalendar()
	{
		try
		{	
			var	sTmp;
			hideCalendar();
			if(type=="1")
			{
			    ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected)
			   
			    if (ctlToPlaceValue.name=="txtDateFr")
			    {
			        setValue("1");
			    }
			    else
			    {
			        setValue("2");
			    }
			    if(ctlToPlaceEndDateValue!=null)
			    { //place value in end date if end date control passed/present
					ctlToPlaceEndDateValue.value =	ctlToPlaceValue.value;
					setExpDate(objName);
			    }
			}
			else
			{
//			    if(ChDate())
//			    {
			        ctlToPlaceValue.value =	constructDate(dateSelected,monthSelected,yearSelected)
//			    }
			}			
		}
		catch(er)
		{
				alert(er);
		}  		
	}

// * call in closeCalendar()
function ChDate()
{
        var FDate=constructDate(dateSelected,monthSelected,yearSelected)
	    currdate = new Date();
        currdate.setDate(currdate.getDate());

        var month="";
        var year="";
        var day="";
       	
        year=currdate.getFullYear();
        month=currdate.getMonth();
        day=currdate.getDate(); 
        
        var cdate=month+1+"/"+day+"/"+year;
        
        dtStartDate = new Date(cdate); 
        dtEndDate = new Date(FDate); 
            
        if (dtEndDate.getTime() < dtStartDate.getTime())
        {
            alert('Please Enter Current OR Future Date');
            return false;	                
        }
        return true;
}


	/*** Start Month Pulldown ***/
       //* set the interval of given method
	function StartDecMonth()
	{
		intervalID1=setInterval("decMonth()",80)
		
	}
       //* set the interval of given method
	function StartIncMonth()
	{
		intervalID1=setInterval("incMonth()",80)
	}
      // * if selected month is  last month of year then next month will be first month of next year
      //* call in init()
	function incMonth ()
	{
	
			if(forwardallow == '1')
		{
		return ;
		}

		monthSelected++
		if (monthSelected>11)
		{
			monthSelected=0
			yearSelected++
		}
		constructCalendar()
	}
// * if selected month is first month of year then month of last year is last month
// * call in init()
	function decMonth ()
	{
	
		if(backallow == '1')
	     {
		return ;
		 }
		
		monthSelected--
		
		if (monthSelected<0) 
		{
			monthSelected=11
			yearSelected--
		}
		constructCalendar()
	}
	
// * call in popUpMonth() 
	function constructMonth() 
	{
		popDownYear()
		
//		if (!monthConstructed) 
//		{
           
			
			
			if(startDate != null && endDate != null)
			{
			sHTML =	""
			 if(yearSelected == yearNow)
             {
             for	(i=monthNow; i<12;	i++) 
			{
			
				sName =	monthName[i];
				
			if(i >= monthSelected)
				{
				if(i == monthSelected)
				{
				sName =	"<B>" +	sName +	"</B>"
				}

				}
				sHTML += "<tr><td id='m" + i + "' onmouseover='this.className=\"dropdown-select-style\"' onmouseout='this.className=\"dropdown-normal-style\"' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
				
			}
			getObj("selectMonth").innerHTML = "<table class='dropdown-style' cellspacing=0 cellpadding=1 onmouseover='clearTimeout(timeoutID1)' onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"\",100);event.cancelBubble=true'>" + sHTML + "</table>"

			monthConstructed=true
          
          }
      
          else if(yearSelected > yearNow)
          {
          for	(i=0; i <= monthNow;	i++) 
			{
				sName =	monthName[i];
				
              if(i == monthSelected)
				{
				sName =	"<B>" +	sName +	"</B>"
				}
				
				sHTML += "<tr><td id='m" + i + "' onmouseover='this.className=\"dropdown-select-style\"' onmouseout='this.className=\"dropdown-normal-style\"' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
				
			}
          getObj("selectMonth").innerHTML = "<table class='dropdown-style' cellspacing=0 cellpadding=1 onmouseover='clearTimeout(timeoutID1)' onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" + sHTML + "</table>"

          monthConstructed=true
          }	
          
          
          }	
		else // old code 23oct
		{
		if (!monthConstructed) 
		{
			sHTML =	""
			for	(i=0; i<12;	i++) 
			{
				sName =	monthName[i];
				if (i==monthSelected)
				{
					sName =	"<B>" +	sName +	"</B>"
				}
				sHTML += "<tr><td id='m" + i + "' onmouseover='this.className=\"dropdown-select-style\"' onmouseout='this.className=\"dropdown-normal-style\"' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
			}

			getObj("selectMonth").innerHTML = "<table class='dropdown-style' cellspacing=0 cellpadding=1 onmouseover='clearTimeout(timeoutID1)' onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" + sHTML + "</table>"

			monthConstructed=true
		}
		
		
		}
	}
// * asign the left & top lenth of popmonth
// * call in init()
	function popUpMonth() 
	{
		constructMonth()
		crossMonthObj.visibility = (dom||ie)? "visible"	: "show"
		if(type=="1")
		{
		    crossMonthObj.left = parseInt(crossobj.left) + 20 // x offset of month selector
		    crossMonthObj.top =	parseInt(crossobj.top) + 16 // y offset of month selector
		}
		else
		{
		    crossMonthObj.left = (parseInt(crossobj.left) + 30) + "px";
		    crossMonthObj.top =	(parseInt(crossobj.top) + 20) + "px";
		}
	}

	function popDownMonth()
	{
		crossMonthObj.visibility= "hidden"
	}

	/*** END Month Pulldown ***/
	/*** Start Year Pulldown ***/
// * increase the year in popdown year in calender
	function incYear() 
	{
	return; 
		for	(i=0; i<7; i++){
			newYear	= (i+nStartingYear)+1
			if (newYear==yearSelected)
			{ 
			    txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;"
			}
			else
			{
			    txtYear =	"&nbsp;" + newYear + "&nbsp;" 
			}
			getObj("y"+i).innerHTML = txtYear
		}
		nStartingYear ++;
		bShow=true
	}
      //* decrease the year in popdown year in calender
     
     function decYear()
	   {
		return ;
		for	(i=0; i<7; i++)
		{
			newYear	= (i+nStartingYear)-1
			if (newYear==yearSelected)
			{ 
			    txtYear =	"&nbsp;<B>"	+ newYear +	"</B>&nbsp;" 
			}
			else
			{ 
			    txtYear =	"&nbsp;" + newYear + "&nbsp;" 
			}
			getObj("y"+i).innerHTML = txtYear
		}
		nStartingYear --;
		bShow=true
		
	}
// * select the given year 
// call in constructYear()
	function selectYear(nYear) 
	{
		yearSelected=parseInt(nYear+nStartingYear);
		yearConstructed=false;
		constructCalendar();
		popDownYear();
	}

	function constructYear() 
	{
		popDownMonth()
		
		
			
			
		sHTML =	""
		if (!yearConstructed) 
		{ 
        
			//naresh 23oct
			if (startDate !=null && endDate!=null)
			{
			sHTML =	"<tr><td align='center' onmouseover='this.className=\"dropdown-select-style\"' >	</td></tr>"
			//sHTML =	"<tr><td align='center'	onmouseover='this.className=\"dropdown-select-style\"' onmouseout='clearInterval(intervalID1);this.className=\"dropdown-normal-style\"' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'></td></tr>"
			}
			else
			{
			sHTML =	"<tr><td align='center'	onmouseover='this.className=\"dropdown-select-style\"' onmouseout='clearInterval(intervalID1);this.className=\"dropdown-normal-style\"' onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"
			}
			j =	0
			
			//nStartingYear =	yearSelected-3 
			nStartingYear = startDate.getFullYear();
			nEndingYear = endDate.getFullYear();

			for	(i=(nStartingYear); i<=(nEndingYear); i++) 
			//for	(i=(nStartingYear); i<=(yearSelected+3); i++) 	
			{
				sName =	i;
				if (i==yearSelected)
				{
					sName =	"<B>" +	sName +	"</B>"
				}
                            
				sHTML += "<tr><td id='y" + j + "' onmouseover='this.className=\"dropdown-select-style\"' onmouseout='this.className=\"dropdown-normal-style\"' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
				
				j ++;
			}
             // naresh 23oct    
             if (startDate !=null && endDate!=null)
			{
			 sHTML += "<tr><td align='center'> </td></tr>"
			 }
			else
			{
			  sHTML += "<tr><td align='center' onmouseover='this.className=\"dropdown-select-style\"' onmouseout='clearInterval(intervalID2);this.className=\"dropdown-normal-style\"' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'	onmouseup='clearInterval(intervalID2)'>+</td></tr>"
			}

			getObj("selectYear").innerHTML	= "<table width=44 class='dropdown-style' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"	+ sHTML	+ "</table>"

		yearConstructed	= true
		
	}
	}
//* clear the interval time 
	function popDownYear() 
	{
		clearInterval(intervalID1)
		clearTimeout(timeoutID1)
		clearInterval(intervalID2)
		clearTimeout(timeoutID2)
		crossYearObj.visibility= "hidden"
	}
// * call in init()
	function popUpYear() 
	{
		var	leftOffset

		constructYear()
		
		crossYearObj.visibility	= (dom||ie)? "visible" : "show"
		leftOffset = parseInt(crossobj.left) + getObj("spanYear").offsetLeft
		if(type=="1")
		{
		    if (ie)
		    {
			   
			    leftOffset += 1 // x offset of year selector
		    }
		    crossYearObj.left =	leftOffset
		    crossYearObj.top = parseInt(crossobj.top) +	16 // y offset of year selector
		}
		else
		{

		    leftOffset += 6
		    crossYearObj.left =	leftOffset + ".";
		    crossYearObj.top = (parseInt(crossobj.top) +	20) + "px";
		}
	}

	/*** END Year Pulldown ***/
	
	/*** Start actual calendar code which builds string of calendar content***/
     // * get the date and return number of week
     // * call in constructCalender()
	function WeekNbr(today)
    {
		
		Year = takeYear(today);
		Month = today.getMonth();
		Day = today.getDate();
		now = Date.UTC(Year,Month,Day+1,0,0,0);
		var Firstday = new Date();
		Firstday.setYear(Year);
		Firstday.setMonth(0);
		Firstday.setDate(1);
		then = Date.UTC(Year,0,1,0,0,0);
		var Compensation = Firstday.getDay();
		if (Compensation > 3) Compensation -= 4;
		else Compensation += 3;
		NumberOfWeek =  Math.round((((now-then)/86400000)+Compensation)/7);
		return NumberOfWeek;
	}
       //* return year
       //* call in weekNbr
	function takeYear(theDate)
	{
		x = theDate.getFullYear();
		var y = x % 100;
		y += (y < 38) ? 2000 : 1900;
		return y;
	}

	//builds string containing HTML table that is calender
	
	
	function constructCalendar() 
	{
       
	if(yearSelected == yearNow && monthSelected < monthNow )// ||
			
			{
		     
		     yearSelected = yearNow ;
			 monthSelected = monthNow ;
			
			}
			else if ( yearSelected != yearNow && monthSelected > monthNow  )//  || yearSelected != yearNow 
			{
			
			yearSelected = yearNow + 1 ;
           
            monthSelected = monthNow ;
   
            }

  
    // * 	 iCalWidth = 155
	    forwardallow= '0';
	    backallow= '0';

		var iDateCelWidth = (iCalWidth/7) - 4
		var dateMessage
		var	startDate =	new	Date (yearSelected,monthSelected,1)
		var	endDate	= new Date (yearSelected,monthSelected+1,1);
		endDate	= new Date (endDate	- (24*60*60*1000));
		numDaysInMonth = endDate.getDate()
		
		datePointer	= 0
		dayPointer = startDate.getDay() - startAt  //*var startAt = 0 // 0 - sunday ; 1 - monday
		
		if (dayPointer<0)
		{
			dayPointer = 6
		}

		sHTML =	"<table	border=0 cellspacing=0 cellpadding=1 width=100%><tr>"

		if (showWeekNumber==1)
		{
			sHTML += "<td width=" + iDateCelWidth + ">" + weekString + "</td><td width=1 rowspan=7 class='weeknumber-div-style'><img src='"+imgDir+"divider.gif' width=1></td>"
		}

		for	(i=0; i<7; i++)	
		{
			
			// day header style
			sHTML += "<td align='right' class='dayheader-style' width=" + iDateCelWidth + ">"+ dayName[i]+"</td>"
		}
		sHTML +="</tr><tr>"
		
		if (showWeekNumber==1)
		{
			sHTML += "<td align=right width=" + iDateCelWidth + ">" + WeekNbr(startDate) + "</td>"
		}

		for	( var i=1; i<=dayPointer;i++ )
		{
			sHTML += "<td width=" + iDateCelWidth + ">&nbsp;</td>"
		}
		//Start writing cells with dates in them
		for	( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
		{
		
		 if((datePointer == numDaysInMonth) && (( dayPointer % 7)  == 6 )){
		 
           }
        else{
         dayPointer++;
          }
		  // dayPointer++;
			sHTML += "<td align=right width=" + iDateCelWidth + ">"

			var sStyle="normal-day-style"; //regular day
		
		
		//* naresh	
		
		if (startDate != null && endDate != null)
		{
		// previous date of current date
		  if ((datePointer < dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
		     { 
		  if (datePointer == 1 )
		         {
		         
				  backallow='1';
				     }
				     				  sStyle = "pre-day-style"; 

			    }
        // next date from current date of next year
          if ((datePointer > dateNow)&&(monthSelected==monthNow)&&(yearSelected !=yearNow)) 
				  {
				  
				  if (datePointer == numDaysInMonth )
		           {
				  forwardallow='1';
				   }
				   				  sStyle = "pre-day-style"; 

				  }
				  
//       if(monthSelected==7)
//       {
//        sStyle = "pre-day-style"; 
//       }
    
			
			
			if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) //today
			{ 
			    sStyle = "current-day-style"; 
			} 
			else if	(dayPointer % 7 == (startAt * -1) +1) //end-of-the-week day
			{ 
			    sStyle = "end-of-weekday-style"; 
			}
         //* naresh  for sunday
           if	((dayPointer % 7 == (startAt * -1) +1)&& (datePointer < dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
            { 
         
			    sStyle = "pre-day-style"; 
			}
			// for Next year and current year and sunday
			if	((dayPointer % 7 == (startAt * -1) +1)&& (datePointer > dateNow)&&(monthSelected==monthNow)&&(yearSelected !=yearNow))
            { 
         
			    sStyle = "pre-day-style"; 
			}
			
			
          //*naresh  
          }
          else // old code 23oct
          {
          if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) //today
			{ 
			    sStyle = "current-day-style"; 
			} 
			else if	(dayPointer % 7 == (startAt * -1) +1) //end-of-the-week day
			{ 
			    sStyle = "end-of-weekday-style"; 
			}
          }   
			//selected day
			if ((datePointer==odateSelected) &&	(monthSelected==omonthSelected)	&& (yearSelected==oyearSelected))
			{ 
			    sStyle += " selected-day-style"; 
			}

			sHint = ""
			for (k=0;k<HolidaysCounter;k++)
			{
				if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
				{
					if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
					{
						sStyle += " holiday-style";
						sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
					}
				}
			}

			var regexp= /\"/g
			sHint=sHint.replace(regexp,"&quot;")
            if(type=="1")
            {
            
			    dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "
			
		        sHint = selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected));
		        //* nareshdate
		        if ((datePointer < dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) 
		        {
		   
			    sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" "+datePointer+"'>" + datePointer + "</a>"
			    }
			    else if (   ((datePointer > dateNow)&&(monthSelected==monthNow)&&(yearSelected !=yearNow)) )
			    {
			     sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" "+datePointer+"'>" + datePointer + "</a>"
			    }
			    else 
			    {
			    sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" href='javascript:dateSelected="+datePointer+";closeCalendar();'>" + datePointer + "</a>"
			    }
			    
            }
            else
            {
                dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "
			    sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" href='javascript:dateSelected="+datePointer+";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>"
            }
			sHTML += ""
			if ((dayPointer+startAt) % 7 == startAt) 
			{ 
				sHTML += "</tr><tr>" 
				if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
				{
					sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "</td>"
				}
			}
		}
		sHTML+="<div onclick='bShow=true' id='calendar' class='div-style'><table width="+ iCalWidth + " cellpadding=1 cellspacing=0 class='table-style' height=" + iCalHeight + "><tr class='title-background-style'><td height=13><table cellpadding=0 cellspacing=0 width=100%><tr><td class='title-style' height=13 valign=top><span id='caption'></span></td><td align=right width=15><a href='javascript:hideCalendar()'><img src='"+imgDir+"close.gif' width='15' height='13' border='0' alt='Close the Calendar'></a></td></tr></table></td></tr><tr><td class='body-style' valign=top><span id='content'></span></td></tr>"		
		//write string to calendar content placeholder
		getObj("content").innerHTML  = sHTML

		getObj("spanMonth").innerHTML = "&nbsp;" +	monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
		getObj("spanYear").innerHTML =	"&nbsp;" + yearSelected	+ "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
		
		
		
		
	}

//* 
//* call in closeCalendar()
     function setExpDate(iID)
	{
		if(iID.substring(iID.length - 3,iID.length) == "Enr")
		{
			var ArrayOfDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
			tb = iID.substring(0,iID.length - 3) + "Exp"
			obj = getObj(iID)
			dt =obj.value;
			mm = dt.substring(0,2)
			dd = dt.substring(3,5)
			yy = parseInt(dt.substring(6,10))
			yy = yy + parseInt(noOfYears)
			obj = getObj(tb);
			obj.value= mm + "/" + dd + "/" + yy
		}	
	}
	
function getDays(GivenYear)
{
	if((GivenYear % 4 == 0 && GivenYear % 100 !=0 ) || (GivenYear % 100 == 0 && GivenYear % 400 ==0 ))
		return 29;
	else
		return 28;
}	
	
	//handles building calendar - this is the function that is called by page controls to do calendar functionality
	function popUpCalendarUser(ctl, ctl3)
	{
	
	    ctl2=getObj(ctl3)
	    type=1
		var	leftpos=0; // (x) location on page of element calling this function - used to hide selects near calendar
		var	toppos=0; // (y) location on page of element calling this function - used to hide selects near calendar
		objName = ctl2.name;

	    try
	    {	
			if (bPageLoaded)
			{
				if ( crossobj.visibility ==	"hidden" ) 
				{
					ctlToPlaceValue = ctl2;
					if(ctlEndDate!=null)
					{
						ctlToPlaceEndDateValue = ctlEndDate;
					}
					dateFormat=format;			

					formatChar = " "
					aFormat	= dateFormat.split(formatChar)
					if (aFormat.length<3)
					{
						formatChar = "/"
						aFormat	= dateFormat.split(formatChar)
						if (aFormat.length<3)
						{
							formatChar = "."
							aFormat	= dateFormat.split(formatChar)
							if (aFormat.length<3)
							{
								formatChar = "-"
								aFormat	= dateFormat.split(formatChar)
								if (aFormat.length<3)
								{
									// invalid date	format
									formatChar=""
								}
							}
						}
					}

					tokensChanged =	0
					if ( formatChar	!= "" )
					{					
						//CODE CHANGE - specify delimiter on date value so can split val properly
						formatChar = "/"
						
						// use user's date
						x = ctl2.value ;
						ctl2.value = "";
						aData =	ctl2.value.split(formatChar)
						ctl2.value = x;
						for	(i=0;i<3;i++)
						{
							if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
							{
								dateSelected = parseInt(aData[i], 10)
								tokensChanged ++
							}
							else if	((aFormat[i]=="m") || (aFormat[i]=="mm"))
							{							
								monthSelected =	parseInt(aData[i], 10) - 1 	
								tokensChanged ++
							}
							else if	(aFormat[i]=="yyyy")
							{
								yearSelected = parseInt(aData[i], 10)
								tokensChanged ++
							}
							else if	(aFormat[i]=="mmm")
							{
								for	(j=0; j<12;	j++)
								{
									if (aData[i]==monthName[j])
									{
										monthSelected=j
										tokensChanged ++
									}
								}
							}
						}
														
					}
		
					if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
					{
						dateSelected = dateNow
						monthSelected = monthNow		
						yearSelected = yearNow
					}				

					odateSelected=dateSelected
					omonthSelected=monthSelected
					oyearSelected=yearSelected

					aTag = ctl
					do
					{
						aTag = aTag.offsetParent;
						leftpos	+= aTag.offsetLeft;
						toppos += aTag.offsetTop;
					} while(aTag.tagName!="BODY");

					crossobj.left =	fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX
					crossobj.top = fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight : fixedY
					constructCalendar (1, monthSelected, yearSelected);
					crossobj.visibility=(dom||ie)? "visible" : "show"
					
					//make call to hide selects
					hideElement('SELECT', getObj("calendar"));
					hideElement('APPLET', getObj("calendar"));	
						
					bShow = true;
				}
			}
			else
			{
				init();
			}
		}
		catch(er)
		{
				alert(er);
		}  	
		
	}
	
	
    function BookHotel()
			{
		// This is Function is currently using		
			
			var chin=document.selectHotelForm.txtchin.value
    	    
            var chin_array=chin.split("/")
    
            var Imlength=chin_array[0].length;
            var Idlength=chin_array[1].length;
            var Iylength=chin_array[2].length;
    
            if(Imlength==1)
            {
                var Imonth=0+""+chin_array[0]
            }
            else
            {
                var Imonth=chin_array[0]
            }
            
			if(Idlength==1)
            {
                var Iday=0+""+chin_array[1]
            }
            else
            {
                var Iday=chin_array[1]
            }
            
			
			var chout=document.selectHotelForm.txtchout.value
    	    
            var chout_array=chout.split("/")
    
            var Omlength=chout_array[0].length;
            var Odlength=chout_array[1].length;
            var Oylength=chout_array[2].length;
    
            if(Imlength==1)
            {
                var Omonth=0+""+chout_array[0]
            }
            else
            {
                var Omonth=chout_array[0]
            }
            
			if(Idlength==1)
            {
                var Oday=0+""+chout_array[1]
            }
            else
            {
                var Oday=chout_array[1]
            }
				 
    			
   iRet = window.open("http://www.travelodge.com/Travelodge/control/Booking/check_avail?brandCode=TL,MQ,DI,HJ,KG,RA,SE&searchWithinMile"
                    +"s=25&areaType=1&destination=nanaimo&stateName=British%20Columbia&state=BC&countryName=Canada&country=CA&checkInDate="
                    + Imonth+"/"+Iday  + "&numberAdults=" + document.selectHotelForm.txtAdults.value + "&numberRooms=" + document.selectHotelForm.txtRooms.value + "&checkOutDate=" + Omonth+"/"+Oday+ "&numberChildren=" + document.selectHotelForm.txtChildren.value
                    + "&rateName=" + "Best%20Avail" + "&rate=LTWU&id=08770&propBrandId=TL&force_nostay=false"                   
  );  
	
	}
    
    
    
    
// *call in closeCalendar()
			
    function setValue(Action)
    {
    		
	    var dt
	    currdate = new Date();
        currdate.setDate(currdate.getDate());

        var month="";
        var year="";
        var day="";
       	
        year=currdate.getFullYear();
        month=currdate.getMonth();
        day=currdate.getDate(); 
        
        var cdate=month+1+"/"+day+"/"+year
        var cyear=(month)+"/"+31+"/"+(year+1)
       
	    if(Action == "1")
	    {
		    dt = getObj("txtDateFr").value   
		    obj1 = getObj("arrivalDay");   
		    obj2 = getObj("arrivalMonthYear");
	    }
	    else
	    {
		    dt = getObj("txtDateTo").value ;
		    obj1 = getObj("departureDay") ;   
		    obj2 = getObj("departureMonthYear")  ;

	    }
    	
	    if(dt != "")
	    {
		    mm = dt.substring(0,2)
		    dd = dt.substring(3,5)
		    yr=dt.substring(6,10);
		    if(dd<10)
		    {
		        dd=dd.substring(1,2)
		    }
		    dtStartYear = new Date(cyear);
		    dtStartDate = new Date(cdate); 
            dtEndDate = new Date(dt); 
            
            if (dtEndDate.getTime() < dtStartDate.getTime())
            {
                alert('Please Enter Current OR Future Date');
                return false;
            }
            if(dtEndDate.getTime()>dtStartYear.getTime())
            {
                alert('Please Enter Date within 1 Year');
                return false;
            }
		    else
		    {
		        obj2.value =yr+""+mm;
		        SetDate1(Action,mm,yr)
		        obj1.value = dd;
		       CompareDate1()
    		   
		       var Ival=getObj("arrivalMonthYear").value
		       var Iyear=Ival.substring(0,4)
		       var Imonth=Ival.substring(4,6)
    		   
		       var Oval=getObj("departureMonthYear").value
		       var Oyear=Oval.substring(0,4)
		       var Omonth=Oval.substring(4,6)
    		   
		       getObj("txtchin").value=Imonth+"/"+getObj("arrivalDay").value+"/"+Iyear
		       getObj("txtchout").value=Omonth+"/"+getObj("departureDay").value+"/"+Oyear
    		   
		       checkin=getObj("txtchin").value;
               checkout=getObj("txtchout").value;
		    }    					
	    }
    }


// * call in setValue()
function SetDate1(Dtype,month,year)
{
    SDcurrdate = new Date();    
    SDcurrdate.setDate(SDcurrdate.getDate());
	var SDday=0;
	SDday=SDcurrdate.getDate();

	var SDAindex=document.selectHotelForm.arrivalMonthYear.selectedIndex
	var SDDindex=document.selectHotelForm.departureMonthYear.selectedIndex
    
    if(Dtype==1)
    {
        if(SDAindex!=0)
        {
            var SDday=1
        }
       
        for(l=1;l<document.selectHotelForm.arrivalDay.options.length+1;l++)
        {
            document.selectHotelForm.arrivalDay.remove(l-1)
            l=l-1
        }
    }
    else
    {
        if(SDDindex!=0)
        {
	        var SDday=1
        }
        for(l=1;l<document.selectHotelForm.departureDay.options.length+1;l++)
        {
            document.selectHotelForm.departureDay.remove(l-1)
            l=l-1
        }
    }

    for(j=SDday;j<=31;j++)
	{
        var chdate=new Date(year,month-1,j)
        if(j==chdate.getDate())
	    {
	        if(Dtype==1)
	        {
	            var AoptionObject=new Option(j)
	            var AoptionRank = document.selectHotelForm.arrivalDay.options.length
	            document.selectHotelForm.arrivalDay.options[AoptionRank]=AoptionObject
	            document.selectHotelForm.arrivalDay.options[AoptionRank].value=j
	        }
	        else
	        {
	            var DoptionObject=new Option(j)
	            var DoptionRank = document.selectHotelForm.departureDay.options.length
	            document.selectHotelForm.departureDay.options[DoptionRank]=DoptionObject
	            document.selectHotelForm.departureDay.options[DoptionRank].value=j 
	        }    
	    
	    }
	}
	length=document.selectHotelForm.arrivalDay.options.length
}


    function CompareDate1()
    {
        var ddf=getObj("arrivalDay").value;
       
        var ddt=getObj("departureDay").value;
       
        if ((ddf)<10)
        {
            ddf=("0"+ddf);
        }
        if ((ddt)<10)
        {
            ddt=("0"+ddt);
        }
	    var dt1=getObj("arrivalMonthYear").value.substring(4,6) + "/" + ddf + "/" + getObj("arrivalMonthYear").value.substring(0,4);
	    var dt2=getObj("departureMonthYear").value.substring(4,6) + "/" + ddt + "/" + getObj("departureMonthYear").value.substring(0,4);


	    dtStartDate = new Date(dt1); 
	    dtEndDate = new Date(dt2); 
    	
	    var today = new Date();
//	    var adultcount = getObj("nadult").value;
//	    var childcount = getObj("nchild").value;


        var arrdayindex=getObj("arrivalDay").selectedIndex;
		var arrday=getObj("arrivalDay").value
		var arrmonth=getObj("arrivalMonthYear").selectedIndex;
        arrdayindex++
      
	    if (dtEndDate.getTime() <= dtStartDate.getTime())
		{
		
		    if(length==arrdayindex)
		    {
		        arrmonth++
                getObj("departureMonthYear").selectedIndex=arrmonth           
                	
		    }
		    else
		    {
		        arrday++
		        getObj("departureMonthYear").value = getObj("arrivalMonthYear").value;
		        getObj("departureDay").value = arrday;
		        
		    }
		SetDateD1()
		}
		
	    if (dtStartDate.getTime() < (today.getTime() - 86400000))
		{
		    var arrday=getObj("arrivalDay").value
		    if(length==arrdayindex)
		    {
		        arrmonth++
                getObj("departureMonthYear").selectedIndex=arrmonth           
            
		    }
		    else
		    {
		        arrday++
		        getObj("departureMonthYear").value = getObj("arrivalMonthYear").value;
		        getObj("departureDay").value = arrday;
		    }
		
		}
    }

// * call in CompareDate1()
function SetDateD1()
{
    SDcurrdate = new Date();    
    SDcurrdate.setDate(SDcurrdate.getDate());
    
	var SDday=0;
	SDday=SDcurrdate.getDate();
	
	var SDayear=document.selectHotelForm.departureMonthYear.value.substring(0,4)
	var SDamonth=document.selectHotelForm.departureMonthYear.value.substring(6,4)
	
	var SAindex=document.selectHotelForm.arrivalMonthYear.selectedIndex
	var SDindex=document.selectHotelForm.departureMonthYear.selectedIndex
    if(SDindex!=0)
    {
	    var SDday=1
    }

    for(l=1;l<document.selectHotelForm.departureDay.options.length+1;l++)
    {      
        document.selectHotelForm.departureDay.remove(l-1)
        l=l-1
    }

    for(j=SDday;j<=31;j++)
	{
        var chdate=new Date(SDayear,SDamonth-1,j)
        if(j==chdate.getDate())
	    {	       
	         var DoptionObject=new Option(j)
	         var DoptionRank = document.selectHotelForm.departureDay.options.length
	         document.selectHotelForm.departureDay.options[DoptionRank]=DoptionObject
	         document.selectHotelForm.departureDay.options[DoptionRank].value=j
	         
	    }
 
	}
	
	if(SAindex==SDindex)
	{
	    var value=document.selectHotelForm.arrivalDay.value
	    value++
	    document.selectHotelForm.departureDay.value=value
	}
	 
}



function ChInDate()
{
 try
 {
    var chin=getObj("txtchin").value
    
    var chin_array=chin.split("/")
    
    var Imlength=chin_array[0].length;
    var Idlength=chin_array[1].length;
    var Iylength=chin_array[2].length;
    
    if(Imlength==1)
    {
        var Imonth=0+""+chin_array[0]
    }
    else
    {
        var Imonth=chin_array[0]
    }
    
    if(Idlength==1)
    {
        var Idate=chin_array[1]
    }
    else
    {
        var Istr=chin_array[1].substring(0,1)
        
        if(Istr==0)
        {
            Istr=chin_array[1].substring(1,2)
            Idate=Istr
        }
        else
        {
            var Idate=chin_array[1]
        }
        
    }
    
    if(Iylength==1)
    {
        var Iyear=200+""+chin_array[2]
    }
    else
    {
        if(Iylength==2)
        {
            var Iyear=20+""+chin_array[2]
        }
        else
        {
            if(Iylength==3)
            {
                var Iyear=2+""+chin_array[2]
            }
            else
            {
                var Iyear=chin_array[2]
            }
        }
        
    }
    
    var Cin=Iyear+Imonth
    
    var arrmonth=getObj("arrivalMonthYear").value   
    var arrday=getObj("arrivalDay").value
    
    getObj("arrivalMonthYear").value=Cin
    getObj("arrivalDay").value=Idate
     
    if((getObj("arrivalMonthYear").value=="")||(getObj("arrivalDay").value==""))
    {
        alert('Please enter valid Date')
        getObj("arrivalMonthYear").value=arrmonth
        getObj("arrivalDay").value=arrday
        getObj("txtchin").value=arrmonth.substring(4,6)+"/"+arrday+"/"+arrmonth.substring(0,4)        
    }
    SetDate();
     
    CompareDate1();
    getObj("txtchout").value=getObj("departureMonthYear").value.substring(4,6)+"/"+getObj("departureDay").value+"/"+getObj("departureMonthYear").value.substring(0,4)
   }
   catch(ex)
   {
        alert('Please enter valid Date in "mm/dd/yyyy" format')
        getObj("txtchin").value=getObj("arrivalMonthYear").value.substring(4,6)+"/"+getObj("arrivalDay").value+"/"+getObj("arrivalMonthYear").value.substring(0,4)
   } 
}


function ChOutDate()
{
  try
  {
	var chout=getObj("txtchout").value
    var chout_array=chout.split("/")
    
    var Omlength=chout_array[0].length;
    var Odlength=chout_array[1].length;
    var Oylength=chout_array[2].length;
    
    if(Omlength==1)
    {
        var Omonth=0+""+chout_array[0]
    }
    else
    {
        var Omonth=chout_array[0]
    }
    
    if(Odlength==1)
    {
        var Odate=chout_array[1]
    }
    else
    {
        var Ostr=chout_array[1].substring(0,1)
        
        if(Ostr==0)
        {
            Ostr=chout_array[1].substring(1,2)
            Odate=Ostr
        }
        else
        {
            var Odate=chout_array[1]
        }
        
    }
    
    if(Oylength==1)
    {
        var Oyear=200+""+chout_array[2]
    }
    else
    {
        if(Oylength==2)
        {
            var Oyear=20+""+chout_array[2]
        }
        else
        {
            if(Oylength==3)
            {
                var Oyear=2+""+chout_array[2]
            }
            else
            {
                var Oyear=chout_array[2]
            }
        }
        
    }
    
    var Cout=Oyear+Omonth
    
    var demonth=getObj("departureMonthYear").value   
    var deday=getObj("departureDay").value
    
    getObj("departureMonthYear").value=Cout
    getObj("departureDay").value=Odate
     
    if((getObj("departureMonthYear").value=="")||(getObj("departureDay").value==""))
    {
        alert('Please enter valid Date')
        getObj("departureMonthYear").value=demonth
        getObj("departureDay").value=deday
        getObj("txtchout").value=demonth.substring(4,6)+"/"+deday+"/"+demonth.substring(0,4)
    }
	CompareDate1();
	
	var cmonth=getObj("departureMonthYear").value.substring(4,6)
	var cyear=getObj("departureMonthYear").value.substring(0,4)
	var cdate=getObj("departureDay").value
	
	getObj("txtchout").value=cmonth+"/"+cdate+"/"+cyear
  }
  catch(ex)
  {
       alert('Please enter valid Date in "mm/dd/yyyy" format')
       getObj("txtchout").value=getObj("departureMonthYear").value.substring(4,6)+"/"+getObj("departureDay").value+"/"+getObj("departureMonthYear").value.substring(0,4)
  }
}	
		

	function OpenNewWin(url)
	{
		if(url.length > 3)
		{
			if(url.substring(0,4) == "http")
    			newWin = window.open(url);
	    	else
			{
				newWin = window.open("http://" + url);
			}
		}
		else
		 	newWin = window.open(url);
	}
		
	
	
	function popUpCalendarAdmin(ctl,ctl2,from)
	{
	
	    if(ctl==document.getElementById("ctl00_cphContent_imgCal2"))
	    { 
	        if(document.getElementById("ctl00_cphContent_txtFrom").value=="")
	        {
	            alert('Please select Start Date');
	            return false;
	        }
	    }
	 
	     if(ctl==document.getElementById("ctl00_cphContent_imgCal4"))
	     {
	        if(document.getElementById("ctl00_cphContent_txtFrom2").value=="")
	        {
	            alert('Please select Start Date');
	            return false;
	        }
	     }
	 
	     if(ctl==document.getElementById("ctl00_cphContent_imgCal6"))
	     {
	        if(document.getElementById("ctl00_cphContent_txtFrom3").value=="")
	        {
	            alert('Please select Start Date');
	            return false;
	        }
	     }
	    
	    type=2
        imgDir = "../include/controls/popup_cal/"
	    getObj("closeimg").src=imgDir+"close.gif"
		var	leftpos=0
		var	toppos=0
		if(from == 2)
		{
            ValidatorEnable(document.getElementById("ctl00_cphContent_RequiredFieldValidator4"), true);
            ValidatorEnable(document.getElementById("ctl00_cphContent_RequiredFieldValidator6"), true);
            
       	}
		else if (from == 3)
		{
            ValidatorEnable(document.getElementById("ctl00_cphContent_RequiredFieldValidator5"), true);
            ValidatorEnable(document.getElementById("ctl00_cphContent_RequiredFieldValidator7"), true);
            
		}
		
		if (bPageLoaded)
		{
			if ( crossobj.visibility ==	"hidden" )
			{
				ctlToPlaceValue	= document.getElementById(ctl2)
				dateFormat=format;

				formatChar = " "
				aFormat	= dateFormat.split(formatChar)
				if (aFormat.length<3)
				{
					formatChar = "/"
					aFormat	= dateFormat.split(formatChar)
					if (aFormat.length<3)
					{
						formatChar = "."
						aFormat	= dateFormat.split(formatChar)
						if (aFormat.length<3)
						{
							formatChar = "-"
							aFormat	= dateFormat.split(formatChar)
							if (aFormat.length<3)
							{
								// invalid date	format
								formatChar=""
							}
						}
					}
				}

				tokensChanged =	0
				if ( formatChar	!= "" )
				{
					// use user's date
					aData =	document.getElementById(ctl2).value.split(formatChar)

					for	(i=0;i<3;i++)
					{
						if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
						{
							dateSelected = parseInt(aData[i], 10)
							tokensChanged ++
						}
						else if	((aFormat[i]=="m") || (aFormat[i]=="mm"))
						{
							monthSelected =	parseInt(aData[i], 10) - 1
							tokensChanged ++
						}
						else if	(aFormat[i]=="yyyy")
						{
							yearSelected = parseInt(aData[i], 10)
							tokensChanged ++
						}
						else if	(aFormat[i]=="mmm")
						{
							for	(j=0; j<12;	j++)
							{
								if (aData[i]==monthName[j])
								{
									monthSelected=j
									tokensChanged ++
								}
							}
						}
					}
				}

				if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
				{
					dateSelected = dateNow
					monthSelected =	monthNow
					yearSelected = yearNow
					
				}

				odateSelected=dateSelected
				omonthSelected=monthSelected
				oyearSelected=yearSelected

				aTag = ctl
				do {
					aTag = aTag.offsetParent;
					leftpos	+= aTag.offsetLeft;
					toppos += aTag.offsetTop;
				} while(aTag.tagName!="BODY");
				
                var oPosLeft = (fixedX==-1 ? ctl.offsetLeft	+ leftpos :	fixedX) + "px";
                var oPosTop = (fixedY==-1 ?	ctl.offsetTop +	toppos + ctl.offsetHeight +	2 :	fixedY) + "px";
                
				crossobj.left =	oPosLeft;
				crossobj.top = oPosTop;
				
				constructCalendar (1, monthSelected, yearSelected);
				crossobj.visibility=(dom||ie)? "visible" : "show"
				bShow = true;
				
			}
		}
		else
		{		
			init();
		}
	}	
	
	//handles click on Enter Key to hide calendar
	document.onkeypress = function hidecal1 () { 
		if (event.keyCode==27) 
		{
			hideCalendar()
		}
	}
		
    //handles click on of document to hide calendar
	document.onclick = function hidecal2 () { 		
		if (!bShow)
		{
			hideCalendar()
		}
		bShow = false
	}

	//does initiation of calendar vars
//	if(ie)
//	{
//		init()
//	}
//	else
//	{
//		window.onload=init();
//		SetMonth();
//		
//	}
	
