v=11;

if (navigator.userAgent.indexOf('Mozilla/3') != -1) {
     v=10;
}

var a='http://ads.rediff.com/RealMedia/ads/';
var RN = new String (Math.random());
var RNS = RN.substring (2, 11);
function da(width, height, posn) {
     var p='www.rediff.com/money-general.htm/1' + RNS + '@' + posn;
     if(v < 11) {
          document.write('<A HREF=' + a + 'click_nx.ads/' + p + '><IMG SRC=' + a + 'adsTReam_nx.ads/' + p + ' BORDER=0 WIDTH=' + width + ' HEIGHT= ' + height + ' VSPACE=0 HSPACE=0><\/A>');
     } else {
          document.write('<SCRIPT LANGUAGE=JavaScript1.1 SRC=' + a + 'adsTReam_jx.ads/' + p + '><\/SCRIPT>');
     }
}

function pop(file,Iwidth,Iheight){
  var newWin1=window.open(file,'nWin','x=0,y=0,toolbar=no,location=no,directories=no,status=no,scrollbars=no, copyhistory=no,width='+Iwidth+',height='+Iheight+',screenX=0,screenY=0,left=20,top=20');
}

function header_menu(){
    var rediff_url="http://www.rediff.com";
	document.write("<TABLE bgcolor=\"ffffff\"  CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"0\">");
	document.write("	<TR>");
	document.write("		 <TD WIDTH=\"160\">");
	document.write("			  <A HREF=\"http://money.rediff.com/\"><IMG SRC=\"http://im.rediff.com/uim/news/moneywiz.gif\" WIDTH=\"153\" HEIGHT=\"23\" BORDER=\"0\" HSPACE=\"0\" VSPACE=\"0\" Title=\"Rediff Moneywiz\"/></a>");
	document.write("		 </TD>");
	document.write("                        <TD WIDTH=\"80%\" HEIGHT=\"16\" >");
    document.write("                                      <FONT CLASS=\"fv10\">");
    document.write("                                                            <A HREF=\"http://www.rediff.com/\">Rediff Home</A> | <A HREF=\"http://www.rediff.com/money/\">Business</A>");
    document.write("                        <span id=hp style=\"behavior:url(#default#homepage)\"></span>");
    if (navigator.userAgent.indexOf("MSIE")!=-1){
		var thePage = window.location.href;
		var theText='Make this your homepage';
	    document.write(" | <a  class=srchlink href=\"#\" onclick=\"style.behavior='url(#default#homepage)';setHomePage('"+thePage+"');window.location.href=window.location.href;return false;\">"+theText+"</a>");
	}
	document.write("			  </FONT>");
	document.write("		 </TD>");
	document.write("	</TR></table><table CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"0\">");
	document.write("	<TR>");
	document.write("		 <TD HEIGHT=\"25\">");
	document.write('<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD BGCOLOR=#1E2A64 WIDTH=65 ALIGN=CENTER><A HREF=http://money.rediff.com/><FONT CLASS=ft11 COLOR=#FFFFFF><B>Markets</B></FONT></A></TD><TD WIDTH=2></TD><TD CLASS=toptabs width=120 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF="\http://moneygame.rediff.com/"\>Share Bazaar Game</A></B></FONT></TD><TD WIDTH=2></TD> <TD CLASS=toptabs WIDTH=107 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/tools/what-if>Investment Tool</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=47 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/tools/forex>Forex</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=55 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/indices>Indices</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=60 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/sectors>Sectors</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=85 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/mutual-funds>Mutual Funds</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=88 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/indicators>Global Trends</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=72 ALIGN=CENTER HEIGHT=25><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/tips>Stock Tips</A></B></FONT></TD><TD WIDTH=2></TD><TD CLASS=toptabs WIDTH=66 ALIGN=CENTER><FONT CLASS=ft11><B><A HREF=http://money.rediff.com/directory>Directory</A></B></FONT></TD></TR></TABLE>');
	document.write("		 </TD>");
	document.write("	</TR>");
	document.write("	<TR>");
	document.write("		 <TD COLSPAN=\"2\" BGCOLOR=\"#1E2A64\" HEIGHT=\"8\"></TD>");
	document.write("	</TR>");
	document.write("</TABLE>");
}

function closeLinks()
{
	document.getElementById('linkspopup').style.display="none";
}
function openLinks()
{
	document.getElementById('linkspopup').style.display="block";
	
}
function bread_crumbs(page_link, page_type){ //alert(page_link);
	var thePage = window.location.href;
	document.write("<TABLE WIDTH=\"100%\" CELLSPACING=\"0\" CELLPADDING=\"0\" BORDER=\"0\">");
	document.write("	<TR>");
	document.write("		 <TD WIDTH=\"0.1%\" BGCOLOR=\"#B7B7B7\"></TD>");
	document.write("		 <TD WIDTH=\"1.8%\"></TD>");
	document.write("		 <TD height=\"35\">");
	document.write("			  <FONT class=\"f12\">You are here:");

    if(page_link =='Markets'){
	document.write("					<A HREF=\"http://www.rediff.com/money/index.html\">");
	document.write("						 <U>Business</U></A>");
        document.write("					<FONT SIZE=\"2\" FACE=\"Arial\"> &#187; </FONT>");
	    document.write("						 Markets Home");
   }else{

	    document.write("					<A HREF=\"http://money.rediff.com/\">");
	    document.write("						 <U>Markets Home</U></A>");
	}
	if(page_type != '')
    if(page_type == 'Company' || page_type == 'Mutual Fund' || page_type == 'MfSearch' || page_type == 'Markets'){
            document.write("					<FONT SIZE=\"2\" FACE=\"Arial\"> &#187; </FONT>");
            document.write("					"+unescape(page_link));
    }else{
            document.write("					<FONT SIZE=\"2\" FACE=\"Arial\"> &#187; </FONT>");
            document.write("					"+unescape(page_link));
            document.write("					<FONT SIZE=\"2\" FACE=\"Arial\"> &#187; </FONT>");
           document.write("					"+page_type);
    }
	document.write("			  </FONT>");
	document.write("			  <BR/>");
	document.write("		 </TD>");
	document.write("		 <TD width=\"20%\" align=\"right\">");
	if(page_link !='My Portfolio'){
	document.write("			  <FONT CLASS=\"fv10\">");
	var urlval = "http://www.rediff.com/money/feedback.html?u="+document.URL;
	document.write("					<a href=\""+thePage+"\" title=\"Update Now\"><span class=\"iconUpdate\">&#160;&#160;&#160;</span><U>Update&nbsp;Now!</U></a>&nbsp;|&nbsp;<a href=\'javascript:pop(\""+urlval+"\",\"550\",\"550\")\'><b>Feedback</b></A>   ");
	document.write("         </FONT>");
	}
	document.write("		</TD>");
	document.write("	</TR>");
	document.write("</TABLE>");
}

// cookie changes
var rbtval = getCookie('RBT');
if ((rbtval))   {
	var rbtpos =rbtval.indexOf('money');
	if(rbtpos < 0 ) {
		var newval = rbtval + ',' + 'money'
		setCookie('RBT',newval,'45');
	}
} else  {
	setCookie('RBT','money','45');
}

