<!-- //-- Begin


function focus_on_textbox(){
	
var n = 'show_notes_slidedown'; var notesObj=MM_findObj(n); notesObj.focus();	
	
}

function restricted_chars(e){
	//-- Prevent the user from entering restricted chars.
	
//alert('restricted_chars');
	
	var rc = document.all? window.event.keyCode:e.which;
	var ok = rc;
	var msg = '';
	
//alert(rc);

	var show_notes_slidedownObj = MM_findObj("show_notes_slidedown");
	var allow_this_field_for_restricted_charsObj = MM_findObj('allow_this_field_for_restricted_chars');
	var use_alternative_field = false;
	var alternative_field = 'not found';
	if(allow_this_field_for_restricted_charsObj){
		if(allow_this_field_for_restricted_charsObj.value.length > 0){
			use_alternative_field = true;
		}
	}
	
	var restricted_ok = false;
	if(show_notes_slidedownObj){
		if(show_notes_slidedownObj.notesHasFocus == true){
			restricted_ok = true;
		}
	}
	
	if(use_alternative_field == true){
		restricted_ok = true;
	}
	
	if(restricted_ok == true){
		//alert('restricted_chars_msg');
		ok = restricted_chars_msg(rc);
	}else{
		//alert('restricted_chars_trap_13');
		ok = restricted_chars_trap_13(rc);
	}
	
	return ok;
}

function restricted_chars_trap_13(rc){
	
	//-- If the notes field has focus then the javascript function restricted_chars()
	//-- allows line return char(13) otherwise return is converted to a tab to allow
	//-- navigation from one screen field to the next by pressing 'RETURN'
		
	if(rc==13){
//alert('returning 9');
		ok = 9;
	}else{
		ok = restricted_chars_msg(rc);
	}
	
	return ok;
}

//function restricted_chars_ignore_13(rc){
//	//-- Prevent the user from entering restricted chars.
//	
////alert('restricted_chars_ignore_13');
//	var ok = rc;
//	
//	if(rc==13){
//		ok = 10;  //-- Line feed
//	}else{
//		ok = restricted_chars_msg(rc);
//	}
//	
//	return ok;
//}

function restricted_chars_msg(rc){
	
//alert('function restricted_chars_msg');	
	
	var ok = rc;
	var msg = '';
	
//alert(rc);
	
	switch(rc){
		case 34: //-- "
			msg = 'quote';
			break;
//		case 37: //-- %
//			msg = 'percent';
//			break;
		case 42: //-- *
			msg = 'asterisk';
			break;
		case 60: //-- <
			msg = 'less than';
			break;
		case 61: //-- =
			msg = 'equals';
			break;
		case 62: //-- >
			msg = 'greater than';
			break;
//		case 63: //-- ?
//			msg = '';
//			break;
		case 92: //-- \
			msg = 'back slash';
			break;		
	}
	
	if(msg.length > 0){
		msg = 'Reserved Character\n\n'+
			  'Please do not use the \''+msg+'\' key.';
		ok = 32;
		alert(msg);
	}
		
	return ok;
}

document.onkeypress = restricted_chars;
if(document.layers) document.captureEvents(Event.KEYPRESS);

function do_onclick_part(rowId){
	//-- Search screen contain rows of records.
	//-- The final cell is usually the 'Notes' button
	//-- The entire row EXEPT the notes button cell must perform an onclick
	//-- The actions to be taken 'onclick' are hwld in the field onclick_part_<rowId>
	
//alert('function do_onclick_part(');
	
	var n = "onclick_part_"+rowId;
	var onclick_partObj = MM_findObj(n);
	
	if(!onclick_partObj){
		alert("The hidden '"+n+"' field is missing from your form.");
	}else{
		var onclick_val = onclick_partObj.value;
		//onclick_val = addslashes(onclick_val);
//alert(onclick_val);
		eval(onclick_val);
	}
	
}

function checkToSeeIfImClosed(obj_id, form_action){
//-- Used by the calendar <div> code to check if the <div> has been closed (hidden) when the calendar is clicked.
//-- Sometimes the user clicks the month or year and has not selected a date, which then closes the <div>
//-- When the <div> has been closed we want to perform the 'form_action'.

//alert('function checkToSeeIfImClosed');

//alert(obj_id);

	var obj = MM_findObj(obj_id);
	var checker = 0;

	for(var i=0;i<=3000;i++){
		
		checker++;
		//-- Check 3 times, every 1000
		if(checker==100){
			checker=0;
			if(obj.style.visibility=='hidden'){
				setFormTo(form_action,0.1);
				break;
			}
		}
	}

}

function alterMyRows(obj_name, min_rows){
//-- Dynamically alter the number of lines in a text-area as the user is typing.

//alert('function alterMyRows('+obj_name+' '+min_rows+')');

	if(isNaN(min_rows)){
		min_rows = 1;
	}

	var obj = MM_findObj(obj_name);
	if(!obj){
		echo("The field '"+obj_name+"' is not present in your form.");
	}else{
	
		var obj_cols = obj.cols;
		var hold_rows = obj.rows;
		var val = Trim(obj.value);
		var idd_len = val.length;
		var no_of_rows = 1;
	
		if(idd_len>0){
		
			//-- Has the auto-text-wrap left a space on the end of the first line?
			var bdry_fix1 = 0;
			if(idd_len>obj_cols){
				var short_val = val.substring(0,obj_cols -1);
				var bdry_fix1 = get_length_at_last_word_boundary(short_val);
			}
	
			//-- Has the auto-text-wrap left a space on the end of the second and subsequent lines?
			var short_val = '';
			var bdry_fix2 = 0;
			for(ibx=2;ibx<=100;ibx++){
//alert(i+' obj_cols*ibx='+obj_cols*ibx+'  idd_len='+idd_len);				
				if(idd_len>(obj_cols *ibx)){
					short_val = val.substring(obj_cols,(obj_cols *ibx)-1);
					bdry_fix2 = bdry_fix2 + get_length_at_last_word_boundary(short_val);
//alert('bdry_fix2='+bdry_fix2);					
				}else{
					break;
				}
			}
			
			var bdry_fix = bdry_fix1 + bdry_fix2;
	
			var found_half_widths = get_half_widths(val);
			
			idd_len = idd_len - found_half_widths + bdry_fix;
			
			var no_of_rows = parseInt(idd_len/obj_cols,10);
			if(no_of_rows <= idd_len/obj_cols){
				no_of_rows = no_of_rows +1;
			}
		}
	
		if(hold_rows != no_of_rows){
			obj.rows = no_of_rows;
		}

		if(obj.rows < min_rows){
			obj.rows = min_rows;
		}
	}
}

