//// Top Stocks
function stock_search_frm_top()
{	
	var search_stk_top = LTrim(RTrim(document.stock_search_top.search_stk_top.value));
	
	
	if(search_stk_top.length < 3)
	{
		alert("Please enter minimum 3 character for search");
		return false;
	}

	document.stock_search_top.action = "http://www.moneycontrol.com/stocks/cptmarket/compsearchnew.php?fname=price&companyname="+(document.stock_search_top.search_stk_top.value).replace(/&/,"%26");
	return true;
}

function stock_search_frm_top1()
{	
	var search_stk_top1 = LTrim(RTrim(document.stock_search_top1.search_stk_top1.value));
	
	
	if(search_stk_top1.length < 3)
	{
		alert("Please enter minimum 3 character for search");
		return false;
	}

	document.stock_search_top1.action = "http://www.moneycontrol.com/stocks/cptmarket/compsearchnew.php?fname=price&companyname="+(document.stock_search_top1.search_stk_top1.value).replace(/&/,"%26");
	return true;
}

function post_search_18()
 {
 	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 	var search_str = LTrim(RTrim(document.topsearch_18.search_str.value));
 	var section = document.topsearch_18.cid.value;
 	for(x=0;x<document.topsearch_18.search_cat.length;x++)
 	{
 		if(document.topsearch_18.search_cat[x].checked==true)
 		{
 			var search_cat=document.topsearch_18.search_cat[x].value;
 			break;
 		}
 	}
 	if(search_cat=="News" || search_cat=="Keyword")
 	{
 		if(search_str.length < 3)
 		{
 			alert("Please enter minimum 3 characters for search");
 			return false;
 		}
 	}
 	else
 	{
 		if(search_str.length < 1)
 		{
 			alert("Please enter minimum 1 character for search");
 			return false;
 		}
 	}
 	
 	if(search_cat=="")
 	{
 		
 		switch (section)
 		{
 			case "3": // News
 			{
 				document.topsearch_18.action = "http://www.moneycontrol.com/mccode/news/searchresult.php";
 				break;
 			}
 			case "0": //Markets
 			{
 				document.topsearch_18.action = "http://www.moneycontrol.com/stocks/cptmarket/compsearchnew.php?fname=price&companyname="+(document.topsearch_18.search_str.value).replace(/&/,"%26");
 				break;
 			}
 			case "7": //MMB
 			{
 				document.topsearch_18.action = "http://www.moneycontrol.com/india/messageboard/mmb_search_result.php?f_criteria=Topic&f_Period=4&f_search="+document.topsearch_18.search_str.value;
 				break;
 			}
 			case "2": //MF
 			{
 				document.topsearch_18.action = "http://www.moneycontrol.com/mf/mf_info/mfsearch.php?AMCname="+document.topsearch_18.search_str.value;
 				break;
 			}
 			default:
 			{
 				//document.topsearch_18.action = "/news/newssearch/newscat.php";
 				document.topsearch_18.action = "http://www.moneycontrol.com/stocks/cptmarket/compsearchnew.php?fname=price&companyname="+(document.topsearch_18.search_str.value).replace(/&/,"%26");
 				break;
 			}
 		}
 	}
 	else
 	{
 		var search_val=document.topsearch_18.search_str.value;
 		if(search_cat == "News") 		{
 			
 			document.topsearch_18.action = "http://www.moneycontrol.com/mccode/news/searchresult.php";
 		} 				
 		else if(search_cat == "Keyword")
 		{
 			document.topsearch_18.mbsearch_str.value = search_val;
 			document.topsearch_18.action="http://www.moneycontrol.com/india/messageboard/mmb_search_result.php?f_criteria=Keyword&f_Period=1&f_search="+document.topsearch_18.search_str.value;
 		} 
 		else if(search_cat == "Web")
 		{
 			document.topsearch_18.action = "http://www.moneycontrol.com/mccode/news/searchresult_archive.php?domains=www.moneycontrol.com&q=" + document.topsearch_18.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";
 		} 		
 		return true;
 	}
 }
 // Removes leading whitespaces
 function LTrim( value ) {
 	
 	var re = /\s*((\S+\s*)*)/;
 	return value.replace(re, "$1");
 	
 }
 
 // Removes ending whitespaces
 function RTrim( value ) {
 	
 	var re = /((\s*\S+)*)\s*/;
 	return value.replace(re, "$1");
 	
 }

function ctab(num,dname,bname,ls)
{
	for(var i=1; i<=ls; i++)
	{
		if(num==i){
			
		  document.getElementById(bname+i).style.display = 'block';
		   document.getElementById(dname+i).className = "grtabon";		   
		}
		else{
			document.getElementById(bname+i).style.display = 'none';
			document.getElementById(dname+i).className = "grtaboff";
		}
		
	}
}

