/* constants variables, try to be synchronized with the C code*/
var TRange=null;
var BROWSER_UNDEFINED=0;
var BROWSER_MICROSOFT=1;
var BROWSER_NETSCAPE=2;
var BROWSER_SAFARI=3;
var BROWSER_OPERA=4;

var MAX_GRAPH_SERIES=4; var MAX_SAMPLES_PER_SERIES=288;
var PAGE_WIDTH_STR ="900";  
var PAGE_WIDTH_SMALLER_STR="900";

var CGI_BIN="cgi-bin";
var CGI_PRI="cgi-pri";
var CGI_FILE="CGIhandler.cgi";
var CGI_PUBLIC_INPUT=CGI_BIN+"/"+CGI_FILE+"?";
var CGI_PRIVATE_INPUT=CGI_PRI+"/"+CGI_FILE+"?";


var link2_livesites="/"+CGI_PUBLIC_INPUT+"sort=site_name";
//var link2_livesites="site_list.html";
var iframe_livesites="<iframe id=\"ifrm\" name=\"ifrm\" src=\""+link2_livesites+"\" scrolling=\"auto\" width=940 height=540 frameborder=0>";

var ex_InvD_href="<a href=\"/examples/ExInvDirect.html\" target=\"_blank\">Click here for an example</a>";
var ex_RevG_href="<a href=\"/examples/ExRevGrade.html\" target=\"_blank\">Click here for an example</a>";
var ex_Solzone_href="<a href=\"/examples/ExSolzone.html\" target=\"_blank\">Click here for an example</a>";
var ex_Weather_href="<a href=\"/examples/ExWeather.html\" target=\"_blank\">Click here for an example</a>";

var dl_folder="downloads";  //downloads folder
var link2_brochure= "<a href=\""+dl_folder+"/SolRenView Monitoring Brochure.pdf\">SolrenView&trade; data sheet</a>";
var link2_manual=   "<a href=\""+dl_folder+"/Guide to SolrenView.pdf\">SolrenView&trade; installation manual</a>";
var link2_WeaManual="<a href=\""+dl_folder+"/Weather Station Installation Manual.pdf\">Weather Station installation manual</a>";
var link2_survey=   "<a href=\""+dl_folder+"/SolrenView order form.pdf\">SolrenView&trade; site survey</a>";
var link2_pc_sw=    "<a href=\""+dl_folder+"/PVIDAQ.zip\">Free Windows-based RS232 PV monitor</a>";
var link2_3000_sw=  "<a href=\""+dl_folder+"/SOLECTRIA MONITOR 1.04 for XP.zip\">Free RS232 data logging software (PVI3000-5300 only)</a>";

var site_info_title="";
/****/


/*start global variables*/
var windowvar;  
var interval=900; var update_link=''; var update_descr='Refresh in ';
var testheight=0;
var browser_num=GetBrowser();//BROWSER_UNDEFINED;
var bVerbose=0;//set to one to enable some alert boxes
/*used for UpdateBarGraphs*/
var bar_height_inc=7;//default
var height_inc=bar_height_inc;   var GraphTimeoutID=0; var block_index=-1;
var rgb_color=""; var GraphZoom=1.0; var glast_width=0; var glast_height=0;
var start_win_width=0; var start_win_height=0;
var ZoomFactor=1.0;
var bFastGraph=0;
var bDbug=0;

/*end for UpdateBarGraphs*/


/*start functions*/


function Move2Site(bRight)
{ var site_id=0;  var param_str; var value; 
//alert('Move2Site, bRight='+bRight);
 var search_params=location.search;
// var search_params="&cond=site_ID=350&somethingelse&paramlast";
  var param=new Array(); var value=""; var new_params=""; var search_str='site_ID';
  param=search_params.split('&');
//  alert('param:'+Array2String(param));
  var i=0; var param_strlen=0;  var j=0;
  for(i=0;i<param.length;i++)
  {
     param_str=GetParamValue(param[i],param_str, 0);
     value=GetParamValue(param[i],param_str,1);
//alert('param_str='+param_str);
     if((param_str==search_str)&&(value.length>0))
     {
       site_id=parseInt(value);     
       if(site_id>0)     
       {
         var replace_value="";
         if(bRight)
           replace_value=""+(site_id+1);
         else
           replace_value=""+(site_id-1);
         new_params+='&'+param_str+'='+replace_value;
       } //if(site_id>0)     
       else
       {
         if(i>0)
           new_params+='&';
         new_params+=param[i];
       } 
     } //'site_ID'
     if((param_str=='cond')&&(value.length>0))
     {
       var pos=value.indexOf(search_str+'=');
       if(pos>=0)
       {
         site_id=parseInt(value.substr((pos+search_str.length+1),value.length-1));

       }//if(pos>=0)
       if(site_id>0)
       {
         var replace_value=search_str+"=";
         if(bRight)
           replace_value+=""+(site_id+1);
         else
           replace_value+=""+(site_id-1);
         new_params+='&'+param_str+'='+replace_value;
       } //if(site_id>0)     
       else
       {
         if(i>0)
           new_params+='&';
         new_params+=param[i];
       }
     }//if((param_str=='cond')&&(value.length>0))
     else//save the existing params
     {
       if(i>0)
         new_params+='&';
       new_params+=param[i];
     } 
  }//for(i=0;i<param.length;i++)
  location.search=new_params;
}//Move2Site

function GetNoQuotes(checkStr)
{
  var i=0;var j=0;var check="";
  var tmpstr=""; 
  
  for(i=0;i<checkStr.length;i++)
  {
    check=checkStr.charAt(i);
    if((check!="\'")&&(check!="\""))//copy it over to tmpstr
      tmpstr+=check;
  }
//  checkStr=tmpstr;
  return tmpstr;
}//GetNoQuotes

