	function SubmitView(list,itemtype)
		{
	
		if(list.options[list.selectedIndex].text.charAt(0)== "(")
			return false
		
		//alert(list.options[list.selectedIndex].value)
		
		SubmitViewCommandLine(list.options[list.selectedIndex].value, itemtype)
		}
		
	function SubmitViewCommandLine(command_line,itemtype)
		{
		if (command_line.indexOf("javascript:QuickSearch") != -1)
			ProcessFunctionCall(command_line,itemtype)
		else
			{
			if((command_line.charAt(0) == "j") || (command_line.charAt(0) == "/"))
				ProcessUrl(command_line,itemtype)
			else
				ProcessDisplayPage(command_line,itemtype)
			}
		}
		
	//alert(command_line,itemtype)	
	function ProcessFunctionCall(command_line,itemtype)
		{
		var r, re;
		re = "~"
				
		r = command_line.split(re)

	    eval(r[0])
		}

	function FixViewName(view)
		{
		
		// this function replaces junk in the view name and encodes +
		// the correct way is to use encodeURIComponent() but it does not
		// work with older version of the browsers EI 4.7...
		// in addition ++ is not being encded properly because it
		// regular expressions do not work properly with EI 4.7...
		//JF
		
		var viewname
		viewname = escape(view.replace(RegExp("\xa0", "g"), ""))
//		viewname = viewname.replace(RegExp("[+]", "g"), "%2B")
		return viewname.replace("+", "%2B")
		}	
			
	function ProcessDisplayPage(command_line,itemtype)
		{
		//alert(command_line)
		//if(list.options[list.selectedIndex].value == "null")
		if(command_line == "null")
			return false
		var r, re;
		var loc
		re = "~"
				
		
		//r = list.options[list.selectedIndex].value.split(re);
		r = command_line.split(re);
		

		if (r.length < 7)
			alert("This Function is expecting 7 parameters(recieved " + r.length + ")")
		else
			{
			var viewname
			viewname = FixViewName(r[6])
			
			loc = "/common/display.asp?NewQuery="+escape(r[0])+
				"&Order="+escape(r[1]) + "&ItemType="+itemtype+"&DataType="+itemtype+
				"&CompanyName="+escape(r[3]) + "&ViewName=" + viewname + 
				//"&CompanyId="+escape(r[2]) + 
				"&Tel="+escape(r[4]) +	"&Fax="+escape(r[5])

			document.location = loc
			}
		}
		
	function ProcessUrl(command_line, datatype)
		{ 
		var r, re;
		re = "~"
				
		r = command_line.split(re);
		
		var loc = r[0]
		var orderlink = ""
		
		if ( (loc.indexOf("adminOrders.asp") != -1) || (loc.indexOf("dispOrders.asp") != -1) )
			{
			orderlink = document.location.href
			orderlink = "&OrderLink=" + escape(orderlink)
			}	
		
		loc = loc + orderlink
		document.location = loc
		}

	function load_checkmessages(IsLogin, graphic, name)
		{
		if (IsLogin == "Y")
			{
			win_width = 675
			win_height = 400
		
			change_graphics(graphic, name)
			MessageWindow = window.open('/common/checkmessages.asp', "MessageSummary", "status=no,resizable=yes,width="+win_width+",height="+win_height+",scrollbars=yes,menubar=no,top=" + 20 + ",left=" + 40)
			MessageWindow.focus()
			}
		else
			alert("Please Login or Register for a FREE 30 Day Trial.")
		}

	function normal()
		{
		// if (navigator.appVersion.indexOf("MSIE 4") == -1)
			top.frame1.focus()
			
		document.images[temp].src = "/common/pic/" + temp_url
		}
		
	function change_graphics(graphic, name)
		{
		eval("document." + name + ".src='" + "/common/pic/" + graphic + "'")
		
		// if (navigator.appVersion.indexOf("MSIE 4") == -1)
//			top.frame1.focus()   // 06/18/2003 jf
		}
		
	function refresh(graphic, num)
		{
		
		//(graphic, num)
		
		if (top.DisplayItems != null)
			top.DisplayItems.location = top.DisplayItems.location.href
		else
			document.location.replace(document.location.href)
		}
		
	function refresh_mouseout()
		{
		document.refresh_button.src="/common/pic/refresh.gif"
		}

	function GetItemType(ThisForm)
		{
		ItemType = "B"

		//var ii		
		
		if (ThisForm.ItemType.type == "hidden")
			{
			ItemType = ThisForm.ItemType.value
			}
		else
			{
			ItemType = ThisForm.ItemType.value
			//	alert(ItemType)
			}
				
		return ItemType
		}

	function GetCurrentCompany(CompanyId)
		{
		if (CompanyId == "9999" || CompanyId == "10157" || CompanyId == "10345")
			CurrentCompany = "&Current_Company=-1"
		else
			CurrentCompany = "&Current_CompanyId=" + CompanyId + "&CompanyId=" + CompanyId
		
		return CurrentCompany
		}

	function CallPage(Location, IsLogin, CompanyId)
		{
		if (IsLogin == "Y")
			{
			document.location = Location
			}
		else
			{
			if (CompanyId == 9999)
				alert("Please Login or Register for a FREE 30 Day Trial.")
			else
				{
				if (CompanyId == 10157)
					alert("Please Login or call TM3 Customer Service at 800-367-8215 for Access.")
				else
					alert("Please Login or Register Online.")
				}
			}
		}
		
	function CallAdvancedSearch(ThisForm, ItemType,CompanyId, IsLogin)
		{ 
		if (ItemType != "M" && ItemType != "P" && ItemType != "Q")
			{
			Location="/common/FORM.asp" +
				"?ItemType=" + GetItemType(ThisForm) + GetCurrentCompany(CompanyId)
			}
		else 
		    {
		    Location="/common/FORM.asp" +
				"?ItemType=" + ItemType + GetCurrentCompany(CompanyId)
			}
	
		CallPage(Location, IsLogin, CompanyId)
		}

	function CallStateSearch(ThisForm, CompanyId, userid, IsLogin)
		{
		ItemType = GetItemType(ThisForm)
		
		if (ItemType == "M")
			CallAdvancedSearch(ThisForm, CompanyId, IsLogin)
		
		else
			{
			if (userid == "mfu")
				Location="/common/ItemsByStateOther.asp" + "?ItemType=" + ItemType + GetCurrentCompany(CompanyId)
			else
				Location="/common/ItemsByState.asp" + "?ItemType=" + ItemType + GetCurrentCompany(CompanyId)
				
			CallPage(Location, IsLogin, CompanyId)
			
			}
		}
	function CallStateSearchMap(ThisForm, CompanyId, userid, IsLogin)
		{
		ItemType = GetItemType(ThisForm)
		
		if (ItemType == "M")
			CallAdvancedSearch(ThisForm, CompanyId, IsLogin)
		
		else
			{
			Location="/common/ItemsByStateMap.asp" +
				"?ItemType=" + ItemType + GetCurrentCompany(CompanyId)
				
			CallPage(Location, IsLogin, CompanyId)
			
			}
		}
		
	function stringReplace(originalString, findText, replaceText)
		{
		var pos = originalString.indexOf(findText)
		var len = findText.length
		
		while (pos != -1)
			{
			preString = originalString.substring(0, pos)
			postString = originalString.substring(pos + len, originalString.length)
			originalString = preString + replaceText + postString
			pos = originalString.indexOf(findText)
			}
			
		return originalString
		}
		
	function Trim(Str)
		{
		var ReturnStr = stringReplace(Str, "  ", " ")
		
		if (ReturnStr.charAt(0) == ' ')
			ReturnStr = ReturnStr.substring(1, ReturnStr.length)
		
		if (ReturnStr.charAt(ReturnStr.length - 1) == ' ')
			ReturnStr = ReturnStr.substring(0, ReturnStr.length - 1)

		return ReturnStr
		}
		
	function GetDefaultOrder(ItemType, CompanyId)
		{
		var Order = ""
		
		if (ItemType == 'B')
		    
			if (CompanyId == 810 || CompanyId == 830 || CompanyId == 980 || CompanyId == 990 || 
				CompanyId == 760 || CompanyId == 890 || CompanyId == 995 || CompanyId == 808 || CompanyId == 150)
				Order = escape("Item Number")
			else
				{
//				alert(list.options[list.selectedIndex].value)
				Order = escape("MOST RECENT")
				}
		else if (ItemType == 'O')
//			{
//			if (CompanyId == 9999 || CompanyId == 10157)
//				Order = escape("MOST RECENT")
//			else
				Order = "MATURITY"
//				}
		else if (ItemType == 'I')
			Order = "MATURITY"
//			Order = escape("MOST RECENT")
		else if (ItemType == 'M')
			Order = "OrderByMaturity"
		else if (ItemType == 'A')
			Order = "Maturity"
		else if (ItemType == '')
			if (CompanyId == 810 || CompanyId == 830 || CompanyId == 980 || CompanyId == 990 || 
				CompanyId == 760 || CompanyId == 890 || CompanyId == 995 || CompanyId == 808)
				Order = escape("Item Number")
			else
				Order = escape("MOST RECENT")
		return Order
		}

	function GetCompanyType(ItemType, CompanyId)
		{
		var Type = CompanyId
		if ((CompanyId == "9999") || (CompanyId == "10157") || (CompanyId == "10345"))
			{
			if (ItemType == 'B')
				Type = 0
			else if (ItemType == 'O')
				Type = -1
			else if (ItemType == 'I')
				Type = -2
			else if (ItemType == 'M')
				Type = 0
			else if (ItemType == 'A')
				Type = 0
			else if (ItemType == '')
				Type = 0
			}
			
		return Type
		}
		
		
