var manu = navigator.appName;
var vers = navigator.appVersion;
var isNS6 = false;
var lastSection = '';
var frmName = '';
var ProcWindow;

	

if (manu.indexOf("Microsoft")>=0 && vers.indexOf("5")>=0)
{
	isNS6 = false;
}
else if (manu.indexOf("Netscape")>=0 && vers.indexOf("5")>=0)
{
	isNS6 = true;
}

function ViewUser(sFormName, sFieldValue, sURL)
{
	if (document.forms[sFormName].elements[sFieldValue].value != '')
	{
		document.location.href = sURL + '&user=' + document.forms[sFormName].elements[sFieldValue].value;
	}
}	

function ToggleSection(sectionID, imgID, openImg, closeImg)
{
	var oSection = document.getElementById(sectionID);
	
	if (imgID != '')
	{
		var imgSection = document.getElementById(imgID);
	}

	if (oSection.style.display == 'block')
	{
		oSection.style.display = 'none';
		if (imgID != '' && imgSection.src != '')
		{
			imgSection.src = closeImg;
		}
	}
	else
	{
		oSection.style.display = 'block';
		if (imgID != '' && imgSection.src != '')
		{
			imgSection.src = openImg;
		}
	}
}

function OpenSmallWindow(URL)
{
	var smallWindow;
	smallWindow = window.open(convertAmptoAmp(URL),'smallPopup','width=200,height=200,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	smallWindow.focus();	
}

function OpenTaskWindow(URL)
{
	var taskWindow;
	taskWindow = window.open(convertAmptoAmp(URL),'taskPopup','width=510,height=370,scrollbars=yes,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	taskWindow.focus();	
}
function OpenPictureUploader()
{
	var calWindow;
	calWindow = window.open('upload.aspx','UploadPopup','width=330,height=250,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	calWindow.focus();	
}

function OpenCalendar(dt,formName, elementName, elementNameCTC)
{
	var calWindow;
	calWindow = window.open('calendar.asp?dt='+ dt + '&frm=' + formName + '&el=' + elementName + '&elCTC=' + elementNameCTC,'CalendarPopup','width=200,height=140,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	calWindow.focus();	
}
function OpenCalendarSpecial(dt,formName, elementName, elementNameCTC)
{
	var calWindow;
	calWindow = window.open('calendarSpecial.asp?dt='+ dt + '&frm=' + formName + '&el=' + elementName + '&elCTC=' + elementNameCTC,'CalendarPopup','width=200,height=140,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	calWindow.focus();	
}function OpenLogonHours(user,formName, elementName,LogonHours)
{
	var lhWindow;
	lhWindow = window.open('logonhours.asp?user=' + user + '&frm=' + formName + '&el=' + elementName + '&logonHours=' + LogonHours,'LogonHoursPopup','width=550,height=200,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	lhWindow.focus();	
}
function ShowViolation(sURL,sMessage, sForm, sObject)
{
	var svWindow;
	if (sURL.indexOf(".asp?") == -1)
	{
	svWindow = window.open(sURL + '?violations=' + sMessage + '&form=' + sForm + '&obj=' + sObject,'RuleViolationPopup','width=400,height=320,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,screenX=50,screenY=50,left=300,top=170');
	}
	else
	{
	svWindow = window.open(convertAmptoAmp(sURL) + '&violations=' + sMessage + '&form=' + sForm + '&obj=' + sObject,'RuleViolationPopup','width=400,height=320,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,screenX=50,screenY=50,left=300,top=170');
	}
	
	svWindow.focus();
}
function OpenSharePicker(URL, objtype, formName, elementName,jsFunc)
{
	var shopWindow;
	if (URL.indexOf(".asp?") == -1)
	{
		shWindow = window.open(URL + '?objtype=' + objtype + '&frm=' + formName + '&el=' + elementName + '&jsFunc=' + jsFunc,'SharePickerPopup','width=560,height=430,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	else
	{
		shWindow = window.open(URL + '&objtype=' + objtype + '&frm=' + formName + '&el=' + elementName + '&jsFunc=' + jsFunc,'SharePickerPopup','width=560,height=430,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	
	shWindow.focus();	
}
function OpenObjectPicker(URL, objtype, formName, elementName,jsFunc)
{
	var opWindow;
	if (URL.indexOf(".asp?") == -1)
	{
		opWindow = window.open(URL + '?objtype=' + objtype + '&frm=' + formName + '&el=' + elementName + '&jsFunc=' + jsFunc,'ObjectPickerPopup','width=560,height=430,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	else
	{
		opWindow = window.open(convertAmptoAmp(URL) + '&objtype=' + objtype + '&frm=' + formName + '&el=' + elementName + '&jsFunc=' + jsFunc,'ObjectPickerPopup','width=560,height=430,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	opWindow.focus();	
}

function AddToGroup(URL, objtype, formName, elementName,jsFunc)
{
	var objectDN
	if (window.document.frmNavigation)
	{
		objectDN = window.document.frmNavigation.objectDN.value;
	}
	var opWindow;
	if (URL.indexOf(".asp?") == -1)
	{
		opWindow = window.open(URL + '?objtype=' + objtype + '&frm=' + formName + '&el=' + elementName + '&jsFunc=' + jsFunc + '&objectDN=' + objectDN,'ObjectPickerPopup','width=420,height=350,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	else
	{
		opWindow = window.open(convertAmptoAmp(URL) + '&objtype=' + objtype + '&frm=' + formName + '&el=' + elementName + '&jsFunc=' + jsFunc + '&objectDN=' + objectDN,'ObjectPickerPopup','width=420,height=350,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	opWindow.focus();	
}

function OpenObjectPickerSingle(URL, objtype, formName, elementText, elementValue, jsFunc)
{
	var opsWindow;
	if (URL.indexOf(".asp?") == -1)
	{
		opsWindow = window.open(URL + '?objtype=' + objtype + '&frm=' + formName + '&ev=' + elementValue + '&et=' + elementText + '&jsFunc=' + jsFunc,'ObjectPickerSinglePopup','width=460,height=360,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	else
	{
		opsWindow = window.open(convertAmptoAmp(URL) + '&objtype=' + objtype + '&frm=' + formName + '&ev=' + elementValue + '&et=' + elementText + '&jsFunc=' + jsFunc,'ObjectPickerSinglePopup','width=460,height=360,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	opsWindow.focus();	
}

function OpenExtensionPicker(URL, ExtType)
{
	var epWindow;

	if (URL.indexOf(".asp?") == -1)
	{
		epWindow = window.open(URL + '?extType=' + ExtType,'ExtensionPicker','width=450,height=350,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=40,screenY=60,left=200,top=100')
	}
	else
	{
		epWindow = window.open(convertAmptoAmp(URL) + '&extType=' + ExtType,'ExtensionPicker','width=450,height=350,scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=40,screenY=60,left=200,top=100')
	}
	epWindow.focus();	
}

function OpenSelectDomain(URL, formName, elementName)
{
	var sdWindow;

	if (URL.indexOf(".asp?") == -1)
	{
		sdWindow = window.open(URL + '?frm=' + formName + '&el=' + elementName,'selectDomain','width=400,height=200,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	else
	{
		sdWindow = window.open(convertAmptoAmp(URL) + '&frm=' + formName + '&el=' + elementName,'selectDomain','width=400,height=200,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')
	}
	sdWindow.focus();	
}

function ToggleObject(URL)
{
	var ToggleWindow;
	ToggleWindow = window.open(convertAmptoAmp(URL),'ToggleObjectPopup','width=200,height=220,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	ToggleWindow.focus();
}

function ResetPassword(URL)
{
	var doWindow;
	doWindow = window.open(convertAmptoAmp(URL),'ResetPasswordPopup','width=420,height=220,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	doWindow.focus();
}

function ChangeRowClass(sObject, sNewClass)
{
	sObject.className = sNewClass;
}

function confirmDelete(sURL,sMessage)
{
	var response = confirm(sMessage)
	if (response)
	{
		document.location.href = convertAmptoAmp(sURL);
		ShowProcessingWindow();
	}
}
function DeleteObject(URL, sMessage)
{
	var response = confirm(sMessage)
	if (response)
	{
		ShowProcessingWindow();
		OpenDeleteObject(URL);
	}
}

function OpenDeleteObject(URL)
{
	var doWindow;
	doWindow = window.open(convertAmptoAmp(URL),'DeleteObjectPopup','width=200,height=200,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	doWindow.focus();
}

function OpenNewObject(URL)
{
	var nuWindow;
	nuWindow = window.open(convertAmptoAmp(URL),'NewObjectPopup','width=480,height=400,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,screenX=20,screenY=40,left=250,top=130')
	nuWindow.focus();
}
function OpenAdvancedSearch(URL)
{
	var searchWindow;
	searchWindow = window.open(URL,'searchPopup','width=540,height=320,scrollbars=no,location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=yes,screenX=20,screenY=40,left=250,top=50')		
	searchWindow.focus();	
}

function OpenVersion()
{
	var verWindow;
	verWindow = window.open('Version.asp','VersionPopup','width=465,height=345,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	verWindow.focus();	
}

function convertAmptoAmp(URL)
{
	var permURL = URL.toString();
	var newURL;
	var ampPos = permURL.indexOf("&amp;");
	
	if(ampPos >= 0)
	{
		newURL = permURL.substr(0,permURL.indexOf("&amp;")) + '%26' + permURL.substr(ampPos + 5, permURL.length);
	}
	else
	{
		newURL = permURL;
	}
	return newURL;
}

function enableFields(bChecked, sForm, arFields)
{
	var sType = "";
	for(i=0;i<arFields.length;i++)
	{
		sType = document.forms[sForm].elements[arFields[i]].type;
		if ((sType == "select-one") || (sType == "text") || (sType == "checkbox") || (sType == "select-multiple") || (sType == "textarea") || (sType == "button"))
		{
			// This is a normal entry type
			document.forms[sForm].elements[arFields[i]].disabled = !bChecked;
			if (document.forms[sForm].elements[arFields[i]].disabled) document.forms[sForm].elements[arFields[i]].style.background = '#DDDDDD';
			else document.forms[sForm].elements[arFields[i]].style.background = '#FFFFFF';
		}
		else
		{
			// This is a radio button collection
			// This will disable/enable the radio buttons
			for(j=0;j<document.forms[sForm].elements[arFields[i]].length;j++)
			{
				document.forms[sForm].elements[arFields[i]][j].disabled = !bChecked;
				if (document.forms[sForm].elements[arFields[i]][j].disabled) document.forms[sForm].elements[arFields[i]][j].style.background = '#DDDDDD';
				else document.forms[sForm].elements[arFields[i]][j].style.background = '#FFFFFF';
			}
		}
	}
}

function SelectDropDownLists(sForm)
{
	for (i=0;i<document.forms[sForm].length;i++)
	{
		if (document.forms[sForm].elements[i].type == 'select-multiple')
		{
			// This is a multi Select! - Select all the items in it.
			for(j=0;j<document.forms[sForm].elements[i].options.length;j++)
			{
				document.forms[sForm].elements[i].options[j].selected = true;
			}
		}
	}

}

function addElementToSelectList(frmName, elName, elText, elValue)
{
	// If the only element in there is the spacer element, remove it before you add the new element
	if((document.forms[frmName].elements[elName].options.length == 1) && 
		(document.forms[frmName].elements[elName].options[0].value == 0)) 
	{
		document.forms[frmName].elements[elName].options.length = 0;
	}
	document.forms[frmName].elements[elName].options[document.forms[frmName].elements[elName].options.length] = new Option(elText,elValue);
}

function RemoveUser(fromList)
{
	var lastRemoved;
	for(i=(fromList.length -1);i>=0;i--)
	{
		if (fromList.options[i].selected)
		{
			fromList.remove(i);
			lastRemoved = i;
		}
	}
}

function validateEmailAddress(strToValidate,errorMessage)
{
	/*
	var emailAddress = strToValidate;
	var posOfAtSign = emailAddress.indexOf('@');
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	// If there is an @ sign continue checking
	if (posOfAtSign>=0)
	{
		// Make sure there are not more than 1 @ sign
		if(((emailAddress.search(exclude) != -1)||
		(emailAddress.search(check))== -1)||
		(emailAddress.search(checkend) == -1))
		{
		  alert(errorMessage);
		  return false;
		}
	}
	*/
	return true;
}

function checkFieldForEmpty(iField, sMessage)
{
	if (iField.value == '')
	{
		alert(sMessage);
		return false;
	}
	else
	{
		return true;
	}
}

function selectAll(inList)
{
	for(i=0;i<inList.length;i++)
	{
		inList.options[i].selected = true;
	}
}

function HideAllTabs()
{
	for (i=0;i<tabs.length;i++)
	{
		var oSection = document.getElementById('disp_' + tabs[i]);
		if (oSection.style.display == 'block')
		{
			oSection.style.display = 'none';
		}
		var oDiv = document.getElementById('nav_' + tabs[i]);
		oDiv.className = 'sys-toppane-bgcolor';
	}
}

function ShowTab(sTab)
{
	HideAllTabs()
	var oSection = document.getElementById('nav_' + sTab);
	oSection.className = 'sys-toppane-selection';
	var oDiv = document.getElementById('disp_' + sTab);
	oDiv.style.display = 'block';
}

function showalltabs()
{
	if (isNS6)
	{
		var tabToShow;
		for(i=0;i<tabs.length;i++)
		{
			tabToShow = document.getElementById(tabs[i]);
			tabToShow.style.display = "block";
		}
	}
}
function GoBack(x)
{
	history.go(0-x);
}
function Refresh()
{
	document.location.reload();
}
function Print()
{
	window.print();
}

function ShowProcessingWindow()
{
	if (opener != null)
	{
		// This is a new window
		if (!opener.parent.isWindowOpen())
		{
			opener.parent.openProcWindow();
		}
	}
	else
	{
		if (parent.opener != null)
		{
			// This is a new window, with frames
			if (!parent.opener.parent.isWindowOpen())
			{
				parent.opener.parent.openProcWindow();
			}
		}
		else
		{
			// This is the default right hand window
			if (!parent.isWindowOpen())
			{
				parent.openProcWindow();
			}
		}
		
	}
}

function HideProcessingWindow()
{
	if (opener != null)
	{
		// This is a new window
		if (opener.parent.isWindowOpen())
		{
			opener.parent.closeProcWindow();
		}
	}
	else
	{
		if (parent.opener != null)
		{
			// This is a new window, with frames
			if (parent.opener.parent.isWindowOpen())
			{
				parent.opener.parent.closeProcWindow();
			}
		}
		else
		{
			// This is the default right hand window
			if (parent.isWindowOpen())
			{
				parent.closeProcWindow();
			}
		}
		
	}
}

function AddTxtValue(sForm,sTxtElement, sSelElement)
{
	elText = document.forms[sForm].elements[sTxtElement].value;
	elValue = elText;
	if(elText != '')
	{
		document.forms[sForm].elements[sSelElement].options[document.forms[sForm].elements[sSelElement].options.length] = new Option(elText,elValue);
		document.forms[sForm].elements[sTxtElement].value = '';
	}
}

function IsNum(element,evnt)
{
	var nn=element.value
	var charCode = (navigator.appName == "Netscape") ? evnt.which : evnt.keyCode

	// allow minus sign at the beginning:
	if (element.value.length==0 && charCode==45) return true

	// permit 1 decimal place...
	if (charCode==46 && nn.indexOf(".")==-1) return true

	// ...and numbers
	if (charCode > 31 && (charCode < 48 || charCode > 57 ))
	   {
	    return false
	   }
	return true
}

// Gradient Buttons
function showGrey()
{
	for (i=0;i<showGrey.arguments.length;i++)
	{
		document.all(showGrey.arguments[i]).style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#CCCCCC', EndColorStr='#FFFFFF')"; 
	}
}
function showBlue()
{
	for (i=0;i<showBlue.arguments.length;i++)
	{
		document.all(showBlue.arguments[i]).style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#C7D8FA', EndColorStr='#8caae6')"; 
	}
}
// Gradient Title Bars
function showGradGrey()
{
	for (i=0;i<showGradGrey.arguments.length;i++)
	{
		document.all(showGradGrey.arguments[i]).style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#FFFFFF', EndColorStr='#CCCCCC')";
	}
}

function showGradBlue()
{
	for (i=0;i<showGradBlue.arguments.length;i++)
	{
		document.all(showGradBlue.arguments[i]).style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#0000BC', EndColorStr='#8caae6')";
	}
}
/* RJD - Function to autofill
// RJD - Fills another field as data is inserted - not currently used
//
	function updateParentOrg()
	{
		if(document.frmUser.imDoseParentOrganisation.value != document.frmUser.company.value.substr(0,20))
		{
			document.frmUser.imDoseParentOrganisation.value = document.frmUser.company.value.substr(0,20);
		}
		
	}*/
// RJD - Disable some fields
function disableFields()
{
	// RJD - Sets Parent Organsation to a specific string, and disables the field if user affiliation is Staff
	if (document.frmUser.imDoseUserAffiliation.value == 'Staff')
	{
		document.frmUser.imDoseParentOrganisation.value = "";
		document.frmUser.imDoseParentOrganisation.disabled=true;
	}
	else
	{
	// RJD - Otherwise set the value back to that obtained from AD. 
		document.frmUser.imDoseParentOrganisation.disabled = false;
		if (document.frmUser.adParentOrg.value != "")
		{
			document.frmUser.imDoseParentOrganisation.value = document.frmUser.adParentOrg.value;
		}
	}
}
// RJD - Disable fields within opener
function disableOpenerFields()
{
	// RJD - Sets Parent Organsation to a specific string, and disables the field if user affiliation is Staff
	if (window.opener.document.frmUser.imDoseUserAffiliation.value == 'Staff')
	{
		window.opener.document.frmUser.imDoseParentOrganisation.value = "";
		window.opener.document.frmUser.imDoseParentOrganisation.disabled=true;
	}
	else
	{
	// RJD - Otherwise set the value back to that obtained from AD. 
		window.opener.document.frmUser.imDoseParentOrganisation.disabled = false;
		if (window.opener.document.frmUser.adParentOrg.value != "")
		{
			window.opener.document.frmUser.imDoseParentOrganisation.value = window.opener.document.frmUser.adParentOrg.value;
		}
	}
}

function OpenPopupWindow(URL)
{
	var smallWindow;
	smallWindow = window.open(convertAmptoAmp(URL),'smallPopup','width=525,height=340,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no,screenX=20,screenY=40,left=250,top=130')		
	smallWindow.focus();	
}

