/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *
 * Shubhangi
 */

 var xmlhttpshu;
function lookup(inputString,strelementid) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
           document.getElementById("suggestions").style.display='none';


		} else {

             autosearch(inputString,strelementid);
             document.getElementById("indicator").style.display='block';
             document.getElementById("suggestions").style.display='block';

           }
	} // lookup

   function fill(thisValue,elestock,companyid) {
        document.getElementById("suggestions").style.display='none';
        document.getElementById("indicator").style.display='none';
        document.getElementById("inputString").value=thisValue.toString().replace(":::", " ").toString().replace("::", " ");
        document.getElementById(elestock).value=thisValue.toString().substring(thisValue.toString().indexOf("::")+2,thisValue.toString().indexOf(":::"));
        //document.getElementById(elemarket).value=thisValue.toString().substring(0,thisValue.toString().indexOf("::"));
        if(document.getElementById('sectorrow')!=null){
            sectorindexloadforstock(companyid,"sector");
            sectorindexloadforstock(companyid,"index");
        }
        if(document.getElementById('timeperiodcell')!=null){
            if(document.getElementById('pricechart_stock')!=null)
                timeperiodloadforstock(companyid,'pricechart');
            else if(document.getElementById('presentvalue_stock')!=null)
                timeperiodloadforstock(companyid,'pv1000');
            else if(document.getElementById('putcall_stock')!=null)
                timeperiodloadforstock(companyid,'putcall');
        }
        setTimeout("document.getElementById('suggestions').style.display='none'", 200);
	}


    function   autosearch(inputString,strelementid)
            {
                 url="rpc.php?queryString="+inputString+"&stockhtmid="+strelementid;
                 document.getElementById("autoSuggestionsList").innerHTML="";

                     xmlhttpshu=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpshu = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
            }
                    if (xmlhttpshu!=null)
                    {
                        xmlhttpshu.onreadystatechange=state_Change;
                        xmlhttpshu.open("GET",url,true);
                        xmlhttpshu.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }



    }
       function lookupforAll(inputString,elestock,elemarket,companyhtmid) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
           document.getElementById("suggestions").style.display='none';


		} else {

             autosearchAll(inputString,elestock,elemarket,companyhtmid);
             document.getElementById("indicator").style.display='block';
             document.getElementById("suggestions").style.display='block';

           }
	} // lookup






function fillforAll(thisValue,elestock,elemarket,elestockid) {
        document.getElementById("suggestions").style.display='none';
        document.getElementById("indicator").style.display='none';
        var market=thisValue.toString().substring(0,thisValue.toString().indexOf("::"))
        var companyid=elestockid.toString().substring(elestockid.toString().indexOf("::")+2);
        var companycode=thisValue.toString().substring(thisValue.toString().indexOf("::")+2,thisValue.toString().indexOf(":::"));
        document.getElementById("inputString").value=thisValue.toString().replace(":::", " ").toString().replace("::", " ");
        document.getElementById(elemarket).value=market;
        document.getElementById(elestock).value=thisValue.toString().substring(thisValue.toString().indexOf("::")+2,thisValue.toString().indexOf(":::"));
        document.getElementById(elestockid.toString().substring(0,elestockid.toString().indexOf("::"))).value=companyid;

       if(document.getElementById('sectorrow')!=null){
            sectorindexloadforstock(companyid,market,"sector");
            sectorindexloadforstock(companyid,market,"index");
        }
        if(document.getElementById('timeperiodcell')!=null){
            if(document.getElementById('pricechart_stock')!=null)
                timeperiodloadforstock(companyid,market,'pricechart');
            else if(document.getElementById('presentvalue_stockid')!=null)
                timeperiodloadforstock(companyid,market,'pv1000');
            else if(document.getElementById('putcall_stockid')!=null)
                timeperiodloadforstock(companyid,market,'putcall');
        }
        setTimeout("document.getElementById('suggestions').style.display='none'", 200);
	}
     function lookupformarket(inputString,elestock,elemarket,companyhtmid) {
		if(inputString.length == 0) {
			// Hide the suggestion box.

           document.getElementById("suggestions").style.display='none';


		} else {
            var market=document.getElementById("market").value;

            autosearchmarket(inputString,elestock,elemarket,companyhtmid,market);
             document.getElementById("indicator").style.display='block';
             document.getElementById("suggestions").style.display='block';

           }
	} // lookup

 function   autosearchmarket(inputString,stockhtmid,markethtmid,companyhtmid,market)
            {


                 url="rpcmarket.php?queryString="+inputString+"&stockhtmid="+stockhtmid+"&markethtmid="+markethtmid+"&companyhtmid="+companyhtmid+"&market="+market;
                 document.getElementById("autoSuggestionsList").innerHTML="";

                     xmlhttpshu=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpshu = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
            }
                    if (xmlhttpshu!=null)
                    {
                        xmlhttpshu.onreadystatechange=state_Change;
                        xmlhttpshu.open("GET",url,true);
                        xmlhttpshu.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }



    }


  function   autosearchAll(inputString,stockhtmid,markethtmid,companyhtmid)
            {

                      
                 url="http://"+window.location.host+"/member/rpc.php?queryString="+inputString+"&stockhtmid="+stockhtmid+"&markethtmid="+markethtmid+"&companyhtmid="+companyhtmid;
                 document.getElementById("autoSuggestionsList").innerHTML="";

                     xmlhttpshu=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpshu = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
            }
                    if (xmlhttpshu!=null)
                    {
                        xmlhttpshu.onreadystatechange=state_Change;
                        xmlhttpshu.open("GET",url,true);
                        xmlhttpshu.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }



    }

   function  indexload(){
         
            var market=document.getElementById('marketindex').value;
         
           
            url="indexload.php?market="+market;
                 
                     xmlhttpshu=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpshu = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
                }
                    if (xmlhttpshu!=null)
                    {
                        xmlhttpshu.onreadystatechange=stateChanges;
                        xmlhttpshu.open("GET",url,true);
                        xmlhttpshu.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }


    }