function get_half_widths(val){
//-- Adjust string length for chars 'l' and 'i' and 'j' etc

//alert('function get_half_widths ');

	var idd_len = val.length;

	var found_half_widths = 0;
	var one_char = '';

	for(var i=0;i<idd_len;i++){
		one_char = val.substring(i,i+1);
		if(one_char=='i' || one_char=='I' || one_char=='j' || one_char=='l' || one_char==':' || one_char==';' || one_char=='.' || one_char==','){
			found_half_widths++;
		}
		if(one_char>='A' && one_char<='Z'){
			found_half_widths = found_half_widths - 1;
		}

	}

	found_half_widths = parseInt((found_half_widths/2),10);

	return found_half_widths;
	
}

function get_length_at_last_word_boundary(val){

//alert('function get_length_at_last_word_boundary '+val);

	var half_widths = get_half_widths(val);
	var idd_len = val.length + half_widths;
	for(var i=idd_len;i>=0;i--){
		one_char = val.substring(i,i+1);
		if(one_char==' '){
			break;
		}
	}

//alert('function get_length_at_last_word_boundary OUT');

	return idd_len - i;
}

function setToView(){

//alert('function setToView');

	cursorwait();
	var MM_formUsageObj = MM_findObj('MM_formUsage');
	MM_formUsageObj.value = 'view';
}

function setToRefresh(){

//alert('function setToView');

	cursorwait();
	var MM_formUsageObj = MM_findObj('MM_formUsage');
	MM_formUsageObj.value = 'refresh';
}

function setToGetDetail(){

//alert('function setToView');

	var MM_formUsageObj = MM_findObj('MM_formUsage');
	MM_formUsageObj.value = 'get_detail';
}

function orderby_push(colName, currentDirection){
	//-- Push the last column name onto a queue.
	
//alert('function orderby_push('+colName+' '+currentDirection);
	
	//-- First remove any occurences of the current column
	if(remove_from_queue(colName)){
		var orderby_queueObj = MM_findObj('orderby_queue');
		if(!orderby_queueObj){
			alert("The 'orderby_queue' hidden field is missing from your form.");
		}
		var orderby_queue_val = orderby_queueObj.value;
		
		//-- The hidden field object 'orderby_queue_has_changed' is used in the PHP function make_the_orderby_part
		//-- to determine if the screen refresh is due to the user selecting a new order by field or not.
		var orderby_queue_has_changedObj = MM_findObj('orderby_queue_has_changed');
		if(!orderby_queue_has_changedObj){
			alert("The 'orderby_queue_has_changed' hidden field is missing from your form.");
		}
		orderby_queue_has_changedObj.value = 'y'
			
		//-- Now add the field name and direction to the end of the queue.
			
		if(currentDirection == "ASC"){
			direction = "DESC";
		}else{
			direction = "ASC";
		}
		
		if(orderby_queue_val.length > 0){
			orderby_queueObj.value = orderby_queue_val+'~'+colName+' '+direction;
		}else{
			orderby_queueObj.value = colName+' '+direction;
		}
		
//alert(orderby_queueObj.value);
		
		setFormTo('view', 1);
	
	}
}

function remove_from_queue(colName){
			
	//-- Remove any occurences of the current column
	var foundObj_flag = true;
	var orderby_queueObj = MM_findObj('orderby_queue');
	
	if(!orderby_queueObj){
		alert("Your form does not contain the hidden 'orderby_queue' field.");
		foundObj_flag = false;
	}else{

		var orderby_queue_val = orderby_queueObj.value;
		
		if(orderby_queue_val.length > 0){
			var search_str = colName;
			var ptr1 = orderby_queue_val.indexOf(search_str);  //-- ptr1 is the start of the string to be extracted
		
			if(ptr1 > -1){
				//-- Look for the start of the next orderby field in the queue
				
				var ptr2 = orderby_queue_val.indexOf('~', parseInt(ptr1+1));
				
				//-- Is there only one field_name in the queue?
				//-- Otherwise
				//-- Is the field_name to be extracted
				//-- 	a) at the front
				//--	b) in the middle
				//--	c) at the end
				
				var hold = orderby_queue_val;
				
				if(ptr1 == 0 && ptr2 < 0){
					//alert('//-- There is there only one field_name in the queue');
					orderby_queue_val = '';
				}else{
					//alert('//-- There is more than one field_name in the queue.');
					if(ptr1 == 0){
						//alert('//-- The field_name to be extracted is at the front of the queue.');
						orderby_queue_val = orderby_queue_val.substring(ptr2+1);
					}else{
						if(ptr2 < 0){
							//alert('//-- The field_name to be extracted is at the end of the queue.');
							orderby_queue_val = orderby_queue_val.substring(0, ptr1-1);
						}else{
							//alert('//-- The field_name to be extracted is in the middle of the queue.');
							orderby_queue_val = orderby_queue_val.substring(0, ptr1-2)+orderby_queue_val.substring(ptr2-1);
						}
					}
				}
		
				//alert('removed one before='+hold+' after='+orderby_queue_val);
			}
			orderby_queueObj.value = orderby_queue_val;
		}
	}
	
	return foundObj_flag;
}
	
function openChild(file,window) {
//-- Open a window for a select form that will return the key ID of the selected record.

//alert('function openChild');

	var width="920", height="450";
	var left = (screen.width/2) - width/2;
	var top = (screen.height/2) - height/2;
	var styleStr = 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbar=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	
	childWindow=open(file,window,styleStr);
    
	if(childWindow.opener == null) childWindow.opener = self;
}

function openSelectWindow(theURL,winName, winwidth, winheight) {
//-- Opens a window that displays a selection list.

	var newwindowObj = false;

	if(!winwidth || winwidth.length ==0){
		winwidth = 1100;
	}
	if(!winheight || winheight.length ==0){
		winheight = 600;
	}	
	var features = 'toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width='+winwidth+',height='+winheight;	
	
	newwindowObj = MM_openBrWindow(theURL,winName,features);
	
	//return false;
	return newwindowObj;

}

