DHTMLSuite.include("calendar");

function parseDate(inputObject) {
			try {
			
				var re = new RegExp("(\/)|( )", "g");
						inputObject.value = inputObject.value.replace(re, "-");
				var val = inputObject.value.split("-");
				var obDate = new Date(val[2], val[1]-1, val[0]);
				if(obDate.getFullYear()!=val[2]  || obDate.getMonth() != val[1]-1 || obDate.getDate() != val[0]) {
					inputObject.value="";
					return false;
				}
				
			} catch (e) {
				inputObject.value="";
				return false;
			}
	
		return true;
		
		}
		
	function pickDate(buttonObj,inputObject,inputObjectRif,calendarOrdine)
	{
	
	calendarOrdine.setCalendarPositionByHTMLElement(inputObject,0,inputObject.offsetHeight+2); // Position the calendar right below the form input

		
		if(inputObjectRif != undefined){
				  
		//2009-04-27	
		
		var sp = inputObjectRif.value.split("-");
			var dt = new Date(sp[2], sp[1]-1, sp[0]);
			modello.invalidDateRange = new Array();
			modello.addInvalidDateRange(false,{day: dt.getDate()-1, month: dt.getMonth() + 1,year: dt.getFullYear()});
	
		}
	
		
		calendarOrdine.addHtmlElementReference('myDate',inputObject);	// Adding a reference to this element so that I can pick it up in the getDateFromCalendar below(myInput is a unique key)
		
		if(calendarOrdine.isVisible()){
			calendarOrdine.hide();
		}else{
			calendarOrdine.resetViewDisplayedMonth();	// This line resets the view back to the inital display, i.e. it displays the inital month and not the month it displayed the last time it was open.
			calendarOrdine.display();
		}	
		
	}	
	

	/* inputArray is an associative array with the properties
	year
	month
	day
	calendarRef - Reference to the DHTMLSuite.calendar object.
	*/
	function getDateFromCalendar(inputArray)
	{
		var references = calendarOrdine.getHtmlElementReferences(); // Get back reference to form field.
		references.myDate.value = inputArray.day + '-' + inputArray.month + '-' + inputArray.year ;
		calendarOrdine.hide();	
		
	}
	
	