function getCookie(name){
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1){
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	}else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
			
function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
		expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
        + ";expires="+expire.toGMTString()+ ";domain=.rediff.com;path=/;";
}

var bt_array = {"service":"moneywiz","category":"Gc"};
document.write("<SCRIPT LANGUAGE=\"JavaScript\" TYPE=\"text/javascript\" SRC=\"http://im.rediff.com/uim/common/bt.js\"><\/SCRIPT>");

//chart.js

function write_chart(xml_url,parameters, width, height){
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH='+width+' HEIGHT='+height+' id="FusionCharts_1">');
    document.write('<PARAM NAME="movie" VALUE="http://money.rediff.com/money1/images/FC_2_3_Area2D.swf">');
    document.write('<PARAM NAME="FlashVars" VALUE="&dataURL='+xml_url+'?companyCode='+parameters+'&chartWidth='+width+'&chartHeight='+height+'">');
    document.write('<PARAM NAME="quality" VALUE="high">');
    document.write('<PARAM NAME="bgcolor" VALUE="#FFFFFF">');
    document.write('<EMBED src="http://money.rediff.com/money1/images/FC_2_3_Area2D.swf" FlashVars="&dataURL='+xml_url+'?companyCode='+parameters+'&chartWidth='+width+'&chartHeight='+height+'" quality="high" bgcolor="#FFFFFF"  WIDTH='+width+' HEIGHT='+height+' NAME="FusionCharts_1" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
    document.write('</OBJECT>');
}

function write_chart_compare(xml_url,parameters, width, height){
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH='+width+' HEIGHT='+height+' id="FusionCharts_1">');
    document.write('<PARAM NAME="movie" VALUE="http://money.rediff.com/money1/images/FC_2_3_MSLine.swf">');
    document.write('<PARAM NAME="FlashVars" VALUE="&dataURL='+xml_url+'?companyCode='+parameters+'&chartWidth='+width+'&chartHeight='+height+'">');
    document.write('<PARAM NAME="quality" VALUE="high">');
    document.write('<PARAM NAME="bgcolor" VALUE="#FFFFFF">');
    document.write('<EMBED src="http://money.rediff.com/money1/images/FC_2_3_MSLine.swf" FlashVars="&dataURL='+xml_url+'?companyCode='+parameters+'&chartWidth='+width+'&chartHeight='+height+'" quality="high" bgcolor="#FFFFFF"  WIDTH='+width+' HEIGHT='+height+' NAME="FusionCharts_1" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
    document.write('</OBJECT>');
}

//market_popup.js

var tempid = '';
var alertmaxprice ='';
var alertminprice ='';
function getPage(pageLocation){
    window.location = pageLocation;
}
function addPortfolio(companycode){
    getPage("http://portfolio.rediff.com/money/jsp/add_portfolio.jsp?companyCode="+companycode+"&equity=yes");
}

function opendropdown(id){
		closedropdown('addPortfolio');
		closedropdown('simpleSearch');
		closedropdown('advanceSearch');
        document.getElementById(id).style.display="block";
}
function closedropdown(id){
	if(document.getElementById(id))
	    document.getElementById(id).style.display="none";
}
function showAddPopup(companyId){
    tempid = companyId;
    if(document.all){
        document.getElementById("addportfoliopopup").style.display="block";
    }else{
        document.getElementById("addportfoliopopup").style.display="block";
    }
}
function closeAddPopup(){
    document.forms["add_pf_co"].reset();
    document.getElementById("addportfoliopopup").style.display="none";
}
function  doAddPortfolioSubmit(){

    var message="Please fill up carefully with following details \n\n";
    var x=0;
    var check=checkQuantity(document.add_pf_co.quantity);
        if(check==false){
            message=message+" * Please enter only integer values for Quantity.\n\n";
            x=1;
        }
        var check1=checkCost(document.add_pf_co.price);
            if(check1==false){
            message=message+" * Please enter numeral values for Cost. \n\n";
            x=1;
        }
    if(document.add_pf_co.date.value==''){
        message=message+" * Date shouldn't be blank";
        x=1;
    }else{
        var date = document.add_pf_co.date.value;
       var currentDate = new Date();
       var y = date.split("/");
       var tempdate =  y[1]+"/"+y[0]+"/"+y[2];
       dt = new Date(tempdate);
       if(dt > currentDate) {
            message=message+" * You cannot select future date.";
            x=1;
        }
    }
    if (x==1) {
        alert(message);
        return false;
    }else{
    submitPortfolioForm();
    }
}
function xshowAddPopup(companyId){
    if(tempid != '')
       xcloseAddPopup();
	tempid = companyId;
    document.getElementById(tempid).className="moneypopup";
    document.getElementById(tempid).innerHTML =  document.getElementById("addportfoliopopup").innerHTML ;
    document.getElementById("addportfoliopopup").innerHTML ="";
    document.getElementById(tempid).style.display="block";
}
function xcloseAddPopup(){
	resetDiv('co');
	document.getElementById("addportfoliopopup").innerHTML =   document.getElementById(tempid).innerHTML;
    document.getElementById(tempid).style.display="none";
    document.getElementById(tempid).innerHTML =  "";
    tempid='';
}

function showPDiv(id){
	if(id == 'portfolio'){
		document.getElementById('plink').style.display="none";
		document.getElementById('ppage').style.display="block";
		document.getElementById('swpage').style.display="none";
	}else if(id == 'sw'){
		document.getElementById('ppage').style.display="none";
		document.getElementById('plink').style.display="none";
		document.getElementById('swpage').style.display="block";
	}else if(id == 'sportfolio'){
		document.getElementById('slink').style.display="none";
		document.getElementById('spage').style.display="block";
		document.getElementById('sswpage').style.display="none";
	}else if(id == 'ssw'){
		document.getElementById('spage').style.display="none";
		document.getElementById('slink').style.display="none";
		document.getElementById('sswpage').style.display="block";
	}
}

function resetDiv(id){
	
	if (id == 'co'){
		document.getElementById('ppage').style.display="none";
		document.getElementById('plink').style.display="block";
		document.getElementById('swpage').style.display="none";	
	}else if (id == 'mf'){
		document.getElementById('spage').style.display="none";
		document.getElementById('slink').style.display="block";
		document.getElementById('sswpage').style.display="none";	
	}
}


var tempDateId ='';
var mftempDateId ='';
function dateClk(formId){
	document.domain="rediff.com";
    if(formId == 'mf'){

        tempDateId = 'mf';
        show_calendar('mf_add_form.date');
    }else{
        tempDateId = 'cm';
        show_calendar('add_pf_co.date');
    }
}
function setDate(dt, dateObj){
    if(tempDateId == 'cm')
        document.add_pf_co.date.value=dt;
    else
        document.mf_add_pf_co.date.value=dt;
}
function mfdateClk(formId){
    if(formId == 'mf'){
        tempDateId = 'mf';
        show_calendar('mf_add_form.date');
    }else{
        tempDateId = 'cm';
        show_calendar('add_pf_co.date');
    }
}
function mfsetDate(dt, dateObj){
    if(tempDateId == 'cm')
        document.add_pf_co.date.value=dt;
    else
        document.mf_add_pf_co.date.value=dt;
}
function submitPortfolioForm(){
    var cmprice=document.add_pf_co.price.value;
    var cmquantity=document.add_pf_co.quantity.value;
    var cmdate=document.add_pf_co.date.value;
    document.forms["add_pf_co"].code.value =  tempid;
    document.forms["add_pf_co"].flag.value =  'cm';
    document.forms["add_pf_co"].transDetails.value='cm|'+tempid+'|'+cmprice+'|'+cmquantity+'|'+cmdate;
    document.add_pf_co.method = "post";
	document.add_pf_co.target = "_parent";
    document.add_pf_co.action = "http://portfolio.rediff.com/money/jsp/select_portfolio.jsp";
    document.add_pf_co.submit();

}

function checkQuantity(fieldName){
    var strValue=fieldName.value;
    var cnt
    if(strValue.length==0){
        return false;
    }else{
        for(cnt=0;cnt<strValue.length; cnt++){
            if(!(strValue.charAt(cnt)>='0' && strValue.charAt(cnt) <='9')) {
                return false
            }
        }
    }
    return true
}

function checkCost(fieldName){
    var strValue=fieldName.value;
    var cnt
    if(strValue.length==0){
        return false;
    }else if(strValue.charAt(0)=='.'){
        return false;
    }else{
        for(cnt=0;cnt<strValue.length; cnt++){
            if(!(strValue.charAt(cnt)>='0' && strValue.charAt(cnt) <='9') && strValue.charAt(cnt)!='(' && strValue.charAt(cnt)!=')' && strValue.charAt(cnt)!='.' && strValue.charAt(cnt)!='') {
                return false
            }
        }
    }
    return true
}

function  mfdoAddPortfolioSubmit(code){

    var message="Please fill up carefully with following details \n\n";
             var x=0;
             var check=mfcheckQuantity(document.mf_add_form.quantity);
			 if(check==false){
					message=message+" * Please enter valid values for Quantity.\n\n";
					x=1;
			}
			var check1=mfcheckCost(document.mf_add_form.price);
			 if(check1==false){
					message=message+" * Please enter numeral values for Cost. \n\n";
					x=1;
			}
			if(document.mf_add_form.date.value==''){
				message=message+" * Date shouldn't be blank";
					x=1;
			}
			if(document.mf_add_form.date.value!=''){
			   var date = document.mf_add_form.date.value;
			    var currentDate = new Date();
			    var y = date.split("/");
			    var tempdate =  y[1]+"/"+y[0]+"/"+y[2];
			    dt = new Date(tempdate);
			    if(dt > currentDate) {
			        message=message+" * You cannot select future date.";
			        x=1;
			    }
			}
			if (x==1) {
				alert(message);
            	return false;
            }else{
				mfsubmitPortfolioForm(code);
			}
   }

function mfcheckQuantity(fieldName){
    var strValue=fieldName.value;
    var cnt
    var len = strValue.length;
    if(len==0){
        return false;
    }else{
         if(len == 1){
		    if(strValue.charAt(0)=='0' || strValue.charAt(0)=='.')
			    return false;
	    }else if(len == 2){
		    if(strValue.charAt(1)=='.' )
		        return false;
		    else{
		       if(strValue.charAt(0)=='.' && strValue.charAt(1)=='0')
		        return false;
		    }
	}else{
	    if(len == 3)
		    if(strValue.charAt(0)=='0' && strValue.charAt(1)=='.' && strValue.charAt(2)=='0')
		        return false;
        for(cnt=0;cnt<len; cnt++){
            if(!((strValue.charAt(cnt)>='0' && strValue.charAt(cnt) <='9')||(strValue.charAt(cnt)=='.'))) {
                return false
                }
          }
      }
    return true
    }
}

function mfcheckCost(fieldName){
    var strValue=fieldName.value;
    var cnt
    if(strValue.length==0){

    return false;
    }else if(strValue.charAt(0)=='.'){
        return false;
    }else{
    for(cnt=0;cnt<strValue.length; cnt++){
    if(!(strValue.charAt(cnt)>='0' && strValue.charAt(cnt) <='9') && strValue.charAt(cnt)!='(' && strValue.charAt(cnt)!=')' && strValue.charAt(cnt)!='.' && strValue.charAt(cnt)!='') {
        return false
                }
          }
      }
    return true
}

function mfsubmitPortfolioForm(code){
	
	if(code == null || code.length <1){
	var code = newSchemeId;
	if(code.indexOf("a") != -1){
            code =code.replace("a",",");
        }
    }
	var mfprice=document.mf_add_form.price.value;
    var mfquantity=document.mf_add_form.quantity.value;
    var mfdate=document.mf_add_form.date.value;
    document.mf_add_form.transDetails.value='mf|'+code+'|'+mfprice+'|'+mfquantity+'|'+mfdate;
    document.mf_add_form.method = "post";
	document.mf_add_form.target = "_parent";
    document.mf_add_form.action = "http://portfolio.rediff.com/money/jsp/select_portfolio.jsp";
    document.mf_add_form.submit();
}

var newId='';
var newSchemeId ='';
function mfshowAddPopup(schemeId,planId){
	if (newId != '')
		mfcloseAddPopup();
    newId = schemeId+planId;
	newSchemeId = schemeId+'a'+planId;
    document.getElementById(newId).className="moneypopup";
    document.getElementById(newId).innerHTML =  document.getElementById("mfaddportfoliopopup").innerHTML ;
    document.getElementById("mfaddportfoliopopup").innerHTML ="";
    document.getElementById(newId).style.display="block";
}
function mfcloseAddPopup(){
	
	resetDiv('mf');
    document.getElementById("mfaddportfoliopopup").innerHTML =   document.getElementById(newId).innerHTML;
    document.getElementById(newId).style.display="none";
    document.getElementById(newId).innerHTML =  "";
    newId='';
	newSchemeId='';
}

function checkalertvalidate(){
	var stockmessage="";
    var x=0;
    var maxprice=Trim(document.stockwatch_popup.maxprice.value);
	var dotIndex = maxprice.indexOf(".");
	var tempCount = 0;
	while(dotIndex != -1){
		tempCount++;
		dotIndex = maxprice.indexOf(".",dotIndex+1);
	}
	if(tempCount <2){ 
		while (maxprice.indexOf(",") != -1)
			maxprice= maxprice.replace(/,/,"");
		if(maxprice.length >=1){
			var checkmax=checkalertPrice(maxprice);
			if(checkmax==false){
				stockmessage="Please enter numbers only";
				x=1;
			}
		}
	}else{
		stockmessage="Please enter only one decimal";
		x=1;
	}
    var minprice=Trim(document.stockwatch_popup.minprice.value);
	dotIndex = minprice.indexOf(".");
	tempCount = 0;
	while(dotIndex != -1){
		tempCount++;
		dotIndex = minprice.indexOf(".",dotIndex+1);
	}
	if(tempCount <2){ 
		while (minprice.indexOf(",") != -1)
			minprice= minprice.replace(/,/,"");
		if(minprice.length>=1){
			var checkmin=checkalertPrice(minprice);
			if(checkmin==false){ 
				stockmessage="Please enter numbers only";
				x=1;
			}
		}
	}else{
		stockmessage="Please enter only one decimal";
		x=1;
	}
    if(x==1){
        alert(stockmessage);
		return false;
    }else{
		alertmaxprice =maxprice;
		alertminprice = minprice;
		submitAlertStockForm('co');
    }
}
function checkmfalertvalidate(){
	var stockmessage="";
    var x=0;
    var maxprice=Trim(document.mfstockwatch_popup.maxprice.value);
	var dotIndex = maxprice.indexOf(".");
	var tempCount = 0;
	while(dotIndex != -1){
		tempCount++;
		dotIndex = maxprice.indexOf(".",dotIndex+1);
	}
	if(tempCount <2){
		while (maxprice.indexOf(",") != -1)
			maxprice= maxprice.replace(/,/,"");
		if(maxprice.length >=1){
			var checkmax=checkalertPrice(maxprice);
			if(checkmax==false){
				stockmessage="Please enter numbers only";
				x=1;
			}
		}
	}else{
		stockmessage="Please enter only one decimal";
		x=1;
	}
    var minprice=Trim(document.mfstockwatch_popup.minprice.value);
	dotIndex = minprice.indexOf(".");
	tempCount = 0;
	while(dotIndex != -1){
		tempCount++;
		dotIndex = maxprice.indexOf(".",dotIndex+1);
	}
	if(tempCount <2){
		while (minprice.indexOf(",") != -1)
			minprice= minprice.replace(/,/,"");
		if(minprice.length>=1){
			var checkmin=checkalertPrice(minprice);
			if(checkmin==false){
				stockmessage="Please enter numbers only";
				x=1;
			}
		}
	}else{
		stockmessage="Please enter only one decimal";
		x=1;
	}
    if(x==1){
        alert(stockmessage);
		return false;
    }else{
		alertmaxprice = maxprice;
		alertminprice = minprice;
		submitAlertStockForm('mf');
    }
}
function checkmfalertvalidate1(){
	var stockmessage="";
    var x=0;
    var maxprice=Trim(document.mfstockwatch_popup.maxprice.value);
	var dotIndex = maxprice.indexOf(".");
	var tempCount = 0;
	while(dotIndex != -1){
		tempCount++;
		dotIndex = maxprice.indexOf(".",dotIndex+1);
	}
	if(tempCount <2){
		while (maxprice.indexOf(",") != -1)
			maxprice= maxprice.replace(/,/,"");
		if(maxprice.length >=1){
			var checkmax=checkalertPrice(maxprice);
			if(checkmax==false){
				stockmessage="Please enter numbers only";
				x=1;
			}
		}
	}else{
		stockmessage="Please enter only one decimal";
		x=1;
	}
    var minprice=Trim(document.mfstockwatch_popup.minprice.value);
	dotIndex = minprice.indexOf(".");
	tempCount = 0;
	while(dotIndex != -1){
		tempCount++;
		dotIndex = maxprice.indexOf(".",dotIndex+1);
	}
	if(tempCount <2){
		while (minprice.indexOf(",") != -1)
			minprice= minprice.replace(/,/,"");
		if(minprice.length>=1){
			var checkmin=checkalertPrice(minprice);
			if(checkmin==false){
				stockmessage="Please enter numbers only";
				x=1;
			}
		}
	}else{
		stockmessage="Please enter only one decimal";
		x=1;
	}
    if(x==1){
        alert(stockmessage);
		return false;
    }else{
		alertmaxprice = maxprice;
		alertminprice = minprice;
		submitAlertStockForm('mf1');
    }
}

function checkalertPrice(strValue){
    strValue = Trim(strValue);
	var tempValue='';
    if(strValue.length>0){
		
		if(isNaN(strValue)){
			return false;
		}
	}
    return true
}

function Trim(str){
	return str.replace(/^\s*|\s*$/g,"");
}

function submitAlertStockForm(id){
	var maxprice = alertmaxprice;
	var minprice = alertminprice;
	if (id =='co'){
		document.forms["stockwatch_popup"].code.value=tempid;
		document.forms["stockwatch_popup"].flag.value='sw_add';
		document.forms["stockwatch_popup"].transDetails.value='sw_edit|1|'+tempid+'|'+maxprice+'|'+minprice+"|edit|SW";
		document.stockwatch_popup.method="post";
		document.stockwatch_popup.target="_parent";
		document.stockwatch_popup.action="http://portfolio.rediff.com/money/jsp/stockwatch_edit.jsp";
		document.stockwatch_popup.submit();
	}else if(id == 'mf'){
		document.forms["mfstockwatch_popup"].code.value=newSchemeId;
		document.forms["mfstockwatch_popup"].flag.value='sw_add';
		document.forms["mfstockwatch_popup"].transDetails.value='sw_edit|1|'+newSchemeId+'|'+maxprice+'|'+minprice+"|edit|SW";
		document.mfstockwatch_popup.method="post";
		document.mfstockwatch_popup.target="_parent";
		document.mfstockwatch_popup.action="http://portfolio.rediff.com/money/jsp/stockwatch_edit.jsp";
		document.mfstockwatch_popup.submit();
	}else if(id == 'mf1'){
		document.forms["mfstockwatch_popup"].flag.value='sw_add';
		document.forms["mfstockwatch_popup"].transDetails.value='sw_edit|1|'+document.forms["mfstockwatch_popup"].code.value+'|'+maxprice+'|'+minprice+"|edit|SW";
		document.mfstockwatch_popup.method="post";
		document.mfstockwatch_popup.target="_parent";
		document.mfstockwatch_popup.action="http://portfolio.rediff.com/money/jsp/stockwatch_edit.jsp";
		document.mfstockwatch_popup.submit();
	}
}


function addPortfolioGame(compId ){
 getPage("http://moneygame.rediff.com/player_home.php?cid="+tempid+"&do=mw");
}

function openMfPopup(){
    document.getElementById("mfAddPortfolio").style.display="block";
}
function closeMfPopup(){
    document.forms["mf_add_form"].reset();
    document.getElementById("mfAddPortfolio").style.display="none";
}
function openMfPopup(id){
    document.getElementById(id).style.display="block";
}
function closeMfPopup(id){
	if(id == 'mfAddPortfolio'){
		document.forms["mf_add_form"].reset();
	}else if(id == 'mfAddStockwatch'){
		document.forms["mfstockwatch_popup"].reset();
	}
	document.getElementById(id).style.display="none";
}

//tab.js
function openTab(numtabs,tabfamily,tabid){
	var tempTabId;
	var currentTabId= tabfamily + tabid;
	for(i=1; i<= numtabs; i++){
		tempTabId = tabfamily+i;
		getEl(tempTabId+"m").className="";		
		getEl(tempTabId).style.display="none";
	}
	getEl(currentTabId+"m").className="currenttab";	
	getEl(currentTabId).style.display="block";		
}
function getEl(id){
	if(document.getElementById(id))
	{
	return document.getElementById(id);
	}
}

//mfsearch.js

    var level = -1;

    function callSchemes(){
        var amc = document.MFSearch.Amc.value;
        document.MFSearch.Class.options.length=0;
        document.MFSearch.Class.options[0] = new Option('Select One (Optional)',-1);
        document.MFSearch.Plan.options.length=0;
        document.MFSearch.Plan.options[0] = new Option('Select One (Optional)',-1);
        document.MFSearch.Type.options.length=0;
        document.MFSearch.Type.options[0] = new Option('Select One (Optional)',-1);

        if(amc == '-1'){
            var parameter = 'level=0';
            getTablepass(parameter);
        }else{
            level = 1;
            var parameter = 'amcCode='+amc+'&level='+level;
            getTablepass(parameter);
        }
     }
     function callClass(){
        var amc = document.MFSearch.Amc.value;
        if(amc == '-1'){
            var parameter = 'level=0';
            getTablepass(parameter);

        }else{
            document.MFSearch.Class.options.length=0;
            document.MFSearch.Class.options[0] = new Option('Select One (Optional)',-1);
            document.MFSearch.Plan.options.length=0;
            document.MFSearch.Plan.options[0] = new Option('Select One (Optional)',-1);
            document.MFSearch.Type.options.length=0;
            document.MFSearch.Type.options[0] = new Option('Select One (Optional)',-1);
            level = 2;
            var parameter = 'amcCode='+amc+'&level='+level;
            getTablepass(parameter);
        }
     }
     function callPlan(){
        var amc = document.MFSearch.Amc.value;
        var class1 = document.MFSearch.Class.value;
        if(class1 != '-1'){
            document.MFSearch.Plan.options.length=0;
            document.MFSearch.Plan.options[0] = new Option('Select One (Optional)',-1);
            document.MFSearch.Type.options.length=0;
            document.MFSearch.Type.options[0] = new Option('Select One (Optional)',-1);
            level = 3;
            var parameter = 'amcCode='+amc+'&classCode='+class1+'&level='+level;
            getTablepass(parameter);
         }
     }

     function callType(){
        var amc = document.MFSearch.Amc.value;
        var class1 = document.MFSearch.Class.value;
        var plan = document.MFSearch.Plan.value;
        if(plan != '-1'){
            document.MFSearch.Type.options.length=0;
            document.MFSearch.Type.options[0] = new Option('Select One (Optional)',-1);
            level = 4;
            var parameter = 'amcCode='+amc+'&classCode='+class1+'&planCode='+plan+'&level='+level;
            getTablepass(parameter);
        }
     }

    function getTablepass(parameter) {
        var str = parameter;
        var url = "http://money.rediff.com/money/jsp/createXml.jsp?"+str;
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = stateHandler;
            req.open("GET", url, true);
            req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
            req.send(null);
        } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            req.onreadystatechange = stateHandler;
            req.open("GET", url, true);
            req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            req.send();
        }
    }

    function stateHandler() {
        if (req.readyState == 4){
            if (req.status == 200){
                var val = req.responseText;
                var xmlDoc = setformdata(val);
                if(xmlDoc) {
                    if(level == '0'){
                        parsexmldropdown(xmlDoc,'2');
                        parsexmldropdown(xmlDoc,'3');
                        parsexmldropdown(xmlDoc,'4');
                    }else if(level=='1') {
                        parsexmldropdown(xmlDoc,'2');
                        parsexmldropdown(xmlDoc,'3');
                        parsexmldropdown(xmlDoc,'4');

                    } else if(level=='2'){
                        parsexmldropdown(xmlDoc,'2');
                        parsexmldropdown(xmlDoc,'3');
                        parsexmldropdown(xmlDoc,'4');
                    } else if(level=='3') {
                        parsexmldropdown(xmlDoc,'3');
                        parsexmldropdown(xmlDoc,'4');
                    } else if(level=='4') {
                        parsexmldropdown(xmlDoc,level);
                        var len = document.MFSearch.Type.options.length;
                        if(len == 2){
                            document.MFSearch.Type.options[1].selected=true;
                        }
                    }else{
                        parsexmldropdown(xmlDoc,level);
                    }
                }
            }else {
                alert('failed');
            }
        }
        return true;
    }
    function setformdata(xml) {
        if(navigator.appName.indexOf("Microsoft")!=-1){
            var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(xml);
            return xmlDoc;
        }else{
            var parser=new DOMParser();
            var doc=parser.parseFromString(xml,"text/xml");
            var xmlDoc=doc.documentElement;
            xmlDoc.async = false;
            return xmlDoc;
        }
    }
    var ELEMENT_NODE = 1;
    function parsexmldropdown(xmlDoc,level) {
        var id = '';
        var combo ;

        if(level == '2'){
            id = 'ClassList';
            combo = document.MFSearch.Class;
        }else if(level == '3'){
            id = 'PlanList';
            combo = document.MFSearch.Plan;
        }else if(level == '4'){
            id = 'TypeList';
            combo = document.MFSearch.Type;
        }
        var addressbook = xmlDoc.getElementsByTagName(id);
        if(addressbook[0].childNodes.length>0){
            for ( i= 0; i < addressbook[0].childNodes.length; ++i) {
                adddetails =  addressbook[0].childNodes[i];
                if(adddetails.nodeType != ELEMENT_NODE) continue;
                combo.options[i+1] = new Option(adddetails.childNodes[1].childNodes[0].nodeValue,adddetails.childNodes[0].childNodes[0].nodeValue);
            }
        }
    }
    function simple(){
        document.MFSearch.searchType.value='simple';
        document.MFSearch.Amc.value='-1';

        var len = document.MFSearch.radioBtn.length;
        var check = false;
		var redbtnval = "";
        for(var n=0; n<len; n++){
           if(document.MFSearch.radioBtn[n].checked){
                check =  true;
				redbtnval = document.MFSearch.radioBtn[n].value;
		   }
       }
           if(check == true){
                document.MFSearch.next.value=25;
                document.MFSearch.prev.value=1;
				if(redbtnval == 'H'){
					document.MFSearch.action="http://money.rediff.com/mutual-funds/high-risk";
				}else if(redbtnval == 'M'){
					document.MFSearch.action="http://money.rediff.com/mutual-funds/med-risk";
				}else if(redbtnval == 'L'){
					document.MFSearch.action="http://money.rediff.com/mutual-funds/low-risk";
				}
                formSubmit();
            }else
                alert("Select any one of the options");
        }


    function advance(){
            document.MFSearch.next.value=25;
            document.MFSearch.prev.value=1;
            document.MFSearch.searchType.value='advance';

            if(document.MFSearch.Amc.value == '-1' && document.MFSearch.Class.value == '-1' && document.MFSearch.Plan.value == '-1' && document.MFSearch.Type.value == '-1'){
                alert("Select any one of the options");
            }else{
				document.MFSearch.hdamc.value=document.MFSearch.Amc.options[document.MFSearch.Amc.selectedIndex].text;
			    document.MFSearch.hdclass.value=document.MFSearch.Class.options[document.MFSearch.Class.selectedIndex].text;
			    document.MFSearch.hdplan.value=document.MFSearch.Plan.options[document.MFSearch.Plan.selectedIndex].text;
			    document.MFSearch.hdtype.value=document.MFSearch.Type.options[document.MFSearch.Type.selectedIndex].text;
			    document.MFSearch.message.value=null;
				formactionname();
                formSubmit();
            }
        }
		function formactionname(){
			var optarray = new Array("amc","class","plan","type");
			var myBoolean=new Boolean(false);
			var cnt=0;
			var tempurl="";
			var whtSpMult = new RegExp("\\s\\s+", "g");
			for(var i=0;i<optarray.length;i++){
				var fldval = document.getElementById(optarray[i]);
				if(fldval.value != '-1'){
					cnt++;
					if(cnt == 1){
						var fldtext = fldval.options[fldval.selectedIndex].text
						fldtext = replaceAll(fldtext,"-"," ");
						fldtext = fldtext.replace(whtSpMult," ");
						fldtext = replaceAll(fldtext," ","-");
						fldtext = replaceAll(fldtext,"&","and");
						fldtext = fldtext.toLowerCase();
						tempurl = optarray[i]+"/"+fldtext;
					}
				}
			}
			if(cnt > 1){
				document.MFSearch.action="http://money.rediff.com/mutual-funds/advanced";
			}else if(cnt == 1){
				document.MFSearch.action="http://money.rediff.com/mutual-funds/"+tempurl;
			}else{
				document.MFSearch.action="http://money.rediff.com/mutual-funds";
			}
		}
		function replaceAll(text, strA, strB)
		{
			while ( text.indexOf(strA) != -1)
			{
				text = text.replace(strA,strB);
			}
			return text;
		}

        function formSubmit(){			
            
            document.MFSearch.method="post";
            document.MFSearch.submit();

        }

    function invisible(){
        document.getElementById('dd1').style.visibility="hidden";
        document.getElementById('dd1').style.display="none";
        document.getElementById('dd2').style.visibility="hidden";
        document.getElementById('dd2').style.display="none";
        document.getElementById('dd3').style.visibility="hidden";
        document.getElementById('dd3').style.display="none";
    }
    function showDiv(id){
        invisible();
        document.getElementById(id).style.visibility="visible";
        document.getElementById(id).style.display="block";
    }

    function perviuosClick() {
        if(document.MFSearch.searchType.value == 'simple'){
            document.MFSearch.radioBtn.value = document.MFSearch.msgKey.value;
        }else if(document.MFSearch.searchType.value == 'advance'){
            var temp = document.MFSearch.msgKey.value.split("/");
            document.MFSearch.Amc.value = temp[0];
            document.MFSearch.Class.value = temp[1];
            document.MFSearch.Plan.value = temp[2];
            document.MFSearch.Type.value = temp[3];
        }
        var nextValue=document.MFSearch.next.value;
        var prevValue=document.MFSearch.prev.value;
        nextValue = eval(nextValue)-25;
        prevValue=eval(prevValue)- 25;
        document.MFSearch.next.value=nextValue;
        document.MFSearch.prev.value=prevValue;
        formSubmit();
   }
   function nextClick() {
        if(document.MFSearch.searchType.value == 'simple'){
            document.MFSearch.radioBtn.value = document.MFSearch.msgKey.value;
        }else if(document.MFSearch.searchType.value == 'advance'){
            var temp = document.MFSearch.msgKey.value.split("/");
            document.MFSearch.Amc.value = temp[0];
            document.MFSearch.Class.value = temp[1];
            document.MFSearch.Plan.value = temp[2];
            document.MFSearch.Type.value = temp[3];
        }
        var nextValue=document.MFSearch.next.value;
        var prevValue=document.MFSearch.prev.value;
        prevValue = eval(prevValue)+25;
        nextValue = eval(nextValue)+25;
        document.MFSearch.next.value=nextValue;
        document.MFSearch.prev.value=prevValue;
        formSubmit();
   }
   
   //racinhome.js
   
   function stopRacing(){
   if(!document.all){
    getEl("area021_table").innerHTML =   getEl("area021").innerHTML;
     getEl("area021").innerHTML = "";
    getEl("area022_table").innerHTML =   getEl("area022").innerHTML;
     getEl("area022").innerHTML = "";
    getEl("area033_table").innerHTML =   getEl("area033").innerHTML;
     getEl("area033").innerHTML = "";
    }

}
function getEl(id){
	if(document.getElementById(id))
	{
return document.getElementById(id);
	}
}

