//Add or update the branch detail
function UpdateCostCentreBranch(BranchID){

	var AfterUpdate = function(oXML) {	

		var returnVal = oXML.responseText
		if (returnVal.substr(0,5) == "Error") {
			alert(returnVal);
			return;
		}
		else {
			//portal_reloadUserGrid()
			alert(returnVal);
			checkAction(20,76,2,null,false,null,false);
		}
		regularCursor();
	}
	
	//if (document.getElementById("txtBranchCode").value != "")
	//{
		if (document.getElementById("txtBranch").value != "")
		{
			var activeBit
			if (document.getElementById("chkActive").checked) {
				activeBit = "1";
			} else {
				activeBit = "0";
			}
			
			var page = "modules/costcentres/CostCentreBranches.asp";
			var	data = "action=updatebranch&" + fetchInputFormData("frmCostCentreBranch") + "&Active=" + activeBit;
			hiddenSubmit(page,data, AfterUpdate, 0, null,null, false);
		}
		else{
			alert ("Please enter a valid branch name");
			return;
		}
	//}
	//else{
	//	alert ("Please enter a valid branch code");
	//	return;
	//}
}

//Add or update the centre detail
function UpdateCostCentre(CentreID){

	var bool_update = false;
	
	var AfterUpdate = function(oXML) {	
		var returnVal = oXML.responseText
		if (returnVal.substr(0,5) == "Error") {
			alert(returnVal);
			return;
		}
		else {
			//portal_reloadUserGrid()
			alert(returnVal);
			checkAction(21,78,2,null,false,null,false);	
		}
		regularCursor();
	}
	
//	if (document.getElementById("txtCentreName").value != "")
//	{
		if (document.getElementById("selBranch").value != 0)
		{
				var activeBit
				if (document.getElementById("chkActive").checked) {
					activeBit = "1";
				} else {
					activeBit = "0";
				}
				
				if (document.getElementById("txtCentreCode").value == ""){
					
					if (confirm("Please note this Cost Centre will be added without a Code. Press OK to continue.")){
						bool_update = true;
					}
				}
				else{
					bool_update = true;
				}
				
				if (bool_update == true){
					var page = "modules/costcentres/CostCentres.asp"
					var	data = "action=updatecentre&" + fetchInputFormData("frmCostCentre") + "&Active=" + activeBit;
					hiddenSubmit(page,data, AfterUpdate, 0, null,null, false)
				}
		}
		else
		{
			alert ("Please select a valid branch before you proceed");
			return;
		}
		
//	}
//	else{
//		alert ("Please enter a valid centre name before you proceed");
//		return;
//	}
}
