////////////////  SENSEX Values:


function sensex_ajax_auto()
{

	if(!IE)
					var objXml = new XMLHttpRequest();
				else
					var objXml = new ActiveXObject("Microsoft.XMLHTTP");

					datafile = "/mccode/markets/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";
									//alert(currentcloseprice_bse);						
									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);
	
}
////////////////////// CNBC TV18-Matrix
matrix_plus="http://img1.moneycontrol.com/images/mc2008/markets/plus2.gif";
matrix_minus="http://img1.moneycontrol.com/images/mc2008/markets/minus2.gif";
function mycnbcmatrix(adserved)
{
	if(document.getElementById("martixclass").className=='matrixoff' || document.getElementById("martixclass").className=='matrixon_ad')
	{
			document.getElementById("martixclass").className='matrixon';
			$("#matrixplusminus").attr("src",matrix_minus);		
			
			if(adserved==1)
			document.getElementById("cnbcmatrixcontent").innerHTML="<div style='background:#fff;'><div><img src='http://img1.moneycontrol.com/images/mc2008/markets/top_cur_WT.gif'></div>		<div style='padding:0px; background:#fff;'><table cellpadding=0 cellspacing=0 border=0 width='100%' height='190px' style='background:#fff;'><tr><Td align=center valign=top><img src='http://img1.moneycontrol.com/images/markets_new_loader.gif' valing=center align=center></td></tr></table></div>			<div><img src='http://img1.moneycontrol.com/images/mc2008/markets/top_cur_WB.gif'></div></div>";

			document.getElementById("matrixdownimg").style.display="block";

			$('#cnbcmatrixcontent').load('/watchlist1/allpages_matrix_2008.php', '', function(data) 
				{
					
					if(adserved==1)
						document.getElementById("cnbcmatrixcontent").style.display="block";
					else
					$('#cnbcmatrixcontent').slideDown(500);
					

					next_prev('0', 'cookie');
				});		
	}
	else
	{
		
		$('#cnbcmatrixcontent').slideUp(500);
		$("#matrixplusminus").attr("src",matrix_plus);	
		document.getElementById("matrixdownimg").style.display="none";
		
		document.getElementById("martixclass").className='matrixoff';

		if(typeof(matrix_adunit_mktid) == 'undefined')
			matrix_adunit_mktid=0;

		if(typeof(matrix_adunit) != 'undefined' && matrix_adunit==1 && matrix_adunit_mktid==0)
		{
			setcookie('WATCH_INTER_COUNT','0',1);
			
		}
	}
}

///////

 function closefunction()
 {	
	mycnbcmatrix(1);
 }


function opencnbcmatrix(passmatrix)
{
	
	if(typeof(matrix_adunit) != 'undefined' && matrix_adunit==1 && getcookie('WATCH_INTER_COUNT')<1 && document.getElementById("martixclass").className=='matrixoff')
	{
				
				setcookie('WATCH_INTER_COUNT',watchlist_inter_count,1);
				document.getElementById("martixclass").className='matrixon_ad';
				$("#matrixplusminus").attr("src",matrix_minus);
				document.getElementById("matrixdownimg").style.display="block";

				document.getElementById("cnbcmatrixcontent").innerHTML=document.getElementById("watchadd").innerHTML;
				document.getElementById("cnbcmatrixcontent").style.display="block";
				//$('#cnbcmatrixcontent').slideDown(500);
		
	}
	else
	{
		//setcookie('WATCH_INTER_COUNT','0',1);
		mycnbcmatrix(0);
	}
}
////////

var watchlist_inter_count = getcookie('WATCH_INTER_COUNT')
if(watchlist_inter_count == null) {
watchlist_inter_count = 0;
}
else{
watchlist_inter_count++;
}

/////////// Cookie Funtions for Matrix
function getcookies(cookiename) 
{
	var cookiestring=document.cookie;
	var i=0;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="")
		return "";

	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1)
		index2=cookiestring.length;

	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
/////

function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}
//////
function getcookie(cookiename) 
{
	 var cookiestring=document.cookie;
	 var i=0;
	 var index1=cookiestring.indexOf(cookiename);
	 if (index1==-1 || cookiename=="") return ""; 
	 var index2=cookiestring.indexOf(';',index1);
	 if (index2==-1) index2=cookiestring.length; 
	 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
//////
function setcookie(name,value,duration)
{
	cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);	
	document.cookie=cookiestring;
	if(!getcookie(name))
		return false;
	else
		return true;
}
////###############

function chkvalsms()
{
mytmpobj=document.myformsms;

	tmpuser_phone=mytmpobj.phone 
	var tmpphone=tmpuser_phone.value;
	if(tmpuser_phone.value=="")
	{
	alert("Please Enter Your Mobile Number ");
	tmpuser_phone.focus();
	return false;
	}

	if(isNaN(tmpuser_phone.value)==true)
	{
	alert("Mobile number should be Numeric");
	tmpuser_phone.focus();
	return false;
	}


	if(tmpuser_phone.value.substring(0,1)!=9)
	{
		alert("Mobile number should start with 9");
		tmpuser_phone.focus();
		return false;
	}

	if(tmpuser_phone.value.length < 10)
	{
		alert("You should enter your 10 digits mobile number");
		tmpuser_phone.focus();
		return false;
	}

	


	setcookiesms('SMS_PRODUCT_MOBILE',tmpuser_phone.value,durationsms);	

}

///#########
var durationsms;
function setcookiesms(name,value,durationsms)
{
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(durationsms)+ "; path=/; domain=.moneycontrol.com; ";
	document.cookie=cookiestring;
}

/*function getexpirydate( nodays)
{
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}*/

//////////

function s_wl_refresh()
{
	if(typeof(matrix_adunit) != 'undefined' && matrix_adunit==1)
	{

		if(document.getElementById("martixclass").className=='matrixoff' || document.getElementById("martixclass").className=='matrixon_ad')
		{		
			sensex_ajax_auto();	
			if(typeof(sensex2refresh) != 'undefined' && sensex2refresh==1)
			{
				sensex_markets_auto();
			}
		}
		else
		{
			sensex_ajax_auto();
			if(typeof(sensex2refresh) != 'undefined' && sensex2refresh==1)
			{
				sensex_markets_auto();
			}
			next_prev(glob_next, glob_sec_toload);
		}
		
	}
	else
	{
	
		if(document.getElementById("martixclass").className=='matrixoff' || document.getElementById("martixclass").className=='matrixon_ad')
		{		
			sensex_ajax_auto();		
		}
		else
		{
			sensex_ajax_auto();
			next_prev(glob_next, glob_sec_toload);
		}
	}
	
}