function validate_mp_poll_1()
{
	
	// set var radio_choice to false
	var radio_choice = false;

	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < document.form_mp_poll_1.radio_mp_poll.length; counter++)
	{
	// If a radio button has been selected it will return true
	// (If not it will return false)
	if (document.form_mp_poll_1.radio_mp_poll[counter].checked)
		{
			radio_choice = true; 
			var check_var=counter+1;
		}	
	}

	if (!radio_choice)
	{
		// If there were no selections made display an alert box 
		alert("Please select a option.")
		return (false);
	}	
	
	if(check_var==1)
		pass_val="opt1";
	if(check_var==2)
		pass_val="opt2";
	if(check_var==3)
		pass_val="opt3";

	pollid=document.getElementById('pollid').value;

	window.open('http://www.moneycontrol.com/india/messageboard/marketpulse/poll_inter.php?op=poll&poll_id='+pollid+'&radio_mp_poll='+pass_val,'Polldetails'); 	

	return false;
	
}

function valid_sen()
{

	var str = document.form_sensex.sen_val.value;
	var dec = document.form_sensex.sen_valdec.value;
	if(str=="" && dec == "")
	{
		alert("Please enter the value");
		return false;
	}
	else
	{	
		if(!isNaN(str)==true)
		{
			strval=document.form_sensex.sen_val.value;
			strval_dec=document.form_sensex.sen_valdec.value;
			
			actionname="http://www.moneycontrol.com/sensexchallenge/upvalue.php?str=" + strval + "&str_dec=" + strval_dec;
			document.form_sensex.action=actionname;
			document.form_sensex.submit();
			return true;
			
		}else
		{
			alert("Please enter only numbers");
			document.form_sensex.sen_val.value="";
			return false;
		}return false;
	}	
}


function clickclear(thisfield, defaulttext) 
{
	if (thisfield.value == defaulttext) 
	{
		thisfield.value = "";
		return false;
	}
}

function clickrecall(thisfield, defaulttext) 
{	
	if (thisfield.value == "") 
	{
		thisfield.value = defaulttext;
		return false;
	}
}

function sensex_ajax_auto30()
{
	var IE = document.all?true:false;	
	if(!IE)
		var objXml = new XMLHttpRequest();
	else
		var objXml = new ActiveXObject("Microsoft.XMLHTTP");

		datafile = "/stocksprices/sensex_ajax.php";


	objXml.open("GET", datafile, true);
	objXml.setRequestHeader("Cache-Control","no-cache"); 

	objXml.onreadystatechange=function() 
		{
			if (objXml.readyState==4) 
			{
			if (objXml.status!=404)
				{	
				   if((objXml.responseText).length > 0)
					{
						data=objXml.responseText;

						var broken_value=data.split("|");
						
						var currentcloseprice_nse=broken_value[0];
						var change_nse=broken_value[1];

						var currentcloseprice_bse=broken_value[2];
						var change_bse=broken_value[3];


						if(change_bse > 0)
							var img_arr_bse = "http://img1.moneycontrol.com/images/mc2008/markets/uparrow.gif";
						else
							var img_arr_bse = "http://img1.moneycontrol.com/images/mc2008/markets/dwn_arrowred.gif";
						if(change_nse > 0)
							var img_arr_nse = "http://img1.moneycontrol.com/images/mc2008/markets/uparrow.gif";
						else
							var img_arr_nse = "http://img1.moneycontrol.com/images/mc2008/markets/dwn_arrowred.gif";
											
						document.getElementById("sensex_val_top").innerHTML=currentcloseprice_bse;
						document.getElementById("sensex_change").innerHTML=change_bse;
						document.getElementById("nifty_val_top").innerHTML=currentcloseprice_nse;
						document.getElementById("nifty_change").innerHTML=change_nse;
						document.getElementById("bse_img_top").src=img_arr_bse;
						document.getElementById("nse_img_top").src=img_arr_nse;
						
					}
				}
			
			}
		}
	objXml.send(null);
	
}

function ref_flash()
{
	$("#flash_element").slideUp(200);
	
	$('#flash_element').html("<div style='background-color:#FFFFFF;'><div style='margin:150px 100px 15px 100px;background-color:#FFFFFF;'><img src='http://img1.moneycontrol.com/images/markets_new_loader.gif' ></div></div>");
 
	$('#flash_element').load('/budget2009/flashes.html', '', function(data) 
	{	
		$("#flash_element").slideDown(800);		
	});
} 

