// JavaScript Document
var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
var bandwidth = null;
var chosenBandwidth = null;
var mediaThroughput = 0;
var count;
var maxcountdown;
var fredlayer = null;
var fieldXlayer = null;
var smr03layer = null;
var legendlayer = null;;
var imglayer = null;
var lidlayer = null;
var tidlayer = null;
var sclayer = null;
var high = "high";
var low = "low";
var fredLeft;
var fredTop;
var newwin;
var vreset = false;
var nocookies = false;
// window.onresize = get_form_coordinates;

function getLayer(layer)
{
    var mylayer = null;
  	    if(ns4){
           //thisbrowser="NN4";
           mylayer = document.layers[layer];
        }
        else if (ie4) {
           //thisbrowser="ie"
           mylayer = document.all[layer];
        }
	    else{ 
           //thisbrowser="NN6";
           mylayer = document.getElementById(layer);
        }
	return mylayer;
}

function countdown(){
	// alert("location: "+document.location.hostname);
    if (!fredlayer)fredlayer=getLayer("fred");
    if (fredlayer)
	{
	    fredlayer.style.posLeft = fredLeft;
        fredlayer.style.posTop = fredTop;
	    fredlayer.style.border = "0";
        fredlayer.style.width = "180 px";
    }
	count--; 
    changelayer_content(count);
    if (count>0)
	{
        Id = window.setTimeout("countdown()",1000); 
    }
	else if (!count)get_radio_value(null);
    
	if (!fieldXlayer)
	{
	    fieldXlayer=getLayer("fieldX");
	    if (fieldXlayer)
		{
		    fieldXlayer.style.width = "400px";
		}
	}

	if (!smr03layer)
	{
	   smr03layer=getLayer("smr03");
	   if (smr03layer)
	   {
	        smr03layer.style.visibility = "visible";
		    smr03layer.style.width = "480px";
	   }
    }
		   
}	
function stopButton(todo)
{
    if (!sclayer)sclayer = getLayer("sc");
	if (sclayer)
	{
	   if (todo == "enable")
 	   {
	       sclayer.disabled=false;
	       sclayer.style.visibility="visible";
	       sclayer.value="stop countdown";
	   }
	   else if (todo == "finished")
	   {
	   	   sclayer.disabled=true;
	       sclayer.style.visibility="hidden";
	       sclayer.value="";
	   }
	}
}

function changelayer_content(counter)
{
    if (!fredlayer)fredlayer=getLayer("fred");
    if (fredlayer)
	{
	  if (count > 0)
	  { 
	    var  msgstring = "<BR><P><FONT color=red size=1> "+counter+" secs. till main page loads</FONT></P>";
        if(ns4)
		{
		    fredlayer.document.open();
            fredlayer.document.write(msgstring);
            fredlayer.document.close();
        }
        else fredlayer.innerHTML=msgstring;
      }
	  else
	  {
	    fredlayer.style.visibility = "hidden";
	  }
	}
	if (count <= 0)stopButton("finished");
}

function getLegend()
{
	return '<FONT color=#00008b>Website optimized for </font><FONT color=green>' + checkBandwidth(chosenBandwidth) + ' </font><FONT color=#00008b>speed connection!</font>'
}

function setLegend(sLegend)
{
    if (!legendlayer)legendlayer=getLayer("lid");
    if (legendlayer)
	{
	    if(ns4)
		{
            //thisbrowser="NN4";
            legendlayer.document.open();
            legendlayer.document.write(sLegend);
            legendlayer.document.close();
		}
        else legendlayer.innerHTML = sLegend;
    }
}
function savesetting(currObj)
{
	if (currObj.id=="mycheckbox")
	{
	    if (currObj.checked == true)
		{
			vreset = true;
	    }
		else
	    {
            vreset = false;
		}
		get_radio_value(null);
	}
	else
	{
   	    setCookie("mediaThroughput",chosenBandwidth = currObj.id,getExpireDate("1day"));
	    setLegend(getLegend());
	}
}


