function $id(a_strID){
	
	try{
		var l_objElement = document.getElementById(a_strID)
	}
	catch(err){
		var l_objElement =  null
		alert("Error: $id:" + a_strID + ", not found")
	}
	
	return l_objElement

}


function checkInputLength(a_objControl,a_lngMaxLength){
	//alert(document.all(a_objControl).value)
	//create a string object based on the current value of the specified control
	var l_strValue = new String(a_objControl.value)
	//if the length of the string object is greater than the supplied max length value
	if (l_strValue.length > a_lngMaxLength){
		//compose a message to inform the user
		var l_strMessage = "The maximum number of " + a_lngMaxLength + " characters, for this field has been exceeded.\n\r"
		l_strMessage = l_strMessage + "The value will be truncated to "+ a_lngMaxLength + " characters."
		alert(l_strMessage)
		//trim the control value to the max length
		//document.all(a_objControl).value = l_strValue.slice(0,a_lngMaxLength)
		a_objControl.value = l_strValue.slice(0,a_lngMaxLength)
	}
	//event.bubbleCancel = true
}


function whichElement(e)
{
var targ;
if (e!=null){
if (!e)
  {
  var e=window.event;
  }
if (e.target)
  {
  targ=e.target;
  }
else if (e.srcElement)
  {
  targ=e.srcElement;
  }
try{
if (targ.nodeType==3) // defeat Safari bug
  {
  targ = targ.parentNode;
  }
}
catch(err){}
var tname;
tname=targ.tagName;
}
else{
targ=null
}
return targ;
}

function enableForm(a_objEvent,a_objForm, a_bolReadOnly){
	var i
	//grab thw object, which has triggered the event which calls this function
	//alert (a_objForm.id)
	//alert(a_objEvent)
	var l_objCurrent = whichElement(a_objEvent)
	//alert("l_objCurrent.id = " + l_objCurrent.id)
	if (l_objCurrent==null){
		//the object which triggered this function, isn't on a form
		//so nothing needs to be set to read only
		//to prevent a atempt to disable a 'non-form',
		//set the current form object to be the supplied form object
		d_objCurrentForm = a_objForm
	}
	//test if the supplied form is the same as the current form
	if (d_objCurrentForm.id != a_objForm.id){
		//alert("the form of the event-firing object is different to that of the one being edited")
		//the form of the event-firing object is different to that of the one being edited
		//test if the data has changed
		if(d_bolFormChanged){
			//data on the form being edited has changed, inform the user that they need to save the record
			alert("You need to either save or discard the changes you have made to the previous record")
			a_objEvent.returnValue = false
			return false
		}
		else{
			//alert("the data has not changed")
			//the data has not changed
			//set the form to readonly
			enableForm(a_objEvent,d_objCurrentForm, true)
			
			//set the edited form to be the form of the trigger element
			d_objCurrentForm = a_objForm
			
			//set the newly selected form to be editable
			enableForm(a_objEvent,d_objCurrentForm, false)
			a_objEvent.returnValue = true
			return true
		}
	}
	else{
		//alert("the triggering element belongs to the form currently being edited")
		//the triggering element belongs to the form currently being edited
		if (a_bolReadOnly){
			//alert("the form is to be set to readonly")
			//the form is to be set to readonly
			//set the edited flag to false, as the form will be reset and modified values lost
			d_bolFormChanged = false
			//loop through all the 'input' form elements, setting visibility & readonly status
			//alert(a_objForm.id)
			//alert(a_objForm.id + ".elements.length = " + a_objForm.elements.length)
			
			//need to make sure the supplied object is a form
			if(a_objForm.tagName=="FORM"){
			
			for (i = 0; i <= (a_objForm.elements.length - 1); i++) 
			{                        
				//alert(document.all(a_objForm.id).elements[i].id)
				enableElement(a_objForm.elements[i],a_bolReadOnly)		  
				//class 2 elements are 'visible' when the form is in readonly mode
				if (a_objForm.elements[i].className =='2'){
						a_objForm.elements[i].style.display='block'
						a_objForm.elements[i].disabled=false
				}
				//class 2 elements are 'hidden' when the form is in readonly mode
				if (a_objForm.elements[i].className =='1'){
						a_objForm.elements[i].style.display='none'
				}
			}
			//loop through all elements of the form, to see if any other elements should have their
			//visibility set. This allows elements such as <DIV>'s, <FONT>'s etc to be switched on/off
			for (i = 0; i <= (a_objForm.childNodes.length - 1); i++) 
			{                        
				//alert(a_objForm.all[i].id)
				//class 2 elements are 'visible' when the form is in readonly mode
				if (a_objForm.childNodes[i].className =='2'){
						a_objForm.childNodes[i].style.display='block'
				}
				//class 2 elements are 'hidden' when the form is in readonly mode
				if (a_objForm.childNodes[i].className =='1'){
						a_objForm.childNodes[i].style.display='none'
				}
			}
			}
			else{
				//not a form
			}
			a_objEvent.returnValue = true
			return true
		}
		else{
			//alert("the form is to be set to editable, set the document level varialble current form")
			//the form is to be set to editable, set the document level varialble current form
			//alert("d_objCurrentForm =" + a_objForm.id )
			d_objCurrentForm = a_objForm
			//loop through all the 'input' form elements, setting visibility & readonly status
			//for (i = 0; i <= (a_objForm.elements.length - 1); i++) 
			for (i = 0; i <= (a_objForm.length - 1); i++) 
			{                        
				//alert(document.all(a_objForm.id).elements[i].id)
				enableElement(a_objForm.elements[i],a_bolReadOnly)		  
				if (a_objForm.elements[i].className =='2'){a_objForm.elements[i].style.display='none'}
				if (a_objForm.elements[i].className =='1'){a_objForm.elements[i].style.display='block'}
			}
			//loop through all elements of the form, to see if any other elements should have their
			//visibility set. This allows elements such as <DIV>'s, <FONT>'s etc to be switched on/off
			//for (i = 0; i <= (a_objForm.all.length - 1); i++) 
			try{
				//alert(a_objForm.firstChild)
				for (i = 0; i <= (a_objForm.childNodes.length - 1); i++) 
				{                        
					//alert(a_objForm.all[i].id)
					//class 2 elements are 'hidden' when the form is in edit mode
					if (a_objForm.childNodes[i].className =='2'){
							a_objForm.childNodes[i].style.display='none'
					}
					//class 1 elements are 'visible' when the form is in edit mode
					if (a_objForm.childNodes[i].className =='1'){
							a_objForm.childNodes[i].style.display='block'
					}
				}
			}
			catch(err){
			
			}
			a_objEvent.returnValue = true
			return true
		}
	}
	
}