function state_Change()
{
    if (xmlhttpshu.readyState==4)
  { // 4 = "loaded"
        if (xmlhttpshu.status==200)
        {// 200 = "OK"
        
         document.getElementById("autoSuggestionsList").innerHTML=xmlhttpshu.responseText;
         document.getElementById("indicator").style.display='none';
         
        }

        else
        {
            alert("Problem retrieving data:" + xmlhttpshu.statusText);
        }
    }
}


function stateChanges()
{
    
    if (xmlhttpshu.readyState==4)
  { // 4 = "loaded"
        if (xmlhttpshu.status==200)
        {// 200 = "OK"
         document.getElementById("indexrow").innerHTML=xmlhttpshu.responseText;
        }
        else
        {
            alert("Problem retrieving data:" + xmlhttpshu.statusText);
        }
    }
}

function emailidcheck(){
        var mailid=document.getElementById('mailid').value;
        var url="../StockResearch/StockReportMenu.php?mailid="+mailid+"&market="+market+"&companyid="+companyid;

        document.getElementById("autoSuggestionsList").innerHTML='<img src="../lightwindow/images/ajax-loading.gif" />';

                 xmlhttpshu=null;
               try{
                        // Opera 8.0+, Firefox, Safari
                        xmlhttpshu = new XMLHttpRequest();
                    } catch (e){
                        // Internet Explorer Browsers
                        try{
                                xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e) {
                            try{
                                xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                            } catch (e){
                                // Something went wrong
                                alert("Your browser broke!");

                        }
                }
        }
                if (xmlhttpshu!=null)
                {
                    xmlhttpshu.onreadystatechange=state_Change;
                    xmlhttpshu.open("GET",url,true);
                    xmlhttpshu.send(null);

                }
                else
                {
                     alert("Your browser does not support XMLHTTP.");
                }


}
  function insertstocktab(mailid){
      var daily="";
      var overview="";
      var financial="";
        for (i=0;i<9;i++) {
             if(document.forms['stocktab'].daily[i].checked==true){
               daily=daily+","+document.forms['stocktab'].daily[i].value+"="+1;
            }else{
             daily=daily+","+document.forms['stocktab'].daily[i].value+"="+0;
           }
         }
         for (i=0;i<6;i++) {
             if(document.forms['stocktab'].overview[i].checked==true){
               overview=overview+","+document.forms['stocktab'].overview[i].value+"="+1;
            }else{
             overview=overview+","+document.forms['stocktab'].overview[i].value+"="+0;
           }
         }
         for (i=0;i<11;i++) {
             if(document.forms['stocktab'].financial[i].checked==true){
               financial=financial+","+document.forms['stocktab'].financial[i].value+"="+1;
            }else{
              financial=financial+","+document.forms['stocktab'].financial[i].value+"="+0;
           }
         }
       
       
		var url="InserStockTab.php";
        var postString="mailid="+mailid.replace("&",":::")+"&financial="+financial.replace("&",":::")+"&daily="+daily.replace("&",":::")+"&overview="+overview.replace("&","::")+"&loggedInUserId="+loggedInUserId+"&market="+market+"&companyid="+companyid;//'chart_type=' + encodeURI(char);
       
        document.getElementById("ajax_chart_form").innerHTML='<img src="../lightwindow/images/ajax-loading.gif" />';
		 xmlHttp=null;
               try{
                        // Opera 8.0+, Firefox, Safari
                        xmlHttp = new XMLHttpRequest();
                    } catch (e){
                        // Internet Explorer Browsers
                        try{
                                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                        } catch (e) {
                            try{
                                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                            } catch (e){
                                // Something went wrong
                                alert("Your browser broke!");

                        }
                }
           }
                if (xmlHttp!=null)
                {
                    xmlHttp.onreadystatechange=stateTabChanged;
                    xmlHttp.open("post",url,true);
                    xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
		            xmlHttp.setRequestHeader('Content-length', postString.length);
					xmlHttp.setRequestHeader('Connection', 'close');
                    xmlHttp.send(postString);

                }
                else
                {
                     alert("Your browser does not support XMLHTTP.");
                }
    }

    function stateTabChanged()
{

	var temp;

    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
		var op= xmlHttp.responseText ;
		

		if(op == 0)
		{
			//document.getElementById('flagAjax').setAttribute("value",op);
		}
		else
		{
                
			temp = op;
			var results = temp.split("|||");

              document.getElementById('ajax_chart_form').innerHTML = results[0];
            if(results.length == 2)
			{
                    var sURL = unescape(window.location.pathname);
                    window.location.href = sURL+"?action=daily&companyid="+companyid+"&market="+market;
			}
			else
			{
				document.getElementById('ajax_chart_form').innerHTML = results[0];
			}

              // myLightWindow.deactivate();
		}
   }
 }

 function   emailsend(url)
 {
    // var sURL = unescape(window.location.pathname);
      
      document.forms[1].action = url;
      document.forms[1].submit();
 }

  function   lookupforemail(inputString)
            {

                      
                 url="../StockResearch/emailajax.php?queryString="+inputString;
                 document.getElementById("autoSuggestionsList").innerHTML="";

                     xmlhttpshu=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpshu = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
            }
                    if (xmlhttpshu!=null)
                    {
                        xmlhttpshu.onreadystatechange=state_Change;
                        xmlhttpshu.open("GET",url,true);
                        xmlhttpshu.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }



    }
    function fillforemail(thisValue) {
        document.getElementById("suggestions").style.display='none';
        document.getElementById("inputString").value=thisValue.toString();
        setTimeout("document.getElementById('suggestions').style.display='none'", 200);
	}
    function   accessvarible()
            {

                 if(ValidateForm()==false){
                     return false;
                 }
                 var startdate=document.getElementById('startdate').value;
                 var enddate=document.getElementById('enddate').value;
                 var varible=document.getElementById('varible').value;

                  var pos1=startdate.indexOf(dtCh);
                 var pos2=startdate.indexOf(dtCh,pos1+1);
                 var strDay =startdate.substring(0,pos1);
                 var strMonth=startdate.substring(pos1+1,pos2);
                 var strYear=startdate.substring(pos2+1);
                 startdate=strYear+"-"+strMonth+"-"+strDay;

                 strDay =enddate.substring(0,pos1);
                 strMonth=enddate.substring(pos1+1,pos2);
                 strYear=enddate.substring(pos2+1);
                 enddate=strYear+"-"+strMonth+"-"+strDay;

                 url="../StockResearch/accessdatabaseajax.php?startdate="+startdate+"&enddate="+enddate+"&varible="+varible+"&market="+market+"&companyid="+companyid;
document.getElementById("autoSuggestionsList").innerHTML='<img src="../lightwindow/images/ajax-loading.gif" />';

                     xmlhttpshu=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpshu = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
                  }
                    if (xmlhttpshu!=null)
                    {
                        xmlhttpshu.onreadystatechange=state_Change;
                        xmlhttpshu.open("GET",url,true);
                        xmlhttpshu.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }
                  return true;


    }


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr,date){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)



	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The "+date+" date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month in "+date+" date")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day in "+date+" date")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear+"in "+date+" date")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date in "+date+" date")
		return false
	}
