//PopUp defaults 
popUpHorizontalAlign = "center";
popUpVerticalAlign = "center";
popUpWidth = null;	//set to half of screen width at runtime
popUpHeight = null; //set to half of screen height at runtime
popUpLeft = null; 
popUpTop = null; 
popUpToolbar = 0;
popUpScrollbars = 0;
popUpLocation = 0;
popUpStatusbar = 0;
popUpMenubar = 0;
popUpResizable = 0;

function popUp(pURL,pWidth,pHeight,pLeft,pTop,pToolbar,pScrollbars,pLocation,pStatusbar,pMenubar,pResizable) {
	//CHECK url ... if null alert and return (do nothing)
	if(pURL == null){
		alert("ERROR: popUp URL is null !!");
		return;
	}
	
	//SET width 
	setPopUpWidth(pWidth); 
	if (popUpWidth == null){
		popUpWidth = screen.width/2;
	}
	
	//SET height
	setPopUpHeight(pHeight); 
	if (popUpHeight == null){
		popUpHeight = screen.height/2;
	}
	
	//SET left
	setPopUpLeft(pLeft);
	if (popUpLeft == null){
		if(popUpHorizontalAlign == "right"){
			popUpLeft = (screen.width - popUpWidth);
		}else{
			popUpLeft = (screen.width - popUpWidth)/2;
		}
	}
	
	//SET top
	setPopUpTop(pTop);
	if(popUpTop == null){
		if(popUpVerticalAlign == "bottom"){
			popUpTop = (screen.height - popUpHeight);
		}else{
			popUpTop = (screen.height - popUpHeight)/2;
		}
	}
	
	//SET toolbar
	setPopUpToolbar(pToolbar);

	//SET scrollbars
	setPopUpScrollbars(pScrollbars);

	//SET location
	setPopUpLocation(pLocation);

	//SET statusbar
	setPopUpStatusbar(pStatusbar);

	//SET menubar
	setPopUpMenubar(pMenubar);

	//SET resizable
	setPopUpResizable(pResizable);
	
	//SET features
	var popUpFeatures = "toolbar = "+popUpToolbar + "," + 
						"scrollbars="+popUpScrollbars + "," + 
						"location="+popUpLocation + "," + 
						"statusbar="+popUpStatusbar + "," + 
						"menubar="+popUpMenubar + "," + 
						"resizable="+popUpResizable + "," + 
						"width="+popUpWidth + "," + 
						"height="+popUpHeight + "," + 
						"left = "+popUpLeft + "," + 
						"top = "+popUpTop;
	
	//Make sure it is not pulled from cache
	day = new Date();
	id = day.getTime();
	
	//POPUP
	eval("page" + id + " = window.open(pURL, id , popUpFeatures);");
}

function setPopUpWidth(pWidth){
	if(isNumeric(pWidth)){
		popUpWidth = pWidth;
	}
}
function setPopUpHeight(pHeight){
	if(isNumeric(pHeight)){
		popUpHeight = pHeight;
	}
}

function setPopUpLeft(pLeft){
	if(isNumeric(pLeft)){
		popUpLeft = pLeft;
	}
}

function setPopUpTop(pTop){
	if(isNumeric(pTop)){
		popUpTop = pTop;
	}
}

function setPopUpToolbar(pToolbar){
	if(isPositive(pToolbar)){
		popUpToolbar = 1;
	}
}

function setPopUpScrollbars(pScrollbars){
	if(isPositive(pScrollbars)){
		popUpScrollbars = 1;
	}
}

function setPopUpLocation(pLocation){
	if(isPositive(pLocation)){
		popUpLocation = 1;
	}
}

function setPopUpStatusbar(pStatusbar){
	if(isPositive(pStatusbar)){
		popUpStatusbar = 1;
	}
}

function setPopUpMenubar(pMenubar){
	if(isPositive(pMenubar)){
		popUpMenubar = 1;
	}
}

function setPopUpResizable(pResizable){
	if(isPositive(pResizable)){
		popUpResizable = 1;
	}
}

function setPopUpHorizontalAlign(pHorizontalAlign){
	if(/right|Right|RIGHT/.test(pHorizontalAlign)){
		popUpHorizontalAlign = "right";
	} else if(/left|Left|LEFT/.test(pHorizontalAlign)){
		//popUpHorizontalAlign = "left"; //do not need to set just set popUpLeft to 0
		popUpLeft = 0;
	}
}