function enableForm2(a_objEvent,a_objForm, a_bolReadOnly){
	var i
	//grab thw object, which has triggered the event which calls this function
	alert (a_objForm.id)
	//var e=a_objWindow.event
	alert(a_objEvent)
	var l_objCurrent = whichElement(a_objEvent)
	//alert(d_objCurrentForm.id + " edited=" + d_bolFormChanged)
	alert("l_objCurrent.id = " + l_objCurrent.id)
	//alert("l_objCurrent.form = " + l_objCurrent.form)
	//alert("a_objForm.id = " + a_objForm.id)
	if (l_objCurrent.form==null){
		//the object which triggered this function, isn't on a form
		//so nothing needs to be set to read only
		//to prevent a atempt to disable a 'non-form',
		//set the current form object to be the supplied form object
		d_objCurrentForm = a_objForm
	}
	//test if the supplied form is the same as the current form
	if (d_objCurrentForm.id != a_objForm.id){
		//alert("the form of the event-firing object is different to that of the one being edited")
		//the form of the event-firing object is different to that of the one being edited
		//test if the data has changed
		if(d_bolFormChanged){
			//data on the form being edited has changed, inform the user that they need to save the record
			alert("You need to either save or discard the changes you have made to the previous record")
			a_objEvent.returnValue = false
			return false
		}
		else{
			//alert("the data has not changed")
			//the data has not changed
			//set the form to readonly
			enableForm(null,d_objCurrentForm, true)
			
			//set the edited form to be the form of the trigger element
			d_objCurrentForm = a_objForm
			
			//set the newly selected form to be editable
			enableForm(null,d_objCurrentForm, false)
			a_objEvent.returnValue = true
			return true
		}
	}
	else{
		//alert("the triggering element belongs to the form currently being edited")
		//the triggering element belongs to the form currently being edited
		if (a_bolReadOnly){
			//alert("the form is to be set to readonly")
			//the form is to be set to readonly
			//set the edited flag to false, as the form will be reset and modified values lost
			d_bolFormChanged = false
			//loop through all the 'input' form elements, setting visibility & readonly status
			//alert(a_objForm.id)
			//alert(a_objForm.id + ".elements.length = " + a_objForm.elements.length)
			
			//need to make sure the supplied object is a form
			for (i = 0; i <= (a_objForm.elements.length - 1); i++) 
			{                        
				//alert(document.all(a_objForm.id).elements[i].id)
				enableElement(null,a_objForm.elements[i],a_bolReadOnly)		  
				//class 2 elements are 'visible' when the form is in readonly mode
				if (a_objForm.elements[i].className =='2'){
						a_objForm.elements[i].style.display='block'
						a_objForm.elements[i].disabled=false
				}
				//class 2 elements are 'hidden' when the form is in readonly mode
				if (a_objForm.elements[i].className =='1'){
						a_objForm.elements[i].style.display='none'
				}
			}
			//loop through all elements of the form, to see if any other elements should have their
			//visibility set. This allows elements such as <DIV>'s, <FONT>'s etc to be switched on/off
			for (i = 0; i <= (a_objForm.childNodes.length - 1); i++) 
			{                        
				//alert(a_objForm.all[i].id)
				//class 2 elements are 'visible' when the form is in readonly mode
				if (a_objForm.childNodes[i].className =='2'){
						a_objForm.childNodes[i].style.display='block'
				}
				//class 2 elements are 'hidden' when the form is in readonly mode
				if (a_objForm.childNodes[i].className =='1'){
						a_objForm.childNodes[i].style.display='none'
				}
			}
			a_objEvent.returnValue = true
			return true
		}
		else{
			//alert("the form is to be set to editable, set the document level varialble current form")
			//the form is to be set to editable, set the document level varialble current form
			//alert("d_objCurrentForm =" + a_objForm.id )
			d_objCurrentForm = a_objForm
			//loop through all the 'input' form elements, setting visibility & readonly status
			//for (i = 0; i <= (a_objForm.elements.length - 1); i++) 
			for (i = 0; i <= (a_objForm.length - 1); i++) 
			{                        
				//alert(document.all(a_objForm.id).elements[i].id)
				enableElement(null,a_objForm.elements[i],a_bolReadOnly)		  
				if (a_objForm.elements[i].className =='2'){a_objForm.elements[i].style.display='none'}
				if (a_objForm.elements[i].className =='1'){a_objForm.elements[i].style.display='block'}
			}
			//loop through all elements of the form, to see if any other elements should have their
			//visibility set. This allows elements such as <DIV>'s, <FONT>'s etc to be switched on/off
			//for (i = 0; i <= (a_objForm.all.length - 1); i++) 
			for (i = 0; i <= (a_objForm.childNodes.length - 1); i++) 
			{                        
				//alert(a_objForm.all[i].id)
				//class 2 elements are 'hidden' when the form is in edit mode
				if (a_objForm.childNodes[i].className =='2'){
						a_objForm.childNodes[i].style.display='none'
				}
				//class 1 elements are 'visible' when the form is in edit mode
				if (a_objForm.childNodes[i].className =='1'){
						a_objForm.childNodes[i].style.display='block'
				}
			}
			a_objEvent.returnValue = true
			return true
		}
	}
	
}

