// [MODULE-HEADER]
// *************************************************************************************************
//
// Name:				ShoWareFrontEndPerSectionReservation.js
//
// Created:			13/10/2003 VisionOne AG, St Gallen fbe
// Modified:		23/11/2005 VisionOne AG, St Gallen fbe	: Handling section tooltip display type defined in settings
// Modified:		Mi-07.04.2004 VisionOne AG, St. Gallen EPE	: changed the CSS class at the function PopupSectionDetails
// Modified:		12/02/2004 VisionOne AG, St Gallen fbe	: Changed the Css to 'SeatMapTooltipText'
// Modified:		13/10/2003 VisionOne AG, St Gallen fbe	: Creation
//
// *************************************************************************************************

//
// constants
//
var SECTION_PREFIX = "sec";

//
// Formats the section code so that it only has valid js variable names
//
function FormatSectionCode(sectionCode)
{
	var replaceChar = "_";
	var invalidChars = new Array(" ", "/", "-", ";", ".", "%", "#", "!", ",");
	
	
	for (i=0; i < sectionCode.length; ++i)
	{
		sectionCode = sectionCode.split(invalidChars[i]).join(replaceChar);
	}
		
	return sectionCode;
}

//
// Shows the popup with section informations
//
function ShowSectionDetails(sectionCode)
{
	var safeSectionCode = FormatSectionCode(sectionCode);
	var sectionValues = eval(SECTION_PREFIX + safeSectionCode);
	
	var name = sectionValues[1];
	var perspectiveUrl = sectionValues[3];
	var total = sectionValues[4]
	var available = sectionValues[5];	
	
	PopupSectionDetails(sectionCode, name, available, total, perspectiveUrl);
}

//
// Navigates to the section url
//
function NavigateToSection(sectionCode)
{
	if (canClickSection)
	{
		var safeSectionCode = FormatSectionCode(sectionCode);
		var sectionValues = eval(SECTION_PREFIX + safeSectionCode);
		var secId = sectionValues[0];
		var available = sectionValues[5];
		
		// 22/11/2005 VisionOne AG, St Gallen fbe
		// do not navigate to section if it doesn't contain tickets		
		if (available > 0)
		{
			var url = NAVIGATIONHELPER_ShoWareFrontEndPerReservation + "?PERFORMANCEID=" + performanceid + "&SECTIONID=" + secId;
			if (bookWithoutPromotion)
				url = url + "&NOPROMO=1";
			window.location.href = url;
		}
		else
		{
			alert(res_text_notticketsavailableinsection);
		}
	}
}

//
// Formats the section popup information
//
function PopupSectionDetails(sectionCode, sectionName, available, total, perspectiveUrl)
{	
	var content = 
		"<table cellpadding=1 cellspacing=0 border=0><tr><td><table cellpadding=0 cellspacing=3 border=0><tr><td nowrap class='SeatMapTooltipTitleText'><b>" + txt_section + ": " + sectionName + "</b></td></tr>";
	
	// 23/11/2005 VisionOne AG, St Gallen fbe
	// Handling section tooltip display type defined in settings
	if (sectionAvailableTooltipType == "AvailableOfTotal")
	{
		content += "<tr><td nowrap class='SeatMapTooltipText'>" + txt_availables + ": " + available + " " + txt_of + " " + total + "</td></tr>";
	}
	else if (sectionAvailableTooltipType == "Available")
	{
		content += "<tr><td nowrap class='SeatMapTooltipText'>" + txt_availables + ": " + available + "</td></tr>";
	}
	
	content += "</table></td></tr></table>";
		
	PopupContent(content);	
}

//
// shows the section popup
//
function PopupContent(content)
{
	showBalloon(content, 0, 100, '#FFFFFF');
}

//
// hides the popup
//
function HideSectionDetails()
{	
	hideBalloon();
}

//
// Verifies if the confirmation key was filled out
//
function CheckConfirmationKey()
{	
	if (confirmationKeyInputControlName.length > 0)
	{
		var inputText = null;
		
		if (document.all)
		{		
			inputText = document.all[confirmationKeyInputControlName];			
		}
		else if (document.frames)
		{
			inputText = document.frames[confirmationKeyInputControlName];
		}
		
		if (inputText && inputText.value.length == 0)
		{
			alert(confirmationKeyMessage);
			inputText.focus();
			return false;	
		}
	}
	
	return true;
}


//
// Does the post back to get the best pick
//
function DoBestPick(priceCategoryID, ticketAmount)
{
	
	__doPostBack(cmdBestPickName, priceCategoryID + ";" + ticketAmount);
}



var B_Type = new crossBrowserType();
function crossBrowserType() {
	this.IE = false;
	this.NS4 = false;
	this.NS6 = false;
	this.id = "";

	if (document.all) {this.IE = true; this.id = "IE";}
	else if (document.getElementById) {this.NS6 = true; this.id = "NS6";}
	else if (document.layers) {this.NS4 = true; this.id = "NS4";}
}
function crossGetObject(id) {
	var obj = null;
	if (B_Type.IE) obj=document.all[id];
	else if (B_Type.NS6) obj=document.getElementById(id);
	else if (B_Type.NS4) obj=document.layers[id];
	return obj;
}

var previousDiv = null;;

function ShowDiv(divName){
	var objDiv = crossGetObject(divName);
	
	if (previousDiv)
		if (previousDiv == divName)
		{
			HideDiv(previousDiv);
			return;
		}
		else
			HideDiv(previousDiv);
	
	previousDiv = divName;
	
	if (objDiv)
	{
		objDiv.style.display = "block";
	}
}
function HideDiv(divName){
	var objDiv = crossGetObject(divName);
	previousDiv = null;
	
	if (objDiv)
	{
		objDiv.style.display = "none";
	}
}
