var P1Content = "";
var P1Url = "";
var P2Content = "";
var P2Url = "";
var P3Content = "";
var P3Url = "";
var P4Content = "";
var P4Url = "";
var P5Content = "";
var P5Url = "";
var P6Content = "";
var P6Url = "";
var P1Refresh = 0;
var P2Refresh = 0;
var P3Refresh = 0;
var P4Refresh = 0;
var P5Refresh = 0;
var P6Refresh = 0;
var xml1Http;
var xml2Http;
var xml3Http;
var xml4Http;
var xml5Http;
var xml6Http; 
var Panel1Update;
var Panel2Update;
var Panel3Update;
var Panel4Update;
var Panel5Update;
var Panel6Update;
var CurrentPanel;
var Q1;
var Q2;
var Q3;
var Q4;
var Q5;
var Q6;
var TestMode = 0;
var AltMode = 0;
var Sat24Count = 0;
var metWarnResp = "";
var metRSSCount = 0;
var metRSS = new Array();
var rssRotateID;
var TheWeatherEnabled = 0;
var metRSSEnabled = 0;

function SetContent(scContent,scPanel) {
if (scContent == "") { return; } else {
  if (scPanel == 1) {
   document.getElementById("content1").innerHTML=scContent;
    if (P1Refresh > 0) { clearTimeout(Panel1Update); Panel1Update = setTimeout("UpdateContent(1)", P1Refresh*1000); xml1Http = null;}
   }
   if (scPanel == 2) {
   document.getElementById("content2").innerHTML=scContent;
    if (P2Refresh > 0) { clearTimeout(Panel2Update); Panel2Update = setTimeout("UpdateContent(2)", P2Refresh*1000); xml2Http = null;}
   }
   if (scPanel == 3) {
   document.getElementById("content3").innerHTML=scContent;
    if (P3Refresh > 0) { clearTimeout(Panel3Update); Panel3Update = setTimeout("UpdateContent(3)", P3Refresh*1000); xml3Http = null;}
   }
   if (scPanel == 4) {
   document.getElementById("content4").innerHTML=scContent;
    if (P4Refresh > 0) { clearTimeout(Panel4Update);Panel4Update = setTimeout("UpdateContent(4)", P4Refresh*1000); xml4Http = null;}
   }
   if (scPanel == 5) {
   document.getElementById("content5").innerHTML=scContent;
    if (P5Refresh > 0) { clearTimeout(Panel5Update); Panel5Update = setTimeout("UpdateContent(5)", P5Refresh*1000); xml5Http = null;}
   }
   if (scPanel == 6) {
   document.getElementById("content6").innerHTML=scContent;
    if (P6Refresh > 0) { clearTimeout(Panel6Update); Panel6Update = setTimeout("UpdateContent(6)", P6Refresh*1000); xml6Http = null;}
   }
 //tb_remove();
 //executeJavaScript(scPanel);
 tb_init('a.thickbox_new, area.thickbox_new, input.thickbox_new');
 document.getElementById("CopyLink").innerHTML='<br><hr><br>The panels you have open, and the screen layout are contained in the link below:<br><small><a href="' + NewPageReq() + '">' + NewPageReq() + '</a></small><br/><b>BEFORE YOU BOOKMARK THIS PAGE - CLICK THE LINK ABOVE TO SAVE YOUR SETTINGS!</b><br/><br/><a href="#" onClick="toggleLayer(\'CopyLink\')">Close This Box</a>';
 scContent = null;
 scPanel = null;
 }
 }
 
 function GetContent() {
 var tmpResp;
 var PanelID;
 tmpResp = "";

if (xml1Http == null) {} else {if (xml1Http.readyState == 4) { SetContent(xml1Http.responseText,1); xml1Http = null;}}
if (xml2Http == null) {} else {if (xml2Http.readyState == 4) { SetContent(xml2Http.responseText,2); xml2Http = null;}}
if (xml3Http == null) {} else {if (xml3Http.readyState == 4) { SetContent(xml3Http.responseText,3); xml3Http = null;}}
if (xml4Http == null) {} else {if (xml4Http.readyState == 4) { SetContent(xml4Http.responseText,4); xml4Http = null;}}
if (xml5Http == null) {} else {if (xml5Http.readyState == 4) { SetContent(xml5Http.responseText,5); xml5Http = null;}}
if (xml6Http == null) {} else {if (xml6Http.readyState == 4) { SetContent(xml6Http.responseText,6); xml6Http = null;}}
 
}

 function UpdateContent(PanelID){
 //alert('UpdateContent: ' + PanelID);
 if (PanelID == 1) {
  if (P1Url == "") {} else {
   xml1Http=GetXmlHttpObject();
   if (xml1Http==null)
  {
  return;
  } 
 var url=P1Url;
 url=url+"?sid="+Math.random();
 //alert('URL: ' + url);
 xml1Http.onreadystatechange=GetContent;
 xml1Http.open("GET",url,true);
 xml1Http.send(null);
}
}

 if (PanelID == 2) {
  if (P2Url == "") {} else {
   xml2Http=GetXmlHttpObject();
   if (xml2Http==null)
  {
  return;
  } 
 var url=P2Url;
 url=url+"?sid="+Math.random();
 xml2Http.onreadystatechange=GetContent;
 xml2Http.open("GET",url,true);
 xml2Http.send(null);
}
}

 if (PanelID == 3) {
  if (P3Url == "") {} else {
   xml3Http=GetXmlHttpObject();
   if (xml3Http==null)
  {
  return;
  } 
 var url=P3Url;
 url=url+"?sid="+Math.random();
 xml3Http.onreadystatechange=GetContent;
 xml3Http.open("GET",url,true);
 xml3Http.send(null);
}
}

 if (PanelID == 4) {
  if (P4Url == "") {} else {
   xml4Http=GetXmlHttpObject();
   if (xml4Http==null)
  {
  return;
  } 
 var url=P4Url;
 url=url+"?sid="+Math.random();
 xml4Http.onreadystatechange=GetContent;
 xml4Http.open("GET",url,true);
 xml4Http.send(null);
}
}

 if (PanelID == 5) {
  if (P5Url == "") {} else {
   xml5Http=GetXmlHttpObject();
   if (xml5Http==null)
  {
  return;
  } 
 var url=P5Url;
 url=url+"?sid="+Math.random();
 xml5Http.onreadystatechange=GetContent;
 xml5Http.open("GET",url,true);
 xml5Http.send(null);
}
}

 if (PanelID == 6) {
  if (P6Url == "") {} else {
   xml6Http=GetXmlHttpObject();
   if (xml6Http==null)
  {
  return;
  } 
 var url=P6Url;
 url=url+"?sid="+Math.random();
 xml6Http.onreadystatechange=GetContent;
 xml6Http.open("GET",url,true);
 xml6Http.send(null);
}
}
tmpResp = null;
PanelID = null;
url = null;
}