function SelectedForView(Selected, ThisForm, ItemType, IsLogin, UserId, CompanyId, Order, Query, CompanyName, ViewName, Tel, Fax)
{
	var location
	var selected_string
	var most_recent_string

	selected_string = "&selected=Y"
	most_recent_string = "&most_recent_ind=on"
	location = "display.asp?CompanyId=" + CompanyId + "&DataType=" + ItemType
	location = location + "&ItemType=" + ItemType
	location = location + "&Order=" + Order

	if (Selected)  // not selected now make it selected
		{
		if (Query.search(selected_string) == -1)
			Query += selected_string
		}
	else
		{
		if (Query.search(selected_string) != -1)
			Query = Query.replace(selected_string, "")
		}
		
	if (Query.search(most_recent_string) != -1)
		Query = Query.replace(most_recent_string, "")
	location += "&NewQuery=" + escape(Query)			
	if (ViewName != null)
		location += "&ViewName=" + escape(ViewName)
	if (ViewName != null)
		location += "&CompanyName=" + escape(CompanyName)
	if (Tel != null)
		location += "&Tel=" + escape(Tel)
	if (Fax != null)
		location += "&Fax=" + escape(Fax)
			
	CallPage(location, IsLogin, CompanyId)
	
	
}

	/*	
	function SelectedForView(Selected, ThisForm, ItemType, IsLogin, UserId, CompanyId, Order, Query)
	{	//	Selected argument added by tkong 
		//	function in quicksearchmenu.asp passes it.
		
		var location
		location = "display.asp?CompanyId=" + GetCompanyType(ItemType, CompanyId) + "&DataType=" + ItemType
		location = location + "&ItemType=" + ItemType
		location = location + "&Order=" + Order + "&NewQuery=" + escape(Query)
		CallPage(location, IsLogin, CompanyId)
	}
	*/		

