function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
timer = 0;

function processURL(){	

	var r= Math.random()*5;
	var website = document.getElementById('website').value;

	var file = "process.php?url="+website+"&r="+r;
//alert(file);
    http.open("get",file);
    http.onreadystatechange = function(){
		if(http.readyState == 4){
			var response = http.responseText;
		//	alert(response);
			var responseArray = response.split("||");
			 if(response == 0){
				document.getElementById('status').innerHTML = "Screenshot has been created in job queue.";
				setTimeout('processURL()', 3000);
				timer++;
			}else if(responseArray[0] == 0){
				document.getElementById('status').innerHTML = "Your screenshot is in a job queue with a total of "+responseArray[1]+" jobs. Your screenshot will be processed shortly.<br><i><font color='silver'>[This page will automatically forward you to your screenshot when it is completed, there is no need to refresh this screen.]</font></i>";
				setTimeout('processURL()', 3000);
			}else if(response == 1){
				document.getElementById('status').innerHTML = "Your screenshot is currently being generated. ("+timer+")";
				setTimeout('processURL()', 3000);
				timer++;
			}else if(response == "error"){
				document.getElementById('status').innerHTML = "<font color='red'>There was a problem processing your screenshot.  The URL will be reviewed. <br>If this is urgent, you can report it to our <a href='http://www.webshotspro.com/report_url.php?url="+website+"'>staff here</a> or wait for our system to automatically handle the request.</font>";
			}else if(response == "rejected"){
				document.getElementById('status').innerHTML = "<font color='red'>This URL has been rejected from our system.</font>";
			}else if(response == "urlformat"){
				document.getElementById('status').innerHTML = "<font color='red'>The URL must begin with an 'http://'.</font>";
			}else{
				document.getElementById('status').innerHTML = "Screenshot done.";
				window.location="http://www.webshotspro.com/info/"+response;
			}
		}
	}
    http.send(null);
	return false;
}

