﻿/*
Rocco Forte right-hand navigation code
*/

// Factory class to hold list of registered navigation items
__NavigationItems = {};
__NavigationItems.items = {};

__NavigationItems.create = function (id) {
	var newItem = new NavigationItem(id);
	this.items[id] = newItem;
	return newItem;
}

__NavigationItems.createBatch = function (idList) {
	for (var n=0; n<idList.length; n++)
	{ this.create(idList[n]); }
}

// global function for triggering off onclick of nav link
function showRightNav(id)
{ __NavigationItems.items[id].show(); }

// Individual navigation item class
function NavigationItem(id)
{
	this.id = id;
	this.on = false;
}
NavigationItem.prototype.show = function () {
	// check current state (click-to-turn-off)
	var currentlyOn = this.on;
	
	// hide others, if any
	for (var itemId in __NavigationItems.items)
	{
		if (__NavigationItems.items[itemId].on)
		{ __NavigationItems.items[itemId].hide(); }
	}
	// show this
	if (!currentlyOn)
	{
		this.on = true;
		var domElement = document.getElementById(this.id);
		domElement.style.display = 'block';
		
		// change parent class
		var domParent = domElement.parentNode;
		domParent.setAttribute('class', 'on');
		
		/*
		This is here to try and fix the case where a page with little content allows
		the right-hand navigation to overflow the bottom of its column.
		
		Needs to check if we're on the group site (must be a better way to do this)
		*/
		if (document.getElementById('introflash'))
		{ setHeight(null, 'introflash', 'right', null); }
		else
		{ setHeight(); }
		
	}
}
NavigationItem.prototype.hide = function () {
	// hide this
	this.on = false;
	var domElement = document.getElementById(this.id);
	domElement.style.display = 'none';
	
	// change parent class
	var domParent = domElement.parentNode;
	domParent.setAttribute('class', '');
}

function CorporteLogin(form) {
    var username = document.getElementById("corporate_username").value;
    var password = document.getElementById("corporate_password").value;
    if (username == "") {
        alert("Please enter username");
        return false;
    }
    if (password == "") {
        alert("Please enter password");
        return false;
    }

    var hotel_url = XmlHttp.create();
    hotel_url.open('GET', '/_xml/hotel_id.xml', false);
    hotel_url.send(null);
    var hotel_response = (hotel_url.responseXML);
    var Hurl = (hotel_response.getElementsByTagName('url')[0].firstChild.nodeValue);

    form.submit();
}
