// this is where the ajax script goes....

var xmlhttp;
var serverCheckTimeoutMillis =10000 ; //10 seconds
var isServer0=false;

var c=0;
var t;
var timer_is_on=0;

/*function showShips(str)*/
function showShips()
{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="shipsinport.php";
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function load(page) {
	var load = window.open(page,'','scrollbars=yes,menubar=no,height=500,width=400,resizable=no,toolbar=no,location=no,status=no');
}

function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
	document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
	isServer0 = true ;
	}
}

function GetXmlHttpObject()
{
	if (window.XMLHttpRequest)
	  {
	  return new XMLHttpRequest(); // code for IE7+, Firefox, Chrome, Opera, Safari
	  }
	if (window.ActiveXObject)
	  {
	  return new ActiveXObject("Microsoft.XMLHTTP");	// code for IE6, IE5
	  }
	return null;
}

var dNow = new Date();
var startTimeMillis = dNow.getTime();

var intervalID = window.setInterval("checkServers()",10000);

function checkServers()
{
	var isTimeoutHappened = false;
	var currentTimeMillis = -1;
	
	dNow = new Date();
	currentTimeMillis = dNow.getTime();
	
	if ((currentTimeMillis - startTimeMillis) >= serverCheckTimeoutMillis) isTimeoutHappened = true;
	
	if (isServer0 == false && isTimeoutHappened)
	{
		window.clearInterval(intervalID);
		showError("Failed to connect.");
	}

}
function showError(link)
{
	document.getElementById("txtHint").innerHTML=link ;
}

function redirect(link)
{
	window.location=link;
}
///*******************************///
/*function timedCount()
{
	//document.getElementById('txt').value=c;
	c=c+1;
	if (c <= 15) //go on for 15 seconds.....
	  {
		t=setTimeout("timedCount()",1000);
	  }
	 else { 
		clearTimeout(t); 
	 }
}

function doTimer()
{
	if (!timer_is_on)
	  {
	  timer_is_on=1;
	  timedCount();
	  }
}

function stopCount()
{
	clearTimeout(t);
	timer_is_on=0;
}*/