<!-- //-- Begin

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);
	
	if(rc==13){
		ok = 9;
	}else{
		
		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');
		var orderby_queue_val = orderby_queueObj.value;
		
//		if(orderby_queue_val_len > 0){
//
//			//-- Is the queue already full?
//			//-- If yes the remove the first item pushed onto the queue.
//			var queue_ctr = orderby_queue_val.split("~").length;
//			if(queue_ctr >= maxQueueCount){
//				//-- Remove the first object in the queue
//				var ptr = orderby_queue_val.indexOf('~');
//				var new_orderby_queue_val = orderby_queue_val.substring(ptr, orderby_queue_val_len -1);
//				
//				orderby_queue_val = new_orderby_queue_val;
//			}
//		}
			
		//-- 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;
		}
		
		setFormTo('view', orderby_queueObj);
	
	}
}

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 setorderby(colName){
//-- Set the column name for the hidden orderby field.
//-- then refresh the screen so that the SQL SELECT script picks up the orderby field name
//-- and builds that name into the SQL ORDER BY statement.
//--
//-- Set the also_orderby to the previous value of the orderby.

//alert('function setorderby '+colName);

	cursorwait();

	colName = colName.toLowerCase();

	var n = 'orderby';
	var orderbyObj = MM_findObj(n);
	if(!orderbyObj){
		alert("ERROR... Could not find the 'orderby' form object.");
	}else{
		
//alert('function setorderby 1');
	
		var orderbyval = orderbyObj.value;
//alert('function setorderby 1a');

		if(orderbyval){
			orderbyval = orderbyval.toLowerCase();
			
			if(colName != orderbyval){
				//-- Copy the current orderby into also_orderby.
				//-- But not if the user is clicking on the same column teice to changr the order dorection.
				var also_orderbyObj = MM_findObj('also_orderby');
				if(also_orderbyObj){
					also_orderbyObj.value = orderbyval;
				}
			}
		}
	}
	
//alert('function setorderby 3');

	var n = 'orderdirection';
	var orderdirectionObj = MM_findObj(n);
	if(!orderdirectionObj){
		alert("ERROR... Could not find the 'orderdirection' form object.");
	}else{
//alert('function setorderby 2');

		var orderdirectionval = orderdirectionObj.value;
		if(orderdirectionval){
			orderdirectionval = orderdirectionval.toUpperCase();
		}
	}
//alert('function setorderby 4');	
	colName = colName.toLowerCase();

	//-- Is this a new column to sort on or a switch in direction for the same column?

//alert(orderbyval+"=="+colName);

	if(orderbyval == colName){

		//-- Same column, switch direction.
		if(orderdirectionval == 'DESC'){
			orderdirectionObj.value = 'ASC';
		}else{
			orderdirectionObj.value = 'DESC';
		}
	}else{
//alert('function setorderby 6');
		//-- New column to sort by
		orderbyObj.value = colName;
		orderdirectionObj.value = 'DESC';
	}
	
	setFormTo('view', orderbyObj);
}

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');

	var formName = thisObj.form.name;
	resetAllCheckboxLabels(formName);
}

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);

	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);
	var toObj = MM_findObj(toName);
	
	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 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+'==');

	var objNotes = MM_findObj(notesObjName);
	
	var objShowNotes = MM_findObj('show_notes');
	var show_notes_slidedownObj = MM_findObj('show_notes_slidedown');
	
	//var err = false;
	
	if(!objNotes){
		//err = true;
		alert("Your form does not contain the notes field '"+notesObjName+"'.");
	}else{
		
		if(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');
			notes_field_nameObj.value = notesObjName;
			flag_notes_exist('on');
			
			/*if(show_notes_slidedownObj){
				show_notes_slidedownObj.value = objNotes.value;
			}*/
		}
		
		if(objShowNotes){
			//-- The old notes field which may be displayed permanently at the bottom of the screen.
			objShowNotes.value = objNotes.value;
		}
		
	}
	
}

