var sectorsdef="*AIR,*AGR,*BIO,*BML,*BNK,*BRK,*CAS,*CHM,*CMP,*COL,*CON,*DEF,*DRG,*FRT,*GLD,*HLT,*HOM,*HOS,*INS,*INT,*LDR,*MAC,*MOR,*NWK,*OIL,*OLE,*QQQ,*REF,*RES,*RET,*RLR,*SEM,*SHP,*SLV,*SME,*SOF,*SOL,*STG,*STL,*TIT,*UTL",
sectornames="Airline,Agriculture,Biotech,Base Metal,Bank,Brokerage,Casino,Chemical,Computer,Coal,Consumer,Defense/Aerospace,Drug,Freight Carrier,Gold,Healthcare,Homebuilder,Hospital,Insurance,Internet,Leader,Machinery,Mortgage Invest,Network,Oil Driller,Oil/Gas Explorer,Top QQQQ,Oil Refiner,REIT Residtl,Retail,Railroad,Semiconductor,Shipping,Silver,Semiequipment,Software,Solar,Storage,Steel/Iron,Title Insurance,Utility",
linedatesecv='N',winsize,sectvkey=new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19),sectnamekey={0:0,1:1,2:2,3:4,4:8,5:14,6:15,7:16,8:18,9:19,10:21,11:23,12:24,13:28,14:29,15:31,16:32,17:36,18:38,19:40}; 

if (screen.width>810)
   winsize='width=860,height=760';
else
   winsize='width=790,height=550,';
                              
function sortsecvdata(a,b){
  return((1.0*sectvdata[b])-(1.0*sectvdata[a]));
}

function getid(name){
  return(document.getElementById(name));
}

function inittable(){
  var l3=new Array(),n=0;
  l3[n++]='<table style="width:160px;border:1px solid #999999;" cellspacing="0" cellpadding="0" border="0">';
  l3[n++]='<tr style="padding:1px;background-color:#dddddd;text-align:center;font:bold 11px Tahoma,Arial,Helvetica,sans-serif;"><td colspan=3 width=100% height=16 valign=middle><a href="javascript:ow(\'http://www.stockconsultant.com\')">StockConsultant.com</a></td></tr>';
  l3[n++]='<tr style="padding:1px;background-color:#dddddd;"><td nowrap width="10%" id="sectvpage" style="padding-left:0px; border-bottom:1px solid #999999;font:bold 12px Tahoma,Arial,Helvetica,sans-serif;">Pg 1</td>';
  l3[n++]='<td nowrap style="border-bottom:1px solid #999999;font:bold 12px Tahoma,Arial,Helvetica,sans-serif;" valign=middle  width="60%" align=center>&nbsp;Market View</td>';
  l3[n++]='<td nowrap style="border-bottom:1px solid #999999;" width="30%" align=right><span style="height:12px;cursor:pointer;" onclick="showsectorv(1)">&nbsp; <img width=10 height=9 src="img/smleftarrow2.gif"></span>&nbsp;';
  l3[n++]='<span style="height:12px;cursor:pointer;" onclick="showsectorv(2)"><img width=10 height=9 src="img/smrightarrow2.gif">&nbsp;</span>';
  l3[n++]='</td></tr>';
  l3[n++]='<tr><td colspan=3 width="100%" nowrap><div id="innertable"></div></td></tr>';
  l3[n++]='<tr><td id="secvdate" colspan=3 style="line-height:1.7em;padding:2px;font:10px Arial, Helvetica, sans-serif;background-color:#ffffff;" valign=middle align=center></td></tr></table>';
  document.write(l3.join(""));
}

function decodesecvdata(){
  var i,ts='';
  sectvdata=sectvdata.split(',');
  if (sectvdata.length<23)
    for (i=0;i<20;i++) ts+='N,';
  else
    for (i=0;i<sectvdata.length;i++)
      if ((i<22)&(i>0)){
        if (sectvdata[i].charAt(0)=='D')
          linedatesecv=sectvdata[i].substr(2).split("=");
        else
          ts+=sectvdata[i]+',';
      }
  sectvdata=ts.split(',');
  sectvkey.sort(sortsecvdata);
}

function ow(name){
  window.open(name,'newWin',winsize+'resizable=1,toolbar=1,location=1,menubar=1,status=1,scrollbars=1,left=10,top=10,screenX=10,screenY=10').focus();
}
 