function ParseContent(pcName, pcID) {
var tmpName;
var tmpUrl;
var tmpRefresh;
//alert('ParseContent: ' + pcName + ',' + pcID);
if (pcName == "") { return; }
if (pcName == "TRAC") { tmpName = "TRAC"; tmpUrl = "trac2.php"; tmpRefresh = 10; }
else if (pcName == "RStrikes") { tmpName = "RStrikes"; tmpUrl = "r-strikes.php"; tmpRefresh = 10; }
else if (pcName == "Nexstorm") { tmpName = "Nexstorm"; tmpUrl = "nexstorm.php"; tmpRefresh = 30; }
else if (pcName == "Sat24") { tmpName = "Sat24"; tmpUrl = "sat24.php"; tmpRefresh = 300; }
else if (pcName == "Meteox") { tmpName = "Meteox"; tmpUrl = "meteox.php"; tmpRefresh = 300; }
else if (pcName == "GCam") { tmpName = "GCam"; tmpUrl = "webcam.php"; tmpRefresh = 10; }
else if (pcName == "FalkirkCam") { tmpName = "FalkirkCam"; tmpUrl = "falkirk-webcam.php"; tmpRefresh = 60; }
else if (pcName == "Wasp2") { tmpName = "Wasp2"; tmpUrl = "wasp2.php"; tmpRefresh = 30; }
else if (pcName == "Trac2") { tmpName = "Trac2"; tmpUrl = "trac2.php"; tmpRefresh = 10; }
else if (pcName == "testpanel") { tmpName = "testpanel"; tmpUrl = "testpanel.php"; tmpRefresh = 60; }
else if (pcName == "blitz") { tmpName = "blitz"; tmpUrl = "blitzortung.php"; tmpRefresh = 60; }
else if (pcName == "ukasfscotland") { tmpName = "ukasfscotland"; tmpUrl = "ukasf-scotland.php"; tmpRefresh = 900; }
else if (pcName == "Sat242") { tmpName = "Sat242"; tmpUrl = "sat24-2.php"; tmpRefresh = 300; }
else { return; }

if (pcID == "") { return; }
if (pcID == 1) { P1Content = tmpName; P1Url = tmpUrl; P1Refresh = tmpRefresh; clearTimeout(Panel1Update); UpdateContent(1);}
else if (pcID == 2) { P2Content = tmpName; P2Url = tmpUrl; P2Refresh = tmpRefresh; clearTimeout(Panel2Update); UpdateContent(2);}
else if (pcID == 3) { P3Content = tmpName; P3Url = tmpUrl; P3Refresh = tmpRefresh; clearTimeout(Panel3Update); UpdateContent(3);}
else if (pcID == 4) { P4Content = tmpName; P4Url = tmpUrl; P4Refresh = tmpRefresh; clearTimeout(Panel4Update); UpdateContent(4);}
else if (pcID == 5) { P5Content = tmpName; P5Url = tmpUrl; P5Refresh = tmpRefresh; clearTimeout(Panel5Update); UpdateContent(5);}
else if (pcID == 6) { P6Content = tmpName; P6Url = tmpUrl; P6Refresh = tmpRefresh; clearTimeout(Panel6Update); UpdateContent(6);}

tmpName = null;
tmpUrl = null;
tmpRefresh = null;
pcName = null;
pcID = null;
} 