function openStandardWindow(theURL,winName, winwidth, winheight) {
//-- Opens a window with a specified size.

//alert('function openStandardWindow('+theURL+' '+winName+')');

	var newwindowObj = false;

	if(!winwidth){
		winwidth ='';
	}
	if(winwidth.length ==0){
		winwidth = 1100;
	}
	if(!winheight){
		winheight = '';
	}
	if(winheight.length ==0){
		winheight = 800;
	}
	if(!winName){
		winName = '';
	}
	if(winName.length ==0){
		winName = "stdWin";
	}
	if(!theURL){
		theURL = '';
	}
	if(theURL.length ==0){
		alert('No URL passed to function openStandardWindow.');
	}else{
		var features = 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+winwidth+',height='+winheight;
	  
		newwindowObj = MM_openBrWindow(theURL,winName,features);
	}
	
	//return false;
	return newwindowObj;

}

function openWindow(theURL,winName) {
//-- Opens a window. No size specified

	var newwindowObj = false;

	if(!winName){
		winName = "standardWin";
	}
	
//alert('function openWindow('+theURL+' '+winName+')');

	var features = 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes;';
//alert(theURL);
  
	newwindowObj = MM_openBrWindow(theURL,winName,features);
	
	//return false;
	return newwindowObj;

}

function gotoURL(theURL){
	document.location.href = theURL;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0

//alert('function MM_openBrWindow '+theURL);

	var newwindowObj = false;

	var newwindowObj = window.open(theURL,winName,features);

	if(!newwindowObj){
		alert('Could not open '+theURL);
	}else{
//alert(getKeys(newwindowObj));
		//-- A window with the same name may already be open, so force it to the top of all displayed windows.
		if(window.focus){
			newwindowObj.focus();
		}
	}
	
	//return false;
	return newwindowObj;
}

function getKeys(obj){ 
   var keys = []; 
   for(var key in obj){ 
      keys.push(key); 
   } 
   return keys; 
} 

function MM_findObj(n, d) { //v4.01

  var p,i,x;
  try{
	  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(var i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(var i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); 
  }catch(err){
	  var caller_is = "caller is " + MM_findObj.caller.toString();
	  alert('ERROR in MM_findObj\n\n'+caller_is.split('{',1));
  }

  //if(!x){alert('not found '+n);}else{alert('found '+x.name);}
  return x;
}

function setFocus(objName) {
	//-- Set the focus to the named HTML FORM object.
//alert('function setFocus');	
	MM_findObj(objName).focus();
}


function selectAll(formObj, isInverse) {
	
//alert('function selectAll');

   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];
      if(fldObj.type == 'checked')
      { 
         if(isInverse)
            fldObj.checked = (fldObj.checked) ? false : true;
         else fldObj.checked = true; 
       }
   }
}


function checkboxLabel(boxName) {
//-- Switch the checkbox label class between 'normmal'-not selected and 'bold'-selected	

//alert('function checkboxLabel');

	var chxObj = MM_findObj(boxName);
	var labName = 'lab_'+boxName;
	var chxLabelObj = MM_findObj(labName);
	
	if(chxObj.checked == true) {
		chxLabelObj.style.fontWeight='normal';
	}
	else {
		chxLabelObj.style.fontWeight='bold'; 
	}
}

function resetCheckboxLabel(boxName) {
	
//alert('function resetCheckboxLabel');	

	var chxObj = MM_findObj(boxName);
	var labName = 'lab_'+boxName;
	var chxLabelObj = MM_findObj(labName);
	
	if(chxObj.checked == true) {
		chxLabelObj.style.fontWeight='bold';
	}
	else {
		chxLabelObj.style.fontWeight='normal'; 
	}
}

function resetAllCheckboxLabelsThisObj(thisObj) {
//-- see resetAllCheckboxLabels(formName) { below

//alert('function resetAllCheckboxLabelsThisObj');
	try{
		var formName = thisObj.form.name;
		resetAllCheckboxLabels(formName);
	}catch(err){
		alert("Error "+err+" in function resetAllCheckboxLabelsThisObj");
	}
}

function resetAllCheckboxLabels(formName) {
//-- Reset all the forms labels. Set the text attribute to bold/normal after the form 'Reset' button has been clicked.
//-- This allows for the checkbox default to be either checked or unchecked.

//alert('function resetAllCheckboxLabels');

	var formObj = MM_findObj(formName);
	
	if(!formObj){
		alert("The form '"+formName+"' does not exist.");
	}else{
	
		for(var i=0; i < formObj.length; i++)
		{
			fldObj = formObj.elements[i];
			if(fldObj.type == 'checked')
			{ 
				resetCheckboxLabel(fldObj.name);
			}	
		}
	}
}

function mySubmit(formName) {
//-- resets all checkbox labels after the 'reset' form button has been clicked.

//alert('function mySubmit');

	//var formObj = MM_findObj(formName);

    //setTimeout('formObj.reset()',1000);
    setTimeout('resetAllCheckboxLabels("AddUserform")',1000);	
    //return true;
}

function copyValue(fromName, toName) {
//-- Copy the value from the first object to the second object	

//alert('function copyValue');
	
	var fromObj = MM_findObj(fromName);
	if(!fromObj && toObj){
		alert("The '"+fromName+"' object does not exist in your form.");
	}
	var toObj = MM_findObj(toName);
	if(!toObj && toObj){
		alert("The '"+toName+"' object does not exist in your form.");
	}
	
	if(fromObj && toObj){
		toObj.value = fromObj.value;
	}
}


function setSexFromTitle(titleName, sexName, dropdown_sexName) {
//-- Based on the values of the Title field pre-set the Sex field.
//-- The title field and sex field must be drop down boxes

//alert('function setSexFromTitle');

	var isDropDownFlag = false;

	titleObj = MM_findObj(titleName);

//	var titleObj = MM_findObj(titleName);
	var sexObj = MM_findObj(sexName);
	var sexdropdownObj = MM_findObj(dropdown_sexName);	
	
	if(sexdropdownObj.type == "select-one"){
		isDropDownFlag = true;
	}else{
		isDropDownFlag = false;
	}
		
	var titleValue = titleObj.value.toLowerCase();

	switch(titleValue) {
		case "dr.":
			if(isDropDownFlag == false){
				sexdropdownObj.value = sexObj.value;
			}else{
				sexdropdownObj.disabled = false;
				sexObj.value = sexdropdownObj.value;
				
				if(sexObj.value == 'M'){
					sexdropdownObj.selectedIndex = 1;
				} else {
					sexdropdownObj.selectedIndex = 0;
				}
			}
			break;		
		case "mr.": 
		case "lord":
		case "sir":
			if(isDropDownFlag == false){
				sexdropdownObj.value = 'M';
			}else{	
				sexdropdownObj.selectedIndex = 1;
				sexdropdownObj.disabled = true;
				sexObj.value = 'M';
			}
			break;
		case "mrs.":	
		case "ms.":			
		case "lady":
			if(isDropDownFlag == false){
				sexdropdownObj.value = 'F';
			}else{
				sexdropdownObj.selectedIndex = 0;
				sexdropdownObj.disabled = true;
				sexObj.value = 'F';
			}
			break;				
		default :
			if(isDropDownFlag == false){
				sexdropdownObj.value = 'M';
			}else{
				sexdropdownObj.selectedIndex = 1;
				sexdropdownObj.disabled = false;
				sexObj.value = 'M';
			}
			break;		
	}
	
}