//floater_top.js

var isstop = true;
function doOnLoadsFunctions()
{
  if(typeof(right_onload) == "function")
  {
    right_onload();
  }
}

  function article(url,companyname){
                    window.open("sendmail.jsp?url="+url+"&#38;companyname="+companyname, "sendmail","width=507,height=420,status=no,resizable=no,location=no,top=200,left=200");
                    }
//floater-initial

var isstop = true;
var target_x = 3;
var target_y = 0;
var fm_height = 0;
var floatHeight = 0;
var begin_top = 10;

//floater-main

var initDone = false;
var fm_id='scontentsub';
var floating_menu = null;
var fm_shift_x, fm_shift_y, fm_next_x, fm_next_y;
var fm_height = 0;
var sliderCell = null;
var progressbar = null;
var sTop = 0;
var popupOffset = 0; 
var errormsg = "";

function right_onload(from_popup_layout)
{
  if( from_popup_layout ) {
    popupOffset = 200;
  }
  
  setTimeout("floater_init();", 50);
}
function floater_init()
{
  floating_menu =
    document.getElementById
    ? document.getElementById(fm_id)
    : document.all
      ? document.all[fm_id]
      : document.layers[fm_id];
	  
  
  fm_height = floating_menu.offsetHeight;
  sliderCell = document.getElementById("slidercell");
  
  compute_shifts();

  if (document.layers)
  {
    fm_next_x = 0;
    fm_next_y = 0;
  }
  else
  {
    fm_next_x = fm_shift_x + target_x;
    fm_next_y = fm_shift_y + target_y;
    move_menu();
  }
  float_menu();
}
function move_menu()
{
	/*
  if (document.layers){
    floating_menu.top = fm_next_y;
  }
  else{
    floating_menu.style.top = fm_next_y + 'px';
  }
  */
}
function pageHeight()
{
  return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}