function ChangeOptions(coOption,coPanel)
{
if (coOption == "NONE") {
ResetPanel(coPanel);
}
else {
ParseContent(coOption,coPanel);
}

coOption = null;
coPanel = null;
}

function ResetPanel(rpPanelID) {
var emptyCont = "<img src='empty.jpg'></img>";

if (rpPanelID == 1) { P1Content = ""; P1Url = ""; P1Refresh = 0; SetContent(emptyCont,1); clearTimeout(Panel1Update);}
if (rpPanelID == 2) { P2Content = ""; P2Url = ""; P2Refresh = 0; SetContent(emptyCont,2); clearTimeout(Panel2Update);}
if (rpPanelID == 3) { P3Content = ""; P3Url = ""; P3Refresh = 0; SetContent(emptyCont,3); clearTimeout(Panel3Update);}
if (rpPanelID == 4) { P4Content = ""; P4Url = ""; P4Refresh = 0; SetContent(emptyCont,4); clearTimeout(Panel4Update);}
if (rpPanelID == 5) { P5Content = ""; P5Url = ""; P5Refresh = 0; SetContent(emptyCont,5); clearTimeout(Panel5Update);}
if (rpPanelID == 6) { P6Content = ""; P6Url = ""; P6Refresh = 0; SetContent(emptyCont,6); clearTimeout(Panel6Update);}

rpPanelID = null;
}

function ResetAllPanels() {
ResetPanel(1);
ResetPanel(2);
ResetPanel(3);
ResetPanel(4);
ResetPanel(5);
ResetPanel(6);
document.selPanel.optsPanel1.options[0].selected=true;
document.selPanel.optsPanel2.options[0].selected=true;
document.selPanel.optsPanel3.options[0].selected=true;
document.selPanel.optsPanel4.options[0].selected=true;
document.selPanel.optsPanel5.options[0].selected=true;
document.selPanel.optsPanel6.options[0].selected=true;
}

function NewPageReq() {
var tmpLink;
tmpLink = "http://www.bordersweather.co.uk/storm_track/?args=1";
if (P1Content == "") {} else { tmpLink = tmpLink + "&P1=" + P1Content; }
if (P2Content == "") {} else { tmpLink = tmpLink + "&P2=" + P2Content; }
if (P3Content == "") {} else { tmpLink = tmpLink + "&P3=" + P3Content; }
if (P4Content == "") {} else { tmpLink = tmpLink + "&P4=" + P4Content; }
if (P5Content == "") {} else { tmpLink = tmpLink + "&P5=" + P5Content; }
if (P6Content == "") {} else { tmpLink = tmpLink + "&P6=" + P6Content; }
if (AltMode == 0) {} else { tmpLink = tmpLink + "&mode=2"; }
return tmpLink;
tmpLink = null;
}

function CheckQuery() {
if (Q1 == "") {} else { ChangeOptions(Q1,1); Q1=null; SetStoredOption(1); } 
if (Q2 == "") {} else { ChangeOptions(Q2,2); Q2=null; SetStoredOption(2); }
if (Q3 == "") {} else { ChangeOptions(Q3,3); Q3=null; SetStoredOption(3); }
if (Q4 == "") {} else { ChangeOptions(Q4,4); Q4=null; SetStoredOption(4); }
if (Q5 == "") {} else { ChangeOptions(Q5,5); Q5=null; SetStoredOption(5); }
if (Q6 == "") {} else { ChangeOptions(Q6,6); Q6=null; SetStoredOption(6); }
}

