// --------------------------------------------------------------------------------
// nspkg_form.js
// --------------------------------------------------------------------------------

var nspkg_form_pre = "tmpl_nspkg_Form_nspkgForm_";
var showOptions = false;

// --- Attach JS to document elements and execute simple statements. ---
ow_f_AppendLoadEvent(
function() {
    if (document.getElementById(nspkg_form_pre + "subm") != null) 
        ow_f_AddEvent(document.getElementById(nspkg_form_pre + "subm"), "click", nspkg_form_Click, false);

	if (document.getElementById("nspkg_form") != null) {
	    var inp = document.getElementById("nspkg_form").getElementsByTagName("input");
	    for (var i = 0; i < inp.length; i++) {
	        if (inp[i].type == "text") ow_f_AddEvent(inp[i], "keypress", nspkg_form_Key, false);
	    }

	    // Attach event to submit on enter when select has focus
	    var inp = document.getElementById("nspkg_form").getElementsByTagName("select");
	    for (var i = 0; i < inp.length; i++) {
	        ow_f_AddEvent(inp[i], "keypress", nspkg_form_Key, false);
	    }
	}

}
);

//// --- Javascript to handle updatepanel refreshes and focus changes ---
//var lastFocusedControlId = "";

//function focusHandler(e) {
//    // Use ECMAScript method of IE detection
//    if (/*@cc_on!@*/false) {
//        // Set active element in IE
//        document.activeElement = e.originalTarget;
//    } else {
//        // Allow active element to maintain focus in all other browsers
//        e.originalTarget.focus = true;
//    }
//}

//// Add handlers for asp.net javascript events
//function appInit() {
//    if (typeof (window.addEventListener) !== "undefined") {
//        window.addEventListener("focus", focusHandler, true);
//    }
//    Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler);
//    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler);
//}

//// Handle page loading event
//function pageLoadingHandler(sender, args) {
//    lastFocusedControlId = typeof (document.activeElement) === "undefined"
//        ? "" : document.activeElement.id;
//}

//// Give focus to the specified control
//function focusControl(targetControl) {
//    if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
//        var focusTarget = targetControl;
//        if (focusTarget && (typeof (focusTarget.contentEditable) !== "undefined")) {
//            oldContentEditableSetting = focusTarget.contentEditable;
//            focusTarget.contentEditable = false;
//        }
//        else {
//            focusTarget = null;
//        }
//        targetControl.focus();
//        if (focusTarget) {
//            focusTarget.contentEditable = oldContentEditableSetting;
//        }
//    }
//    else {
//        targetControl.focus();
//    }
//}

//// Handle the page load event
//function pageLoadedHandler(sender, args) {
//    if (document.getElementById("nspkg_form") != null) {
//        var inp = document.getElementById("nspkg_form").getElementsByTagName("input");
//        for (var i = 0; i < inp.length; i++) {
//            if (inp[i].type == "text") ow_f_AddEvent(inp[i], "keypress", nspkg_form_Key, false);
//        }

//        // Attach event to submit on enter when select has focus
//        var inp = document.getElementById("nspkg_form").getElementsByTagName("select");
//        for (var i = 0; i < inp.length; i++) {
//            ow_f_AddEvent(inp[i], "keypress", nspkg_form_Key, false);
//        }
//    }


//    // Set focus to the last active control on updatepanel refresh
//    if (typeof (lastFocusedControlId) !== "undefined" && lastFocusedControlId != "") {
//        var newFocused = $get(lastFocusedControlId);
//        if (newFocused) {
//            focusControl(newFocused);
//        }
//    }
//}

//Sys.Application.add_init(appInit);




// --------------------------------------------------------------------------------
// nspkg_form_Key()
// Fires when a textfield had focus and ENTER was pressed.
// --------------------------------------------------------------------------------
function nspkg_form_Key(e) {
	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

	if (code == 13) {
		document.getElementById(nspkg_form_pre + "subm").click();
		if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
	}
}

// --------------------------------------------------------------------------------
// nspkg_form_Click()
// Fires when the submit button was clicked.
// --------------------------------------------------------------------------------
function nspkg_form_Click(e) {
	if (!nspkg_form_Valid()) {
		if (!e) var e = window.event;
		if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
	} else {
		return;
	}
}

// --------------------------------------------------------------------------------
// nspkg_form_Valid()
// Validates the data entered in the Accommodations app.
// --------------------------------------------------------------------------------
// Arguments:
//	- none
// Returns:
//	- the results of the validation [boolean]
// --------------------------------------------------------------------------------

function nspkg_form_Valid() {
	return true;
}