function ref_impact()
{
	$("#impact_anal").slideUp(500);
	
	$('#impact_anal').html("<div style='margin:150px 100px 15px 100px;'><img src='http://img1.moneycontrol.com/images/markets_new_loader.gif' ></div>");
 
	$('#impact_anal').load('/budget2009/impact_analysis.html', '', function(data) 
	{	
		$("#impact_anal").slideDown(1000);		
	});
}

function hotstockstab(sttab)
{
	var htmlfiles = new Array("", "HS_TopGainers.html", "HS_TopLosers.html", "HS_TopVolume.html", "HS_BlockDeals.html", "HS_OnlyBuyers.html", "HS_OnlySellers.html", "HS_52wkHighs.html", "HS_52wkLows.html", "HS_HourlyGainers.html", "HS_HourlyLosers.html", "HS_VolumeShockers.html");

	for(tabcnt=1; tabcnt<=11; tabcnt++)
	{
		if(sttab==tabcnt)
			document.getElementById("hotstocks_"+tabcnt).className='on';			
		else
			document.getElementById("hotstocks_"+tabcnt).className='';
	}	

	$('#hotstockdatadiv').fadeOut(1);
	$('#hotstockdatadiv').html("<div style='margin:150px 100px 15px 100px;'><img src='http://img1.moneycontrol.com/images/markets_new_loader.gif' ></div>");

	//urchinTracker("/budget2009/stats/"+htmlfiles[sttab]);

	$('#hotstockdatadiv').load('/budget2009/stats/'+htmlfiles[sttab], '', function(data) 
		{					
			$('#hotstockdatadiv').fadeIn(1000);
		});
}

function secindicestab(sttab)
{
	var htmlfiles = new Array("", "SI_Auto.html", "SI_Bankex.html", "SI_CGoods.html", "SI_CDurables.html", "SI_FMCG.html", "SI_Healthcare.html", "SI_IT.html", "SI_Metal.html", "SI_OilGas.html", "SI_PSU.html");

	for(tabcnt=1; tabcnt<=10; tabcnt++)
	{
		if(sttab==tabcnt)
			document.getElementById("sectorindice_"+tabcnt).className='on';			
		else
			document.getElementById("sectorindice_"+tabcnt).className='';
	}	

	$('#sectorindicesdatadiv').fadeOut(1);

	$('#sectorindicesdatadiv').html("<div style='margin:150px 100px 15px 100px;'><img src='http://img1.moneycontrol.com/images/markets_new_loader.gif' ></div>");

	//urchinTracker("/budget2009/stats/"+htmlfiles[sttab]);

	$('#sectorindicesdatadiv').load('/budget2009/stats/'+htmlfiles[sttab], '', function(data) 
		{					
			$('#sectorindicesdatadiv').fadeIn(1000);
		});
}


function validate_mp_poll_2()
{	
	// set var radio_choice to false
	var radio_choice = false;

	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < document.form_mp_poll_2.radio_mp_poll1.length; counter++)
	{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (document.form_mp_poll_2.radio_mp_poll1[counter].checked)
		{
			radio_choice = true; 
			var check_var=counter+1;
		}
	}

	if (!radio_choice)
	{
		// If there were no selections made display an alert box 
		alert("Please select a option.")
		return (false);
	}
	
	if(check_var==1)
		pass_val="opt1";
	if(check_var==2)
		pass_val="opt2";
	if(check_var==3)
		pass_val="opt3";
	if(check_var==4)
		pass_val="opt4";

	pollid=document.getElementById('pollid').value;

	window.open('http://www.moneycontrol.com/india/messageboard/marketpulse/poll_inter.php?op=poll&poll_id='+pollid+'&radio_mp_poll='+pass_val,'Polldetails'); 
	return false;	
}

function validate_mp_poll_1()
{
	//alert("this");
	var radio_choice = false;
	for (counter = 0; counter < document.form_mp_poll_1.radio_mp_poll.length; counter++)
	{
	if (document.form_mp_poll_1.radio_mp_poll[counter].checked)
		{
			radio_choice = true; 
			var check_var=counter+1;
		}
	}

	if (!radio_choice)
	{
	alert("Please select a option.")
	return (false);
	}
	if(check_var==1)
		pass_val="opt1";
	if(check_var==2)
		pass_val="opt2";
	if(check_var==3)
		pass_val="opt3";

	pollid=document.getElementById('pollid').value;	window.open('http://www.moneycontrol.com/india/messageboard/marketpulse/poll_inter.php?op=poll&poll_id='+pollid+'&radio_mp_poll='+pass_val,'Polldetails'); 
	return false;
	
}