var menu_sh = 0;
var m_popupid = 0;
//var men_sel = "2";
var more_men=1;
function tab_ser(obj){
	for(var i=1; i<=7; i++)	{
		if(obj==i){
			document.getElementById('tab'+i).className = "on";
		}
		else{
			document.getElementById('tab'+i).className= '';
		}
	}
	document.getElementById('topsearch_type').value=obj;
}

function menus(obj)
{
	if(m_popupid > 0)
 	{
 		if(m_popupid != men_sel)
 		{
			document.getElementById('menu'+m_popupid).className= '';	
			document.getElementById('submenu'+m_popupid).style.display = 'none';

		}
	}
	m_popupid = obj;
	document.getElementById('menu'+m_popupid).className= 'on';	
	document.getElementById('submenu'+men_sel).style.display = 'none';
	document.getElementById('submenu'+m_popupid).style.display = 'block';
	menu_sh = 1;	
}

function menus_out(obj)
{
	if(menu_sh == 0 && m_popupid > 0)
 	{
 		if(m_popupid != men_sel)
 		{			
			document.getElementById('menu'+men_sel).className = "on";
			document.getElementById('submenu'+men_sel).style.display = 'block';
		}
		document.getElementById('menu'+m_popupid).className= '';	
		document.getElementById('submenu'+m_popupid).style.display = 'none';
		if(m_popupid == men_sel)
		{
			document.getElementById('menu'+men_sel).className = "on";
			document.getElementById('submenu'+men_sel).style.display = 'block';
		}
		m_popupid = 0;
	}
}

function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
	
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

function search_post()
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var search_str = LTrim(RTrim(document.topsearch.search_str.value));
	var section = document.topsearch.cid.value;
	if(search_str == "Type Here")
	{
		alert("Search string cannot be blank!!!");
		document.topsearch.search_str.focus();
		return false;
	}
	
	if(search_str.length < 3)
	{
		alert("Please enter minimum 3 characters for search");
		document.topsearch.search_str.focus();
		return false;
	}
	

	var topsearch_type=document.topsearch.topsearch_type.value;
	if(topsearch_type==1)
		var ser_typ="Price";
	else if(topsearch_type==2)
		var ser_typ="MFs";
	else if(topsearch_type==3)
		var ser_typ="News";
	else if(topsearch_type==4)
		var ser_typ="Keyword";
	else if(topsearch_type==5)
		var ser_typ="Opinions";
	else if(topsearch_type==6)
		var ser_typ="Notices";
	else if(topsearch_type==7)
		var ser_typ="Videos";

	var search_val=document.topsearch.search_str.value;
		if(ser_typ == "News")
		{
			//document.topsearch.action = "/news/newssearch/newscat.php";
			document.topsearch.action = "/mccode/news/searchresult.php";
		}
		else if(ser_typ == "Price")
		{
            var sText=document.topsearch.search_str.value;
			sText=sText.toUpperCase();
			if(search_str.length <2)
			{
				Char = sText.charAt(0); 	 
				if (ValidChars.indexOf(Char) != -1) 
					document.topsearch.action ="http://www.moneycontrol.com/india/stockmarket/pricechartquote/"+Char;
			}
			else
				document.topsearch.action = "/stocks/cptmarket/compsearchnew.php?fname=price&companyname="+(document.topsearch.search_str.value).replace(/&/,"%26");
		}
		else if(ser_typ == "MFs")
		{
			var sText=document.topsearch.search_str.value;
			sText=sText.toUpperCase();
			if(search_str.length <2)
			{
				Char = sText.charAt(0); 	 
				if (ValidChars.indexOf(Char) != -1) 
					document.topsearch.action ="http://www.moneycontrol.com/india/mutualfunds/mutualfundsinfo/snapshot/"+Char;
				else
					document.topsearch.action = "/mf/mf_info/mfsearch.php?AMCname="+document.topsearch.search_str.value;
			}	
			else
				document.topsearch.action = "/mf/mf_info/mfsearch.php?AMCname="+document.topsearch.search_str.value;
		}
		else if(ser_typ == "Topic")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action = "/msgboard/viewmsg/find_topic.php";
		}
		else if(ser_typ == "Boarder")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action="/msgboard/viewmsg/find_boarders.php";
		}
		else if(ser_typ == "Stock")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action="/msgboard/viewmsg/find_topic_stock.php";
		}
		else if(ser_typ == "Keyword")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action="/india/messageboard/mmb_search_result.php?f_criteria=Keyword&f_Period=1&f_search="+document.topsearch.search_str.value;
		}
		else if(ser_typ == "Opinions")
		{
			document.topsearch.action = "/mccode/news/searchresult.php?expert=1";
		}

		else if(ser_typ == "Notices")
		{
			document.topsearch.action = "/stocks/cptmarket/compsearchnew.php?notice_q=1&fname=price&companyname="+(document.topsearch.search_str.value).replace(/&/,"%26");
		}

		else if(ser_typ == "Web")
		{
			document.topsearch.action = "/mccode/news/searchresult_archive.php?domains=www.moneycontrol.com&q=" + document.topsearch.search_str.value + "&client=ca-money_test_js&forid=1&channel=7271894659&ie=ISO-8859-1&oe=ISO-8859-1&flav=0000&cof=GALT%3A%230066CC%3BGL%3A1%3BDIV%3A%23999999%3BVLC%3A336633%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3AFF9900%3BALC%3A0066CC%3BLC%3A0066CC%3BT%3A000000%3BGFNT%3A666666%3BGIMP%3A666666%3BFORID%3A11&hl=en&x=38&y=9";
		}
		else if(ser_typ == "Videos")
		{
			document.topsearch.action = "http://www.moneycontrol.com/news/video/search_newsvideos.php?search_str=" + document.topsearch.search_str.value;
		}
}

function clopen_moremenu(action_val)
{
	if(action_val==1)
	{
		if(more_men==1)
		{
			document.getElementById('moremenu').style.display = 'block';
			more_men=0;
		}
		else
		{
			document.getElementById('moremenu').style.display = 'none';
			more_men=1;
		}
	}
	else if(action_val==2)
	{
		document.getElementById('moremenu').style.display = 'none';
		more_men=1;
	}
}
