var requestTime;
var appTimeOut = 180;
var popupWindow;
var IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;

// Set the genauser variable when the page is loaded.
function setGenaUser() {
	var genaUser;
        var randomnumber = Math.floor(Math.random()*100);
        // Get the date and time.
        var d = new Date();
        requestTime = d.getHours()*3600+d.getMinutes()*60+d.getSeconds();
        genaUser = d.getDay() + "." + d.getMonth() + "." + d.getYear() + "." + d.getHours() + "." + d.getMinutes() + "." + d.getSeconds() + "." + randomnumber;

	// Set the genauser variable on the CEMETERY form.
	parent.topFrame.document.CEMETERY.genauser.value = genaUser;
}

// Check the current time to see if we have timed out.
function getVari() {
        // Set the time this request was sent
        var dd = new Date();
        var newTime = dd.getHours()*3600+dd.getMinutes()*60+dd.getSeconds();

        // Compare the two times to see if they are outside the timeout period.
        // Subtract old time from new time and compare to timeout period in seconds
        if ( newTime-requestTime > parent.appTimeOut) {
                parent.topFrame.document.CEMETERY.target = "dummyframe";
                parent.topFrame.document.CEMETERY.submit();
        }

        // Set the new request time back to the top frame.
        requestTime = newTime;
}

function searchName () {
	
	// Set up all the variables required to submit this command.
	parent.topFrame.document.CEMETERY.command.value = "find_plot.s";
	parent.topFrame.document.CEMETERY.range.value = "1,15,1";
	parent.topFrame.document.CEMETERY.surname.value = searchFrame.document.SEARCH.surname.value;
	for (var i = 0; i < searchFrame.document.SEARCH.deathOpt.length; i++) {
		if (searchFrame.document.SEARCH.deathOpt[i].selected) {
			topFrame.document.CEMETERY.deathOpt.value = searchFrame.document.SEARCH.deathOpt[i].value;
		}
	}

	// Check to see if we are within the timeout period.
	getVari();

	// Submit the form
        parent.topFrame.document.CEMETERY.target = "resultFrame";
        parent.topFrame.document.CEMETERY.submit();
}

function moreResults(range , surname , options) {
	// Check to see if we are within the timeout period.
	getVari();


	// Set the variables and submit the form.
	parent.topFrame.document.CEMETERY.range.value = range;
	parent.topFrame.document.CEMETERY.surname.value = surname;
	parent.topFrame.document.CEMETERY.deathOpt.value = options;
	parent.topFrame.document.CEMETERY.command.value = "find_plot.s";
	parent.topFrame.document.CEMETERY.target = "resultFrame";

	// Submit the form.
	parent.topFrame.document.CEMETERY.submit();
}

function textResults(cemID) {
	// Check to see if we are within the timeout period.
	getVari();


	// Set the variables and submit the form.
	parent.topFrame.document.CEMETERY.cemID.value = cemID;
	parent.topFrame.document.CEMETERY.command.value = "showDetails.s";

	myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=400,height=410,resizable=yes");
	if (IE6) {
		// For some reason on Win XP/IE 6. you cannot resize a popup window opened
		// from a different page. So close and reopen the popup works.
		// %&^%*&^%* MicroSoft
		popupWindow.close();
		myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=400,height=410,resizable=yes");
	} else {
		// Just resize the window like normal browsers understand.
		popupWindow.resizeTo("400","410");
	}

	// Change the target of the form to our newly created pop-up.
	parent.topFrame.document.CEMETERY.target = "popResults";

	// Make sure the popup is at the front.
	popupWindow.focus();

	// Submit the form.
	parent.topFrame.document.CEMETERY.submit();

	// Make sure the popup is at the front.
	window.popupWindow.focus;
}

function headstone(cemID) {
	// Check to see if we are within the timeout period.
	getVari();


	// Set the variables and submit the form.
	parent.topFrame.document.CEMETERY.cemID.value = cemID;
	parent.topFrame.document.CEMETERY.command.value = "showHstone.s";

	// Open the pop-up window.
	myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=670,height=620,resizable=yes");
	if (IE6) {
		// For some reason on Win XP/IE 6. you cannot resize a popup window opened
		// from a different page. So close and reopen the popup works.
		// %&^%*&^%* MicroSoft
		popupWindow.close();
		myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=670,height=620,resizable=yes");
	} else {
		// Just resize the window like normal browsers understand.
		popupWindow.resizeTo("670","620");
	}

	// Change the target of the form to our newly created pop-up.
	parent.topFrame.document.CEMETERY.target = "popResults";

	// Make sure the popup is at the front.
	popupWindow.focus();

	// Submit the form.
	parent.topFrame.document.CEMETERY.submit();
}

function showResults(cemID) {
	// Check to see if we are within the timeout period.
	getVari();

	// Open the pop-up window.
	myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=400,height=410");
	window.popupWindow.resizeTo("400","410");

	// Set the variables and submit the form.
	parent.topFrame.document.CEMETERY.cemID.value = cemID;
	parent.topFrame.document.CEMETERY.command.value = "showDetails.s";

	// Change the target of the form to our newly created pop-up.
	parent.topFrame.document.CEMETERY.target = "popResults";
	
	// Change the size of the popup window to the map size.
	//thisWin.resizeTo("400", "410");

	// Make sure the popup is at the front.
	window.popupWindow.focus();

	// Submit the form.
	parent.topFrame.document.CEMETERY.submit();
}

function showHeadstone(cemID) {
	// Check to see if we are within the timeout period.
	getVari();

	// Open the pop-up window.
	myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=670,height=620");
	popupWindow.resizeTo("670","620");

        // Set the variables and submit the form.
        parent.topFrame.document.CEMETERY.cemID.value = cemID;
        parent.topFrame.document.CEMETERY.command.value = "showHstone.s";

        // Change the target of the form to our newly created pop-up.
        parent.topFrame.document.CEMETERY.target = "popResults";

	// Change the size of the popup window to the map size.
        popupWindow.resizeTo("670", "620");

	// Make sure the popup is at the front.
	popupWindow.focus();

        // Submit the form.
        parent.topFrame.document.CEMETERY.submit();
}

function showMap(cemID) {
	// Check to see if we are within the timeout period.
	getVari();

	// Open the pop-up window.
	myPopUp("about:blank" , "popResults" , "toolbars=yes,scrollbars=no,width=550,height=680");
	popupWindow.resizeTo("550","680");

	// Set the variables and submit the form.
	parent.topFrame.document.CEMETERY.cemID.value = cemID;
	parent.topFrame.document.CEMETERY.command.value = "showMap.s";

	// Change the target of the form to our newly created pop-up.
	parent.topFrame.document.CEMETERY.target = "popResults";
	
	// Change the size of the popup window to the map size.
	popupWindow.resizeTo("550", "680");

	// Make sure the popup is at the front.
	popupWindow.focus();

	// Submit the form.
	parent.topFrame.document.CEMETERY.submit();
}

function myPopUp(strUrl, strName, strFeatures) {
	// Open the URL for the results.
	popupWindow = window.open(strUrl,strName,strFeatures);
}
