var browser = new Browser();

 if (browser.ie4 || browser.ie5){

	 document.write("<iframe id='spCal' name='spCal' STYLE='display:none; border:0;position:absolute;width:205;height:150;z-index=105' MARGINHEIGHT='0' MARGINWIDTH='0' width:156 SCROLLING='NO'></iframe>");

}

 if (browser.ns6 || browser.ns4){

	 document.write("<div id='spCal' name='spCal' class='content' STYLE='display:none; border:ridge;position:fixed;width:200;height:140;z-index=4' MARGINHEIGHT='0' MARGINWIDTH='0' width:156 SCROLLING='NO'></div>");

 }


var newformat = {date:{d:0,m:1,y:2},time:{h:0,m:1}};



function buildCal() {

	var calDate = new Date();
	calDateField = arguments[0];


	CalFrame = document.getElementById("spCal");
	 
	if (CalFrame== undefined)
	 {
		
	   
    	    document.write("<span id='spCal' STYLE='display:none; border:ridge;position:fixed;width:200;height:140;z-index=100' MARGINHEIGHT='0' MARGINWIDTH='0' NORESIZE FRAMEBORDER='0' width:156 SCROLLING='NO'></span>");
	    CalFrame = document.getElementById("spCal");
	
	   
	 }

	
        	   
       CalFrame.style.left = getAbsX(document.getElementById("IMG1")) + "px";
		   

	
	var eT = calDateField.offsetTop; 
	var eH = calDateField.offsetHeight;
	var dH = CalFrame.style.pixelHeight;
	var sT = document.body.scrollTop;
	

        CalFrame.style.top=getAbsY(calDateField) + "px";
    switch (isValidDate(calDateField.value))
    {
		case 0:

			calDate = new Date();
			break;
		case -1:

    		alert('invalid date given');
    		return false;
    		break;
    		
    	case 1:
			calDate = calDateField.value.toDateTime(newformat);
			break;
    }
    
	if (CalFrame.style.display == "")
	{
		CalFrame.style.display = "none";
		return;
	}

  	drawCal(calDate.getDate() + '/' + (calDate.getUTCMonth() + 1) + '/' + calDate.getFullYear());
CalFrame.style.display = "";

}

function drawCal (sDate)
{
	var sHTML = new String();
	var lTargetYear;
	var lTargetMonth;
	var lTargetDay;
	
	var sSplitDate;
	
	var objPop;

	sSplitDate = sDate.split('/');
	
	lTargetYear = sSplitDate[2];
	lTargetDay = sSplitDate[0];
	lTargetMonth = sSplitDate[1] -1;
	sHTML += '<html><body><style>';
	sHTML += '.calHeading {background-color : Silver; border-top-style: outset; font: 8px Verdana;}'
	sHTML += '.calRegularDay {background-color : #007f9b;}';
	sHTML += 'A.calRegularDay.HOVER {background-color : #FFFACD;}';
	sHTML += '.calOtherDay {background-color : #eeeeee;FONT-FAMILY: verdana, arial; font : xx-small;}';
	sHTML += '.calToday { font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : #ffffff;background-color : #ffffcc;}';
	sHTML += '.calReg, TD.calReg:ACTIVE, TD.calReg:FOCUS, TD.calReg:HOVER, TD.calReg:VISITED {font-family : Arial,Helvetica,Sans-serif;font-size : 11px;}' ;
	sHTML += 'TD.calReg:HOVER {background-color : #eeeeee }';
	sHTML += 'background-color : #D5D7C3; cursor: hand; display : block;}';
	sHTML += ' select.month{ font-family : Arial,Helvetica,Sans-serif; font-size : 11px; color : blue; width : 75px;}';
	sHTML += 'TD.calReg:VISITED {	background-color : Blue;} </style>';
	sHTML += '	<link href="bellapaisrentalstyle.css" rel="stylesheet" type="text/css">';

	sHTML += '<table cellspacing=0 border=0 cellpadding=0>';
	sHTML += '<tr class="GenelYAZIArial">';
	sHTML +=  '<td width=1></td>';
	sHTML +=   '<td width=200></td>';
	sHTML +=   '<td width=1></td></tr>';
	sHTML +=  '<tr class="GenelYAZIArial"><td width=1></td>';
	sHTML +=  '<td width=200>';
	sHTML += DrawCalendarMonth(lTargetYear, lTargetMonth, lTargetDay);
	sHTML +=  '</tr></table></body></html>';//</td><td width=1></td>';
    
     var calobj = document.getElementById("spCal");

     
     
      	if (browser.ie4 || browser.ie5){
		self.spCal.document.open();
		self.spCal.document.write(sHTML);
		self.spCal.document.close();

	}
	  if (browser.ns6 || browser.ns4){
	   calobj.innerHTML=sHTML;
	  }
     

}

