function checkall(FormName,Group){
	var d_form = document.getElementById(FormName).elements;
	for(var formCount=0;formCount<d_form.length;formCount++){
		var elemState = d_form[formCount].disabled;
		d_form[formCount].disabled=false;
		if(d_form[formCount].id==Group){
			d_form[formCount].checked = true;
		}
		d_form[formCount].disabled = elemState;
	}
}
function uncheckall(FormName,Group){
	var d_form = document.getElementById(FormName).elements; 
	for(var formCount=0;formCount<d_form.length;formCount++){
		var elemState = d_form[formCount].disabled;
		d_form[formCount].disabled=false;
		if(d_form[formCount].id==Group){
			d_form[formCount].checked = false;
		}
		d_form[formCount].disabled = elemState;
	}
}
function changeRightsValue(FormName,ID, List,State){
	var d_form = document.getElementById(FormName).elements,rList=document.getElementById(List).value;
		d_form[ID].value = (State) ? rList : ""
}
function CheckBox(Form, Group, Indexed){
	CheckBoxGroup = Group
	CheckBoxValid = false;
	CheckBoxGroup_OtherAnswerValid = false;
	ThisForm = Form;
	CheckGroupName = CheckBoxGroup.replace("req__","");
	CheckGroupCount = 1;
	
	while(ThisForm[CheckGroupName+"_"+CheckGroupCount]){
		if(ThisForm[CheckGroupName+"_"+CheckGroupCount].checked){
		    // Get value; otherwise check if other is present.
			if(ThisForm[CheckGroupName+"_"+CheckGroupCount].value != ""){
				if(UrlParameters == ""){ UrlParameters = (ThisForm[CheckGroupName+"_"+CheckGroupCount].name) + "=" + escape(ThisForm[CheckGroupName+"_"+CheckGroupCount].value); }
				else{ UrlParameters = UrlParameters + "&" + (ThisForm[CheckGroupName+"_"+CheckGroupCount].name) + "=" + escape(ThisForm[CheckGroupName+"_"+CheckGroupCount].value); }
			}
			else{
				// search for check box value
				CheckBoxGroup_OtherAnswer = (ThisForm[CheckGroupName+"_"+CheckGroupCount].name);
				CheckBoxGroup_OtherAnswerCount = 1;
				CheckBoxGroup_OtherAnswerValid = false;
				if(ThisForm[(CheckBoxGroup_OtherAnswer+"_DO_NOT_INCLUDE")]){
					if(ThisForm[(CheckBoxGroup_OtherAnswer+"_DO_NOT_INCLUDE")].value!=""){
						if(UrlParameters == ""){
							UrlParameters = (CheckBoxGroup_OtherAnswer) + "=" + escape(ThisForm[(CheckBoxGroup_OtherAnswer+"_DO_NOT_INCLUDE")].value);
						}
						else{
							UrlParameters = UrlParameters + "&" + (CheckBoxGroup_OtherAnswer) + "=" + escape(ThisForm[(CheckBoxGroup_OtherAnswer+"_DO_NOT_INCLUDE")].value);
						}
						CheckBoxGroup_OtherAnswerValid = true;
					}
				}
				if(!CheckBoxGroup_OtherAnswerValid){
					alert(Alerts.CHECKBOXOTHER + CheckBoxGroup.replace("req__",""));
					d_form[(CheckBoxGroup_OtherAnswer+"_DO_NOT_INCLUDE")].focus();
					UrlParameters = "";
					return false;
				}
			}
			CheckBoxValid = true;
		}
		CheckGroupCount++;
	}
	if(!CheckBoxValid){
		alert(Alerts.CHECKBOX + CheckBoxGroup.replace("req__",""));
		UrlParameters = "";
		return false;
	}
	Indexed+=2;
	// move back to current id
	return Indexed--;
}
function RadioBtn(Form, Group, Indexed){
	var RadioGroup = Group
	var IsRadioValid = false;
	var ThisForm = Form;
	var RadioCount = 0

	for(RadioCount=0;RadioCount<ThisForm[RadioGroup].length;RadioCount++){
		if(ThisForm[RadioGroup][RadioCount].checked){
			if(UrlParameters == ""){
				UrlParameters = ThisForm[RadioGroup][RadioCount].name + "=" + escape(ThisForm[RadioGroup][RadioCount].value);
			}
			else{
				UrlParameters += "&" + ThisForm[RadioGroup][RadioCount].name + "=" + escape(ThisForm[RadioGroup][RadioCount].value);
			}
			IsRadioValid=true;
		}
	}
	if(!IsRadioValid){
		alert(Alerts.RADIO + RadioGroup.replace("req__", "").replace(/[_]/g," ") + "\"");
		UrlParameters = "";
		return false;
	}
	// move back to current id
	return Indexed;
}
function CheckForm(FormName, Action){
	UrlParameters = "";
	var d_form = document.getElementById(FormName).elements;
	for(var formCount=0;formCount<d_form.length;formCount++){
		// Only validate if required
		if(d_form[formCount].type!="hidden"){
			// check if element is required
			if( (d_form[formCount].id.indexOf("req__") != -1 || d_form[formCount].name.indexOf("req__") != -1) ){
				// check if element is radio or checkbox
				if(d_form[formCount].type.indexOf("radio") != -1 || d_form[formCount].type.indexOf("checkbox") != -1){
					// search for a checked field
					if(d_form[formCount].type.indexOf("radio") !== -1){
						formCount=RadioBtn(d_form,d_form[formCount].name,formCount);
						if(!formCount) return false;
					}
					else if(d_form[formCount].type.indexOf("checkbox") !== -1){
						formCount=CheckBox(d_form,d_form[formCount].id,formCount);
						if(!formCount) return false;
					}
				}
				else{
					if(d_form[formCount].value==""){
						alert(Alerts.MISSINGDATA + d_form[formCount].id.replace("req__","").replace(/[_]/g," ") + "\"");
						UrlParameters = "";
						return false;
					}
					else{
						if(UrlParameters == ""){
							UrlParameters = d_form[formCount].name.replace("req__","") + "=" + escape(d_form[formCount].value);
						}
						else{
							UrlParameters += "&" + d_form[formCount].name.replace("req__","") + "=" + escape(d_form[formCount].value);
						}
					}
				}
			}
			else if ( d_form[formCount].id.indexOf("DO_NOT_INCLUDE") == -1){
				// store all inlucded elements
				// check if element is radio or checkbox
				if( d_form[formCount].type.indexOf("radio") != -1 || d_form[formCount].type.indexOf("checkbox") != -1 ){
					if(d_form[formCount].checked){
						if(UrlParameters == ""){ UrlParameters = d_form[formCount].name + "=" + escape(d_form[formCount].value); }
						else{ UrlParameters += "&" + d_form[formCount].name+ "=" + escape(d_form[formCount].value); }
					}
				}
				else{ UrlParameters += (UrlParameters == "") ? d_form[formCount].name + "=" + escape(d_form[formCount].value) : "&" + d_form[formCount].id + "=" + escape(d_form[formCount].value); }
			}
		}
		else{
			// store all hidden elements
			UrlParameters += (UrlParameters == "") ? d_form[formCount].name + "=" + escape(d_form[formCount].value) : "&" + d_form[formCount].id + "=" + escape(d_form[formCount].value);
		}		
	}
	if(CheckForm.arguments[2]){
		if(CheckForm.arguments[2] == 'Prompt'){
			if(confirm(Alerts.CONFIRM)){
				document.getElementById(FormName).submit();
				return false;
			}
			else{ UrlParameters = "";	}
		}
		else if(CheckForm.arguments[2] == 'Ajax'){
			if(confirm(Alerts.CONFIRM)){
				if(document.getElementById("Load_Message"))
					AjaxMessageSection = "Loading_Message";
				else
					AjaxMessageSection = "LoadingMessage";

				AjaxSection = "InnerBody";
				if(CheckForm.arguments[3] && CheckForm.arguments[4]){
					AjaxMessageSection = CheckForm.arguments[3];
					AjaxSection = CheckForm.arguments[4];
				}
				// Only if it exists...
				nodisplay('FormBody');
				ExecuteAjax = new AjaxEvent(AjaxMessageSection, AjaxSection, Action);
				return true;
			}
			else{ UrlParameters = "";	}		
		}
		else{ return true; }
	}
	else{ location.href=Action+"?t="+Math.random()+"&"+UrlParameters; }
    	
	return false;
}