var flgSubmitted = false;


function window_onbeforeunload() {
	if (checkunload) {
		return "You haven't completed this function. Please use the 'Continue' and 'Previous' buttons below."
	}
	
 } 

function window_onload() {

//	Set up standard variables on window load, and set focus to first input field

	checkunload = true
	flgSubmitted = false
	printneeded = true
	helpshown = false
	infoshown = false
	popped = false
	printed = false
	maxcols=4
	
	with (document) {
		if (forms.length > 0) {
			with (forms[0]) {
				var n
				for (n = 0; n < elements.length; ++n) {
					if (elements[n].type != "hidden") {
						elements[n].focus()
						if (elements[n].type == "text") {
							elements[n].select()
						}
						break
					}
				}
			}
		}
	}
}

function showInfo(url) {

//	Display a pop-up window with information

	infowindow = window.open(url,"info","height=500,width=700,scrollbars=yes,location=no,toolbar=no,resizable=yes,status=no")
	infoshown = true
	return false
}

function window_onunload() {

//	Close any help window and then force a Log Out if the window is being closed untidily

	if (helpshown) {
		helpwindow.close()
	}

	if (infoshown) {
		infowindow.close()
	}

	if (checkunload) {
		untidywindow = window.open("untidyclose.asp","untidy","height=200,width=300,scrollbars=no,location=no,toolbar=no,resizable=no,status=no")
	}
	
	if (popped) {
		popup.close()
	}
}

function getOut(str) {
	checkunload=false;
	document.forms[0].elements["TxtPRK"].value = str;
	// document.forms[0].submit();
}

/*
 Function to ensure Submit button is pressed only once 
*/

function SubmitOnce(theform) {
    if (!flgSubmitted) {
        checkunload= false;
        flgSubmitted = true;

		// search thru every element in the form and disable all buttons
		
		var i
        for (i=0;i<theform.length;i++) {
			var tempobj=theform.elements[i];
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset"||tempobj.type.toLowerCase()=="button") {
				tempobj.disabled=true;
            }
        return true;
        }
    } else {
		return false;
    }
}
	
	
function SubmitOnceAndValidate(theform) {
    if (!flgSubmitted) {
		if (validate(theform)) {
			checkunload= false;
			flgSubmitted = true;

			// search thru every element in the form and disable all buttons
		
			var i
			for (i=0;i<theform.length;i++) {
				var tempobj=theform.elements[i];
				if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset"||tempobj.type.toLowerCase()=="button") {
					tempobj.disabled=true;
			    }
			return true;
			}
		} else {
			return false;
		}
    } else {
		return false;
    }
}

function AllowSubmit() {
    if (!flgSubmitted) {
        checkunload= false;
        flgSubmitted = true;
        return true;
    } else {
		return false;
    }
}

// Create the popup object. For predictable results, always create
// a global popup object.

function openPopup()
{
  
    //var tprint = window.showModalDialog("printscreen.asp","","DialogHeight:35mm;DialogWidth:300px;help:no;status=no;");
    //if (tprint == "yes")
	//	{window.print();}
    //   return false;
}

function CmdPrev_onclick(theform) {
   if (!flgSubmitted) {
          checkunload= false;
          flgSubmitted = true;
			var i
			for (i=0;i<theform.length;i++) {
				var tempobj=theform.elements[i];
				if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset"||tempobj.type.toLowerCase()=="button") {
					tempobj.disabled=true;
			    }
			}
// Mimics the action of the Browser Back buttons
		history.back();

    } else {
		return false;
    }
	
}
