var http;
var pbar;
var prate;
var prem;
var dtStart = new Date();
try
{ http = new XMLHttpRequest();
} catch (tryms2)
{ try
  { http = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (tryms1)
  { try
    { http = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed)
    { http = false;
    }
  }
}

function checkForm(theForm)
{ var lc = theForm.file.value.toLowerCase();
  var len = lc.length;
  var ext;
  var i;
  if (len < 5)
  { alert("Please select a video file.");
    theForm.file.focus();
    return (false);
  }
  ext = "";
  i = lc.lastIndexOf('.');
  if (i != -1)
    for (i++; i<len; i++)
      ext += lc.charAt(i);
  if (ext != 'wmv' && ext != 'mpg' && ext != 'flv' && ext != 'mp4' && ext != 'm4v' && ext != 'mov')
  { alert("StudySite only accepts video files in Windows Media (.wmv), Flash (.flv), QuickTime (.mov) and MPEG (.mpg, .mp4, .m4v) formats.");
    theForm.file.focus();
    return (false);
  }
  if (theForm.title.value == "")
  { alert("Please enter a title for the video.");
    theForm.title.focus();
    return (false);
  }
  if (theForm.cat.value == "0")
  { alert("Please select a category of interest.");
    theForm.top.focus();
    return (false);
  }
  var e = document.getElementById("msg");
  e.innerHTML = "<strong>Uploading your video file; please wait...</strong><br />" +
    "Stopping your browser or leaving this page will stop the upload.";
  e = document.getElementById("prog");
  e.style.visibility = "visible";
  e = document.getElementById("upbtn");
  e.style.visibility = "hidden";
  window.setTimeout(PollProgress, 1000);
  return (true);
}

function PollProgress()
{ var url = "/ex/ssui.dll/upprog?ul=" + dtStart.getMilliseconds();
  http.open("GET", url, true);
  http.onreadystatechange = HttpRcv;
  http.send(null);
}

function HttpRcv()
{ if (http.readyState == 4)
  { if (http.status == 200)
    { var reply = http.responseText.split(",");
	  pbar.width = reply[0];
	  prate.innerHTML = reply[1];
	  prem.innerHTML = reply[2];
	}
	window.setTimeout(PollProgress, 1000);
  }
}
