function toggle(div_id, sc_dspid) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) 
		{	
		//el.style.display = 'block';
				$.get("../sub_india/company_popup.php?sc_did="+sc_dspid, function(datadata)
					{
					//alert(datadata);
					$('#popUpDiv').html(datadata);
					el.style.display = 'block';
					//$('#popUpDiv').fadeOut(1000);
					});
					
					//el.style.display = 'block';
		}
	else {
		el.style.display = 'none';
		}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/2-150;//150 is half popup's height
	//popUpDiv.style.top = popUpDiv_height + 'px';
	popUpDiv.style.top = 100 + 'px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);

	//window_width=window_width/2-430;//150 is half popup's width
	remain_width=window_width-860;
	remain_width=remain_width/2;	
	popUpDiv.style.left = window_width + 'px';
	popUpDiv.style.left = remain_width + 'px';
	
}
function popup(windowname, scdid) {
	blanket_size(windowname);
	window_pos(windowname);
	toggle('blanket');
	toggle(windowname, scdid);		
} 
 
/////////////////////////

function post_screener()
{

var sel_criteria = document.getElementById("screen_crit").value;
	if(sel_criteria == "")
	{
		alert("Please select a criteria to screen companies on");
		document.getElementById("screen_crit").focus();
		return false;
	}

	if(sel_criteria == "marketcap" || sel_criteria == "netsales" || sel_criteria == "netprofit" || sel_criteria == "totassets")
	{
		var sel_sector = document.getElementById("ind_sel").value;
		document.getElementById("mktinfo_scr_frm").action = "http://www.moneycontrol.com/stocks/marketinfo/"+sel_criteria+".php?indcode="+sel_sector+"&optex=BSE";		
		document.getElementById("optex").value = "BSE";

	}
	else if(sel_criteria == "qtrgrowth")
	{
		sector = document.getElementById("ind_code").value;
		document.getElementById("mktinfo_scr_frm").action = "http://www.moneycontrol.com/stocks/marketinfo/"+sel_criteria+"/index.php?indcode="+sector+"&call_option=N";		
		document.getElementById("call_option").value = "N";
	}
	else
	{
		sector = document.getElementById("ind_code").value;
		document.getElementById("mktinfo_scr_frm").action = "http://www.moneycontrol.com/stocks/marketinfo/"+sel_criteria+"/bse/index.php?indcode="+sector;		
	}

	document.getElementById("mktinfo_scr_frm").submit();
	return false;
}
/////////

function graph_nse_bse(pasid, exchn)
{
	
	if(exchn==2)
		{		
		document.getElementById("b_n_graph").innerHTML="<iframe id='bsensegraph' name='bsensegraph' src='http://www.moneycontrol.com/mcplus/portfolio/line_intraday_bsense.php?sc_id="+pasid+"&sc_ex=N' framespacing='0' frameborder='no' scrolling='no' width='199px' height='128px' allowtransparency='true'></iframe>";		
		}
	else 
		{
		document.getElementById("b_n_graph").innerHTML="<iframe id='bsensegraph' name='bsensegraph' src='http://www.moneycontrol.com/mcplus/portfolio/line_intraday_bsense.php?sc_id="+pasid+"&sc_ex=B' framespacing='0' frameborder='no' scrolling='no' width='199px' height='128px' allowtransparency='true'></iframe>";
		}
}
