  function selectValue(radioGroup, val){
    for (var ii = 0; ii<radioGroup.length; ii++){
      optVal = radioGroup[ii].value - 0;
      if (val == optVal)
         radioGroup[ii].checked = true;
      else
        radioGroup[ii].checked = false;
    }		
  }

  function startDetect()
  {
    detect();
  }

  function buildSetupString(){
    form = document.setup;
    var setupStr = "_v";
    setupStr += form.real.value;
    setupStr += form.netshow.value;
    if (form.quicktime)
      setupStr += form.quicktime.value;
    setupStr += form.bandwidth.value;

    return setupStr;
  }	
  
  function getSetupUrl(setupString, rawUrl)
  {
    var pos = rawUrl.indexOf("_v");
    if (pos < 0)
      return rawUrl; 
    var scndPos = rawUrl.indexOf("/", pos);
    if (scndPos < 0)
      return rawUrl; 
    var tmpUrl = rawUrl.substring(0,pos);
    tmpUrl += setupString;
    tmpUrl += rawUrl.substring(scndPos);

    return tmpUrl;
    
  }

	// this function can be used to remove setup information from a given url;
  function removeSetupInfoFromUrl(url) {
    var pos = url.indexOf("_v");
    if ( pos < 0 ) return url;
    var posTo = url.indexOf("/", pos);
    if ( posTo < 0 ) return url;
    var tmpUrl = url.substring(0, pos+2);
    var rest = url.substring(posTo);
    return tmpUrl + rest;
  }
  
  

  function getContentSetupUrl(setupString, rawUrl)
  {
    var pos = rawUrl.indexOf("/_v");
    if (pos < 0)
      return rawUrl; 
    var scndPos = rawUrl.indexOf("/", pos + 1);
    if (scndPos < 0)
      return rawUrl; 
    var tmpUrl = rawUrl.substring(0,pos +1);
    tmpUrl += "_v" + setupString;
    tmpUrl += rawUrl.substring(scndPos);
    var appendChar = (tmpUrl.lastIndexOf("?") > 0 ? "&" : "?");
    tmpUrl += appendChar + "tv1_storeVS=1";
    return tmpUrl;
  }


  function checkForStream (){
    var form = document.setup;
    var userBw = form.bandwidth.value - 0;
    var playerBw;
    if (form.real.value != "") {
      playerBw = form.minBwReal.value - 0;
      if (playerBw != 0 && playerBw <= userBw)  
        return true;
    }
    if (form.netshow.value != "") {
      playerBw = form.minBwNetshow.value - 0;
      if (playerBw != 0 && playerBw <= userBw)  
        return true;
    }
    if (form.quicktime && form.quicktime.value != "") {
      playerBw = form.minBwQuicktime.value - 0;
      if (playerBw != 0 && playerBw <= userBw)  
        return true;
    }
    
    return false;
  }

  function startTest (url) {
    var setupString = getSetupString();
    document.location.href=getSetupUrl(setupString, url);
  }

  function getSetupString() {
    return buildSetupString();
  }

  function handleErr(msg, file_loc, line_no) {
   if (tryIt) {
     tryIt = false;
     return true;
   }
   return false;
  }

  function clickBw (num){
    document.setup.bandwidth.value=num;
    return true;
  }

  function clickReal (bool){ 
    if (bool)
      document.setup.real.value="r";
    else
      document.setup.real.value="";
  }

  function clickNetshow (bool){ 

    if (bool)
      document.setup.netshow.value="m";
    else
      document.setup.netshow.value="";
  }

  function clickQuicktime (bool){ 
    if(document.setup.quicktime)
    {
      if (bool)
        document.setup.quicktime.value="q";
      else
        document.setup.quicktime.value="";
    }
  }

  function commit() {
    var setupString = getSetupString();
    var newHref = getSetupUrl(setupString, backUrl);
    parent.location.href = newHref;
    tryIt = true;
    if (parent.opener && !parent.opener.closed && !parent.opener.tv1_noRefresh) {
      var openerRef = parent.opener.document.location.href;
      var newOpenerRef = getSetupUrl(setupString, openerRef);
      if (openerRef != newOpenerRef)
	parent.opener.document.location.href = newOpenerRef;
    }
    tryIt = false;

    window.focus();
  }


  function nextPage() {
    var form = document.setup;
    var page = form.pgNum.value - 0;
    form.pgNum.value = ++page;
    form.submit();
  }

  function prevPage() {
    var form = document.setup;
    var page = form.pgNum.value - 0;
    form.pgNum.value = --page;
    form.submit();
  }

  function goPage(num) {
    var form = document.setup;
    form.pgNum.value = num - 0;
    form.submit();
  }

  function realTest(bool) {
    clickReal(bool);
    goPage(2);
  }

  function netshowTest(bool) {
    clickNetshow(bool);
    goPage(2);
  }