function enableElement (a_objElement,a_bolLocked){
	//this function does  work correctly
	//it should make elements which can be made readonly, readonly
	//and disable those which cannot be made readonly
	
	
	//alert(a_objElement.tagName)
	//alert(a_objElement.type)

	switch (a_objElement.tagName){
	//switch (a_objElement.nodeName){
		case 'INPUT':
			//alert(a_objElement.type)
			switch (a_objElement.type){
			case 'text':
				//alert('tagName=INPUT.type=text: ' + a_objElement.tagName + ', ' + a_objElement.type + ', disabled=' + a_bolLocked)
				a_objElement.readOnly = a_bolLocked
			break
			case 'password':
				a_objElement.readOnly = a_bolLocked
			break
			case 'file':
				a_objElement.readOnly = a_bolLocked
				break
			//case 'button':
				//buttons are used to perform non submit or reset actions
				//hence these should be enabled/disabled explicitly as required
			//break
			case 'reset':
				//a reset button, when disabled does not reset the form
				//the 'onclick' event is handled before the reset is sent
				//hence when it is sent, and the control has been disabled the form is NOT reset
				//
				//no action is taken
			break
			default:
				//alert('tagName=INPUT.type=default: ' + a_objElement.tagName + ', ' + a_objElement.type + ', disabled=' + a_bolLocked)
				a_objElement.disabled = a_bolLocked
			break
			}
		break
		case 'TEXTAREA':
			a_objElement.readOnly = a_bolLocked
		break
		default:
			//alert('tagName=defaultt: ' + a_objElement.tagName + ', ' + a_objElement.type + ', disabled=' + a_bolLocked)
			a_objElement.disabled = a_bolLocked
		break
	}

}




function toggleclassNameDisplay(a_objElement, a_strclassName){
	//this function swaps the visability of all the elements in the 'all' collection of the supplied element
	//whose className property matches the supplied a_strclassName value
	
	//initilise and loop through the 'all' collection for the provided element
	for(var i=0; i<a_objElement.all.length; i++) {
		//test if the className property matches the supplied argument
		if(a_objElement.all[i].className == a_strclassName){
			//alert(a_objElement.all[i].className);
			
			
			//the className matches toggle the elelments visability
			if (a_objElement.all[i].style.display == 'block'){
				a_objElement.all[i].style.display = 'none';
			}
			else{
				a_objElement.all[i].style.display = 'block';
			}
		}
	}//close the loop

	
}


function toggleclassNameDisplay2(a_objElement, a_strclassName){
	//this function swaps the visability of all the elements in the 'all' collection of the supplied element
	//whose className property matches the supplied a_strclassName value
	
	//initilise and loop through the 'all' collection for the provided element
	//for(var i=0; i<a_objElement.all.length; i++) {
	for(var i=0; i<a_objElement.childNodes.length; i++) {
		if(!confirm('a_objElement.childNodes[i].className ' + a_objElement.all[i].className)){return}//alert(a_objElement.all[i].tagName);
		if (typeof(a_objElement.childNodes[i].childNodes)=='object'){toggleclassNameDisplay(a_objElement.childNodes[i], a_strclassName)}
		//test if the className property matches the supplied argument
		if(a_objElement.childNodes[i].className == a_strclassName){
			//alert(a_objElement.all[i].className);
			
			
			//the className matches toggle the elelments visability
			if (a_objElement.childNodes[i].style.display == 'block'){
				a_objElement.childNodes[i].style.display = 'none';
			}
			else{
				a_objElement.childNodes[i].style.display = 'block';
			}
		}
	}//close the loop

	
}


function toggleElementDisplay1(a_objElement){
	//this function swaps the visability of the supplied element
	//alert(a_objElement.id)
	if (a_objElement){
		if (a_objElement.style.display == 'inline'){
			a_objElement.style.display = 'none';
		}
		else{
			a_objElement.style.display = 'inline';
		}
	}
	else{
		//alert("does not exist")
	}
}

function toggleElementDisplay(a_objElement){
	//this function swaps the visability of the supplied element
	//alert(a_objElement.id)
	if (a_objElement){
		if (a_objElement.style.display == 'block'){
			a_objElement.style.display = 'none';
		}
		else{
			a_objElement.style.display = 'block';
		}
	}
	else{
		//alert("does not exist")
	}
}


function setElementDisplay(a_objElement, a_bolShow){
	//this function sets the visability of the supplied element
	if (a_objElement){
		if (a_bolShow){
			a_objElement.style.display = 'block';
		}
		else{
			a_objElement.style.display = 'none';
		}
	}
	else{
		//alert("does not exist")
	}
}