function getScrollXY() {
  var scrOfY = 0; 
  if( typeof( window.pageYOffset ) == 'number' ) {
   
    scrOfY = window.pageYOffset;
    
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    
    scrOfY = document.body.scrollTop;
    
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    
    scrOfY = document.documentElement.scrollTop;
    
  }
  
  return scrOfY;
}
function compute_shifts(){
  sTop = getScrollXY();
  
  if(pageHeight() + sTop - fm_height >= sliderCell.offsetHeight){
    if(fm_height == 0){
	  fm_shift_y = sliderCell.offsetHeight - (sliderCell.offsetHeight-sTop) - begin_top;
	  if( fm_shift_y < 0 ) fm_shift_y = 0;
	  
	}else{
	  fm_shift_y = sliderCell.offsetHeight - fm_height;
	}
  }
  else if(sTop - begin_top >= 0){
    fm_shift_y = (sTop - begin_top + (20+popupOffset));
  }
  else{
    fm_shift_y = 0;
  }
  if( fm_shift_y > sliderCell.offsetHeight ){
    fm_shift_y = sliderCell.offsetHeight;
  }
}

function float_menu(){
  var step_x, step_y;
  
  compute_shifts();
  step_y = (fm_shift_y + target_y - fm_next_y) * .07;
  
  if (Math.abs(step_y) < .5)
step_y = fm_shift_y + target_y - fm_next_y;

  if (Math.abs(fm_next_y) > (sliderCell.offsetHeight- floating_menu.offsetParent.offsetHeight))
  {
    if (step_y < 0){
fm_next_y += step_y;
      move_menu();
    }
    else {
      move_menu();
    }
  }
  else if (Math.abs(step_x) > 0 || Math.abs(step_y) > 0){
    fm_next_y += step_y;
    move_menu();
  }
  else {
  }
  setTimeout('float_menu()', 20);
}