function clearnotes() {

//alert('function clearnotes');

	var objShowNotes = MM_findObj('show_notes');
	if(objShowNotes){
		objShowNotes.value = '';
	}
	
	if(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');

	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');

	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;
}

/*function user_check(loggedin_staff_id, s, e){
//-- Check to ensure that the user (record creator) exists on the current form

//alert('function user_check '+s+' '+e);

	var found_subscript = false;
	var istart = 0;
	var iend = 0;
	var subscript = '';
	
	if(isNaN(loggedin_staff_id)){	
		var msg = '========= YOUR USER SESSION HAS TIMED OUT =========   \n\n'+
		          '   Because your screen has been inactive for 30\n'+
				  '   minutes your session has ended and your logged\n'+
				  '   in user ID is blank. If you continue then any\n'+
				  '   INSERTS AND UPDATES YOU MAKE WILL FAIL.\n\n'+
				  'Please go back to the Admin Menu to refresh your ID.  ';
				  
		alert(msg);
	}else{
		
	
		if(s && e){
			if(s>=0 && e>=s){
				found_subscript = true;
				istart = s;
				iend = e;
			}
		}
	
		for(var i=istart; i<=iend; i++){
			if(found_subscript == true){
				subscript = '_'+i;
			}
		
		
			created_fieldname = 'rec_created_by_staff_id'+subscript;
			var rec_created_by_staff_idObj = MM_findObj(created_fieldname);
			updated_fieldname = 'rec_updated_by_staff_id'+subscript;
			var rec_updated_by_staff_idObj = MM_findObj(updated_fieldname);
			
	//alert('created_fieldname='+created_fieldname+'  updated_fieldname='+updated_fieldname);
			
			var theval = '';
			var errmsg = '';
			var err_field = '';
			var msg = '';
			var newUserId = '';
			
			if(rec_created_by_staff_idObj){
				theval = Trim(rec_created_by_staff_idObj.value);
				if(theval.length==0){
					errmsg += 'ERROR... the Created By Staff ID field is blank.\n('+created_fieldname+')';
					err_field = created_fieldname;
				}else{
					if(theval <=0){
						errmsg += 'ERROR... the Created By Staff ID must be greater than zero.\n('+created_fieldname+')';
						err_field = updated_fieldname;
					}
				}
			}
			
			user_id_err_msg(err_field, errmsg);
		
			if(rec_updated_by_staff_idObj){
				theval = Trim(rec_updated_by_staff_idObj.value);
				if(theval.length==0){
					if(errmsg.length > 1){
						errmsg += '\n\n';
					}
					errmsg += 'ERROR... the Updated By Staff ID field is blank.\n('+updated_fieldname+')';
					err_field = updated_fieldname;
				}else{
					if(theval <=0){
						errmsg += 'ERROR... the Updated By Staff ID must be greater than zero.\n('+updated_fieldname+')';
						err_field = updated_fieldname;
					}
				}
			}
			
			user_id_err_msg(err_field, errmsg);
		}
	}
//alert('function user_check OUT');
}*/

			
function user_id_err_msg(err_field, errmsg){
	
	if(errmsg.length > 1){
		msg = 'Enter the user ID to be used for the missing \''+err_field+'\'';
		
		errmsg += '\n\nYou cannot save or update a record with this error.';
		errmsg += '\n\nPlease return to the Admin Menu and logon.';

		alert(errmsg);
		var newUserId = prompt(msg);
		if(!isNaN(newUserId)){
			var rec_staff_idObj = MM_findObj(err_field);	
			rec_staff_idObj.value = newUserId;
		}
	}
}

//-- 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.

//alert('function confirm_delete_row');

	if(boxObj.checked == true){
		if(mark_one_row(row_id, 'm')){
			if(!confirm('Are you sure you want to delete this row?')){
				boxObj.checked = false;
				result = mark_one_row(row_id, 'r');
			}
		}
	}else{
		//-- Box has been clicked but it is NOT ticked
		result = mark_one_row(row_id, 'r');
	}
}

//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){
//--
//-- 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);
				}
				
			}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.
					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 mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no');
	if(!mine){
		alert('You are using popup blocking.\nPlease disable popup blocking for this website.');
	}else{
		var popUpsBlocked = true;
		mine.close();
	}
}

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 (isNS) {
		if(visibility == "hide"){
			isVisible = false;
		}
		if(obj.type == 'hidden' ){
			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){
//-- Set the hidden field 'MM_formUsage' to identify if the record should be INSERTED or UPDATED or CLEARED.

//alert('function setFormTo '+formAction);

	cursorwait();

	var delaytime=50;
	
	if(theDelay){
		if(!isNaN(theDelay)){
			if(theDelay > 10){
				alert('The delay time should be <= 10');
			}else{
				delaytime=theDelay*200;
			}
		}
	}

	var hiddenObj = MM_findObj('MM_formUsage');
	if(!hiddenObj){
		alert("ERROR... Cannot save your information because your form does not contain the hidden 'MM_formUsage' field.");
	} else {

		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(){	
	//document.body.style.cursor='default';
	setTimeout("document.body.style.cursor='default';",200);
}

function cursorwait(){
//alert('function cursorwait');	
	//document.body.style.cursor='wait';
	setTimeout("document.body.style.cursor='wait';",200);
	//set_cursor('wait');
	
	
}

function cursorhand(){	
	//document.body.style.cursor='pointer';
	setTimeout("document.body.style.cursor='pointer';",200);
}

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');
	
	max_rowsObj.value = max_rowsddObj.options[max_rowsddObj.selectedIndex].value; 
	
//alert('set_max_rows');

	return true;
}

// end hiding script from old browsers -->