//create request object called httprequest
function createAjaxObj()
{
var httprequest = false;
if (window.XMLHttpRequest) { // if Mozilla, Safari etc
httprequest = new XMLHttpRequest();
if (httprequest.overrideMimeType) httprequest.overrideMimeType('text/xml');
}
else if (window.ActiveXObject)
{ // if IE
try {
httprequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try{
httprequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{}
}
}
return httprequest;
}
//http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm
//ACCESSIBLE VARIABLES (for use within your callback functions):
//1) ajaxpack.ajaxobj //points to the current ajax object
//2) ajaxpack.filetype //The expected file type of the external file ("txt" or "xml")
//3) ajaxpack.basedomain //The root domain executing this ajax script, taking into account the possible "www" prefix.
//4) ajaxpack.addrandomnumber //Set to 0 or 1. When set to 1, a random number will be added to the end of the query string of GET requests to bust file caching of the external file in IE. See docs for more info.
//ACCESSIBLE FUNCTIONS:
//1) ajaxpack.getAjaxRequest(url, parameters, callbackfunc, filetype)
//2) ajaxpack.postAjaxRequest(url, parameters, callbackfunc, filetype)
var ajaxpack = new
Object()
ajaxpack.basedomain = "http:
//"+window.location.hostname
ajaxpack.ajaxobj = createAjaxObj()
ajaxpack.filetype = "txt"
ajaxpack.addrandomnumber = 0
//Set to 1 or 0. See documentation.
ajaxpack.getAjaxRequest =
function(txt1, parameters, callbackfunc, filetype)
{
ajaxpack.ajaxobj = createAjaxObj() //recreate ajax object to defeat cache problem in IE
if(ajaxpack.addrandomnumber==1) //Further defeat caching problem in IE?
var parameters=parameters+"&ajaxcachebust="+new Date().getTime();
if(this.ajaxobj) {
this.filetype = filetype;
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('GET', txt1+"?"+parameters, true);
this.ajaxobj.send(null);
}
}
ajaxpack.postAjaxRequest=function(txt1, parameters, callbackfunc, filetype)
{
ajaxpack.ajaxobj = createAjaxObj() //recreate ajax object to defeat cache problem in IE
if(this.ajaxobj) {
this.filetype = filetype;
this.ajaxobj.onreadystatechange = callbackfunc;
this.ajaxobj.open('POST', txt1, true);
this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
this.ajaxobj.setRequestHeader("Content-length", parameters.length);
this.ajaxobj.setRequestHeader("Connection", "close");
this.ajaxobj.send(parameters);
}
}
function processGetPost()
{
var myajax = ajaxpack.ajaxobj;
var myfiletype = ajaxpack.filetype;
if(download_loading_count > 41) {}
else {
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt") {
document.getElementById('download_details').style.display = 'block';
hideDownloadsLoading();
document.getElementById('download_details').innerHTML = myajax.responseText;
}
else {
alert(myajax.responseXML);
}
}
}
}
}
function createpoststring()
{
var url_value = document.getElementById("chooser_form").txt1.value;
var poststr = "url=" + escape(url_value);
return poststr;
}
var download_loading_int = false;
var download_loading_count = 0;
var selected_form = 0;
var history_value = '
';
//main function
function openDownloads()
{
url_value = document.chooser_form.txt1.value;
if(url_value == "")
{alert('Please enter a URL first.');document.forms[selected_form_name].txt1.focus();}
else {
document.getElementById('download_container').style.display = 'block';
document.getElementById('download_details').style.display = 'none';
document.getElementById('download_loading').style.display = 'inline';
document.getElementById('download_loading_c').innerHTML = '';
if(download_loading_int) {
clearInterval(download_loading_int);
}
download_loading_count = 0;
ajaxpack.postAjaxRequest("index_p/", createpoststring(), processGetPost, "txt");
download_loading_int = setInterval('
if(download_loading_count == 40){hideDownloadsLoading();document.getElementById(\'download_details\'
).style.display = \'block\'
;document.getElementById(\'download_details\'
).innerHTML = \'Error: Timeout. Please
try again.\'
;}download_loading_count++;document.getElementById(\'download_loading_c\'
).innerHTML += "."', 2000);
}
}
function hideDownloadsLoading()
{
if(download_loading_int) {
clearInterval(download_loading_int);
}
document.getElementById('
download_loading').style.display = '
none';
}
function htmlspecialchars(str)
{
return str.replace(/&/g, "&").replace(/</g,"<").replace(/>/g, ">").replace(/'/g, "'").replace(/"/g, """);
}