return true
}

function checkdate(startdate,enddate){
    var daysInMonth = DaysArray(12)
	var pos1=startdate.indexOf(dtCh)
	var pos2=startdate.indexOf(dtCh,pos1+1)
	var strDay=startdate.substring(0,pos1)
    var strMonth=startdate.substring(pos1+1,pos2)
	var strYear=startdate.substring(pos2+1)
	var dtstart=new Date();
    dtstart.setFullYear(strYear,strMonth-1,strDay);
    pos1=enddate.indexOf(dtCh)
	pos2=enddate.indexOf(dtCh,pos1+1)
	strDay=enddate.substring(0,pos1)
    strMonth=enddate.substring(pos1+1,pos2)
	strYear=enddate.substring(pos2+1)
	var dtend=new Date();
    dtend.setFullYear(strYear,strMonth-1,strDay);
    if(dtstart>dtend){
        alert('start date shoud be less than end date');
        return false
    }
    var today = new Date();
    if(today<dtend){
        alert('End date shoud be less or equal to Today\'s date ');
        return false
    }
    if(today<dtstart){
        alert('Start date shoud be less or equal to Today\'s date ');
        return false
    }
     return true
}
function ValidateForm(){
	var start=document.getElementById('startdate');
	if (isDate(start.value,'Start')==false){
		start.focus()
		return false
	}
    var end=document.getElementById('enddate');
    if (isDate(end.value,'End')==false){
		end.focus()
		return false
	}
    if (checkdate(start.value,end.value)==false){
		start.focus()
		return false
	}

    return true
 }
