/*
 * $Header: /bit10/htdocs/intranet.dev.bit10.net/javascript/B10_interfacecontrols.js 4     28/06/02 14:21 Steveg $
 *
 * short:   display utility functions for bit10 ltd. Intranet
 *
 * $Log: /bit10/htdocs/intranet.dev.bit10.net/javascript/B10_interfacecontrols.js $
 * 
 * 4     28/06/02 14:21 Steveg
 * Amending code for Neted set tree view
 * 
 * 3     27/03/02 18:07 Christina
 * moved projectChangeRequest and projectIssue functions into here
 * 
 * 2     27/03/02 16:08 Alex
 * Added functions B10_toggleTOC() and B10_toggleTOCnode() for controlling
 * the display of the table of contents on the site.
 * 
 * 1     16/10/01 21:39 Alex
 * Initial revision.
 *
 */

//
//  B10_toggleProjects() -- toggle project display in client summary view
//
function B10_toggleProjects(strClient) {
  if (document.all['tbl_' + strClient].style.display == 'none') {
    document.all['ctlShow_' + strClient].style.display  = 'none';
    document.all['ctlHide_' + strClient].style.display  = '';
    document.all['tbl_' + strClient].style.display      = '';
  } else {
    document.all['ctlShow_' + strClient].style.display  = '';
    document.all['ctlHide_' + strClient].style.display  = 'none';
    document.all['tbl_' + strClient].style.display      = 'none';
  }
}


//
//  B10_togglePriorities() -- toggle change display in project summary view
//
function B10_togglePriorities(strPriority) {
  if (document.all['tbl_' + strPriority].style.display == 'none') {
    document.all['ctlShow_' + strPriority].style.display  = 'none';
    document.all['ctlHide_' + strPriority].style.display  = '';
    document.all['tbl_' + strPriority].style.display      = '';
  } else {
    document.all['ctlShow_' + strPriority].style.display  = '';
    document.all['ctlHide_' + strPriority].style.display  = 'none';
    document.all['tbl_' + strPriority].style.display      = 'none';
  }
}


//
//  B10_toggleTOC() -- toggle table of contents
//
function B10_toggleTOC() {
  if (document.all['tbl_toc'].style.display == 'none') {
    document.all['ctlShow_toc'].style.display  = 'none';
    document.all['ctlHide_toc'].style.display  = '';
    document.all['tbl_toc'].style.display      = '';
  } else {
    document.all['ctlShow_toc'].style.display  = '';
    document.all['ctlHide_toc'].style.display  = 'none';
    document.all['tbl_toc'].style.display      = 'none';
  }
}


//
//  B10_toggleTOCnode() -- toggle a node of the table of contents
//
function B10_toggleTOCnode(strNode) {
		//Don't try to toggle if the child wasn't drawn (not yet live)
	 if (document.all['toc_' + strNode] != undefined)
	 {	 
	  if (document.all['toc_' + strNode].style.display == 'none') {
  	  document.all['tocShow_' + strNode].style.display  = 'none';
    	document.all['tocHide_' + strNode].style.display  = '';
	    document.all['toc_' + strNode].style.display      = '';
  	} else {
    	document.all['tocShow_' + strNode].style.display  = '';
		  document.all['tocHide_' + strNode].style.display  = 'none';
    	document.all['toc_' + strNode].style.display      = 'none';
	  }
	}
}

//Netscape version of the above function
function B10_toggleTOCnodeNS(strNode) {
  		//alert(strNode);
			//alert(document.frmTest['toc_' + strNode].style.display);
		//Don't try to toggle if the child wasn't drawn (not yet live)
	 if (document.frmTree['toc_' + strNode] != undefined)
	 {	 

	  if (document.frmTree['toc_' + strNode].style.display == 'none') {
		  document.frmTree['toc_' + strNode].style.display  = 'none';
    	document.frmTree['toc_' + strNode].style.display  = '';
	    document.frmTree['toc_' + strNode].style.display      = '';
  	} else {
    	document.frmTree['toc_' + strNode].style.display  = '';
		  document.frmTree['toc_' + strNode].style.display  = 'none';
    	document.frmTree['toc_' + strNode].style.display      = 'none';
	  }
	}
}



//
//  B10_radioClear() -- uncheck radio buttons and clear object value
//
function B10_radioClear(object) {
  object.value = "";
  for (i = 0; i < object.length; i++)
    object[i].checked = false;
}

//
//  B10_radioFindIndexByValue()
// returns index of radio button whose value is objectValue
// if not found returns index of first button whose value is not empty
//
function B10_radioFindIndexByValue(object, objectValue) {
  var index;
  for (i = object.length-1; i > -1 ; i--) {
    if ((object[i].value != ""))
      index = i;
    if (object[i].value == objectValue)
      break;
  }
  return index
}


//
// Project change request functions
// ================================


