// teaser.js - for Warwick Hotel chain. This script is used along
// with the "warwickHotelLinks" form to hide the submit button (onDomReady)
// from users with javascript enabled, and add onchange functionality
// to the select dropdown.

function selectHotel() {
	
	var linkList = document.getElementById('linkList');
	if (linkList.options[linkList.selectedIndex].value != ''){
		var newWindow = window.open(linkList.options[linkList.selectedIndex].value, '_blank');
	}
	newWindow.focus();
	return false;
}

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;
	
	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// add onchange functionality to "linkList" select and hide the submit button
	var linkList = document.getElementById('linkList');
	linkList.onchange = selectHotel;
	var submitButton = document.getElementById('warwickHotelLinksSubmit');
	submitButton.style.display = 'none';
};

/* for Mozilla */
if (document.addEventListener) {
   document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
   document.write("<script defer src=ieonload.js><"+"/script>");
/*@end @*/

/* for other browsers */
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

addLoadEvent(init);