function setDisplayByFilter2(a_objElement, a_strProperty, a_strDelimiter, a_intIndex,a_strValue, a_bolDisplay){
	//this function swaps the visability of all the elements in the 'all' collection of the supplied element
	//the supplied property(a_strProperty) is 'split' using the supplied a_strDelimiter
	//the n'th index (a_intIndex), of the 'split' property, is then tested against the a_strValue.
	//If it matches, then its 'style.display' value is set
	//a_bolDisplay==null, then the displaye is toggeld on/off
	//a_bolDisplay==true, then the display is set on
	//a_bolDisplay==false, then the display is set off

	//initilise and loop through the 'all' collection for the provided element
	for(var i=0; i<a_objElement.all.length; i++) {
		//alert(a_objElement.all[i].tagName);
		
		//
		var l_strPropValue= eval('a_objElement.all[i].'+ a_strProperty)
		//if(!(window.confirm('l_strPropValue: ' + l_strPropValue))){return}
		 
		//test the property value
		if(l_strPropValue!=''){
			var l_strFilter
			//if a_strDelimiter is null or an empty string
			if(a_strDelimiter==null ||a_strDelimiter=='' ){
				l_strFilter	= l_strPropValue
			}
			else{
				//try to split the property value using the supplied delimiter
				var l_strTemp = l_strPropValue.split(a_strDelimiter)
				l_strFilter = l_strTemp[a_intIndex]
				//if(!(window.confirm('l_strFilter (postSplit): ' + l_strFilter))){return}
			}
			
			
			if(typeof(l_strFilter)=='undefined'){
				//if(!(confirm('The ' + a_strProperty + '(==' + l_strPropValue + ') for the curent element[' + i + '] will not split'))){return}
			}
			else{
				//alert('The ' + a_strProperty + ' with a value of ' + l_strPropValue + ' will be tested against:' +  a_strValue)
			}
			
			//test if the property (part of property) matches the supplied a_strValue argument
			if(l_strFilter == a_strValue){
				//they match
				//test to see if the display is to be toggled
				switch(a_bolDisplay){
				case null:
					//alert('Toggle the display of the element with a ' + a_strProperty + ' value of ' + l_strPropValue)
					//toggle the elelments visability
					if (a_objElement.all[i].style.display == 'block'){
						a_objElement.all[i].style.display = 'none';
					}
					else{
						a_objElement.all[i].style.display = 'block';
					}
					break
				case true:
					//alert('Show the element with a ' + a_strProperty + ' value of ' + l_strPropValue)
					a_objElement.all[i].style.display = 'block';
					break
				case false:
					//alert('Hide the element with a ' + a_strProperty + ' value of ' + l_strPropValue)
					a_objElement.all[i].style.display = 'none';
					break
				}
				
				

			}
			
		}//close test the property value
	}//close the loop

	
}

function checkSubmitButton(a_objForm){
	for (i = 0; i <= (a_objForm.elements.length - 1); i++){
		alert(a_objForm.elements[i].value)
	}
	return false
}

function setDefaultDate(a_objElement, a_strClassName, a_strDefaultValue){
	if ((a_objElement.value != '') || (a_objElement.value !=' ')){
		if (a_strDefaultValue == 'today'){
			var l_dtmToday = new Date()
			a_objElement.value = l_dtmToday.getDate() + '-' + (l_dtmToday.getMonth() + 1) + '-' + l_dtmToday.getFullYear()
		}
		else{
			a_objElement.value = a_strDefaultValue
		}
	}
	a_objElement.className = a_strClassName
}


function getModalValue(a_objTargetElement, a_strPrompt, a_strValueType){
	//branch code depending on the required value type
	switch (a_strValueType){
	case ('number'||'NUMBER'):
		var l_varReturnValue = window.showModalDialog('system/getNumber.htm',a_strPrompt,'dialogHeight:200px;dialogWidth:300px');
		break;
	}
	if(l_varReturnValue){
		//alert("getModalValue: value to be returned: " + l_varReturnValue)
		a_objTargetElement.value = l_varReturnValue;
		return true;
	}
	else{
		return false;
	}
}


function closeDataForm(){
	//function to close a page, opened by the openDataForm function above
	//
	//it checks the opener window for the existance of the variable DataForm_element,
	//which holds the elemet object for the reference number of the dataform eg the rdc number
	//
	//if the variable exists and differs to the current reference number on the data form, the user is given the option
	//to update the element on the opener window
	//alert("Hello")
	//check for the existance of a opener window
	//if(!window.opener.closed){
	//if((window.opener)&&(!window.opener.closed)){
	if(typeof(window.opener)=='object'){
		//alert("opened by page:-" + window.opener.location);
		//alert("Hello, again")
		
		var l_objOpener = window.self.opener
		//alert(l_objOpener.name)
		
		//check for the existance of the DataForm_element variable in the opener window
		if(window.opener.DataForm_element){
			//alert(window.opener.location + "\n\r" + "opener element:-" + window.opener.DataForm_element.id);
			//alert(window.opener.DataForm_element.id)
			
			if(window.opener.DataForm_field){
				//get the current value of the reference number of this form
				//by evaluating a string with the id of the opener.DataForm_element encapsulated within a document.all statment
				var l_lngCurrentReference = eval("document.all('" + window.opener.DataForm_field +"').value")
			}
			else{
				//get the current value of the reference number of this form
				//by evaluating a string with the id of the opener.DataForm_element encapsulated within a document.all statment
				var l_lngCurrentReference = eval("document.all('" + window.opener.DataForm_element.id +"').value")
			}
			//alert("1  l_lngCurrentReference=" + l_lngCurrentReference)
			
			//check the value in the window.opener.DataForm_element against the reference number on the current form
			if(!isNaN(l_lngCurrentReference)&&(l_lngCurrentReference!=window.opener.DataForm_element.value)){
				//alert("different value")
				
				//check if the opener.DataForm_element has a value
				if(window.opener.DataForm_element.value==""){
				
					//update the opener document
					window.opener.DataForm_element.value = l_lngCurrentReference
					window.opener.d_bolFormChanged = true
					window.opener.DataForm_element.onchange()
				}
				//the DataForm_element contains a value
				else{
					
						//check if the opener.DataForm_element is not disabled and not readonly
						if(!window.opener.DataForm_element.disabled && !window.opener.DataForm_element.readOnly){
							
							//create a prompt for the confirmation command
							var l_strPrompt = "The " + window.opener.DataForm_element.id.toUpperCase() + " of this page, "
							l_strPrompt += "differs to that on the parent Page.\n\r\n\r"
							l_strPrompt += "Do you wish to update  the ORIGINAL " + window.opener.DataForm_element.id.toUpperCase() 
							l_strPrompt += " ( " + window.opener.DataForm_element.value + " ), " + "\n\r"
							l_strPrompt += "on the parent page, with the NEW value ( " + l_lngCurrentReference + " ), from this page?"
							
							//ask the user if they wish the opener document to be updated
							if(confirm(l_strPrompt)){
								//alert("update value")
					
								//update the opener document
								window.opener.DataForm_element.value = l_lngCurrentReference
								window.opener.d_bolFormChanged = true
								window.opener.DataForm_element.onchange()
							}
							//user dose not wish to update opener
							else{
								//alert("discard value")
							}
						}
						//the control is locked
						else{
							alert("Unable to update the " + window.opener.DataForm_element.id.toUpperCase()  + ", on the parent page, as the control is locked")
						}
					}
			}
			//the values match or are non numeric
			else{
				//alert("no change")
			}
		}
		//a window.opener.DataForm element does not exist
		else{
			//alert("No DataForm_element variable found")
		}
	
	}
	//an opener window does not exist
	else{
		//alert("no opener window");
	}
	close();
}




