
	function pickDate(Src, evnt, siteUrl){
	var x = evnt.screenX;	
	var y = evnt.screenY;
	var  tbName = Src.substring( 0,Src.indexOf("Image1"))+ "TextBox1"; 
	var dateValue = document.getElementById(tbName).value;
window.open(siteUrl+ "Common/calendarPopUp/calendarPopUp.aspx?src=" + Src+"&value="+dateValue, "_blank", "height=165, width=220, left="+(x-30)+", top="+(y+15)+", " + 
"location=no, menubar=no, resizable=no, " + 
"scrollbars=no, titlebar=no, toolbar=no", true);
		}
		
		
	// check date value after control lose focus
	function onBlurEvent(field)
	{
		if (! check_date(field))
			field.value='';
	}
	
	function check_date(field)
	{
		var aDate = field.value;
		if (aDate != "")
		{
			var date_array = aDate.split('-');
			if (date_array.length != 3)
			{
			//   alert('Date format is not valid!');
			   return false;
			}
			
		var day = date_array[2];

//		Attention! Javascript consider months in the range 0 - 11
		var month =date_array[1] - 1;
		month=month+"";
		var year = date_array[0];
		if (year.length==2)	
		year='20'+year;

      // This instruction will create a date object
      source_date = new Date(year,month,day);

      if(year != source_date.getFullYear())
         return false;

      if(month != source_date.getMonth())
	        return false;
      if(day != source_date.getDate())
         return false;
    //format date correctly  
	month=parseInt(month)+1;
	month=month+"";
	if (month.length==1)	
	{	
		month='0'+month;
	}
	
	if (day.length==1)	
		day='0'+day;
		
	 field.value=year+'-'+month+'-'+day; 
	}
	  return true;
}