function setPopUpVerticalAlign(pVerticalAlign){
	if(/top|Top|TOP/.test(pVerticalAlign)){
		//popUpVerticalAlign = "top"; do not need to set just set popUpTop to 0
		popUpRight = 0;
	} else if(/bottom|Bottom|BOTTOM/.test(pVerticalAlign)){
		popUpVerticalAlign = "bottom";
	}
}

function isPositive(pVar){
	return pVar == 1 || pVar == true ||  /true|True|TRUE|yes|Yes|YES/.test(pVar);
}

function isNumeric(pVar){
	return /[0-9]/.test(pVar);
}


var fsman;

function FormState(formObj) {
	this.formObj = formObj;		
	this.formObj.onclick = fsmanScan;
	this.formObj.onkeyup = fsmanScan;
	this.formObj.onfocus = fsmanScan;
	this.formObj.onchange = fsmanScan;
	this.registeredButtons = new Array();
	this.allElements = new Array(formObj.elements.length);
	var elementObj;
	for (var j = 0; j < formObj.elements.length; j++) {
		elementObj = formObj.elements[j];
		var elementValue = "";
		var noscan = elementObj.getAttribute("noscan");
		if (noscan != null && noscan.length > 1) {
			this.allElements[j] = "noscan";
		} else {
			switch (elementObj.type) {

				case ("text"):
				case ("textarea"):
				case ("hidden"):
				case ("password"):
					elementValue = elementObj.value;
					break;
				case ("radio"):
				case ("checkbox"):
					elementValue = elementObj.defaultChecked;
					break;
				case ("select-one"):
					elementValue = elementObj.selectedIndex;
					break;
				case ("select-multiple"):
					for (var k = 0; k < elementObj.options.length; k++) {
						// the value is a string representing the selected state of each option
						elementValue += elementObj.options[k].defaultSelected.toString();
					}
					break;
			}
			this.allElements[j] = elementValue;
		}
	}
}

FormState.prototype.hasChanged = function () {

	var elementObj;
	var formState;
	var elementValue;
	var elemHasChanged = false;
	for (var i = 0; i < this.formObj.elements.length; i++) {
		elementObj = this.formObj.elements[i];
		elementValue = this.allElements[i];
		var noscan = elementObj.getAttribute("noscan");
		if (noscan != null && noscan.length > 1) {
			elemHasChanged = false;
		} else {			
			switch (elementObj.type) {
				case ("text"):
				case ("textarea"):
				case ("hidden"):
				case ("password"):
					elemHasChanged = (elementValue != elementObj.value);
					break;
				case ("radio"):
				case ("checkbox"):
					if ((elementValue == false && elementObj.checked) || (elementValue == true && !elementObj.checked)) {
						elemHasChanged = true;
					}
					break;
				case ("select-one"):
					elemHasChanged = (elementValue != elementObj.selectedIndex);
					break;
				case ("select-multiple"):
					var multiValueString = "";
					for (var k = 0; k < elementObj.options.length; k++) {
						multiValueString += elementObj.options[k].selected.toString();
					}
					elemHasChanged = (elementValue != multiValueString);

			}
		}
		if (elemHasChanged) {
			return true;
		}
	}
	return elemHasChanged;
}

FormState.prototype.scan = function () {
	if (this.hasChanged()) {
		this.unlockButtons();
		return true;
	} else {
		this.lockButtons();
		return false;
	}		
}

FormState.prototype.register = function (buttonObj) {
	if (buttonObj != null) {
		buttonObj.disabled = true;
		this.registeredButtons[this.registeredButtons.length] = buttonObj;
	}
}

FormState.prototype.unlockButtons = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		this.registeredButtons[i].disabled = false;
	}
}	

FormState.prototype.lockButtons = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		this.registeredButtons[i].disabled = true;
	}
}


function FormStateManager(documentString, sff) {
	this.initialized = false;
	this.allForms = null;
	this.doc = null;		
	this.docString = documentString;		
	this.registeredButtons = new Array();
	this.selectFirstField = (sff) ? true : false;
	this.forceApplyButtonLockFlag = false;
	this.noscan = false;
	this.initialize();
}