function openDataForm(a_objElement,a_strField,a_strURL,a_lngWidth,a_lngHeight,a_strDefaults){
	
	//the a_strDefaults argument is used to pass request values to the form
	//its syntax should be:- 
	//  destinationField1=sourceValueField1&destinationField2=sourceValueField2&destinationField3=UserInputPrompt??defaultText
	//where destinationField is the name of the control on the new page and
	//sourceValueField is the name of the control on the current page from which to extract the value
	//usertInputPrompt is text used to prompt the user for input
	//defaultText is the default text displayed in the user input box.
	//
	//This function requires the 'creatValuePairs' funtion to be available
	
	//create window variable to hold supplied variable
	window.DataForm_element = a_objElement
	
	//create window variable to hold the name of the 'linked field' on the dataform
	window.DataForm_field = a_strField
	
	//construct the features string for the open command
	var l_strWindowFeatures = "width=" + a_lngWidth +", height=" + a_lngHeight + ", toolbar=no, menubar=no, scrollbars=yes , resizable=yes"
	
	//check if the a_strDefaults argument contains a value
	if(a_strDefaults!=""){
		//the argument contains something
		//alert("the raw defaults string= " + a_strDefaults)
		var l_strQuery =""
		//test to see if the default string contains ampersand
		if(a_strDefaults.search("&")==-1){
			//alert("no ampersand found")
				l_strQuery += createValuePair(a_strDefaults)
		}
		else{
			//try to split it into an array of name and value pairs using '&' as the delimiter
			var a_strValuePair = a_strDefaults.split("&")
			//loop through the array of default strings
			for (var l_intCounter=0;l_intCounter<a_strValuePair.length;l_intCounter++){
				//alert(l_intCounter + "   " + a_strValuePair[l_intCounter] )
				//pass each element to the create value pairs function
				var l_strSubQuery = createValuePair(a_strValuePair[l_intCounter])
				if((l_strSubQuery!="")&&(l_intCounter!=0)){
					//the element returned a valid value pair, and the counter is not equal to zero
					//append an ampersand to the query string
					l_strQuery +=  "&"
				}
				//append the returned value pair to the existing query string
				l_strQuery +=  l_strSubQuery
			}//close the loop
			//alert("The query string = " + l_strQuery)
		}
	}
	//the a_strDefaults argument is empty
	else{
	}
	//test if the composed query string is empty
	if(l_strQuery!=""){
		//if not empty insert an ampersand in front
		l_strQuery = "&" + l_strQuery
	}
	//test if the supplied element has a value and is numeric
	if((a_objElement.value!="")&&(!isNaN(a_objElement.value))){
		var l_objDataFormWindow = window.open(a_strURL + "?" + a_strField + "=" + a_objElement.value, a_objElement.id + a_objElement.value, l_strWindowFeatures)
	}
	else{
		if(isNaN(a_objElement.value)){
			alert("The reference number is invalid")
		}
		else{
			var l_objDataFormWindow = window.open(a_strURL + "?cmdaction=new" + l_strQuery,a_objElement.id + "_new", l_strWindowFeatures)
		}
	}
	if (l_objDataFormWindow){
		l_objDataFormWindow.focus()
	}
}