function QuickSearch(ThisForm, ItemType, IsLogin, UserId, CompanyId, CompanyType, Admin, CurrentMSRBDate, Selected)
{
	var SearchString = Trim(ThisForm.QuickSearch.value)
	var StateString = ""
	var CouponString = ""
	var MaturityString = ""
	var AmountString = ""
	var ListString = ""
	var NewQuery = ""
	var Location
	var pos
	var ListLenght
		
		//alert('SearchString='+SearchString)
		//alert ('ItemType='+ItemType )
			
	if (ItemType == 'C' || ItemType == 'U')
		{
		SearchString = stringReplace(SearchString, " ", "")
		if (CompanyId==9999 && CompanyType == "Main" && Admin == "Y")
			{
			if (ItemType == 'C')
				{
				if (SearchString.search("[^0-9.]") != -1 || SearchString.length > 5)
					{
					alert("Error: " + SearchString + " is not a valid Company ID Search string.")
					return false
					}
				else if (SearchString.length > 0)
					Location = "/common/CompanyEdit.asp?itemtype=F&companyid=" + SearchString 
							+ "&QuickSearch=" + SearchString
				else			
					Location = "/common/DisplayCompanies.asp?itemtype=F"
				}	
			else
				{
				if (SearchString.length > 0)
					{
					if (SearchString.indexOf(",") > -1)
						{
						var Lname = SearchString.replace(",", "")
						Location = "/common/UserManager.asp?itemtype=F&Name=" + Lname	
									+ "&QuickSearch=" + SearchString
						}			
					else
					    {
					    if (SearchString.length < 3)
					        {
       						Location = "/common/UserManager.asp?itemtype=F&SearchUserId=" + SearchString	
									+ "&QuickSearch=" + SearchString 
				             }
				         else
				             if (SearchString.indexOf("@") > -1)
				             {  
						     Location = "/common/ViewsList.asp?itemtype=F&SearchUserId=" + SearchString	
							 		+ "&QuickSearch=" + SearchString + "&UserID=" + SearchString
							 }	 	
				             else
				             {   
						     Location = "/common/UserEdit.asp?itemtype=F&SearchUserId=" + SearchString	
									+ "&QuickSearch=" + SearchString + "&UserID=" + SearchString
							 }	 	
						  }			
					}			
				else
					Location = "/common/UserManager.asp?Name=A&ItemType=F&ExpiredUsers=Y"
				}
			}
		else
			{
			alert("No Authorization to perform the search")	
			return
			}
		}	
	else
		{
	
		if ((ItemType != "A" ) && (ItemType != "B" ) && (ItemType != "I" ) 
			&& (ItemType != "O" ) && (ItemType != "P" ) && (ItemType != "M"))
			ItemType = "B"
				
		if (SearchString.charAt(0) >= '0' && SearchString.charAt(0) <= '9')
			{ 
			// cusip search
			SearchString = stringReplace(SearchString, " ", "")
			 if (ItemType == 'M')
				{ 
				Location="/common/MSRBSummary.asp?cusip=" + SearchString +
						"&QuickSearch=" + SearchString +
						"&ItemType=" + ItemType
				}
			else 
				{
				Location="/common/display.asp" +
						"?CompanyId=" + GetCompanyType(ItemType, CompanyId) +
						"&ItemsPerPage=25" +
						"&QuickSearch=" + escape(SearchString) +
						"&NewQuery=" + escape("&cusip=" + SearchString)+
						"&users=" + UserId +
						"&datatype=" + ItemType +
						"&OrginalItemsPerPage=25" +
						"&itemtype=" + ItemType + 
						"&MenuSelection=AdvancedSearch" +
						"&CompanyType=" + GetCompanyType(ItemType, CompanyId) +
						"&CurrentCompanyId=" + CompanyId +
						"&order=" + GetDefaultOrder(ItemType, CompanyId) 
				}
			}
		else
			{
			if ((SearchString.toUpperCase().substr(0,2))!="L-")
               {			
			   SearchString = stringReplace(SearchString, "-", "..")
			   }
			 else
			   {
					if (SearchString.length > 2)
					{
                      ListLenght=SearchString.length					
					  ListString=SearchString.toUpperCase().substr(2,ListLenght)
					}
					else
					{
					  ListString=""
					}
			   SearchString = ""
			   }  
			pos = SearchString.indexOf(",")

			if (pos != -1)
				{
				StateString = stringReplace(Trim(SearchString.substring(0, pos)), " ", ",")
				postString = stringReplace(Trim(SearchString.substring(pos + 1, SearchString.length)), " ", "")
					
				pos = postString.indexOf(",")
					
				if (pos != -1)
					{
					CouponString = postString.substring(0, pos)
					postString = postString.substring(pos + 1, postString.length)
						
					pos = postString.indexOf(",")

					if (pos != -1)
						{
						MaturityString = postString.substring(0, pos)
						postString = postString.substring(pos + 1, postString.length)
							
						pos = postString.indexOf(",")
							
						if (pos != -1)
							{
							AmountString = postString.substring(0, pos)
							postString = postString.substring(pos + 1, postString.length)
							}
						else
							{
							if (postString.length != 0)
								AmountString = postString
							}
						}
					else
						{
						if (postString.length != 0)
							MaturityString = postString
						}
					}
				else
					{
					if (postString.length != 0)
						CouponString = postString
					}
				}
			else
				{
				if (SearchString.length != 0)
					StateString = stringReplace(SearchString, " ", ",")
				}
					
			if (StateString.length > 0)
				NewQuery += "&state=" + StateString
			if (CouponString.length > 0)
				NewQuery += "&coupon=" + CouponString
			if (MaturityString.length > 0)
				NewQuery += "&maturity=" + MaturityString
			if (AmountString.length > 0)
				NewQuery += "&lot=" + AmountString
			if (ListString.length > 0)
				NewQuery += "&account=" + ListString

			if (NewQuery.length == 0)
				{
				switch(ItemType)
					{
					case "A":
					break
					case "B":
					break
					
				case "I":	
				case "O":
					//if (Selected != 1)
					//	NewQuery = "&new_ind=on&stale_ind=on&lot=1..&coupon=0.."
					break
				}
			}

		Location="/common/display.asp" +
				"?CompanyId=" + GetCompanyType(ItemType, CompanyId) +					
				"&datatype=" + ItemType +				
				"&QuickSearch=" + escape(SearchString) +
				"&itemtype=" + ItemType 
		if (Selected == 1)
			NewQuery += "&selected=Y"

										
		if (NewQuery.length != 0)
			Location += "&NewQuery=" + escape(NewQuery)
		else
			Location += "&ForceBlankQuery=Y"

//			if (Selected == 1) 
//				Location += "&selected=Y"

		if (ItemType == 'M' || ItemType == 'P')
			{
			if (SearchString.length == 0)
				{
				CallAdvancedSearch(ThisForm, ItemType, CompanyId, IsLogin)			
				return
				}
					
			Location=Location +	"&floater='N'" + "&tradedate=" + CurrentMSRBDate
			}
			
		Location=Location + "&order=" + GetDefaultOrder(ItemType, CompanyId) 
		}
			
		if (CouponString.search("[^0-9.]") != -1)
			alert("Error: " + CouponString + " is not a valid Coupon Search string.")
	}
				

	CallPage(Location, IsLogin, CompanyId)
}
