/**
*	whnShowlist.js
*
*	JavaScript functions used for managing and 
*	creating the dynamic show selection lists
*
*	@copyright	Webhosting.net, Inc. 2002 <copyright@webhosting.net>
*	
*	$Id: whnShowlist.js,v 1.13 2003/01/16 02:28:58 broadwaywww Exp $
*	$Revision: 1.13 $
*	$Author: broadwaywww $
*	$Date: 2003/01/16 02:28:58 $
*	$Source: /usr/local/broadwaycollection_repository/thebroadwaycollection/thebroadwaycollection/html/whnShowlist.js,v $
*/

/**
*	initShows
*
*	Populate the shows select list
*
*	@author		L.P.Boyce <leonard@webhosting.net>
*	@copyright	Webhosting.net, Inc <copyright@webhosting.net>
*	@access		public
*/
function initShows() {
	var shows = new Array( "", "------------- Select Category ------------", "1", "Aeros", "2", "Annie", "3", "blast!", "4", "Cabaret", "5", "Cats", "6", "Cinderella", "7", "Contact", "194", "CYBERJAM", "199", "Fiddler On The Roof", "8", "Fosse", "148", "Hands Across The Sea", "9", "Jekyll & Hyde", "160", "Jesus Christ Superstar", "166", "Man of La Mancha", "141", "Movin' Out", "200", "Oklahoma!", "201", "Oliver", "10", "Saturday Night Fever", "172", "Shockwave", "11", "South Pacific", "182", "Starlight Express", "12", "Stomp", "13", "Swing", "14", "Tap Dogs", "15", "The Best Little Whorehouse In Texas", "188", "The Boy From Oz", "16", "The Full Monty", "17", "The Producers", "18", "The Sound of Music", "228", "The Tony Awards", "134", "Thoroughly Modern Millie", "19", "Various Programs & Window Cards", "202", "Wonderful Town" );
	
	theForm = document.searchForm;
	theForm.elements['q1'].length = 0;
	cnt = 0;
	for ( i=0; i < shows.length; i++ ) {
		if ( i % 2 == 0 ) {
			theForm.elements['q1'].options[cnt] = new Option( shows[i+1], shows[i] );
			cnt++;
		}
	}
}





/**
*	initCategories
*
*	Populate the categories select list
*
*	@author		L.P.Boyce <leonard@webhosting.net>
*	@copyright	Webhosting.net, Inc <copyright@webhosting.net>
*	@access		public
*
*	@param	array	categories	An array of categories and their values
*/
function initCategories( categories ) {
	var theForm = document.searchForm;
	cnt = 1;
	theForm.elements['q2'].length = 0;
	theForm.elements['q2'].options[0] = new Option( "--------------- Select Category -------------", "" );
	for ( i=0; i < categories.length; i++ ) {
		if ( i % 2 == 0 ) {
			theForm.elements['q2'].options[cnt] = new Option( categories[i+1], categories[i] );
			cnt++;
		}
	}
}





/**
*	showVal
*
*	Get the value of the currently selected show
*
*	@author		L.P.Boyce <leonard@webhosting.net>
*	@copyright	Webhosting.net, Inc <copyright@webhosting.net>
*	@access		public
*
*	@return	string	retVal	The value of the currently selected item
*/
function showVal() {
	retVal = "";
	theForm = document.searchForm;
	
	retVal = theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value;
	return retVal;
}