function showsectorv(num){
    var i,ts,ts2,ts3,l3=new Array(),n=0,data,s,e,
    secnames=sectornames.split(','),secdefs=sectorsdef.split(',');
    if (num==1){ s=0;e=10;}
    else{ s=10;e=20;}
    l3[n++]='<table style="background-color:#ffffff;" width="100%" cellspacing="0" cellpadding="0" border="0"><tr><td>';
    for (i=s;i<e;i++){
      if (((i+1) % 2)==0) ts='background-color:#eeeeee;'; else ts='';
      l3[n++]='<div  style="'+ts+'padding:2px 0px 2px 4px;font:normal 11px Tahoma, arial;color:#0000ff;"><a href="javascript:ow(\'http://www.stockconsultant.com/consultnow/basicplus.cgi?symbol='+secdefs[sectnamekey[sectvkey[i]]]+'\')">'+secnames[sectnamekey[sectvkey[i]]].toUpperCase()+'</a>';
      data=sectvdata[sectvkey[i]];
      if (data=='N')
        l3[n++]=' - N/A';
      else{
        data*=1.0;
        ts=' <span style="position:relative;top:0px;"><img  width=11 height=6 src="img/large';
        if (data>=0) ts+='up.gif"><font color="#009900"> ';
        else ts+='down.gif"><font color="#ff0000"> ';
        l3[n++]=ts+data+'%</font></span>';
      }
      l3[n++]='</div>';
    }
    l3[n++]='</td></tr></table>';
    if (linedatesecv.length==1) ts="No date";
    else{
      ts=dodatestuff(linedatesecv[0],linedatesecv[1],0,1);    
      ts2=ts.split(',');
      if (ts.indexOf("close")<0){
        ts3=ts2[1].split(' ');
        ts=ts3[1]+ts3[2]+' '+ts3[3]+'(delayed)';
      } else ts=ts2[1];
      ts2=ts2[0].split(' ');
      ts=ts2[1]+' '+ts2[2]+', '+ts;
    }
    getid("secvdate").innerHTML=ts;  
    if (num==1) getid("sectvpage").innerHTML="&nbsp;Pg 1";
    else getid("sectvpage").innerHTML="&nbsp;Pg 2";
    getid("innertable").innerHTML=l3.join("");
  }

function FindDay(d,m,y){
  if ((m==1)||(m==2)){
    m+=10; y--;
  } else m-=2;
  return (d + Math.floor(2.6*m - 0.2) - 38 + y + Math.floor(y/4) + Math.floor(19/4)) % 7;
}

function dodatestuff(l0,l1,num,smsize){
  var fdy=0,daystr,monthstr,yearstr,datestr,timestr,
  daynamemed = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),monthname = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  if (l0.length>6){
    daystr=Math.round(l0.substr(6,2));
    monthstr=Math.round(l0.substr(4,2));
    yearstr=Math.round(l0.substr(0,4));
    if (yearstr>1999) fdy=yearstr-1928;
    else fdy=yearstr-1900;
  }
  else{
    daystr=Math.round(l0.substr(4,2));
    monthstr=Math.round(l0.substr(2,2));
    fdy=Math.round(l0.substr(0,2));
    yearstr="20"+fdy;
  }
  if (smsize==1){
    yearstr-=2000;
    if (yearstr<10) yearstr='0'+yearstr;
    datestr=daynamemed[FindDay(daystr, monthstr, fdy)];
  } else 
    datestr=dayname[FindDay(daystr, monthstr, fdy)];
  datestr+=' '+daystr+' '+monthname[monthstr-1]+' '+yearstr;
  var strz=l1.split(":"),tz="pm",hz=parseFloat(strz[0]),mz=parseFloat(strz[1])-1;
  if (mz<0){
    mz+=60; hz--;
  } 
  if (hz<12) tz="am";
  else
    if (hz>12) hz-=12;
  if ((mz>=0)&&(mz<=9)) mz="0"+mz;
  if (((hz>=6)&&(hz<12)&&(tz=="pm")) || ((hz>=0)&&(hz<8) && (tz=="am")) 
        || (daystr=="Saturday") || (daystr=="Sunday")) 
    timestr="close";
  else 
    timestr=hz+":"+mz+" "+tz+" ET";
  if (num==0) return(datestr+', '+timestr);
}

