var ie = 0;
var n = 1;

if (document.all)
{
	n = 0;
	ie = 1;
}

function checkDisabled(m_oSelect)
{
	if(m_oSelect.disabled)
	{
		m_oSelect.disabled = false;
	}
}

function popNewWindow(name,url,height,width)
{
	options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + width + ',height=' + height + ',copyhistory=no';
    window.open(url,name,options);
}

function popQuant(m_sUrl)
{
	options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=750,height=550,copyhistory=no';
    window.open(m_sUrl,'quant',options);
}

function openWindow(m_sUrl, m_sWindowName, m_sSettings)
{
	var m_oPopupWin = window.open(m_sUrl,m_sWindowName,m_sSettings);
	m_oPopupWin.focus();
}

function formFocus(m_sFrmName, m_sElementName)
{
	eval("document." + m_sFrmName + "." + m_sElementName + ".focus();");
	return false;
}

function sendToFundProfile(m_oFrm)
{
	if (m_oFrm.selManager.value == "-1")
	{
		alert("Please select a manager");
	}
	else
	{	
		var m_sAPIRCode = m_oFrm.selFund.value;

		window.location = "fund-profile.asp?APIRCode=" + m_sAPIRCode;
	}
	return false;
}

String.prototype.trim = function() 
{
  return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
}

function testThis()
{
	alert("common");
}

function editPort()
{
	alert("editPort");
	var urlStr = "editport.asp";
	var PopupWin = window.open(urlStr,"editPort","scrollbars=yes,toolbar=no,directories=no,status=yes,menubar=no,resizable=yes,width=200,height=270")
	PopupWin.focus();
}

function popCalendarWindow(m_nFormName, m_nFieldName)
{
	var win = null;
	var n;
	var ie;
	
	if (document.all)
	{
		n=0;
		ie=1;
	}
	
	if (document.layers)
	{
		n=1;
		ie=0;
	}
	
	if (ie)
	{ 
		aWidth = 155;
		aHeight = 185;
	}
		
	if (n)
	{
		aWidth = 162;
		aHeight = 190;
	}

	LeftPosition = (screen.width) ? (screen.width-aWidth)/2 : 50;
	TopPosition = (screen.height) ? (screen.height-aHeight)/2 : 50;

	settings = 'height='+ aHeight + ',width=' + aWidth
	settings += ',top=' +TopPosition +', left='+LeftPosition 
	settings += ',heading=no,topbar=no,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,border=no'

	win = window.open("/management/calendar/calendar.asp?formName=" + m_nFormName + "&fieldName=" + m_nFieldName,"calendar",settings);

	if(win.window.focus)
	{
		win.window.focus();
	}
} 

function isValidEmail(m_sEmailAddress)
{
	var tempAddress
	tempAddress = m_sEmailAddress;
	tempAddress.replace ("'", "");
	var m_oRegEx = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 	var m_bIsValid = m_oRegEx.test(tempAddress);
	
	return m_bIsValid;
}

function selectOption(label, id)
{
    this.label = label;
    this.id = id;
}



function UpdateChildOptions (childSelect, parentSelect, dataArray, unselectedText, parentMissingID)
{
	childSelect.options[0] = new Option (unselectedText, '-1');
	childSelect.length = 1;

	var parentID = "-1";	
	if (typeof parentSelect.selectedIndex == 'undefined')
	{
		parentID = parentMissingID;
	}
	else
	{
		parentID = parentSelect.options[parentSelect.selectedIndex].value;
	}
	
	if (parentID == "-1")
	{
		// Array 0 is used for a default list of options if parent drop-down exists but no "parent" option is selected
		parentID = "0";
	}
	var m_arrPopulate = eval (dataArray + "[" + parentID + "]");

	if (!m_arrPopulate)
	{
		//alert ("Couldn't find array " + dataArray + "[" + parentID + "]");
		return;
	}
		
	FillSelectFromArray (childSelect, m_arrPopulate);
}