function overColour(fieldName, newColour, usecursorhand) {
//-- Record the current cell colour in a hidden field named 'holdColour'
//-- then set the field colour as per the input param.

//alert('function overColour fieldName='+fieldName + ' newColour=' + newColour);

	if(typeof(usecursorhand) == 'undefined'){
		usecursorhand = true;
	}

	var MM_formUsageObj = MM_findObj('MM_formUsage');
	if(MM_formUsageObj){
	
		var targetObj = MM_findObj(fieldName);
		if(!targetObj){
			alert("Error in function overColour.\nThe fieldName "+fieldName+" does not exist in the form.");
		}else{
			var holdObj = MM_findObj('holdColour');
			if(!holdObj){
				alert("Error in function overColour.\nThe hidden object 'holdColour' does not exist in the form.");
			}else{
				holdObj.value = targetObj.bgColor;
				targetObj.bgColor = newColour;
				if(usecursorhand == true){
					cursorhand();
				}
			}
		}
	}
//alert('function overColour OUT');	
}

function restoreColour(fieldName) {
//-- Restore the row colour previously set in function overColour()

//alert('function restoreColour');

	var MM_formUsageObj = MM_findObj('MM_formUsage');
	if(MM_formUsageObj){
		
		var targetObj = MM_findObj(fieldName);
		var holdObj = MM_findObj('holdColour');
		if(!holdObj){
			alert("The field 'holdColour' does not exist in your form.\n\nPlease press F5 to refresh the screen.");
		}else{
			targetObj.bgColor = holdObj.value;
			cursordefault();
		}
	}

}

//function reset_MM_formUsage(formUsage){
////-- Reset the MM_formUsage to the input value
//alert('function reset_MM_formUsage');
//
//	var MM_formUsageObj = MM_findObj('MM_formUsage');
//
//	if(!MM_formUsageObj){
//		alert('ERROR... your screen form does not have a MM_formUsage hidden field.');
//	}else{
//		MM_formUsageObj.value = formUsage;
//	}	
//}

var global_disable_show_notes_slidedown = false;

function shownotes(notesObjName) {
//-- Each row has a hidden notes field. Show the field at the bottom of the screen as the cursor passes over the displayed row.

//alert('function shownotes =='+notesObjName+'==IN==');

	var objNotes = MM_findObj(notesObjName);
	var notes_are_disabled = false;
	var disable_shownotesObj = MM_findObj('disable_shownotes');

	if(disable_shownotesObj){
		if(disable_shownotesObj.value == 'disabled'){
			notes_are_disabled = true;
		}
	}
	
//if(notes_are_disabled == true){
//	alert('notes_are_disabled == true');
//}else{
//	alert('notes_are_disabled ==false');
//}
			
	if(!objNotes){
		alert("Your form does not contain the notes field '"+notesObjName+"'.");
	}else{
//		if(disable_shownotesObj){
			if(notes_are_disabled == false){
				if(global_disable_show_notes_slidedown == false){	
					//-- Set the hidden field value to the name of the current notes field
					var notes_field_nameObj = MM_findObj('notes_field_name');
					if(notes_field_nameObj){
						notes_field_nameObj.value = notesObjName;
						flag_notes_exist('on');
					}
				}
				
				var objShowNotes = MM_findObj('show_notes');	
				if(objShowNotes){
					//-- The old notes field which may be displayed permanently at the bottom of the screen.
					objShowNotes.value = objNotes.value;
				}
			}
//		}
	}
//alert('function shownotes =='+notesObjName+'==OUT==');
	
}

function clearnotes() {

//alert('function clearnotes');

	var disable_shownotesObj = MM_findObj('disable_shownotes');
	if(disable_shownotesObj){
		if(disable_shownotesObj.value != 'disabled'){
		
			var objShowNotes = MM_findObj('show_notes');
			if(objShowNotes){
				objShowNotes.value = '';
			}
			
			if(global_disable_show_notes_slidedown == false){
				var show_notes_slidedownObj = MM_findObj('show_notes_slidedown');
				if(show_notes_slidedownObj){
					show_notes_slidedownObj.value = '';
				}
			}
		}
	}
}


function mobileformat(mobileObj){
//-- Format the mobile number to #### ### ## ##

//alert('function mobileformat');

	if(typeof(mobileObj) == 'object'){
	
		var mobileno = mobileObj.value + " ";  //-- Force int to string.
	
		mobileno = removeWhiteSpace(mobileno);
		mobileObj.value = mobileno;
	
		var mobLen = mobileno.length;
	
		if(mobLen>5){
			var splitmobileno = mobileno.split("");
	
			mobileno = "";
			for(var i=0; i<mobLen; i++){
				mobileno += splitmobileno[i];
				if(i==3 || i==6 || i == 8){
					mobileno += " ";
				}
			}
		
		}
			
		mobileObj.value = mobileno;
	}
}


function NIformat(niObj){
//-- Format the National Insurance number to ## ## ## ## #

//alert('function niformat');

	if(typeof(niObj) == 'object'){
			
		var nino = niObj.value + " ";  //-- Force int to string.
	
		nino = removeWhiteSpace(nino);
		niObj.value = nino;
	
		var niLen = nino.length;
	
		if(niLen>5){
			var splitnino = nino.split("");
	
			nino = "";
			for(var i=0; i<niLen; i++){
				nino += splitnino[i];
				if(i==1 || i==3 || i == 5 || i == 7){
					nino += " ";
				}
			}
		
		}
			
		niObj.value = nino;
	}

}

function getFuncName() {
//-- Find the name of the function that calls this function
//-- The function name is used for debugging error messages.

//alert('function getFuncName');
var ownName = 'js-script';

/** THIS DOES NOT WORK===================================
	var ownName = arguments.callee.name();
	alert(ownName);
	ownName = ownName.substr('function '.length);        // trim off "function "
	ownName = ownName.substr(0, ownName.indexOf('('));        // trim off everything after the function name

**/
	
	return ownName;
}