function getExpireDate(duration)
{
       /*
         cookie expires in one year (actually, 365 days)
         365 days in a year
         24 hours in a day
         60 minutes in an hour
         60 seconds in a minute
         1000 milliseconds in a second
       */
        var expires = new Date();
        // fix the bug in Navigator 2.0, Macintosh
        fixDate(expires);
		if (duration == "1year")expires.setTime(expires.getTime() + 1000*60*60*24*365);
        else if (duration == "1day")expires.setTime(expires.getTime() + 60* 24 * 60 * 1000);
        else if (duration == "1minute")expires.setTime(expires.getTime() + 60 * 1000);
		else expires.setTime(expires.getTime());
		return expires;
}
function moveResize(xwidth,xheight)
{
        if (window.screen)
		{
           var ah = screen.availHeight - 50;
           var aw = screen.availWidth - 10;

           var xc = (aw - xwidth) / 2;
           var yc = (ah - xheight) / 2;
		   if (yc < 0)yc = 0;
		   if (xc < 0)xc = 0;
		   if (xwidth < aw)aw = xwidth;
		   if (xheight < ah)ah = xheight;
		   // if(window.resizeTo)window.resizeTo(aw,ah);
		   // if(window.moveTo)window.moveTo(xc,yc);
        }
}
function isgeocities()
{
    if (document.URL.indexOf('geocities') == -1)return false;
	else return true;
}

function checkBandwidth(xBandwidth)
{
	if ( xBandwidth == "CABLE-DSL (E1)") {  return (high) }
    else if ( xBandwidth == "CABLE-DSL (T1)") {  return (high) }
    else if ( xBandwidth == "CABLE-DSL") {  return (high) }
    else {  return (low) }
}