function Array2String(myArray)
{
//alert('in Array2String');
  var i=0; var display="";
  i=0;for(i=0;i<myArray.length;i++)
  {
    display=(i==myArray.length-1)?(display+myArray[i]):(display+myArray[i]+',') ;
  }
  return display;
}
function WebLinkMatch(full_link,link)
{//check whether link is comparable to full_link
//  alert('WebLinkMatch('+full_link+','+link+')');
  if((link.length<=0)||(full_link.length<=0))
    return false;
  var pos=full_link.indexOf(link);
//  alert('WebLinkMatch: pos='+pos);
  if(pos>=0)
  {
//    alert('full'+full_link.length);
//alert('link_full.length='+link_full.length+',pos='+pos+'link.length='+link.length);
    if(full_link.length==(pos+link.length))
      return true;
  }
  return false;
}
function PrintImgDimensions(obj)
{
  var height=0; var width=0;  var obj;
  height=obj.offsetHeight; width=obj.offsetWidth;
  alert(obj.src+': '+width+' X '+height);
}
function SetObj_Value(obj,value)
{
  if(obj)
  {
    obj.value=value;
//alert('localhost: obj true='+value);
    return true;
  }
//alert('localhost: obj false');
  return false;
}
function SetObj_innerHTML(obj,innerHTML)
{ 
  if(obj)
  { obj.innerHTML=innerHTML;
    return true;
  }
  return false;
}
function GetParamValue(param_value_str,param_str, bGetValueStr)
{
  var pos=param_value_str.indexOf('='); var value_str="";
  param_str="";value_str="";//initialize them, just in case
  if(pos>0)
  {
    param_str=param_value_str.substring(0,pos); 
    value_str=param_value_str.substring(pos+1,param_value_str.length); 
    value_str=GetNoQuotes(value_str);
  }
  else
  {
    param_str=param_value_str; value_str="";
  }
  if(bGetValueStr)
    return value_str;
  else
    return param_str;
}
function GetWebDomain(linkstr) 
{ var domain_str=""; 
  var http_start_str="http://'"; //alert('in GetWebDomain:'+linkstr);
  var pos=linkstr.indexOf(http_start_str)+http_start_str.length;

  domain_str=linkstr.substring(pos, linkstr.length); //now domain string starts after http:// string

  pos=domain_str.indexOf('/'); //now get the next position of slash, that will indicate end of domain str
  domain_str=domain_str.substring(0, pos);

  return domain_str;

}
function GetWebParams(linkstr) 
{
//  alert(linkstr);
  var pos=linkstr.indexOf('?');
  if(pos<0)
    return "";
  var params_start=linkstr.substring(linkstr.indexOf('?')+1, linkstr.length);
  return params_start;
}
function lightup(imageobject, opacity)
{
  var css_opaque_class="";
  var BrowserNum=GetBrowser(); 
  if(opacity>100)
    opacity=100;//limit it
  else if(opacity<0)
    opacity==0;
//  alert('opacity='+opacity);
  switch(BrowserNum)
  {
//    case BROWSER_NETSCAPE:
//     imageobject.style.MozOpacity=opacity/100;
//    break;
    case BROWSER_NETSCAPE:
    case BROWSER_MICROSOFT:

      imageobject.className='opaque'+opacity;

    break;
    default:
      imageobject.className='opaque'+opacity;//this should work as long as the css file is included
    break;

  }//switch(BrowserNum)
  return opacity;
}//lightup
function SetOpacity(element_id,opacity,increment,next_call_ms)
{
  var call_str="";
//alert('here, id'+element_id);
  var obj=document.getElementById(element_id);
  opacity=lightup(obj, opacity);
  if((increment==0)||(next_call_ms<=0)) //we're done
    return;
  if( ((increment>0)&&(opacity<100))||((increment<0)&&(opacity>0)) )//otherwise don't do call back
  {
    opacity+=increment;
    call_str="SetOpacity('"+element_id+"',"+opacity+","+increment+","+next_call_ms+")";
    if(next_call_ms>0)//protection
      window.setTimeout(call_str,next_call_ms);  
  }//set up the next call
}//SetOpacity
function UpdateObjSrc(index, obj_id, src_array, src_array_name, next_call_ms)
{
  if(!document.getElementById(obj_id))//protection
    return -1;
  if((index>=src_array.length)||(index<0))//protection 
    index=0;
  var call_str=""; 

  document.getElementById(obj_id).src=src_array[index];

  if((next_call_ms>0))//if array only has one element, there's no point to keep refreshing the src
  {
//update index for next call
    if(index>=(src_array.length-1))
      index=0;
    else
      index++;

    call_str="UpdateObjSrc("+index+",\""+obj_id+"\","+src_array_name+",\""+src_array_name+"\","+next_call_ms+")";
    window.setTimeout(call_str,next_call_ms);  

  }//if(next_call_ms>0)

}//UpdateObjSrc
function FlashPage0UpdatePics(movie_id,replace_top,pic_id)
{
  document.getElementById(movie_id).style.display='none'; 
  document.getElementById(replace_top).style.display='block'; 
  document.getElementById(pic_id).style.display='block'; 
  SetOpacity(pic_id,0,0,0);//first set opacity of the site picture to zero

  SetOpacity(pic_id,25,25,50);//set timeout with this
}//FlashPage0UpdatePics
function Zoom(factor)
{

}//Zoom
function GetMin(a,b)
{
  if(a<b)
    return a;
  return b;
}
function GetWinHeight()
{
  if( typeof( window.innerHeight ) == 'number' ) 
  {//Non-IE
    return window.innerHeight;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {//IE 6+ in 'standards compliant mode'
//alert('IE 6: returning document.documentElement.clientHeight');
    return document.documentElement.clientHeight;  
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {//IE 4 compatible
//alert('IE 4: returning document.body.clientHeight');
    return document.body.clientHeight;    
  }
}//GetWinHeight
function GetWinWidth()
{
  if( typeof( window.innerWidth ) == 'number' ) 
  {//Non-IE
    return window.innerWidth;
  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {//IE 6+ in 'standards compliant mode'
    return document.documentElement.clientWidth;  
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {//IE 4 compatible
    return document.body.clientWidth;    
  }
}//GetWinHeight

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth+'Height='+myHeight);//  window.alert( 'Height = ' + myHeight );
}


function DisplayWinDimensions()
{
 return alertSize();
//  var height=0; var width=0;
//  ifwindow.innerHeight 
  alert('window.document.documentElement width='+window.document.documentElement.clientHeight+',height='+window.document.documentElement.clientHeight);
  alert('document.documentElement width='+document.documentElement.clientHeight+',height='+document.documentElement.clientHeight);
  alert('document.documentElement width='+window.innerWidth+',height='+window.innerHeight);
}
function getTransformProperty(element) 
{//alert('in getTransformProperty');
  var properties = ['transform', 'WebkitTransform', 'MozTransform'];
  var p;
  while (p = properties.shift()) 
  {
    if (typeof element.style[p] != 'undefined') 
      return p;
  }
  return false;
}//getTransformProperty
function ZoomPage(zoom_factor)
{ var bZoomDone=0;
  if(zoom_factor<1.0)//don't feel like zooming out
    return false;
  ZoomFactor=zoom_factor;
  var obj=window.document.body;
  var check_width=document.body.clientWidth;    var check_height=document.body.clientHeight;
//try the transform property first
  var property=getTransformProperty(obj) ;// alert(property);
  var movepercent=(50*(zoom_factor-1.0)/zoom_factor);
  if(property)
  {
    var transform_str="";
    transform_str='scale('+zoom_factor+') ';
    transform_str+='translate('+movepercent+'%,'+movepercent+'%)';
    switch(property)
    {
      case "WebkitTransform":
        obj.style.WebkitTransform=transform_str;
      break;
      case "MozTransform":
        obj.style.MozTransform=transform_str;
      break;
      case "transform":
        obj.style.transform=transform_str;
      break;
      default:
        return false;
      break;
    }//switch(property)
    return true;
  }//if(property)
//still here, so try the zoom property

  obj.style.zoom=1.0;//first set the zoom to 1

  if(obj.style.zoom)//got zoom property
  {//save body height and width b4..if the zoom works, they should change
//alert('1.b4: '+check_width+' x '+check_height+' ,after:'+document.body.clientWidth+' x '+document.body.clientHeight);
    obj.style.zoom=zoom_factor;
    if((document.body.clientWidth==check_width)&&(document.body.clientHeight==check_height))
    { // alert('no change from zoom');
    }
    else//done
    {  
      return true;
    }
  }//if(obj.style.zoom)
  return false;
}//ZoomPage
function CanZoom()
{
  if(!ZoomFactor)
    ZoomFactor=1.0;
  var save_zoom=ZoomFactor;
//alert('in CanZoom, save_zoom='+save_zoom+'ZoomFactor='+ZoomFactor);
  var check_width=document.body.clientWidth;    var check_height=document.body.clientHeight;
  if(!ZoomPage(1.1))
  { 
    if(bVerbose) 
      alert('no zoom1'); 
    return false;
  }
//alert('save_zoom='+save_zoom);
  return ZoomPage(save_zoom);//set it back to 1 after check
}//CanZoom
function ScreenRes(wdth)
{
//DisplayWinDimensions(); return;
//var body_height=window.document.body.clientHeight; var body_width=window.document.body.clientWidth;

  window.document.body.style.zoom=1;
  alert('here: screen width='+screen.width+',height='+screen.height);
  
//  alert('b4 win width='+window.width+',height='+window.height);
//  alert('b4 body W='+window.document.body.clientWidth+',H='+window.document.body.clientHeight);
//  window.width=screen.width; window.height=screen.height;

//  alert('after win width='+window.width+',height='+window.height);

  if(window.document.body.style.zoom)
    alert('got window.document.body.style.zoom='+window.document.body.style.zoom);
  else
  {
    if(window.document.body.style)
      alert('got window.document.body.style, but NO.zoom');
    else
      alert('NO window.document.body.style');
  }
  window.document.body.style.zoom = screen.width/wdth;
//  window.document.Fm.TxAre.value=wdth;

  alert("zoom=("+screen.width+"/"+wdth+")="+window.document.body.style.zoom);//(screen.width/wdth));

//  alert('BODY ('+body_width+'X'+body_height+') to ('+window.document.body.clientWidth+'X'+window.document.body.clientHeight+')');
//  alert('AFTER body W='+window.document.body.clientWidth+',H='+window.document.body.clientHeight);
  
}//ScreenRes
function SelfClose()
{
  window.opener=null;window.close();
}
function OpenGraph(open_url,WinName,zoom_factor)
{
  var width=400; var height=170;
  if(zoom_factor>1.0)
  {
    width*=zoom_factor; height*=zoom_factor;
    if(open_url.indexOf('?')>-1)
      open_url+='&zoom='+zoom_factor;
    else
      open_url+='?zoom='+zoom_factor;
  }
  var newwin;
  var win_params="toolbar=no, menubar=no, replace=true, scrollbars=no, height="+height+", width="+width;
  win_params+=",titlebar=no, location=no, status=no, directories=no";
  newwin=window.open(open_url,WinName,win_params);
  newwin.focus();
  return newwin;
}
function OpenSRVWin(open_url,WinName)
{
 var width=1000; var height=740;
  var newwin;
  var win_params="toolbar=no, menubar=no, replace=true, scrollbars=no, height="+height+", width="+width;
  win_params+=",titlebar=no, location=no, status=no, directories=no";
  newwin=window.open(open_url,WinName,win_params);
  newwin.focus();
  return newwin;
}//OpenSRVWin

function openMax(open_url,WinName)
{
  var width=900;   var height=600; 
//alert('in openMax, url='+open_url);
  if(screen)//replace with browser's properties
   {width=screen.width; height=screen.height; }
  var win_params="channelmode=yes, toolbar=no, menubar=no, scrollbars=no, resizable=no, replace=true, height="+height+", width="+width+", left=0,top=0";
  win_params+=",titlebar=no, location=no, status=no, directories=no";


  if(0==1)//(GetBrowser()!=BROWSER_MICROSOFT)
  {
    win_params+=", fullscreen=yes";
  }//if(GetBrowser()!=BROWSER_MICROSOFT)
  alert('name='+WinName+',params='+win_params);

  var newwin=window.open(open_url,WinName,win_params);
  newwin.focus();
//  alert('title='+newwin.title);

//  self.close();
  return newwin;
}//openMax
function SetWinSize(set_width,set_height)
{
//  alert('in setwinsize, setting to '+set_width+' X '+set_height);

  if( typeof( window.innerWidth ) == 'number' ) 
  {//Non-IE    
    window.innerWidth=set_width;   window.innerHeight=set_height;

  } 
  else
    window.resizeTo(set_width,set_height);

  /*
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {//alert('IE6');    //IE 6+ in 'standards compliant mode'

    document.documentElement.clientWidth=set_width;   document.documentElement.clientHeight=set_height;
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {    //alert('IE4');//IE 4 compatible
    
    window.resizeTo(set_width,set_height);
  }
*/
}//SetWinSize
function SetToMaxWindow()
{
  var set_width=900;   var set_height=600; 

  window.moveTo(0,0);

//alert('in SetToMaxWindow');
  if(screen)//replace with browser's properties
  { set_width=screen.width; set_height=screen.height; }

  alert('setting to width='+set_width+', set_height='+set_height);

  SetWinSize(set_width,set_height); return;

  if( typeof( window.innerWidth ) == 'number' ) 
  {//Non-IE
    
//    myWidth = window.innerWidth;    myHeight = window.innerHeight;
    window.innerWidth=set_width;   window.innerHeight=set_height;

  } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
  {//alert('IE6');    //IE 6+ in 'standards compliant mode'

    window.resizeTo(set_width,set_height);
//    document.documentElement.clientWidth=set_width;   document.documentElement.clientHeight=set_height;
  } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
  {    //alert('IE4');//IE 4 compatible
    
    window.resizeTo(set_width,set_height);
  }

}//SetToMaxWindow
function GetModeDescr(bMode)
{ 
  if(bMode>0) 
    return "On"; 
  else return "Off";
}//GetModeDescr
function GetFnNameFromCallee(callee_obj)
{
  var fn_name;
  fn_name=callee_obj.name;
  if(!fn_name)
  {//    alert('no');
    fn_name=callee_obj.toString();//"dunno";
    fn_name = fn_name.substr('function '.length);
    fn_name = fn_name.substr(0,fn_name.indexOf('('));

  } //!fn_name

  return fn_name;
}
function show(id, hide)
{
   document.getElementById(hide).style.display = 'none';
   document.getElementById(id).style.display = 'block';
} 
function UpdateClassName2(objID,OnRate,OffRate,Text2,Text1,Text0)
{
 var fn_str; var params; var format_txt; var next_update;
 var txtDisplay;
 var bToggle; var max_count=3;
// alert('in here');
// document.getElementById('txtTest').value='count='+this.count;

 if (typeof this.count=='undefined') //fake static var initialization, hehe
 {
//  alert(arguments.callee.name);
   this.count=0;
 }
// this.count^=1;
 if(this.count>=max_count)
   this.count=0;
 else
   this.count++;
 bToggle=this.count;

 params="'"+objID+"',"+OnRate+","+OffRate+",'"+Text2+"','"+Text1+"','"+Text0+"'"; 

// alert(format_txt);
 next_update=(bToggle)?OnRate:OffRate;

// fn_str="UpdateClassName"+"("+params+")";
 fn_str=GetFnNameFromCallee(arguments.callee)+"("+params+")";

 if((bToggle==1)||(bToggle==3) )
   document.getElementById(objID).className=Text1;//"WeaSunny1_trans";
 else if(bToggle==2)
   document.getElementById(objID).className=Text2;
 else
   document.getElementById(objID).className=Text0;

// format_txt=bToggle+":"+document.getElementById(objID).className; document.getElementById('txtTest').value=format_txt;

 window.setTimeout(fn_str,next_update);   

}//UpdateClassName

function UpdateClassName(objID,OnRate,OffRate,OnText,OffText)
{
 var fn_str; var params; var format_txt; var next_update;
 var txtDisplay;
 var bToggle;
// alert('in here');
// document.getElementById('txtTest').value='count='+this.count;

 if (typeof this.count=='undefined') //fake static var initialization, hehe
 {
//  alert(arguments.callee.name);
   this.count=0;
 }
// this.count^=1;
 if(this.count>=3)
   this.count=0;
 else
   this.count++;
 bToggle=this.count;

 params="'"+objID+"',"+OnRate+","+OffRate+",'"+OnText+"','"+OffText+"'"; 
// alert(format_txt);
 next_update=(bToggle)?OnRate:OffRate;

 fn_str="UpdateClassName"+"("+params+")";// fn_str=GetFnNameFromCallee(arguments.callee)+"("+params+")";

// txtDisplay=0ffText;
// if(bToggle==0)
// else
//   txtDisplay=0nText;
 if(bToggle==0)
   document.getElementById(objID).className=OffText;
 else if(bToggle==1)
   document.getElementById(objID).className="WeaSunny1_trans";
 else if(bToggle==2)
   document.getElementById(objID).className=OnText;
 else if(bToggle==3)
   document.getElementById(objID).className="WeaSunny1_trans";

// format_txt=bToggle+":"+document.getElementById(objID).className; document.getElementById('txtTest').value=format_txt;

 window.setTimeout(fn_str,next_update);   

}//UpdateClassName

function fmt2digits(x)
{ var digitstr;
  if(x<10)//only 1 digit
   digitstr='0'+String(x);
  else if(x>99)
   digitstr='99';//limit it for now
  else 
   digitstr=String(x);
  return digitstr;
}//fmt2digits
function GetCgiStart()
{
  var link_str=location.href;
  var cgi_start=link_str.substring(0,link_str.lastIndexOf(CGI_INPUT)+CGI_INPUT.length);
 // alert('cgi_start:'+cgi_start);
  return cgi_start;
}
function HideObj(obj,bDoHide)
{
  var opacity=(bDoHide)?0:100;
  opacity=lightup(obj,opacity);  //note for IE, lib_css file must be included for classes opaqueX
//  if(bDoHide)
//    obj.style.visibility='hidden';
//  else
//    obj.style.visibility='visible';

  return;
}
function ToSiteList()
{
  var link_str=location.href;
  link_str=GetCgiStart()+"sort=site_name";
//alert('after:'+link_str);
  location.href=link_str;
}
function updatetimer()
{
 var mins_left; var secs_left;
 var mins_str; var secs_str;
 if(update_link.length==0)//not set yet
   update_link=document.location.href;//set to default, which is just a refresh of current page

 if(interval==-1) {  location.href=update_link/*document.location.href*/; return; }
 mins_left=Math.floor(interval/60);  secs_left=interval-(mins_left*60);
 mins_str=fmt2digits(mins_left);  secs_str=fmt2digits(secs_left);

 
 if(document.getElementById('txtmsg'))
 {
//   document.getElementById('txtmsg').value="[Refresh in "+mins_str+":"+secs_str+"]";
   document.getElementById('txtmsg').value="["+update_descr+mins_str+":"+secs_str+"]";
 }
 if(document.getElementById('txtStatus'))
   document.getElementById('txtStatus').value+=" .";

 interval--;
 windowvar=window.setTimeout("updatetimer()",1000);   
}//updatetimer

function GetBrowser()
{
 var appName=navigator.appName;  
 var appStr=appName.toLowerCase(); var appVersion=navigator.appVersion.toLowerCase();
 if(bVerbose)
   alert('appName='+navigator.appName+', appVersion='+navigator.appVersion);

// alert('appStr='+appStr);
//alert('appCodeName='+navigator.appCodeName+',appName='+navigator.appName+',appVersion='+navigator.appVersion);

 if(appStr.indexOf("microsoft")>=0)   
   return BROWSER_MICROSOFT;
 else if(appVersion.indexOf("safari")>=0)
   return BROWSER_SAFARI;
 else if(appStr.indexOf("netscape")>=0)   
   return BROWSER_NETSCAPE;
 else if(appStr.indexOf("opera")>=0)
   return BROWSER_OPERA;
   return BROWSER_UNDEFINED;

}//GetBrowser
function HaveParentFrame()
{
 if((parent.document.location)&&(parent.document.location!=location.href))
   return true;//alert('has parent.document.location:'+parent.document.location);
 else
   return false;//alert('NO parent');

}//HaveParentFrame
function RedirectPage(redirect_page)
{
 location.href=redirect_page;
}
function Redirect2Login()
{
  var oldlink=location.href;
  var link_start=oldlink.substring(0,oldlink.lastIndexOf(CGI_BIN));
  var link_end=oldlink.substring(oldlink.lastIndexOf(CGI_BIN)+CGI_BIN.length,oldlink.length);
  var newlink=link_start+CGI_PRI+link_end;
//alert(newlink);
  location.href=newlink;
}
function ReplaceParamStr(search_params,replace_param,replace_value)
{
//alert("ReplaceParamStr: search_params:'"+search_params+"'");
  var params_start="";
  if(search_params.charAt(0)=='?')
    params_start=search_params.substring(1,search_params.length);
        
//alert("params_start='"+params_start+"',len="+params_start.length);
  var param=new Array(); var value=""; var new_params="";
  param=params_start.split('&');
//  alert('param:'+Array2String(param));
  var i=0; var param_strlen=0;  var j=0;  
  var param_str; 
//alert('B4:param length='+param.length+',param[0].length='+param[0].length);
  if((param.length==1)&&(param[0].length>=params_start.length))
    param_strlen=0;
  else  
    param_strlen=1;
//alert('after:param_strlen='+param_strlen);
  if(1==1)//param_strlen)
  {
    i=0;for(i=0;i<param.length;i++)
    {
      param_str=GetParamValue(param[i],param_str,0);//get param str
      value=GetParamValue(param[i],param_str,1);
      param_str=param_str.toLowerCase();
      if(param_str.length>0)
      {
//alert('['+i+']:'+param_str+',value='+value);
        switch(param_str)
        {
          case replace_param:
            if(new_params.length)//add ampersand before parameter=value pair
              new_params+='&';
            new_params+=param_str+'='+replace_value;
            break;//replace_param
          default:
            if(new_params.length)//add ampersand before parameter=value pair
              new_params+='&';   
            new_params+=param_str;
            if(value.length)
              new_params+='='+value;
            break;//default
         }//switch(param_str)
       } //if(param_str.length>0)

     }//for(i=0;i<param.length;i++)
  }//got params
  if(new_params.indexOf(replace_param+'='+replace_value)<0) //add parameter for color
  {
    if(new_params.length>0)
      new_params+='&'
    else
      new_params+='?'
    new_params+=replace_param+'='+replace_value;
  }
  if(new_params.charAt(0)!='?')
     new_params='?'+new_params; 
  return new_params;
}//ReplaceParamStr


function WrRowSeparator(height,column_span)
{// alert('in WrRowSeparator: column_span='+column_span);
  if(height<=0) return;
  var column_span_str="";

  if(column_span>0)
    column_span_str=' colspan='+column_span;
  str='<tr><td'+column_span_str+'><img src=\"/rgb/clear.gif\" height='+height+' width=1></td></tr>';
 // alert(str);
  document.write(str);
}
function FrmSRVChildResize()
{ // alert('in FrmSRVChildResize,browser='+browser_num);
//bVerbose=1;
 if(parent.document.getElementById('zoom_id'))
 {
//  if(browser_num==BROWSER_UNDEFINED)
//    browser_num=GetBrowser();

  if(browser_num==BROWSER_SAFARI)
  {
    if(parent.document.getElementById('zoom_id'))//if(parent.document.getElementById('zoom_id'))
    {
      if(bVerbose)
        alert('parent zoom='+parent.document.getElementById('zoom_id').value);
      document.body.style.zoom=parseFloat(parent.document.getElementById('zoom_id').value);
      if(document.getElementById('zoom_id'))//update self's zoom id text for own child
      {
        document.getElementById('zoom_id').value=document.body.style.zoom;
        if(bVerbose)
          alert('updating self zoom_id='+document.getElementById('zoom_id').value);
      }//if(document.getElementById('zoom_id'))
    }//if(parent.document.getElementById('zoom_id'))
  

  }//safari
 } //if(parent.document.getElementById('zoom_id'))

}//FrmSRVChildResize
function Redirect2Public()
{
  var oldlink=location.href;
  var link_start=oldlink.substring(0,oldlink.lastIndexOf(CGI_PRI));
  var link_end=oldlink.substring(oldlink.lastIndexOf(CGI_PRI)+CGI_PRI.length,oldlink.length);
  var newlink=link_start+CGI_BIN+link_end;
//alert(newlink);
  location.href=newlink;
}
function CustomStartTbl(width,top_pos)
{
  var left_pos="0";
  if(GetBrowser()==BROWSER_MICROSOFT)
    left_pos=")";
  StartTblTag(width,top_pos,left_pos,0,'');
}//CustomStartTbl
function StartTblTag(width,top_pos,left_pos,height,style_str)
{
  var print_str; 
  printf_str='<table align=center width='+width+' style="position:absolute;top:'+top_pos+'px;';
  if(left_pos>0)
    printf_str=printf_str+'left:'+left_pos+'px;';
  if(height>0)
    printf_str=printf_str+'height:'+height+'px;';
  printf_str=printf_str+style_str+'">';

//  if(height>0)
//    printf_str='<table align=center width='+width+' style="position:absolute;top:'+top_pos+'px;left:'+left_pos+'px;height:'+height+'px;'+style_str+'">';
//  else
//    printf_str='<table align=center width='+width+' style="position:absolute;top:'+top_pos+'px;left:'+left_pos+'px;'+style_str+'">';
  alert(printf_str);
  document.write(printf_str);
}//StartTblTag

function DrawOuterTbl(height)
{
  var type;
  var print_str; var left_pos="0";

  if(GetBrowser()==BROWSER_MICROSOFT)
    left_pos="0";//"29";

  StartTblTag(PAGE_WIDTH_STR,220,left_pos,height,'border-bottom:10px solid #100;border-left:10px solid #100;border-right:10px solid #100;border-color:#DCDCDC;');
  document.write('<tr><td>&nbsp;</td></tr></table>');//end table
}//DrawOuterTbl

function SetRefresh(bFocus)
{
  windowvar=window.setTimeout("updatetimer()",1000);  
  if(bFocus)
    window.focus();
}
function PrintSRVLinks(bUseMovie)
{
 var str="";
 if(bUseMovie)//print out the display to play the swf file
 {
  str="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"940\" height=\"150\" id=\"menu\" align=\"middle\">";
  str+="<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
  str+="<param name=\"movie\" value=\"menu.swf\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><param name=\"bgcolor\" value=\"#eeeeee\" /><embed src=\"menu.swf\" quality=\"high\" wmode=\"transparent\" bgcolor=\"#eeeeee\" width=\"940\" height=\"150\" name=\"menu\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
  str+="</object>";
 } 
 else//format cells to display individual links
 {
  str="<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"940\">";
  str+="<tr><td width=\"940\" colspan=\"6\"><img src=\"images/h_header.jpg\" border=\"0\" /></td></tr><tr>";
  str+="<Td valign=\"top\"><a href=\"h_home.html\"><img src=\"images/h_home.jpg\" border=\"0\" /></a></Td>";
  str+="<Td valign=\"top\"><a href=\"h_products.html\"><img src=\"images/h_products.jpg\" border=\"0\" /></a></Td>";
  str+="<Td valign=\"top\"><a href=\"h_livesites.html\"><img src=\"images/h_livesites.jpg\" border=\"0\" /></a></Td>";
  str+="<Td valign=\"top\"><a href=\"h_downloads.html\"><img src=\"images/h_downloads.jpg\" border=\"0\" /></a></Td>";
  str+="<Td valign=\"top\"><a href=\"h_contact.html\"><img src=\"images/h_contact.jpg\" border=\"0\" /></a></Td>";
  str+="<Td valign=\"top\"><a href=\"http://www.solren.com\" target=\"_blank\"><img src=\"images/h_solren.jpg\" border=\"0\" /></a></Td>";
  str+="</tr></table>";
 }//format individual links 
 document.write(str);
}//PrintSRVLinks
function GetKeyCode(e)
{
 var KeyID;
 if(e&&e.which)
   KeyID=e.which;
 else 
   KeyID=event.keyCode;
 return KeyID;
}
function GraphPageResize()
{
  if((glast_width==0)&&(glast_height==0))
  {
    glast_width=start_win_width; glast_height=start_win_height;
//    ZoomPage(GraphZoom);
    return; 
  }
    
  var WinWidth=GetWinWidth(); var WinHeight=GetWinHeight(); 
  var width_diff=Math.abs(glast_width-WinWidth); var height_diff=Math.abs(glast_height-WinHeight);
  document.title=GetWinWidth()+' x '+GetWinHeight();
    
  if((width_diff<100)&&(height_diff<100))//this is to prevent excessive triggers from IE
  {
    return;
  }
  var height_ratio=(WinHeight/start_win_height); var width_ratio=(WinWidth/start_win_width);
  var min_ratio=GetMin(height_ratio,width_ratio);//get and use only the minimum of the two

  document.title+=' min_ratio='+min_ratio;

  if(min_ratio>=1.0)
  {
    GraphZoom=min_ratio;
    ZoomPage(GraphZoom);
  }
  glast_width=WinWidth; glast_height=WinHeight;

  document.title+=' zoom='+GraphZoom;

}//GraphPageResize
function testload()
{
//alert('in testload');
  ZoomPage(GraphZoom);
  start_win_width=GetWinWidth(); start_win_height=GetWinHeight();
//  glast_width=start_win_width; glast_height=start_win_height;
//  GraphPageResize();
}
function CheckGraphParams()
{
  var linkstr=location.href; 
  var params_start=linkstr.substring(linkstr.indexOf('?')+1, linkstr.length);
  var param=new Array(); var value="";
  param=params_start.split('&');
  var i=0; var param_strlen=0;  var j=0;  
  var param_str; 
  if((param.length==1)&&(param[0].length>=linkstr.length))
    param_strlen=0;
  else 
    param_strlen=1;

  if(param_strlen)
  {
    i=0;for(i=0;i<param.length;i++)
    {
      param_str=GetParamValue(param[i],param_str,0);//get param str
      value=GetParamValue(param[i],param_str,1);
      param_str=param_str.toLowerCase();
      switch(param_str)
      {
        case "rgb":
          if(value.length)
            rgb_color=value;
        break;
        case "zoom":
          if(value.length)
          {
              ZoomPage(parseFloat(value));
          } 
        break;
        case "fast":
          if(value.length)
            bFastGraph=parseInt(value);
          else 
            bFastGraph=1;
        break;
        case "dbug":
          bDbug=(value.length)?parseInt(value):1;
        break;
      }//switch(param_str)

    }//for(i=0;i<param.length;i++)
  }//got params

}//CheckGraphParams()
function ShowLine(checkobj,Line_element)
{  var graphObj;
  graphObj=document.getElementById(Line_element);
  if(graphObj)
  {
    if(checkobj.checked)
    {
      graphObj.style.visibility='visible';
    }
    else
    {
      graphObj.style.visibility='hidden';
    }
  }
}//ShowLine

function UpdateGraphBlocks(graphIndex)
{
  var graph_element="g"+graphIndex;
  if(rgb_color.length)//overwrite color
  {
//    if(block_index<0)//not used yet
//    {
//alert('block_index='+block_index);
      block_index=0; 
      while(block_index<MAX_GRAPH_SERIES)
      {
        var block_element=graph_element+'_block'+block_index;//ie g0_block0
        if(document.getElementById(block_element))
        {    //          alert('got element '+block_element);
          document.getElementById(block_element).src='/RGB/clear.gif';
          document.getElementById(block_element).style.backgroundColor=rgb_color;
          block_index++;
        }//if(document.getElementById(block_element))
        else
          break;
       } //while(document.getElementById(block_element))
//     }//if(block_index<0)
  } //if(rgb_color.length)//overwrite color
}//UpdateGraphBlocks
function UpdateBarGraphs(graphIndex,height_array,height_array_name,next_call_ms)
{
  var call_str="";
  var graph_element="g"+graphIndex; var bGraphNotFinished=0; 
  if(document.getElementById(graph_element))//got graph element
  {
    var check_element="";    i=0; var max_height=0;
    while(i<=MAX_SAMPLES_PER_SERIES)/*this loop goes through all the bar elements in the graph, and increment them all by 1 if necessary */
    {
      check_element=graph_element+'_'+i;
      if(document.getElementById(check_element))
      {       
        if(height_array[i]>max_height)
          max_height=height_array[i];//update max_height

        if(document.getElementById(check_element).height<height_array[i])
        {
          bGraphNotFinished=1;//assert that the graph isn't done yet
          document.getElementById(check_element).height+=height_inc; //increment
        }//current height is still less than final height
        else if(document.getElementById(check_element).height>height_array[i])//overshot a bit
          document.getElementById(check_element).height=height_array[i];
        if(rgb_color.length)//overwrite color
        {
          if(block_index<0)//not used yet
          {
            UpdateGraphBlocks(graphIndex);

/*
//alert('block_index='+block_index);
            block_index=0; 
            while(block_index<MAX_GRAPH_SERIES)
            {
              var block_element=graph_element+'_block'+block_index;//ie g0_block0
              if(document.getElementById(block_element))
              {    //          alert('got element '+block_element);
                document.getElementById(block_element).src='/RGB/clear.gif';
                document.getElementById(block_element).style.backgroundColor=rgb_color;
                block_index++;
              }//if(document.getElementById(block_element))
              else
                break;
            } //while(document.getElementById(block_element))
*/
          }//if(block_index<0)



          document.getElementById(check_element).src='/RGB/clear.gif'; document.getElementById(check_element).style.backgroundColor=rgb_color;
        } //if(rgb_color.length)//overwrite color
       i++;
      }
      else//done with elements for this graph
        break;
    }//while(i<=MAX_SAMPLES_PER_SERIES)

    if(next_call_ms>0)//more to go
    {//set up timer for next call

      if(GraphTimeoutID>0)//first make sure this is canceled
        clearTimeout (GraphTimeoutID);
      call_str="";//initialize to empty first
      if(bGraphNotFinished==0)
      { 
        graphIndex++;//increment to the next graph
        graph_element="g"+graphIndex;
        if(document.getElementById(graph_element))
        {
          height_array_name=graph_element+"_height"; //and update name of the array for the next graph
         
        }// if(document.getElementById(graph_element)
        else
        {
         next_call_ms=0; //alert('should be done');
        }
        height_inc=bar_height_inc;//reset to default increment for next graph
      } 
      else//not done, see if we need to update height_inc
      {
        if((max_height<60)&&(height_inc>=bar_height_inc))//decrease the increment by half if the final height is less than 60 percent
          height_inc=(bar_height_inc/2);
      }
      call_str="UpdateBarGraphs("+graphIndex+","+height_array_name+",'"+height_array_name+"',"+next_call_ms+")";
      if((call_str.length>0)&&(next_call_ms>0))
      { 
        GraphTimeoutID=window.setTimeout(call_str,next_call_ms);  
      } 
      else
        GraphTimeoutID=0;//set to zero
    }//more to go, set up timer for next call

  }//if(document.getElementById(graph_element))
  else//graph_element not found, no need to continue timeout
  {
//alert('done');
  }//graph_element not found, no need to continue timeout

//  if(next_call_ms>0)

}//UpdateBarGraphs
function FinishBarGraphs(graphIndex,height_array)
{
  var i=0;
  var graph_element="g"+graphIndex;
  if(document.getElementById(graph_element))//got graph element
  {
    while(i<=MAX_SAMPLES_PER_SERIES)/*this loop goes through all the bar elements in the graph, and increment them all by 1 if necessary */
    {
      check_element=graph_element+'_'+i;
      if(document.getElementById(check_element))
      {
        document.getElementById(check_element).height=height_array[i];

        if(rgb_color.length)//overwrite color
        {
          if(block_index<0)//not used yet
            UpdateGraphBlocks(graphIndex);
          document.getElementById(check_element).src='/RGB/clear.gif'; document.getElementById(check_element).style.backgroundColor=rgb_color;

        }//if(rgb_color.length)//overwrite color

      }//got check_element
      else//done with elements for this graph
        break;

      i++;
    }//while(i<=MAX_SAMPLES_PER_SERIES)


  } //got graph element

}//FinishBarGraphs
function ClearGraphingTimeout(graph_element,height_array)//clear any pending timeout from GraphTimeoutID, and displays all the graphs without animation
{
  var check_element="";
  if(GraphTimeoutID!=0)
  {
    clearTimeout (GraphTimeoutID);
    GraphTimeoutID=0;
  }
  
  //just to be sure, run through the array and manually set everything 
  i=0;for(i=0;i<height_array.length;i++)
  {
    check_element=graph_element+'_'+i;
    if(document.getElementById(check_element))
    {
      document.getElementById(check_element).height=height_array[i];
    }//if(document.getElementById(check_element))

  }//(i=0;i<height_array.length;i++)
}//ClearPreviousGraphing

function CheckSearch2(txt,e)
{//note e is event object passed in, doesn't seem to work if I use event object directly, needs to be passed in from function call

 var KeyID = GetKeyCode(e);

 if(KeyID==13)//enter key
    FindString(txt.value);  
}
function CheckSearch(txt)
{
 var KeyID = (window.event)? event.keyCode : e.which;//  alert(keyID);
 if(KeyID==13)
    FindString(txt.value);  
}
function FindString (str) {
 if (parseInt(navigator.appVersion)<4) return;
 var strFound;
 if (window.find) {

  // CODE FOR BROWSERS THAT SUPPORT window.find

  strFound=self.find(str);
  if (strFound && self.getSelection && !self.getSelection().anchorNode) {
   strFound=self.find(str)
  }
  if (!strFound) {
   strFound=self.find(str,0,1)
   while (self.find(str,0,1)) continue
  }
 }
 else if (navigator.appName.indexOf("Microsoft")!=-1) {

  // EXPLORER-SPECIFIC CODE

  if (TRange!=null) {
   TRange.collapse(false)
   strFound=TRange.findText(str)
   if (strFound) TRange.select()
  }
  if (TRange==null || strFound==0) {
   TRange=self.document.body.createTextRange()
   strFound=TRange.findText(str)
   if (strFound) TRange.select()
  }
 }
 else if (navigator.appName=="Opera") {
  alert ("Opera browsers not supported, sorry...")
  return;
 }
 if (!strFound) alert ("String '"+str+"' not found!")
 return;
}
function custom_onload()
{
  var link_str=location.href;
  var display_page=0;  var bViewPVDetails=0; var bViewSummary=0;

  if(link_str.indexOf("sort=pvi_IDs&cond=site_ID")>=0)  //summary page
    display_page=1;
  else if (link_str.indexOf("view=")>=0)//inverter direct graphs
    display_page=2;

  bViewSummary=(display_page==1)?1:0;   bViewPVDetails=(display_page==2)?1:0;

  if(bViewSummary)
    {windowvar=window.setTimeout("updatetimer()",1000);  }
  else if(bViewPVDetails) 
  {
  }

//alert('bViewSummary='+bViewSummary+',bViewPVDetails='+bViewPVDetails);
}//custom_onload


function testfunction()
{
  alert("testheight="+testheight);
  
//  document.write("blah");
  return;
  alert("appCodeName="+navigator.appCodeName);//
  alert("appName="+navigator.appName);//
  alert("userAgent="+navigator.userAgent);
}