function SetStoredOption(ssoID) {
var i;
if (ssoID == 1) { 
for(i=1; i <= document.selPanel.optsPanel1.options.length-1; i++) {
if (document.selPanel.optsPanel1.options[i].value == P1Content) { document.selPanel.optsPanel1.options[i].selected = true; }
}
}
if (ssoID == 2) { 
for(i=1; i <= document.selPanel.optsPanel2.options.length-1; i++) {
if (document.selPanel.optsPanel2.options[i].value == P2Content) { document.selPanel.optsPanel2.options[i].selected = true; }
}
}

if (ssoID == 3) { 
for(i=1; i <= document.selPanel.optsPanel3.options.length-1; i++) {
if (document.selPanel.optsPanel3.options[i].value == P3Content) { document.selPanel.optsPanel3.options[i].selected = true; }
}
}

if (ssoID == 4) { 
for(i=1; i <= document.selPanel.optsPanel4.options.length-1; i++) {
if (document.selPanel.optsPanel4.options[i].value == P4Content) { document.selPanel.optsPanel4.options[i].selected = true; }
}
}

if (ssoID == 5) { 
for(i=1; i <= document.selPanel.optsPanel5.options.length-1; i++) {
if (document.selPanel.optsPanel5.options[i].value == P5Content) { document.selPanel.optsPanel5.options[i].selected = true; }
}
}

if (ssoID == 6) { 
for(i=1; i <= document.selPanel.optsPanel6.options.length-1; i++) {
if (document.selPanel.optsPanel6.options[i].value == P6Content) { document.selPanel.optsPanel6.options[i].selected = true; }
}
}
i = null;
ssoID = null;
}

       function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function executeJavaScript(ejs) {
}

function GenerateMetRSSArray(rssStr) {
if (rssStr == metWarnResp) { return; }
metWarnResp = rssStr;
clearTimeout(rssRotateID);
metRSS = null;
metRSS = new Array();

var tmpArr = rssStr.split("#SEP#");

for(var i=0;i < tmpArr.length;i++)
    {  
        if (tmpArr[i] !=='') { metRSS[i] = tmpArr[i]; }   
    }  
metRSSCount = -1;

 var tmpStr;
 tmpStr = metRSS[0];
  if (tmpStr.indexOf('No Met Office Warnings') == -1) {
    var tmpCount;
    tmpCount = metRSS.length;
    //tmpCount = tmpCount-1;
    document.getElementById("showmettext").innerHTML = "<b><font color=\"red\"><img src=\"ani_exclamation.gif?sid="+Math.random() + "\" border=0 height=25 width=25>*** SHOW MET WARNINGS: " + tmpCount + " ***</b></font>";
    document.getElementById("hidemettext").innerHTML = "<font color=\"blue\"><img src=\"error.png?sid="+Math.random() + "\" border=0 height=16 width=16> Hide Met Warnings</font>";
   } else { document.getElementById("showmettext").innerHTML = "<font color=\"blue\"><img src=\"info.png?sid="+Math.random() + "\" border=0 height=16 width=16> Show Met Warnings</font>";
            document.getElementById("hidemettext").innerHTML = "<font color=\"blue\"><img src=\"info.png?sid="+Math.random() + "\" border=0 height=16 width=16> Hide Met Warnings</font>";
    }
 
CycleMetRSS();
tmpArr = null;
i = null;
tmpStr = null;
}

function CycleMetRSS() { 
if (metRSSEnabled == 0) { return; }
metRSSCount = metRSSCount +1;
if (metRSSCount >= metRSS.length) { metRSSCount = 0; }
 var tmpStr;
 tmpStr = metRSS[0];
  if (tmpStr.indexOf('No Met Office Warnings') == -1) {
   document.getElementById("MetRSS").innerHTML = "<b>" + (metRSSCount +1) + " of " + (metRSS.length) + ": </b>" +  metRSS[metRSSCount];
  } else 
  {
  document.getElementById("MetRSS").innerHTML = metRSS[metRSSCount]; 
  }
rssRotateID = setTimeout("CycleMetRSS()", 5000);
tmpStr = null;
}

function ResetWarningsText() {
var tmpStr;
tmpStr = metRSS[0];
  if (tmpStr.indexOf('No Met Office Warnings') == -1) {
    var tmpCount;
    tmpCount = metRSS.length;
    document.getElementById("showmettext").innerHTML = "<b><img src=\"error.png?sid="+Math.random() + "\" border=0 height=16 width=16> Show Met Warnings: " + tmpCount + "</b>";
}
else {
    document.getElementById("showmettext").innerHTML = "<img src=\"info.png?sid="+Math.random() + "\" border=0 height=16 width=16> Show Met Warnings";
}
tmpStr = null;
tmpCount = null;
}

function ToggleWeather() {
if (TheWeatherEnabled == 0) { TheWeatherEnabled = 1; UpdateTheWeather();}
else { TheWeatherEnabled = 0; }
}

function ToggleRSSCycle() {
if (metRSSEnabled == 0) { metRSSEnabled =1; metRSSCount = -1; CycleMetRSS(); } else { metRSSEnabled = 0; } 
}
