// JavaScript Document

  function field( id ) {
    var ele = document.getElementById( id )
    if ( !ele ) {
      alert( 'Specified document element not found.  id="' + id + '"' );
    }
    return ele
  }
 
  function checkDate( obj ) {
    if ( obj && obj.nodeName == 'INPUT' ) {
      var val = obj.value;
      if ( !val.match( /^\d{1,2}\/\d{1,2}\/\d{4}$/ ) ) {
        alert( 'Invalid date' );
        obj.value = 'dd/mm/yyyy';
      }
    }
  }
 
  //function addDays( id1, id2, id3 , id4) {
    
	//alert(id4);
	
  function addDays( id1, id2, id3) {
	  
	function D2( val ) {
      //return ( val ) < 10 ? '0' + val : val;
	  return ( val );
    }
    var start = field( id1 );
    var days  = field( id2 );
    var fini  = field( id3 );
	
	
    if ( start && field ) {
      if ( start.value[ 0 ] == 'm' ) {
        alert( 'Enter a date first' )
        fini.value = '';
      } else {
        var date = start.value.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
        var when = new Date( RegExp.$3, parseInt( RegExp.$2,10 ) - 1, RegExp.$1 );
        var then = new Date( when.getFullYear(), when.getMonth(), when.getDate() + parseInt( days.value ) );
        fini.value = D2( then.getDate() ) + '/' +
                     D2( then.getMonth() + 1 ) + '/' +
                     + then.getFullYear()
      }
    }
  }