//-- Use tick boxes named like 'name="delete_row_<?php echo($i); ?>"'
//-- to identify which rows should be deleted.
function confirm_delete_row(boxObj, row_id){
//-- Confirm that the selected row should be deleted.
//-- This function checks that the boxObj is a ticked checkbox.

//alert('function confirm_delete_row boxObj.name='+boxObj.name+' row_id='+row_id);

	if(boxObj.checked == true){
		if(!do_confirm_delete_row(row_id)){
			boxObj.checked = false;
		}
	}else{
		//-- Box has been clicked but it is NOT ticked
		result = mark_one_row(row_id, 'r');
	}
}

function do_confirm_delete_row(row_id){
//-- Confirm that the selected row should be deleted.

//alert('function do_confirm_delete_row '+row_id);

	var do_delete = true;

	if(mark_one_row(row_id, 'm')){
		if(!confirm('Are you sure you want to delete this row?')){
			do_delete = false;
			result = mark_one_row(row_id, 'r');
		}
	}
	
	return do_delete;
}

//function mark_deleted_row(do_refresh){
function mark_all_deleted_rows(){
//-- If one row has a ticked 'delete row' check box then mark the row for deletion.

//alert('function mark_all_deleted_rows()');

	var MM_formUsageObj = MM_findObj('MM_formUsage');
	var formEls=MM_formUsageObj.form.elements;
	var remove_len = 'delete_row_'.length;
	var found_ticked_box = false;
	
	var result = false;
	
	var fel = formEls.length;
	
	for(var i=0; i<fel; i++){
		currEl=formEls[i];
		currName=currEl.name;
		
		if(currName.indexOf('delete_row_')==0){ //-- Found a delete tick box
//alert('Found a delete tick box');
			currName_length = currName.length;
			//-- Make sure that there is a suffix to the 'delete_row_'
			if(currName_length > remove_len){
				
				row_id = currName.substring(remove_len,currName_length);
				
				theBoxObj = MM_findObj('delete_row_'+row_id);
				if(theBoxObj.checked == true){
					
					//-- At this point we have found a 'delete row' check box
					found_ticked_box = true;
					
					result = mark_one_row(row_id, 'm');
//					if(do_refresh == true){
//						break;
//					}
				}
//alert('row_id='+row_id+' '+remove_len+' '+currName_length);
			}
		}
	}

	return found_ticked_box;
}

function mark_one_row(row_id, mark_or_undo_flag){
//--
//-- NOTE. A row must contain at least one <input type="text> that is not hidden, a button or checkbox so that the row suffix can be found.
//--
//-- mark_or_undo_flag == 'm' mark the row for deletion.
//-- mark_or_undo_flag == 'r' remove the line through.

//alert('function mark_one_row('+row_id+')');

	var MM_formUsageObj = MM_findObj('MM_formUsage');
	var formEls=MM_formUsageObj.form.elements;
	
	if(mark_or_undo_flag != 'm' && mark_or_undo_flag != 'r'){
		alert("ERROR in func mark_one_row. The flag = '"+mark_or_undo_flag+"'.");
	}

	var row_id_suffix = "_"+row_id;
	var row_id_len = row_id_suffix.length +1;
	
	var started_row = false;
	
	for(ii=0; ii<formEls.length; ii++){
		currEl=formEls[ii];
		currName=currEl.name;
	
		//-- Only check the element if it is not disabled.
		if(!currEl.disabled && currEl.type != "hidden" && currEl.type != "button" && currEl.type != "checkbox"){

			//-- If the row_id is appended to the form element then the element is on the row to be marked for deletion.
			currName=currEl.name;
			currName_len = currName.length;
			pos = currName_len - row_id_len +1; //-- The position of row_id string in the element name.

			//-- Strip out the underline and row id
			var id_part = currName.substr(pos);

			if(id_part == row_id_suffix){
				if(currName.indexOf(row_id_suffix)==pos){	//-- the row_id (eg _1) exists as the end of the element name.
					started_row = make_object_class_delete(currName, currEl, started_row, mark_or_undo_flag);
					
					var hold_currEl = currEl;
					var hold_currName = currName;
					
				}
				
			}else{
				//-- This element does not have the required row id suffix
				//-- if elements have been found with the correct suffix then this must
				//-- now be the next row, so exit the for loop
				if(started_row == true){
					//-- Change the class of a row of text.
					//-- Each row should have an id="row_<number>"
					var n = "row_"+row_id;
					var rowObj = MM_findObj(n);
					if(rowObj){
						ignore_me = make_object_class_delete(rowObj.id, rowObj, started_row, mark_or_undo_flag);
					}
					
					break;
				}
			}

		}
	}
	
	return started_row;
}

function make_object_class_delete(currName, currEl, started_row, mark_or_undo_flag){
	
	//-- Ignore the changed and error fields.
	if(currName.indexOf('row_changed_')== -1 && currName.indexOf('row_error_')== -1 ){

		if(mark_or_undo_flag == 'm'){

			//-- Copy the class to a new attribute 'old_class' so that the class can be restored if required.
			var holdOldClassName = currEl.className.toLowerCase();
			
			if(holdOldClassName.length > 0){
//alert('make_object_class_delete currName='+currName+' holdOldClassName='+holdOldClassName);
				if(holdOldClassName.indexOf('deletethisrow') == -1){
					currEl.old_className = currEl.className;
					
					if(holdOldClassName.indexOf('centred') != -1){
						if(holdOldClassName.indexOf('disabled') != -1){
							currEl.className = 'deleteThisRowCentredDisabled';
						}else{
							currEl.className = 'deleteThisRowCentred';
						}
					}else{
						
						if(holdOldClassName.indexOf('right') != -1){
							if(holdOldClassName.indexOf('disabled') != -1){
								currEl.className = 'deleteThisRowRightDisabled';
							}else{
								currEl.className = 'deleteThisRowRight';
							}
	
						}else{
			
							if(holdOldClassName.indexOf('disabled') != -1){
								currEl.className = 'deleteThisRowDisabled';
							}else{
								currEl.className = 'deleteThisRow';
							}
						}
					}
		
					currEl.readOnly = true;

				}
			}
		}else{
			if(currEl.old_className != 'undefined'){
				currEl.className = currEl.old_className;
			}
			currEl.readOnly = false;
		}
		
		started_row = true;
	}
	
	return started_row;
}