function createValuePair(a_strText){
	//this function is called from within the openDataForm funtion, it parses the supplied
	//string from the form "targetfield=currentdocumentsourceelement"
	//test if the supplied string  contains an equals character
	if(a_strText.search("=")!=-1){
		//the string contains an equals
		//split the string on that charater
		var l_strTextArray = a_strText.split("=")
		if(l_strTextArray.length==2){
			//the array is two elements long

			//alert( l_strTextArray[1])
			//test to see if the value is to be prompted for
			//create a regular expression used in the text search, match "??"
			var l_objSearchExpression = new RegExp("[?]{2}")
			//alert( l_strTextArray[1].search(l_objSearchExpression))
			if( l_strTextArray[1].search(l_objSearchExpression)!=-1){
				//alert("ask for input")
				//split the string using the search expression
				var l_strPromptArray =  l_strTextArray[1].split(l_objSearchExpression)
				//prompt the user for a value
				//return  l_strTextArray[0] + "=" + window.prompt( l_strTextArray[1],"Enter")
				//if the array is two elements long
				if(l_strPromptArray.length>=2){
					//it is at least 2 elements long, use the first element as the prompt and the second as the default value
					return  l_strTextArray[0] + "=" + window.prompt( l_strPromptArray[0], l_strPromptArray[1])
				}
				else{
					//it is only one element long,use it for both the prompt and default
					return  l_strTextArray[0] + "=" + window.prompt( l_strPromptArray[0], l_strPromptArray[0])
				}
			}
			else{
				//the value is to be extracted from an element on the form
				//attempt to assign the element object to a local varialble
				var l_objSourceElement = document.all( l_strTextArray[1])
				//test if the source element on the current document does not exists
				//ie the local variable equals null
				if (l_objSourceElement==null){
					//the supplied element name does not exist
					//alert("Cannot find document.all('" +  l_strTextArray[1] + "')")
					return ""
				}
				else{
					//the element does exist
					//alert("the following would be returned: " + l_strTextArray[0] + "=" + l_objSourceElement.value)
					return  l_strTextArray[0] + "=" + l_objSourceElement.value
				}
			}
			
			
		}
		else{
			//the array is not two elements long
			//alert("the array is not two elements long")
			return ""
		}
	}
	else{
		//the string does not contain an equals character
		return ""
	}

}




function openMinMaxCalendar(a_objValue,a_minDD_MM_YYYY,a_maxDD_MM_YYYY){
	
	//create an object to hole the dialogArguments
	var l_objParam = new Object();
	//alert('a_objValue.value:' + a_objValue.value)
	l_objParam.defaultDate = a_objValue.value;
	//alert('a_minDD_MM_YYYY:' + a_minDD_MM_YYYY)
	l_objParam.minDate = a_minDD_MM_YYYY;
	l_objParam.maxDate = a_maxDD_MM_YYYY;
	l_objParam.selDate = "abc";
	
	var l_varReturn
	l_varReturn=window.showModalDialog('/ol_booking/system/modal_MinMaxCalendar.htm',l_objParam,'dialogHeight:350px;dialogWidth:300px');
	//window.showModalDialog('/ol_booking/system/modal_MinMaxCalendar.htm?date=' + new Date(),l_objParam,'dialogHeight:350px;dialogWidth:300px');
	//l_varReturn=window.open('/ol_booking/system/modal_MinMaxCalendar.htm?date=' + new Date(),l_objParam,'dialogHeight:350px;dialogWidth:300px');
	
	//alert(l_objParam.selDate)
	if (l_varReturn=="" || typeof(l_varReturn)=="undefined" || l_varReturn==null ){
		//alert('No Return vlaue: ' + typeof(a_objValue))
		return l_objParam.defaultDate
	}
	else{
		return l_varReturn
	}
	


}


function openInfoPop(a_strType,a_lngValue){
	
	//create an object to hold the dialogArguments
	var l_objParam = new Object();
	l_objParam.defaultData =  a_lngValue;
	//alert(a_lngValue)
	
	var l_varReturn = new Object();
	var l_strHREF
	var l_strOptions
	switch(a_strType){
	case 'location_info':
		l_strHREF = '/booking/popup_location.asp?location_id=' + a_lngValue;
		l_strOptions = 'dialogHeight:500px;dialogWidth:600px';
		break;
	case 'accom_info':
		l_strHREF = '/booking/popup_location.asp?resource_id=' + a_lngValue;
		l_strOptions = 'dialogHeight:500px;dialogWidth:600px';
		break;
	case 'rate_info':
		l_strHREF = '/booking/popup_rate.asp?rate_id=' + a_lngValue
		l_strOptions = 'dialogHeight:500px;dialogWidth:450px';
		break;
	case 'rate_edit':
		l_strHREF = '/client/client/client_rateedit.asp?rate_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'rate_types':
		l_strHREF = '/client/client/client_ratetypes.asp?rate_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:900px'
		break
	case 'rate_test':
		l_strHREF = '/client/client/client_ratetest.asp?rate_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'features':
		l_strHREF = '/client/client/client_features.asp?features=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'images':
		l_strHREF = '/client/client/client_images.asp?images=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'news':
		l_strHREF = '/client/client/client_news.asp?news_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'acknowledge':
		l_strHREF = '/client/client/client_acknowledge.asp?id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'send_comm':
		l_strHREF = '/client/client/client_SendComm.asp?ct_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	case 'edit_template':
		l_strHREF = '/client/client/client_Template.asp?CTemplate_id=' + a_lngValue
		l_strOptions = 'dialogHeight:700px;dialogWidth:700px'
		break
	case 'messages':
		l_strHREF = '/client/client/client_message.asp?msg_id=' + a_lngValue
		//l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px'
		break
	}
	//alert(l_strHREF)
	//##//l_varReturn=window.showModalDialog(l_strHREF,l_objParam,l_strOptions);
	
	
	if (window.showModalDialog) {
		l_varReturn=window.showModalDialog(l_strHREF,l_objParam,l_strOptions);
	}
	else {
		//alert(l_strOptions.replace(/dialog/gi,""))
		window.open(l_strHREF,'_name',l_strOptions.replace(/dialog/gi,"") + ',modal=yes');
		//window.open(l_strHREF,'_name','height=255,width=250,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no ,modal=yes');
	}	
	//#//window.open(l_strHREF,null,"height=900,width=700,status=yes,toolbar=yes,menubar=yes,location=no,resizable=yes,scrollbars=yes");
	
	//alert(l_varReturn)
	if (true){
		//if (l_varReturn=="" || typeof(l_varReturn)=="undefined" || l_varReturn==null ){
		if (typeof(l_varReturn)=="undefined" || l_varReturn==null ){
			//alert('No Return vlaue: ' + typeof(a_objValue))
			return l_objParam.defaultData
		}
		else{
			return l_varReturn
		}
	}

}