function DrawCalendarMonth(lYear, lMonth, lDay)
{
   var sCal = new String();
   var sMonthPicker = new String();
   var dcurrDate= new Date(lYear, lMonth, lDay);
   
	monthArray = new Array('January', 'February', 'March', 'April', 'May', 'June',
                               'July', 'August', 'September', 'October', 'November', 'December');
    weekdayList  = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    weekdayArray = new Array('Su','Mo','Tu','We','Th','Fr','Sa');
    var lDaysInMonth = GetDaysInMonth(dcurrDate.getMonth()+1, dcurrDate.getYear());
    var thisMonthFirstDay = new Date(dcurrDate.getFullYear(), dcurrDate.getMonth(), 1);
   
    var sNextYear = (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear() +1);
    var sPrevYear = (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + 1 + '/' + (thisMonthFirstDay.getFullYear() -1);    
    var sPrevYear = ( 1 + '/' + (thisMonthFirstDay.getUTCMonth()+ 1) + '/' + (thisMonthFirstDay.getFullYear() -1));
    var sNextMonth = ( 1 + '/' + (thisMonthFirstDay.getUTCMonth()+ 2) + '/' + (thisMonthFirstDay.getFullYear()));
    var sPrevMonth = ( 1 + '/' + (thisMonthFirstDay.getUTCMonth()+ 0) + '/' + (thisMonthFirstDay.getFullYear()));
    
    

  
  
   sMonthPicker += '<select class="Input1" name="month" id="month" onchange="javascript:var blah=\'01/\' + (this.selectedIndex + 1) + \'/' + thisMonthFirstDay.getFullYear() +'\';parent.drawCal(blah);">';
		for (var y=0; y < 12;y++){
	      sMonthPicker += '<option value="' + y + '"';
	         if (y == lMonth) sMonthPicker += ' selected';
		  sMonthPicker += '>' + monthArray[y] + '</option>';
	    }
	    sMonthPicker += '</select>';


  sCal = '<table width=200 border=0 cellpadding="1" cellspacing="2" class="GenelYAZIArial">' + '<tr class="heading" bgcolor="#757F88">';
   sCal += '<td style="cursor:hand;"  onclick="javascript:parent.drawCal(\'' + sPrevYear +'\');" align=center><img src="Rent a Car Images/prv.gif" width="16" height="15"></td>';

   sCal += '<td colspan=5 align=center><font face="verdana, arial" size=1 color="#FFFFFF">' + sMonthPicker + dcurrDate.getFullYear() + '</font></td>';

   sCal += '<td style="cursor:hand;" onclick="parent.drawCal(\'' + sNextYear +'\');" align=center><img src="Rent a Car Images/next.gif" width="16" height="15"></td>';
   sCal += '</tr>';

 weekdays = '<tr bgcolor="#aaaaaa">';

		for (i in weekdayArray) {
			weekdays += '<td align=center bgcolor="#729A9A"><font color="#FFFFFF">' + weekdayArray[i] +'</font></td>';
		}
		weekdays += '</TR><TR>';
 
  sCal += weekdays;
   

  
   
  for (i=0; i < thisMonthFirstDay.getDay(); i++)  
	{
		sCal += DrawOtherDay(thisMonthFirstDay.getDay() - i, dcurrDate);
	}
  
  for (i=1; i < lDaysInMonth+1; i++)  
	{
		dcurrDate.setDate(i);
		sCal += DrawNormalDay(i, dcurrDate);
		
		if (dcurrDate.getDay() ==6) 

			{ 
				sCal +='</tr><tr>';      
    	    }
	
	}
  
 return sCal;

}

function DrawOtherDay(lDayOffset, dDate)
{
 var DayNumber;
 var dWorkingDate = new Date(dDate.getYear(), dDate.getMonth(), (- lDayOffset) + 1) 
 var sTemp = new String(); 
 
 DayNumber = dWorkingDate.getDate();
 

 sTemp = '<td bgcolor="#757F88" align=center><font color="#FFFFFF">';
 sTemp += '';
 sTemp += DayNumber + '</font></td>';
 return sTemp;
}

function DrawNormalDay(DayNumber, dDate)
{

  var sDayDate = new String();
  var sTemp = new String(); 
  var dToday = new Date();
  var sClassName = 'calReg';
  

sDayDate = DayNumber + '/' + (dDate.getMonth() + 1) + '/' + dDate.getFullYear();


 if (sDayDate == (dToday.getDate() + '/' + (dToday.getMonth() + 1) + '/' + dToday.getFullYear()))
  {

	sClassName='calToday';
  }
  
  sTemp += '<td class="GriBorder" ';

  sTemp += 'onclick="javascript:parent.calDateField.value=(\'' + sDayDate + '\'); parent.HideCal();"';
  
  
  sTemp += ' align=center>';
  sTemp += '<a href="#" onclick="void(\'' + sDayDate + '\')" class="GenelYAZIArial" > <font color="#FF9900">' + DayNumber + '</font></a></td>';
  
  return sTemp;
}

function HideCal()
{
	CalFrame.style.display = "none"
}

function GetNextMonth(dCurrentDate) {

	var lbmonth;
	var lbyear;
	

        if (dCurrentDate.getMonth == 11) {
            dCurrentDate.setMonth(0);
            dCurrentDate.setYear(dCurrentDate.getYear() + 1);

        }
        else {
            dCurrentDate.setMonth(dCurrentDate.getMonth() + 1);
        }

        return dCurrentDate;
}


function GetDaysInMonth(iMonth, iYear) 
{

	var dPrevDate = new Date(iYear, iMonth, 0);
	return dPrevDate.getDate();
}

String.prototype.getDateStr = function (dateformat) 
{
 re = {d:"\\d(\\d|)",m:"([\\d]|)\\d",y:"\\d\\d([\\d]|)([\\d]|)" };
 tempobj = {};
 for(var i=0; i<3; i++)
  for(var j in dateformat)
   if(dateformat[j]==i) {
    dateformat[i]=j;
    break;
   }
 var re_str = "\\b" + re[dateformat[0]] + "([\\.]|[\\/])" + re[dateformat[1]] + "([\.]|[\/])" + re[dateformat[2]] + "\\b";
 var date = this.match(new RegExp(re_str,"gmi"));
 return  (date==null ? null : date[0].indexOf(".")!=-1 && date[0].indexOf("/")!=-1? null : date[0]);
}

String.prototype.getTimeStr = function (timeformat) {
 var time = this.match(/\b(\d|)\d\:\d\d\b/);
 return (time==null ? null : time[0]);
}


String.prototype.toDateTime = function (format) {
 typeof(format)=="undefined"? format = {date:{y:2,m:1,d:0},time:{h:0,m:1}} : null;
 with(this) {
  var d_ = getDateStr(format.date);
  var d = d_!= null? d_.split(d_.match(/\D/)) : [1,1,1970];
  d[format.date.m]--;
  new String(d[format.date.y]).length==2? d[format.date.y]=parseInt("19" + d[format.date.y]) : null;
  var t_ = getTimeStr(format.time);
  t = t_!=null? t_.split(t_.match(/\D/)) : [0,0];
 }

 with(format) {
  var td = new Date (d[date.y],d[date.m],d[date.d],t[time.h],t[time.m]);
  return (td.getFullYear()==d[date.y] && td.getMonth()==d[date.m] && 
         td.getDate()==d[date.d] && td.getHours()==t[time.h] && 
         td.getMinutes()==t[time.m]? td : null);
 }
}

function Browser() {
	  this.dom = document.getElementById?1:0;
	  this.ie4 = (document.all && !this.dom)?1:0;
	  this.ns4 = (document.layers && !this.dom)?1:0;
	  this.ns6 = (this.dom && !document.all)?1:0;
	  this.ie5 = (this.dom && document.all)?1:0;
	  this.ok = this.dom || this.ie4 || this.ns4;
	  this.platform = navigator.platform;
	}
	

function isValidDate (sDateIn) {
	 	switch(true) 	{
	 		case (Date.UTC(new Date(1970,0,1,0,0,0))==Date.UTC(sDateIn.toDateTime(newformat))):

	 			return 0;
	 			break;
	 		case ((sDateIn.toDateTime(newformat)) != null): 
	 			
	 			return 1;
	 			break;
	 		case true: 

	 			return -1;
	 			break;
	 	
	 	}
}


function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left"); }
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top"); }
function getAbsPos(elt,which) {
 iPos = 0;
 while (elt != null) {
  iPos += elt["offset" + which];
  elt = elt.offsetParent;
 }
 return iPos;
}