	var timeoutDelay = 2000; // milliseconds, change this if you like, set to 0 for the calendar to never auto disappear
	var g_startDay = 0// 0=sunday, 1=monday
	
	// preload images
	var imgUp = new Image(8,12);
	imgUp.src = 'images/up.gif';
	var imgDown = new Image(8,12);
	imgDown.src = 'images/down.gif';
	
	// used by timeout auto hide functions
	var timeoutId = false;
	
	// the now standard browser sniffer class
	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;
	}
	var browser = new Browser();
		
	// dom browsers require this written to the HEAD section
	
	if (browser.dom || browser.ie4){
	    document.writeln('<style>');
		document.writeln('#container {');
		document.writeln('position : absolute;');
		document.writeln('left : 100px;');
		document.writeln('top : 100px;');
		document.writeln('width : 124px;');;
		browser.platform=='Win32'?height=140:height=149;
		document.writeln('height : ' + height +'px;');
		document.writeln('clip:rect(0px 124px ' + height + 'px 0px);');
		//document.writeln('overflow : hidden;');
		document.writeln('visibility : hidden;');
		document.writeln('background-color : #ffffff');
		document.writeln('}');
		document.writeln('</style>')
		document.write('<div id="container" name="container"');
		if (timeoutDelay) document.write(' onmouseout="calendarTimeout();" onmouseover="if (timeoutId) clearTimeout(timeoutId);"');
		document.write('>aaa</div>');
	}
	
	var g_Calendar;  // global to hold the calendar reference, set by constructor
	
	function calendarTimeout(){
	  if (browser.ie4 || browser.ie5){
	    if (window.event.srcElement && window.event.srcElement.name!='month') timeoutId=setTimeout('g_Calendar.hide();',timeoutDelay);
	  }
	  if (browser.ns6 || browser.ns4){
	    timeoutId=setTimeout('g_Calendar.hide();',timeoutDelay);
	  }
	}
	
	// constructor for calendar class
	function Calendar(){
	  g_Calendar = this;
	  // some constants needed throughout the program
	  
	  this.daysOfWeek = new Array("א","ב","ג","ד","ה","ו","ש");
	  this.months = new Array("ינואר","פברואר","מרץ","אפריל","מאי","יוני","יולי","אוגוסט","ספטמבר","אוקטובר","נובמבר","דצמבר");
	  this.daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	 
	  
	  if (browser.ns4)
	  {
	    var tmpLayer = new Layer(127);
		if (timeoutDelay){
		  tmpLayer.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		  tmpLayer.onmouseover = function(event) { if (timeoutId) clearTimeout(timeoutId); };
		  tmpLayer.onmouseout = function(event) { timeoutId=setTimeout('g_Calendar.hide()',timeoutDelay);};
		}
	    tmpLayer.x = 500;
	    tmpLayer.y = 100;
	    tmpLayer.bgColor = "#ffffff";
	  }
	  if (browser.dom || browser.ie4){
		var tmpLayer = browser.dom?document.getElementById('container'):document.all.container;
	  }
	  this.containerLayer = tmpLayer;
	  if (browser.ns4 && browser.platform=='Win32') {
	    this.containerLayer.clip.height=134;
	    this.containerLayer.clip.width=127;
	  }

	}
	
 	Calendar.prototype.getFirstDOM = function() {
		var thedate = new Date();
		thedate.setDate(1);
		thedate.setMonth(this.month);
		thedate.setFullYear(this.year);
		return thedate.getDay();
	}

	Calendar.prototype.getDaysInMonth = function (){
	   if (this.month!=1) {
	   return this.daysInMonth[this.month]
	   }
	   else {
	     // is it a leap year
		    if (Date.isLeapYear(this.year)) {
			  return 29;
			}
		    else {
			  return 28;
			}
	   }
	}
	 
	Calendar.prototype.buildString = function(){
	  var tmpStr = '<form onSubmit="this.year.blur();return false;"><table dir="ltr" width="100%" border="0" cellspacing="0" style="padding:3" cellpadding="0" class="calBorderColor"><tr><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0" class="calBgColor">';
	  tmpStr += '<tr>';
	  tmpStr += '<td width="100%" class="cal" align="left">';
	  if (this.hasDropDown) {
	    tmpStr += '<select class="month" name="month" onchange="g_Calendar.selectChange();">';
		for (var i=0;i<this.months.length;i++){
	      tmpStr += '<option value="' + i + '"' 
		  if (i == this.month) tmpStr += ' selected';
		  tmpStr += '>' + this.months[i] + '</option>';
	    }
	    tmpStr += '</select>';
	  } else {
	    tmpStr += '<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-left:1px solid #4A9423;"><tr><td class="head"><a href="javascript: g_Calendar.changeMonth(+1);" style="font-size:14px;color:white;text-decoration:none;"> <b> < </b></a></td><td class="head" width="100%" align="center"><font style="font-size:13">' + this.months[this.month] + '</font>&nbsp;' + this.year + '</td><td class="head"><a href="javascript: g_Calendar.changeMonth(-1);" style="font-size:14px;color:white;text-decoration:none;"> <b>> </b></a> </td></tr></table>';
	  }
	  tmpStr += '</td>';
	 
	  var iCount = 1;

	  
	  var iFirstDOM = (7+this.getFirstDOM()-g_startDay)%7; // to prevent calling it in a loop
	  
	  var iDaysInMonth = this.getDaysInMonth(); // to prevent calling it in a loop
	  
	  tmpStr += '<table width="100%" border="0" style="border-left:1px solid #4A9423;border-right:1px solid #4A9423;border-bottom:1px solid #4A9423;" cellspacing="0" cellpadding="1" class="calBgColor">';  // printing the header of Days
	  tmpStr += '<tr>';
	    for (var i=0;i<7;i++){
		  tmpStr += '<td align="center" class="calDaysColor">' + this.daysOfWeek[(g_startDay+i)%7] + '</td>';
		}
	  tmpStr += '</tr>';
	  var tmpFrom = parseInt('' + this.dateFromYear + this.dateFromMonth + this.dateFromDay,10);
	  var tmpTo = parseInt('' + this.dateToYear + this.dateToMonth + this.dateToDay,10);
	  var tmpCompare;
	 
	  
	
	  for (var j=1;j<=6;j++){
	     tmpStr += '<tr>';
	     for (var i=1;i<=7;i++){
		   tmpStr += '<td width="16" align="center" '
		   
		  
		   
		   if ( (7*(j-1) + i)>=iFirstDOM+1  && iCount <= iDaysInMonth)// here we print the days of the month
			 {
		     if (iCount==this.day && this.year==this.oYear && this.month==this.oMonth) tmpStr += 'class="calHighlightColor"';
			 else {
			    if (i==7-g_startDay || i==((7-g_startDay)%7)+6) tmpStr += 'class="calWeekend"';
				else tmpStr += 'class="cal"';
			 }
		     tmpStr += '>';
			 /* could create a date object here and compare that but probably more efficient to convert to a number
			   and compare number as numbers are primitives */
			
			 tmpCompare = parseInt('' + this.year + padZero(this.month) + padZero(iCount),10);
			 //alert(i%7 + " whreeras " + parseInt((7-g_startDay)%7+ 1))
			 
			
			//alert(document.OrderForm.dateComponent == "[object]")
					
			if (tmpCompare >= tmpFrom && tmpCompare <= tmpTo && getRelevantDays(i) ) { 
			  tmpStr += '<a class="cal" href="javascript: g_Calendar.clickDay(' + iCount + ');">' + iCount + '</a>';
			} else {
			  tmpStr += '<span class="disabled">' + iCount + '</span>';
			}	

			 
			 iCount++;
		   } 
			else //here we print where there isnt such a day in the calender (empty places)
			{
		    if  (i==7-g_startDay || i==((7-g_startDay)%7)+6) tmpStr += 'class="calWeekend"'; else tmpStr +='class="cal"';
			 tmpStr += '>&nbsp;';
			}
		   tmpStr += '</td>'
		 }
		 tmpStr += '</tr>'
	  }
	  tmpStr += '</table></td></tr></table></form>'
		
	  return tmpStr;
	}
	
	Calendar.prototype.selectChange = function(){
	  this.month = browser.ns6?this.containerLayer.ownerDocument.forms[0].month.selectedIndex:this.containerLayer.document.forms[0].month.selectedIndex;
	  this.writeString(this.buildString());
	}
	
	Calendar.prototype.inputChange = function(){
	  var tmp = browser.ns6?this.containerLayer.ownerDocument.forms[0].year:this.containerLayer.document.forms[0].year;
	  if (tmp.value >=1900 || tmp.value <=2100){
	    this.year = tmp.value;
	    this.writeString(this.buildString());
	  } else {
	    tmp.value = this.year;
	  }
	}
	Calendar.prototype.changeYear = function(incr){
	   (incr==1)?this.year++:this.year--;
	   this.writeString(this.buildString());
	}
	Calendar.prototype.changeMonth = function(incr){
	    if (this.month==11 && incr==1){
	      this.month = 0;
	  	  this.year++;
	    } else {
	      if (this.month==0 && incr==-1){
	        this.month = 11;
		    this.year--;
	      } else {
		    (incr==1)?this.month++:this.month--;
		  }
		}
		this.writeString(this.buildString());
	}
	
	Calendar.prototype.clickDay = function(day){
	   var tmp = eval('document.' + this.target);
	   if (this.dateFormat=='dd-mmm-yyyy' || this.dateFormat=='dd/mmm/yyyy') tmp.value = day + this.dateDelim + this.months[this.month].substr(0,3) + this.dateDelim + this.year;
	   
	   if (this.dateFormat=='dd/mm/yyyy' || this.dateFormat=='dd-mm-yyyy'){
			if (day<10) tmp.value = '0' + day;
			else tmp.value = day;
			
			if (this.month+1<10) tmp.value += this.dateDelim + '0' + (this.month+1) + this.dateDelim + this.year;
			else tmp.value += this.dateDelim + (this.month+1) + this.dateDelim + this.year;
	   }
	   if (this.dateFormat=='mm/dd/yyyy' || this.dateFormat=='mm-dd-yyyy') tmp.value = (this.month+1) + this.dateDelim + day + this.dateDelim + this.year;
	   if (this.dateFormat=='yyyy-mm-dd') tmp.value = this.year + this.dateDelim + (this.month+1) + this.dateDelim + day;
	   	
	  
	   if ( ! checkDate())	
			{
			tmp.value = ""
			}
	   
	   if (browser.ns4) this.containerLayer.hidden=true;
	   if (browser.dom || browser.ie4){
	     this.containerLayer.style.visibility='hidden'
	   }
	   //if((frmSearch.ToDate.value=="")||(frmSearch.ToDate.value=="עד תאריך")){frmSearch.ToDate.value=DateAdd(frmSearch.FromDate.value, 13,"ddmmyyyy")}
		
	}
	
	Calendar.prototype.writeString = function(str){
	  if (browser.ns4){
	    this.containerLayer.document.open();
	    this.containerLayer.document.write(str);
	    this.containerLayer.document.close();
	  } 
	  if (browser.dom || browser.ie4){
		
	    this.containerLayer.innerHTML = str;
	  }
	}
									   //event,'frmSearch.FromDate', false, 'dd/mm/yyyy', -42, -2,new Date(),new Date(frmSearch.ToDate.value.substring(3,5)+'/'+frmSearch.ToDate.value.substring(0,2)+'/'+frmSearch.ToDate.value.substring(6,10))
	Calendar.prototype.show = function(event, target, bHasDropDown, dateFormat, bLeft, bTop, dateFrom, dateTo){
	// calendar can restrict choices between 2 dates, if however no restrictions
	// are made, let them choose any date between 1900 and 3000	
	
	
	var d ;
	d = new Date();

	if (dateFrom) this.dateFrom = dateFrom; else this.dateFrom = new Date(d.getFullYear() ,d.getMonth()-1,d.getDate());
	
	this.dateFromDay = padZero(this.dateFrom.getDate());
	this.dateFromMonth = padZero(this.dateFrom.getMonth());
	this.dateFromYear = this.dateFrom.getFullYear();
	if (dateTo) this.dateTo = dateTo; else this.dateTo = new Date(d.getFullYear()+1 ,d.getMonth()-1,d.getDate());
	this.dateToDay = padZero(this.dateTo.getDate());
	this.dateToMonth = padZero(this.dateTo.getMonth());
	this.dateToYear = this.dateTo.getFullYear();
	this.hasDropDown = bHasDropDown;
	if (dateFormat) this.dateFormat = dateFormat; else this.dateFormat = 'dd/mm/yyyy';
	switch (this.dateFormat){
	  case 'dd-mmm-yyyy':
	  case 'dd-mm-yyyy':
	  case 'yyyy-mm-dd':
	    this.dateDelim = '-';
		break;
	  case 'dd/mm/yyyy':
	  case 'mm/dd/yyyy':
	  case 'dd/mmm/yyyy':
	    this.dateDelim = '/';
		break;
	}
	
	  if (browser.ns4) {
	    if (!this.containerLayer.hidden) {
		  this.containerLayer.hidden=true;
		  return;
		}
	   }
	  if (browser.dom || browser.ie4){
	    if (this.containerLayer.style.visibility=='visible') {
		  this.containerLayer.style.visibility='hidden';
		  return;
		}  
	  }
	
	  if (browser.ie5 || browser.ie4){
	    var event = window.event;
	  }
	  if (browser.ns4){
	    this.containerLayer.x = event.x+10;
	    this.containerLayer.y = event.y-5;
	  }
	  if (browser.ie5 || browser.ie4){
	    var obj = event.srcElement;
 	    x = 0;
  		while (obj.offsetParent != null) {
    		  x += obj.offsetLeft;
    		  obj = obj.offsetParent;
  		}
  		x += obj.offsetLeft;
	    y = 0;
		var obj = event.srcElement;
	    while (obj.offsetParent != null) {
    		  y += obj.offsetTop;
    		  obj = obj.offsetParent;
  		}
  		y += obj.offsetTop+25;
        this.containerLayer.style.left = x+bLeft;
		if (event.y>0)this.containerLayer.style.top = y+bTop;
	  }
	  if (browser.ns6){
	    this.containerLayer.style.left = event.pageX+10;
		this.containerLayer.style.top = event.pageY-5;
	  }
	  this.target = target;
	  var tmp = eval('document.' + this.target);
	  if (tmp && tmp.value && tmp.value.split(this.dateDelim).length==3 && tmp.value.indexOf('d')==-1){
	    var atmp = tmp.value.split(this.dateDelim)
		switch (this.dateFormat){
		 case 'dd-mmm-yyyy':
		 case 'dd/mmm/yyyy':
		   for (var i=0;i<this.months.length;i++){
		     if (atmp[1].toLowerCase()==this.months[i].substr(0,3).toLowerCase()){
		       this.month = this.oMonth = i;
			   break;
		     }
		   }
		   this.day = parseInt(atmp[0],10);
		   this.year = this.oYear = parseInt(atmp[2],10);
		   break;
		 case 'dd/mm/yyyy':
		 case 'dd-mm-yyyy':
		   this.month = this.oMonth = parseInt(atmp[1]-1,10); 
		   this.day = parseInt(atmp[0],10);
		   this.year = this.oYear = parseInt(atmp[2],10);
		   break;
		 case 'mm/dd/yyyy':
		 case 'mm-dd-yyyy':
		   this.month = this.oMonth = parseInt(atmp[0]-1,10);
		   this.day = parseInt(atmp[1],10);
		   this.year = this.oYear = parseInt(atmp[2],10);
		   break;
		 case 'yyyy-mm-dd':
		   this.month = this.oMonth = parseInt(atmp[1]-1,10);
		   this.day = parseInt(atmp[2],10);
		   this.year = this.oYear = parseInt(atmp[0],10);
		   break;
		}
	  } else { // no date set, default to today
	    var theDate = new Date();
	  	 this.year = this.oYear = theDate.getFullYear();
	     this.month = this.oMonth = theDate.getMonth();
	     this.day = this.oDay = theDate.getDate();
	  }
	
	  this.writeString(this.buildString());
	 
	  // and then show it!
	   if (browser.ns4) {
	   this.containerLayer.hidden=false;
	   }
	  if (browser.dom || browser.ie4){
	       this.containerLayer.style.visibility='visible';
	  }
	}
	
	Calendar.prototype.hide = function(){
	  
	   
	    if (browser.ns4) this.containerLayer.hidden = true;
		if (browser.dom || browser.ie4){
	    this.containerLayer.style.visibility='hidden';
	    
	   
	  }
	}
	
	function handleDocumentClick(e){
	  if (browser.ie4 || browser.ie5) e = window.event;

	  if (browser.ns6){
	    var bTest = (e.pageX > parseInt(g_Calendar.containerLayer.style.left,10) && e.pageX <  (parseInt(g_Calendar.containerLayer.style.left,10)+125) && e.pageY < (parseInt(g_Calendar.containerLayer.style.top,10)+125) && e.pageY > parseInt(g_Calendar.containerLayer.style.top,10));
	    if (e.target.name!='imgCalendar' && e.target.name!='month'  && e.target.name!='year' && e.target.name!='calendar' && !bTest){
		  g_Calendar.hide(); 
		}
	  }
	  if (browser.ie4 || browser.ie5){
		// extra test to see if user clicked inside the calendar but not on a valid date, we don't want it to disappear in this case
	   var bTest = (e.x > parseInt(g_Calendar.containerLayer.style.left,10) && e.x <  (parseInt(g_Calendar.containerLayer.style.left,10)+125) && e.y < (parseInt(g_Calendar.containerLayer.style.top,10)+125) && e.y > parseInt(g_Calendar.containerLayer.style.top,10));
	    if (e.srcElement.name!='imgCalendar' && e.srcElement.name!='month' && e.srcElement.name!='year' && !bTest & typeof(e.srcElement)!='object'){
		  g_Calendar.hide(); 
		}
	  }
	  if (browser.ns4) g_Calendar.hide();
	}
	
	// utility function
	function padZero(num) {
	  return ((num <= 9) ? ("0" + num) : num);
	}
	  // Finally licked extending  native date object;
	  Date.isLeapYear = function(year){ if (year%4==0 && ((year%100!=0) || (year%400==0))) return true; else return false; }
	  Date.daysInYear = function(year){ if (Date.isLeapYear(year)) return 366; else return 365;}
	  var DAY = 1000*60*60*24;
	  Date.prototype.addDays = function(num){
		return new Date((num*DAY)+this.valueOf());
	  }	
	  
	 // events capturing, careful you don't override this by setting something in the onload event of 
	// the body tag
	window.onload=function(){ 
	  window.focus()
	  new Calendar(new Date());
	  if (browser.ns4){
	    if (typeof document.NSfix == 'undefined'){
		  document.NSfix = new Object();
	      document.NSfix.initWidth=window.innerWidth;
		  document.NSfix.initHeight=window.innerHeight;
		}
	  }
	 
	 //fncPageOnLoad()
	}
	if (browser.ns4) window.onresize = function(){
	  if (document.NSfix.initWidth!=window.innerWidth || document.NSfix.initHeight!=window.innerHeight) window.location.reload(false);
	} // ns4 resize bug workaround
	//window.document.onclick=handleDocumentClick;
   
 //window.onerror = function(msg,url,line){
	 // alert('******* an error has occurred ********'
	//  + '\nText:' + msg + '\nurl:' + url + '\nline:' + line);
	//}