//
//  B10_toggleIsAssigned_ChangeRequest() -- toggle assign to user display in project change view
//
function B10_toggleIsAssigned_ChangeRequest(frmParent) {
  if (frmParent.ctlIsAssigned.checked) {
    // assign change
    frmParent.ctlIsAssigned.value = 1;
    document.all.frmIsAssigned.style.display = "";
    frmParent.ProjectChange_UserAssigned[B10_radioFindIndexByValue(frmParent.ProjectChange_Notify, "")].checked = true; // check first radio by default
     // enable notification to assigned user
    frmParent.ProjectChange_Notify[B10_radioFindIndexByValue(frmParent.ProjectChange_Notify, "assigned")].disabled = false;
    B10_setDefaultNotify_ProjectChange(frmParent);
  } else {
    /// don't assign change
    frmParent.ctlIsAssigned.value = 0;
    document.all.frmIsAssigned.style.display = "none";
     // disable notification to assigned user
    frmParent.ProjectChange_Notify[B10_radioFindIndexByValue(frmParent.ProjectChange_Notify, "assigned")].disabled = true;
    B10_setDefaultNotify_ProjectChange(frmParent);
    with (frmParent) { B10_radioClear(ProjectChange_UserAssigned); }
  }
}

//
//  B10_toggleNotify_ChangeRequest() -- toggle notify project team display in project change view
//
function B10_toggleNotify_ChangeRequest(frmParent) {
  if (frmParent.ctlNotify.checked) {
    // notify
    frmParent.ctlNotify.value = 1;
    document.all.frmNotify.style.display = "";
    B10_setDefaultNotify_ProjectChange(frmParent);
  } else {
    // don't notify
    frmParent.ctlNotify.value = 0;
    document.all.frmNotify.style.display = "none";
    B10_setDefaultNotify_ProjectChange(frmParent);
    with (frmParent) { B10_radioClear(ProjectChange_Notify); }
  }
}

//
//  B10_setDefaultNotify_ProjectChange() -- sets the default checked radio button for email notification
//  depending on assigned/unassaign, notify/don't notify status
//
function B10_setDefaultNotify_ProjectChange(frmParent) {
  if (frmParent.ctlNotify.checked == false) {
    B10_radioClear(frmParent.ProjectChange_Notify);
  } else {
    B10_radioClear(frmParent.ProjectChange_Notify);
    if (frmParent.ctlIsAssigned.checked) {
      frmParent.ProjectChange_Notify[B10_radioFindIndexByValue(frmParent.ProjectChange_Notify, "assigned")].checked = true;
    } else {
      frmParent.ProjectChange_Notify[B10_radioFindIndexByValue(frmParent.ProjectChange_Notify, "internal")].checked = true;
    }
  }
}


//
// Project issue functions
// ================================

//
//  B10_toggleIsAssigned_Issue() -- toggle assign to user display in issue view
//
function B10_toggleIsAssigned_Issue(frmParent) {
  if (frmParent.ctlIsAssigned.checked) {
    // assign change
    frmParent.ctlIsAssigned.value = 1;
    document.all.frmIsAssigned.style.display = "";
    frmParent.ProjectIssue_UserAssigned[B10_radioFindIndexByValue(frmParent.ProjectIssue_Notify, "")].checked = true; // check first radio by default
     // enable notification to assigned user
    frmParent.ProjectIssue_Notify[B10_radioFindIndexByValue(frmParent.ProjectIssue_Notify, "assigned")].disabled = false;
    B10_setDefaultNotify_Issue(frmParent);
  } else {
    /// don't assign change
    frmParent.ctlIsAssigned.value = 0;
    document.all.frmIsAssigned.style.display = "none";
     // disable notification to assigned user
    frmParent.ProjectIssue_Notify[B10_radioFindIndexByValue(frmParent.ProjectIssue_Notify, "assigned")].disabled = true;
    B10_setDefaultNotify_Issue(frmParent);
    with (frmParent) { B10_radioClear(ProjectIssue_UserAssigned); }
  }
}

//
//  B10_toggleNotify_Issue() -- toggle notify project team display in project change view
//
function B10_toggleNotify_Issue(frmParent) {
  if (frmParent.ctlNotify.checked) {
    // notify
    frmParent.ctlNotify.value = 1;
    document.all.frmNotify.style.display = "";
    B10_setDefaultNotify_Issue(frmParent);
  } else {
    // don't notify
    frmParent.ctlNotify.value = 0;
    document.all.frmNotify.style.display = "none";
    B10_setDefaultNotify_Issue(frmParent);
    with (frmParent) { B10_radioClear(ProjectIssue_Notify); }
  }
}

//
//  B10_setDefaultNotify_Issue() -- sets the default checked radio button for email notification
//  depending on assigned/unassaign, notify/don't notify status
//
function B10_setDefaultNotify_Issue(frmParent) {
  if (frmParent.ctlNotify.checked == false) {
    B10_radioClear(frmParent.ProjectIssue_Notify);
  } else {
    B10_radioClear(frmParent.ProjectIssue_Notify);
    if (frmParent.ctlIsAssigned.checked) {
      frmParent.ProjectIssue_Notify[B10_radioFindIndexByValue(frmParent.ProjectIssue_Notify, "assigned")].checked = true;
    } else {
      frmParent.ProjectIssue_Notify[B10_radioFindIndexByValue(frmParent.ProjectIssue_Notify, "internal")].checked = true;
    }
  }
}
