/*******************************************************************************************************/

  //this function resets the date to the default status if it is removed from the list
  //it is called when the remove date link is clicked
  function resetDate(theMonth, theDay, theYear) {

	if ((obj=findObj(theMonth))!=null) {
		for (i=0;i<obj.length;i++) {
		    if (obj.options[i].value == '')
		    	obj.options[i].selected = true;
		}
   	}
  	if ((obj=findObj(theDay))!=null) {
		for (i=0;i<obj.length;i++) {
		    if (obj.options[i].value == '')
		    	obj.options[i].selected = true;
		}
   	}
  	if ((obj=findObj(theYear))!=null) {
		for (i=0;i<obj.length;i++) {
		    if (obj.options[i].value == '')
		    	obj.options[i].selected = true;
		}
	}
  }

/*******************************************************************************************************/

  //this function adds and removes dates
  function addRemove (theId, theNum, theAction) {
  
  	if ((obj=findObj(theId+theNum))!=null) {
  		obj.style.display = theAction;
  	}
  }

/*******************************************************************************************************/

  //this function hides all specified links (remove/add date) except for the one that called it
  function hideShow	(theId, theNum, whoCalls) {

	//this loop hides all links (type given ex: remove/add date)
  	for(i=1; i<theNum; i++) {
  		if ((obj=findObj(theId+i))!=null) {
  			obj.style.display = 'none';
   		}
  	}

	//if new date added, 'add date' and 'remove date' is displayed except if it is the 5th date
  	if(theNum!=5 && (whoCalls=='going')) {
  		if ((obj=findObj(theId+theNum))!=null) {
			obj.style.display = '';
   		}
  	}
  	//else, if it is the 5th, display just the 'remove date'
  	else if(theNum==5) {
  		if ((obj=findObj('ha5'))!=null) {
			obj.style.display = '';
   		}
  	}
  	//else, if date is removed, display previous 'add date' and 'remove date' except if 1st date
  	else if(theNum!=1 && (whoCalls=='hide')) {
  		if ((obj=findObj(theId+theNum))!=null) {
			obj.style.display = '';
   		}
  	}
  	//else, display just the 'remove date'
  	else {
  		if ((obj=findObj('a1'))!=null) {
			obj.style.display = '';
   		}
  	}
  }

/*******************************************************************************************************/

  function findObj(n,d) { //v4.01
    var p,i,x;
    if(!d){
    	d=document;}
//    if((p=n.indexOf("?"))!=0&&parent.frames.length) {
//    	d=parent.frames[n.substring(p+1)].document;
//    	n=n.substring(0,p);
//    }
    if(!(x=d[n])&&d.all){
    	x=d.all[n];
    	}
    for (i=0;!x&&i<d.forms.length;i++){
    	x=d.forms[i][n];}
    for(i=0;!x&&d.layers&&i<d.layers.length;i++){
    	x=findObj(n,d.layers[i].document);}
    if(!x && d.getElementById){
    	x=d.getElementById(n);}
    return x;
  }

/*******************************************************************************************************/

  function going(layID) {

	//call function to display new date
    addRemove('d', layID, 'block');

	//call function to hide every 'add date' link except for the one we just showed
	//unless it is the last one, which is always hidden
    hideShow('a', layID, 'going');

   	//call function to hide every 'remove date' link except for the one we just showed
    hideShow('ha', layID, 'going');

    return false;
  }

/*******************************************************************************************************/

  function hideEm(layID) {

	//call function to reset date properties of newly removed date
  	resetDate(('theM'+layID), ('theD'+layID), ('theY'+layID));

	//call function to remove date
   	addRemove('d', layID, 'none');

	//call function to hide every 'add date' link except for the one previous to the one we hid
	hideShow('a', (layID-1), 'hide');

	//call function to hide every 'remove date' link except for the one previous to the one we hid
	//unless it is the first one, which is always hidden
	hideShow('ha', (layID-1), 'hide');

    return false;
  }