var xmlhttpsector=null;
var xmlhttpindex=null;
function sectorindexloadforstock(companyid,market,sectorindex){

           url="sectorloadbystock.php?market="+market+"&companyid="+companyid+"&sectorindex="+sectorindex;
            if(sectorindex=='sector'){
                
                     xmlhttpsector=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpsector = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpsector = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpsector = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
                }
                    if (xmlhttpsector!=null)
                    {
                        xmlhttpsector.onreadystatechange=stateChangesSector;
                        xmlhttpsector.open("GET",url,true);
                        xmlhttpsector.send(null);

                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }
            }else{
                  xmlhttpindex=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttpindex = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttpindex = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttpindex = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                                 }
                            }
                        }
                    if (xmlhttpindex!=null)
                    {
                        xmlhttpindex.onreadystatechange=stateChangesindex;
                        xmlhttpindex.open("GET",url,true);
                        xmlhttpindex.send(null);
                    }
                    else
                    {
                         alert("Your browser does not support XMLHTTP.");
                    }
            }
}
function stateChangesSector()
{

    if (xmlhttpsector.readyState==4)
  { // 4 = "loaded"
        if (xmlhttpsector.status==200)
        {// 200 = "OK"
         document.getElementById("sectorrow").innerHTML=xmlhttpsector.responseText;
        }
        else
        {
            alert("Problem retrieving data:" + xmlhttpsector.statusText);
        }
    }
}


function stateChangesindex()
{

    if (xmlhttpindex.readyState==4)
  { // 4 = "loaded"
        if (xmlhttpindex.status==200)
        {// 200 = "OK"
         document.getElementById("indexrow").innerHTML=xmlhttpindex.responseText;
        }
        else
        {
            alert("Problem retrieving data:" + xmlhttpindex.statusText);
        }
    }
}
xmlhttptimeperiod=null
function timeperiodloadforstock(companyid,market,type){

            url="./light/ajaxfile/pv1000timeperiod.php?type="+type+"&companyid="+companyid+"&market="+market;
            
             xmlhttptimeperiod=null;
           try{
                    // Opera 8.0+, Firefox, Safari
                    xmlhttptimeperiod = new XMLHttpRequest();
                } catch (e){
                    // Internet Explorer Browsers
                    try{
                            xmlhttptimeperiod = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try{
                            xmlhttptimeperiod = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e){
                            // Something went wrong
                            alert("Your browser broke!");

                    }
            }
        }
            if (xmlhttptimeperiod!=null)
            {
                xmlhttptimeperiod.onreadystatechange=stateChangesTimePeriod;
                xmlhttptimeperiod.open("GET",url,true);
                xmlhttptimeperiod.send(null);

            }
            else
            {
                 alert("Your browser does not support XMLHTTP.");
            }
     }