function show_msg(){
  }
 
 function lTrim(str){
            for (var i=0; str.charAt(i)==" "; i++);
                return str.substring(i,str.length);
            }

function rTrim(str){
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
}
function trim(str){
	var st="";
	st = lTrim(rTrim(str));
	return st;
}
function setEncode(str){
	str = trim(str);
	str = escape(str);
	alert(str);
}

function frmSubmit() {
	if( (document.get_quote.query.value).replace(/^\s+/g,'').replace(/\s+$/g,'')!="" && (document.get_quote.query.value).replace('Search by company or mutual fund name','')!="")
		document.get_quote.submit();
}

function showDivPopup(id, type){
	if(type=='portfolio'){
		document.getElementById('plink').style.display="none";
		document.getElementById('ppage').style.display="block";
		document.getElementById('swpage').style.display="none";
		
	}else if(type == 'sw'){
		document.getElementById('plink').style.display="none";
		document.getElementById('ppage').style.display="none";
		document.getElementById('swpage').style.display="block";
		
	}else{
		document.getElementById('plink').style.display="block";
		document.getElementById('ppage').style.display="none";
		document.getElementById('swpage').style.display="none";
		
		
	}
	xshowAddPopup(id);
}

function checkCoDate(){
        if(document.add_pf_co.day.value ==-1 || document.add_pf_co.month.value ==-1 || document.add_pf_co.YEAR.value ==-1){
            alert("Please select Date");
        }else{
            document.add_pf_co.date.value = document.add_pf_co.day.value+"/"+document.add_pf_co.month.value+"/"+document.add_pf_co.YEAR.value;
            var check = false;
            check= isValidDate(document.add_pf_co.month.value+"/"+document.add_pf_co.day.value+"/"+document.add_pf_co.YEAR.value);
            if(check == true){
                doAddPortfolioSubmit();
             }
        }
    }
	
	function year_fillup(){
        var combo = document.add_pf_co.YEAR;
        combo.options[0] = new Option('YYYY',-1);
        var count=1;
        for(var i = curr_year; i>=last_year; i--){
            combo.options[count]= new Option(i,i);
            count++;
        }
     }
	 
	     var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    curr_month = curr_month + 1;
    var curr_year = d.getFullYear();
    var last_year = curr_year-30;
	
    function isValidDate(dateStr) {
 
        var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

        var matchArray = dateStr.match(datePat); 
        if (matchArray == null) {
        alert("Date is not in a valid format.")
        return false;
        }
        month = matchArray[1]; 
        day = matchArray[3];
        year = matchArray[4];
        if (month < 1 || month > 12) {
        alert("Month must be between 1 and 12.");
        return false;
        }
        if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31.");
        return false;
        }
        if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Month "+month+" doesn't have 31 days!")
        return false
        }
        if (month == 2) { 
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day>29 || (day==29 && !isleap)) {
            alert("February " + year + " doesn't have " + day + " days!");
            return false;
        }
        }
        return true;  
}