FormStateManager.prototype.initialize = function () {
	this.initialized = false;
	this.forceApplyButtonLockFlag = false;
	this.allForms = new Array();
	
	
	if (this.docString != null) {
		this.doc = eval(this.docString);
		if (this.doc != null && this.doc.forms.length > 0) {
			this.allForms = new Array();
			var formStateObj;
			for (var i = 0; i < this.doc.forms.length; i++) {
				var formStateObj = new FormState(this.doc.forms[i]);
				this.registerFormState(formStateObj);
				if (i == 0) {
					this.focusFirst(this.doc.forms[i]);
				}
			}
			this.doc.onunload = fsmanInitialize;
		} else {
			setTimeout("fsmanInitialize()", 500);
			return;
		}
	}
}

FormStateManager.prototype.registerFormState = function(formStateObj) {
	if (formStateObj != null) {						
		this.allForms[this.allForms.length] = formStateObj;
		this.initialized = true;
	}
}

FormStateManager.prototype.focusFirst = function (formObj) {
	var elementObj;
	for (var e = 0; e < formObj.elements.length; e++) {
		elementObj = formObj.elements[e];
		if (elementObj.type == "text" || elementObj.type == "textarea") {
			if (this.selectFirstField) {
				elementObj.select();	
			} else {
				elementObj.focus();	
			}	
			break;
		}
	}	
}

FormStateManager.prototype.hasChanged = function () {
	if (!this.initialized) {
		this.initialize();
		return false;
	}
	for (var i = 0; i < this.allForms.length; i++) {
		formStateObj = this.allForms[i];
		if (formStateObj.hasChanged()) {
			return true;
		}
	}
	return false;
}

FormStateManager.prototype.scan = function () {
	if (this.noscan) return;
	var childFSHasChanged = false;
	var fsObj;
	for (var i = 0; i < this.allForms.length; i++) {
		fsObj = this.allForms[i];
		if (fsObj.scan()) {
			childFSHasChanged = true;
		}
	}
	
	if (childFSHasChanged) {
		this.unlockButtons();
	} else {
		this.lockButtons();
	}
}	

FormStateManager.prototype.register = function (buttonObj) {
	if (buttonObj != null) {
		buttonObj.disabled = true;
		this.registeredButtons[this.registeredButtons.length] = buttonObj;
	}
}

FormStateManager.prototype.unlockButtons = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		button = this.registeredButtons[i];
		if (button.name == "mainSubmit") {
			if (this.forceApplyButtonLockFlag) continue;
		}
		button.disabled = false;
	}
}	

FormStateManager.prototype.lockButtons = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		this.registeredButtons[i].disabled = true;
	}
}

FormStateManager.prototype.lockApplyButton = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		button = this.registeredButtons[i];
		
		if (button.name == "mainSubmit") {
			button.disabled = true;
		}

	}
}	

FormStateManager.prototype.unlockApplyButton = function () {
	// Check bypass lock
	if (this.forceApplyButtonLockFlag) return;
	
	for (var i = 0; i < this.registeredButtons.length; i++) {
		button = this.registeredButtons[i];
		
		if (button.name == "mainSubmit") {
			button.disabled = false;
		}

	}
}

FormStateManager.prototype.unlockResetButton = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		button = this.registeredButtons[i];
		if (button.name == "mainReset") {
			button.disabled = false;
		}

	}
}	

FormStateManager.prototype.lockResetButton = function () {
	for (var i = 0; i < this.registeredButtons.length; i++) {
		button = this.registeredButtons[i];

		if (button.name == "mainReset") {
			button.disabled = true;
		}

	}
}


FormStateManager.prototype.forceApplyButtonLock = function () {
	this.forceApplyButtonLockFlag = true;	
}

FormStateManager.prototype.clearApplyButtonLock = function () {
	this.forceApplyButtonLockFlag = false;	
}

FormStateManager.prototype.disableScan = function () {
	this.noscan = true;	
}	

FormStateManager.prototype.enableScan = function () {
	this.noscan = false;	
}		

function unlockButtons() {
	if (fsman != null) {
		setTimeout("fsman.unlockButtons()", 50);
	}
}

function lockButtons() {
	if (fsman != null) {
		setTimeout("fsman.lockButtons()", 50);
	}	
}

function unlockApplyButton() {
	if (fsman != null) {
		setTimeout("fsman.unlockApplyButton()", 50);	
	}
}

function lockApplyButton() {
	if (fsman != null) {
		setTimeout("fsman.lockApplyButton()", 50);
	}			
}

function unlockResetButton() {
	if (fsman != null) {
		setTimeout("fsman.unlockResetButton()", 50);	
	}	
}

function lockResetButton() {
	if (fsman != null) {
		setTimeout("fsman.lockResetButton()", 50);
	}	
}