var g_msPerDay = 1000*60*60*24;
var g_aMonths = new Array("01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12");
var g_aDays = new Array("01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", 
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31");

function DateAdd(sDate, numDays, sFormat)
{
	sDate = sDate.substring(3,5)+'/'+sDate.substring(0,2)+'/'+sDate.substring(6,10)
	startDateTemp = new Date(sDate)
	var returnDate = new Date(startDateTemp.getTime());
	returnDate.setTime(Math.round(returnDate.getTime())+g_msPerDay*numDays);
	nYear = returnDate.getYear();
	if(returnDate.getYear()<2000)
    nYear += 1900;
	switch(sFormat){
		case "mmddyyyy":
			returnDateString = g_aMonths[returnDate.getMonth()] + "/" + g_aDays[returnDate.getDate()-1] + "/" + nYear
			break
		case "ddmmyyyy":
			returnDateString = g_aDays[returnDate.getDate()-1] + "/" + g_aMonths[returnDate.getMonth()] + "/" + nYear
			break
	}
	return returnDateString;
}

//--------------

	function dateDiff( dout ,din ) 
	{
		var oneMinute = 60 * 1000
		var oneHour = oneMinute * 60
		var oneDay = oneHour * 24
		var diff = dout.getTime() - din.getTime()
		diff = Math.floor(diff/oneDay)
				
		return diff
	}
	
	function checkDate()
	{

    var fromDate;
    var toDate;


	fromDate = document.frmCalulator.FromDate.value;

	var T = new Date(fromDate.substring(6, 10), fromDate.substring(3, 5) - 1, fromDate.substring(0, 2));
	var S = new Date();
	var numDays = dateDiff(T, S);
	var aid510;
	var countDay;
	
	aid510 = document.frmCalulator.aid.value;

    // Tamara, 17/06/2009 - Change flow for the program num:510
	if ((aid510 == 510) || (aid510 == 517) || (aid510 == 560) || (aid510 == 550)  || (aid510 == 554))
	{
	    countDay = 1000; 
	}
	else if (aid510 == 551)
	{
	    countDay = 120; 
	}
	else if ((aid510 == 544)  || (aid510 == 328)) //add this to shatap 544,328 to allow 90 days in advance
	{
	    countDay = 90;
	}
	else if ((aid510 == 526) || (aid510 == 534))//add this to shatap 526,534, allow 60 days in advance
	{
	    countDay = 60;
	}
	else
	{
	    countDay = 60; 
	}

	if (numDays > countDay)
	{
	    alert("בחר תאריך עד " + countDay + " יום לפני מועד הנסיעה");
	    return false;
	}
	else
	{
	    return true;
	}
	
	}
	
	function checkDate484()
	{
	
	var fromDate,toDate
	
	
	fromDate = document.frmCalulator.FromDate.value
	
	
	var T =  new Date(fromDate.substring(6,10), fromDate.substring(3,5)-1, fromDate.substring(0,2) ) 
	var S = new Date();
	var numDays = dateDiff(T,S)
	
   
	if (numDays>60)
		{
		alert("בחר תאריך עד 60 יום לפני מועד הנסיעה")
		return false
		}
	else	
		return true
	}
