/*
  (c) Copyright 2003-2005 Reality Enhancement Pty Ltd
	
  Reproduction is strictly forbidden.

  http://www.realityenhancement.com
  sales@realityenhancement.com
*/

var isSubmitOk=true;
var ignoreSubmitOk=false;
function SubmitOk()
{
	if(!isSubmitOk){
		alert('You have already submitted a request. Please wait.');
		return false;
	} else {
		isSubmitOk=false;
		return true;
	}
}

function __StyleBDoPostBack(eventTarget, eventArgument) {
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("m icrosoft") > -1) {
    theform = document.forms[0];
    }
    else {
    theform = document.forms[0];
    }
    theform.__EVENTTARGET.value = eventTarget; // eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
}

function BSubmit(target, cmd, clientID)
{
	var val=true;
	
	if (typeof(Page_ValidationActive) != "undefined" && Page_ValidationActive == true) { val = Page_ClientValidate(); } // ValidatorOnSubmit();

	if (val && (ignoreSubmitOk || SubmitOk()))
	{
		if (document.getElementById(clientID) != null)
		{
			document.getElementById(clientID).value = "Please Wait"
		}
		//if (!submitbutton)
		//{
		    __StyleBDoPostBack(target,cmd);
		    //__doPostBack(target,cmd);
		//}
	}
	return false;	// Always cancel the buttons event as the page is handling it	
}

function BFormSubmit(target, cmd, clientID)
{
    var val=true;

	if (typeof(Page_ValidationActive) != "undefined" && Page_ValidationActive == true) val = Page_ClientValidate(); // ValidatorOnSubmit();
	
	if (val && (ignoreSubmitOk || SubmitOk()))
	{
		if (document.getElementById(clientID) != null)
		{
			document.getElementById(clientID).value = "Please Wait"
		}
	}
    return WebForm_OnSubmit();
}

// Internet Explorer
function SubmitTo(e, target)
{
	if (!e) var e = window.event;
	var code;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (code == 13)
	{	
		if (!SubmitOk()) return false;
		
		ignoreSubmitOk=true;
		document.getElementById(target).click();

		return false;
	}
	
	return true;
}

// Would be nice to build both in to a single function (even though they are called different with a different parameter).
function FormKeypressEnter(e)
{
	var result = true;
	
	if (!e) var e = window.event;
	var code;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	if (code == 13) {

		result = false;
		/*var testTarget = new String(evnt.target);
		// nasty - need to list each and every control pointing to certain buttons.
		if ((-1 != testTarget.indexOf("USER")) || (-1 != testTarget.indexOf("PASSWORD"))) {
			SubmitForm();
			result = false;
		}
		*/
	}
	return result;
}

// This function is used to change lower to upper case for the Input text
function cUpper(cObj) 
{
	cObj.value=cObj.value.toUpperCase();
	if ((typeof(cObj.onchange) == "undefined") || cObj.onchange == null) return true;
	else cObj.onchange();
}