/**
*	populateCategories
*
*	Populate the categories select list with categories
*	valid for the selected show
*
*	@author		L.P.Boyce <leonard@webhosting.net>
*	@copyright	Webhosting.net, Inc <copyright@webhosting.net>
*	@access		public
*
*	@param	int		showID	The ID of the currently selected show
*	@return	string	retVal	The value of the currently selected item
*/
function populateCategories( showID ) {
	theForm = document.searchForm;
	
	/*
	* Format for the belows is as follows:
	*	
	*/
	/* base categories for general searching */
	catarray_0_catarray = new Array( "Apparel", "Apparel", "Baseball Caps", "Baseball Caps", "Collectibles", "Collectibles", "Music & Video", "Music & Video", "Programs", "Programs", "Window Cards", "Window Cards" );
	/* Aeros - 1 */
	catarray_1_catarray = new Array( "20", "Apparel", "21", "Baseball Caps", "22", "Music & Video" );
	/* Annie - 2 */
	catarray_2_catarray = new Array( "26", "Apparel", "27", "Baseball Caps", "28", "Collectibles", "29", "Music & Video", "30", "Programs", "31", "Window Cards" );
	/* blast! - 3 */
	catarray_3_catarray = new Array( "32", "Apparel", "33", "Baseball Caps", "143", "Collectibles", "35", "Music & Video", "36", "Programs", "37", "Window Cards" );
	/* Cabaret - 4 */
	catarray_4_catarray = new Array( "38", "Apparel", "39", "Baseball Caps", "40", "Collectibles", "41", "Music & Video", "42", "Programs", "43", "Window Cards" );
	/* Cats - 5 */
	catarray_5_catarray = new Array( "44", "Apparel", "146", "Collectibles", "45", "Baseball Caps", "47", "Music & Video", "48", "Programs", "49", "Window Cards" );
	/* Cinderella - 6 */
	catarray_6_catarray = new Array( "50", "Apparel", "51", "Baseball Caps", "52", "Collectibles", "53", "Music & Video", "54", "Programs" );
	/* Contact - 7 */
	catarray_7_catarray = new Array( "56", "Apparel", "57", "Baseball Caps", "58", "Collectibles", "61", "Window Cards" );
	/* Fosse - 8 */
	catarray_8_catarray = new Array( "62", "Apparel", "63", "Baseball Caps", "64", "Collectibles", "65", "Music & Video", "66", "Programs", "67", "Window Cards" );
	/* Jekyll & Hyde - 9 */
	catarray_9_catarray = new Array( "68", "Apparel", "69", "Baseball Caps", "70", "Collectibles", "71", "Music & Video", "72", "Programs" );
	/* Saturday Night Fever - 10 */
	catarray_10_catarray = new Array( "74", "Apparel", "75", "Baseball Caps", "76", "Collectibles", "77", "Music & Video", "78", "Programs" );
	/* South Pacific - 11 */
	catarray_11_catarray = new Array( "226", "Apparel", "144", "Collectibles", "83", "Music & Video", "85", "Window Cards" );
	/* Stomp - 12 */
	catarray_12_catarray = new Array( "86", "Apparel", "179", "Baseball Caps", "88", "Collectibles", "89", "Music & Video", "90", "Programs", "180", "Window Cards" );
	/* Swing - 13 */
	catarray_13_catarray = new Array( "92", "Apparel", "93", "Baseball Caps", "94", "Collectibles", "95", "Music & Video", "96", "Programs" );
	/* Tap Dogs - 14 */
	catarray_14_catarray = new Array( "98", "Apparel", "99", "Baseball Caps", "100", "Collectibles", "101", "Music & Video", "102", "Programs" );
	/* The Best Little Whorehouse in Texas - 15 */
	catarray_15_catarray = new Array( "104", "Apparel", "105", "Baseball Caps", "106", "Collectibles", "107", "Music & Video", "108", "Programs", "109", "Window Cards" );
	/* The Full Monty - 16 */
	catarray_16_catarray = new Array( "110", "Apparel", "111", "Baseball Caps", "112", "Collectibles", "113", "Music & Video", "114", "Programs", "115", "Window Cards" );
	/* The Producers - 17 */
	catarray_17_catarray = new Array( "116", "Apparel", "117", "Baseball Caps", "118", "Collectibles", "119", "Music & Video", "120", "Programs", "121", "Window Cards" );
	/* The Sound of Music - 18 */
	catarray_18_catarray = new Array( "122", "Apparel", "124", "Collectibles", "126", "Programs", "127", "Window Cards" );
	/* Various programs and window cards - 19 */
	catarray_19_catarray = new Array( "132", "Programs", "133", "Window Cards" );
	/* Thoroughly Modern Millie - 134 */
	catarray_134_catarray = new Array( "136", "Apparel", "137", "Baseball Caps", "138", "Collectibles", "140", "Music & Video", "135", "Programs", "139", "Window Cards" );
	/* Movin' Out - 141 */
	catarray_141_catarray = new Array( "142", "Apparel", "177", "Baseball Caps", "178", "Collectibles", "145", "Music & Video", "198", "Programs", "147", "Window Cards" );
	/* Hands Across The Sea - 148 */
	catarray_148_catarray = new Array( "150", "Apparel", "152", "Collectibles", "149", "Music & Video", "151", "Programs" );
	/* Bring In Da Noise, Bring In Da Funk */
	//catarray_153_catarray = new Array( "154", "Apparel", "181", "Baseball Caps", "155", "Collectibles" );
	/* Dance of the Vampires */
	//catarray_156_catarray = new Array( "157", "Apparel", "158", "Baseball Caps", "159", "Window Cards" );
	/* Jesus Christ Superstar */
	catarray_160_catarray = new Array( "161", "Apparel", "162", "Baseball Caps", "163", "Collectibles", "164", "Music & Video", "165", "Window Cards" );
	/* Man of La Mancha */
	catarray_166_catarray = new Array( "167", "Apparel", "168", "Baseball Caps", "169", "Collectibles", "170", "Music & Video", "171", "Window Cards" );
	/* Shockwave */
	catarray_172_catarray = new Array( "173", "Apparel", "174", "Baseball Caps", "175", "Collectibles", "176", "Window Cards" );
	/* Starlight Express */
	catarray_182_catarray = new Array( "183", "Apparel", "184", "Collectibles", "185", "Music & Video", "186", "Window Cards", "193", "Programs" );
	/* The Boy From Oz */
	catarray_188_catarray = new Array( "189", "Apparel", "227", "Baseball Caps", "190", "Collectibles", "191", "Music & Video", "197", "Programs", "192", "window Cards" );
	/* CYBERJAM */
	catarray_194_catarray = new Array( "195", "Apparel", "196", "Collectibles" );
	/* Fiddler On The Roof */
	catarray_199_catarray = new Array( "203", "Apparel", "204", "Baseball Caps", "205", "Collectibles", "206", "Music & Video", "207", "Window Cards" );
	/* Oklahoma! */
	catarray_200_catarray = new Array( "208", "Apparel", "209", "Baseball Caps", "210", "Collectibles", "211", "Music & Video", "212", "Programs", "213", "Window Cards" );
	/* Oliver */
	catarray_201_catarray = new Array( "214", "Apparel", "215", "Baseball Caps", "216", "Collectibles", "217", "Music & Video", "218", "Programs", "219", "Window Cards" );
	/* Wonderful Town */
	catarray_202_catarray = new Array( "220", "Apparel", "221", "Baseball Caps", "222", "Collectibles", "223", "Music & Video", "224", "Programs", "225", "Window Cards" );
	/* The Tony Awards */
	//catarray_228_catarray = new Array( "229", "Apparel", "230", "Baseball Caps", "231", "Collectibles", "232", "Music & Video", "233", "Programs", "234", "Window Cards" );
	catarray_228_catarray = new Array( "229", "Apparel", "230", "Baseball Caps", "231", "Collectibles","232", "Songbook", "234", "Window Cards"  );
	if ( showID != 0 ) {
		showID = showVal();
	}
	categories = eval( "catarray_" + showID + "_catarray" );
	//alert( categories );
	initCategories( categories );
}





