var msgIncorrectDay=".dd/mm/yyyy יום לא חוקי. השתמש בתבנית ";
var msgIncorrectMonth=".dd/mm/yyyy חודש לא חוקי. השתמש בתבנית ";
var msgIncorrectDate=".dd/mm/yyyy תאריך לא חוקי. השתמש בתבנית ";


function getInputDate(dateField){	
     var returnValue = window.showModalDialog('../html/cal.htm',window,'resizable:false; scroll:false; edge:sunken;dialogWidth:245px;dialogHeight:269px');               
     // alert (returnValue.getDate());
     var currentDate = new Date();
	 //alert(currentDate);
     if(returnValue != null)
     {     	
         //dateField.value = returnValue;
         if(dateField == "ReturnDate")
         {
			document.IsraelRentals.ReturnDay.selectedIndex = returnValue.getDate()-1
			document.IsraelRentals.ReturnMonth.selectedIndex = returnValue.getMonth()
			//alert(returnValue.getFullYear());
			if(returnValue.getFullYear() == currentDate.getFullYear())
				document.IsraelRentals.ReturnYear.selectedIndex = 0
			else if(returnValue.getFullYear() == currentDate.getFullYear()+1)
				document.IsraelRentals.ReturnYear.selectedIndex = 1
		changeHourOption(2);
			
         }
         else if(dateField == "PickDate")
         {         	
         		//alert(returnValue.getFullYear());
			document.IsraelRentals.PickDay.selectedIndex = returnValue.getDate()-1
			document.IsraelRentals.PickMonth.selectedIndex = returnValue.getMonth()
			
			if(returnValue.getFullYear() == currentDate.getFullYear())
				document.IsraelRentals.PickYear.selectedIndex = 0
			else if(returnValue.getFullYear() ==currentDate.getFullYear()+1)
				document.IsraelRentals.PickYear.selectedIndex = 1
		changeHourOption(1);
         }
         Set_DayNum()
     }
    
	 //alert("waw" + returnValue.getMonth())
	 
 }

function dateonly(myfield, e) {
       var key;
       var keychar;
 
       if (window.event)
          key = window.event.keyCode;
       else if (e)
          key = e.which;
       else
          return true;
 
      keychar = String.fromCharCode(key);
      
       // control keys
       if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
          return true;
       }
 
       // numbers
       else if ((("0123456789/").indexOf(keychar) > -1)){         
        return true;
        //return checkdateformat(myfield);          
       }
 
       return false;
   }
 
 function checkdateformat(myfield){
   
    if (myfield.value==null || myfield.value.length == 0){  
         return true;
    }
    //only one /
    if (myfield.value.indexOf('/') == myfield.value.lastIndexOf('/')){
             alert (msgIncorrectDate);
            return setFocus(myfield);        
    }

    var day = myfield.value.substring(0,myfield.value.indexOf('/'));
    if (day .length > 2 || day .length < 1){
            alert (msgIncorrectDay);
            return setFocus(myfield);        
    }
    if (day<1 || day>31) {
            alert (msgIncorrectDay);
            return setFocus(myfield);
    }

    var month = myfield.value.substring(myfield.value.indexOf('/')+1,myfield.value.lastIndexOf('/'));    
    if (month .length > 2  || month .length < 1){
            alert (msgIncorrectMonth);
            return setFocus(myfield);        
    }
     if (month<1  || month>12) {
            alert (msgIncorrectMonth);
            return setFocus(myfield);
          }          
    var year = myfield.value.substring(myfield.value.lastIndexOf('/')+1,myfield.value.length);    

    if (year.length != 4) {
            alert (msgIncorrectDate);
            return setFocus(myfield);
          }          
    //alert (day + " " + month + " " + year);              
          
          return true;
 }
 
 
 function checkdateonexit(myfield) {
    //if (myfield.value != "") {
    //      alert (msgIncorrectDate);
    //return setFocus(myfield);
   //}  
  return checkdateformat(myfield);
 }
 

 function daysInMonth(month) {
   if (month != "" ) {
  if (month == 4 || month == 6 || month==9 || month==11)
   return 30;
  else if (month == 2)
   return 29;
  else return 31;
   }
 }
 
 function setFocus(myfield) {
  myfield.focus(); 
  return true;
 }