function openEditPop(a_strType,a_lngValue,a_strTarget){
	
	//create an object to hold the dialogArguments
	var l_objParam = new Object();
	l_objParam.defaultData =  a_lngValue;
	//alert(a_lngValue)
	
	var l_varReturn
	var l_strHREF
	//var l_strTarget = '_247newPop'
	var l_strTarget = '_self'
	var l_strOptions
	switch(a_strType){
	case 'rate_info':
		l_strHREF = '/booking/popup_rate.asp?rate_id=' + a_lngValue
		l_strOptions = 'dialogHeight:350px;dialogWidth:400px'
		break
	case 'rate_edit':
		l_strHREF = '/client/client/client_rateedit.asp?rate_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		break
	case 'rate_test':
		l_strHREF = '/client/client/offers/client_ratetest.asp?rate_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes'
		break
	case 'accom_edit':
		l_strHREF = '/client/client/Client_AccommodationEdit.asp?resource_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		break
	case 'accom_config':
		l_strHREF = '/client/client/Client_AccommodationConfig.asp?resource_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		break
	case 'location_edit':
		l_strHREF = '/client/client/Client_LocationEdit.asp?location_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		l_strTarget = '_self'
		l_strTarget = a_strTarget
		break
	case 'l_popup_edit':
		l_strHREF = '/client/client/Client_popupEdit.asp?location_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		break
	case 'r_popup_edit':
		l_strHREF = '/client/client/Client_popupEdit.asp?resource_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		break
	case 'features':
		l_strHREF = '/client/client/client_features.asp?features=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'calendar':
		l_strHREF = '/client/client/client_bookingCalendar.asp?location_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'booking':
		l_strHREF = '/client/client/client_booking.asp?booking_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'billing':
		l_strHREF = '/client/client/client_billing.asp?client_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'images':
		l_strHREF = '/client/client/client_images.asp?images=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'ak_template':
		l_strHREF = '/client/client/client_Template.asp?text_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'terms_edit':
		l_strHREF = '/client/client/client_termsedit.asp?text_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'client_config':
		l_strHREF = '/client/client/Client_ClientConfig.asp?client_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		l_strTarget = '_self'
		break
	case 'invoice':
		l_strHREF = '/client/client/Client_invoice.asp?booking_id=' + a_lngValue
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		l_strTarget = '_new'
		break
	case 'client_yearview':
		l_strHREF = '/client/client/client_yearview.asp?location_id=' + a_lngValue
		l_strOptions = 'dialogHeight:900px;dialogWidth:700px,resizable=yes,scrollbars=yes'
		break
	case 'la_contact':
		l_strHREF = '/booking/location_contact.asp?location_id=' + a_lngValue + '&accom_id=' + a_strTarget
		l_strOptions = 'height=900px,width=700px,resizable=yes,scrollbars=yes'
		l_strTarget = "_blank"
		break
	case 'booking_calendar':
		l_strHREF = '/booking/YVAvailability.asp?location_id=' + a_lngValue
		l_strOptions = 'Height:900px;Width:900px,resizable=yes,scrollbars=yes,menubar=yes,titlebar=yes,toolbar=yes,status=yes'
		l_strTarget = "_blank"
		break
	}
	//alert(l_strHREF)
	//win.open(href,targetname,feature
	var l_objDataFormWindow = window.open(l_strHREF,l_strTarget, l_strOptions)
	
	//alert(l_varReturn)
	if (l_varReturn=="" || typeof(l_varReturn)=="undefined" || l_varReturn==null ){
		//alert('No Return vlaue: ' + typeof(a_objValue))
		return l_objParam.defaultData
	}
	else{
		return l_varReturn
	}

}


function getDateObj(a_strDD_MM_YYYY){
	//convert a date string into a date object
	//create a date object
	var l_objDate = new Date
	if(a_strDD_MM_YYYY){
		//split the supplied string into an array
		var l_strDate = a_strDD_MM_YYYY.split("/")
		l_objDate.setFullYear(l_strDate[2], l_strDate[1]-1,l_strDate[0])
	}
	return l_objDate
}



function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}