function popupdetect(){
//-- Check to see if popup blocking is enabled.

	var popup_checkerObj = MM_findObj('popup_checker');
	//-- If the screen is refreshed we dont want the popup detect to keep checking
	//-- Eg Only check once.
	
	if(!popup_checkerObj){
		alert("The 'popup_checker' is missing from your form.");
	}else{
		if(popup_checkerObj.value.length == 0){
			popup_checkerObj.value = 'donepopup';
			//alert('Check popup');	
			var winpop = window.open('','','width=8,height=8,left=2000,top=0,scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no');
			if(!winpop){
				alert('You are using pop-up blocking.\n\nPlease change your web browser to       \nallow pop-ups from this website.');
			}else{
				var popUpsBlocked = true;
				winpop.close();
			}
		}else{
			//alert('dont check popup');
		}
	}
}

function resizeBox(obj){
//-- Used to resize the fields in the top filter bar.
//-- The fields are initially reduced in size to saxe space.
//-- When the user types info into the fields they expand to accomodate the text.

	//-- If the user is pressing the cursor keys so the field is not changing
	//-- then do nothing or the cursor will continously jump to the end of the line.
	var field_lengthObj = MM_findObj('field_length');
	var prev_field_length = 0;
	if(!field_lengthObj){
		alert("ERROR... the hidden field 'field_length' does not exist in your form.");
	}else{
		prev_field_length = field_lengthObj.value;
	}
	
	//-- Don't resize if the object field is empty.
//alert(obj.value.length +' '+ prev_field_length);
	if(obj.value.length > 0 && obj.value.length != prev_field_length){
		var w = 40;
		var l = 0.1;
		var theString = obj.value;
		
		for(var i=0;i<obj.value.length;i++){
			onechar = theString.substr(i,1);
			if(onechar >= 'a' && onechar <= 'z' || onechar == ' '){
				if(onechar == 'i' || onechar == 'l' || onechar == 'j'){
					l = parseFloat(l) + 0.34;
				}else{
					if(onechar == ' '){
						l = parseFloat(l) + 0.5;
					}else{
						l = parseFloat(l) + 0.98;
					}
				}
			}else{
				if(onechar == 'I'){
					l = parseFloat(l) + 0.34;
				}else{
					l = parseFloat(l) + 1.03;
				}
			}
		}
		
		if(w < (l +2)* 6){
			w = (l +2)* 6;
		}
	
		obj.style.width = w;

	}
	
	if(field_lengthObj){
		field_lengthObj.value = w;	
	}
	
}

function shrinkBox(obj, n){
	
	//-- Restore this object to its original size (as specified in parameter 'n')


	var field_width = 7.34 * n;
	
	obj.style.width = field_width;
}

function objectIsVisible(obj){
//-- Is the object visible?
//-- This test is used before setting object attributes that would give the object focus.
//-- If the object is not visible then an error would occur.

	var isNS = (navigator.appName == "Netscape"); 
	var isVisible = true;
	
	if(!obj){
		isVisible = false;
	}else{
	
		if(isNS) {
			if(obj.visibility == "hide"){
				isVisible = false;
			}
		}else {
			if(!obj.style){
				isVisible = false;
			}else{
				if(obj.style.visibility == "hidden"){
					isVisible = false;
				}
			}
		}
		
		if(obj.type == "hidden"){
			isVisible = false;
		}
	}
/**
	if(isVisible){
		alert(obj.name+' visible');
	}else{
		alert(obj.name+' not visible');
	}
**/

	return isVisible;
}

function get_vat(m){
	
//alert('function get_vat in misc.js THIS SHOULD NOT BE USED\nYou should be using function return_vat in vat.js');
	
	if(!isNaN(m)){

		var vat = parseInt(m * 100);
		
		vat = vat * 175;
//var o = vat;
		vat = vat + 556;
//alert('old='+o+' vat+555='+vat);
		vat = parseInt(vat / 1000);
//alert(vat);
		vat = vat / 100;
//alert(vat);
//vat = Math.round(vat*100)/100 ;

	}else{
		var vat = error;
	}
	
//alert('function get_vat OUT');
	
	return vat;
	
}