function UpdateChildOptionsWithFilter (childSelect, parentSelect, filterSelect, dataArray, unselectedText)
{
	childSelect.options[0] = new Option (unselectedText, '-1');
	childSelect.length = 1;
	
	var parentID = parentSelect.options[parentSelect.selectedIndex].value;
	var filterID = filterSelect.options[filterSelect.selectedIndex].value;

	// Array 0 is used for a default list of options if no parent or filter option is selected
	if (parentID == "-1") parentID = "0";
	if (filterID == "-1") filterID = "0";
	
	// Check that we have some child options to add ... if not, just leave the sub-options empty
	if (typeof eval (dataArray + "[" + parentID + "]") != 'undefined')
	{
		var m_arrPopulate = eval (dataArray + "[" + parentID + "]" + "[" + filterID + "]");
		if (!m_arrPopulate)
		{
			// No match for that parent/filter combo, try without filter
			m_arrPopulate = eval (dataArray + "[" + parentID + "]" + "[0]");
			if (!m_arrPopulate)
			{
				//alert ("Couldn't find array " + dataArray + "[" + parentID + "]" + "[" + filterID + "]");
				return;
			}
		}
		
		FillSelectFromArray (childSelect, m_arrPopulate);
	}
}


function UpdateChildOptionsWithFilterAndNullValues(childSelect, parentSelect, filterSelect, dataArray, unselectedText, nullIndex) {
    childSelect.options[0] = new Option(unselectedText, '-1');
    childSelect.length = 1;

    var parentID = parentSelect.options[parentSelect.selectedIndex].value;
    var filterID = filterSelect.options[filterSelect.selectedIndex].value;

    // Array 0 is used for a default list of options if no parent or filter option is selected
    if (parentID == "-1") parentID = "0";
    if (filterID == "-1") filterID = "0";

    // Check that we have some child options to add ... if not, just leave the sub-options empty
    if (typeof eval(dataArray + "[" + parentID + "]") != 'undefined') {
        var m_arrPopulate = eval(dataArray + "[" + parentID + "]" + "[" + filterID + "]");
        if (!m_arrPopulate) {
            // No match for that parent/filter combo, try without filter
            m_arrPopulate = eval(dataArray + "[" + parentID + "]" + "["+ nullIndex +"]");
            if (!m_arrPopulate) {
                //alert("Couldn't find array " + dataArray + "[" + parentID + "]" + "[" + filterID + "]");
                return;
            }
        }

        FillSelectFromArray(childSelect, m_arrPopulate);
    }
}

function FillSelectFromArray (childSelect, m_arrPopulate)
{
	for (i=0; i<m_arrPopulate.length; i++)
	{
		childSelect.options[i+1] = new Option(m_arrPopulate[i].label, m_arrPopulate[i].id);
		childSelect.length = m_arrPopulate.length + 1;
	}
}


function SetMenuValue (selectMenu, setValue)
{
	if (typeof selectMenu.options != 'undefined')
	{
		for (var intOption = 0; intOption < selectMenu.options.length; intOption++)
		{
			if (selectMenu.options[intOption].value == setValue)
			{
				selectMenu.options[intOption].selected = true;
			}
		}
	}
}

// for supertoast "use client default" checkbox 
function checkClientSetting(m_oFrm, checkName, m_arrClientDefault)
{
	var m_sChkBoxName, m_sChkValue;
	// get header checkbox
	for(var x=0; x<=m_oFrm.length-1; x++)
	{
		if(m_oFrm.elements[x].type == "checkbox" && m_oFrm.elements[x].name == checkName)
		{
			m_sChkValue = m_oFrm.elements[x].checked;
			break;
		}
	}
	
	for (var iCount=0; iCount < m_arrClientDefault.length; iCount++)
	{
		for(var y=0; y < m_oFrm.length; y++)
		{
			if(m_arrClientDefault[iCount] == m_oFrm.elements[y].name)
			{
				// tick the individual checkboxes if the "Use Client Default" is unticked
				if (m_sChkValue == false)
				{
					m_oFrm.elements[y].checked = true;
				}
				else
				{
					// untick the individual checkboxes if the "Use Client Default" is ticked
					m_oFrm.elements[y].checked = false;
				}
			}
			
		}
	}
}

function ToggleRestoreDefault(m_oFrm, m_bChecked, m_sChkName, m_arrChkList)
{
	// find the checkbox value for "All" or "Use Client default", etc...
	for(var x=0; x< m_oFrm.length; x++)
	{
		// do 
		if(m_oFrm.elements[x].name == m_sChkName)
		{
			if (m_oFrm.elements[x].checked)
			{
				m_oFrm.elements[x].checked = false;
				checkClientSetting(m_oFrm, m_sChkName, m_arrChkList);
				
			}
			
		}	
	}
		
}