function forceApplyButtonLock() {
	if (fsman != null) {
		setTimeout("fsman.forceApplyButtonLock()", 50);
	}	
}

function clearApplyButtonLock() {
	if (fsman != null) {
		setTimeout("fsman.clearApplyButtonLock()", 50);
	}	
}	

function fsmanScan() {
	setTimeout("fsman.scan()", 50);
}
function fsmanInitialize() {
	fsman.initialize();		
}
	
function clickResortTab(eleName) {
  

  var widgetId = "widget" + eleName;
  var widget = document.getElementById(widgetId);
  widget.style.display = "block";

  if (widgetId == "widgetOverview")
  {
    var widgetGR = document.getElementById("widgetGuest Rooms");
    widgetGR.style.display = "none";

    var widgetKP = document.getElementById("widgetKids Programs");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetSpa Services");
    widgetSS.style.display = "none";
  }

  if (widgetId == "widgetGuest Rooms")
  {
    var widgetO = document.getElementById("widgetOverview");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetKids Programs");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetSpa Services");
    widgetSS.style.display = "none";
  }

  if (widgetId == "widgetKids Programs")
  {
    var widgetO = document.getElementById("widgetOverview");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetGuest Rooms");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetSpa Services");
    widgetSS.style.display = "none";
  }

  if (widgetId == "widgetSpa Services")
  {
    var widgetO = document.getElementById("widgetOverview");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetGuest Rooms");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetKids Programs");
    widgetSS.style.display = "none";
  }
}

function clickDiningTab(eleName) {
  

  var widgetId = "widget" + eleName;
  var widget = document.getElementById(widgetId);
  widget.style.display = "block";

  if (widgetId == "widgetCharacter Dining")
  {
    var widgetGR = document.getElementById("widgetBy Location");
    widgetGR.style.display = "none";

    var widgetKP = document.getElementById("widgetBy Cuisine");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Name");
    widgetSS.style.display = "none";

    var widgetDS = document.getElementById("widgetDinner Shows");
    widgetDS.style.display = "none";

    var widgetDP = document.getElementById("widgetDinner Packages");
    widgetDP.style.display = "none";
  }

  if (widgetId == "widgetBy Location")
  {
    var widgetO = document.getElementById("widgetCharacter Dining");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetBy Cuisine");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Name");
    widgetSS.style.display = "none";

    var widgetDS = document.getElementById("widgetDinner Shows");
    widgetDS.style.display = "none";

    var widgetDP = document.getElementById("widgetDinner Packages");
    widgetDP.style.display = "none";
  }

  if (widgetId == "widgetBy Cuisine")
  {
    var widgetO = document.getElementById("widgetCharacter Dining");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetBy Location");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Name");
    widgetSS.style.display = "none";

    var widgetDS = document.getElementById("widgetDinner Shows");
    widgetDS.style.display = "none";

    var widgetDP = document.getElementById("widgetDinner Packages");
    widgetDP.style.display = "none";
  }

  if (widgetId == "widgetBy Name")
  {
    var widgetO = document.getElementById("widgetCharacter Dining");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetBy Location");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Cuisine");
    widgetSS.style.display = "none";

    var widgetDS = document.getElementById("widgetDinner Shows");
    widgetDS.style.display = "none";

    var widgetDP = document.getElementById("widgetDinner Packages");
    widgetDP.style.display = "none";
  }

  if (widgetId == "widgetDinner Shows")
  {
    var widgetO = document.getElementById("widgetCharacter Dining");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetBy Location");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Cuisine");
    widgetSS.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Name");
    widgetSS.style.display = "none";

    var widgetDP = document.getElementById("widgetDinner Packages");
    widgetDP.style.display = "none";
  }

  if (widgetId == "widgetDinner Packages")
  {
    var widgetO = document.getElementById("widgetCharacter Dining");
    widgetO.style.display = "none";

    var widgetKP = document.getElementById("widgetBy Location");
    widgetKP.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Cuisine");
    widgetSS.style.display = "none";

    var widgetSS = document.getElementById("widgetBy Name");
    widgetSS.style.display = "none";

    var widgetDS = document.getElementById("widgetDinner Shows");
    widgetDS.style.display = "none";
  }
}


function removeWidget(widget) {

  widget.style.display = "none";
}


function appendSiteId(url) 
{
	var siteId = document.forms['siteIdForm'].siteID.value;
	url = url + '&SiteID=' + siteId;
	window.location.href = url;
}