var isIE;

if (navigator.appName == "Microsoft Internet Explorer") {
			if (parseInt(navigator.appVersion) >= 4) {
				isIE = true;
				//document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"groups/corp_comm/documents/web_asset/nasdw_000462.css\">");
			}
} else {
			isIE = false;
				//document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"groups/corp_comm/documents/web_asset/nasdw_001337.css\">");
}

function onloadtasks(print) { // CALLS ALL THE NECESSARY FUNCTIONS THAT EXECUTE UPON LOADING THE PAGE
	
	if (print != 1) 
	{
		SetContentHeight();
//		TopNavFunctions();
//		fnInit();
	}
}
			
//SETS THE REQUIRED BOTTOM PADDING BASED ON THE SCREEN RESOLUTION. THIS IS REQUIRED TO ELIMINATE GREEN SPACE BELOW THE CONTENT AREA.
function SetContentHeight(){
	// browser sniffer
	var NN, IE, dynNN, dynIE
	var agent = navigator.appName + navigator.appVersion;

	NN = ( (agent.indexOf("Netscape") > -1 ) ? 1 : 0);
	IE = ( (agent.indexOf("Explorer" )> -1 || agent.indexOf("MSIE") > -1 ) ? 1 : 0);

	if (parseInt(navigator.appVersion) >= 4){
		if (navigator.appName == "Netscape"){
			dynNN = true;
		} else {
			dynIE = true;
		}
	}
		

	var ScreenHeight;
//	var NavHeight;
	var ContentTopHeight;

	// If browsing with IE, set the height of the nav area to the available height in the browser window.
//  if (dynIE){
//		ScreenHeight = parseInt(document.body.clientHeight);
//		NavHeight = parseInt(TopNav1.height) + parseInt(TopNav2.height) + parseInt(TopNav3.height) + parseInt(TopNav4.height);
//		ContentTopHeight = parseInt(ContentTop.height);
//		LeftNav.height = ScreenHeight - (NavHeight + ContentTopHeight + 2);
//
//  }
}

//CALLS ALL THE NECESSARY TOP NAVIGATION FUNCTIONALITY
function TopNavFunctions(){
	SetActiveArea();
}


////////////////////////////////////////////////////////////////////////////
// Function : outsideLink
// Comments : this function opens external content in a new window. 
/////////////////////////////////////////////////////////////////////////////
function outsideLink(url){
 eval("window.open('" + url + "','_blank')");
}

////////////////////////////////////////////////////////////////////////////
// Function : outsidelink
// Comments : this function opens external content in a new window. Same as outsideLink.  People were having trouble
//            with case sensitivity.
/////////////////////////////////////////////////////////////////////////////
function outsidelink(url){
 eval("window.open('" + url + "','_blank')");
}

function nativelink(contentId){ 
	var newUrl = "";
	if (isIE){
		var oBase = document.all.tags('BASE');
		strHref = oBase[0].href;
		newUrl += strHref;
	}
	newUrl += "idcplg?IdcService=GET_FILE";
	newUrl += "&dDocName=" + contentId;
	newUrl += "&RevisionSelectionMethod=LatestReleased";
	newUrl += "&Rendition=primary";
	//newUrl += "&noSaveAs=1";
	newUrl += "&allowInterrupt=1";
	
	// Navigate to the new url
	window.location = newUrl;
}

function pdflink(contentId){ 
	var newUrl = "";
	newUrl += g_httpCgiUrl;
	newUrl += "ssDocName=" + contentId;
	// Navigate to the new url	
	window.open(newUrl);
}

function email(mailID, displayName){ 
	var newUrl = "";
	newUrl += "http://apps.finra.org/EmailMask/EmailMask.aspx?";
	newUrl += "&id=" + mailID;
	newUrl += "&displayName=" + displayName;
	window.open(newUrl,'mail','menubar=0,location=0,titlebar=0,status=0,toolbar=0,resizable=1,width=600,height=500');
}


function searchWithin(frm,adv){
	if(frm.UserText.value != "" && frm.UserText.value != null)
	{
		if(adv)
		{
			var sortString = frm.SelectSort.options[frm.SelectSort.selectedIndex].value;
			//Clean up form fields
			frm.SortSpec.value = sortString;			
			frm.SelectedGroups.value = "";

			//parse checked security groups into search params
			var securityGroupQueryText = "";
			var b = 0;
			var secGrps = new Array();
			for(i=0; i<frm.Coll.length; i++){
				if (frm.Coll[i].checked){
					secGrps[b] = frm.Coll[i].value;
					b++;							
				}
			}
			if (secGrps.length > 0 ){
				for (i=0; i<secGrps.length; i++){
					securityGroupQueryText += "dSecurityGroup<matches>`" + secGrps[i] + "`";
					frm.SelectedGroups.value += secGrps[i] + ",";
					if (i<secGrps.length-1){
						securityGroupQueryText += "<or>";	
					}
				}
			}
			if (securityGroupQueryText.length > 0){
				if (frm.QueryText.value.length > 0){
					frm.QueryText.value = "(" + frm.QueryText.value + ")"	+ "<and>" + securityGroupQueryText;
				} else {
					frm.QueryText.value = securityGroupQueryText;
				}	

			}
		}
		frm.submit();
	}
	else
	{
		alert("Please enter search term.");
	}
}

