<!-- //
// © 2003-2009 FDF Infonet

var Submitted = false;		//Global declaration for FlagSubmitted function

function IBSSetStep(Step){
    var li;

    if (Step == "0" || Step == ""){
        li = document.getElementById("step1");
        if (!(li == undefined)){
            li.className = "error";
        }
        li = document.getElementById("step2");
        if (!(li == undefined)){
            li.className = "error";
        }
        li = document.getElementById("step3");
        if (!(li == undefined)){
            li.className = "error";
        }
    } else {
        li = document.getElementById("step" + Step);
        if (!(li == undefined)){
            li.className = "active";
        }
    }
    return true;
}
function NoEdit(){
	alert("This entry cannot be updated");
}
function FlagSubmitted(){
	//Make sure the form can't be submitted more than once
	//Implement by "onsubmit='return FlagSubmitted()'"
	//or equivalent
	var Status;
	
	if (Submitted){
		alert("An action is already in progress, please wait");
		Status = false;
	} else {
		Status = true;
	}
	Submitted = true;
	return Status;
}
function CheckTextLength(TextField){
	//Check length restriction on a textarea
	//Expect to be called as the 'onkeypress' event handler
	//with attribute 'maxlength' on the textarea
	var Status;
	var MaxLength;
	
	Status = true;
	if (TextField.maxlength != undefined){
		MaxLength = parseInt(TextField.maxlength);
		if (TextField.value.length >= MaxLength){
			//At max. length already - don't allow the new character
			alert("String too long - max of " + MaxLength + " characters permitted");
			//TextField.value = TextField.value.substring(0, MaxLength) + "<-" + TextField.value.substring(MaxLength);
			Status = false;
		}
	}
	return Status;
}
function ToggleList(chkBox, lstElement){
	//Show or Hide the list depending on the check box setting
	if (chkBox.checked){
		lstElement.style.display="";
	} else {
		lstElement.style.display="none";
	}
}
function ShowSpan(SpanName, ShowIt){
	var ShowElements = document.getElementsByTagName("span");
	var Setting;

	if (ShowIt.toUpperCase() == "Y") {Setting = ""} else {Setting = "none"}
	if (ShowElements != undefined){
		for (var i=0; i< ShowElements.length; i++){
		    if (ShowElements[i].name != null){
			    if (ShowElements[i].name == SpanName){
				    ShowElements[i].style.display = Setting;
			    }
			}
		}
	}
}
function ShowSpanByClass(SpanClass, ShowIt){
// DPA 15/06/2010 Added function for generic support (name attribute on a span tag isn't always supported)
	var ShowElements = document.getElementsByTagName("span");
	var Setting;

	if (ShowIt.toUpperCase() == "Y") {Setting = ""} else {Setting = "none"}
	if (ShowElements != undefined){
		for (var i=0; i< ShowElements.length; i++){
			    if (ShowElements[i].className == SpanClass){
				    ShowElements[i].style.display = Setting;
			    }
		}
	}
}
window.onbeforeprint = function(){
	//Printing support: hide non-printing elements, show printing element
	var HideElements = document.getElementsByTagName("div");
	
	if (HideElements != null){
		for (var i=0; i < HideElements.length; i++){
			if (HideElements[i].style.print == "show"){
				HideElements[i].style.display = "";
				HideElements[i].ExpandedForPrinting = true;
			} else {
				HideElements[i].ExpandedForPrinting = false;
			}
			if (HideElements[i].style.print == "none"){
				HideElements[i].style.display = "none";
				HideElements[i].HiddenForPrinting = true;
			} else {
				HideElements[i].HiddenForPrinting = false;
			}
		}
	}
}
window.onafterprint = function(){
	//Printing support: reinstate elements
	var HideElements = document.getElementsByTagName("div");
	
	if (HideElements != null){
		for (var i=0; i < HideElements.length; i++){
			if (HideElements[i].ExpandedForPrinting){
				HideElements[i].style.display = "none";
			}
		}
		for (var i=0; i < HideElements.length; i++){
			if (HideElements[i].HiddenForPrinting){
				HideElements[i].style.display = "";
			}
		}
	}
}
function SetInputValue(InputName, InputValue){
	//Set checked input value from specified value
	var Fields;
	var j;
//alert("Setting " + InputValue + " for " + InputName);
	if (InputName != undefined && InputValue != undefined){
		Fields = document.getElementsByName(InputName);
		if (Fields != undefined){
			for (j = 0; j < Fields.length; j++){
				Fields[j].value = InputValue;
			}
		}
	}
	return true;
}
function GetInputValue(InputName){
	//Return Input field value
	var InputValue = "";
	var Fields;
	var j;
	
	if (InputName != ""){
		Fields = document.getElementsByName(InputName);
		if (Fields != undefined){
			for (j = 0; j < Fields.length; j++){
				InputValue = Fields[j].value;
				break;
			}
		}
	}
	return InputValue;
}
function SetSelectedOption(SelectField, OptionValue){
	//Set selected option in a select list to the option value specified
	var j;

//alert(SelectField.name + ": " + SelectField.type);
	if (SelectField != undefined && OptionValue != undefined){
		if (SelectField.type == "select-one"){
			for (j = 0; j < SelectField.options.length; j++){
				if (SelectField.options[j].value == OptionValue){
//	alert("Setting " + SelectField.name + " to " + OptionValue);
					SelectField.options[j].selected = true;
					SelectField.selectedIndex = j;
					break;
				} else {
					if (SelectField.options[j].value == "" && SelectField.options[j].innerText == OptionValue){
//	alert("Setting " + SelectField.name + " to " + OptionValue);
						SelectField.options[j].selected = true;
						SelectField.selectedIndex = j;
						break;
					}
				}
			}
		}
	}
}
function GetSelectedOption(SelectField){
	//Return the selected option in a select list
	var SelectedOption;
	
	SelectedOption = "";
	if (SelectField != undefined){
		if (SelectField.type == "select-one"){
			if (SelectField.options.length > 0){
				if (SelectField.selectedIndex >= 0 && SelectField.selectedIndex < SelectField.options.length){
					SelectedOption = SelectField.options[SelectField.selectedIndex].value;
					if (SelectedOption == ""){
						SelectedOption = SelectField.options[SelectField.selectedIndex].text;
					}
				}
			}
		}
	}
	return SelectedOption;
}
function SetCheckBox(CheckBoxName, CheckBoxValue){
	//Set checked radio button from specified value
	var Fields;
	var j;
//alert(CheckBoxName + " with " + CheckBoxValue);
	if (CheckBoxName != undefined && CheckBoxValue != undefined){
		Fields = document.getElementsByName(CheckBoxName);
		if (Fields != undefined){
			if (Fields.length == 1){
				//Single checkbox; check if input value is "Y", clear otherwise
				if (CheckBoxValue == "Y"){
					Fields[0].checked = true;
				} else {
					Fields[0].checked = false;
				}
			} else {
				//Group of checkboxes; look for our value and flag it alone
				for (j = 0; j < Fields.length; j++){
//alert(Fields[j].value + " vs. " + CheckBoxValue);
					if (Fields[j].value == CheckBoxValue) {
						Fields[j].checked = true;
					} else {
						Fields[j].checked = false;
					}
				}
			}
		}
	}
}
function SetRadioButton(RadioName, RadioValue){
	//Set checked radio button from specified value
	var Fields;
	var j;
	
	if (RadioName != undefined && RadioValue != undefined){
		Fields = document.getElementsByName(RadioName);
		if (Fields != undefined){
			for (j = 0; j < Fields.length; j++){
				if (Fields[j].value == RadioValue) {
					Fields[j].checked = true;
				} else {
					Fields[j].checked = false;
				}
			}
		}
	}
}
function GetRadioButton(RadioName){
	//Return checked radio button value
	var RadioValue = "";
	var Fields;
	var j;
	
	if (RadioName != ""){
		Fields = document.getElementsByName(RadioName);
		if (Fields != undefined){
			for (j = 0; j < Fields.length; j++){
				if (Fields[j].checked){
					RadioValue = Fields[j].value;
					break;
				}
			}
		}
	}
	return RadioValue;
}
function SetCheckBoxes(CheckBoxName, Settings){
	//Scan list of checkboxes named CheckBoxName,
	//set those with an matching entry in Settings to 'checked'
	var cbList = document.all.tags("INPUT");

	if (cbList != undefined){
		for (var i=0; i < cbList.length; i++){
			if (cbList[i].type == "checkbox" && cbList[i].name == CheckBoxName){
				if (Settings.indexOf(cbList[i].value) > -1){
					cbList[i].checked = true;
				} else {
					cbList[i].checked = false;
				}
			}
		}
	}
	return true;
}
function GetCheckBoxes(CheckBoxName){
	//Return comma separated list of values from checked checkboxes
	var cbList = document.getElementsByName(CheckBoxName);
	var OutString = "";
	var Delimiter = "";
	
	if (cbList != undefined){
		for (var i=0; i < cbList.length; i++){
			if (cbList[i].checked){
				OutString = OutString + Delimiter + cbList[i].value;
				Delimiter = ",";
			}
		}
	}
	return OutString;
}
function ShowSaveButton(){
	//Show any save button(s) on the page
	var btnSave = document.all("cmdSave");

	if (btnSave != undefined){
		if (btnSave.length == null){
			btnSave.style.display = "";
		} else {
			for (var i=0; i<btnSave.length; i++){
				btnSave[i].style.display = "";
			}
		}
	}
}
function HideSaveButton(){
	//Hide any save button(s) on the page
	var btnSave = document.all("cmdSave");

	if (btnSave != undefined){
		if (btnSave.length == null){
			btnSave.style.display = "none";
		} else {
			for (var i=0; i<btnSave.length; i++){
				btnSave[i].style.display = "none";
			}
		}
	}
}
function Format_Date(FieldValue){
//Function to format a field as a date value
//Date format is dd/mm/yyyy or dd/mm/yy or dd-mmm-yyyy or dd-mmm-yy
//Returns null if the input value is not a date

	var Status;
	var DateString;
	var SlashPos;
	var Slash2Pos;
	var TheDay   = "D";
	var TheMonth = "M";
	var TheYear  = "Y";
	var TestDate;
	
	Status = true;
	DateString = FieldValue.replace("-", "/");
	DateString = DateString.replace("-", "/");
	SlashPos = DateString.indexOf("/");
	Slash2Pos = DateString.lastIndexOf("/");
	if (SlashPos == -1 || SlashPos == Slash2Pos){
		Status = false;
	} else {
		TheDay   = DateString.substring(0, SlashPos);
		TheMonth = DateString.substring(SlashPos + 1, Slash2Pos);
		TheYear  = DateString.substring(Slash2Pos + 1, DateString.length);
		if (isNaN(TheMonth)){
			switch (TheMonth.toUpperCase()){
			case "JAN":
				TheMonth = 1;
				break;
			case "FEB":
				TheMonth = 2;
				break;
			case "MAR":
				TheMonth = 3;
				break;
			case "APR":
				TheMonth = 4;
				break;
			case "MAY":
				TheMonth = 5;
				break;
			case "JUN":
				TheMonth = 6;
				break;
			case "JUL":
				TheMonth = 7;
				break;
			case "AUG":
				TheMonth = 8;
				break;
			case "SEP":
				TheMonth = 9;
				break;
			case "OCT":
				TheMonth = 10;
				break;
			case "NOV":
				TheMonth = 11;
				break;
			case "DEC":
				TheMonth = 12;
				break;
			}
		}
	}
	if (Status){
		if (isNaN(TheDay) || isNaN(TheMonth) || isNaN(TheYear)) {
			Status = false;
		} else {
			if (parseInt(TheYear) < 75){
				TheYear = parseInt(TheYear) + 2000;
			}
			var TestDate = new Date(Number(TheYear), (Number(TheMonth) - 1), Number(TheDay));
			
			if (TestDate.getDate() != Number(TheDay) || TestDate.getMonth() != (Number(TheMonth) - 1) || ( (TestDate.getFullYear() != Number(TheYear)) && (TestDate.getYear() != Number(TheYear)) )) {
				Status = false;
			} else {
				Status = true;
			}
		}
	}
	if (Status){
		DateString = String(100 + TestDate.getDate()).substring(1, 3) + "/" + String(100 + TestDate.getMonth() + 1).substring(1, 3) + "/" + String(TestDate.getFullYear());
	} else {
		DateString = "";
	}
	return DateString;
}
function StripQueryString(FormId){
    //Strip querystring from form action attribute (.NET workaround)
    var frm = document.getElementById(FormId);
    var action;

    if (frm == undefined){
        alert("No form matching '" + FormId + "'");
    } else {
        action = frm.attributes.action.value;
    //alert(action);
        if (action.indexOf("?") >= 0){
            frm.attributes.action.value = action.substring(0, action.indexOf("?"));
        }
    //alert(frm.action);
    }
}
function StripSpaces(inString){
	//Function to strip off leading and trailing spaces from inString
	var StartPos;
	var EndPos;
	var Pos;
	var TheString = inString.toString();	//Just in case inString isn't!
	
	StartPos = -1;
	for (Pos=0; Pos<TheString.length; Pos++){
		if (TheString.charCodeAt(Pos) != 32){
			//No more leading spaces
			StartPos = Pos;
			break;
		}
	}
	EndPos = 0;
	for (Pos=TheString.length - 1; Pos >= 0; Pos--){
		if (TheString.charCodeAt(Pos) != 32){
			//No more trailing spaces
			EndPos = Pos;
			break;
		}
	}
	if (StartPos == -1){
		TheString = "";
	} else {
		TheString = TheString.substring(StartPos, EndPos + 1);
	}
	return TheString;
}
// -->