function displaybutt()
{
    var firstVisit = true; //assume it so
	var msgStr;
	var connectiondiscrepancy = false;
	var Row1st, Row2nd, Row3rd, Row4th, Row5th, cell;

	// Get rid of the "javascript must be enabled message"
	if (!imglayer)
	{
	    imglayer=getLayer("imgdiv");
	    if (imglayer)imglayer.innerHTML= '<table cellpadding="0" cellspacing="0"><tr><td><img src="images/hms-exmouth.gif" width="250" height="121"></td></tr></table>';
	}
	if (!smr03layer)
	{
	    smr03layer=getLayer("smr03");
	    if (smr03layer)smr03layer.style.visibility = "visible";		
	} 

 
    if (getCookie( 'test' ))
    {   // User is accepting cookies and has refreshed the page in under a minute
	   chosenBandwidth = getCookie("mediaThroughput");
    }
    else
	{
       /* Check if user is accepting cookies */
       setCookie( 'test', 'none', getExpireDate("1minute"));
 
       // if Get_Cookie succeeds, cookies are enabled, since 
       //the cookie was successfully created.
       if (!getCookie( 'test' ))
       {
           nocookies = true;
		   chosenBandwidth = 0;
       }   
       else
	   {
	       chosenBandwidth = getCookie("mediaThroughput");
	   }
	}
	
	if ((!chosenBandwidth) || (chosenBandwidth == "reset"))
	{ 
		if (chosenBandwidth == "reset")document.location.hash = '#divanchor';
	    chosenBandwidth = bandwidth;
		if (!nocookies)setCookie("mediaThroughput",bandwidth,getExpireDate("1day"));
    }
	else firstVisit = false;
	
	
	// Set Legend depending on high/load speed link
	if (!lidlayer)lidlayer = getLayer("lid");
	if (lidlayer)lidlayer.innerHTML = getLegend();

    if (!tidlayer)tidlayer=getLayer("tid");
    // tidlayer.deleteRow(); // Delete the existing row


	// if (!isgeocities())
	// {
	  Row1st = tidlayer.insertRow();
	  Row2nd = tidlayer.insertRow();
	  if (firstVisit)
	  {
	    Row3rd = tidlayer.insertRow();
	    Row4th = tidlayer.insertRow();
	    Row5th = tidlayer.insertRow();
	   
	    cell = Row1st.insertCell();
		cell.style.posWidth  = 200;		
        msgStr = '<input id="14.4k" type="radio" name="RadioGroup1"';
		if (chosenBandwidth == "14.4k")
		{
		    msgStr += ' CHECKED ';
		}
		msgStr += 'onClick="savesetting(this)">';
		if (chosenBandwidth == "14.4k")
		{
		    msgStr += '<font color="#00008b">';
		}
		msgStr += '14.4k';
		if (chosenBandwidth == "14.4k")
		{
		    msgStr += '</font>';
		}	
		cell.innerHTML = msgStr;
		
		cell = Row1st.insertCell();
		cell.style.posWidth  = 200;		
        msgStr = '<input id="CABLE-DSL" type="radio" name="RadioGroup1"';
		if ((chosenBandwidth == "CABLE-DSL") ||
		    (chosenBandwidth == "CABLE-DSL (T1)") ||
		    (chosenBandwidth == "CABLE-DSL (E1)"))
		{
		    msgStr += ' CHECKED ';
		}
		msgStr += 'onClick="savesetting(this)">';
		if ((chosenBandwidth == "CABLE-DSL") ||
		    (chosenBandwidth == "CABLE-DSL (T1)") ||
		    (chosenBandwidth == "CABLE-DSL (E1)"))
		{
		    msgStr += '<font color="#00008b">';
		}
		msgStr += 'CABLE-DSL';
		if ((chosenBandwidth == "CABLE-DSL") ||
		    (chosenBandwidth == "CABLE-DSL (T1)") ||
		    (chosenBandwidth == "CABLE-DSL (E1)"))
		{
		    msgStr += '</font>';
		}	
		cell.innerHTML = msgStr;

	    cell = Row2nd.insertCell();
		cell.style.posWidth  = 200;		
        msgStr = '<input id="28k" type="radio" name="RadioGroup1"';
		if (chosenBandwidth == "28k")
		{
		    msgStr += ' CHECKED ';
		}
		msgStr += 'onClick="savesetting(this)">';
		if (chosenBandwidth == "28k")
		{
		    msgStr += '<font color="#00008b">';
		}
		msgStr += '28k';
		if (chosenBandwidth == "28k")
		{
		    msgStr += '</font>';
		}	
		cell.innerHTML = msgStr;

	    cell = Row2nd.insertCell();
		cell.style.posWidth  = 200;
		cell.rowSpan = 2;		
        msgStr = '<span style="font-size: 90%; color: #00008b; font-weight: strong">';
		if (mediaThroughput != 20000)
     	{
			msgStr += ' Your connection:<br> ' + parseInt(mediaThroughput) + ' kbits/s';		
        }
		else
		{
			msgStr += ' Your connection: Speed above measureable limit';					
		}
		msgStr += '</span>';
		cell.innerHTML = msgStr;
		
		
	    cell = Row3rd.insertCell();
		cell.style.posWidth  = 200;		
        msgStr = '<input style="color:red" id="56k" type="radio" name="RadioGroup1"';
		if (chosenBandwidth == "56k")
		{
		    msgStr += ' CHECKED ';
		}
		msgStr += 'onClick="savesetting(this)">';
		if (chosenBandwidth == "56k")
		{
		    msgStr += '<font color="#00008b">';
		}
		msgStr += '56k';
		if (chosenBandwidth == "56k")
		{
		    msgStr += '</font>';
		}	
		cell.innerHTML = msgStr;


	    cell = Row4th.insertCell();
		cell.style.posWidth  = 200;		
        msgStr = '<input id="ISDN" type="radio" name="RadioGroup1"';
		if (chosenBandwidth == "ISDN")
		{
		    msgStr += ' CHECKED ';
		}
		msgStr += 'onClick="savesetting(this)">';
		if (chosenBandwidth == "ISDN")
		{
		    msgStr += '<font color="#00008b">';
		}
		msgStr += 'ISDN(64-128K)';
		if (chosenBandwidth == "ISDN")
		{
		    msgStr += '</font>';
		}	
		cell.innerHTML = msgStr;

		cell = Row4th.insertCell();
		msgStr = '<INPUT ID="sc" style="color: red; visibility: hidden"  TYPE="BUTTON" VALUE="stop countdown" onclick="javascript:count = -1">';
		cell.innerHTML = msgStr;

        cell = Row5th.insertCell();
		cell.id = "mp";
        msgStr = '<INPUT TYPE="BUTTON" style="color: green; font-size: 110%"  VALUE="MAIN PAGE" onclick="get_radio_value(this)">';
		cell.innerHTML = msgStr;

        cell = Row5th.insertCell();
        msgStr = '<div id="fred"></div>';
		cell.innerHTML = msgStr;

	    maxcountdown = count = 181;
      }
      else
      { 
		cell = Row1st.insertCell();
        cell.style.posWidth  = 20;
		cell.vAlign  = "top";
        msgStr = '<input id="mycheckbox" type="checkbox" name="CheckBox" onClick="savesetting(this)">';
		cell.innerHTML = msgStr;
		
		cell = Row1st.insertCell();
        cell.style.posWidth = 200;
        msgStr = '<span ';
   	    if (checkBandwidth(bandwidth) != checkBandwidth(chosenBandwidth))
 	    {
		    msgStr += 'style="color: orange; font-weight: bold"';
		}
	    msgStr += '><font size="-2">Check box to change connection type from ' + chosenBandwidth + '</font></span>';
		cell.innerHTML = msgStr;
		
		cell = Row1st.insertCell();
        cell.style.posWidth = 180;
		cell.vAlign = "bottom";
        cell.id = "tdsc";		
        msgStr = '<INPUT ID="sc" style="color: red; visibility: hidden"  TYPE="BUTTON" VALUE="stop countdown" onclick="javascript:count = -1">';
		cell.innerHTML = msgStr;
		
		cell = Row2nd.insertCell();
	    msgStr = '&nbsp;';
		cell.innerHTML = msgStr;

		cell = Row2nd.insertCell();
		cell.id = "mp";
		cell.align = "left";
        msgStr = '<INPUT TYPE="BUTTON" style="color: green; font-size: 110%" VALUE="MAIN PAGE" onclick="get_radio_value(this)">';
		cell.innerHTML = msgStr;
		
		cell = Row2nd.insertCell();
        msgStr = '<div id="fred"></div>';
		cell.innerHTML = msgStr;
	
  	    if (checkBandwidth(bandwidth) != checkBandwidth(chosenBandwidth))
 	    {
	           Row3rd = tidlayer.insertRow();
	           Row4th = tidlayer.insertRow();

          	   cell = Row3rd.insertCell();
               cell.colSpan = 3;
	           msgStr = '<font size="-2">NB: Software has measured connection as: ' + bandwidth + '</font>';
		       cell.innerHTML = msgStr;

          	   cell = Row4th.insertCell();
               cell.colSpan = 3;
               msgStr = '<font size="-2">which is a <FONT color=red>' + checkBandwidth(bandwidth) + ' </font>speed connection!</font>';
               cell.innerHTML = msgStr;
 		}
	    maxcountdown = count = 61;
      }
	  stopButton("enable");   // make stop button enabled and visible
      // moveResize(800,1000);
    // }
    // else
	// {
	    // maxcountdown = count = 0;
	// }
}


function goback()
{
    if (newwin && newwin.focus)newwin.focus();
	window.blur();
    history.go(-1);
}
function closer()
{
    top.close();
}
function get_radio_value(currObj)
{
    if (!vreset)
	{
	    var windowname = "main" + checkBandwidth(chosenBandwidth);
        // moveResize(1000,1000);
		if (chosenBandwidth != "forget it")
        {
		    if (checkBandwidth(chosenBandwidth) != checkBandwidth(bandwidth))
			{
			    if (checkBandwidth(chosenBandwidth) == "high")
				{
				   alert ("You may experience a delay while main page loads as you have only a low speed link! Hit the <BACK> button to reset connection type in case of excessive delay!");
				}
            }
		    top.location.href = "hms-exmouth.htm?speed=" + escape(checkBandwidth(chosenBandwidth));
        }
		else alert("We are sorry but you have insufficient bandwidth to access the main page of this site!");
	}
	else
	{
	    setCookie("mediaThroughput","reset",getExpireDate("1minute"));

	    // Force a reload if continue button not hit
	    window.location.reload();
	}
}






