function placeFocus(){
            if (document.forms.length > 0){
                var field = document.forms[0];
                for (i = 0; i < field.length; i++) {
                    if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
                        document.forms[0].elements[i].focus();
                        break;
                    }
                }
            }
       }
      
function st2new1(n)
{
	for(i=1;i<=14;i++)
	{
		tabnm=document.getElementById('headTabs'+ i);

		if (n==i)
		{
			
			
			document.getElementById('arrow'+i).style.visibility="visible";
			tabnm.className="headback1sel";
			//showDiv('ds'+n);
			
			document.getElementById('spo'+i).style.visibility = "visible";
			document.getElementById('spo'+i).style.display = "block";
		}
		else
		{
		
		
			tabnm.className="headback1";
			document.getElementById('arrow'+i).style.visibility="hidden";
			//hideDiv('ds'+i);
			//hideDiv('ss'+i);
			document.getElementById('spo'+i).style.visibility = "hidden";
			document.getElementById('spo'+i).style.display = "none";
		}
	}
}
function hideDiv(divnm)
{
		document.getElementById(divnm).style["display"]="none" ;
		document.getElementById(divnm).style["visibility"]="hidden" ;
}
function display_div(id){
        var tabnm = document.getElementById('headTabs'+ id);
        tabnm.className="headback1sel";
        document.getElementById('arrow'+id).style.visibility="visible";
        showDiv('ds'+id);
		showDiv('spo'+id);
    }
	
        function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
            var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
            return newnumber;
        }
        function hide() {
            document.getElementById('balloon1').style.display="none";
        }
        function isInteger(s){
            var i;
        
            if (isEmpty(s))
                if (isInteger.arguments.length == 1) return 0;
                else return (isInteger.arguments[1] == true);
            /*
            for (i = 0; i < s.length; i++) {
                var c = s.charAt(i);
                if (!isDigit(c)) return false;
            }
            */
            if (isNaN(s)) {
                return false;
            } else if (s < 0) {
                return false;
            }
            return true;
        }
        
        function isEmpty(s){
            return ((s == null) || (s.length == 0))
        }
        
        function isDigit (c){
            return ((c >= "0") && (c <= "9"))
        }
        function formatNumCurrency(iNum) {
            var aNum = new Array;
            var iLen = 0;
            var sFormattedNumber = "";
            if (!isEmpty(iNum)) {
                var sNum = ""+iNum+"";
                //alert(sNum);
                iPos = sNum.indexOf(".");
                if(iPos!=-1){
                    var iNum1 = sNum.substring(0, iPos);
                    var iNum2 = sNum.substring(iPos + 1, sNum.length);
                }else{
                    var iNum1 = sNum;
                }
                iLen = iNum1.length - 1;
                var iLoop = 0;
                for (i=iLen; i>=0; i--) {
                    iLoop++;
                    if (iLoop == 4) {
                        sFormattedNumber = iNum1.charAt(i) + "," + sFormattedNumber;
                    } else if ((iLoop > 4) && (iLoop % 2) == 0) {
                        sFormattedNumber = iNum1.charAt(i) + "," + sFormattedNumber;
                    } else {
                        sFormattedNumber = iNum1.charAt(i) + sFormattedNumber;
                    }
                    //alert(sFormattedNumber);
                }
                if(iNum2 > 0)
                    sFormattedNumber = sFormattedNumber + "." + iNum2;
                //alert("Finally: " + sFormattedNumber);
                return sFormattedNumber;
            }
            return 0;
        }

		function get_result() {
            var iInvestedAmt = trim(document.getElementById('in_money').value);			
            var sRepStr = /,/g;
            iInvestedAmt = iInvestedAmt.replace(sRepStr, "");
            var sRepStr = / /g;
            iInvestedAmt = iInvestedAmt.replace(sRepStr, "");
            if (!isInteger(iInvestedAmt)) {
                if (iInvestedAmt) {
                    document.getElementById("balloon1").style.display = 'block';
                }
                return false;
            }
			
            var iSelectedPeriod = document.getElementById("selPer").value;
            if ((aRates[iSelectedPeriod] > 0) && (iInvestedAmt > 0)) {
                document.getElementById("balloon1").style.display = "none";
                var iCurrentPrice = aRates[0];
                var iTotalShares = iInvestedAmt / aRates[iSelectedPeriod];

                alert("iSelectedPeriod"+aRates[iSelectedPeriod]);
                alert("formula "+iTotalShares+" = "+iInvestedAmt+" / "+aRates[iSelectedPeriod]);
                alert("iTotalShares"+iTotalShares);
                
                if (aBonus[iSelectedPeriod] != undefined) {
                    var iOldShares = aBonus[iSelectedPeriod][0];
                    var iNewShares = aBonus[iSelectedPeriod][1];
                    iTotalShares = ((iTotalShares * iNewShares) / iOldShares) + iTotalShares;
                }
                if (aSplit[iSelectedPeriod] != undefined) {
                    var iOldVal = aSplit[iSelectedPeriod][0];
                    var iNewVal = aSplit[iSelectedPeriod][1];
                    //alert("Old: " + iTotalShares + "===" + iOldVal + "" +iNewVal);
                    iTotalShares = ((iTotalShares * iOldVal) / iNewVal)
                    //alert("Shares: "+iTotalShares);
                }
    
                var iCurrentAmt = roundNumber(iCurrentPrice * iTotalShares, 2);
                alert("iCurrentAmt"+iCurrentAmt);
				if (parseFloat(iCurrentAmt) <= 1) {
						iCurrentAmt = 1;
				}
                var sCurrentAmt = formatNumCurrency(iCurrentAmt);
                //alert(sCurrentAmt);
    			document.getElementById('res_val').innerHTML="Rs "+ sCurrentAmt;
    			if (iCurrentAmt < iInvestedAmt) {
    				document.getElementById('res_val').className="col_red";
    			} else if (iCurrentAmt > iInvestedAmt) {
                    document.getElementById('res_val').className="col_green";
                } else {
                    document.getElementById('res_val').className="col_white";
                }
            } else {
                document.getElementById('res_val').innerHTML="Rs 0.00";
                document.getElementById('res_val').className="col_white";
            }

		}
		function clear_field() {
            document.getElementById('in_money').value="";
            document.getElementById('res_val').innerHTML="Rs 00,00,00,000.00";
            document.getElementById('res_val').className = "col_white";
        }