function addslashes(str) {
    //-- Escapes single quote, double quotes and backslash characters in a string with backslashes 
	
//alert('function addslashes()');
	
	//-- Just in case the string already has slashes.
	str = stripslashes(str);

 
    str = (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
	
	str = str.replace(/%/g, " \\% ");

//alert('2 addslashes='+str);
	
	return str;
}

function stripslashes(str) {
    // Strips backslashes from a string  
 
    str = (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
	
	str = str.replace(/ \% /g, "%");
	str = str.replace(/\%/g, "%");
	str = str.replace(/% /g, "%");
	str = str.replace(/ %/g, "%");
	
//alert('stripslashes='+str);

	return str;
}

function reset_limit(){
	
//-- This func is used by some of the top-of-the-page filter bars.
	
//-- When the user enters search criteria, using the top filter bar,
//-- the sql query LIMIT must be reset or the page displayed may be empty
//-- because the displayed page is past the selected data.
//--
//-- Reset the 2 LIMIT variables.

	//for(i=1;i<=7;i++){
	for(i=1;i<=3;i++){
	
		switch(i){
			case 1: p = '_bank_statRs'; break;
			case 2: p = '_chequeRs'; break;
			case 3: p = ''; break;
			case 4: p = ''; break;
			case 5: p = ''; break;
			case 6: p = ''; break;
			case 7: p = ''; break;
			case 8: p = ''; break;
		}
	
		pn = 'pageNum'+p;
		tr = 'totalRows'+p;
		
		pageNumObj = MM_findObj(pn);
		if(pageNumObj){
			pageNumObj.value = 0;
		}
		
		totalRowsObj = MM_findObj(tr);
		if(totalRowsObj){
			totalRowsObj.value=0;
		}

	}
}

function convert_pound(txt){
//-- Convert '£' to recognisable character in the text
	
	if(typeof(txt) == 'string'){
		var pound = '';
		pound = String.fromCharCode(163);
		
		txt = txt.replace(/£/g, pound);
	}
	
	if(typeof(txt) == 'undefined'){
		var txt = ' ';
	}
	
	return txt;
}

function pages_dd(obj){
	
//-- This func is called by the 'pages' drop down.
//-- When the user selects the page number for sql SELECT LIMIT this func updates the hidden pageNum field.
                    
	var pageNumObj = MM_findObj('pageNum');
	if(!pageNumObj){
		alert('Error... The hidden field \'pageNum\' does not exist in your form.');
	}else{
		pageNumObj.value = obj.options[obj.selectedIndex].value -1;
	}
	
	setFormTo('view');

}

function setFormTo(formAction, theDelay, show_error){
//-- Set the hidden field 'MM_formUsage' to identify if the record should be INSERTED or UPDATED or CLEARED.

//alert('function setFormTo '+formAction);

	if(!show_error){
		show_error = true;
	}

	cursorwait();

	var delaytime=50;
	
	if(theDelay){
		if(!isNaN(theDelay)){
			if(theDelay > 10){
				//alert('function setFormTo: The delay time should be <= 10');
			}else{
				delaytime=theDelay*200;
			}
		}
	}

	var hiddenObj = MM_findObj('MM_formUsage');
	if(!hiddenObj){
		if(show_error == true){
			alert("ERROR... Cannot save your information because your form does not contain the hidden 'MM_formUsage' field.");
		}
	} else {
		
		//if(hiddenObj.value != formAction){
			//-- Thisfunction 'setFormTo' will not allow a screen refresh twice for the same 'form action'
			//-- Eg. if MM_formUsage is already set to 'refresh' then it wont do it a second time until the MM_formUsage == ''
	
			hiddenObj.value = formAction;

			if(formAction == 'insert' || formAction == 'update') {
				if(validate_form(hiddenObj.form)){
					setTimeout("submit_form('MM_formUsage')",delaytime);
				}
			} else {
				setTimeout("submit_form('MM_formUsage')",delaytime);
			}

		//}
	}	

}

function submit_form(objName){
	
//alert('function submit_form '+objName);	
	
	//cursordefault();
	var obj = MM_findObj(objName);
	if(!obj){
		alert("ERROR... Cannot save your information because your form does not contain the'"+objName+"' field.");
	} else {
		obj.form.submit();
	}
}

function cursordefault(){	

	setTimeout("reset_cursor('default');",200);
}

function cursorwait(){

	setTimeout("reset_cursor('wait');",200);
	
}

function cursorhand(){	

	setTimeout("reset_cursor('pointer');",200);
}

function reset_cursor(cursor_type){
	
	try{
		document.body.style.cursor=cursor_type;
	}
	catch(err){
	}
	
}

function set_max_rows(){
	//-- Called when the max_rows drop down box is changed.
	//-- The hidden 'max_rows' object is updated before the screen is refreshed.
	
//alert('set_max_rows');
	
	var max_rowsddObj = MM_findObj('max_rowsdd');
	var max_rowsObj = MM_findObj('max_rows');
	
	if(max_rowsddObj && max_rowsObj){
		max_rowsObj.value = max_rowsddObj.options[max_rowsddObj.selectedIndex].value; 
		return true;
	}
	
//alert('set_max_rows');

	return false;
}

function clear_all_form_filter_fields(){
	//-- If $clear_all_form_filter_fields = 'y'
	//-- then find all fields in the form that  end in '_filter'
	//-- and set them to = '';
	//-- 
	//-- NOTE: The filter values should the reset (when required) at the top of the code
	//-- in the start of the php. This is because the php at the top of the code will use the
	//-- filter values to select from the DB.  Unfortunately, this javascript is executed after
	//-- the whole screen has loaded (the screen has to load for the filter fields to exist in the form)
	//-- To get around this the screen will be refreshed if any filter field have been reset by this function.
	
	var ok_to_continue = false;
	var got_error = false;
	var found_a_filter = false
	
	var formName = 'formhmopro';
	var formObj = MM_findObj(formName);
	if(!formObj){
		got_error = true;
		alert("ERROR... the form '"+formName+"' does not exist.");
	}

	if(got_error == false){
		var clear_all_form_filter_fieldsObj = MM_findObj('clear_all_form_filter_fields');
		if(!clear_all_form_filter_fieldsObj){
			alert("ERROR... The field 'clear_all_form_filter_fields' does not exist in your form");
		}else{
			if(clear_all_form_filter_fieldsObj.value == 'y'){
				ok_to_continue = true;
			}
		}
	}
	
	if(ok_to_continue == true){
		for(i=0; i<formObj.elements.length; i++){
			var field_name = formObj.elements[i].name;
		
			var slen = field_name.length;
			if(slen > 7){
				if(field_name.substr(length - 7) == '_filter'){
										
					found_a_filter = true;
										
					if(field_name == 'filter_type_filter'){
						formObj.elements[i].value = 'all';
					}else{
						if(field_name == 'selected_bank_account_type_filter'){
							formObj.elements[i].value = 'x';
						}else{
							formObj.elements[i].value = '';
						}
					}
				}
			}
		}
	}
	
	if(found_a_filter == true){
		
		//alert('function clear_all_form_filter_fields()');
		
		var MM_formUsageObj = MM_findObj('MM_formUsage');
		setFormTo(MM_formUsageObj.value);
	}
	
}

//-------------------------------------------------------------------------------------------
//-- Bank Account Filters
function reset_account_dropdowns(){
	//-- When the hide/show account tick box is clicked, reset both dropdowns to 'All'
	
	//-- Simple account select
	var selected_bank_account_type_filterObj = MM_findObj('selected_bank_account_type_filter');
	if(typeof(selected_bank_account_type_filterObj)=='object'){
		selected_bank_account_type_filterObj.selectedIndex = 0;
		set_cookie('HMOPRO_selected_bank_account_type_filter', 'x');
	}
	
	//-- Specific account select.
	var account_filterObj = MM_findObj('account_filter');
	if(typeof(account_filter_obj)=='object'){
		account_filter_obj.selectedIndex = 0;
		set_cookie('HMOPRO_account_filter', 'All');
	}
	
	//-- The current/all radio button
	var rad_acct_period_filterObj = MM_findObj('rad_acct_period_filter');
	if(typeof(rad_acct_period_filterObj)=='object'){
		if(rad_acct_period_filterObj){
		rad_acct_period_filterObj[1].checked = true;
		set_cookie('HMOPRO_rad_acct_period_filter', 'a');
		}
	}
	
	update_hidden_account_dropdown();
	
	 n='account_filter';
	 obj1=MM_findObj(n);
	 
	 n2='account_filter_default';
	 obj2=MM_findObj(n2);
	 
	 if(obj1 && obj2){
	 	obj1.value=obj2.value;
	 }
	 
	 reset_limit();
	 
	 update_hidden_account_dropdown();

	setFormTo('view');
	
}

function update_hidden_account_dropdown(){
	
//alert('function update_hidden_account_dropdown()');
	
	//-- The drop_down name is 'account_filter'
	//-- When the user makes a selection from the drop down the following hidden filter fields need to be updated
	//-- 	'selected_bank_sort_code_filter'
	//--    'selected_bank_account_number_filter'
	//--    'selected_bank_account_type_filter'
	
	//-- See inc_filter_bar/inc_filter_parts/inc_select_bank_acct_specific.php
	//-- See inc_filter_bar/inc_filter_parts/inc_select_bank_acct_specific_internal.php
	
	var do_this = false;
	
	var account_filter_obj = MM_findObj('account_filter');
	if(typeof(account_filter_obj)=='object'){
		if(account_filter_obj){
			do_this = true;
		}
	}
	
	if(do_this == false){
		var account_filter_obj = MM_findObj('internal_acct_desc_filter');
		if(typeof(account_filter_obj)=='object'){
			if(account_filter_obj){
				do_this = true;
			}
		}
	}
	
	if(do_this == true){
		
		var selected_sort_code = '';
		var selected_acct_no = '';
		var selected_acct_type = '';
		var selected_acct_name = '';
		
		var selected_val = account_filter_obj.options[account_filter_obj.selectedIndex].value;
		var selected_val_array = selected_val.split('-');
		
		var account_ctr_obj = MM_findObj('account_ctr');
		var ctr = account_ctr_obj.value;
		for(ai=0; ai<ctr; ai++){
			var n1 = 'acct_no_list_'+ai;
			var n2 = 'sort_code_list_'+ai;
			var n3 = 'acct_type_list_'+ai;
			
			var acct_no_obj = MM_findObj(n1);
			var sort_code_obj = MM_findObj(n2);
			var acct_type_obj = MM_findObj(n3);
			
			if(sort_code_obj.value == selected_val_array[0] && acct_no_obj.value == selected_val_array[1]){
				selected_sort_code = sort_code_obj.value;
				selected_acct_no = acct_no_obj.value;
				selected_acct_type = acct_type_obj.value;
				break;
			}
		}
		
//alert(selected_val);
		
		var selected_bank_sort_code_filter_obj = MM_findObj('selected_bank_sort_code_filter');
		var selected_bank_account_number_filter_obj = MM_findObj('selected_bank_account_number_filter');
		var selected_bank_account_type_filter_obj = MM_findObj('selected_bank_account_type_filter');
		
//		var selected_bank_sort_code_filter_obj = MM_findObj('selected_bank_sort_code_filter');
//		var selected_bank_account_number_filter_obj = MM_findObj('selected_bank_account_number_filter');
//		var selected_bank_account_type_filter_obj = MM_findObj('selected_bank_account_type_filter');
		
		selected_bank_sort_code_filter_obj.value = selected_sort_code;
		selected_bank_account_number_filter_obj.value = selected_acct_no;
		selected_bank_account_type_filter_obj.value = selected_acct_type;
		
//		selected_bank_sort_code_filter_obj.value = selected_sort_code;
//		selected_bank_account_number_filter_obj.value = selected_acct_no;
//		selected_bank_account_type_filter_obj.value = selected_acct_type;
	}

//alert('done');

}



function update_cheque_book_account_dropdown(s){
	
//alert('function update_cheque_book_account_dropdown()');
	
	//-- The drop_down name is 'cheque_book_acct_type_<subscript>'
	//-- When the user makes a selection from the drop down the following fields need to be updated
	//-- 	'cheque_book_sort_code_<subscript>'
	//--    'cheque_book_account_number_<subscript>'
	//--    'cheque_book_account_type_<subscript>'
	
	//-- See inc_cheque_book_table.php
	
	var do_this = false;
	
	var n = "dd_cheque_book_acct_type_"+s;
	var cheque_book_acct_typeObj = MM_findObj(n);
	if(typeof(cheque_book_acct_typeObj)=='object'){
		if(cheque_book_acct_typeObj){
			do_this = true;
		}
	}
	
	if(do_this == true){
				
		var selected_sort_code = '';
		var selected_acct_no = '';
		var selected_acct_type = '';
		var selected_acct_name = '';
		
		var selected_val = cheque_book_acct_typeObj.options[cheque_book_acct_typeObj.selectedIndex].value;
		var selected_val_array = selected_val.split('-');
		
		var cb_account_ctrObj = MM_findObj('cb_account_ctr');
		var ctr = cb_account_ctrObj.value;
		for(ai=0; ai<ctr; ai++){
			var n1 = 'cb_acct_no_list_'+ai;
			var n2 = 'cb_sort_code_list_'+ai;
			var n3 = 'cb_acct_type_list_'+ai;
			
			var acct_no_obj = MM_findObj(n1);
			var sort_code_obj = MM_findObj(n2);
			var acct_type_obj = MM_findObj(n3);
			
			if(sort_code_obj.value == selected_val_array[0] && acct_no_obj.value == selected_val_array[1]){
				selected_sort_code = sort_code_obj.value;
				selected_acct_no = acct_no_obj.value;
				selected_acct_type = acct_type_obj.value;
				break;
			}

		}
//alert(selected_val);
		
		var n = "cheque_book_sort_code_"+s;	
		var cheque_book_sort_codeObj = MM_findObj(n);
		var n = "cheque_book_acct_no_"+s;
		var cheque_book_account_numberObj = MM_findObj(n);
		var n = "cheque_book_acct_type_"+s;
		var cheque_book_account_typeObj = MM_findObj(n);
		
		cheque_book_sort_codeObj.value = selected_sort_code;
		cheque_book_account_numberObj.value = selected_acct_no;
		cheque_book_account_typeObj.value = selected_acct_type;
		
	}

//alert('done');

}

function substr_count(string,substring,start,length)
{
 var c = 0;
 if(start) { string = string.substr(start); }
 if(length) { string = string.substr(0,length); }
 for (var i=0;i<string.length;i++)
 {
  if(substring == string.substr(i,substring.length))
  c++;
 }
 return c;
}


//-------------------------------------------------------------------------------------------

/*//-- To retrieve browser info use:
//--	Browser name: BrowserDetect.browser
//--	Browser version: BrowserDetect.version
//--	OS name: BrowserDetect.OS
//--
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if(dataString) {
				if(dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if(dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if(index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

alert('Browser name: '+BrowserDetect.browser+'\nBrowser version: '+BrowserDetect.version+'\nOS name: '+BrowserDetect.OS);


*/
// end hiding script from old browsers -->