function stateChangesTimePeriod()
{

    if (xmlhttptimeperiod.readyState==4)
  { // 4 = "loaded"
        if (xmlhttptimeperiod.status==200)
        {// 200 = "OK"
         document.getElementById("timeperiodcell").innerHTML=xmlhttptimeperiod.responseText;
        }
        else
        {
            alert("Problem retrieving data:" + xmlhttptimeperiod.statusText);
        }
    }
}




function lookupforAllStock(inputString,elestock,elemarket,companyhtmid) {
	if(inputString.length == 0) {
		document.getElementById("suggestions").style.display='none';
	}else{
		autosearchAllStock(inputString,elestock,elemarket,companyhtmid);
		document.getElementById("indicator").style.display='block';
		document.getElementById("suggestions").style.display='block';
	}
}

function autosearchAllStock(inputString,stockhtmid,markethtmid,companyhtmid){
	url="rpcStock.php?queryString="+inputString+"&stockhtmid="+stockhtmid+"&markethtmid="+markethtmid+"&companyhtmid="+companyhtmid;
	document.getElementById("autoSuggestionsList").innerHTML="";
	xmlhttpshu=null;
	try{
		// Opera 8.0+, Firefox, Safari
		xmlhttpshu = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			xmlhttpshu = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				xmlhttpshu = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
			}
		}
	}
	if (xmlhttpshu!=null){
		xmlhttpshu.onreadystatechange=state_Change;
		xmlhttpshu.open("GET",url,true);
		xmlhttpshu.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

function fillforAllStock(thisValue,elestock,elemarket,elestockid) {
	document.getElementById("suggestions").style.display='none';
    document.getElementById("indicator").style.display='none';
    document.getElementById("inputString").value=thisValue.toString().replace(":::", " ").toString().replace("::", " ");
    document.getElementById(elemarket).value=thisValue.toString().substring(0,thisValue.toString().indexOf("::"));
    document.getElementById(elestock).value=thisValue.toString().substring(thisValue.toString().indexOf("::")+2,thisValue.toString().indexOf(":::"));
    document.getElementById(elestockid.toString().substring(0,elestockid.toString().indexOf("::"))).value=elestockid.toString().substring(elestockid.toString().indexOf("::")+2);
    
    var market = document.getElementById(elemarket).value;
    var stock = document.getElementById(elestock).value;
    var stockid = document.getElementById(elestockid.toString().substring(0,elestockid.toString().indexOf("::"))).value;
    
    if(document.getElementById('sectorrow')!=null){
    	SectorIndexMarketLoadForStock(market,stock,stockid);
    }
    if(document.getElementById('timeperiodcell')!=null){
        if(document.getElementById('pricechart_stock')!=null)
            timeperiodloadforstock(companyid,'pricechart');
        else if(document.getElementById('presentvalue_stock')!=null)
            timeperiodloadforstock(companyid,'pv1000');
        else if(document.getElementById('putcall_stock')!=null)
            timeperiodloadforstock(companyid,'putcall');
    }
    setTimeout("document.getElementById('suggestions').style.display='none'", 200);
}

function SectorIndexLoadForMarket(){
	var market=document.getElementById('market').value;
	if(market == "-1")
		market = "AUSTRALIA";
	urlI="sector_index_loadby_market.php?market="+market+"&sectorindex=index";
	urlS="sector_index_loadby_market.php?market="+market+"&sectorindex=sector";
	
	xmlhttpindex=null;
	xmlhttpsector=null;
	try{
		// Opera 8.0+, Firefox, Safari
		xmlhttpindex = new XMLHttpRequest();
		xmlhttpsector = new XMLHttpRequest();
	}catch (e){
		// Internet Explorer Browsers
		try{
			xmlhttpindex = new ActiveXObject("Msxml2.XMLHTTP");
			xmlhttpsector = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlhttpindex = new ActiveXObject("Microsoft.XMLHTTP");
				xmlhttpsector = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
			   alert("Your browser broke!");
			}
		}
	}
	if(xmlhttpindex!=null){
		xmlhttpindex.onreadystatechange=stateChangesindex;
		xmlhttpindex.open("GET",urlI,true);
		xmlhttpindex.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
	if(xmlhttpsector!=null){
		xmlhttpsector.onreadystatechange=stateChangesSector;
		xmlhttpsector.open("GET",urlS,true);
		xmlhttpsector.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
}

var xmlhttpmarket=null;
function SectorIndexMarketLoadForStock(market,stock,stockid){
	urlS="sector_index_market_loadby_stock.php?companyid="+stockid+"&market="+market+"&sectorindex=sector";
	urlI="sector_index_market_loadby_stock.php?companyid="+stockid+"&market="+market+"&sectorindex=index";
	//urlM="http://buyselltips.net/sector_index_market_loadby_stock.php?companyid="+stockid+"&market="+market+"&sectorindex=market";
	
	xmlhttpindex=null;
	xmlhttpsector=null;
	//xmlhttpmarket=null;
	try{
		// Opera 8.0+, Firefox, Safari
		xmlhttpindex = new XMLHttpRequest();
		xmlhttpsector = new XMLHttpRequest();
		//xmlhttpmarket = new XMLHttpRequest();
	}catch (e){
		// Internet Explorer Browsers
		try{
			xmlhttpindex = new ActiveXObject("Msxml2.XMLHTTP");
			xmlhttpsector = new ActiveXObject("Msxml2.XMLHTTP");
			//xmlhttpmarket = new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlhttpindex = new ActiveXObject("Microsoft.XMLHTTP");
				xmlhttpsector = new ActiveXObject("Microsoft.XMLHTTP");
				//xmlhttpmarket = new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
			   alert("Your browser broke!");
			}
		}
	}
	if(xmlhttpindex!=null){
		xmlhttpindex.onreadystatechange=stateChangesindex;
		xmlhttpindex.open("GET",urlI,true);
		xmlhttpindex.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
	if(xmlhttpsector!=null){
		xmlhttpsector.onreadystatechange=stateChangesSector;
		xmlhttpsector.open("GET",urlS,true);
		xmlhttpsector.send(null);
	}else{
		alert("Your browser does not support XMLHTTP.");
	}
//	if(xmlhttpmarket!=null){
//		xmlhttpmarket.onreadystatechange=stateChangesMarket;
//		xmlhttpmarket.open("GET",urlM,true);
//		xmlhttpmarket.send(null);
//	}else{
//		alert("Your browser does not support XMLHTTP.");
//	}
}

function stateChangesMarket(){
	if (xmlhttpmarket.readyState==4){ // 4 = "loaded"
		if (xmlhttpmarket.status==200){// 200 = "OK"
			document.getElementById("marketrow").innerHTML=xmlhttpmarket.responseText;
        }else{
            alert("Problem retrieving data:" + xmlhttpmarket.statusText);
        }
    }
}

function enable_disable(elementType){
	var boolean = false;
	if(elementType == "pricemoving"){
		boolean = document.chat_form.pricemoving[0].checked;
	}else if(elementType == "PriceChange"){
		boolean = document.chat_form.PriceChange[0].checked;
	}else if(elementType == "volatility"){
		boolean = document.chat_form.volatility[0].checked;
	}
	
	if(boolean)
		document.getElementById("market").disabled=true;
	else
		document.getElementById("market").disabled=false;
}


 function indexsectorload(form){

              var market=document.getElementById('marketlist').value;
              url="sectorindexloadbymarket.php?market="+market;
              index='sectorrow';
               var xmlhttp=null;
                   try{
                            // Opera 8.0+, Firefox, Safari
                            xmlhttp = new XMLHttpRequest();
                        } catch (e){
                            // Internet Explorer Browsers
                            try{
                                    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try{
                                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e){
                                    // Something went wrong
                                    alert("Your browser broke!");

                            }
                    }
                }
                if (xmlhttp!=null)
                {
                    xmlhttp.onreadystatechange=function (){

                        if (xmlhttp.readyState==4 )
                      {     if (xmlhttp.status==200){
                                        document.getElementById('maindiv').innerHTML=xmlhttp.responseText;
                            }else{
                                alert("Problem retrieving data:" + xmlhttp.statusText);
                            }
                        }
                    };
                    xmlhttp.open("GET",url,true);
                    xmlhttp.send(null);

                }
                else
                {
                     alert("Your browser does not support XMLHTTP.");
                }
 }


