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 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 = "http://www.moneycontrol.com/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 = "http://www.moneycontrol.com/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 = "http://www.moneycontrol.com/mf/mf_info/mfsearch.php?AMCname="+document.topsearch.search_str.value;
			}	
			else
				document.topsearch.action = "http://www.moneycontrol.com/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 = "http://www.moneycontrol.com/msgboard/viewmsg/find_topic.php";
		}
		else if(ser_typ == "Boarder")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action="http://www.moneycontrol.com/msgboard/viewmsg/find_boarders.php";
		}
		else if(ser_typ == "Stock")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action="http://www.moneycontrol.com/msgboard/viewmsg/find_topic_stock.php";
		}
		else if(ser_typ == "Keyword")
		{
			document.topsearch.mbsearch_str.value = search_val;
			document.topsearch.action="http://www.moneycontrol.com/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 = "http://www.moneycontrol.com/mccode/news/searchresult.php?expert=1";
		}

		else if(ser_typ == "Notices")
		{
			document.topsearch.action = "http://www.moneycontrol.com/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 readCookie(name) {
     var nameEQ = name + "=";
     var ca = document.cookie.split(';');
     for(var i=0;i < ca.length;i++) {
         var c = ca[i];
         while (c.charAt(0)==' ') c = c.substring(1,c.length);
         if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
     }
     return false;
 }
 
 if(readCookie('nnmc'))
 {
 	var user_status="<a href='http://www.moneycontrol.com/mcplus/portfolio/logout.php?ref=http://www.moneycontrol.com/mcplus/portfolio/loginportfolio.php' class='bl-12-u'><B>Sign Out</B></a>&nbsp;";			
 }
 else
 {
 	var user_status=" <a href='http://www.moneycontrol.com/india/bestportfoliomanager/stocks/mutualfunds/loginportfolio' class='bl-12-u'><b>Sign in</b></a>&nbsp;/&nbsp;<a href='http://www.moneycontrol.com/registration/commonregistration.php' class='bl-12-u'><b>Register</b></a>&nbsp;";
 }