function addCFile(a_strID){
	alert(a_strID)
	var l_objValue = $id(a_strID)
	var l_objDisplay = $id(a_strID + "_display")
	
	var l_strReturn = openInfoPop('images',l_objValue.value);
	
	//clear the existing values
	l_objValue.value =""
	
	//clear the displayed file names
	while(l_objDisplay.options.length!=0){
		l_objDisplay.remove(l_objDisplay.options[0]);
	}
	
	var l_strFile = l_strReturn.split(";")
	//loop through the returned files
	for (var i=0 ; i < l_strFile.length ; i++){

		var l_objOption=document.createElement('option');
		var l_strFileBits = l_strFile[i].split(":")
		
		l_objOption.value=l_strFileBits[0]
		l_objOption.text=l_strFileBits[1]
		l_objOption.title=l_strFileBits[2]
		try
		  {
		  l_objDisplay.add(l_objOption,null); // standards compliant
		  }
		catch(ex)
		  {
		  l_objDisplay.add(l_objOption); // IE only
		  }
		if (l_objValue.value == "") {
			l_objValue.value = l_strFileBits[0]
		}
		else{
			l_objValue.value += "," + l_strFileBits[0]
		}
	
	}
		
}

	function fileListAction(a_strSelect,a_strAction,a_varValue){
	//a_strAction=='move'	;a_varValue = true(up) or false(down)
	//a_strAction=='view'	;a_varValue = un-used
	//a_strAction=='edit'	;a_varValue = edit type ('select' or 'text')
	//a_strAction=='update'	;a_varValue = edit type ('select' or 'text')
	//a_strAction=='add'	;a_varValue = edit type ('select' or 'text')
	//a_strAction=='remove'	;a_varValue = un-used
	//a_strAction=='size'	;a_varValue = value to change size by (1 or -1)
	//a_strAction==''		;a_varValue = un-used
	//a_strAction==''		;a_varValue = un-used
	
	
	//variables refereing to the main select object
	var l_objValue = $id(a_strSelect)	
	var l_objSelect = $id(a_strSelect + "_display")	
	var l_lngOptIndex = l_objSelect.selectedIndex
	
	try{var l_objOption = l_objSelect.options[l_lngOptIndex]}
	catch(err){var l_objOption=null}
	
	
	if(l_lngOptIndex != -1){
		//these actions require an option to be selected
		switch(a_strAction){
		case "move":			
			
			var l_objNewOption = document.createElement('option');
			l_objNewOption.value = l_objOption.value
			l_objNewOption.text = l_objOption.text
			l_objNewOption.className = l_objOption.className
			l_objNewOption.classValue = l_objOption.classValue

			if(a_varValue){
				//going up
				//prevent the inserted option from 'overflowing' to the bottom of the list
				if(l_lngOptIndex==0){
					l_objSelect.add(l_objNewOption,1)
				}
				else{
					l_objSelect.add(l_objNewOption,l_lngOptIndex-1)
				}
			}
			else{
				//going down
				if(l_lngOptIndex > l_objSelect.options.length -2 ){
					//alert("last?")
				l_objSelect.add(l_objNewOption,l_lngOptIndex+1)
				}
				else{
					//alert("not last")
				l_objSelect.add(l_objNewOption,l_lngOptIndex+2)
				}
			}
			l_objSelect.remove(l_objSelect.selectedIndex)
			l_objSelect.options[0].selected = true
			l_objSelect.options[l_objNewOption.index].selected = true	
			break
		case "remove":
			//remove the selected option from the select
			if(l_lngOptIndex != l_objSelect.options.length){
				l_objSelect.remove(l_lngOptIndex)
			}
			break
			
		}
	}
	//these actions don't require an option to be selected
	switch(a_strAction){
	case "size":
		//resize the select box
		var l_lngNewSize = l_objSelect.size + a_varValue
		if(l_lngNewSize >0 && l_lngNewSize<11){
			l_objSelect.size = l_lngNewSize
		}
		break
	case "add":
		//add a new option to the select
		//var l_objValue = $id(a_strID)
		//var l_objDisplay = $id(a_strID + "_display")
	
		var l_strReturn = openInfoPop('images',l_objValue.value);
		//alert(l_strReturn)
		if (l_strReturn != null && l_objValue.value != l_strReturn){
			//clear the existing values
			l_objValue.value =""
	
			//clear the displayed file names
			while(l_objSelect.options.length!=0){
				l_objSelect.remove(l_objSelect.options[0]);
			}
	
			var l_strFile = l_strReturn.split(";")
			//loop through the returned files
			for (var i=0 ; i < l_strFile.length ; i++){

				var l_objOption=document.createElement('option');
				var l_strFileBits = l_strFile[i].split(":")
					
				l_objOption.value=l_strFileBits[0]
				l_objOption.text=l_strFileBits[1]
				l_objOption.title=l_strFileBits[2]
				try{
				  l_objSelect.add(l_objOption,null); // standards compliant
				}
				catch(ex){
				  l_objSelect.add(l_objOption); // IE only
				}
				/*
				if (l_objValue.value == "") {
					l_objValue.value = l_strFileBits[0]
				}
				else{
					l_objValue.value += "," + l_strFileBits[0]
				}
				*/
	
			}
		}
		else{
			alert('No files selected')
		}
		break
	}
	
	//update the hidden value field
	l_objValue.value = ""
	for (var i = 0 ; i < l_objSelect.options.length ; i++){
		
		if (l_objSelect.options[i].value != ""){
			if (l_objValue.value != ""){
				l_objValue.value += "," + l_objSelect.options[i].value
			}
			else{
				l_objValue.value = l_objSelect.options[i].value
			}
		}
	
	}		
}





function cancelBubble(windowEvent) {
    if (windowEvent.bubbles === undefined) {  // Internet Exlorer
        // always cancel bubbling
        windowEvent.cancelBubble = true;
		CancelEvent (windowEvent)
    }
    else {        // Firefox, Opera, Safari
        if (windowEvent.bubbles) {
            windowEvent.stopPropagation ();
			CancelEvent (windowEvent)
        }
        else {

        }
    }

}

       function CancelEvent (event) {
            if (event.cancelable === undefined) {
                event.returnValue = false;
                WriteInfo ("The " + eventName + " event is probably canceled.");
            }
            else {
                    // in Firefox, the cancelable property always returns true,
                    // so the cancelable state of the event cannot be determined
                if (event.cancelable) {
                    event.preventDefault ();
                    WriteInfo ("The " + eventName + " event is canceled.");
                }
                else {
                    WriteInfo ("The " + eventName + " event is not cancelable.");
                }
            }
        }


function noReturn(e){
var keynum;
var keychar;
var numcheck;
//alert("here")
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if(keynum==13){
		// cr not allowed
		//alert("CR not allowed")
		cancelBubble(e)
		return false
	}
	else{
		//return !numcheck.test(keychar);
		return true;
	}

}