/**
*	submitSearch
*
*	Submit the form
*
*	@author		L.P.Boyce <leonard@webhosting.net>
*	@copyright	Webhosting.net, Inc <copyright@webhosting.net>
*	@access		public
*/
function submitSearch() {
	theForm = document.searchForm;
//	debugVals();
	if ( theForm.elements['q2'].options[theForm.elements['q2'].selectedIndex].value == "" && theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value != "" ) {
		// Only a Show selected
		theForm.elements['query'].value = "^ataglance.sql";
		targetCat = theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value;
		window.location='http://www.thebroadwaycollection.com/cgi-bin/category.cgi?category=' + targetCat;
		return false;
	}
	else if ( theForm.elements['q2'].options[theForm.elements['q2'].selectedIndex].value != "" && theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value != "" ) {
		// Both a Show and a Category selected, therefore we target the q2 value 
		targetCat = theForm.elements['q2'].options[theForm.elements['q2'].selectedIndex].value;
		targetLocation = "http://www.thebroadwaycollection.com/cgi-bin/category.cgi?category=" + targetCat + "&type=store";
		window.location = targetLocation;
		return false;
	}
	else if ( theForm.elements['q2'].options[theForm.elements['q2'].selectedIndex].value != "" && theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value == "" ) {
		// Only a Category selected, so we need to do a free-text search
		theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value = "1";
		theForm.elements['query'].value = "^ataglance3.sql";
		theForm.elements['categoryholder'].value = theForm.elements['q2'].options[theForm.elements['q2'].selectedIndex].value;
		//debugVals();
	}
	if ( theForm.elements['query'].value != "" ) {
		// Actually submit the form
		theForm.submit();
	}
}







/**
*	debugVals
*
*	Alert all form values for visual validation
*
*	@author		L.P.Boyce <leonard@webhosting.net>
*	@copyright	Webhosting.net, Inc <copyright@webhosting.net>
*	@access		public
*/
function debugVals() {
	theForm = document.searchForm;
	alertVal = "q1: " + theForm.elements['q1'].options[theForm.elements['q1'].selectedIndex].value + "\n";
	alertVal += "q2: " + theForm.elements['q2'].options[theForm.elements['q2'].selectedIndex].value + "\n";
	alertVal += "q3: " + theForm.elements['q3'].value + "\n";
	alertVal += "query: " + theForm.elements['query'].value + "\n";
	alert( alertVal );
}