function clickLink(){

	  var amtVal = document.getElementById("in_money").value;	
      	if (parseFloat(amtVal) <= 1.00) {
						amtVal = 1;
				}else{
						amtVal=amtVal;
				}
	   var iSelectedPeriod = document.getElementById("selPer").value;
	   var companyCode = document.getElementById("companyCode").value;
	   document.frmStockChart.action="http://money.rediff.com/tools/advanced/"+companyCode;
       document.frmStockChart.submit();
  }

function openTabSingle(id){
					document.paging.cTab.value = id;
					var jspPage = document.paging.pageType.value+".jsp";
					document.paging.action= "/money/jsp/" + jspPage;					
					document.paging.submit();
				}
function openTabIndices(id){
	document.paging.cTab.value = id;
	var jspPage = document.paging.pageType.value+".jsp";
	//document.paging.action= "/money/jsp/" + jspPage;
	if (id == 1) {
		document.paging.action= "http://money.rediff.com/indices/bse";
	}else if (id == 2) {
		document.paging.action= "http://money.rediff.com/sectors";
	}else if (id == 3) {
		document.paging.action= "http://money.rediff.com/indices/bse/dollex";
	}else if (id == 4) {
		document.paging.action= "http://money.rediff.com/indices/world";
    }else if (id == 5) {
        document.paging.action = "http://money.rediff.com/indices/futures";
	}else{
		document.paging.action= "http://money.rediff.com/indices/bse";
	}
	document.paging.submit();
}
function openTabGainer(grpid){
	document.paging.action= "http://money.rediff.com/gainers/"+grpid;
	document.paging.submit();
}
function openTabLoser(grpid){
	document.paging.action= "http://money.rediff.com/losers/"+grpid;
	document.paging.submit();
}

													
function frmSubmitFooter() {
if( (document.get_quote1.query.value).replace(/^\s+/g,'').replace(/\s+$/g,'')!="" && (document.get_quote1.query.value).replace('','')!="" &&  (document.get_quote1.query.value).replace('Search by company or mutual fund name','')!="")
		document.get_quote1.submit();
	document.get_quote1.focus();
}		
								
								                   function frmSubmitCompare() {
                            if( (document.get_quote_compare.query.value).replace(/^\s+/g,'').replace(/\s+$/g,'')!="" && (document.get_quote_compare.query.value)!='Company Name Or Symbol')
                                document.get_quote_compare.submit();
                    }
					
				function disp_banner(pr1,pr2,id){
	if ((navigator.appName.indexOf("Microsoft") != -1) || (navigator.userAgent.toLowerCase().indexOf('firefox'))){
	OAS_AD(id);
	}else{
	da(pr1,pr2,id);
	}
}
function display_banner_div(id){
	if(document.getElementById(id))
		document.getElementById(id).innerHTML = document.getElementById(id+"_hidden").innerHTML;
	document.getElementById(id+"_hidden").innerHTML="";
}
function openTabMarketcap(grpid){
	document.paging.action= "http://money.rediff.com/companies/market-capitalisation/"+grpid;
	document.paging.submit();
}
function company_chart(tabid){
	document.getElementById("tabId").value=tabid;
	var compname = document.getElementById("companyName").value;
	var compcode = document.getElementById("companyCode").value;
	document.companychart.method="POST";
	document.companychart.action = "http://money.rediff.com/companies/"+compname+"/"+compcode;
	document.companychart.submit();
}

